1 #include <cpExtensions/Visualization/ImageBlender.h>
3 #include <vtkDataObject.h>
4 #include <vtkImageData.h>
5 #include <vtkImageIterator.h>
6 #include <vtkImageProgressIterator.h>
7 #include <vtkInformation.h>
8 #include <vtkInformationVector.h>
10 // -------------------------------------------------------------------------
11 cpExtensions::Visualization::ImageBlender::
12 Self* cpExtensions::Visualization::ImageBlender::
15 return( new Self( ) );
19 // -------------------------------------------------------------------------
20 cpExtensions::Visualization::ImageBlender::
24 this->SetNumberOfInputPorts( 1 );
27 // -------------------------------------------------------------------------
28 cpExtensions::Visualization::ImageBlender::
33 // -------------------------------------------------------------------------
34 int cpExtensions::Visualization::ImageBlender::
36 vtkInformation* request,
37 vtkInformationVector** inputVector,
38 vtkInformationVector* outputVector
41 if( this->GetNumberOfInputConnections( 0 ) == 0 )
44 vtkDataObject::SetPointDataActiveScalarInfo(
45 outputVector->GetInformationObject( 0 ),
52 // -------------------------------------------------------------------------
54 // This templated function executes the filter for any type of data.
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
62 vtkImageIterator< T > inItsFast[ 256 ];
64 vtkImageProgressIterator< T > outIt( outData, outExt, self, id );
65 vtkImageIterator< T >* inIts;
74 inIts = new vtkImageIterator< T >[ numInputs ];
75 inSI = new T*[ numInputs ];
79 // Loop through all input ImageData to initialize iterators
80 for( int i = 0; i < numInputs; ++i )
81 inIts[ i ].Initialize( inDatas[ i ], outExt );
83 // Loop through output pixels
84 while( !outIt.IsAtEnd( ) )
86 for( int j = 0; j < numInputs; ++j )
87 inSI[ j ] = inIts[ j ].BeginSpan( );
89 T* outSI = outIt.BeginSpan( );
90 T* outSIEnd = outIt.EndSpan( );
93 while( outSI != outSIEnd )
95 #error TENER EN CUENTA EL ORDEN DE LAS IMAGENES PARA PONER COLORES
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 );
102 for( int l = 0; l < numInputs; ++l )
106 for( int j = 0; j < numInputs; ++j )
107 inIts[ j ].NextSpan( );
112 if( numInputs >= 256)
120 // -------------------------------------------------------------------------
121 void cpExtensions::Visualization::ImageBlender::
123 vtkInformation* request,
124 vtkInformationVector** inputVector,
125 vtkInformationVector* outputVector,
126 vtkImageData*** inData, vtkImageData** outData,
127 int outExt[ 6 ], int id
130 if( inData[ 0 ][ 0 ] == NULL )
132 vtkErrorMacro( << "Input " << 0 << " must be specified." );
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 )
142 int otherType = inData[ 0 ][ i ]->GetScalarType( );
143 int otherComp = inData[ 0 ][ i ]->GetNumberOfScalarComponents( );
144 if( otherType != scalarType || otherComp != numComp )
148 "ThreadedRequestData: Input " << i
149 << " has " << otherComp << " components of type "
150 << otherType << ", but input 0 has " << numComp
151 << " components of type " << scalarType
162 cpExtensions_Visualization_ImageBlender_Execute(
163 this, inData[ 0 ], numInputs,
164 outData[ 0 ], outExt, id, static_cast< VTK_TT* >( 0 )
169 vtkErrorMacro( << "Execute: Unknown ScalarType" );
174 // -------------------------------------------------------------------------
175 int cpExtensions::Visualization::ImageBlender::
176 FillInputPortInformation( int i, vtkInformation* info )
178 info->Set( vtkAlgorithm::INPUT_IS_REPEATABLE( ), 1 );
179 return( this->Superclass::FillInputPortInformation( i,info ) );