//! \file DeformableMesh.cxx //! Basic illustration of the vtkDeformableMesh filter //! in an infinite loop. //! //! \author Jerome Velut //! \date February 2011 #include "vtkDeformableMesh.h" #include "vtkSmartPointer.h" #include "vtkSphereSource.h" #include "vtkImageEllipsoidSource.h" #include "vtkImageSobel3D.h" #include "vtkImageMagnitude.h" #include "vtkPolyDataMapper.h" #include "vtkActor.h" #include "vtkProperty.h" #include "vtkRenderer.h" #include "vtkRenderWindow.h" #include "vtkRenderWindowInteractor.h" int main( int argc, char** argv ) { // Build data processing pipeline vtkSmartPointer sphereSource; sphereSource = vtkSmartPointer::New( ); vtkSmartPointer deformableMesh; deformableMesh = vtkSmartPointer::New(); vtkSmartPointer ellipsoidSource; ellipsoidSource = vtkSmartPointer::New(); vtkSmartPointer sobel1; sobel1 = vtkSmartPointer::New(); vtkSmartPointer magnitude; magnitude = vtkSmartPointer::New(); vtkSmartPointer sobel2; sobel2 = vtkSmartPointer::New(); // Configure PointSource ellipsoidSource->SetWholeExtent(0,63,0,63,0,63); ellipsoidSource->SetCenter(31,31,31); ellipsoidSource->SetRadius(18, 14, 18); // External forces computation sobel1->SetInputConnection(ellipsoidSource->GetOutputPort( )); magnitude->SetInputConnection(sobel1->GetOutputPort()); sobel2->SetInputConnection(magnitude->GetOutputPort()); // Deformable model initialisation sphereSource->SetCenter(31,31,31); sphereSource->SetRadius(16); sphereSource->SetPhiResolution(36); sphereSource->SetThetaResolution(36); // Configure deformableMesh deformableMesh->IterateFromZeroOff(); deformableMesh->SetScaleFactor(.0003); // Model deformableMesh->SetInputConnection(0, sphereSource->GetOutputPort()); // Deformation forces deformableMesh->SetInputConnection(1, sobel2->GetOutputPort( )); deformableMesh->SetInputArrayToProcess( 0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, "Magnitude" ); // Visualisation pipeline vtkSmartPointer mapper; mapper = vtkSmartPointer::New(); vtkSmartPointer actor; actor = vtkSmartPointer::New(); vtkSmartPointer mapper1; mapper1 = vtkSmartPointer::New(); vtkSmartPointer actor1; actor1 = vtkSmartPointer::New(); vtkSmartPointer renderer; renderer = vtkSmartPointer::New(); renderer->SetBackground(1.0, 1.0, 1.0); vtkSmartPointer renWin; renWin = vtkSmartPointer::New(); mapper->SetInputConnection(deformableMesh->GetOutputPort()); mapper->SetScalarVisibility(0); actor->SetMapper(mapper); actor->GetProperty()->SetRepresentationToWireframe(); mapper1->SetInputConnection(sphereSource->GetOutputPort()); mapper1->SetScalarVisibility(0); actor1->SetMapper(mapper1); actor1->GetProperty()->SetColor(1.0, 0.0, 0.0); actor1->GetProperty()->SetOpacity(0.3); renderer->AddActor(actor); renderer->AddActor(actor1); renWin->AddRenderer(renderer); // Iterative loop: // - Increment the number of iteration // - Render -> it will trigger only one iteration in the DeformableMesh. while( 1 ) { deformableMesh->SetNumberOfIterations(deformableMesh->GetNumberOfIterations()+1); renWin->Render(); } return( 0 ); }