Changeset 4256 for trunk/packages/vizservers/vtkvis/ImageCutplane.cpp
- Timestamp:
- Mar 20, 2014, 9:40:41 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/vtkvis/ImageCutplane.cpp
r4082 r4256 13 13 #include <vtkPointData.h> 14 14 #include <vtkCellData.h> 15 #include <vtkRectilinearGrid.h> 16 #include <vtkStructuredGrid.h> 15 17 #include <vtkPolyDataMapper.h> 16 18 #include <vtkProperty.h> 17 19 #include <vtkImageData.h> 20 #include <vtkProbeFilter.h> 21 #include <vtkGaussianSplatter.h> 18 22 #include <vtkLookupTable.h> 19 23 #include <vtkTransform.h> … … 29 33 ImageCutplane::ImageCutplane() : 30 34 GraphicsObject(), 35 _pipelineInitialized(false), 31 36 _colorMap(NULL), 32 37 _renderer(NULL) … … 147 152 148 153 vtkDataSet *ds = _dataSet->getVtkDataSet(); 149 vtkImageData *imgData = vtkImageData::SafeDownCast(ds); 150 151 if (imgData == NULL) { 152 ERROR("DataSet is not an image."); 153 return; 154 } 155 if (ds->GetPointData()->GetScalars() == NULL) { 156 ERROR("No scalar field"); 157 return; 158 } 154 155 if (_dataSet->is2D()) { 156 USER_ERROR("Image cutplane requires a 3D data set"); 157 _dataSet = NULL; 158 return; 159 } 160 161 if (ds->GetPointData() == NULL || 162 ds->GetPointData()->GetScalars() == NULL) { 163 USER_ERROR("No scalar field was found in the data set"); 164 return; 165 } 166 159 167 double bounds[6]; 160 168 _dataSet->getBounds(bounds); … … 188 196 _mapper[i] = vtkSmartPointer<vtkImageResliceMapper>::New(); 189 197 _mapper[i]->SetSlicePlane(_cutPlane[i]); 190 _mapper[i]->SetInputData(imgData); 198 } 199 } 200 201 if (!_pipelineInitialized) { 202 vtkImageData *imgData = vtkImageData::SafeDownCast(ds); 203 if (imgData == NULL) { 204 // Need to resample to ImageData 205 if (_dataSet->isCloud()) { 206 // DataSet is a 3D point cloud 207 vtkSmartPointer<vtkGaussianSplatter> splatter = vtkSmartPointer<vtkGaussianSplatter>::New(); 208 #ifdef USE_VTK6 209 splatter->SetInputData(ds); 210 #else 211 splatter->SetInput(ds); 212 #endif 213 int dims[3]; 214 dims[0] = dims[1] = dims[2] = 64; 215 if (vtkStructuredGrid::SafeDownCast(ds) != NULL) { 216 vtkStructuredGrid::SafeDownCast(ds)->GetDimensions(dims); 217 } else if (vtkRectilinearGrid::SafeDownCast(ds) != NULL) { 218 vtkRectilinearGrid::SafeDownCast(ds)->GetDimensions(dims); 219 } 220 TRACE("Generating volume with dims (%d,%d,%d) from %d points", 221 dims[0], dims[1], dims[2], ds->GetNumberOfPoints()); 222 splatter->SetSampleDimensions(dims); 223 splatter->Update(); 224 225 TRACE("Done generating volume"); 226 227 for (int i = 0; i < 3; i++) { 228 _mapper[i]->SetInputConnection(splatter->GetOutputPort()); 229 } 230 } else { 231 // (Slow) Resample using ProbeFilter 232 double xLen = bounds[1] - bounds[0]; 233 double yLen = bounds[3] - bounds[2]; 234 double zLen = bounds[5] - bounds[4]; 235 236 int dims[3]; 237 dims[0] = dims[1] = dims[2] = 64; 238 if (xLen == 0.0) dims[0] = 1; 239 if (yLen == 0.0) dims[1] = 1; 240 if (zLen == 0.0) dims[2] = 1; 241 if (vtkStructuredGrid::SafeDownCast(ds) != NULL) { 242 vtkStructuredGrid::SafeDownCast(ds)->GetDimensions(dims); 243 } else if (vtkRectilinearGrid::SafeDownCast(ds) != NULL) { 244 vtkRectilinearGrid::SafeDownCast(ds)->GetDimensions(dims); 245 } 246 TRACE("Generating volume with dims (%d,%d,%d) from %d points", 247 dims[0], dims[1], dims[2], ds->GetNumberOfPoints()); 248 249 double xSpacing = (dims[0] == 1 ? 0.0 : xLen/((double)(dims[0]-1))); 250 double ySpacing = (dims[1] == 1 ? 0.0 : yLen/((double)(dims[1]-1))); 251 double zSpacing = (dims[2] == 1 ? 0.0 : zLen/((double)(dims[2]-1))); 252 253 vtkSmartPointer<vtkImageData> resampleGrid = vtkSmartPointer<vtkImageData>::New(); 254 resampleGrid->SetDimensions(dims[0], dims[1], dims[2]); 255 resampleGrid->SetOrigin(bounds[0], bounds[2], bounds[4]); 256 resampleGrid->SetSpacing(xSpacing, ySpacing, zSpacing); 257 258 vtkSmartPointer<vtkProbeFilter> probe = vtkSmartPointer<vtkProbeFilter>::New(); 259 #ifdef USE_VTK6 260 probe->SetInputData(resampleGrid); 261 probe->SetSourceData(ds); 262 #else 263 probe->SetInput(resampleGrid); 264 probe->SetSource(ds); 265 #endif 266 probe->Update(); 267 268 TRACE("Done generating volume"); 269 270 for (int i = 0; i < 3; i++) { 271 _mapper[i]->SetInputConnection(probe->GetOutputPort()); 272 } 273 } 274 } else { 275 // Have ImageData 276 for (int i = 0; i < 3; i++) { 277 #ifdef USE_VTK6 278 _mapper[i]->SetInputData(imgData); 279 #else 280 _mapper[i]->SetInput(imgData); 281 #endif 282 } 191 283 } 192 284 } … … 228 320 setColorMap(ColorMap::getDefault()); 229 321 } 322 323 _pipelineInitialized = true; 230 324 231 325 for (int i = 0; i < 3; i++) {
Note: See TracChangeset
for help on using the changeset viewer.