Changeset 4608 for vtkvis


Ignore:
Timestamp:
Aug 2, 2014, 12:55:11 AM (10 years ago)
Author:
ldelgass
Message:

Merge r4243 from trunk: resampling non-uniform grids for volumes

Location:
vtkvis/branches/1.7
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • vtkvis/branches/1.7

  • vtkvis/branches/1.7/Volume.cpp

    r3980 r4608  
    1111#include <vtkPointData.h>
    1212#include <vtkImageData.h>
     13#include <vtkProbeFilter.h>
    1314#include <vtkVolumeProperty.h>
    1415#include <vtkGPUVolumeRayCastMapper.h>
     
    3233Volume::Volume() :
    3334    GraphicsObject(),
     35    _useUgridMapper(false),
    3436    _colorMap(NULL)
    3537{
     
    105107    }
    106108
     109    if (ds->GetPointData() == NULL ||
     110        ds->GetPointData()->GetScalars() == NULL) {
     111        WARN("No scalar point data in dataset %s", _dataSet->getName().c_str());
     112    }
     113
    107114    if (vtkImageData::SafeDownCast(ds) != NULL) {
    108115        // Image data required for these mappers
     
    123130#endif
    124131        vtkVolumeMapper::SafeDownCast(_volumeMapper)->SetBlendModeToComposite();
    125     } else if (_dataSet->isCloud() ||
    126                vtkUnstructuredGrid::SafeDownCast(ds) == NULL) {
    127         // DataSet is a 3D point cloud, rectilinear grid or structured grid
     132    } else if (_dataSet->isCloud()) {
     133        // DataSet is a 3D point cloud
    128134        vtkSmartPointer<vtkGaussianSplatter> splatter = vtkSmartPointer<vtkGaussianSplatter>::New();
    129135#ifdef USE_VTK6
     
    151157#endif
    152158        _volumeMapper->SetInputConnection(splatter->GetOutputPort());
     159        vtkVolumeMapper::SafeDownCast(_volumeMapper)->SetBlendModeToComposite();
     160    } else if (vtkUnstructuredGrid::SafeDownCast(ds) == NULL || !_useUgridMapper) {
     161        // (Slow) Resample using ProbeFilter
     162        double bounds[6];
     163        ds->GetBounds(bounds);
     164        double xLen = bounds[1] - bounds[0];
     165        double yLen = bounds[3] - bounds[2];
     166        double zLen = bounds[5] - bounds[4];
     167
     168        int dims[3];
     169        dims[0] = dims[1] = dims[2] = 64;
     170        if (xLen == 0.0) dims[0] = 1;
     171        if (yLen == 0.0) dims[1] = 1;
     172        if (zLen == 0.0) dims[2] = 1;
     173        if (vtkStructuredGrid::SafeDownCast(ds) != NULL) {
     174            vtkStructuredGrid::SafeDownCast(ds)->GetDimensions(dims);
     175        } else if (vtkRectilinearGrid::SafeDownCast(ds) != NULL) {
     176            vtkRectilinearGrid::SafeDownCast(ds)->GetDimensions(dims);
     177        }
     178        TRACE("Generating volume with dims (%d,%d,%d) from %d points",
     179              dims[0], dims[1], dims[2], ds->GetNumberOfPoints());
     180
     181        double xSpacing = (dims[0] == 1 ? 0.0 : xLen/((double)(dims[0]-1)));
     182        double ySpacing = (dims[1] == 1 ? 0.0 : yLen/((double)(dims[1]-1)));
     183        double zSpacing = (dims[2] == 1 ? 0.0 : zLen/((double)(dims[2]-1)));
     184
     185        vtkSmartPointer<vtkImageData> imageData = vtkSmartPointer<vtkImageData>::New();
     186        imageData->SetDimensions(dims[0], dims[1], dims[2]);
     187        imageData->SetOrigin(bounds[0], bounds[2], bounds[4]);
     188        imageData->SetSpacing(xSpacing, ySpacing, zSpacing);
     189
     190        vtkSmartPointer<vtkProbeFilter> probe = vtkSmartPointer<vtkProbeFilter>::New();
     191        probe->SetInputData(imageData);
     192        probe->SetSourceData(ds);
     193        probe->Update();
     194
     195        TRACE("Done generating volume");
     196
     197#ifdef USE_GPU_RAYCAST_MAPPER
     198        _volumeMapper = vtkSmartPointer<vtkGPUVolumeRayCastMapper>::New();
     199        vtkGPUVolumeRayCastMapper::SafeDownCast(_volumeMapper)->AutoAdjustSampleDistancesOff();
     200#else
     201        _volumeMapper = vtkSmartPointer<vtkVolumeTextureMapper3D>::New();
     202#endif
     203        _volumeMapper->SetInputConnection(probe->GetOutputPort());
    153204        vtkVolumeMapper::SafeDownCast(_volumeMapper)->SetBlendModeToComposite();
    154205    } else {
     
    191242
    192243    initProp();
    193 
    194     if (ds->GetPointData() == NULL ||
    195         ds->GetPointData()->GetScalars() == NULL) {
    196         WARN("No scalar point data in dataset %s", _dataSet->getName().c_str());
    197     }
    198244
    199245    if (_colorMap == NULL) {
  • vtkvis/branches/1.7/Volume.h

    r3961 r4608  
    6767    virtual void update();
    6868
     69    bool _useUgridMapper;
     70
    6971    ColorMap *_colorMap;
    7072    vtkSmartPointer<vtkAbstractVolumeMapper> _volumeMapper;
Note: See TracChangeset for help on using the changeset viewer.