this->WindowLevelCurrentPosition[ 1 ]
) / double( size[ 1 ] );
- double w = this->WindowLevelInitial[ 0 ] * ( double( 1 ) + sw );
- double l = this->WindowLevelInitial[ 1 ] * ( double( 1 ) + sl );
+ double w = this->WindowLevelInitial[ 0 ] + ( sw * 1000.0 );
+ double l = this->WindowLevelInitial[ 1 ] + ( sl * 1000.0 );
double minw = this->m_MPRActors->GetMinWindow( 0 );
double maxw = this->m_MPRActors->GetMaxWindow( 0 );
double minl = this->m_MPRActors->GetMinLevel( 0 );
if( l < minl ) l = minl;
if( maxl < l ) l = maxl;
- this->m_MPRActors->SetWindow( 0, w );
- this->m_MPRActors->SetLevel( 0, l );
+ this->m_MPRActors->SetWindowLevel( 0, w, l );
this->Interactor->Render( );
this->_RenderAssociateInteractors( );
}
void cpExtensions::Visualization::ImageSliceActors::
AddInputConnection( vtkAlgorithmOutput* aout, int axis )
{
- unsigned int nImages = this->SliceMappers.size( );
-
vtkSmartPointer< vtkImageSliceMapper > mapper =
vtkSmartPointer< vtkImageSliceMapper >::New( );
this->SliceMappers.push_back( mapper );
mapper->SetInputConnection( aout );
- mapper->SetOrientation(
- ( nImages == 0 )? axis: this->SliceMappers[ 0 ]->GetOrientation( )
- );
- mapper->Update( );
-
- vtkSmartPointer< vtkImageActor > actor =
- vtkSmartPointer< vtkImageActor >::New( );
- this->ImageActors.push_back( actor );
- actor->SetMapper( mapper );
- actor->Modified( );
-
- if( nImages == 0 )
- {
- this->AddItem( this->TextActor );
- this->AddItem( this->PlaneActor );
-
- } // fi
- this->AddItem( actor );
- this->Modified( );
+ this->_ConfigureNewInput( axis );
}
// -------------------------------------------------------------------------
void cpExtensions::Visualization::ImageSliceActors::
AddInputData( vtkImageData* data, int axis )
{
- unsigned int nImages = this->SliceMappers.size( );
-
vtkSmartPointer< vtkImageSliceMapper > mapper =
vtkSmartPointer< vtkImageSliceMapper >::New( );
this->SliceMappers.push_back( mapper );
mapper->SetInputData( data );
- mapper->SetOrientation(
- ( nImages == 0 )? axis: this->SliceMappers[ 0 ]->GetOrientation( )
- );
- mapper->Update( );
-
- vtkSmartPointer< vtkImageActor > actor =
- vtkSmartPointer< vtkImageActor >::New( );
- this->ImageActors.push_back( actor );
- actor->SetMapper( mapper );
- actor->Modified( );
-
- if( nImages == 0 )
- {
- this->AddItem( this->TextActor );
- this->AddItem( this->PlaneActor );
-
- } // fi
- this->AddItem( actor );
- this->Modified( );
+ this->_ConfigureNewInput( axis );
}
// -------------------------------------------------------------------------
return( this->PlaneActor );
}
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+SetInterpolate( bool v )
+{
+ if( this->Interpolate != v )
+ {
+ for( unsigned int i = 0; i < this->ImageActors.size( ); ++i )
+ this->ImageActors[ i ]->SetInterpolate( v );
+ this->Interpolate = v;
+ this->Modified( );
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+InterpolateOn( )
+{
+ this->SetInterpolate( true );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+InterpolateOff( )
+{
+ this->SetInterpolate( false );
+}
+
// -------------------------------------------------------------------------
double* cpExtensions::Visualization::ImageSliceActors::
GetDisplayBounds( ) const
void cpExtensions::Visualization::ImageSliceActors::
GetDisplayBounds( double bounds[ 6 ] ) const
{
- if( this->ImageActors.size( ) > 0 )
+ if( this->ImageActors.size( ) == 0 )
+ {
+ bounds[ 0 ] = bounds[ 2 ] = bounds[ 4 ] = double( -1 );
+ bounds[ 1 ] = bounds[ 3 ] = bounds[ 5 ] = double( -1 );
+ }
+ else
this->ImageActors[ 0 ]->GetDisplayBounds( bounds );
}
this->PlaneSource->Modified( );
this->PlaneMapper->Modified( );
this->PlaneActor->Modified( );
- this->Modified( );
+ this->UpdateText( );
}
// -------------------------------------------------------------------------
this->Modified( );
}
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+UpdateText( const double& w, const double& l )
+{
+ if( this->SliceMappers.size( ) > 0 )
+ {
+ char axis;
+ int axId = this->SliceMappers[ 0 ]->GetOrientation( );
+ if ( axId == 0 ) axis = 'X';
+ else if( axId == 1 ) axis = 'Y';
+ else if( axId == 2 ) axis = 'Z';
+
+ std::sprintf(
+ this->TextBuffer, "Axis: %c (%d) | W/L (%.2f/%.2f)",
+ axis, this->SliceMappers[ 0 ]->GetSliceNumber( ), w, l
+ );
+ }
+ else
+ this->TextBuffer[ 0 ] = '\0';
+ this->TextActor->SetInput( this->TextBuffer );
+ this->TextActor->Modified( );
+ this->Modified( );
+}
+
// -------------------------------------------------------------------------
cpExtensions::Visualization::ImageSliceActors::
ImageSliceActors( )
- : Superclass( )
+ : Superclass( ),
+ Interpolate( false )
{
this->Clear( );
}
{
}
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::ImageSliceActors::
+_ConfigureNewInput( int axis )
+{
+ unsigned int nImages = this->ImageActors.size( );
+
+ // Configure mapper
+ vtkImageSliceMapper* mapper = this->SliceMappers[ nImages ];
+ if( nImages == 0 )
+ mapper->SetOrientation( axis );
+ else
+ mapper->SetOrientation( this->SliceMappers[ 0 ]->GetOrientation( ) );
+ mapper->Update( );
+
+ // Create actor
+ vtkSmartPointer< vtkImageActor > actor =
+ vtkSmartPointer< vtkImageActor >::New( );
+ this->ImageActors.push_back( actor );
+ actor->SetMapper( mapper );
+ actor->SetInterpolate( this->Interpolate );
+ actor->Modified( );
+
+ if( nImages == 0 )
+ {
+ this->AddItem( this->TextActor );
+ this->AddItem( this->PlaneActor );
+
+ } // fi
+ this->AddItem( actor );
+
+ if( nImages > 1 )
+ this->SetSliceNumber( this->GetSliceNumber( ) );
+ this->Modified( );
+}
+
// eof - $RCSfile$
vtkActor* GetPlaneActor( );
const vtkActor* GetPlaneActor( ) const;
+ void SetInterpolate( bool v );
+ void InterpolateOn( );
+ void InterpolateOff( );
+
double* GetDisplayBounds( ) const;
void GetDisplayBounds( double bounds[ 6 ] ) const;
int GetSliceNumberMaxValue( ) const;
void SetSliceNumber( const int& slice );
void UpdateText( );
+ void UpdateText( const double& w, const double& l );
protected:
ImageSliceActors( );
virtual ~ImageSliceActors( );
+ void _ConfigureNewInput( int axis );
+
private:
// Purposely not implemented
ImageSliceActors( const Self& );
// Multiple actors
std::vector< vtkSmartPointer< vtkImageSliceMapper > > SliceMappers;
std::vector< vtkSmartPointer< vtkImageActor > > ImageActors;
+ bool Interpolate;
// Unique objects
vtkSmartPointer< vtkPolyData > PlaneSource;
#include <cpExtensions/Visualization/MPRActors.h>
+#include <cmath>
+
#include <vtkAlgorithmOutput.h>
#include <vtkImageData.h>
#include <vtkInformation.h>
+#include <vtkLookupTable.h>
#include <vtkOutlineSource.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
this->ImageMaps[ 0 ]->SetInputConnection( aout );
this->SetLookupTableToWindowLevel( 0 );
this->_Update( 0 );
+ this->ResetWindowLevel( 0 );
return( 0 );
}
else
vtkSmartPointer< vtkImageMapToColors >::New( )
);
this->ImageMaps[ N ]->SetInputConnection( aout );
- this->SetLookupTableToWindowLevel( N );
+ this->SetLookupTableToColor(
+ N, double( 1 ), double( 0 ), double( 0 )
+ );
this->_Update( N );
return( N );
}
this->ImageMaps[ 0 ]->SetInputData( image );
this->SetLookupTableToWindowLevel( 0 );
this->_Update( 0 );
+ this->ResetWindowLevel( 0 );
return( 0 );
}
else
vtkSmartPointer< vtkImageMapToColors >::New( )
);
this->ImageMaps[ N ]->SetInputData( image );
- this->SetLookupTableToWindowLevel( N );
+ this->SetLookupTableToColor(
+ N, double( 1 ), double( 0 ), double( 0 )
+ );
this->_Update( N );
return( N );
}
w->RemoveActor( this->ImageOutlineActor );
}
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::MPRActors::
+LinkInteractors( )
+{
+ this->_Update( 0 );
+ this->_Update( 1 );
+ this->_Update( 2 );
+}
+
// -------------------------------------------------------------------------
void cpExtensions::Visualization::MPRActors::
SetLookupTable( unsigned int i, vtkScalarsToColors* lut )
} // fi
}
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::MPRActors::
+SetWindowLevel( unsigned int i, const double& w, const double& l )
+{
+ vtkWindowLevelLookupTable* lut =
+ dynamic_cast< vtkWindowLevelLookupTable* >( this->GetLookupTable( i ) );
+ if( lut != NULL )
+ {
+ lut->SetWindow( w );
+ lut->SetLevel( l );
+ lut->Build( );
+ this->ImageMaps[ i ]->Modified( );
+
+ for( unsigned int j = 0; j < 3; ++j )
+ this->Slices[ 0 ][ j ]->UpdateText( w, l );
+
+ this->Modified( );
+
+ } // fi
+}
+
// -------------------------------------------------------------------------
void cpExtensions::Visualization::MPRActors::
ResetWindowLevel( unsigned int i )
double r[ 2 ];
image->GetScalarRange( r );
lut->SetTableRange( r );
+ lut->SetWindow( r[ 1 ] - r[ 0 ] );
+ lut->SetLevel( ( r[ 1 ] + r[ 0 ] ) / double( 2 ) );
lut->Build( );
this->ImageMaps[ i ]->Modified( );
this->Modified( );
} // fi
}
+// -------------------------------------------------------------------------
+void cpExtensions::Visualization::MPRActors::
+SetLookupTableToColor(
+ unsigned int i, const double& r, const double& g, const double& b
+ )
+{
+ static const double _0 = double( 0 );
+ static const double _1 = double( 1 );
+ static const double _2 = double( 2 );
+ static const double _4 = double( 4 );
+ static const double _6 = double( 6 );
+ static const double _OPACITY = double( 0.6 );
+
+ // Check if the input has been configured
+ vtkImageData* image = this->_Image( i );
+ if( image == NULL )
+ return;
+
+ double range[ 2 ];
+ image->GetScalarRange( range );
+
+ // Get HSV from display color
+ double cmax = ( r > g )? r: g; cmax = ( b > cmax )? b: cmax;
+ double cmin = ( r < g )? r: g; cmin = ( b < cmin )? b: cmin;
+ double d = cmax - cmin;
+
+ double saturation = ( std::fabs( cmax ) > _0 )? d / cmax: _0;
+ double value = cmax;
+ double hue = _0;
+ if( d > _0 )
+ {
+ if( r == cmax )
+ hue = std::fmod( ( g - b ) / d, _6 );
+ else if( g == cmax )
+ hue = ( ( b - r ) / d ) + _2;
+ else if( b == cmax )
+ hue = ( ( r - g ) / d ) + _4;
+ hue *= _1 / _6;
+
+ } // fi
+
+ // Define new lookup table
+ vtkSmartPointer< vtkLookupTable > lut =
+ vtkSmartPointer< vtkLookupTable >::New( );
+ lut->SetScaleToLinear( );
+ lut->SetAboveRangeColor( _0, _0, _0, _0 );
+ lut->SetBelowRangeColor( _0, _0, _0, _0 );
+ lut->SetNanColor( _0, _0, _0, _0 );
+ lut->SetTableRange( range[ 0 ], range[ 1 ] );
+ lut->SetAlphaRange( _0, _OPACITY );
+ lut->SetHueRange( _0, hue );
+ lut->SetSaturationRange( _0, saturation );
+ lut->SetValueRange( _0, value );
+ lut->Build( );
+
+ this->SetLookupTable( i, lut );
+}
+
// -------------------------------------------------------------------------
int cpExtensions::Visualization::MPRActors::
GetSliceNumberMinValue( const int& axis ) const
vtkAlgorithm* algo = this->ImageMaps[ i ]->GetInputAlgorithm( );
vtkInformation* info = algo->GetOutputInformation( 0 );
return(
- vtkImageData::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT( ) ) )
+ vtkImageData::SafeDownCast(
+ info->Get( vtkDataObject::DATA_OBJECT( ) )
+ )
);
}
else
);
this->Slices[ j ][ k ]->UpdateText( );
+ // Add all of slice's props
+ this->Slices[ j ][ k ]->InitTraversal( );
+ vtkProp* prop = this->Slices[ j ][ k ]->GetNextProp( );
+ while( prop != NULL )
+ {
+ this->AddItem( prop );
+ prop = this->Slices[ j ][ k ]->GetNextProp( );
+
+ } // elihw
+
} // rof
} // rof
int AddInputConnection( vtkAlgorithmOutput* aout );
int AddInputData( vtkImageData* image );
- /*
- void SetInputConnection( vtkAlgorithmOutput* aout );
- void SetInputData( vtkImageData* image );
- */
-
void PushDataInto(
vtkRenderer* x,
vtkRenderer* y,
vtkRenderer* z,
vtkRenderer* w
);
- void LinkInteractors( )
- {
- this->_Update( 0 );
- this->_Update( 1 );
- this->_Update( 2 );
- }
+ void LinkInteractors( );
// Lookup table methods
void SetLookupTable( unsigned int i, vtkScalarsToColors* lut );
double GetLevel( unsigned int i ) const;
void SetWindow( unsigned int i, const double& w );
void SetLevel( unsigned int i, const double& l );
+ void SetWindowLevel( unsigned int i, const double& w, const double& l );
void ResetWindowLevel( unsigned int i );
+ // Color lookup table
+ void SetLookupTableToColor(
+ unsigned int i,
+ const double& r = double( 1 ),
+ const double& g = double( 0 ),
+ const double& b = double( 0 )
+ );
+
// Slice access
int GetSliceNumberMinValue( const int& axis ) const;
int GetSliceNumberMaxValue( const int& axis ) const;
#include <cpExtensions/Visualization/MPRObjects.h>
+#include <cmath>
+#include <vtkImageData.h>
+#include <vtkLookupTable.h>
+
// -------------------------------------------------------------------------
cpExtensions::Visualization::MPRObjects*
cpExtensions::Visualization::MPRObjects::
this->m_Renderers[ 3 ]
);
- // Correct cameras positions
- /* TODO
- vtkCamera* zCam = this->m_Renderers[ 2 ]->GetActiveCamera( );
- zCam->SetViewUp( 0, -1, 0 );
- zCam->SetPosition( 0, 0, -1 );
- zCam->SetFocalPoint( 0, 0, 0 );
- */
-
// First rendering
this->m_MPRActors->ResetSlices( );
this->ResetCameras( );
void cpExtensions::Visualization::MPRObjects::
AddAuxiliaryImage( vtkImageData* image )
{
- this->m_MPRActors->AddInputData( image );
-
-#error Definir LUT de la nueva imagen
+ // Try to add new image
+ int id = this->m_MPRActors->AddInputData( image );
+ if( id < 0 )
+ return;
+ // Push everything on renderers
this->m_MPRActors->PushDataInto(
this->m_Renderers[ 0 ],
this->m_Renderers[ 1 ],