[3124] | 1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
| 2 | /* |
---|
[3177] | 3 | * Copyright (C) 2004-2012 HUBzero Foundation, LLC |
---|
[3124] | 4 | * |
---|
| 5 | * Author: Leif Delgass <ldelgass@purdue.edu> |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include <cassert> |
---|
| 9 | #include <cfloat> |
---|
| 10 | #include <cstring> |
---|
| 11 | |
---|
| 12 | #include <vtkDataSet.h> |
---|
| 13 | #include <vtkPointData.h> |
---|
| 14 | #include <vtkCellData.h> |
---|
| 15 | #include <vtkCellDataToPointData.h> |
---|
[3680] | 16 | #include <vtkPolyDataMapper.h> |
---|
[3124] | 17 | #include <vtkUnstructuredGrid.h> |
---|
| 18 | #include <vtkProperty.h> |
---|
| 19 | #include <vtkImageData.h> |
---|
| 20 | #include <vtkLookupTable.h> |
---|
| 21 | #include <vtkTransform.h> |
---|
| 22 | #include <vtkDelaunay2D.h> |
---|
| 23 | #include <vtkDelaunay3D.h> |
---|
| 24 | #include <vtkGaussianSplatter.h> |
---|
| 25 | #include <vtkExtractVOI.h> |
---|
| 26 | #include <vtkDataSetSurfaceFilter.h> |
---|
[3680] | 27 | #include <vtkVertexGlyphFilter.h> |
---|
[3124] | 28 | |
---|
[3616] | 29 | #include "Warp.h" |
---|
[3621] | 30 | #include "Renderer.h" |
---|
[3124] | 31 | #include "Trace.h" |
---|
| 32 | |
---|
[3615] | 33 | using namespace VtkVis; |
---|
[3124] | 34 | |
---|
| 35 | Warp::Warp() : |
---|
[3621] | 36 | GraphicsObject(), |
---|
[3124] | 37 | _warpScale(1.0), |
---|
[3680] | 38 | _cloudStyle(CLOUD_MESH), |
---|
[3124] | 39 | _colorMap(NULL), |
---|
| 40 | _colorMode(COLOR_BY_SCALAR), |
---|
| 41 | _colorFieldType(DataSet::POINT_DATA), |
---|
| 42 | _renderer(NULL) |
---|
| 43 | { |
---|
| 44 | _colorFieldRange[0] = DBL_MAX; |
---|
| 45 | _colorFieldRange[1] = -DBL_MAX; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | Warp::~Warp() |
---|
| 49 | { |
---|
| 50 | #ifdef WANT_TRACE |
---|
| 51 | if (_dataSet != NULL) |
---|
| 52 | TRACE("Deleting Warp for %s", _dataSet->getName().c_str()); |
---|
| 53 | else |
---|
| 54 | TRACE("Deleting Warp with NULL DataSet"); |
---|
| 55 | #endif |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | void Warp::setDataSet(DataSet *dataSet, |
---|
[3189] | 59 | Renderer *renderer) |
---|
[3124] | 60 | { |
---|
| 61 | if (_dataSet != dataSet) { |
---|
| 62 | _dataSet = dataSet; |
---|
| 63 | |
---|
| 64 | _renderer = renderer; |
---|
| 65 | |
---|
| 66 | if (renderer->getUseCumulativeRange()) { |
---|
| 67 | renderer->getCumulativeDataRange(_dataRange, |
---|
| 68 | _dataSet->getActiveScalarsName(), |
---|
| 69 | 1); |
---|
| 70 | renderer->getCumulativeDataRange(_vectorMagnitudeRange, |
---|
| 71 | _dataSet->getActiveVectorsName(), |
---|
| 72 | 3); |
---|
| 73 | for (int i = 0; i < 3; i++) { |
---|
| 74 | renderer->getCumulativeDataRange(_vectorComponentRange[i], |
---|
| 75 | _dataSet->getActiveVectorsName(), |
---|
| 76 | 3, i); |
---|
| 77 | } |
---|
| 78 | } else { |
---|
| 79 | _dataSet->getScalarRange(_dataRange); |
---|
| 80 | _dataSet->getVectorRange(_vectorMagnitudeRange); |
---|
| 81 | for (int i = 0; i < 3; i++) { |
---|
| 82 | _dataSet->getVectorRange(_vectorComponentRange[i], i); |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | update(); |
---|
| 87 | } |
---|
| 88 | } |
---|
| 89 | |
---|
| 90 | /** |
---|
| 91 | * \brief Internal method to set up pipeline after a state change |
---|
| 92 | */ |
---|
| 93 | void Warp::update() |
---|
| 94 | { |
---|
| 95 | if (_dataSet == NULL) |
---|
| 96 | return; |
---|
| 97 | |
---|
| 98 | vtkDataSet *ds = _dataSet->getVtkDataSet(); |
---|
| 99 | |
---|
| 100 | if (_warp == NULL) { |
---|
[3189] | 101 | _warp = vtkSmartPointer<vtkWarpVector>::New(); |
---|
[3124] | 102 | } |
---|
| 103 | |
---|
| 104 | // Mapper, actor to render color-mapped data set |
---|
[3680] | 105 | if (_mapper == NULL) { |
---|
| 106 | _mapper = vtkSmartPointer<vtkPolyDataMapper>::New(); |
---|
[3124] | 107 | // Map scalars through lookup table regardless of type |
---|
[3680] | 108 | _mapper->SetColorModeToMapScalars(); |
---|
[3124] | 109 | } |
---|
| 110 | |
---|
[5824] | 111 | vtkAlgorithmOutput *dsOutput = NULL; |
---|
[3124] | 112 | vtkSmartPointer<vtkCellDataToPointData> cellToPtData; |
---|
| 113 | if (ds->GetPointData() == NULL || |
---|
[3189] | 114 | ds->GetPointData()->GetVectors() == NULL) { |
---|
| 115 | TRACE("No vector point data in dataset %s", _dataSet->getName().c_str()); |
---|
| 116 | if (ds->GetCellData() != NULL && |
---|
| 117 | ds->GetCellData()->GetVectors() != NULL) { |
---|
| 118 | cellToPtData = |
---|
| 119 | vtkSmartPointer<vtkCellDataToPointData>::New(); |
---|
| 120 | cellToPtData->SetInputData(ds); |
---|
[5753] | 121 | cellToPtData->PassCellDataOn(); |
---|
[5824] | 122 | dsOutput = cellToPtData->GetOutputPort(); |
---|
[3189] | 123 | } else { |
---|
[3525] | 124 | USER_ERROR("No vector field was found in the data set"); |
---|
[3189] | 125 | return; |
---|
| 126 | } |
---|
[5824] | 127 | } else { |
---|
[6162] | 128 | dsOutput = _dataSet->getProducerPort(); |
---|
[3124] | 129 | } |
---|
| 130 | |
---|
[3680] | 131 | if (_dataSet->isCloud()) { |
---|
| 132 | // DataSet is a point cloud |
---|
| 133 | if (_cloudStyle == CLOUD_POINTS) { |
---|
| 134 | vtkSmartPointer<vtkVertexGlyphFilter> vgf = vtkSmartPointer<vtkVertexGlyphFilter>::New(); |
---|
[5824] | 135 | vgf->SetInputConnection(dsOutput); |
---|
[3680] | 136 | vtkAlgorithmOutput *warpOutput = initWarp(vgf->GetOutputPort()); |
---|
| 137 | _mapper->SetInputConnection(warpOutput); |
---|
| 138 | } else { |
---|
[3124] | 139 | PrincipalPlane plane; |
---|
| 140 | double offset; |
---|
| 141 | if (_dataSet->is2D(&plane, &offset)) { |
---|
[3680] | 142 | //_cloudStyle == CLOUD_MESH |
---|
[3124] | 143 | vtkSmartPointer<vtkDelaunay2D> mesher = vtkSmartPointer<vtkDelaunay2D>::New(); |
---|
| 144 | if (plane == PLANE_ZY) { |
---|
| 145 | vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New(); |
---|
| 146 | trans->RotateWXYZ(90, 0, 1, 0); |
---|
| 147 | if (offset != 0.0) { |
---|
| 148 | trans->Translate(-offset, 0, 0); |
---|
| 149 | } |
---|
| 150 | mesher->SetTransform(trans); |
---|
| 151 | } else if (plane == PLANE_XZ) { |
---|
| 152 | vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New(); |
---|
| 153 | trans->RotateWXYZ(-90, 1, 0, 0); |
---|
| 154 | if (offset != 0.0) { |
---|
| 155 | trans->Translate(0, -offset, 0); |
---|
| 156 | } |
---|
| 157 | mesher->SetTransform(trans); |
---|
| 158 | } else if (offset != 0.0) { |
---|
| 159 | // XY with Z offset |
---|
| 160 | vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New(); |
---|
| 161 | trans->Translate(0, 0, -offset); |
---|
| 162 | mesher->SetTransform(trans); |
---|
| 163 | } |
---|
[5824] | 164 | mesher->SetInputConnection(dsOutput); |
---|
[3189] | 165 | vtkAlgorithmOutput *warpOutput = initWarp(mesher->GetOutputPort()); |
---|
[3680] | 166 | _mapper->SetInputConnection(warpOutput); |
---|
[3124] | 167 | } else { |
---|
[3680] | 168 | // Data Set is a 3D point cloud and _cloudStyle == CLOUD_MESH |
---|
[3124] | 169 | vtkSmartPointer<vtkDelaunay3D> mesher = vtkSmartPointer<vtkDelaunay3D>::New(); |
---|
[5824] | 170 | mesher->SetInputConnection(dsOutput); |
---|
[3124] | 171 | vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New(); |
---|
[3189] | 172 | gf->SetInputConnection(mesher->GetOutputPort()); |
---|
| 173 | vtkAlgorithmOutput *warpOutput = initWarp(gf->GetOutputPort()); |
---|
[3680] | 174 | _mapper->SetInputConnection(warpOutput); |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | } else if (vtkPolyData::SafeDownCast(ds) != NULL) { |
---|
| 178 | // DataSet is a vtkPolyData with lines and/or polygons |
---|
[5827] | 179 | vtkAlgorithmOutput *warpOutput = initWarp(dsOutput); |
---|
| 180 | _mapper->SetInputConnection(warpOutput); |
---|
[3124] | 181 | } else { |
---|
| 182 | TRACE("Generating surface for data set"); |
---|
| 183 | // DataSet is NOT a vtkPolyData |
---|
| 184 | vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New(); |
---|
[5824] | 185 | gf->SetInputConnection(dsOutput); |
---|
[3189] | 186 | vtkAlgorithmOutput *warpOutput = initWarp(gf->GetOutputPort()); |
---|
[3680] | 187 | _mapper->SetInputConnection(warpOutput); |
---|
[3124] | 188 | } |
---|
| 189 | |
---|
[3542] | 190 | setInterpolateBeforeMapping(true); |
---|
| 191 | |
---|
[3124] | 192 | if (_lut == NULL) { |
---|
| 193 | setColorMap(ColorMap::getDefault()); |
---|
| 194 | } |
---|
| 195 | |
---|
[5824] | 196 | if (_dataSet->getActiveScalarsName() != NULL) { |
---|
| 197 | TRACE("Setting color mode to scalar"); |
---|
| 198 | setColorMode(COLOR_BY_SCALAR); |
---|
| 199 | } else { |
---|
[3680] | 200 | TRACE("Setting color mode to vector magnitude"); |
---|
| 201 | setColorMode(COLOR_BY_VECTOR_MAGNITUDE); |
---|
| 202 | } |
---|
[3124] | 203 | |
---|
| 204 | initProp(); |
---|
[3680] | 205 | getActor()->SetMapper(_mapper); |
---|
| 206 | _mapper->Update(); |
---|
[3124] | 207 | } |
---|
| 208 | |
---|
[3680] | 209 | void Warp::setCloudStyle(CloudStyle style) |
---|
| 210 | { |
---|
| 211 | if (style != _cloudStyle) { |
---|
| 212 | _cloudStyle = style; |
---|
| 213 | if (_dataSet != NULL) { |
---|
| 214 | update(); |
---|
| 215 | } |
---|
| 216 | } |
---|
| 217 | } |
---|
| 218 | |
---|
[3542] | 219 | void Warp::setInterpolateBeforeMapping(bool state) |
---|
| 220 | { |
---|
[3680] | 221 | if (_mapper != NULL) { |
---|
| 222 | _mapper->SetInterpolateScalarsBeforeMapping((state ? 1 : 0)); |
---|
[3542] | 223 | } |
---|
| 224 | } |
---|
| 225 | |
---|
[3124] | 226 | vtkAlgorithmOutput *Warp::initWarp(vtkAlgorithmOutput *input) |
---|
| 227 | { |
---|
| 228 | TRACE("Warp scale: %g", _warpScale); |
---|
| 229 | if (_warpScale == 0.0) { |
---|
| 230 | _warp = NULL; |
---|
| 231 | return input; |
---|
| 232 | } else if (input == NULL) { |
---|
| 233 | ERROR("NULL input"); |
---|
| 234 | return input; |
---|
| 235 | } else { |
---|
| 236 | if (_warp == NULL) |
---|
| 237 | _warp = vtkSmartPointer<vtkWarpVector>::New(); |
---|
| 238 | _warp->SetScaleFactor(_warpScale); |
---|
| 239 | _warp->SetInputConnection(input); |
---|
| 240 | return _warp->GetOutputPort(); |
---|
| 241 | } |
---|
| 242 | } |
---|
| 243 | |
---|
| 244 | /** |
---|
| 245 | * \brief Controls relative scaling of deformation |
---|
| 246 | */ |
---|
| 247 | void Warp::setWarpScale(double scale) |
---|
| 248 | { |
---|
| 249 | if (_warpScale == scale) |
---|
| 250 | return; |
---|
| 251 | |
---|
| 252 | _warpScale = scale; |
---|
| 253 | if (_warp == NULL) { |
---|
[3680] | 254 | vtkAlgorithmOutput *warpOutput = initWarp(_mapper->GetInputConnection(0, 0)); |
---|
| 255 | _mapper->SetInputConnection(warpOutput); |
---|
[3124] | 256 | } else if (scale == 0.0) { |
---|
| 257 | vtkAlgorithmOutput *warpInput = _warp->GetInputConnection(0, 0); |
---|
[3680] | 258 | _mapper->SetInputConnection(warpInput); |
---|
[3124] | 259 | _warp = NULL; |
---|
| 260 | } else { |
---|
| 261 | _warp->SetScaleFactor(_warpScale); |
---|
| 262 | } |
---|
| 263 | |
---|
[3680] | 264 | if (_mapper != NULL) |
---|
| 265 | _mapper->Update(); |
---|
[3124] | 266 | } |
---|
| 267 | |
---|
| 268 | void Warp::updateRanges(Renderer *renderer) |
---|
| 269 | { |
---|
| 270 | if (_dataSet == NULL) { |
---|
| 271 | ERROR("called before setDataSet"); |
---|
| 272 | return; |
---|
| 273 | } |
---|
| 274 | |
---|
| 275 | if (renderer->getUseCumulativeRange()) { |
---|
| 276 | renderer->getCumulativeDataRange(_dataRange, |
---|
| 277 | _dataSet->getActiveScalarsName(), |
---|
| 278 | 1); |
---|
| 279 | renderer->getCumulativeDataRange(_vectorMagnitudeRange, |
---|
| 280 | _dataSet->getActiveVectorsName(), |
---|
| 281 | 3); |
---|
| 282 | for (int i = 0; i < 3; i++) { |
---|
| 283 | renderer->getCumulativeDataRange(_vectorComponentRange[i], |
---|
| 284 | _dataSet->getActiveVectorsName(), |
---|
| 285 | 3, i); |
---|
| 286 | } |
---|
| 287 | } else { |
---|
| 288 | _dataSet->getScalarRange(_dataRange); |
---|
| 289 | _dataSet->getVectorRange(_vectorMagnitudeRange); |
---|
| 290 | for (int i = 0; i < 3; i++) { |
---|
| 291 | _dataSet->getVectorRange(_vectorComponentRange[i], i); |
---|
| 292 | } |
---|
| 293 | } |
---|
| 294 | |
---|
| 295 | // Need to update color map ranges |
---|
| 296 | double *rangePtr = _colorFieldRange; |
---|
| 297 | if (_colorFieldRange[0] > _colorFieldRange[1]) { |
---|
| 298 | rangePtr = NULL; |
---|
| 299 | } |
---|
| 300 | setColorMode(_colorMode, _colorFieldType, _colorFieldName.c_str(), rangePtr); |
---|
| 301 | } |
---|
| 302 | |
---|
| 303 | void Warp::setColorMode(ColorMode mode) |
---|
| 304 | { |
---|
| 305 | _colorMode = mode; |
---|
| 306 | if (_dataSet == NULL) |
---|
| 307 | return; |
---|
| 308 | |
---|
| 309 | switch (mode) { |
---|
| 310 | case COLOR_BY_SCALAR: |
---|
| 311 | setColorMode(mode, |
---|
| 312 | _dataSet->getActiveScalarsType(), |
---|
[5073] | 313 | _dataSet->getActiveScalarsName()); |
---|
[3124] | 314 | break; |
---|
| 315 | case COLOR_BY_VECTOR_MAGNITUDE: |
---|
| 316 | setColorMode(mode, |
---|
| 317 | _dataSet->getActiveVectorsType(), |
---|
[5073] | 318 | _dataSet->getActiveVectorsName()); |
---|
[3124] | 319 | break; |
---|
| 320 | case COLOR_BY_VECTOR_X: |
---|
| 321 | setColorMode(mode, |
---|
| 322 | _dataSet->getActiveVectorsType(), |
---|
[5073] | 323 | _dataSet->getActiveVectorsName()); |
---|
[3124] | 324 | break; |
---|
| 325 | case COLOR_BY_VECTOR_Y: |
---|
| 326 | setColorMode(mode, |
---|
| 327 | _dataSet->getActiveVectorsType(), |
---|
[5073] | 328 | _dataSet->getActiveVectorsName()); |
---|
[3124] | 329 | break; |
---|
| 330 | case COLOR_BY_VECTOR_Z: |
---|
| 331 | setColorMode(mode, |
---|
| 332 | _dataSet->getActiveVectorsType(), |
---|
[5073] | 333 | _dataSet->getActiveVectorsName()); |
---|
[3124] | 334 | break; |
---|
| 335 | case COLOR_CONSTANT: |
---|
| 336 | default: |
---|
| 337 | setColorMode(mode, DataSet::POINT_DATA, NULL, NULL); |
---|
| 338 | break; |
---|
| 339 | } |
---|
| 340 | } |
---|
| 341 | |
---|
| 342 | void Warp::setColorMode(ColorMode mode, |
---|
[3189] | 343 | const char *name, double range[2]) |
---|
[3124] | 344 | { |
---|
| 345 | if (_dataSet == NULL) |
---|
| 346 | return; |
---|
| 347 | DataSet::DataAttributeType type = DataSet::POINT_DATA; |
---|
| 348 | int numComponents = 1; |
---|
| 349 | if (name != NULL && strlen(name) > 0 && |
---|
| 350 | !_dataSet->getFieldInfo(name, &type, &numComponents)) { |
---|
| 351 | ERROR("Field not found: %s", name); |
---|
| 352 | return; |
---|
| 353 | } |
---|
| 354 | setColorMode(mode, type, name, range); |
---|
| 355 | } |
---|
| 356 | |
---|
| 357 | void Warp::setColorMode(ColorMode mode, DataSet::DataAttributeType type, |
---|
[3189] | 358 | const char *name, double range[2]) |
---|
[3124] | 359 | { |
---|
| 360 | _colorMode = mode; |
---|
| 361 | _colorFieldType = type; |
---|
| 362 | if (name == NULL) |
---|
| 363 | _colorFieldName.clear(); |
---|
| 364 | else |
---|
| 365 | _colorFieldName = name; |
---|
| 366 | if (range == NULL) { |
---|
| 367 | _colorFieldRange[0] = DBL_MAX; |
---|
| 368 | _colorFieldRange[1] = -DBL_MAX; |
---|
| 369 | } else { |
---|
| 370 | memcpy(_colorFieldRange, range, sizeof(double)*2); |
---|
| 371 | } |
---|
| 372 | |
---|
[3680] | 373 | if (_dataSet == NULL || _mapper == NULL) |
---|
[3124] | 374 | return; |
---|
| 375 | |
---|
| 376 | switch (type) { |
---|
| 377 | case DataSet::POINT_DATA: |
---|
[3680] | 378 | _mapper->SetScalarModeToUsePointFieldData(); |
---|
[3124] | 379 | break; |
---|
| 380 | case DataSet::CELL_DATA: |
---|
[3680] | 381 | _mapper->SetScalarModeToUseCellFieldData(); |
---|
[3124] | 382 | break; |
---|
| 383 | default: |
---|
| 384 | ERROR("Unsupported DataAttributeType: %d", type); |
---|
| 385 | return; |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | if (name != NULL && strlen(name) > 0) { |
---|
[3680] | 389 | _mapper->SelectColorArray(name); |
---|
[3124] | 390 | } else { |
---|
[3680] | 391 | _mapper->SetScalarModeToDefault(); |
---|
[3124] | 392 | } |
---|
| 393 | |
---|
| 394 | if (_lut != NULL) { |
---|
| 395 | if (range != NULL) { |
---|
| 396 | _lut->SetRange(range); |
---|
| 397 | } else if (name != NULL && strlen(name) > 0) { |
---|
| 398 | double r[2]; |
---|
| 399 | int comp = -1; |
---|
| 400 | if (mode == COLOR_BY_VECTOR_X) |
---|
| 401 | comp = 0; |
---|
| 402 | else if (mode == COLOR_BY_VECTOR_Y) |
---|
| 403 | comp = 1; |
---|
| 404 | else if (mode == COLOR_BY_VECTOR_Z) |
---|
| 405 | comp = 2; |
---|
| 406 | |
---|
| 407 | if (_renderer->getUseCumulativeRange()) { |
---|
| 408 | int numComponents; |
---|
| 409 | if (!_dataSet->getFieldInfo(name, type, &numComponents)) { |
---|
| 410 | ERROR("Field not found: %s, type: %d", name, type); |
---|
| 411 | return; |
---|
| 412 | } else if (numComponents < comp+1) { |
---|
| 413 | ERROR("Request for component %d in field with %d components", |
---|
| 414 | comp, numComponents); |
---|
| 415 | return; |
---|
| 416 | } |
---|
| 417 | _renderer->getCumulativeDataRange(r, name, type, numComponents, comp); |
---|
| 418 | } else { |
---|
| 419 | _dataSet->getDataRange(r, name, type, comp); |
---|
| 420 | } |
---|
| 421 | _lut->SetRange(r); |
---|
| 422 | } |
---|
| 423 | } |
---|
| 424 | |
---|
| 425 | switch (mode) { |
---|
| 426 | case COLOR_BY_SCALAR: |
---|
[3680] | 427 | _mapper->ScalarVisibilityOn(); |
---|
[3124] | 428 | break; |
---|
| 429 | case COLOR_BY_VECTOR_MAGNITUDE: |
---|
[3680] | 430 | _mapper->ScalarVisibilityOn(); |
---|
[3124] | 431 | if (_lut != NULL) { |
---|
| 432 | _lut->SetVectorModeToMagnitude(); |
---|
| 433 | } |
---|
| 434 | break; |
---|
| 435 | case COLOR_BY_VECTOR_X: |
---|
[3680] | 436 | _mapper->ScalarVisibilityOn(); |
---|
[3124] | 437 | if (_lut != NULL) { |
---|
| 438 | _lut->SetVectorModeToComponent(); |
---|
| 439 | _lut->SetVectorComponent(0); |
---|
| 440 | } |
---|
| 441 | break; |
---|
| 442 | case COLOR_BY_VECTOR_Y: |
---|
[3680] | 443 | _mapper->ScalarVisibilityOn(); |
---|
[3124] | 444 | if (_lut != NULL) { |
---|
| 445 | _lut->SetVectorModeToComponent(); |
---|
| 446 | _lut->SetVectorComponent(1); |
---|
| 447 | } |
---|
| 448 | break; |
---|
| 449 | case COLOR_BY_VECTOR_Z: |
---|
[3680] | 450 | _mapper->ScalarVisibilityOn(); |
---|
[3124] | 451 | if (_lut != NULL) { |
---|
| 452 | _lut->SetVectorModeToComponent(); |
---|
| 453 | _lut->SetVectorComponent(2); |
---|
| 454 | } |
---|
| 455 | break; |
---|
| 456 | case COLOR_CONSTANT: |
---|
| 457 | default: |
---|
[3680] | 458 | _mapper->ScalarVisibilityOff(); |
---|
[3124] | 459 | break; |
---|
| 460 | } |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | /** |
---|
| 464 | * \brief Called when the color map has been edited |
---|
| 465 | */ |
---|
| 466 | void Warp::updateColorMap() |
---|
| 467 | { |
---|
| 468 | setColorMap(_colorMap); |
---|
| 469 | } |
---|
| 470 | |
---|
| 471 | /** |
---|
| 472 | * \brief Associate a colormap lookup table with the DataSet |
---|
| 473 | */ |
---|
| 474 | void Warp::setColorMap(ColorMap *cmap) |
---|
| 475 | { |
---|
| 476 | if (cmap == NULL) |
---|
| 477 | return; |
---|
| 478 | |
---|
| 479 | _colorMap = cmap; |
---|
| 480 | |
---|
| 481 | if (_lut == NULL) { |
---|
| 482 | _lut = vtkSmartPointer<vtkLookupTable>::New(); |
---|
[3680] | 483 | if (_mapper != NULL) { |
---|
| 484 | _mapper->UseLookupTableScalarRangeOn(); |
---|
| 485 | _mapper->SetLookupTable(_lut); |
---|
[3124] | 486 | } |
---|
| 487 | _lut->DeepCopy(cmap->getLookupTable()); |
---|
| 488 | switch (_colorMode) { |
---|
| 489 | case COLOR_CONSTANT: |
---|
| 490 | case COLOR_BY_SCALAR: |
---|
| 491 | _lut->SetRange(_dataRange); |
---|
| 492 | break; |
---|
| 493 | case COLOR_BY_VECTOR_MAGNITUDE: |
---|
| 494 | _lut->SetRange(_vectorMagnitudeRange); |
---|
| 495 | break; |
---|
| 496 | case COLOR_BY_VECTOR_X: |
---|
| 497 | _lut->SetRange(_vectorComponentRange[0]); |
---|
| 498 | break; |
---|
| 499 | case COLOR_BY_VECTOR_Y: |
---|
| 500 | _lut->SetRange(_vectorComponentRange[1]); |
---|
| 501 | break; |
---|
| 502 | case COLOR_BY_VECTOR_Z: |
---|
| 503 | _lut->SetRange(_vectorComponentRange[2]); |
---|
| 504 | break; |
---|
| 505 | default: |
---|
| 506 | break; |
---|
| 507 | } |
---|
| 508 | } else { |
---|
| 509 | double range[2]; |
---|
| 510 | _lut->GetTableRange(range); |
---|
| 511 | _lut->DeepCopy(cmap->getLookupTable()); |
---|
| 512 | _lut->SetRange(range); |
---|
[3330] | 513 | _lut->Modified(); |
---|
[3124] | 514 | } |
---|
| 515 | |
---|
| 516 | switch (_colorMode) { |
---|
| 517 | case COLOR_BY_VECTOR_MAGNITUDE: |
---|
| 518 | _lut->SetVectorModeToMagnitude(); |
---|
| 519 | break; |
---|
| 520 | case COLOR_BY_VECTOR_X: |
---|
| 521 | _lut->SetVectorModeToComponent(); |
---|
| 522 | _lut->SetVectorComponent(0); |
---|
| 523 | break; |
---|
| 524 | case COLOR_BY_VECTOR_Y: |
---|
| 525 | _lut->SetVectorModeToComponent(); |
---|
| 526 | _lut->SetVectorComponent(1); |
---|
| 527 | break; |
---|
| 528 | case COLOR_BY_VECTOR_Z: |
---|
| 529 | _lut->SetVectorModeToComponent(); |
---|
| 530 | _lut->SetVectorComponent(2); |
---|
| 531 | break; |
---|
| 532 | default: |
---|
| 533 | break; |
---|
| 534 | } |
---|
| 535 | } |
---|
| 536 | |
---|
| 537 | /** |
---|
| 538 | * \brief Set a group of world coordinate planes to clip rendering |
---|
| 539 | * |
---|
| 540 | * Passing NULL for planes will remove all cliping planes |
---|
| 541 | */ |
---|
| 542 | void Warp::setClippingPlanes(vtkPlaneCollection *planes) |
---|
| 543 | { |
---|
[3680] | 544 | if (_mapper != NULL) { |
---|
| 545 | _mapper->SetClippingPlanes(planes); |
---|
[3124] | 546 | } |
---|
| 547 | } |
---|