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