]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/ImageOutlineSource.cxx
yet another refactoring
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageOutlineSource.cxx
1 #include <cpExtensions/Visualization/ImageOutlineSource.h>
2 #include <vtkInformation.h>
3 #include <vtkInformationVector.h>
4
5 // -------------------------------------------------------------------------
6 cpExtensions::Visualization::ImageOutlineSource::
7 Self* cpExtensions::Visualization::ImageOutlineSource::
8 New( )
9 {
10   return( new Self( ) );
11 }
12
13 // -------------------------------------------------------------------------
14 void cpExtensions::Visualization::ImageOutlineSource::
15 SetBounds( int orientation, double step, double* bounds )
16 {
17   // Update geometry
18   int o = orientation % 3;
19   if( o == 0 )
20   {
21     this->m_Bounds[ 0 ][ 0 ] = step;
22     this->m_Bounds[ 0 ][ 1 ] = bounds[ 2 ];
23     this->m_Bounds[ 0 ][ 2 ] = bounds[ 4 ];
24
25     this->m_Bounds[ 1 ][ 0 ] = step;
26     this->m_Bounds[ 1 ][ 1 ] = bounds[ 2 ];
27     this->m_Bounds[ 1 ][ 2 ] = bounds[ 5 ];
28
29     this->m_Bounds[ 2 ][ 0 ] = step;
30     this->m_Bounds[ 2 ][ 1 ] = bounds[ 3 ];
31     this->m_Bounds[ 2 ][ 2 ] = bounds[ 5 ];
32
33     this->m_Bounds[ 3 ][ 0 ] = step;
34     this->m_Bounds[ 3 ][ 1 ] = bounds[ 3 ];
35     this->m_Bounds[ 3 ][ 2 ] = bounds[ 4 ];
36   }
37   else if( o == 1 )
38   {
39     this->m_Bounds[ 0 ][ 0 ] = bounds[ 0 ];
40     this->m_Bounds[ 0 ][ 1 ] = step;
41     this->m_Bounds[ 0 ][ 2 ] = bounds[ 4 ];
42
43     this->m_Bounds[ 1 ][ 0 ] = bounds[ 1 ];
44     this->m_Bounds[ 1 ][ 1 ] = step;
45     this->m_Bounds[ 1 ][ 2 ] = bounds[ 4 ];
46
47     this->m_Bounds[ 2 ][ 0 ] = bounds[ 1 ];
48     this->m_Bounds[ 2 ][ 1 ] = step;
49     this->m_Bounds[ 2 ][ 2 ] = bounds[ 5 ];
50
51     this->m_Bounds[ 3 ][ 0 ] = bounds[ 0 ];
52     this->m_Bounds[ 3 ][ 1 ] = step;
53     this->m_Bounds[ 3 ][ 2 ] = bounds[ 5 ];
54   }
55   else if( o == 2 )
56   {
57     this->m_Bounds[ 0 ][ 0 ] = bounds[ 0 ];
58     this->m_Bounds[ 0 ][ 1 ] = bounds[ 2 ];
59     this->m_Bounds[ 0 ][ 2 ] = step;
60
61     this->m_Bounds[ 1 ][ 0 ] = bounds[ 1 ];
62     this->m_Bounds[ 1 ][ 1 ] = bounds[ 2 ];
63     this->m_Bounds[ 1 ][ 2 ] = step;
64
65     this->m_Bounds[ 2 ][ 0 ] = bounds[ 1 ];
66     this->m_Bounds[ 2 ][ 1 ] = bounds[ 3 ];
67     this->m_Bounds[ 2 ][ 2 ] = step;
68
69     this->m_Bounds[ 3 ][ 0 ] = bounds[ 0 ];
70     this->m_Bounds[ 3 ][ 1 ] = bounds[ 3 ];
71     this->m_Bounds[ 3 ][ 2 ] = step;
72
73   } // fi
74   this->Modified( );
75 }
76
77 // -------------------------------------------------------------------------
78 cpExtensions::Visualization::ImageOutlineSource::
79 ImageOutlineSource( )
80   : Superclass( )
81 {
82   this->SetNumberOfInputPorts( 0 );
83   for( unsigned int j = 0; j < 4; ++j )
84     for( unsigned int i = 0; i < 3; ++i )
85       this->m_Bounds[ j ][ i ] = double( 0 );
86 }
87
88 // -------------------------------------------------------------------------
89 cpExtensions::Visualization::ImageOutlineSource::
90 ~ImageOutlineSource( )
91 {
92 }
93
94 // -------------------------------------------------------------------------
95 int cpExtensions::Visualization::ImageOutlineSource::
96 RequestData(
97   vtkInformation* request,
98   vtkInformationVector** inputVector,
99   vtkInformationVector* outputVector
100   )
101 {
102   // Get output object
103   vtkInformation* outInfo = outputVector->GetInformationObject( 0 );
104   vtkPolyData* output =
105     vtkPolyData::SafeDownCast(
106       outInfo->Get( vtkDataObject::DATA_OBJECT( ) )
107       );
108
109   // Create points
110   vtkPoints* points = vtkPoints::New( );
111   points->SetDataType( VTK_FLOAT );
112   points->Allocate( 4 );
113
114   // Create lines
115   vtkCellArray* verts = vtkCellArray::New( );
116   vtkCellArray* lines = vtkCellArray::New( );
117   vtkCellArray* faces = vtkCellArray::New( );
118   vtkCellArray* strips = vtkCellArray::New( );
119   lines->Allocate( lines->EstimateSize( 4, 2 ) );
120
121   // Assign points
122   points->InsertPoint( 0, this->m_Bounds[ 0 ] );
123   points->InsertPoint( 1, this->m_Bounds[ 1 ] );
124   points->InsertPoint( 2, this->m_Bounds[ 2 ] );
125   points->InsertPoint( 3, this->m_Bounds[ 3 ] );
126
127   // Assign cells
128   vtkIdType cell_pts[ 4 ][ 2 ] =
129   {
130     { 0, 1 },
131     { 1, 2 },
132     { 2, 3 },
133     { 3, 0 }
134   };
135   lines->InsertNextCell( 2, cell_pts[ 0 ] );
136   lines->InsertNextCell( 2, cell_pts[ 1 ] );
137   lines->InsertNextCell( 2, cell_pts[ 2 ] );
138   lines->InsertNextCell( 2, cell_pts[ 3 ] );
139
140   // Assign to output
141   output->SetPoints( points );
142   output->SetVerts( verts );
143   output->SetLines( lines );
144   output->SetPolys( faces );
145   output->SetStrips( strips );
146
147   // Finish and return
148   points->Delete( );
149   verts->Delete( );
150   lines->Delete( );
151   faces->Delete( );
152   strips->Delete( );
153   return( 1 );
154 }
155
156 // eof - $RCSfile$