Ignore:
Timestamp:
Jun 7, 2013 2:27:25 PM (11 years ago)
Author:
ldelgass
Message:

Improved cloud support in vtkvis: handle ugrids with no cells as well as
polydata clouds, add cloudstyle options to some graphics objects.

File:
1 edited

Legend:

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

    r3621 r3680  
    1313#include <vtkPointData.h>
    1414#include <vtkCellData.h>
    15 #include <vtkDataSetMapper.h>
     15#include <vtkPolyDataMapper.h>
    1616#include <vtkUnstructuredGrid.h>
    1717#include <vtkProperty.h>
     
    3030#include "Trace.h"
    3131
    32 #define MESH_POINT_CLOUDS
    33 
    3432using namespace VtkVis;
    3533
     
    3735    GraphicsObject(),
    3836    _pipelineInitialized(false),
     37    _cloudStyle(CLOUD_MESH),
    3938    _colorMap(NULL),
    4039    _colorMode(COLOR_BY_SCALAR),
     
    159158    for (int i = 0; i < 3; i++) {
    160159        if (_mapper[i] == NULL) {
    161             _mapper[i] = vtkSmartPointer<vtkDataSetMapper>::New();
     160            _mapper[i] = vtkSmartPointer<vtkPolyDataMapper>::New();
    162161            // Map scalars through lookup table regardless of type
    163162            _mapper[i]->SetColorModeToMapScalars();
     
    196195
    197196    if (!_pipelineInitialized) {
    198         vtkPolyData *pd = vtkPolyData::SafeDownCast(ds);
    199         if (pd &&
    200             pd->GetNumberOfLines() == 0 &&
    201             pd->GetNumberOfPolys() == 0 &&
    202             pd->GetNumberOfStrips() == 0) {
     197        _splatter = NULL;
     198        if (_dataSet->isCloud()) {
    203199            // DataSet is a point cloud
    204200            PrincipalPlane plane;
     
    206202            if (_dataSet->is2D(&plane, &offset)) {
    207203                // DataSet is a 2D point cloud
    208 #ifdef MESH_POINT_CLOUDS
    209                 vtkSmartPointer<vtkDelaunay2D> mesher = vtkSmartPointer<vtkDelaunay2D>::New();
    210                 if (plane == PLANE_ZY) {
    211                     vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
    212                     trans->RotateWXYZ(90, 0, 1, 0);
    213                     if (offset != 0.0) {
    214                         trans->Translate(-offset, 0, 0);
     204                if (_cloudStyle == CLOUD_MESH) {
     205                    vtkSmartPointer<vtkDelaunay2D> mesher = vtkSmartPointer<vtkDelaunay2D>::New();
     206                    if (plane == PLANE_ZY) {
     207                        vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
     208                        trans->RotateWXYZ(90, 0, 1, 0);
     209                        if (offset != 0.0) {
     210                            trans->Translate(-offset, 0, 0);
     211                        }
     212                        mesher->SetTransform(trans);
     213                        _actor[1]->VisibilityOff();
     214                        _actor[2]->VisibilityOff();
     215                    } else if (plane == PLANE_XZ) {
     216                        vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
     217                        trans->RotateWXYZ(-90, 1, 0, 0);
     218                        if (offset != 0.0) {
     219                            trans->Translate(0, -offset, 0);
     220                        }
     221                        mesher->SetTransform(trans);
     222                        _actor[0]->VisibilityOff();
     223                        _actor[2]->VisibilityOff();
     224                    } else if (offset != 0.0) {
     225                        // XY with Z offset
     226                        vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
     227                        trans->Translate(0, 0, -offset);
     228                        mesher->SetTransform(trans);
     229                        _actor[0]->VisibilityOff();
     230                        _actor[1]->VisibilityOff();
    215231                    }
    216                     mesher->SetTransform(trans);
    217                     _actor[1]->VisibilityOff();
    218                     _actor[2]->VisibilityOff();
    219                 } else if (plane == PLANE_XZ) {
    220                     vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
    221                     trans->RotateWXYZ(-90, 1, 0, 0);
    222                     if (offset != 0.0) {
    223                         trans->Translate(0, -offset, 0);
     232#ifdef USE_VTK6
     233                    mesher->SetInputData(ds);
     234#else
     235                    mesher->SetInput(ds);
     236#endif
     237                    for (int i = 0; i < 3; i++) {
     238                        _mapper[i]->SetInputConnection(mesher->GetOutputPort());
    224239                    }
    225                     mesher->SetTransform(trans);
    226                     _actor[0]->VisibilityOff();
    227                     _actor[2]->VisibilityOff();
    228                 } else if (offset != 0.0) {
    229                     // XY with Z offset
    230                     vtkSmartPointer<vtkTransform> trans = vtkSmartPointer<vtkTransform>::New();
    231                     trans->Translate(0, 0, -offset);
    232                     mesher->SetTransform(trans);
    233                     _actor[0]->VisibilityOff();
    234                     _actor[1]->VisibilityOff();
     240                } else {
     241                    // _cloudStyle == CLOUD_SPLAT
     242                    if (_splatter == NULL) {
     243                        _splatter = vtkSmartPointer<vtkGaussianSplatter>::New();
     244                    }
     245#ifdef USE_VTK6
     246                    _splatter->SetInputData(ds);
     247#else
     248                    _splatter->SetInput(ds);
     249#endif
     250                    int dims[3];
     251                    _splatter->GetSampleDimensions(dims);
     252                    TRACE("Sample dims: %d %d %d", dims[0], dims[1], dims[2]);
     253                    if (plane == PLANE_ZY) {
     254                        dims[0] = 3;
     255                    } else if (plane == PLANE_XZ) {
     256                        dims[1] = 3;
     257                    } else {
     258                        dims[2] = 3;
     259                    }
     260                    _splatter->SetSampleDimensions(dims);
     261                    for (int i = 0; i < 3; i++) {
     262                        _cutter[i]->SetInputConnection(_splatter->GetOutputPort());
     263                        vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
     264                        gf->UseStripsOn();
     265                        gf->SetInputConnection(_cutter[i]->GetOutputPort());
     266                        _mapper[i]->SetInputConnection(gf->GetOutputPort());
     267                    }
    235268                }
     269            } else {
     270                if (_cloudStyle == CLOUD_MESH) {
     271                    // Data Set is a 3D point cloud
     272                    // Result of Delaunay3D mesher is unstructured grid
     273                    vtkSmartPointer<vtkDelaunay3D> mesher = vtkSmartPointer<vtkDelaunay3D>::New();
    236274#ifdef USE_VTK6
    237                 mesher->SetInputData(pd);
     275                    mesher->SetInputData(ds);
    238276#else
    239                 mesher->SetInput(pd);
    240 #endif
    241                 for (int i = 0; i < 3; i++) {
    242                     _mapper[i]->SetInputConnection(mesher->GetOutputPort());
     277                    mesher->SetInput(ds);
     278#endif
     279                    // Sample a plane within the grid bounding box
     280                    for (int i = 0; i < 3; i++) {
     281                        _cutter[i]->SetInputConnection(mesher->GetOutputPort());
     282                        vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
     283                        gf->UseStripsOn();
     284                        gf->SetInputConnection(_cutter[i]->GetOutputPort());
     285                        _mapper[i]->SetInputConnection(gf->GetOutputPort());
     286                    }
     287                } else {
     288                    // _cloudStyle == CLOUD_SPLAT
     289                    if (_splatter == NULL) {
     290                        _splatter = vtkSmartPointer<vtkGaussianSplatter>::New();
     291                    }
     292#ifdef USE_VTK6
     293                    _splatter->SetInputData(ds);
     294#else
     295                    _splatter->SetInput(ds);
     296#endif
     297                    int dims[3];
     298                    dims[0] = dims[1] = dims[2] = 64;
     299                    TRACE("Generating volume with dims (%d,%d,%d) from point cloud",
     300                          dims[0], dims[1], dims[2]);
     301                    _splatter->SetSampleDimensions(dims);
     302                    for (int i = 0; i < 3; i++) {
     303                        _cutter[i]->SetInputConnection(_splatter->GetOutputPort());
     304                        vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
     305                        gf->UseStripsOn();
     306                        gf->SetInputConnection(_cutter[i]->GetOutputPort());
     307                        _mapper[i]->SetInputConnection(gf->GetOutputPort());
     308                    }
    243309                }
    244 #else
    245                 if (_splatter == NULL) {
    246                     _splatter = vtkSmartPointer<vtkGaussianSplatter>::New();
    247                 }
    248 #ifdef USE_VTK6
    249                 _splatter->SetInputData(pd);
    250 #else
    251                 _splatter->SetInput(pd);
    252 #endif
    253                 int dims[3];
    254                 _splatter->GetSampleDimensions(dims);
    255                 TRACE("Sample dims: %d %d %d", dims[0], dims[1], dims[2]);
    256                 if (plane == PLANE_ZY) {
    257                     dims[0] = 3;
    258                 } else if (plane == PLANE_XZ) {
    259                     dims[1] = 3;
    260                 } else {
    261                     dims[2] = 3;
    262                 }
    263                 _splatter->SetSampleDimensions(dims);
    264                 for (int i = 0; i < 3; i++) {
    265                     _cutter[i]->SetInputConnection(_splatter->GetOutputPort());
    266                     vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
    267                     gf->UseStripsOn();
    268                     gf->SetInputConnection(_cutter[i]->GetOutputPort());
    269                     _mapper[i]->SetInputConnection(gf->GetOutputPort());
    270                 }
    271 #endif
    272             } else {
    273 #ifdef MESH_POINT_CLOUDS
    274                 // Data Set is a 3D point cloud
    275                 // Result of Delaunay3D mesher is unstructured grid
    276                 vtkSmartPointer<vtkDelaunay3D> mesher = vtkSmartPointer<vtkDelaunay3D>::New();
    277 #ifdef USE_VTK6
    278                 mesher->SetInputData(pd);
    279 #else
    280                 mesher->SetInput(pd);
    281 #endif
    282                 // Sample a plane within the grid bounding box
    283                 for (int i = 0; i < 3; i++) {
    284                     _cutter[i]->SetInputConnection(mesher->GetOutputPort());
    285                     vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
    286                     gf->UseStripsOn();
    287                     gf->SetInputConnection(_cutter[i]->GetOutputPort());
    288                     _mapper[i]->SetInputConnection(gf->GetOutputPort());
    289                 }
    290 #else
    291                 if (_splatter == NULL) {
    292                     _splatter = vtkSmartPointer<vtkGaussianSplatter>::New();
    293                 }
    294 #ifdef USE_VTK6
    295                 _splatter->SetInputData(pd);
    296 #else
    297                 _splatter->SetInput(pd);
    298 #endif
    299                 int dims[3];
    300                 dims[0] = dims[1] = dims[2] = 64;
    301                 TRACE("Generating volume with dims (%d,%d,%d) from point cloud",
    302                       dims[0], dims[1], dims[2]);
    303                 _splatter->SetSampleDimensions(dims);
    304                 for (int i = 0; i < 3; i++) {
    305                     _cutter[i]->SetInputConnection(_splatter->GetOutputPort());
    306                     vtkSmartPointer<vtkDataSetSurfaceFilter> gf = vtkSmartPointer<vtkDataSetSurfaceFilter>::New();
    307                     gf->UseStripsOn();
    308                     gf->SetInputConnection(_cutter[i]->GetOutputPort());
    309                     _mapper[i]->SetInputConnection(gf->GetOutputPort());
    310                 }
    311 #endif
    312310            }
    313311        } else {
     
    355353        }
    356354    }
    357 
    358     _pipelineInitialized = true;
    359355
    360356    for (int i = 0; i < 3; i++) {
     
    399395    if (_lut == NULL) {
    400396        setColorMap(ColorMap::getDefault());
    401         setColorMode(_colorMode);
    402     }
     397        if (ds->GetPointData()->GetScalars() == NULL &&
     398            ds->GetPointData()->GetVectors() != NULL) {
     399            TRACE("Setting color mode to vector magnitude");
     400            setColorMode(COLOR_BY_VECTOR_MAGNITUDE);
     401        } else {
     402            TRACE("Setting color mode to scalar");
     403            setColorMode(COLOR_BY_SCALAR);
     404        }
     405    } else if (!_pipelineInitialized) {
     406        double *rangePtr = _colorFieldRange;
     407        if (_colorFieldRange[0] > _colorFieldRange[1]) {
     408            rangePtr = NULL;
     409        }
     410        setColorMode(_colorMode, _colorFieldType, _colorFieldName.c_str(), rangePtr);
     411    }
     412
     413    _pipelineInitialized = true;
    403414
    404415    for (int i = 0; i < 3; i++) {
     
    417428        if (bounds[0] <= bounds[1]) {
    418429            getAssembly()->AddPart(_actor[i]);
     430        }
     431    }
     432}
     433
     434void Cutplane::setCloudStyle(CloudStyle style)
     435{
     436    if (style != _cloudStyle) {
     437        _cloudStyle = style;
     438        if (_dataSet != NULL) {
     439            _pipelineInitialized = false;
     440            update();
    419441        }
    420442    }
     
    630652
    631653    if (_splatter != NULL) {
     654        if (name != NULL && strlen(name) > 0) {
     655            _splatter->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, name);
     656        }
    632657        for (int i = 0; i < 3; i++) {
    633658            _mapper[i]->SelectColorArray("SplatterValues");
Note: See TracChangeset for help on using the changeset viewer.