]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Plugins/BasicFilters/Cutter.cxx
0ae95d51673527840f7336efe16563744cb247ad
[cpPlugins.git] / lib / cpPlugins / Plugins / BasicFilters / Cutter.cxx
1 #include "Cutter.h"
2 #include <cpPlugins/Interface/ImplicitFunction.h>
3 #include <cpPlugins/Interface/Mesh.h>
4
5 #include <vtkCutter.h>
6 #include <vtkProperty.h>
7
8 // -------------------------------------------------------------------------
9 vtkAlgorithm* cpPlugins::BasicFilters::Cutter::
10 GetVTKAlgorithm( )
11 {
12   return( this->m_Algorithm );
13 }
14
15 // -------------------------------------------------------------------------
16 const vtkAlgorithm* cpPlugins::BasicFilters::Cutter::
17 GetVTKAlgorithm( ) const
18 {
19   return( this->m_Algorithm );
20 }
21
22 // -------------------------------------------------------------------------
23 cpPlugins::BasicFilters::Cutter::
24 Cutter( )
25   : Superclass( ),
26     m_Algorithm( NULL )
27 {
28   this->m_ClassName = "cpPlugins::BasicFilters::Cutter";
29   this->m_ClassCategory = "MeshToMeshFilter";
30
31   this->SetNumberOfInputs( 2 );
32   this->SetNumberOfOutputs( 1 );
33   this->_MakeOutput< cpPlugins::Interface::Mesh >( 0 );
34
35   this->m_Parameters = this->m_DefaultParameters;
36 }
37
38 // -------------------------------------------------------------------------
39 cpPlugins::BasicFilters::Cutter::
40 ~Cutter( )
41 {
42   if( this->m_Algorithm != NULL )
43     this->m_Algorithm->Delete( );
44 }
45
46 // -------------------------------------------------------------------------
47 std::string cpPlugins::BasicFilters::Cutter::
48 _GenerateData( )
49 {
50   // Get inputs
51   cpPlugins::Interface::Mesh* mesh =
52     this->GetInput< cpPlugins::Interface::Mesh >( 0 );
53   cpPlugins::Interface::ImplicitFunction* function =
54     this->GetInput< cpPlugins::Interface::ImplicitFunction >( 1 );
55   if( function == NULL )
56     return( "Cutter: Input data 1 is not a valid implicit function." );
57
58   if( this->m_Algorithm != NULL )
59     this->m_Algorithm->Delete( );
60
61   vtkCutter* cutter = vtkCutter::New( );
62   cutter->SetInputData( mesh->GetVTKMesh( ) );
63   cutter->SetCutFunction( function->GetVTKImplicitFunction( ) );
64   cutter->GenerateTrianglesOff( );
65   this->m_Algorithm = cutter;
66
67   // Execute filter
68   this->m_Algorithm->Update( );
69   cpPlugins::Interface::Mesh* out =
70     this->GetOutput< cpPlugins::Interface::Mesh >( 0 );
71   out->SetVTKMesh( this->m_Algorithm->GetOutput( ) );
72
73   return( "" );
74 }
75
76 // eof - $RCSfile$