6 #include <vtkInteractorStyleSwitch.h>
7 #include <vtkProperty.h>
8 #include <vtkRenderer.h>
9 #include <vtkRenderWindow.h>
10 #include <vtkRenderWindowInteractor.h>
11 #include <vtkSmartPointer.h>
13 #include <cpm/DataStructures/QuadEdgeMesh.h>
14 #include <cpm/DataStructures/SimplexMesh.h>
15 #include <cpm/Algorithms/QuadEdge/MeshToDualFilter.h>
16 #include <cpm/Algorithms/Simplex/DeformationFilter.h>
17 #include <cpm/Algorithms/Simplex/InternalForceFunction.h>
18 #include <cpm/IO/MeshReader.h>
19 #include <cpm/VTK/MeshMapper.h>
20 #include <cpm/VTK/ThreadedDeformation.h>
22 // -------------------------------------------------------------------------
23 const unsigned int Dim = 3;
24 const unsigned int Order = 2;
26 typedef float TScalar;
27 typedef cpm::DataStructures::QuadEdgeMesh< TScalar, Dim > TTriangulation;
28 typedef cpm::DataStructures::SimplexMesh< TScalar, Order, Dim > TSimplex;
30 typedef cpm::IO::MeshReader< TTriangulation > TTriangulationReader;
31 typedef cpm::VTK::MeshMapper< TSimplex > TSimplexMapper;
33 cpm::Algorithms::QuadEdge::MeshToDualFilter< TTriangulation, TSimplex >
34 TTriangulationToSimplexFilter;
36 cpm::Algorithms::Simplex::DeformationFilter< TSimplex >
39 cpm::Algorithms::Simplex::InternalForceFunction< TSimplex >
42 cpm::VTK::ThreadedDeformation< TDeformationFilter >
45 // -------------------------------------------------------------------------
46 int main( int argc, char* argv[] )
48 // WARNING: Always call this static method FIRST!!!
49 TThreadedExecution::InitThreadSupport( );
55 << "Usage: " << argv[ 0 ]
56 << " input_triangulation"
61 std::string input_triangulation_fn = argv[ 1 ];
64 TTriangulationReader::Pointer input_triangulation_reader =
65 TTriangulationReader::New( );
66 input_triangulation_reader->SetFileName( input_triangulation_fn );
68 // Compute the simplex (i.e. the triangulation's dual) mesh
69 TTriangulationToSimplexFilter::Pointer triangl2simplex =
70 TTriangulationToSimplexFilter::New( );
71 triangl2simplex->SetInput( input_triangulation_reader->GetOutput( ) );
72 triangl2simplex->Update( );
73 TSimplex::Pointer simplex = triangl2simplex->GetOutput( );
74 simplex->DisconnectPipeline( );
77 vtkSmartPointer< TSimplexMapper > simplex_mapper =
78 vtkSmartPointer< TSimplexMapper >::New( );
79 simplex_mapper->SetInputData( simplex );
81 vtkSmartPointer< vtkActor > simplex_actor =
82 vtkSmartPointer< vtkActor >::New( );
83 simplex_actor->SetMapper( simplex_mapper );
84 simplex_actor->GetProperty( )->SetColor( 1, 0, 0 );
85 simplex_actor->GetProperty( )->SetOpacity( 1 );
86 simplex_actor->GetProperty( )->SetLineWidth( 2 );
87 simplex_actor->GetProperty( )->SetRepresentationToWireframe( );
89 // Create visualization stuff
90 vtkSmartPointer< vtkRenderer > renderer =
91 vtkSmartPointer< vtkRenderer >::New( );
92 vtkSmartPointer< vtkRenderWindow > window =
93 vtkSmartPointer< vtkRenderWindow >::New( );
94 vtkSmartPointer< vtkRenderWindowInteractor > interactor =
95 vtkSmartPointer< vtkRenderWindowInteractor >::New( );
96 vtkInteractorStyleSwitch* iswitch =
97 dynamic_cast< vtkInteractorStyleSwitch* >(
98 interactor->GetInteractorStyle( )
100 renderer->SetBackground( 0.1, 0.3, 0.5 );
101 window->AddRenderer( renderer );
102 window->SetSize( 800, 800 );
103 window->SetInteractor( interactor );
104 if( iswitch != NULL )
105 iswitch->SetCurrentStyleToTrackballCamera( );
108 renderer->AddActor( simplex_actor );
110 // Interact for a while
111 renderer->ResetCamera( );
113 interactor->Start( );
115 // Ok, now configure deformation objects...
116 TInternalForce::Pointer int_force = TInternalForce::New( );
117 int_force->SetPhiConstraintToC0( );
119 TDeformationFilter::Pointer deform = TDeformationFilter::New( );
120 deform->AddForce( int_force, TScalar( 1 ) );
121 deform->SetDamping( TScalar( 1 ) );
122 deform->SetInput( simplex );
124 // Threaded execution...
125 vtkSmartPointer< TThreadedExecution > thread =
126 vtkSmartPointer< TThreadedExecution >::New( );
127 int thId = thread->ExecuteFilter( deform, window );
129 // ... with active interaction
130 interactor->Start( );
132 std::cout << "-----> " << thread->IsThreadActive( thId ) << std::endl;