Changeset 4073
- Timestamp:
- Dec 7, 2013, 12:34:21 AM (11 years ago)
- Location:
- trunk/packages/vizservers/vtkvis
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/vtkvis/ColorMap.cpp
r3982 r4073 488 488 return _elementDefault; 489 489 } 490 491 /** 492 * \brief Render (using CPU) color map to an image 493 */ 494 void 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 17 17 #include <vtkPiecewiseFunction.h> 18 18 #include <vtkLookupTable.h> 19 #include <vtkUnsignedCharArray.h> 19 20 20 21 namespace VtkVis { … … 115 116 static ColorMap *getElementDefault(); 116 117 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 117 124 private: 118 125 static ColorMap *_default; -
trunk/packages/vizservers/vtkvis/Makefile.in
r4060 r4073 6 6 USE_OFFSCREEN_RENDERING = #yes 7 7 USE_THREADS = yes 8 USE_CPU_LEGEND_RENDER = yes 8 9 NEW_SCALAR_BAR = #yes 9 10 … … 125 126 ifdef USE_THREADS 126 127 DEFINES += -DUSE_THREADS 128 endif 129 ifdef USE_CPU_LEGEND_RENDER 130 DEFINES += -DLEGEND_SOFTWARE_RENDER 127 131 endif 128 132 ifdef NEW_SCALAR_BAR -
trunk/packages/vizservers/vtkvis/Renderer.cpp
r3993 r4073 1919 1919 if (colorMap == NULL) 1920 1920 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 1922 1930 if (_legendRenderWindow == NULL) { 1923 1931 _legendRenderWindow = vtkSmartPointer<vtkRenderWindow>::New(); … … 2212 2220 imgData); 2213 2221 #endif 2222 #endif 2214 2223 TRACE("Leave"); 2215 2224 return true; … … 2225 2234 if (colorMap == NULL) 2226 2235 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 2228 2245 if (_legendRenderWindow == NULL) { 2229 2246 _legendRenderWindow = vtkSmartPointer<vtkRenderWindow>::New(); … … 2354 2371 !_legendRenderWindow->GetDoubleBuffer(), 2355 2372 imgData); 2373 #endif 2356 2374 #endif 2357 2375 TRACE("Leave");
Note: See TracChangeset
for help on using the changeset viewer.