Changeset 5119 for geovis


Ignore:
Timestamp:
Mar 11, 2015, 3:11:07 AM (10 years ago)
Author:
ldelgass
Message:

Add legend option for blending against a background color

Location:
geovis/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • geovis/trunk/ColorMap.cpp

    r5118 r5119  
    3434            float x = (float)i/(height-1);
    3535            float val = min + (max - min) * x;
    36             osg::Vec4f rgb = map->getColor(val);
     36            osg::Vec4f rgba = map->getColor(val);
     37            float opacity = rgba[3];
    3738            unsigned char color[3];
    3839            if (opaque) {
    39                 color[0] = (unsigned char)(255. * (bgr ? rgb[2] : rgb[0]));
    40                 color[1] = (unsigned char)(255. * rgb[1]);
    41                 color[2] = (unsigned char)(255. * (bgr ? rgb[0] : rgb[2]));
     40                color[0] = (unsigned char)(255. * (bgr ? rgba[2] : rgba[0]));
     41                color[1] = (unsigned char)(255. * rgba[1]);
     42                color[2] = (unsigned char)(255. * (bgr ? rgba[0] : rgba[2]));
    4243            } else {
    43                 float opacity = rgb[3];
    44                 color[0] = (unsigned char)(255. * (bgColor[0] * (1.0 - opacity) + (bgr ? rgb[2] : rgb[0]) * opacity));
    45                 color[1] = (unsigned char)(255. * (bgColor[1] * (1.0 - opacity) + rgb[1] * opacity));
    46                 color[2] = (unsigned char)(255. * (bgColor[2] * (1.0 - opacity) + (bgr ? rgb[0] : rgb[2]) * opacity));
     44                color[0] = (unsigned char)(255. * (bgColor[0] * (1.0 - opacity) + (bgr ? rgba[2] : rgba[0]) * opacity));
     45                color[1] = (unsigned char)(255. * (bgColor[1] * (1.0 - opacity) + rgba[1] * opacity));
     46                color[2] = (unsigned char)(255. * (bgColor[2] * (1.0 - opacity) + (bgr ? rgba[0] : rgba[2]) * opacity));
    4747            }
    4848            for (int j = 0; j < width; j++) {
     
    5050                dst += 3;
    5151                if (bytesPerPixel == 4) {
    52                     *(dst++) = (unsigned char)255.;
     52                    *(dst++) = (unsigned char)(255. * (opaque ? 1.0 : opacity));
    5353                }
    5454            }
     
    6060                float val = min + (max - min) * x;
    6161                osg::Vec4f rgb = map->getColor(val);
     62                double opacity = rgb[3];
    6263                unsigned char color[3];
    6364                if (opaque) {
     
    6667                    color[2] = (unsigned char)(255. * (bgr ? rgb[0] : rgb[2]));
    6768                } else {
    68                     double opacity = rgb[3];
    6969                    color[0] = (unsigned char)(255. * (bgColor[0] * (1.0 - opacity) + (bgr ? rgb[2] : rgb[0]) * opacity));
    7070                    color[1] = (unsigned char)(255. * (bgColor[1] * (1.0 - opacity) + rgb[1] * opacity));
     
    7474                dst += 3;
    7575                if (bytesPerPixel == 4) {
    76                     *(dst++) = (unsigned char)255.;
     76                    *(dst++) = (unsigned char)(255. * (opaque ? 1.0 : opacity));
    7777                }
    7878            }
  • geovis/trunk/RendererCmd.cpp

    r5118 r5119  
    743743          Tcl_Obj *const *objv)
    744744{
    745     if (objc != 4) {
     745    if (objc < 4) {
    746746        Tcl_AppendResult(interp, "wrong # args: should be \"",
    747747                Tcl_GetString(objv[0]), " colormapName width height\"", (char*)NULL);
     
    755755        return TCL_ERROR;
    756756    }
    757 
    758757    bool opaque = true;
     758    if (objc > 4) {
     759        if (GetBooleanFromObj(interp, objv[4], &opaque) != TCL_OK) {
     760            return TCL_ERROR;
     761        }
     762    }
    759763    float bgColor[3];
    760     memset(bgColor, 0, sizeof(float)*3);
     764    if (objc > 5) {
     765        if (GetFloatFromObj(interp, objv[5], &bgColor[0]) != TCL_OK ||
     766            GetFloatFromObj(interp, objv[6], &bgColor[1]) != TCL_OK ||
     767            GetFloatFromObj(interp, objv[7], &bgColor[2]) != TCL_OK) {
     768            return TCL_ERROR;
     769        }
     770    } else {
     771        memset(bgColor, 0, sizeof(float)*3);
     772    }
    761773    osg::ref_ptr<osg::Image> imgData = new osg::Image();
    762774
  • geovis/trunk/geovis_protocol.txt

    r5107 r5119  
    8585         <numberOfTableEntries> = integer or "default"
    8686
     87legend <colormapName> <w> <h> <?opaque?> <?bgR?> <?bgG?> <?bgB?>
     88       Render a legend colorbar.
     89       <colormapName> - Name of the colormap defined with the colormap command
     90       <w>,<h> - width and height of colorbar
     91       <opaque> - If false, blend with background color
     92       <bgR>,<bgG>,<bgB> - Background color (defaults to black)
     93
    8794renderer render
    8895         Force a new image to be rendered
Note: See TracChangeset for help on using the changeset viewer.