Ignore:
Timestamp:
Dec 7, 2013 12:34:21 AM (10 years ago)
Author:
ldelgass
Message:

Add software rendering of legends, enabled by default. Should work with vtk
6.0 release and up (i.e. work around the bug with the scalar bar actor rendering
with newer VTK).

Location:
trunk/packages/vizservers/vtkvis
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/vtkvis/ColorMap.cpp

    r3982 r4073  
    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}
  • trunk/packages/vizservers/vtkvis/ColorMap.h

    r3982 r4073  
    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;
  • trunk/packages/vizservers/vtkvis/Makefile.in

    r4060 r4073  
    66USE_OFFSCREEN_RENDERING = #yes
    77USE_THREADS             = yes
     8USE_CPU_LEGEND_RENDER   = yes
    89NEW_SCALAR_BAR          = #yes
    910
     
    125126ifdef USE_THREADS
    126127DEFINES         += -DUSE_THREADS
     128endif
     129ifdef USE_CPU_LEGEND_RENDER
     130DEFINES         += -DLEGEND_SOFTWARE_RENDER
    127131endif
    128132ifdef NEW_SCALAR_BAR
  • trunk/packages/vizservers/vtkvis/Renderer.cpp

    r3993 r4073  
    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");
Note: See TracChangeset for help on using the changeset viewer.