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