Changeset 3223
- Timestamp:
- Dec 21, 2012, 4:03:32 PM (12 years ago)
- Location:
- branches/Rappture 1.2/packages/vizservers/vtkvis
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Rappture 1.2/packages/vizservers/vtkvis/RpContour3D.cpp
r3203 r3223 22 22 23 23 #include "RpContour3D.h" 24 #include "RpVtkRenderer.h" 24 25 #include "Trace.h" 25 26 … … 29 30 VtkGraphicsObject(), 30 31 _numContours(numContours), 31 _colorMap(NULL) 32 { 33 _color[0] = 0.0f; 34 _color[1] = 0.0f; 35 _color[2] = 1.0f; 32 _colorMap(NULL), 33 _colorMode(COLOR_CONSTANT), 34 _colorFieldType(DataSet::POINT_DATA), 35 _renderer(NULL) 36 { 37 _colorFieldRange[0] = DBL_MAX; 38 _colorFieldRange[1] = -DBL_MAX; 36 39 } 37 40 … … 40 43 _numContours(contours.size()), 41 44 _contours(contours), 42 _colorMap(NULL) 43 { 44 _color[0] = 0.0f; 45 _color[1] = 0.0f; 46 _color[2] = 1.0f; 45 _colorMap(NULL), 46 _colorMode(COLOR_CONSTANT), 47 _colorFieldType(DataSet::POINT_DATA), 48 _renderer(NULL) 49 { 50 _colorFieldRange[0] = DBL_MAX; 51 _colorFieldRange[1] = -DBL_MAX; 47 52 } 48 53 … … 57 62 } 58 63 59 /** 60 * \brief Called when the color map has been edited 61 */ 62 void Contour3D::updateColorMap() 63 { 64 setColorMap(_colorMap); 65 } 66 67 /** 68 * \brief Associate a colormap lookup table with the DataSet 69 */ 70 void Contour3D::setColorMap(ColorMap *cmap) 71 { 72 if (cmap == NULL) 73 return; 74 75 _colorMap = cmap; 76 77 if (_lut == NULL) { 78 _lut = vtkSmartPointer<vtkLookupTable>::New(); 79 if (_contourMapper != NULL) { 80 _contourMapper->UseLookupTableScalarRangeOn(); 81 _contourMapper->SetLookupTable(_lut); 82 } 83 } 84 85 _lut->DeepCopy(cmap->getLookupTable()); 86 _lut->SetRange(_dataRange); 64 void Contour3D::setDataSet(DataSet *dataSet, 65 Renderer *renderer) 66 { 67 if (_dataSet != dataSet) { 68 _dataSet = dataSet; 69 70 _renderer = renderer; 71 72 if (renderer->getUseCumulativeRange()) { 73 renderer->getCumulativeDataRange(_dataRange, 74 _dataSet->getActiveScalarsName(), 75 1); 76 renderer->getCumulativeDataRange(_vectorMagnitudeRange, 77 _dataSet->getActiveVectorsName(), 78 3); 79 for (int i = 0; i < 3; i++) { 80 renderer->getCumulativeDataRange(_vectorComponentRange[i], 81 _dataSet->getActiveVectorsName(), 82 3, i); 83 } 84 } else { 85 _dataSet->getScalarRange(_dataRange); 86 _dataSet->getVectorRange(_vectorMagnitudeRange); 87 for (int i = 0; i < 3; i++) { 88 _dataSet->getVectorRange(_vectorComponentRange[i], i); 89 } 90 } 91 92 update(); 93 } 87 94 } 88 95 … … 96 103 } 97 104 vtkDataSet *ds = _dataSet->getVtkDataSet(); 98 99 initProp();100 105 101 106 if (_dataSet->is2D()) { … … 181 186 } 182 187 } 183 if (_contourMapper == NULL) { 184 _contourMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); 185 _contourMapper->SetResolveCoincidentTopologyToPolygonOffset(); 186 _contourMapper->SetInputConnection(_contourFilter->GetOutputPort()); 187 _contourMapper->SetColorModeToMapScalars(); 188 getActor()->SetMapper(_contourMapper); 188 189 initProp(); 190 191 if (_dsMapper == NULL) { 192 _dsMapper = vtkSmartPointer<vtkPolyDataMapper>::New(); 193 _dsMapper->SetResolveCoincidentTopologyToPolygonOffset(); 194 _dsMapper->SetInputConnection(_contourFilter->GetOutputPort()); 195 _dsMapper->ScalarVisibilityOff(); 196 //_dsMapper->SetColorModeToMapScalars(); 197 getActor()->SetMapper(_dsMapper); 189 198 } 190 199 … … 193 202 } 194 203 195 _contourMapper->Update(); 204 setColorMode(_colorMode); 205 206 _dsMapper->Update(); 196 207 TRACE("Contour output %d polys, %d strips", 197 208 _contourFilter->GetOutput()->GetNumberOfPolys(), … … 201 212 void Contour3D::updateRanges(Renderer *renderer) 202 213 { 203 VtkGraphicsObject::updateRanges(renderer); 214 if (_dataSet == NULL) { 215 ERROR("called before setDataSet"); 216 return; 217 } 218 219 if (renderer->getUseCumulativeRange()) { 220 renderer->getCumulativeDataRange(_dataRange, 221 _dataSet->getActiveScalarsName(), 222 1); 223 renderer->getCumulativeDataRange(_vectorMagnitudeRange, 224 _dataSet->getActiveVectorsName(), 225 3); 226 for (int i = 0; i < 3; i++) { 227 renderer->getCumulativeDataRange(_vectorComponentRange[i], 228 _dataSet->getActiveVectorsName(), 229 3, i); 230 } 231 } else { 232 _dataSet->getScalarRange(_dataRange); 233 _dataSet->getVectorRange(_vectorMagnitudeRange); 234 for (int i = 0; i < 3; i++) { 235 _dataSet->getVectorRange(_vectorComponentRange[i], i); 236 } 237 } 238 239 // Need to update color map ranges 240 double *rangePtr = _colorFieldRange; 241 if (_colorFieldRange[0] > _colorFieldRange[1]) { 242 rangePtr = NULL; 243 } 244 setColorMode(_colorMode, _colorFieldType, _colorFieldName.c_str(), rangePtr); 245 246 if (_contours.empty() && _numContours > 0) { 247 // Contour isovalues need to be recomputed 248 update(); 249 } 250 } 251 252 253 void Contour3D::setColorMode(ColorMode mode) 254 { 255 _colorMode = mode; 256 if (_dataSet == NULL) 257 return; 258 259 switch (mode) { 260 case COLOR_BY_SCALAR: 261 setColorMode(mode, 262 _dataSet->getActiveScalarsType(), 263 _dataSet->getActiveScalarsName(), 264 _dataRange); 265 break; 266 case COLOR_BY_VECTOR_MAGNITUDE: 267 setColorMode(mode, 268 _dataSet->getActiveVectorsType(), 269 _dataSet->getActiveVectorsName(), 270 _vectorMagnitudeRange); 271 break; 272 case COLOR_BY_VECTOR_X: 273 setColorMode(mode, 274 _dataSet->getActiveVectorsType(), 275 _dataSet->getActiveVectorsName(), 276 _vectorComponentRange[0]); 277 break; 278 case COLOR_BY_VECTOR_Y: 279 setColorMode(mode, 280 _dataSet->getActiveVectorsType(), 281 _dataSet->getActiveVectorsName(), 282 _vectorComponentRange[1]); 283 break; 284 case COLOR_BY_VECTOR_Z: 285 setColorMode(mode, 286 _dataSet->getActiveVectorsType(), 287 _dataSet->getActiveVectorsName(), 288 _vectorComponentRange[2]); 289 break; 290 case COLOR_CONSTANT: 291 default: 292 setColorMode(mode, DataSet::POINT_DATA, NULL, NULL); 293 break; 294 } 295 } 296 297 void Contour3D::setColorMode(ColorMode mode, 298 const char *name, double range[2]) 299 { 300 if (_dataSet == NULL) 301 return; 302 DataSet::DataAttributeType type = DataSet::POINT_DATA; 303 int numComponents = 1; 304 if (name != NULL && strlen(name) > 0 && 305 !_dataSet->getFieldInfo(name, &type, &numComponents)) { 306 ERROR("Field not found: %s", name); 307 return; 308 } 309 setColorMode(mode, type, name, range); 310 } 311 312 void Contour3D::setColorMode(ColorMode mode, DataSet::DataAttributeType type, 313 const char *name, double range[2]) 314 { 315 _colorMode = mode; 316 _colorFieldType = type; 317 if (name == NULL) 318 _colorFieldName.clear(); 319 else 320 _colorFieldName = name; 321 if (range == NULL) { 322 _colorFieldRange[0] = DBL_MAX; 323 _colorFieldRange[1] = -DBL_MAX; 324 } else { 325 memcpy(_colorFieldRange, range, sizeof(double)*2); 326 } 327 328 if (_dataSet == NULL || _dsMapper == NULL) 329 return; 330 331 switch (type) { 332 case DataSet::POINT_DATA: 333 _dsMapper->SetScalarModeToUsePointFieldData(); 334 break; 335 case DataSet::CELL_DATA: 336 _dsMapper->SetScalarModeToUseCellFieldData(); 337 break; 338 default: 339 ERROR("Unsupported DataAttributeType: %d", type); 340 return; 341 } 342 343 if (name != NULL && strlen(name) > 0) { 344 _dsMapper->SelectColorArray(name); 345 } else { 346 _dsMapper->SetScalarModeToDefault(); 347 } 204 348 205 349 if (_lut != NULL) { 206 _lut->SetRange(_dataRange); 207 } 208 209 if (_contours.empty() && _numContours > 0) { 210 // Need to recompute isovalues 211 update(); 350 if (range != NULL) { 351 _lut->SetRange(range); 352 } else if (name != NULL && strlen(name) > 0) { 353 double r[2]; 354 int comp = -1; 355 if (mode == COLOR_BY_VECTOR_X) 356 comp = 0; 357 else if (mode == COLOR_BY_VECTOR_Y) 358 comp = 1; 359 else if (mode == COLOR_BY_VECTOR_Z) 360 comp = 2; 361 362 if (_renderer->getUseCumulativeRange()) { 363 int numComponents; 364 if (!_dataSet->getFieldInfo(name, type, &numComponents)) { 365 ERROR("Field not found: %s, type: %d", name, type); 366 return; 367 } else if (numComponents < comp+1) { 368 ERROR("Request for component %d in field with %d components", 369 comp, numComponents); 370 return; 371 } 372 _renderer->getCumulativeDataRange(r, name, type, numComponents, comp); 373 } else { 374 _dataSet->getDataRange(r, name, type, comp); 375 } 376 _lut->SetRange(r); 377 } 378 } 379 380 switch (mode) { 381 case COLOR_BY_SCALAR: 382 _dsMapper->ScalarVisibilityOn(); 383 break; 384 case COLOR_BY_VECTOR_MAGNITUDE: 385 _dsMapper->ScalarVisibilityOn(); 386 if (_lut != NULL) { 387 _lut->SetVectorModeToMagnitude(); 388 } 389 break; 390 case COLOR_BY_VECTOR_X: 391 _dsMapper->ScalarVisibilityOn(); 392 if (_lut != NULL) { 393 _lut->SetVectorModeToComponent(); 394 _lut->SetVectorComponent(0); 395 } 396 break; 397 case COLOR_BY_VECTOR_Y: 398 _dsMapper->ScalarVisibilityOn(); 399 if (_lut != NULL) { 400 _lut->SetVectorModeToComponent(); 401 _lut->SetVectorComponent(1); 402 } 403 break; 404 case COLOR_BY_VECTOR_Z: 405 _dsMapper->ScalarVisibilityOn(); 406 if (_lut != NULL) { 407 _lut->SetVectorModeToComponent(); 408 _lut->SetVectorComponent(2); 409 } 410 break; 411 case COLOR_CONSTANT: 412 default: 413 _dsMapper->ScalarVisibilityOff(); 414 break; 415 } 416 } 417 418 /** 419 * \brief Called when the color map has been edited 420 */ 421 void Contour3D::updateColorMap() 422 { 423 setColorMap(_colorMap); 424 } 425 426 /** 427 * \brief Associate a colormap lookup table with the DataSet 428 */ 429 void Contour3D::setColorMap(ColorMap *cmap) 430 { 431 if (cmap == NULL) 432 return; 433 434 _colorMap = cmap; 435 436 if (_lut == NULL) { 437 _lut = vtkSmartPointer<vtkLookupTable>::New(); 438 if (_dsMapper != NULL) { 439 _dsMapper->UseLookupTableScalarRangeOn(); 440 _dsMapper->SetLookupTable(_lut); 441 } 442 _lut->DeepCopy(cmap->getLookupTable()); 443 switch (_colorMode) { 444 case COLOR_CONSTANT: 445 case COLOR_BY_SCALAR: 446 _lut->SetRange(_dataRange); 447 break; 448 case COLOR_BY_VECTOR_MAGNITUDE: 449 _lut->SetRange(_vectorMagnitudeRange); 450 break; 451 case COLOR_BY_VECTOR_X: 452 _lut->SetRange(_vectorComponentRange[0]); 453 break; 454 case COLOR_BY_VECTOR_Y: 455 _lut->SetRange(_vectorComponentRange[1]); 456 break; 457 case COLOR_BY_VECTOR_Z: 458 _lut->SetRange(_vectorComponentRange[2]); 459 break; 460 default: 461 break; 462 } 463 } else { 464 double range[2]; 465 _lut->GetTableRange(range); 466 _lut->DeepCopy(cmap->getLookupTable()); 467 _lut->SetRange(range); 468 } 469 470 switch (_colorMode) { 471 case COLOR_BY_VECTOR_MAGNITUDE: 472 _lut->SetVectorModeToMagnitude(); 473 break; 474 case COLOR_BY_VECTOR_X: 475 _lut->SetVectorModeToComponent(); 476 _lut->SetVectorComponent(0); 477 break; 478 case COLOR_BY_VECTOR_Y: 479 _lut->SetVectorModeToComponent(); 480 _lut->SetVectorComponent(1); 481 break; 482 case COLOR_BY_VECTOR_Z: 483 _lut->SetVectorModeToComponent(); 484 _lut->SetVectorComponent(2); 485 break; 486 default: 487 break; 212 488 } 213 489 } … … 263 539 void Contour3D::setClippingPlanes(vtkPlaneCollection *planes) 264 540 { 265 if (_ contourMapper != NULL) {266 _ contourMapper->SetClippingPlanes(planes);267 } 268 } 541 if (_dsMapper != NULL) { 542 _dsMapper->SetClippingPlanes(planes); 543 } 544 } -
branches/Rappture 1.2/packages/vizservers/vtkvis/RpContour3D.h
r3177 r3223 29 29 class Contour3D : public VtkGraphicsObject { 30 30 public: 31 enum ColorMode { 32 COLOR_BY_SCALAR, 33 COLOR_BY_VECTOR_MAGNITUDE, 34 COLOR_BY_VECTOR_X, 35 COLOR_BY_VECTOR_Y, 36 COLOR_BY_VECTOR_Z, 37 COLOR_CONSTANT 38 }; 39 31 40 Contour3D(int numContours); 32 41 … … 40 49 } 41 50 51 virtual void setDataSet(DataSet *dataSet, 52 Renderer *renderer); 53 42 54 virtual void setClippingPlanes(vtkPlaneCollection *planes); 43 55 … … 49 61 50 62 const std::vector<double>& getContourList() const; 63 64 void setColorMode(ColorMode mode, DataSet::DataAttributeType type, 65 const char *name, double range[2] = NULL); 66 67 void setColorMode(ColorMode mode, 68 const char *name, double range[2] = NULL); 69 70 void setColorMode(ColorMode mode); 51 71 52 72 void setColorMap(ColorMap *colorMap); … … 71 91 int _numContours; 72 92 std::vector<double> _contours; 93 73 94 ColorMap *_colorMap; 95 ColorMode _colorMode; 96 std::string _colorFieldName; 97 DataSet::DataAttributeType _colorFieldType; 98 double _colorFieldRange[2]; 99 double _vectorMagnitudeRange[2]; 100 double _vectorComponentRange[3][2]; 101 Renderer *_renderer; 74 102 103 vtkSmartPointer<vtkLookupTable> _lut; 75 104 vtkSmartPointer<vtkContourFilter> _contourFilter; 76 vtkSmartPointer<vtkLookupTable> _lut; 77 vtkSmartPointer<vtkPolyDataMapper> _contourMapper; 105 vtkSmartPointer<vtkPolyDataMapper> _dsMapper; 78 106 }; 79 107 -
branches/Rappture 1.2/packages/vizservers/vtkvis/RpVtkRenderer.h
r3222 r3223 474 474 void setContour3DContourList(const DataSetId& id, const std::vector<double>& contours); 475 475 476 void setContour3DColorMode(const DataSetId& id, 477 Contour3D::ColorMode mode, 478 const char *name, double range[2] = NULL); 479 480 void setContour3DColorMode(const DataSetId& id, 481 Contour3D::ColorMode mode, 482 DataSet::DataAttributeType type, 483 const char *name, double range[2] = NULL); 484 476 485 // Cutplanes 477 486 -
branches/Rappture 1.2/packages/vizservers/vtkvis/RpVtkRendererCmd.cpp
r3222 r3223 2438 2438 2439 2439 static int 2440 Contour3DColorModeOp(ClientData clientData, Tcl_Interp *interp, int objc, 2441 Tcl_Obj *const *objv) 2442 { 2443 Contour3D::ColorMode mode; 2444 const char *str = Tcl_GetString(objv[2]); 2445 if (str[0] == 'c' && strcmp(str, "ccolor") == 0) { 2446 mode = Contour3D::COLOR_CONSTANT; 2447 } else if (str[0] == 's' && strcmp(str, "scalar") == 0) { 2448 mode = Contour3D::COLOR_BY_SCALAR; 2449 } else if (str[0] == 'v' && strcmp(str, "vmag") == 0) { 2450 mode = Contour3D::COLOR_BY_VECTOR_MAGNITUDE; 2451 } else if (str[0] == 'v' && strcmp(str, "vx") == 0) { 2452 mode = Contour3D::COLOR_BY_VECTOR_X; 2453 } else if (str[0] == 'v' && strcmp(str, "vy") == 0) { 2454 mode = Contour3D::COLOR_BY_VECTOR_Y; 2455 } else if (str[0] == 'v' && strcmp(str, "vz") == 0) { 2456 mode = Contour3D::COLOR_BY_VECTOR_Z; 2457 } else { 2458 Tcl_AppendResult(interp, "bad color mode option \"", str, 2459 "\": should be one of: 'scalar', 'vmag', 'vx', 'vy', 'vz', 'ccolor'", (char*)NULL); 2460 return TCL_ERROR; 2461 } 2462 const char *fieldName = Tcl_GetString(objv[3]); 2463 if (mode == Contour3D::COLOR_CONSTANT) { 2464 fieldName = NULL; 2465 } 2466 if (objc == 5) { 2467 const char *name = Tcl_GetString(objv[4]); 2468 g_renderer->setContour3DColorMode(name, mode, fieldName); 2469 } else { 2470 g_renderer->setContour3DColorMode("all", mode, fieldName); 2471 } 2472 return TCL_OK; 2473 } 2474 2475 static int 2440 2476 Contour3DDeleteOp(ClientData clientData, Tcl_Interp *interp, int objc, 2441 2477 Tcl_Obj *const *objv) … … 2632 2668 {"add", 1, Contour3DAddOp, 4, 5, "oper value ?dataSetName?"}, 2633 2669 {"ccolor", 2, Contour3DColorOp, 5, 6, "r g b ?dataSetName?"}, 2634 {"colormap", 2, Contour3DColorMapOp, 3, 4, "colorMapName ?dataSetName?"}, 2670 {"colormap", 7, Contour3DColorMapOp, 3, 4, "colorMapName ?dataSetName?"}, 2671 {"colormode", 7, Contour3DColorModeOp, 4, 5, "mode fieldName ?dataSetName?"}, 2635 2672 {"delete", 1, Contour3DDeleteOp, 2, 3, "?dataSetName?"}, 2636 2673 {"edges", 1, Contour3DEdgeVisibilityOp, 3, 4, "bool ?dataSetName?"}, -
branches/Rappture 1.2/packages/vizservers/vtkvis/RpVtkRendererGraphicsObjs.cpp
r3222 r3223 600 600 } 601 601 602 603 602 /** 604 603 * \brief Set the color mode for the specified DataSet … … 810 809 initCamera(); 811 810 _needsRedraw = true; 811 } 812 813 /** 814 * \brief Set the color mode for the specified DataSet 815 */ 816 void Renderer::setContour3DColorMode(const DataSetId& id, 817 Contour3D::ColorMode mode, 818 DataSet::DataAttributeType type, 819 const char *name, double range[2]) 820 { 821 Contour3DHashmap::iterator itr; 822 823 bool doAll = false; 824 825 if (id.compare("all") == 0) { 826 itr = _contour3Ds.begin(); 827 doAll = true; 828 } else { 829 itr = _contour3Ds.find(id); 830 } 831 if (itr == _contour3Ds.end()) { 832 ERROR("Contour3D not found: %s", id.c_str()); 833 return; 834 } 835 836 do { 837 itr->second->setColorMode(mode, type, name, range); 838 } while (doAll && ++itr != _contour3Ds.end()); 839 840 _needsRedraw = true; 841 } 842 843 /** 844 * \brief Set the color mode for the specified DataSet 845 */ 846 void Renderer::setContour3DColorMode(const DataSetId& id, 847 Contour3D::ColorMode mode, 848 const char *name, double range[2]) 849 { 850 Contour3DHashmap::iterator itr; 851 852 bool doAll = false; 853 854 if (id.compare("all") == 0) { 855 itr = _contour3Ds.begin(); 856 doAll = true; 857 } else { 858 itr = _contour3Ds.find(id); 859 } 860 if (itr == _contour3Ds.end()) { 861 ERROR("Contour3D not found: %s", id.c_str()); 862 return; 863 } 864 865 do { 866 itr->second->setColorMode(mode, name, range); 867 } while (doAll && ++itr != _contour3Ds.end()); 868 869 _needsRedraw = true; 812 870 } 813 871 -
branches/Rappture 1.2/packages/vizservers/vtkvis/protocol.txt
r3222 r3223 259 259 contour3d ccolor r g b <?datasetName?> 260 260 contour3d colormap <colorMapName> <?dataSetName?> 261 contour3d colormode <scalar|vmag|vx|vy|vz|ccolor> <fieldName> <?datasetName?> 262 Set the field used to color the object. 'ccolor' means to use 263 the constant color defined by the ccolor subcommand. 'scalar' uses 264 the active scalar field. 'vmag' uses the magnitude of the current 265 vector field, and 'vx','vy','vz' use the corresponding component of 266 the active vector field. 261 267 contour3d delete <?datasetName?> 262 268 contour3d edges <bool> <?datasetName?>
Note: See TracChangeset
for help on using the changeset viewer.