Changeset 4604 for vtkvis/branches/1.7


Ignore:
Timestamp:
Aug 2, 2014, 12:29:05 AM (10 years ago)
Author:
ldelgass
Message:

Merge r4073-4074,4077-4081 from trunk

Location:
vtkvis/branches/1.7
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • vtkvis/branches/1.7

  • vtkvis/branches/1.7/ColorMap.cpp

    r3982 r4604  
    488488    return _elementDefault;
    489489}
     490
     491/**
     492 * \brief Render (using CPU) color map to an image
     493 */
     494void ColorMap::renderColorMap(ColorMap *map, int width, int height,
     495                              vtkUnsignedCharArray *imgData,
     496                              bool opaque, float bgColor[3],
     497                              bool bgr, int bytesPerPixel)
     498{
     499    int size = bytesPerPixel * width * height;
     500    if (imgData->GetMaxId() + 1 != size) {
     501        imgData->SetNumberOfComponents(bytesPerPixel);
     502        imgData->SetNumberOfValues(size);
     503    }
     504    unsigned char *dst = imgData->GetPointer(0);
     505    vtkLookupTable *table = map->getLookupTable();
     506    if (height > width) {
     507        for (int i = 0; i < height; i++) {
     508            double x = (double)i/(height-1);
     509            double rgb[3];
     510            table->GetColor(x, rgb);
     511            unsigned char color[3];
     512            if (opaque) {
     513                color[0] = (unsigned char)(255. * (bgr ? rgb[2] : rgb[0]));
     514                color[1] = (unsigned char)(255. * rgb[1]);
     515                color[2] = (unsigned char)(255. * (bgr ? rgb[0] : rgb[2]));
     516            } else {
     517                double opacity = table->GetOpacity(x);
     518                color[0] = (unsigned char)(255. * (bgColor[0] * (1.0 - opacity) + (bgr ? rgb[2] : rgb[0]) * opacity));
     519                color[1] = (unsigned char)(255. * (bgColor[1] * (1.0 - opacity) + rgb[1] * opacity));
     520                color[2] = (unsigned char)(255. * (bgColor[2] * (1.0 - opacity) + (bgr ? rgb[0] : rgb[2]) * opacity));
     521            }
     522            for (int j = 0; j < width; j++) {
     523                memcpy(dst, color, 3);
     524                dst += 3;
     525                if (bytesPerPixel == 4) {
     526                    *(dst++) = (unsigned char)255.;
     527                }
     528            }
     529        }
     530    } else {
     531        for (int i = 0; i < height; i++) {
     532            for (int j = 0; j < width; j++) {
     533                double x = (double)j/(width-1);
     534                double rgb[3];
     535                table->GetColor(x, rgb);
     536                unsigned char color[3];
     537                if (opaque) {
     538                    color[0] = (unsigned char)(255. * (bgr ? rgb[2] : rgb[0]));
     539                    color[1] = (unsigned char)(255. * rgb[1]);
     540                    color[2] = (unsigned char)(255. * (bgr ? rgb[0] : rgb[2]));
     541                } else {
     542                    double opacity = table->GetOpacity(x);
     543                    color[0] = (unsigned char)(255. * (bgColor[0] * (1.0 - opacity) + (bgr ? rgb[2] : rgb[0]) * opacity));
     544                    color[1] = (unsigned char)(255. * (bgColor[1] * (1.0 - opacity) + rgb[1] * opacity));
     545                    color[2] = (unsigned char)(255. * (bgColor[2] * (1.0 - opacity) + (bgr ? rgb[0] : rgb[2]) * opacity));
     546                }
     547                memcpy(dst, color, 3);
     548                dst += 3;
     549                if (bytesPerPixel == 4) {
     550                    *(dst++) = (unsigned char)255.;
     551                }
     552            }
     553        }
     554    }
     555}
  • vtkvis/branches/1.7/ColorMap.h

    r3982 r4604  
    1717#include <vtkPiecewiseFunction.h>
    1818#include <vtkLookupTable.h>
     19#include <vtkUnsignedCharArray.h>
    1920
    2021namespace VtkVis {
     
    115116    static ColorMap *getElementDefault();
    116117
     118    static void renderColorMap(ColorMap *map, int width, int height,
     119                               vtkUnsignedCharArray *imgData,
     120                               bool opaque, float bgColor[3],
     121                               bool bgr = false,
     122                               int bytesPerPixel = 3);
     123
    117124private:
    118125    static ColorMap *_default;
  • vtkvis/branches/1.7/Image.cpp

    r3991 r4604  
    148148}
    149149
     150void Image::setAspect(double aspect)
     151{
     152    double bounds[6];
     153    vtkDataSet *ds = _dataSet->getVtkDataSet();
     154    ds->GetBounds(bounds);
     155    double size[3];
     156    size[0] = bounds[1] - bounds[0];
     157    size[1] = bounds[3] - bounds[2];
     158    size[2] = bounds[5] - bounds[4];
     159    double scale[3];
     160    scale[0] = scale[1] = scale[2] = 1.;
     161
     162    vtkImageMapper3D *mapper = getImageMapper();
     163    if (mapper == NULL)
     164        return;
     165
     166    mapper->Update();
     167
     168    double normal[3];
     169    mapper->GetSlicePlane()->GetNormal(normal);
     170
     171    Axis sliceAxis = Z_AXIS;
     172    if (fabs(normal[0]) == 1.0 &&
     173        normal[1] == 0.0 &&
     174        normal[2] == 0.0) {
     175        sliceAxis = X_AXIS;
     176    } else if (normal[0] == 0.0 &&
     177               fabs(normal[1]) == 1.0 &&
     178               normal[2] == 0.0) {
     179        sliceAxis = Y_AXIS;
     180    } else if (normal[0] == 0.0 &&
     181               normal[1] == 0.0 &&
     182               fabs(normal[2]) == 1.0) {
     183        sliceAxis = Z_AXIS;
     184    } else {
     185        TRACE("Non orthogonal slice plane, setting native aspect");
     186        aspect = 0.0;
     187    }
     188
     189    if (aspect == 1.0) {
     190        // Square
     191        switch (sliceAxis) {
     192        case X_AXIS: {
     193            if (size[1] > size[2] && size[2] > 0.0) {
     194                scale[2] = size[1] / size[2];
     195            } else if (size[2] > size[1] && size[1] > 0.0) {
     196                scale[1] = size[2] / size[1];
     197            }
     198        }
     199            break;
     200        case Y_AXIS: {
     201            if (size[0] > size[2] && size[2] > 0.0) {
     202                scale[2] = size[0] / size[2];
     203            } else if (size[2] > size[0] && size[0] > 0.0) {
     204                scale[0] = size[2] / size[0];
     205            }
     206        }
     207            break;
     208        case Z_AXIS: {
     209            if (size[0] > size[1] && size[1] > 0.0) {
     210                scale[1] = size[0] / size[1];
     211            } else if (size[1] > size[0] && size[0] > 0.0) {
     212                scale[0] = size[1] / size[0];
     213            }
     214        }
     215            break;
     216        }
     217    } else if (aspect != 0.0) {
     218        switch (sliceAxis) {
     219        case X_AXIS: {
     220            if (aspect > 1.0) {
     221                if (size[2] > size[1] && size[1] > 0.0) {
     222                    scale[1] = (size[2] / aspect) / size[1];
     223                } else if (size[2] > 0.0) {
     224                    scale[2] = (size[1] * aspect) / size[2];
     225                }
     226            } else {
     227                if (size[1] > size[2] && size[2] > 0.0) {
     228                    scale[2] = (size[1] * aspect) / size[2];
     229                } else if (size[1] > 0.0) {
     230                    scale[1] = (size[2] / aspect) / size[1];
     231                }
     232            }
     233        }
     234            break;
     235        case Y_AXIS: {
     236            if (aspect > 1.0) {
     237                if (size[0] > size[2] && size[2] > 0.0) {
     238                    scale[2] = (size[0] / aspect) / size[2];
     239                } else if (size[0] > 0.0) {
     240                    scale[0] = (size[2] * aspect) / size[0];
     241                }
     242            } else {
     243                if (size[2] > size[0] && size[0] > 0.0) {
     244                    scale[0] = (size[2] * aspect) / size[0];
     245                } else if (size[2] > 0.0) {
     246                    scale[2] = (size[0] / aspect) / size[2];
     247                }
     248            }
     249        }
     250            break;
     251        case Z_AXIS: {
     252            if (aspect > 1.0) {
     253                if (size[0] > size[1] && size[1] > 0.0) {
     254                    scale[1] = (size[0] / aspect) / size[1];
     255                } else if (size[0] > 0.0) {
     256                    scale[0] = (size[1] * aspect) / size[0];
     257                }
     258            } else {
     259                if (size[1] > size[0] && size[0] > 0.0) {
     260                    scale[0] = (size[1] * aspect) / size[0];
     261                } else if (size[1] > 0.0) {
     262                    scale[1] = (size[0] / aspect) / size[1];
     263                }
     264            }
     265        }
     266            break;
     267        }
     268    }
     269
     270    TRACE("%s dims %g,%g,%g", _dataSet->getName().c_str(),
     271          size[0], size[1], size[2]);
     272    TRACE("Setting scale to %g,%g,%g", scale[0], scale[1], scale[2]);
     273    setScale(scale);
     274    mapper->Modified();
     275    mapper->Update();
     276}
     277
    150278void Image::setClippingPlanes(vtkPlaneCollection *planes)
    151279{
  • vtkvis/branches/1.7/Image.h

    r3991 r4604  
    3232{
    3333public:
     34    enum InterpType {
     35        INTERP_NEAREST,
     36        INTERP_LINEAR,
     37        INTERP_CUBIC
     38    };
     39
    3440    Image();
    3541    virtual ~Image();
     
    4551
    4652    virtual void setClippingPlanes(vtkPlaneCollection *planes);
     53
     54    virtual void setAspect(double aspect);
    4755
    4856    void updateColorMap()
     
    8492    }
    8593
     94    void setUseWindowLevel(bool state)
     95    {
     96        vtkImageProperty *property = getImageProperty();
     97        if (property == NULL)
     98            return;
     99
     100        property->SetUseLookupTableScalarRange((state ? 0 : 1));
     101    }
     102
    86103    double getWindow()
    87104    {
     
    100117
    101118        property->SetColorWindow(window);
     119        property->UseLookupTableScalarRangeOff();
    102120    }
    103121
     
    118136
    119137        property->SetColorLevel(level);
    120     }
    121 
    122     void setWindowAndLevel(double window, double level)
    123     {
    124         vtkImageProperty *property = getImageProperty();
    125         if (property == NULL)
    126             return;
    127 
    128         property->SetColorWindow(window);
    129         property->SetColorLevel(level);
     138        property->UseLookupTableScalarRangeOff();
    130139    }
    131140
     
    157166    }
    158167
     168    void setInterpolationType(InterpType type)
     169    {
     170        vtkImageProperty *property = getImageProperty();
     171        if (property == NULL)
     172            return;
     173
     174        switch (type) {
     175        case INTERP_NEAREST:
     176            property->SetInterpolationTypeToNearest();
     177            break;
     178        case INTERP_LINEAR:
     179            property->SetInterpolationTypeToLinear();
     180            break;
     181        case INTERP_CUBIC:
     182            property->SetInterpolationTypeToCubic();
     183            break;
     184        }
     185    }
     186
    159187private:
    160188    virtual void update();
  • vtkvis/branches/1.7/Makefile.in

    r4601 r4604  
    66USE_OFFSCREEN_RENDERING = #yes
    77USE_THREADS             = yes
     8USE_CPU_LEGEND_RENDER   = yes
    89NEW_SCALAR_BAR          = yes
    910
     
    124125ifdef USE_THREADS
    125126DEFINES         += -DUSE_THREADS
     127endif
     128ifdef USE_CPU_LEGEND_RENDER
     129DEFINES         += -DLEGEND_SOFTWARE_RENDER
    126130endif
    127131ifdef NEW_SCALAR_BAR
  • vtkvis/branches/1.7/Renderer.cpp

    r3993 r4604  
    19191919    if (colorMap == NULL)
    19201920        return false;
    1921 
     1921#ifdef LEGEND_SOFTWARE_RENDER
     1922    ColorMap::renderColorMap(colorMap, width, height, imgData, opaque, _bgColor,
     1923#ifdef RENDER_TARGA
     1924                             true, TARGA_BYTES_PER_PIXEL
     1925#else
     1926                             false
     1927#endif
     1928                             );
     1929#else
    19221930    if (_legendRenderWindow == NULL) {
    19231931        _legendRenderWindow = vtkSmartPointer<vtkRenderWindow>::New();
     
    22122220                                      imgData);
    22132221#endif
     2222#endif
    22142223    TRACE("Leave");
    22152224    return true;
     
    22252234    if (colorMap == NULL)
    22262235        return false;
    2227 
     2236#ifdef LEGEND_SOFTWARE_RENDER
     2237    ColorMap::renderColorMap(colorMap, width, height, imgData, opaque, _bgColor,
     2238#ifdef RENDER_TARGA
     2239                             true, TARGA_BYTES_PER_PIXEL
     2240#else
     2241                             false
     2242#endif
     2243                             );
     2244#else
    22282245    if (_legendRenderWindow == NULL) {
    22292246        _legendRenderWindow = vtkSmartPointer<vtkRenderWindow>::New();
     
    23542371                                      !_legendRenderWindow->GetDoubleBuffer(),
    23552372                                      imgData);
     2373#endif
    23562374#endif
    23572375    TRACE("Leave");
     
    31553173        _cameraClipPlanes[1]->SetNormal(1, 0, 0);
    31563174        // top
    3157         _cameraClipPlanes[2]->SetOrigin(0, 0, _imgWorldOrigin[1] + _imgWorldDims[1]);
     3175        _cameraClipPlanes[2]->SetOrigin(0, 0, _imgWorldOrigin[1] + _imgWindowWorldDims[1]);
    31583176        _cameraClipPlanes[2]->SetNormal(0, 0, -1);
    31593177        // right
    3160         _cameraClipPlanes[3]->SetOrigin(_imgWorldOrigin[0] + _imgWorldDims[0], 0, 0);
     3178        _cameraClipPlanes[3]->SetOrigin(_imgWorldOrigin[0] + _imgWindowWorldDims[0], 0, 0);
    31613179        _cameraClipPlanes[3]->SetNormal(-1, 0, 0);
    31623180
  • vtkvis/branches/1.7/RendererCmd.cpp

    r4602 r4604  
    41234123
    41244124static CmdSpec cutplaneOps[] = {
    4125     {"add",          2, CutplaneAddOp, 2, 3, "oper value ?dataSetName?"},
     4125    {"add",          2, CutplaneAddOp, 2, 3, "?dataSetName?"},
    41264126    {"axis",         2, CutplaneSliceVisibilityOp, 4, 5, "axis bool ?dataSetName?"},
    41274127    {"ccolor",       2, CutplaneColorOp, 5, 6, "r g b ?dataSetName?"},
     
    70547054    if (objc == 4) {
    70557055        const char *name = Tcl_GetString(objv[3]);
    7056         g_renderer->setImageLevel(name, window);
    7057     } else {
    7058         g_renderer->setImageLevel("all", window);
     7056        g_renderer->setImageWindow(name, window);
     7057    } else {
     7058        g_renderer->setImageWindow("all", window);
    70597059    }
    70607060    return TCL_OK;
  • vtkvis/branches/1.7/RendererGraphicsObjs.cpp

    r3992 r4604  
    234234}
    235235
    236 /**
    237  * \brief Set the volume slice used for mapping volumetric data
    238  */
    239 template <>
    240 void Renderer::setGraphicsObjectVolumeSlice<HeightMap>(const DataSetId& id, Axis axis, double ratio)
    241 {
    242     HeightMapHashmap::iterator itr;
    243 
    244     bool doAll = false;
    245 
    246     if (id.compare("all") == 0) {
    247         itr = _heightMaps.begin();
    248         if (itr == _heightMaps.end())
    249             return;
    250         doAll = true;
    251     } else {
    252         itr = _heightMaps.find(id);
    253     }
    254 
    255     if (itr == _heightMaps.end()) {
    256         ERROR("HeightMap not found: %s", id.c_str());
    257         return;
    258     }
    259 
    260     do {
    261         itr->second->selectVolumeSlice(axis, ratio);
    262      } while (doAll && ++itr != _heightMaps.end());
    263 
    264     sceneBoundsChanged();
    265     _needsRedraw = true;
    266 }
    267 
    268236}
    269237
Note: See TracChangeset for help on using the changeset viewer.