]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/Visualization/ImageBlender.cxx
OpenGL with opaque binary image... Soon to be plural
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageBlender.cxx
1 #include <cpExtensions/Visualization/ImageBlender.h>
2
3 #include <vtkDataObject.h>
4 #include <vtkImageData.h>
5 #include <vtkImageIterator.h>
6 #include <vtkImageProgressIterator.h>
7 #include <vtkInformation.h>
8 #include <vtkInformationVector.h>
9
10 // -------------------------------------------------------------------------
11 cpExtensions::Visualization::ImageBlender::
12 Self* cpExtensions::Visualization::ImageBlender::
13 New( )
14 {
15   return( new Self( ) );
16 }
17
18
19 // -------------------------------------------------------------------------
20 cpExtensions::Visualization::ImageBlender::
21 ImageBlender( )
22   : Superclass( )
23 {
24   this->SetNumberOfInputPorts( 1 );
25 }
26
27 // -------------------------------------------------------------------------
28 cpExtensions::Visualization::ImageBlender::
29 ~ImageBlender( )
30 {
31 }
32
33 // -------------------------------------------------------------------------
34 int cpExtensions::Visualization::ImageBlender::
35 RequestInformation(
36   vtkInformation* request,
37   vtkInformationVector** inputVector,
38   vtkInformationVector* outputVector
39   )
40 {
41   if( this->GetNumberOfInputConnections( 0 ) == 0 )
42     return( 0 );
43
44   vtkDataObject::SetPointDataActiveScalarInfo(
45     outputVector->GetInformationObject( 0 ),
46     VTK_UNSIGNED_CHAR,
47     1
48     );
49   return( 1 );
50 }
51
52 // -------------------------------------------------------------------------
53 // Description:
54 // This templated function executes the filter for any type of data.
55 template< class T >
56 void cpExtensions_Visualization_ImageBlender_Execute(
57   cpExtensions::Visualization::ImageBlender* self,
58   vtkImageData** inDatas, int numInputs, vtkImageData* outData,
59   int outExt[ 6 ], int id, T* really_not_used
60   )
61 {
62   vtkImageIterator< T > inItsFast[ 256 ];
63   T* inSIFast[ 256 ];
64   vtkImageProgressIterator< T > outIt( outData, outExt, self, id );
65   vtkImageIterator< T >* inIts;
66   T** inSI;
67   if( numInputs < 256 )
68   {
69     inIts = inItsFast;
70     inSI = inSIFast;
71   }
72   else
73   {
74     inIts = new vtkImageIterator< T >[ numInputs ];
75     inSI = new T*[ numInputs ];
76
77   } // fi
78
79   // Loop through all input ImageData to initialize iterators
80   for( int i = 0; i < numInputs; ++i )
81     inIts[ i ].Initialize( inDatas[ i ], outExt );
82
83   // Loop through output pixels
84   while( !outIt.IsAtEnd( ) )
85   {
86     for( int j = 0; j < numInputs; ++j )
87       inSI[ j ] = inIts[ j ].BeginSpan( );
88
89     T* outSI = outIt.BeginSpan( );
90     T* outSIEnd = outIt.EndSpan( );
91
92     // Pixel operation
93     while( outSI != outSIEnd )
94     {
95 #error TENER EN CUENTA EL ORDEN DE LAS IMAGENES PARA PONER COLORES
96
97       double vmax = double( *inSI[ 0 ] );
98       for( int k = 1; k < numInputs; ++k )
99         vmax = ( vmax < double( *inSI[ k ] ) )? double( *inSI[ k ] ): vmax;
100       *outSI = static_cast< T >( vmax );
101       outSI++;
102       for( int l = 0; l < numInputs; ++l )
103         inSI[ l ]++;
104
105     } // elihw
106     for( int j = 0; j < numInputs; ++j )
107       inIts[ j ].NextSpan( );
108     outIt.NextSpan( );
109
110   } // elihw
111
112   if( numInputs >= 256)
113   {
114     delete [] inIts;
115     delete [] inSI;
116
117   } // fi
118 }
119
120 // -------------------------------------------------------------------------
121 void cpExtensions::Visualization::ImageBlender::
122 ThreadedRequestData(
123   vtkInformation* request,
124   vtkInformationVector** inputVector,
125   vtkInformationVector* outputVector,
126   vtkImageData*** inData, vtkImageData** outData,
127   int outExt[ 6 ], int id
128   )
129 {
130   if( inData[ 0 ][ 0 ] == NULL )
131   {
132     vtkErrorMacro( << "Input " << 0 << " must be specified." );
133     return;
134
135   } // fi
136
137   int numInputs = this->GetNumberOfInputConnections( 0 );
138   int scalarType = inData[ 0 ][ 0 ]->GetScalarType( );
139   int numComp = inData[ 0 ][ 0 ]->GetNumberOfScalarComponents( );
140   for( int i = 1; i < numInputs; ++i )
141   {
142     int otherType = inData[ 0 ][ i ]->GetScalarType( );
143     int otherComp = inData[ 0 ][ i ]->GetNumberOfScalarComponents( );
144     if( otherType != scalarType || otherComp != numComp )
145     {
146       if( id == 0 )
147         vtkErrorMacro(
148           "ThreadedRequestData: Input " << i
149           << " has " << otherComp << " components of type "
150           << otherType << ", but input 0 has " << numComp
151           << " components of type " << scalarType
152           );
153       return;
154
155     } // fi
156
157   } // rof
158
159   switch( scalarType )
160   {
161     vtkTemplateMacro(
162       cpExtensions_Visualization_ImageBlender_Execute(
163         this, inData[ 0 ], numInputs,
164         outData[ 0 ], outExt, id, static_cast< VTK_TT* >( 0 )
165         )
166       );
167   default:
168     if( id == 0 )
169       vtkErrorMacro( << "Execute: Unknown ScalarType" );
170     return;
171   } // hctiws
172 }
173
174 // -------------------------------------------------------------------------
175 int cpExtensions::Visualization::ImageBlender::
176 FillInputPortInformation( int i, vtkInformation* info )
177 {
178   info->Set( vtkAlgorithm::INPUT_IS_REPEATABLE( ), 1 );
179   return( this->Superclass::FillInputPortInformation( i,info ) );
180 }
181
182 // eof - $RCSfile$