Changeset 4256 for trunk/packages


Ignore:
Timestamp:
Mar 20, 2014, 9:40:41 PM (11 years ago)
Author:
ldelgass
Message:

Add resmapling of non-uniform datasets to imagecutplane. Note: would eventually
like to share the resampled dataset among multiple pipelines (e.g. for volumes
and cutplanes).

Location:
trunk/packages/vizservers/vtkvis
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/vtkvis/ImageCutplane.cpp

    r4082 r4256  
    1313#include <vtkPointData.h>
    1414#include <vtkCellData.h>
     15#include <vtkRectilinearGrid.h>
     16#include <vtkStructuredGrid.h>
    1517#include <vtkPolyDataMapper.h>
    1618#include <vtkProperty.h>
    1719#include <vtkImageData.h>
     20#include <vtkProbeFilter.h>
     21#include <vtkGaussianSplatter.h>
    1822#include <vtkLookupTable.h>
    1923#include <vtkTransform.h>
     
    2933ImageCutplane::ImageCutplane() :
    3034    GraphicsObject(),
     35    _pipelineInitialized(false),
    3136    _colorMap(NULL),
    3237    _renderer(NULL)
     
    147152
    148153    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
    159167    double bounds[6];
    160168    _dataSet->getBounds(bounds);
     
    188196            _mapper[i] = vtkSmartPointer<vtkImageResliceMapper>::New();
    189197            _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            }
    191283        }
    192284    }
     
    228320        setColorMap(ColorMap::getDefault());
    229321    }
     322
     323    _pipelineInitialized = true;
    230324
    231325    for (int i = 0; i < 3; i++) {
  • trunk/packages/vizservers/vtkvis/ImageCutplane.h

    r4082 r4256  
    8888    virtual void update();
    8989
     90    bool _pipelineInitialized;
     91
    9092    ColorMap *_colorMap;
    9193    Renderer *_renderer;
Note: See TracChangeset for help on using the changeset viewer.