]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/VTK/PointPathToPolyDataFilter.hxx
a79c7633ab86f7f8fa95f796441d1ec5442a54cd
[FrontAlgorithms.git] / lib / fpa / VTK / PointPathToPolyDataFilter.hxx
1 #ifndef __FPA__VTK__POINTPATHTOPOLYDATAFILTER__HXX__
2 #define __FPA__VTK__POINTPATHTOPOLYDATAFILTER__HXX__
3
4 #include <vtkInformation.h>
5 #include <vtkInformationVector.h>
6
7 // -------------------------------------------------------------------------
8 template< class C >
9 typename fpa::VTK::PointPathToPolyDataFilter< C >::
10 Self* fpa::VTK::PointPathToPolyDataFilter< C >::
11 New( )
12 {
13   return( new Self( ) );
14 }
15
16 // -------------------------------------------------------------------------
17 template< class C >
18 const C* fpa::VTK::PointPathToPolyDataFilter< C >::
19 GetInput( ) const
20 {
21   return( this->m_Container );
22 }
23
24 // -------------------------------------------------------------------------
25 template< class C >
26 void fpa::VTK::PointPathToPolyDataFilter< C >::
27 SetInput( const C* c )
28 {
29   if( this->m_Container != c )
30   {
31     this->m_Container = c;
32     this->Modified( );
33
34   } // fi
35 }
36
37 // -------------------------------------------------------------------------
38 template< class C >
39 fpa::VTK::PointPathToPolyDataFilter< C >::
40 PointPathToPolyDataFilter( )
41   : vtkPolyDataAlgorithm( ),
42     m_Container( NULL )
43 {
44   this->SetNumberOfInputPorts( 0 );
45 }
46
47 // -------------------------------------------------------------------------
48 template< class C >
49 fpa::VTK::PointPathToPolyDataFilter< C >::
50 ~PointPathToPolyDataFilter( )
51 {
52 }
53
54 // -------------------------------------------------------------------------
55 template< class C >
56 int fpa::VTK::PointPathToPolyDataFilter< C >::
57 RequestData(
58   vtkInformation* information,
59   vtkInformationVector** input,
60   vtkInformationVector* output
61   )
62 {
63   if( this->m_Container == NULL )
64     return( 0 );
65
66   // Get output
67   vtkInformation* info = output->GetInformationObject( 0 );
68   vtkPolyData* out = vtkPolyData::SafeDownCast(
69     info->Get( vtkDataObject::DATA_OBJECT( ) )
70     );
71
72   // Prepare points
73   vtkPoints* points = out->GetPoints( );
74   if( points == NULL )
75   {
76     points = vtkPoints::New( );
77     out->SetPoints( points );
78     points->Delete( );
79
80   } // fi
81   points->SetNumberOfPoints( this->m_Container->size( ) );
82
83   // Prepare cells
84   vtkSmartPointer< vtkCellArray > cells =
85     vtkSmartPointer< vtkCellArray >::New( );
86
87   unsigned int pId = 0;
88   for(
89     typename C::const_iterator it = this->m_Container->begin( );
90     it != this->m_Container->end( );
91     ++it, ++pId
92     )
93   {
94     TPoint pnt = *it;
95     if( TPoint::Dimension == 1 )
96       points->SetPoint( pId, pnt[ 0 ], 0, 0 );
97     else if( TPoint::Dimension == 2 )
98       points->SetPoint( pId, pnt[ 0 ], pnt[ 1 ], 0 );
99     else
100       points->SetPoint( pId, pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );
101
102     cells->InsertNextCell( 1 );
103     cells->InsertCellPoint( pId );
104
105   } // rof
106   out->SetPoints( points );
107   out->SetVerts( cells );
108   return( 1 );
109 }
110
111 // -------------------------------------------------------------------------
112 template< class C >
113 int fpa::VTK::PointPathToPolyDataFilter< C >::
114 RequestInformation(
115   vtkInformation* information,
116   vtkInformationVector** input,
117   vtkInformationVector* output
118   )
119 {
120   vtkInformation* info = output->GetInformationObject( 0 );
121   /* TODO
122      info->Set(
123      vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES( ), -1
124      );
125   */
126
127   if( this->m_Container != NULL )
128   {
129     /* TODO
130        typename C::TScalar len = this->m_RGC->GetTotalLength( );
131        typename C::TScalar s0 = this->m_RGC->Gets0( );
132        typename C::TPoint p0 = this->m_RGC->Axis( s0 );
133        typename C::TPoint p1 = this->m_RGC->Axis( s0 + len );
134
135        info->Set(
136        vtkStreamingDemandDrivenPipeline::WHOLE_BOUNDING_BOX( ),
137        double( p0[ 0 ] ), double( p1[ 0 ] ),
138        double( p0[ 1 ] ), double( p1[ 1 ] ),
139        double( p0[ 2 ] ), double( p1[ 2 ] )
140        );
141     */
142
143   } // fi
144   return( 1 );
145 }
146
147 #endif // __FPA__VTK__POINTPATHTOPOLYDATAFILTER__HXX__
148
149 // eof - $RCSfile$