]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/PolyLineParametricPathToPolyData.hxx
Architecture updated.
[cpPlugins.git] / lib / cpExtensions / Visualization / PolyLineParametricPathToPolyData.hxx
1 #ifndef __CPEXTENSIONS__VISUALIZATION__POLYLINEPARAMETRICPATHTOPOLYDATA__HXX__
2 #define __CPEXTENSIONS__VISUALIZATION__POLYLINEPARAMETRICPATHTOPOLYDATA__HXX__
3
4 #include <vtkCellArray.h>
5 #include <vtkInformation.h>
6 #include <vtkInformationVector.h>
7 #include <vtkSmartPointer.h>
8
9 // -------------------------------------------------------------------------
10 template< class _TPolyLine >
11 typename
12 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
13 Self*
14 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
15 New( )
16 {
17   return( new Self( ) );
18 }
19
20 // -------------------------------------------------------------------------
21 template< class _TPolyLine >
22 const typename
23 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
24 TPolyLine*
25 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
26 GetInput( ) const
27 {
28   return( this->m_PolyLine );
29 }
30
31 // -------------------------------------------------------------------------
32 template< class _TPolyLine >
33 const typename
34 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
35 TImage*
36 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
37 GetReferenceImage( ) const
38 {
39   return( this->m_ReferenceImage );
40 }
41
42 // -------------------------------------------------------------------------
43 template< class _TPolyLine >
44 void
45 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
46 SetInput( const TPolyLine* pl )
47 {
48   if( this->m_PolyLine != pl )
49   {
50     this->m_PolyLine = pl;
51     this->Modified( );
52
53   } // fi
54 }
55
56 // -------------------------------------------------------------------------
57 template< class _TPolyLine >
58 void
59 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
60 SetReferenceImage( const TImage* i )
61 {
62   if( this->m_ReferenceImage != i )
63   {
64     this->m_ReferenceImage = i;
65     this->Modified( );
66
67   } // fi
68 }
69
70 // -------------------------------------------------------------------------
71 template< class _TPolyLine >
72 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
73 PolyLineParametricPathToPolyData( )
74   : vtkPolyDataAlgorithm( ),
75     m_PolyLine( NULL ),
76     m_ReferenceImage( NULL )
77 {
78   this->SetNumberOfInputPorts( 0 );
79 }
80
81 // -------------------------------------------------------------------------
82 template< class _TPolyLine >
83 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
84 ~PolyLineParametricPathToPolyData( )
85 {
86 }
87
88 // -------------------------------------------------------------------------
89 template< class _TPolyLine >
90 int
91 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
92 RequestData(
93   vtkInformation* information,
94   vtkInformationVector** input,
95   vtkInformationVector* output
96   )
97 {
98   static const unsigned int dim = _TPolyLine::PathDimension;
99
100   if( this->m_PolyLine == NULL )
101     return( 0 );
102
103   // Get output
104   vtkInformation* info = output->GetInformationObject( 0 );
105   vtkPolyData* out = vtkPolyData::SafeDownCast(
106     info->Get( vtkDataObject::DATA_OBJECT( ) )
107     );
108
109   // Get input data
110   auto lst = this->m_PolyLine->GetVertexList( );
111
112   // Prepare points
113   vtkPoints* points = out->GetPoints( );
114   if( points == NULL )
115   {
116     points = vtkPoints::New( );
117     out->SetPoints( points );
118     points->Delete( );
119
120   } // fi
121   points->SetNumberOfPoints( lst->Size( ) );
122
123   // Prepare cells
124   /* TODO
125      vtkSmartPointer< vtkCellArray > verts =
126      vtkSmartPointer< vtkCellArray >::New( );
127   */
128   vtkSmartPointer< vtkCellArray > lines =
129     vtkSmartPointer< vtkCellArray >::New( );
130
131   for( unsigned int i = 0; i < lst->Size( ); ++i )
132   {
133     auto idx = lst->GetElement( i );
134     if( this->m_ReferenceImage != NULL )
135     {
136       typename TImage::PointType pnt;
137       this->m_ReferenceImage->TransformContinuousIndexToPhysicalPoint( idx, pnt );
138       if( dim == 1 )
139         points->SetPoint( i, pnt[ 0 ], 0, 0 );
140       else if( dim == 2 )
141         points->SetPoint( i, pnt[ 0 ], pnt[ 1 ], 0 );
142       else
143         points->SetPoint( i, pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] );
144     }
145     else
146     {
147       if( dim == 1 )
148         points->SetPoint( i, idx[ 0 ], 0, 0 );
149       else if( dim == 2 )
150         points->SetPoint( i, idx[ 0 ], idx[ 1 ], 0 );
151       else
152         points->SetPoint( i, idx[ 0 ], idx[ 1 ], idx[ 2 ] );
153
154     } // fi
155     /* TODO
156        verts->InsertNextCell( 1 );
157        verts->InsertCellPoint( i );
158     */
159     if( i > 0 )
160     {
161       lines->InsertNextCell( 2 );
162       lines->InsertCellPoint( i - 1 );
163       lines->InsertCellPoint( i );
164
165     } // fi
166
167   } // rof
168   out->SetPoints( points );
169   // TODO: out->SetVerts( verts );
170   out->SetLines( lines );
171   return( 1 );
172 }
173
174 // -------------------------------------------------------------------------
175 template< class _TPolyLine >
176 int
177 cpExtensions::Visualization::PolyLineParametricPathToPolyData< _TPolyLine >::
178 RequestInformation(
179   vtkInformation* information,
180   vtkInformationVector** input,
181   vtkInformationVector* output
182   )
183 {
184   vtkInformation* info = output->GetInformationObject( 0 );
185   /* TODO
186      info->Set(
187      vtkStreamingDemandDrivenPipeline::MAXIMUM_NUMBER_OF_PIECES( ), -1
188      );
189   */
190
191   if( this->m_PolyLine != NULL && this->m_ReferenceImage != NULL )
192   {
193     /* TODO
194        typename C::TScalar len = this->m_RGC->GetTotalLength( );
195        typename C::TScalar s0 = this->m_RGC->Gets0( );
196        typename C::TPoint p0 = this->m_RGC->Axis( s0 );
197        typename C::TPoint p1 = this->m_RGC->Axis( s0 + len );
198
199        info->Set(
200        vtkStreamingDemandDrivenPipeline::WHOLE_BOUNDING_BOX( ),
201        double( p0[ 0 ] ), double( p1[ 0 ] ),
202        double( p0[ 1 ] ), double( p1[ 1 ] ),
203        double( p0[ 2 ] ), double( p1[ 2 ] )
204        );
205     */
206
207   } // fi
208   return( 1 );
209 }
210
211 #endif //  __CPEXTENSIONS__VISUALIZATION__POLYLINEPARAMETRICPATHTOPOLYDATA__HXX__
212
213 // eof - $RCSfile$