- Timestamp:
- Aug 2, 2014, 12:29:05 AM (10 years ago)
- Location:
- vtkvis/branches/1.7
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
vtkvis/branches/1.7
- Property svn:mergeinfo changed
/trunk/packages/vizservers/vtkvis merged: 4073-4074,4077-4081
- Property svn:mergeinfo changed
-
vtkvis/branches/1.7/ColorMap.cpp
r3982 r4604 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 } -
vtkvis/branches/1.7/ColorMap.h
r3982 r4604 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; -
vtkvis/branches/1.7/Image.cpp
r3991 r4604 148 148 } 149 149 150 void 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 150 278 void Image::setClippingPlanes(vtkPlaneCollection *planes) 151 279 { -
vtkvis/branches/1.7/Image.h
r3991 r4604 32 32 { 33 33 public: 34 enum InterpType { 35 INTERP_NEAREST, 36 INTERP_LINEAR, 37 INTERP_CUBIC 38 }; 39 34 40 Image(); 35 41 virtual ~Image(); … … 45 51 46 52 virtual void setClippingPlanes(vtkPlaneCollection *planes); 53 54 virtual void setAspect(double aspect); 47 55 48 56 void updateColorMap() … … 84 92 } 85 93 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 86 103 double getWindow() 87 104 { … … 100 117 101 118 property->SetColorWindow(window); 119 property->UseLookupTableScalarRangeOff(); 102 120 } 103 121 … … 118 136 119 137 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(); 130 139 } 131 140 … … 157 166 } 158 167 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 159 187 private: 160 188 virtual void update(); -
vtkvis/branches/1.7/Makefile.in
r4601 r4604 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 … … 124 125 ifdef USE_THREADS 125 126 DEFINES += -DUSE_THREADS 127 endif 128 ifdef USE_CPU_LEGEND_RENDER 129 DEFINES += -DLEGEND_SOFTWARE_RENDER 126 130 endif 127 131 ifdef NEW_SCALAR_BAR -
vtkvis/branches/1.7/Renderer.cpp
r3993 r4604 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"); … … 3155 3173 _cameraClipPlanes[1]->SetNormal(1, 0, 0); 3156 3174 // top 3157 _cameraClipPlanes[2]->SetOrigin(0, 0, _imgWorldOrigin[1] + _imgW orldDims[1]);3175 _cameraClipPlanes[2]->SetOrigin(0, 0, _imgWorldOrigin[1] + _imgWindowWorldDims[1]); 3158 3176 _cameraClipPlanes[2]->SetNormal(0, 0, -1); 3159 3177 // right 3160 _cameraClipPlanes[3]->SetOrigin(_imgWorldOrigin[0] + _imgW orldDims[0], 0, 0);3178 _cameraClipPlanes[3]->SetOrigin(_imgWorldOrigin[0] + _imgWindowWorldDims[0], 0, 0); 3161 3179 _cameraClipPlanes[3]->SetNormal(-1, 0, 0); 3162 3180 -
vtkvis/branches/1.7/RendererCmd.cpp
r4602 r4604 4123 4123 4124 4124 static CmdSpec cutplaneOps[] = { 4125 {"add", 2, CutplaneAddOp, 2, 3, " oper value?dataSetName?"},4125 {"add", 2, CutplaneAddOp, 2, 3, "?dataSetName?"}, 4126 4126 {"axis", 2, CutplaneSliceVisibilityOp, 4, 5, "axis bool ?dataSetName?"}, 4127 4127 {"ccolor", 2, CutplaneColorOp, 5, 6, "r g b ?dataSetName?"}, … … 7054 7054 if (objc == 4) { 7055 7055 const char *name = Tcl_GetString(objv[3]); 7056 g_renderer->setImage Level(name, window);7057 } else { 7058 g_renderer->setImage Level("all", window);7056 g_renderer->setImageWindow(name, window); 7057 } else { 7058 g_renderer->setImageWindow("all", window); 7059 7059 } 7060 7060 return TCL_OK; -
vtkvis/branches/1.7/RendererGraphicsObjs.cpp
r3992 r4604 234 234 } 235 235 236 /**237 * \brief Set the volume slice used for mapping volumetric data238 */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 268 236 } 269 237
Note: See TracChangeset
for help on using the changeset viewer.