Commit 5b1a6721 authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

FIXED create default point cloud visualization for ALL geometry

This means that all component that have GEOMETRY representation
and contains no cell will be visible (automatic creation of a
poly vertex cell containing all the points).
parent b76b1844
......@@ -43,8 +43,7 @@
#include <vtkPolyDataNormals.h>
#include <vtkDoubleArray.h>
#include <vtkProperty.h>
#include <vtkStructuredGrid.h>
#include <vtkUnstructuredGrid.h>
using namespace camitk;
......@@ -67,36 +66,6 @@ VtkMeshComponent::VtkMeshComponent (const QString& fileName) throw(AbortExcepti
// build the vtk data structure from the file
vtkSmartPointer<vtkPointSet> data = VtkMeshUtil::buildVtkPointSet(myFileName.toStdString().c_str(), whatIsIt);
// if this file only contains a point cloud, add a cell to show them automatically
// caveat: if the user save this component, this cell will be saved
if (data->GetNumberOfCells() == 0) {
vtkSmartPointer<vtkIdList> idList = vtkSmartPointer<vtkIdList>::New();
for ( vtkIdType i = 0; i < data->GetNumberOfPoints(); i++ ) {
idList->InsertNextId(i);
}
switch (whatIsIt) {
case VtkMeshUtil::POLY_DATA: {
vtkSmartPointer< vtkPolyData > result = vtkPolyData::SafeDownCast(data);
result->Allocate(1);
result->InsertNextCell(VTK_POLY_VERTEX, idList);
break;
}
case VtkMeshUtil::UNSTRUCTURED_GRID: {
vtkSmartPointer< vtkUnstructuredGrid > result = vtkUnstructuredGrid::SafeDownCast(data);
result->Allocate(1);
result->InsertNextCell(VTK_POLY_VERTEX, idList);
break;
}
case VtkMeshUtil::STRUCTURED_GRID:
// nothing TODO: a structured grid has a specific intern representation with cells.
case VtkMeshUtil::UNKNOWN:
// not possible: an AbortException is thrown if the type is unknown.
break;
}
}
// instanciate the Geometry
initRepresentation(data);
......
......@@ -49,6 +49,7 @@
#include <vtkMath.h>
#include <vtkLookupTable.h>
#include <vtkTransformFilter.h>
#include <vtkIdList.h>
namespace camitk {
//------------------------------- constructor ----------------------------------------
......@@ -136,6 +137,8 @@ Geometry::Geometry(QString label, vtkSmartPointer<vtkPointSet> pointSetPtr, cons
//-- update glyph type size
setGlyphType(InterfaceGeometry::Sphere);
//-- make sure there is at least one cell
createPointCloudVisualization();
}
//------------------------------- destructor ----------------------------------------
......@@ -179,6 +182,36 @@ void Geometry::setPointSet(vtkSmartPointer<vtkPointSet> ps) {
//-- update glyph type size
setGlyphType(InterfaceGeometry::Sphere);
//-- make sure there is at least one cell
createPointCloudVisualization();
}
//------------------------------- createPointCouldVisualization ----------------------------------------
void Geometry::createPointCloudVisualization() {
// assert: pointset is a valid pointset
if (pointSet->GetNumberOfCells() == 0) {
// create the point ids for the unique cell (contains all points)
vtkSmartPointer<vtkIdList> idList = vtkSmartPointer<vtkIdList>::New();
for ( vtkIdType i = 0; i < pointSet->GetNumberOfPoints(); i++ ) {
idList->InsertNextId(i);
}
// add the cells depending on the point set subtype
// if the pointset is a structured grid: nothing to do as a structured grid has a specific intern representation with cells.
if (pointSet->IsA("vtkPolyData")) {
vtkSmartPointer< vtkPolyData > result = vtkPolyData::SafeDownCast(pointSet);
result->Allocate(1);
result->InsertNextCell(VTK_POLY_VERTEX, idList);
}
else
if (pointSet->IsA("vtkUnstructuredGrid")) {
vtkSmartPointer< vtkUnstructuredGrid > result = vtkUnstructuredGrid::SafeDownCast(pointSet);
result->Allocate(1);
result->InsertNextCell(VTK_POLY_VERTEX, idList);
}
}
}
//------------------------------- setMeshWorldTransform ----------------------------------------
......
......@@ -332,6 +332,8 @@ private:
/// the transform filter to place the mesh correctly with respect to its Frame
vtkSmartPointer<vtkTransformFilter> worldTransformFilter;
/// the sphere glyph
vtkSmartPointer<vtkSphereSource> sphereGeom;
///@}
/// @name Other members
......@@ -360,8 +362,12 @@ private:
/// build the glyph extra prop (sphere glyph by default)
void buildGlyph(const GlyphTypes type);
/// the sphere glyph
vtkSmartPointer<vtkSphereSource> sphereGeom;
/** force visualization of point cloud
* If the point set does only contains a point cloud, i.e., there is no cell to visualize the points,
* this method will add a default poly vertex cell that will enable default visualization.
* Caveat: if the user save this component, this cell might be saved as well.
*/
void createPointCloudVisualization();
///@}
/** @name actor colors
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment