]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/VTK/UniqueVerticesToPolyDataFilter.hxx
c2d2629b794222b4dc8645a9ba300154ea9c5898
[FrontAlgorithms.git] / lib / fpa / VTK / UniqueVerticesToPolyDataFilter.hxx
1 #ifndef __FPA__VTK__UNIQUEVERTICESTOPOLYDATAFILTER__HXX__
2 #define __FPA__VTK__UNIQUEVERTICESTOPOLYDATAFILTER__HXX__
3
4 #include <vtkInformation.h>
5 #include <vtkInformationVector.h>
6
7 // -------------------------------------------------------------------------
8 template< class U, class I >
9 typename fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >::
10 Self* fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >::
11 New( )
12 {
13   return( new Self( ) );
14 }
15
16 // -------------------------------------------------------------------------
17 template< class U, class I >
18 const U* fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >::
19 GetInput( ) const
20 {
21   return( this->m_Container );
22 }
23
24 // -------------------------------------------------------------------------
25 template< class U, class I >
26 void fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >::
27 SetInput( const U* c )
28 {
29   if( this->m_Container.GetPointer( ) != c )
30   {
31     this->m_Container = c;
32     this->m_LastContainerModifiedTime = this->m_Container->GetMTime( );
33     this->Modified( );
34
35   } // fi
36 }
37
38 // -------------------------------------------------------------------------
39 template< class U, class I >
40 const I* fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >::
41 GetImage( ) const
42 {
43   return( this->m_Image );
44 }
45
46 // -------------------------------------------------------------------------
47 template< class U, class I >
48 void fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >::
49 SetImage( const I* i )
50 {
51   if( this->m_Image.GetPointer( ) != i )
52   {
53     this->m_Image = i;
54     this->Modified( );
55
56   } // fi
57 }
58
59 // -------------------------------------------------------------------------
60 template< class U, class I >
61 unsigned long fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >::
62 GetMTime( )
63 {
64   unsigned long ctime = this->m_Container->GetMTime( );
65   if( ctime > this->m_LastContainerModifiedTime )
66   {
67     this->m_LastContainerModifiedTime = ctime;
68     this->Modified( );
69
70   } // fi
71   return( this->Superclass::GetMTime( ) );
72 }
73
74 // -------------------------------------------------------------------------
75 template< class U, class I >
76 fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >::
77 UniqueVerticesToPolyDataFilter( )
78   : vtkPolyDataAlgorithm( )
79 {
80   this->SetNumberOfInputPorts( 0 );
81 }
82
83 // -------------------------------------------------------------------------
84 template< class U, class I >
85 fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >::
86 ~UniqueVerticesToPolyDataFilter( )
87 {
88 }
89
90 // -------------------------------------------------------------------------
91 template< class U, class I >
92 int fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >::
93 RequestData(
94   vtkInformation* information,
95   vtkInformationVector** input,
96   vtkInformationVector* output
97   )
98 {
99   if( this->m_Container.IsNull( ) || this->m_Image.IsNull( ) )
100     return( 0 );
101
102   // Get output
103   vtkInformation* info = output->GetInformationObject( 0 );
104   vtkPolyData* out = vtkPolyData::SafeDownCast(
105     info->Get( vtkDataObject::DATA_OBJECT( ) )
106     );
107
108   // Prepare points
109   vtkPoints* points = out->GetPoints( );
110   if( points == NULL )
111   {
112     points = vtkPoints::New( );
113     out->SetPoints( points );
114     points->Delete( );
115
116   } // fi
117   points->SetNumberOfPoints( this->m_Container->Size( ) );
118
119   // Prepare cells
120   vtkSmartPointer< vtkCellArray > cells =
121     vtkSmartPointer< vtkCellArray >::New( );
122
123   unsigned int pId = 0;
124   for(
125     typename U::ConstIterator it = this->m_Container->Begin( );
126     it != this->m_Container->End( );
127     ++it, ++pId
128     )
129   {
130     typename I::PointType pnt;
131     this->m_Image->TransformIndexToPhysicalPoint( *it, pnt );
132     if( I::ImageDimension == 1 )
133       points->SetPoint( pId, pnt[ 0 ], 0, 0 );
134     else if( I::ImageDimension == 2 )
135       points->SetPoint( pId, pnt[ 0 ], pnt[ 1 ], 0 );
136     else
137       points->SetPoint( pId, pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );
138
139     cells->InsertNextCell( 1 );
140     cells->InsertCellPoint( pId );
141
142   } // rof
143   out->SetPoints( points );
144   out->SetVerts( cells );
145   return( 1 );
146 }
147
148 // -------------------------------------------------------------------------
149 template< class U, class I >
150 int fpa::VTK::UniqueVerticesToPolyDataFilter< U, I >::
151 RequestInformation(
152   vtkInformation* information,
153   vtkInformationVector** input,
154   vtkInformationVector* output
155   )
156 {
157   vtkInformation* info = output->GetInformationObject( 0 );
158   /* TODO
159      info->Set(
160      vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES( ), -1
161      );
162   */
163
164   if( this->m_Container.IsNotNull( ) && this->m_Image.IsNotNull( ) )
165   {
166     /* TODO
167        typename C::TScalar len = this->m_RGC->GetTotalLength( );
168        typename C::TScalar s0 = this->m_RGC->Gets0( );
169        typename C::TPoint p0 = this->m_RGC->Axis( s0 );
170        typename C::TPoint p1 = this->m_RGC->Axis( s0 + len );
171
172        info->Set(
173        vtkStreamingDemandDrivenPipeline::WHOLE_BOUNDING_BOX( ),
174        double( p0[ 0 ] ), double( p1[ 0 ] ),
175        double( p0[ 1 ] ), double( p1[ 1 ] ),
176        double( p0[ 2 ] ), double( p1[ 2 ] )
177        );
178     */
179
180   } // fi
181   return( 1 );
182 }
183
184 #endif // __FPA__VTK__UNIQUEVERTICESTOPOLYDATAFILTER__HXX__
185
186 // eof - $RCSfile$