]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/Visualization/ImageBlender.cxx
...
[cpPlugins.git] / lib / cpExtensions / Visualization / ImageBlender.cxx
index 6714d55d3e246efe0d4356a625b315ae43a13335..49292c8dfaa61bc230ce2d1a8581ecd59b02652e 100644 (file)
@@ -1,6 +1,5 @@
 #include <cpExtensions/Visualization/ImageBlender.h>
 
-#include <cmath>
 #include <cstring>
 
 #include <vtkDataObject.h>
@@ -26,8 +25,8 @@ PrintSelf( std::ostream& os, vtkIndent indent )
 
   // Objects
   os << indent << "Colors: " << std::endl;
-  auto i = this->m_Colors.begin( );
-  for( ; i != this->m_Colors.end( ); ++i )
+  auto i = this->Colors.begin( );
+  for( ; i != this->Colors.end( ); ++i )
     os
       << indent << indent << i->first << " : ["
       << i->second.R << ", "
@@ -40,73 +39,9 @@ PrintSelf( std::ostream& os, vtkIndent indent )
 unsigned int cpExtensions::Visualization::ImageBlender::
 GetNumberOfImages( ) const
 {
-  return( ( const_cast< Self* >( this ) )->GetNumberOfInputConnections( 0 ) );
-}
-
-// -------------------------------------------------------------------------
-const double& cpExtensions::Visualization::ImageBlender::
-GetMaxWindow( ) const
-{
-  return( this->m_MaxWindow );
-}
-
-// -------------------------------------------------------------------------
-const double& cpExtensions::Visualization::ImageBlender::
-GetMaxLevel( ) const
-{
-  return( this->m_MaxLevel );
-}
-
-// -------------------------------------------------------------------------
-const double& cpExtensions::Visualization::ImageBlender::
-GetMinWindow( ) const
-{
-  return( this->m_MinWindow );
-}
-
-// -------------------------------------------------------------------------
-const double& cpExtensions::Visualization::ImageBlender::
-GetMinLevel( ) const
-{
-  return( this->m_MinLevel );
-}
-
-// -------------------------------------------------------------------------
-const double& cpExtensions::Visualization::ImageBlender::
-GetWindow( ) const
-{
-  return( this->m_Window );
-}
-
-// -------------------------------------------------------------------------
-const double& cpExtensions::Visualization::ImageBlender::
-GetLevel( ) const
-{
-  return( this->m_Level );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageBlender::
-SetWindow( const double& w )
-{
-  if( this->m_Window != w )
-  {
-    this->m_Window = w;
-    this->Modified( );
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::Visualization::ImageBlender::
-SetLevel( const double& l )
-{
-  if( this->m_Level != l )
-  {
-    this->m_Level = l;
-    this->Modified( );
-
-  } // fi
+  return(
+    ( const_cast< Self* >( this ) )->GetNumberOfInputConnections( 0 )
+    );
 }
 
 // -------------------------------------------------------------------------
@@ -126,8 +61,8 @@ GetColor(
   double& b
   ) const
 {
-  auto c = this->m_Colors.find( i );
-  if( c != this->m_Colors.end( ) )
+  auto c = this->Colors.find( i );
+  if( c != this->Colors.end( ) )
   {
     r = c->second.R;
     g = c->second.G;
@@ -135,8 +70,10 @@ GetColor(
   }
   else
   {
-    r = double( 1 );
-    g = b = double( 0 );
+    TColor c;
+    r = c.R;
+    g = c.G;
+    b = c.B;
 
   } // fi
 }
@@ -150,7 +87,7 @@ SetColor(
   const double& b
   )
 {
-  this->m_Colors[ i ] = TColor( r, g, b );
+  this->Colors[ i ] = TColor( r, g, b );
   this->Modified( );
 }
 
@@ -158,12 +95,12 @@ SetColor(
 cpExtensions::Visualization::ImageBlender::
 ImageBlender( )
   : Superclass( ),
-    m_MaxWindow( double( 0 ) ),
-    m_MaxLevel( double( 0 ) ),
-    m_MinWindow( double( 0 ) ),
-    m_MinLevel( double( 0 ) ),
-    m_Window( double( 0 ) ),
-    m_Level( double( 0 ) )
+    MaxWindow( double( 1 ) ),
+    MaxLevel( double( 1 ) ),
+    MinWindow( double( 0 ) ),
+    MinLevel( double( 0 ) ),
+    Window( double( 1 ) ),
+    Level( double( 0.5 ) )
 {
   this->SetNumberOfInputPorts( 1 );
 }
@@ -207,27 +144,13 @@ RequestInformation(
   this->m_Extent[ 5 ] += 1;
 
   // Configure window/level
-  double range[ 2 ];
-  inData->GetScalarRange( range );
-  this->m_MaxWindow = range[ 1 ] - range[ 0 ];
-  this->m_MinWindow = this->m_MaxWindow * double( 1e-2 );
-  this->m_MinLevel = range[ 0 ];
-  this->m_MaxLevel = range[ 1 ];
-  if( this->m_Window < this->m_MinWindow )
-    this->m_Window = this->m_MinWindow;
-  if( this->m_Window > this->m_MaxWindow )
-    this->m_Window = this->m_MaxWindow;
-  if( this->m_Level < this->m_MinLevel )
-    this->m_Level = this->m_MinLevel;
-  if( this->m_Level > this->m_MaxLevel )
-    this->m_Level = this->m_MaxLevel;
-  this->m_WLSlope = double( 1 ) / this->m_Window;
-  this->m_WLOffset = double( 0.5 ) - ( this->m_Level / this->m_Window );
+  this->m_WLSlope = double( 1 ) / this->Window;
+  this->m_WLOffset = double( 0.5 ) - ( this->Level / this->Window );
 
   // Configure output type
   vtkDataObject::SetPointDataActiveScalarInfo(
     outputVector->GetInformationObject( 0 ),
-    VTK_UNSIGNED_CHAR, 4
+    VTK_UNSIGNED_CHAR, 3
     );
   return( 1 );
 }
@@ -336,7 +259,7 @@ _GenerateData(
   vtkImageData** inDatas,
   int numInputs,
   vtkImageData* outData,
-  int outExt[6],
+  int outExt[ 6 ],
   int id
   )
 {
@@ -351,7 +274,7 @@ _GenerateData(
   int mType = inDatas[ 0 ]->GetScalarType( );
   int mSize = inDatas[ 0 ]->GetScalarSize( );
 
-  double r, g, b, a;
+  double r, g, b;
   int e13 = this->m_Extent[ 1 ] * this->m_Extent[ 3 ];
   for( int k = outExt[ 4 ]; k <= outExt[ 5 ]; ++k )
   {
@@ -374,7 +297,6 @@ _GenerateData(
 
         // Prepare color
         r = g = b = v;
-        a = _1;
 
         // Blend colors
         for( int i = 1; i < numInputs; ++i )
@@ -390,24 +312,20 @@ _GenerateData(
             );
           if( c > double( 0 ) )
           {
-            double cr, cg, cb;
-            this->GetColor( i, cr, cg, cb );
-            double n = std::sqrt( ( cr * cr ) + ( cg * cg ) + ( cb * cb ) );
-            r *= cr * n;
-            g *= cg * n;
-            b *= cb * n;
-            a = _1;
+            TColor rgb = this->Colors[ i ];
+            r *= rgb.R * rgb.N;
+            g *= rgb.G * rgb.N;
+            b *= rgb.B * rgb.N;
 
           } // fi
 
         } // rof
 
         // Update color
-        int di4 = di << 2;
-        oBuffer[ di4 + 0 ] = static_cast< unsigned char >( r * _255 );
-        oBuffer[ di4 + 1 ] = static_cast< unsigned char >( g * _255 );
-        oBuffer[ di4 + 2 ] = static_cast< unsigned char >( b * _255 );
-        oBuffer[ di4 + 3 ] = static_cast< unsigned char >( a * _255 );
+        int di3 = di * 3;
+        oBuffer[ di3 + 0 ] = static_cast< unsigned char >( r * _255 );
+        oBuffer[ di3 + 1 ] = static_cast< unsigned char >( g * _255 );
+        oBuffer[ di3 + 2 ] = static_cast< unsigned char >( b * _255 );
 
       } // rof