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:
2 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}
Note: See TracChangeset for help on using the changeset viewer.