Commit ea2a1aae authored by Emmanuel Promayon's avatar Emmanuel Promayon
Browse files

NEW meshpointdata demo now uses the CamiTK4 point data management system.

initial/original point data are never removed, new demo data are added.
Two type of generation: random (can be done as many times as you wish)
and using the point index (only once)
Note that the generated point data are automatically selected and
visualize when the apply button is pressed.
parent 142e41cf
......@@ -54,13 +54,13 @@ ShowPointData::ShowPointData( ActionExtension* extension ) : Action( extension )
addTag( "Color Bar" );
// Setting the action's parameters
Property* displayMethodProp = new Property( "Display Method", ShowPointData::INITIAL, "How/What Point Data to Show. In this example, there are three ways to show point data: <ol><li>NONE = No point data are displayed</li><li>INITIAL = The point data that were present initially in the vtk data structure</li><li>POINT_DEMO = Demo point data generated automatically for the points (using the point ids)</li></ol>", "" );
displayMethodProp->setEnumTypeName( "DisplayMethod" );
Property* generationMethodProp = new Property( "Generation Method", ShowPointData::RANDOM_PERCENT, "How/What Point Data to Show. In this example, there are two ways to add synthetic point data: <ol><li>The generated point data have random values between 0 and 100</li><li>The generated point data have the values of their point index</li></ol>To show the point data, select the \"Data\" tab in the property editor and select the data you would like to display. Random generation point data are recreated each time.", "" );
generationMethodProp->setEnumTypeName( "GenerationMethod" );
QStringList methodGUIName;
methodGUIName << "Nothing" << "Initial (original)" << "Demo (points)";
displayMethodProp->setAttribute( "enumNames", methodGUIName );
methodGUIName << "Randomly Generated in [0..100]" << "Use Point Index";
generationMethodProp->setAttribute( "enumNames", methodGUIName );
addParameter( displayMethodProp );
addParameter( generationMethodProp );
}
......@@ -77,13 +77,6 @@ Action::ApplyStatus ShowPointData::apply() {
foreach( Component * comp, getTargets() ) {
MeshComponent* input = dynamic_cast<MeshComponent*>( comp );
// check if this mesh was never used as input of this action
if ( !initialPointData.contains( input ) ) {
// backup the read point data
vtkSmartPointer<vtkPointData> meshInitialPointData = vtkSmartPointer<vtkPointData>::New();
meshInitialPointData->ShallowCopy( input->getPointSet()->GetPointData() );
initialPointData.insert( input, meshInitialPointData );
}
process( input );
}
......@@ -95,47 +88,34 @@ Action::ApplyStatus ShowPointData::apply() {
// --------------- process -------------------
void ShowPointData::process( MeshComponent* comp ) {
// Get the parameter
DisplayMethod displayMethod = ( DisplayMethod ) property( "Display Method" ).toInt();
//QString displayMethodString = getProperty("Display Method")->getEnumValueAsString(this);
GenerationMethod displayMethod = ( GenerationMethod ) property( "Generation Method" ).toInt();
vtkSmartPointer<vtkDoubleArray> demoPointData = vtkSmartPointer<vtkDoubleArray>::New();
switch ( displayMethod ) {
case NONE:
comp->setPointData( NULL );
InteractiveViewer::get3DViewer()->setColorScale( false );
break;
case INITIAL: {
vtkSmartPointer<vtkPointData> meshInitialPointData = initialPointData.value( comp );
comp->getPointSet()->GetPointData()->ShallowCopy( meshInitialPointData );
if ( meshInitialPointData->GetNumberOfArrays() > 0 && comp->getPointSet()->GetPointData()->GetScalars() != NULL ) {
double range[2];
//TODO TEST without this ! comp->getPointSet()->Update(); // force vtk to compute the range
comp->getPointSet()->GetPointData()->GetScalars()->GetRange( range );
InteractiveViewer::get3DViewer()->setColorScaleMinMax( range[0], range[1] );
InteractiveViewer::get3DViewer()->setColorScaleTitle( "Initial VTK Point Data" );
InteractiveViewer::get3DViewer()->setColorScale( true );
}
else {
InteractiveViewer::get3DViewer()->setColorScale( false );
int numberOfPoints = comp->getPointSet()->GetNumberOfPoints();
demoPointData->SetNumberOfValues( numberOfPoints );
switch ( displayMethod ) {
case RANDOM_PERCENT:
demoPointData->SetName( "Random" );
for ( vtkIdType i = 0; i < numberOfPoints; ++i ) {
demoPointData->SetValue( i, 100.0 * ((double) rand()) / ((double) RAND_MAX) );
}
// in order to allow regeneration of random data, remove the previous random data if exists
comp->removeDataArray(MeshDataModel::POINTS,"Random");
break;
}
case POINT_DEMO: {
// create a new vtkDataArray to store the demo value
vtkSmartPointer<vtkDoubleArray> demoPointData = vtkSmartPointer<vtkDoubleArray>::New();
int numberOfPoints = comp->getPointSet()->GetNumberOfPoints();
demoPointData->SetNumberOfValues( numberOfPoints );
demoPointData->SetName( "Demo Point Data (Points)" );
case POINT_INDEX:
demoPointData->SetName( "Index" );
for ( vtkIdType i = 0; i < numberOfPoints; ++i ) {
demoPointData->SetValue( i, i );
}
comp->setPointData( demoPointData );
InteractiveViewer::get3DViewer()->setColorScaleMinMax( 0.0, numberOfPoints );
InteractiveViewer::get3DViewer()->setColorScaleTitle( "Point Ids" );
InteractiveViewer::get3DViewer()->setColorScale( true );
break;
}
}
// add the point data
comp->addPointData(demoPointData->GetName(),demoPointData);
// show it!
comp->setActiveData(MeshDataModel::POINTS,demoPointData->GetName());
}
......@@ -41,11 +41,11 @@ public:
/// Default Destructor
virtual ~ShowPointData();
/// in this example, there are three ways to show point data
enum DisplayMethod { NONE, ///< No point data are displayed
INITIAL, ///< The point data that were present initially in the vtk data structure
POINT_DEMO, ///< Demo point data generated automatically for the points (using the point ids)
};
/// in this example, there are two ways to generate point data
enum GenerationMethod {
RANDOM_PERCENT, ///< The generated point data have random values between 0 and 100
POINT_INDEX, ///< The generated point data have the values of their point index
};
/// the corresponding Qt enum (register the enum in Qt), see also Q_DECLARE_METATYPE below
Q_ENUMS( DisplayMethod )
......@@ -62,11 +62,9 @@ private:
/// helper method to simplify the target component processing
virtual void process(camitk::MeshComponent*);
/// store the initial data that were already stored in selected meshes
QMap<camitk::MeshComponent*, vtkSmartPointer<vtkPointData> > initialPointData;
};
Q_DECLARE_METATYPE(ShowPointData::DisplayMethod)
Q_DECLARE_METATYPE(ShowPointData::GenerationMethod )
#endif // SHOWPOINTDATA_H
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