]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Visualization/ImageBlender.cxx
Some bugs...
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageBlender.cxx
index ee4f61642ab9e7c12a330cdfefde657b81528de3..44a08abc90c9f169d7dd89661b3c82c6dfda4ded 100644 (file)
@@ -15,6 +15,16 @@ New( )
   return( new Self( ) );
 }
 
+// -------------------------------------------------------------------------
+unsigned int cpExtensions::Visualization::ImageBlender::
+GetNumberOfInputs( )
+{
+  unsigned int np = this->GetNumberOfInputPorts( );
+  unsigned int ni = 0;
+  for( unsigned int p = 0; p < np; ++p )
+    ni += this->GetNumberOfInputConnections( p );
+  return( ni );
+}
 
 // -------------------------------------------------------------------------
 cpExtensions::Visualization::ImageBlender::
@@ -49,13 +59,54 @@ RequestInformation(
   return( 1 );
 }
 
+// -------------------------------------------------------------------------
+int cpExtensions::Visualization::ImageBlender::
+RequestData(
+  vtkInformation* request,
+  vtkInformationVector** inputVector,
+  vtkInformationVector* outputVector
+  )
+{
+  this->m_Ranges.clear( );
+  for( int i = 0; i < this->GetNumberOfInputPorts( ); ++i )
+  {
+    vtkInformationVector* portInfo = inputVector[ i ];
+    for( int j = 0; j < portInfo->GetNumberOfInformationObjects( ); ++j )
+    {
+      vtkInformation* info = portInfo->GetInformationObject( j );
+      vtkImageData* image = vtkImageData::SafeDownCast(
+        info->Get( vtkDataObject::DATA_OBJECT( ) )
+        );
+      if( image != NULL )
+      {
+        double r[ 2 ];
+        image->GetScalarRange( r );
+        this->m_Ranges.push_back( r[ 0 ] );
+        this->m_Ranges.push_back( r[ 1 ] );
+      }
+      else
+      {
+        this->m_Ranges.push_back( double( 0 ) );
+        this->m_Ranges.push_back( double( 0 ) );
+
+      } // fi
+
+    } // rof
+
+  } // rof
+  return(
+    this->Superclass::RequestData( request, inputVector, outputVector )
+    );
+}
+
 // -------------------------------------------------------------------------
 // Description:
 // This templated function executes the filter for any type of data.
 template< class T >
 void cpExtensions_Visualization_ImageBlender_Execute(
   cpExtensions::Visualization::ImageBlender* self,
-  vtkImageData** inDatas, int numInputs, vtkImageData* outData,
+  vtkImageData** inDatas, int numInputs,
+  const std::vector< double >& ranges, vtkImageData* outData,
   int outExt[ 6 ], int id, T* really_not_used
   )
 {
@@ -92,11 +143,17 @@ void cpExtensions_Visualization_ImageBlender_Execute(
     // Pixel operation
     while( outSI != outSIEnd )
     {
-#error TENER EN CUENTA EL ORDEN DE LAS IMAGENES PARA PONER COLORES
-
-      double vmax = double( *inSI[ 0 ] );
+      // Input 0 is ignored: it is just used to guarantee sizes all over
+      // the result
+      double vmax = double( 0 );
       for( int k = 1; k < numInputs; ++k )
-        vmax = ( vmax < double( *inSI[ k ] ) )? double( *inSI[ k ] ): vmax;
+      {
+        double v =
+          ( ( double( k ) * double( *inSI[ k ] ) ) - ranges[ k << 1 ] ) /
+          ( ranges[ ( k << 1 ) + 1 ] - ranges[ k << 1 ] );
+        vmax = ( vmax < v )? v: vmax;
+
+      } // rof
       *outSI = static_cast< T >( vmax );
       outSI++;
       for( int l = 0; l < numInputs; ++l )
@@ -160,7 +217,7 @@ ThreadedRequestData(
   {
     vtkTemplateMacro(
       cpExtensions_Visualization_ImageBlender_Execute(
-        this, inData[ 0 ], numInputs,
+        this, inData[ 0 ], numInputs, this->m_Ranges,
         outData[ 0 ], outExt, id, static_cast< VTK_TT* >( 0 )
         )
       );