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