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

FIXED tutorials with point data use proper API

parent 92578832
......@@ -92,9 +92,19 @@ Action::ApplyStatus DirectShaker::apply() {
// check the display
bool showDisplacement = property ( "Show Displacement" ).toBool();
if ( !showDisplacement ) {
currentTarget->setPointData ( NULL );
InteractiveViewer::get3DViewer()->setColorScale ( false );
if (!showDisplacement) {
currentTarget->setDataRepresentationOff();
}
else {
// initialize displacement is 0.0
vtkSmartPointer<vtkDoubleArray> displacement = vtkSmartPointer<vtkDoubleArray>::New();
displacement->SetName("Displacement");
displacement->SetNumberOfValues(currentTarget->getPointSet()->GetNumberOfPoints());
for (vtkIdType i = 0; i < currentTarget->getPointSet()->GetNumberOfPoints(); ++i) {
displacement->SetValue(i, 0.0);
}
currentTarget->addPointData(displacement->GetName(),displacement);
}
}
......@@ -126,32 +136,24 @@ void DirectShaker::animate() {
currentTarget->setModified();
// update displacement value
if ( property ( "Show Displacement" ).toBool() ) {
if (property("Show Displacement").toBool()) {
vtkSmartPointer<vtkDoubleArray> displacement = vtkSmartPointer<vtkDoubleArray>::New();
displacement->SetName ( "Displacement" );
displacement->SetName("Displacement");
displacement->SetNumberOfValues(currentTarget->getPointSet()->GetNumberOfPoints());
for ( vtkIdType id = 0; id < currentTarget->getPointSet()->GetNumberOfPoints(); id++ ) {
for (vtkIdType id = 0; id < currentTarget->getPointSet()->GetNumberOfPoints(); id++) {
double displacementVec[3];
initialPosition->GetPoint ( id, displacementVec );
initialPosition->GetPoint(id, displacementVec);
for ( unsigned int j = 0; j < 3; j++ ) {
for (unsigned int j = 0; j < 3; j++) {
displacementVec[j] -= position[id * 3 + j];
}
displacement->InsertValue ( id, sqrt ( displacementVec[0]*displacementVec[0] + displacementVec[1]*displacementVec[1] + displacementVec[2]*displacementVec[2] ) );
displacement->SetValue(id, sqrt(displacementVec[0]*displacementVec[0] + displacementVec[1]*displacementVec[1] + displacementVec[2]*displacementVec[2]));
}
// update the display
// set the values as point data to get the interpolated colors
currentTarget->setPointData ( displacement );
// update color scale in the 3D viewer
double range[2] = {0, 1};
displacement->GetValueRange ( range );
InteractiveViewer::get3DViewer()->setColorScaleMinMax ( range[0], range[1] );
}
else {
currentTarget->setPointData ( NULL );
InteractiveViewer::get3DViewer()->setColorScale ( false );
// will replace the previous
currentTarget->addPointData(displacement->GetName(),displacement);
}
// refresh the view
......
......@@ -91,12 +91,22 @@ Action::ApplyStatus ExternalShaker::apply() {
initialPosition = vtkSmartPointer<vtkPoints>::New();
initialPosition->DeepCopy(currentTarget->getPointSet()->GetPoints());
// check the display
// check and update the display
bool showDisplacement = property("Show Displacement").toBool();
if (!showDisplacement) {
currentTarget->setPointData ( NULL );
InteractiveViewer::get3DViewer()->setColorScale ( false );
currentTarget->setDataRepresentationOff();
}
else {
// initialize displacement is 0.0
vtkSmartPointer<vtkDoubleArray> displacement = vtkSmartPointer<vtkDoubleArray>::New();
displacement->SetName("Displacement");
displacement->SetNumberOfValues(currentTarget->getPointSet()->GetNumberOfPoints());
for (vtkIdType i = 0; i < currentTarget->getPointSet()->GetNumberOfPoints(); ++i) {
displacement->SetValue(i, 0.0);
}
currentTarget->addPointData(displacement->GetName(),displacement);
}
Property* fps = new Property(tr("FPS"), QVariant(0.0), tr("Frame Per Second (including display)"), tr("Hz"));
......@@ -138,6 +148,7 @@ void ExternalShaker::animate() {
if (property("Show Displacement").toBool()) {
vtkSmartPointer<vtkDoubleArray> displacement = vtkSmartPointer<vtkDoubleArray>::New();
displacement->SetName("Displacement");
displacement->SetNumberOfValues(currentTarget->getPointSet()->GetNumberOfPoints());
for (vtkIdType id = 0; id < currentTarget->getPointSet()->GetNumberOfPoints(); id++) {
double displacementVec[3];
......@@ -146,21 +157,12 @@ void ExternalShaker::animate() {
for (unsigned int j = 0; j < 3; j++) {
displacementVec[j] -= position[id * 3 + j];
}
displacement->InsertValue(id, sqrt(displacementVec[0]*displacementVec[0] + displacementVec[1]*displacementVec[1] + displacementVec[2]*displacementVec[2]));
displacement->SetValue(id, sqrt(displacementVec[0]*displacementVec[0] + displacementVec[1]*displacementVec[1] + displacementVec[2]*displacementVec[2]));
}
// update the display
// set the values as point data to get the interpolated colors
currentTarget->setPointData ( displacement );
// update color scale in the 3D viewer
double range[2] = {0, 1};
displacement->GetValueRange(range);
InteractiveViewer::get3DViewer()->setColorScaleMinMax ( range[0], range[1]);
}
else {
currentTarget->setPointData ( NULL );
InteractiveViewer::get3DViewer()->setColorScale ( false );
// will replace the previous
currentTarget->addPointData(displacement->GetName(),displacement);
}
// refresh the view
......
......@@ -100,8 +100,6 @@ void ShowPointData::process( MeshComponent* comp ) {
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(MeshComponent::POINTS,"Random");
break;
case POINT_INDEX:
demoPointData->SetName( "Index" );
......
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