auto spline = ws->GetFilter( "spline" );
auto seeds = ws->GetFilter( "seeds" );
auto axis = ws->GetFilter( "axis" );
+ auto writer = ws->GetFilter( "writer" );
+ auto raster = ws->GetFilter( "raster" );
// Execute reader
try
reader->GetOutputData< vtkImageData >( "Output" ), 2, "image"
);
spline->AddInteractor( view.GetInteractor( ) );
- spline->Update( );
seeds->AddInteractor( view.GetInteractor( ) );
+ spline->Update( );
seeds->Update( );
// Start application and show data
app.exec( );
spline->Modified( );
spline->Update( );
+ raster->Update( );
+ writer->Update( );
wnd.show( );
app.exec( );
--- /dev/null
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#ifndef __cpExtensions__Algorithms__RasterContourFilter__h__
+#define __cpExtensions__Algorithms__RasterContourFilter__h__
+
+#include <cpExtensions/Config.h>
+#include <itkImageSource.h>
+#include <vtkSmartPointer.h>
+
+// -------------------------------------------------------------------------
+class vtkPoints;
+class vtkPolygon;
+
+// -------------------------------------------------------------------------
+namespace cpExtensions
+{
+ namespace Algorithms
+ {
+ /**
+ */
+ template< class _TImage >
+ class RasterContourFilter
+ : public itk::ImageSource< _TImage >
+ {
+ public:
+ // Basic types
+ typedef RasterContourFilter Self;
+ typedef itk::ImageSource< _TImage > Superclass;
+ typedef itk::SmartPointer< Self > Pointer;
+ typedef itk::SmartPointer< const Self > ConstPointer;
+
+ typedef _TImage TImage;
+ typedef typename _TImage::IndexType TIndex;
+ typedef typename _TImage::PixelType TPixel;
+ typedef typename _TImage::PointType TPoint;
+ typedef typename _TImage::RegionType TRegion;
+ typedef itk::ImageBase< 2 > TImageBase;
+
+ public:
+ itkNewMacro( Self );
+ itkTypeMacro( RasterContourFilter, itk::ImageSource );
+
+ itkGetConstObjectMacro( Template, TImageBase );
+ itkGetConstMacro( InsideValue, TPixel );
+ itkGetConstMacro( OutsideValue, TPixel );
+
+ itkSetConstObjectMacro( Template, TImageBase );
+ itkSetMacro( InsideValue, TPixel );
+ itkSetMacro( OutsideValue, TPixel );
+
+ public:
+ void AddPoint( double x, double y );
+ void AddPoint( double p[ 2 ] );
+ void AddPoints( vtkPoints* points );
+ void ClearPoints( );
+
+ protected:
+ RasterContourFilter( );
+ virtual ~RasterContourFilter( );
+
+ virtual void AllocateOutputs( ) cpExtensions_OVERRIDE;
+ virtual void BeforeThreadedGenerateData( ) cpExtensions_OVERRIDE;
+ virtual void AfterThreadedGenerateData( ) cpExtensions_OVERRIDE;
+ virtual void ThreadedGenerateData(
+ const TRegion& region, itk::ThreadIdType id
+ ) cpExtensions_OVERRIDE;
+
+ private:
+ // Purposely not implemented
+ RasterContourFilter( const Self& );
+ void operator=( const Self& );
+
+ protected:
+ vtkSmartPointer< vtkPolygon > m_Polygon;
+ typename TImageBase::ConstPointer m_Template;
+ TPixel m_InsideValue;
+ TPixel m_OutsideValue;
+ };
+
+ } // ecapseman
+
+} // ecapseman
+
+#ifndef ITK_MANUAL_INSTANTIATION
+# include <cpExtensions/Algorithms/RasterContourFilter.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
+
+#endif // __cpExtensions__Algorithms__RasterContourFilter__h__
+
+// eof - $RCSfile$
--- /dev/null
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// ------------------------------------------------------------------------
+
+// Inclusion test taken from:
+// https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
+
+#ifndef __cpExtensions__Algorithms__RasterContourFilter__hxx__
+#define __cpExtensions__Algorithms__RasterContourFilter__hxx__
+
+#include <itkImageRegionIteratorWithIndex.h>
+#include <vtkPolygon.h>
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+void cpExtensions::Algorithms::RasterContourFilter< _TImage >::
+AddPoint( double x, double y )
+{
+ this->m_Polygon->GetPoints( )->InsertNextPoint( x, y, 0 );
+ this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+void cpExtensions::Algorithms::RasterContourFilter< _TImage >::
+AddPoint( double p[ 2 ] )
+{
+ this->m_Polygon->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], 0 );
+ this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+void cpExtensions::Algorithms::RasterContourFilter< _TImage >::
+AddPoints( vtkPoints* points )
+{
+ double p[ 3 ];
+ for( unsigned long i = 0; i < points->GetNumberOfPoints( ); ++i )
+ {
+ points->GetPoint( i, p );
+ this->m_Polygon->GetPoints( )->InsertNextPoint( p[ 0 ], p[ 1 ], 0 );
+
+ } // rof
+ this->Modified( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+void cpExtensions::Algorithms::RasterContourFilter< _TImage >::
+ClearPoints( )
+{
+ this->m_Polygon = vtkSmartPointer< vtkPolygon >::New( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+cpExtensions::Algorithms::RasterContourFilter< _TImage >::
+RasterContourFilter( )
+ : Superclass( ),
+ m_InsideValue( TPixel( 1 ) ),
+ m_OutsideValue( TPixel( 0 ) )
+{
+ this->ClearPoints( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+cpExtensions::Algorithms::RasterContourFilter< _TImage >::
+~RasterContourFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+void cpExtensions::Algorithms::RasterContourFilter< _TImage >::
+AllocateOutputs( )
+{
+ _TImage* out = this->GetOutput( 0 );
+ out->SetSpacing( this->m_Template->GetSpacing( ) );
+ out->SetRegions( this->m_Template->GetRequestedRegion( ) );
+ out->SetOrigin( this->m_Template->GetOrigin( ) );
+ out->SetDirection( this->m_Template->GetDirection( ) );
+ out->Allocate( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+void cpExtensions::Algorithms::RasterContourFilter< _TImage >::
+BeforeThreadedGenerateData( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+void cpExtensions::Algorithms::RasterContourFilter< _TImage >::
+AfterThreadedGenerateData( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+void cpExtensions::Algorithms::RasterContourFilter< _TImage >::
+ThreadedGenerateData( const TRegion& region, itk::ThreadIdType id )
+{
+ vtkPoints* points = this->m_Polygon->GetPoints( );
+ unsigned long nPoints = points->GetNumberOfPoints( );
+ double* arr =
+ static_cast< double* >( points->GetData()->GetVoidPointer( 0 ) );
+ double p[ 3 ], n[ 3 ], b[ 6 ];
+ this->m_Polygon->GetPoints( )->GetBounds( b );
+ n[ 0 ] = n[ 1 ] = double( 0 );
+ n[ 2 ] = double( 1 );
+
+ _TImage* out = this->GetOutput( );
+ itk::ImageRegionIteratorWithIndex< _TImage > iIt( out, region );
+ for( iIt.GoToBegin( ); !iIt.IsAtEnd( ); ++iIt )
+ {
+ TIndex idx = iIt.GetIndex( );
+ TPoint pnt;
+ out->TransformIndexToPhysicalPoint( idx, pnt );
+ p[ 0 ] = pnt[ 0 ];
+ p[ 1 ] = pnt[ 1 ];
+ p[ 2 ] = double( 0 );
+
+ int i, j, c = 0;
+ int nvert = nPoints;
+ for( i = 0, j = nvert - 1; i < nvert; j = i++ )
+ {
+ double pi[ 3 ], pj[ 3 ];
+ points->GetPoint( i, pi );
+ points->GetPoint( j, pj );
+
+ if(
+ ( ( pi[ 1 ] > p[ 1 ] ) != ( pj[ 1 ] > p[ 1 ] ) ) &&
+ ( p[ 0 ] < ( pj[ 0 ] - pi[ 0 ] ) * ( p[ 1 ] - pi[ 1 ] ) / ( pj[ 1 ] - pi[ 1 ] ) + pi[ 0 ] )
+ )
+ c = !c;
+
+ } // rof
+
+ if( c != 0 )
+ iIt.Set( this->m_InsideValue );
+ else
+ iIt.Set( this->m_OutsideValue );
+
+ } // rof
+}
+
+#endif // __cpExtensions__Algorithms__RasterContourFilter__hxx__
+
+// eof - $RCSfile$
#include <cpExtensions/Utility.h>
#include <cpExtensions/Interaction/ImageSliceStyle.h>
#include <cpExtensions/Visualization/CursorActors.h>
+#include <cpExtensions/Visualization/LUTImageActor.h>
#include <cpExtensions/Visualization/WindowLevelImageActor.h>
#include <vtkAssemblyPath.h>
#include <vtkImageData.h>
s += ( this->Interactor->GetShiftKey( ) == 1 )? 10: 1;
this->m_WLActor->SetSliceNumber( s );
s = this->m_WLActor->GetSliceNumber( );
+ if( this->m_LUTActor.GetPointer( ) != NULL )
+ this->m_LUTActor->SetSliceNumber( s );
this->InvokeEvent( vtkCommand::UserEvent + 2, &s );
this->Interactor->Render( );
this->OnMouseMove( );
s -= ( this->Interactor->GetShiftKey( ) == 1 )? 10: 1;
this->m_WLActor->SetSliceNumber( s );
s = this->m_WLActor->GetSliceNumber( );
+ if( this->m_LUTActor.GetPointer( ) != NULL )
+ this->m_LUTActor->SetSliceNumber( s );
this->InvokeEvent( vtkCommand::UserEvent + 2, &s );
this->Interactor->Render( );
this->OnMouseMove( );
this->m_PropPicker->GetPickList( )->RemoveAllItems( );
this->m_PropPicker->AddPickList( curr_actor );
+ auto props = this->CurrentRenderer->GetViewProps( );
+ this->m_LUTActor = NULL;
+ props->InitTraversal( );
+ vtkProp* prop;
+ while( ( ( prop = props->GetNextProp( ) ) != NULL ) && ( this->m_LUTActor.GetPointer( ) == NULL ) )
+ this->m_LUTActor = dynamic_cast< TLUTActor* >( prop );
+
this->m_Cursor->SetImageBounds( curr_actor->GetImage( )->GetBounds( ) );
this->m_Cursor->SetImageOrientation( curr_actor->GetOrientation( ) );
this->m_Cursor->InitTraversal( );
namespace Visualization
{
class CursorActors;
+ class LUTImageActor;
class WindowLevelImageActor;
}
namespace Interaction
public:
typedef ImageSliceStyle Self;
typedef cpExtensions::Visualization::CursorActors TCursor;
+ typedef cpExtensions::Visualization::LUTImageActor TLUTActor;
typedef cpExtensions::Visualization::WindowLevelImageActor TWLActor;
public:
protected:
vtkSmartPointer< vtkPropPicker > m_PropPicker;
+ vtkSmartPointer< TLUTActor > m_LUTActor;
vtkSmartPointer< TWLActor > m_WLActor;
vtkSmartPointer< TCursor > m_Cursor;
vtkSmartPointer< vtkTextActor > m_Text;
_CompletedAction( vtkAbstractWidget* wdg )
{
// Do nothing
+ Self::CompletedAction( wdg );
}
// -------------------------------------------------------------------------
_MoveAction( vtkAbstractWidget* wdg )
{
// Do nothing
+ Self::MoveAction( wdg );
}
// -------------------------------------------------------------------------
_EndSelectAction( vtkAbstractWidget* wdg )
{
// Do nothing
+ Self::EndSelectAction( wdg );
}
// -------------------------------------------------------------------------
_DeleteAction( vtkAbstractWidget* wdg )
{
// Do nothing
+ Self::DeleteAction( wdg );
}
// -------------------------------------------------------------------------
#ifdef cpExtensions_QT4
#include <cpExtensions/Interaction/ImageSliceStyle.h>
+#include <cpExtensions/Visualization/LUTImageActor.h>
#include <cpExtensions/Visualization/MeshActor.h>
#include <cpExtensions/Visualization/OutlineSource.h>
#include <cpExtensions/Visualization/WindowLevelImageActor.h>
+#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkImageData.h>
+#include <vtkImageProperty.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
cpExtensions::QT::ImageWidget::
~ImageWidget( )
{
+ this->Clear( );
if( this->m_OutlineActor != NULL )
delete this->m_OutlineActor;
+ for( auto a = this->m_Actors.begin( ); a != this->m_Actors.end( ); ++a )
+ delete *a;
+ this->m_Actors.clear( );
}
// -------------------------------------------------------------------------
this->m_WLActor->SetImage( image );
this->m_WLActor->SetOrientation( orientation );
+ this->m_LUTActor = vtkSmartPointer< TLUTActor >::New( );
+ this->m_LUTActor->SetOrientation( orientation );
+
this->m_Outline = vtkSmartPointer< TOutline >::New( );
this->m_Outline->SetBounds( image->GetBounds( ) );
this->m_Outline->Update( );
this->ResetCamera( );
}
+// -------------------------------------------------------------------------
+void cpExtensions::QT::ImageWidget::
+Add( vtkDataSet* data, const std::string& name )
+{
+ auto image = dynamic_cast< vtkImageData* >( data );
+ auto pdata = dynamic_cast< vtkPolyData* >( data );
+ if( image != NULL )
+ {
+ this->m_LUTActor->AddImage( image );
+ this->m_LUTActor->GetProperty( )->SetOpacity( 0.5 );
+ this->AddViewProp( this->m_LUTActor, "__LUT_IMAGE__" );
+ this->Render( );
+ }
+ else if( pdata != NULL )
+ {
+ TActor* actor = new TActor( );
+ actor->SetMesh( pdata );
+ this->m_Actors.push_back( actor );
+ this->AddViewProp( actor->GetActor( ), name );
+ this->Render( );
+
+ } // fi
+}
+
// -------------------------------------------------------------------------
void cpExtensions::QT::ImageWidget::
ResetCamera( )
}
else if( ori == 2 )
{
- if ( this->m_Quadrant == 0 ) up[ 1 ] = double( 1 );
- else if( this->m_Quadrant == 1 ) up[ 1 ] = double( 1 );
- else if( this->m_Quadrant == 2 ) up[ 1 ] = double( 1 );
- else if( this->m_Quadrant == 3 ) up[ 1 ] = double( 1 );
+ if ( this->m_Quadrant == 0 ) up[ 1 ] = double( -1 );
+ else if( this->m_Quadrant == 1 ) up[ 1 ] = double( -1 );
+ else if( this->m_Quadrant == 2 ) up[ 1 ] = double( -1 );
+ else if( this->m_Quadrant == 3 ) up[ 1 ] = double( -1 );
pos[ 2 ] *= double( -1 );
} // fi
return( this->m_WLActor );
}
+// -------------------------------------------------------------------------
+void cpExtensions::QT::ImageWidget::
+SetColor( const std::string& name, double r, double g, double b )
+{
+ auto props = this->GetViewProps( name );
+ for( auto p = props.begin( ); p != props.end( ); ++p )
+ {
+ auto actor = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+ if( actor != NULL )
+ actor->GetProperty( )->SetColor( r, g, b );
+
+ } // rof
+ this->Render( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::ImageWidget::
+SetLineWidth( const std::string& name, double w )
+{
+ auto props = this->GetViewProps( name );
+ for( auto p = props.begin( ); p != props.end( ); ++p )
+ {
+ auto actor = dynamic_cast< vtkActor* >( p->GetPointer( ) );
+ if( actor != NULL )
+ actor->GetProperty( )->SetLineWidth( w );
+
+ } // rof
+ this->Render( );
+}
+
/* TODO
// -------------------------------------------------------------------------
#ifdef cpExtensions_QT4
-// TODO: class vtkDataSet;
+// -------------------------------------------------------------------------
+class vtkDataSet;
+// -------------------------------------------------------------------------
namespace cpExtensions
{
namespace Visualization
{
class OutlineSource;
+ class LUTImageActor;
class WindowLevelImageActor;
class MeshActor;
- /* TODO
- class ImageSliceActors;
- class ImageViewerActors;
- */
}
namespace Interaction { class ImageSliceStyle; }
typedef cpExtensions::Visualization::OutlineSource TOutline;
typedef cpExtensions::Visualization::MeshActor TActor;
+ typedef cpExtensions::Visualization::LUTImageActor TLUTActor;
typedef cpExtensions::Visualization::WindowLevelImageActor TWLActor;
typedef cpExtensions::Interaction::ImageSliceStyle TStyle;
void SetImage(
vtkImageData* image, int orientation, const std::string& name
);
+ void Add( vtkDataSet* data, const std::string& name );
virtual void ResetCamera( ) cpExtensions_OVERRIDE;
TWLActor* GetImageActor( );
const TWLActor* GetImageActor( ) const;
+ void SetColor( const std::string& name, double r, double g, double b );
+ void SetLineWidth( const std::string& name, double w );
+
/* TODO
void SetImage(
vtkImageData* image, int orientation, const std::string& name
);
- void Add( vtkDataSet* data, const std::string& name );
// TODO: std::vector< vtkProp* > GetActors( const std::string& name ) const;
int GetOrientation( ) const;
std::string m_ImageName;
vtkSmartPointer< TWLActor > m_WLActor;
+ vtkSmartPointer< TLUTActor > m_LUTActor;
vtkSmartPointer< TOutline > m_Outline;
TActor* m_OutlineActor;
+ std::vector< TActor* > m_Actors;
vtkSmartPointer< TStyle > m_Style;
#ifdef cpExtensions_QT4
#include <cpExtensions/Visualization/ImageOutlineActor.h>
+#include <cpExtensions/Visualization/MeshActor.h>
#include <cpExtensions/Visualization/WindowLevelImageActor.h>
#include <vtkImageData.h>
#include <vtkPlane.h>
+#include <vtkPolyData.h>
/* TODO
#include <cpExtensions/Visualization/MPR3DActors.h>
#include <cpExtensions/Visualization/LUTImageActor.h>
#include <vtkActor.h>
- #include <vtkPolyData.h>
*/
// -------------------------------------------------------------------------
cpExtensions::QT::MPR3DWidget::
~MPR3DWidget( )
{
+ for( auto a = this->m_Actors.begin( ); a != this->m_Actors.end( ); ++a )
+ delete *a;
+ this->m_Actors.clear( );
}
// -------------------------------------------------------------------------
} // rof
}
+// -------------------------------------------------------------------------
+void cpExtensions::QT::MPR3DWidget::
+Add( vtkDataSet* data, const std::string& name )
+{
+ auto image = dynamic_cast< vtkImageData* >( data );
+ auto pdata = dynamic_cast< vtkPolyData* >( data );
+ if( image != NULL )
+ {
+ /* TODO
+ if( this->m_ImageName != "" )
+ {
+ }
+ else
+ this->SetImage( image, name );
+ */
+ }
+ else if( pdata != NULL )
+ {
+ TActor* actor = new TActor( );
+ actor->SetMesh( pdata );
+ this->m_Actors.push_back( actor );
+ this->AddViewProp( actor->GetActor( ), name );
+ this->Render( );
+ if( this->m_ImageName == "" )
+ this->ResetCamera( );
+
+ } // fi
+}
+
// -------------------------------------------------------------------------
cpExtensions::QT::MPR3DWidget::
TWLActor* cpExtensions::QT::MPR3DWidget::
this->Render( );
}
-// -------------------------------------------------------------------------
-void cpExtensions::QT::MPR3DWidget::
-Add( vtkDataSet* data, const std::string& name )
-{
- auto image = dynamic_cast< vtkImageData* >( data );
- auto pdata = dynamic_cast< vtkPolyData* >( data );
- if( image != NULL )
- {
- if( this->m_ImageName != "" )
- {
- }
- else
- this->SetImage( image, name );
- }
- else if( pdata != NULL )
- {
- this->AddViewProp( this->m_Actors->AddMesh( pdata ), name );
- this->Render( );
- if( this->m_ImageName == "" )
- this->ResetCamera( );
-
- } // fi
-
- return;
-
- auto image = dynamic_cast< vtkImageData* >( data );
- auto pdata = dynamic_cast< vtkPolyData* >( data );
- if( image != NULL )
- {
- this->m_Actors->AddLUTImage( image );
- vtkSmartPointer< vtkPropCollection > coll =
- vtkSmartPointer< vtkPropCollection >::New( );
- coll->AddItem( this->m_Actors->GetLUTImageActor( 0 ) );
- coll->AddItem( this->m_Actors->GetLUTImageActor( 1 ) );
- coll->AddItem( this->m_Actors->GetLUTImageActor( 2 ) );
- this->AddViewProps( coll, name );
- this->Render( );
- }
- else if( pdata != NULL )
- {
-
- } // fi
-}
-
// -------------------------------------------------------------------------
void cpExtensions::QT::MPR3DWidget::
SetSliceNumber( int orientation, int slice )
namespace Visualization
{
class ImageOutlineActor;
+ class MeshActor;
class WindowLevelImageActor;
}
typedef MPR3DWidget Self;
typedef cpExtensions::QT::RendererWidget Superclass;
+ typedef cpExtensions::Visualization::MeshActor TActor;
typedef cpExtensions::Visualization::ImageOutlineActor TOLActor;
typedef cpExtensions::Visualization::WindowLevelImageActor TWLActor;
void Clear( );
void SetImage( vtkImageData* image, const std::string& name );
+ void Add( vtkDataSet* data, const std::string& name );
TWLActor* GetImageActor( int o );
const TWLActor* GetImageActor( int o ) const;
/* TODO
void SetImage( vtkImageData* image, const std::string& name );
- void Add( vtkDataSet* data, const std::string& name );
void SetScalarRange( double r[ 2 ] );
vtkSmartPointer< TWLActor > m_WLActors[ 3 ];
vtkSmartPointer< TOLActor > m_OLActors[ 3 ];
+ std::vector< TActor* > m_Actors;
/* TODO
vtkSmartPointer< cpExtensions::Visualization::MPR3DActors > m_Actors;
Add( vtkDataSet* data, const std::string& name )
{
bool success = true;
-/*
auto image = dynamic_cast< vtkImageData* >( data );
auto pdata = dynamic_cast< vtkPolyData* >( data );
this->m_XImage->Add( image, name );
this->m_YImage->Add( image, name );
this->m_ZImage->Add( image, name );
- this->m_3DView->Add( image, name );
+ // TODO: this->m_3DView->Add( image, name );
}
else
this->SetImage( image, name );
this->m_3DView->Add( pdata, name );
else
success = false;
-*/
return( success );
}
this->SetLUTColor( this->GetImageId( image ), r, g, b, a );
}
+// TODO: !!!!!
+#include <vtkImageCast.h>
+
// -------------------------------------------------------------------------
unsigned int cpExtensions::Visualization::LUTImageActor::
AddImage( vtkImageData* image, double r, double g, double b, double a )
{
+ static vtkSmartPointer< vtkImageCast > cast;
+ cast = vtkSmartPointer< vtkImageCast >::New( );
+
if( image != NULL )
{
+ cast->SetOutputScalarTypeToUnsignedChar( );
+ cast->SetInputData( image );
+ cast->Update( );
+
this->m_Images.push_back( image );
this->SetLUTColor( this->m_Images.size( ), r, g, b, a );
- this->m_Blender->AddInputData( image );
+ this->m_Blender->AddInputData( cast->GetOutput( ) );
+ this->m_Blender->Update( );
if( this->m_Images.size( ) == 1 )
{
SetInputConnection( this->m_ImageMap->GetOutputPort( ) );
} // fi
- this->m_Blender->Modified( );
- this->m_ImageMap->Modified( );
this->Modified( );
this->GetProperty( )->SetInterpolationTypeToNearest( );
str << p << cpPlugins_ENV_SEPARATOR;
str << ".";
this->AddEnvironments( str.str( ) );
+
+ // Try to read locally defined paths
+ std::vector< std::string > tokens;
+ cpExtensions::Tokenize( tokens, str.str( ), cpPlugins_ENV_SEPARATOR );
+ for( auto t = tokens.begin( ); t != tokens.end( ); ++t )
+ this->OpenEnvironments( *t );
}
// -------------------------------------------------------------------------
auto o = this->GetInputData( "Input" );
cpPlugins_Demangle_ImageScalars( o, _GD0, 2 );
else cpPlugins_Demangle_ImageScalars( o, _GD0, 3 );
- else this->_Error( "No valid input image." );
+ else this->_Error( "Invalid input image." );
}
// -------------------------------------------------------------------------
#include <plugins/ImageMeshFilters/RasterMeshFilter.h>
#include <cpPlugins/DataObjects/BoundingBox.h>
#include <cpPlugins/DataObjects/Mesh.h>
-
-#include <vtkImageData.h>
-#include <vtkImageStencil.h>
-#include <vtkLinearExtrusionFilter.h>
-#include <vtkPolyDataToImageStencil.h>
-#include <vtkStripper.h>
+#include <cpPlugins_ImageIterators.h>
#include <itkTriangleMeshToBinaryImageFilter.h>
+#include <cpExtensions/Algorithms/RasterContourFilter.h>
#include <itkTriangleMeshToBinaryImageFilter.hxx>
+#include <cpExtensions/Algorithms/RasterContourFilter.hxx>
// -------------------------------------------------------------------------
cpPluginsImageMeshFilters::RasterMeshFilter::
void cpPluginsImageMeshFilters::RasterMeshFilter::
_GD0_2D( _TMesh* mesh )
{
+ typedef unsigned char _TPixel;
typedef itk::ImageBase< 2 > _TImageBase;
- typedef itk::Image< unsigned char, 2 > _TImage;
- typedef cpPlugins::DataObjects::BoundingBox _TBB;
- typedef typename _TImage::PointType _TPoint;
+ typedef itk::Image< _TPixel, 2 > _TImage;
+ typedef cpExtensions::Algorithms::RasterContourFilter< _TImage > _TFilter;
- static const unsigned int PAD = 10;
-
- _TImage::Pointer white = this->GetOutputData< _TImage >( "Output" );
- if( white.IsNull( ) )
- white = _TImage::New( );
-
- // Get configuration values
- typename _TImage::SpacingType spac;
- typename _TImage::SizeType size;
- typename _TImage::PointType origin;
- typename _TImage::DirectionType direction;
- typename _TImage::IndexType index;
-
- auto in_bb = this->GetInput< _TBB >( "Template" );
auto in_im = this->GetInputData< _TImageBase >( "Template" );
- if( in_im != NULL )
- {
- spac = in_im->GetSpacing( );
- size = in_im->GetLargestPossibleRegion( ).GetSize( );
- origin = in_im->GetOrigin( );
- direction = in_im->GetDirection( );
- index = in_im->GetLargestPossibleRegion( ).GetIndex( );
- }
- else
- {
- _TPoint minBB, maxBB;
- if( in_bb != NULL )
- {
- minBB = in_bb->GetMinimum< _TPoint >( );
- maxBB = in_bb->GetMaximum< _TPoint >( );
- }
- else
- {
- double bounds[ 6 ];
- mesh->GetBounds( bounds );
- minBB[ 0 ] = bounds[ 0 ];
- minBB[ 1 ] = bounds[ 1 ];
- maxBB[ 0 ] = bounds[ 2 ];
- maxBB[ 1 ] = bounds[ 3 ];
-
- } // fi
-
- double lx = double( maxBB[ 0 ] - minBB[ 0 ] );
- double ly = double( maxBB[ 1 ] - minBB[ 1 ] );
- double lm = ( lx < ly )? lx: ly;
-
- // Compute spacing
- spac.Fill( lm / double( this->m_Parameters.GetUint( "MinimumSize" ) ) );
-
- // Compute size
- size[ 0 ] = ( unsigned long )( std::ceil( lx / spac[ 0 ] ) );
- size[ 1 ] = ( unsigned long )( std::ceil( ly / spac[ 1 ] ) );
-
- // ... add some padding pixels
- size[ 0 ] += PAD;
- size[ 1 ] += PAD;
-
- // Set origin
- origin = minBB;
- origin[ 0 ] -= double( PAD >> 1 ) * spac[ 0 ];
- origin[ 1 ] -= double( PAD >> 1 ) * spac[ 1 ];
-
- // Remaining values
- direction.SetIdentity( );
- index.Fill( 0 );
-
- } // fi
-
- // Configure output image
- _TImage::RegionType region;
- region.SetSize( size );
- region.SetIndex( index );
- white->SetSpacing( spac );
- white->SetRegions( region );
- white->SetOrigin( origin );
- white->SetDirection( direction );
- white->Allocate( );
- white->FillBuffer( this->m_Parameters.GetUint( "InsideValue" ) );
- if( this->m_WhiteImage.IsNull( ) )
- this->m_WhiteImage = TImage::New( );
- this->m_WhiteImage->SetITK( white );
- vtkImageData* white_vtk = this->m_WhiteImage->GetVTK< vtkImageData >( );
-
- // Configure mini-pipeline
- if( this->m_Stripper.GetPointer( ) == NULL )
- this->m_Stripper = vtkSmartPointer< vtkStripper >::New( );
- this->m_Stripper->SetInputData( mesh );
- this->m_Stripper->Update( );
-
- if( this->m_Extruder.GetPointer( ) == NULL )
- this->m_Extruder = vtkSmartPointer< vtkLinearExtrusionFilter >::New( );
- this->m_Extruder->SetInputConnection( this->m_Stripper->GetOutputPort( ) );
- this->m_Extruder->SetScaleFactor( double( 1 ) );
- this->m_Extruder->SetExtrusionTypeToNormalExtrusion( );
- this->m_Extruder->SetVector( 0, 0, 1 );
- this->m_Extruder->Update( );
-
- if( this->m_PolyDataToStencil.GetPointer( ) == NULL )
- this->m_PolyDataToStencil =
- vtkSmartPointer< vtkPolyDataToImageStencil >::New( );
- this->m_PolyDataToStencil->SetTolerance( 0 );
- this->m_PolyDataToStencil->SetInputConnection( this->m_Extruder->GetOutputPort( ) );
- this->m_PolyDataToStencil->SetOutputOrigin( white_vtk->GetOrigin( ) );
- this->m_PolyDataToStencil->SetOutputSpacing( white_vtk->GetSpacing( ) );
- this->m_PolyDataToStencil->SetOutputWholeExtent( white_vtk->GetExtent( ) );
- this->m_PolyDataToStencil->Update( );
-
- this->m_ImageStencil = this->_CreateVTK< vtkImageStencil >( );
- this->m_ImageStencil->SetInputData( white_vtk );
- this->m_ImageStencil->SetStencilConnection( this->m_PolyDataToStencil->GetOutputPort( ) );
- this->m_ImageStencil->ReverseStencilOff( );
- this->m_ImageStencil->SetBackgroundValue( this->m_Parameters.GetUint( "OutsideValue" ) );
- this->m_ImageStencil->Update( );
- this->GetOutput( "Output" )->SetVTK( this->m_ImageStencil->GetOutput( ) );
+ if( in_im == NULL )
+ this->_Error( "A template is needed for 2D raster (this is temporal)." );
+ _TPixel inside = _TPixel( this->m_Parameters.GetUint( "InsideValue" ) );
+ _TPixel outside = _TPixel( this->m_Parameters.GetUint( "OutsideValue" ) );
+
+ auto filter = this->_CreateITK< _TFilter >( );
+ filter->AddPoints( mesh->GetPoints( ) );
+ filter->SetTemplate( in_im );
+ filter->SetInsideValue( inside );
+ filter->SetOutsideValue( outside );
+ filter->Update( );
+ this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
}
// -------------------------------------------------------------------------
static const unsigned int PAD = 10;
_TFilter* filter = this->_CreateITK< _TFilter >( );
- this->m_WhiteImage = NULL;
- this->m_Stripper = NULL;
- this->m_Extruder = NULL;
- this->m_PolyDataToStencil = NULL;
- this->m_ImageStencil = NULL;
// Get configuration values
typename _TImage::SpacingType spac;
#include <cpPlugins/DataObjects/Image.h>
#include <vtkSmartPointer.h>
-// -------------------------------------------------------------------------
-class vtkStripper;
-class vtkLinearExtrusionFilter;
-class vtkPolyDataToImageStencil;
-class vtkImageStencil;
-
-// -------------------------------------------------------------------------
namespace cpPluginsImageMeshFilters
{
/**
template< class _TMesh >
inline void _GD0_3D( _TMesh* mesh );
-
- protected:
- TImage::Pointer m_WhiteImage;
- vtkSmartPointer< vtkStripper > m_Stripper;
- vtkSmartPointer< vtkLinearExtrusionFilter > m_Extruder;
- vtkSmartPointer< vtkPolyDataToImageStencil > m_PolyDataToStencil;
- vtkSmartPointer< vtkImageStencil > m_ImageStencil;
};
} // ecapseman
this->m_Configured = true;
} // fi
-
- /* TODO
-
- if( this->m_Configured )
- {
- if( points->GetNumberOfPoints( ) == 0 )
- {
- std::stringstream text;
- bool start = true;
- for( auto w = this->m_Widgets.begin( ); w != this->m_Widgets.end( ); ++w )
- {
- for( auto r = ( *w )->Widgets.begin( ); r != ( *w )->Widgets.end( ); ++r )
- {
- auto rep =
- dynamic_cast< vtkSeedRepresentation* >(
- ( *r )->GetRepresentation( )
- );
- if( rep != NULL )
- {
- double pos[ 3 ];
- for( unsigned int i = 0; i < rep->GetNumberOfSeeds( ); ++i )
- {
- rep->GetSeedWorldPosition( i, pos );
- if( !start )
- text << "#";
- start = false;
- text << pos[ 0 ] << " " << pos[ 1 ] << " " << pos[ 2 ];
- points->InsertNextPoint( pos );
-
- } // rof
-
- } // rof
- ( *r )->EnabledOff( );
-
- } // rof
-
- } // rof
- this->m_Parameters.SetString( "Text", text.str( ) );
-
- } // fi
- }
- else
- {
- auto init_seeds = this->m_Parameters.GetString( "Text" );
- std::vector< std::string > tokens;
- cpExtensions::Tokenize( tokens, init_seeds, "#" );
- for( auto tIt = tokens.begin( ); tIt != tokens.end( ); ++tIt )
- {
- std::vector< std::string > coords;
- cpExtensions::Tokenize( coords, *tIt, " \t" );
- int dim = ( coords.size( ) < 3 )? coords.size( ): 3;
- double pos[ 3 ];
- for( unsigned int d = 0; d < 3; ++d )
- {
- pos[ d ] = double( 0 );
- if( d < dim )
- {
- std::istringstream value( coords[ d ] );
- value >> pos[ d ];
-
- } // fi
-
- } // rof
- verts->InsertNextCell( 1 );
- verts->InsertCellPoint( points->GetNumberOfPoints( ) );
- points->InsertNextPoint( pos );
-
- } // rof
- this->_Configure( );
- this->Modified( );
- this->m_Configured = true;
-
- } // fi
- this->GetOutput( "Output" )->SetVTK( pdata );
- */
-}
-
-// -------------------------------------------------------------------------
-/* TODO
-void cpPluginsWidgets::SplineWidget::
-_Configure( )
-{
- typedef cpPlugins::DataObjects::Image _TImage;
-
- auto image = this->GetInput< _TImage >( "Input" );
- if( image != NULL )
- {
- // Update actors
- auto vtk_image = image->GetVTK< vtkImageData >( );
- auto iIt = this->m_Interactors.begin( );
- for( ; iIt != this->m_Interactors.end( ); ++iIt )
- {
- auto ren = ( *iIt )->GetInteractorStyle( )->GetCurrentRenderer( );
- if( ren != NULL )
- {
- auto props = ren->GetViewProps( );
- if( props != NULL )
- {
- props->InitTraversal( );
- while( vtkProp* prop = props->GetNextProp( ) )
- {
- auto actor = dynamic_cast< TImageActor* >( prop );
- if( actor != NULL )
- if( actor->GetImage( ) == vtk_image )
- this->m_Props[ actor ] = *iIt;
-
- } // elihw
-
- } // fi
-
- } // fi
-
- } // rof
-
- // Process image
- if( this->m_Props.size( ) > 0 )
- {
- cpPlugins_Demangle_ImageVisualDims( image->GetITK( ), _GD0_Image );
- else this->_Error( "Invalid input image." );
- }
- else
- this->_Error( "Could not create a valid widget: no actors." );
- }
- else
- this->_Error( "Could not create a valid widget: no input." );
-}
-
-// -------------------------------------------------------------------------
-template< class _TImage >
-void cpPluginsWidgets::SplineWidget::
-_GD0_Image( _TImage* image )
-{
- for( auto p = this->m_Props.begin( ); p != this->m_Props.end( ); ++p )
- {
- TWidgetData* d =
- new TWidgetData(
- this, dynamic_cast< TImageActor* >( p->first ), p->second
- );
- this->m_Widgets.push_back( d );
-
- } // rof
-}
-
-// -------------------------------------------------------------------------
-cpPluginsWidgets::SplineWidget::TWidgetData::
-TWidgetData(
- SplineWidget* seedWidget,
- TImageActor* actor,
- vtkRenderWindowInteractor* iren
- )
-{
- auto cb = vtkSmartPointer< SplineWidgetCallback >::New( );
- cb->Widget = seedWidget;
- cb->Data = this;
- this->Command = cb;
- actor->AddObserver( vtkCommand::InteractionEvent, cb );
-
- auto image = actor->GetImage( );
- int ori = actor->GetOrientation( );
- int ext[ 6 ];
- image->GetExtent( ext );
- for( int i = ext[ ori << 1 ]; i <= ext[ ( ori << 1 ) + 1 ]; ++i )
- {
- auto placer = vtkSmartPointer< _TPlacer >::New( );
- auto handle = vtkSmartPointer< vtkPointHandleRepresentation3D >::New( );
- auto rep = vtkSmartPointer< vtkSeedRepresentation >::New( );
- auto wdg = vtkSmartPointer< _TWidget >::New( );
-
- placer->SetImageSlice( actor );
- handle->GetProperty( )->SetColor( 1, 0, 0 );
- handle->SetPointPlacer( placer );
- rep->SetHandleRepresentation( handle );
- wdg->SetRepresentation( rep );
- wdg->SetInteractor( iren );
- wdg->AddObserver( vtkCommand::PlacePointEvent, cb );
- wdg->AddObserver( vtkCommand::CursorChangedEvent, cb );
- wdg->EnabledOff( );
-
- this->Widgets.push_back( wdg );
- this->Placers.push_back( placer );
- this->Handles.push_back( handle );
- this->Representations.push_back( rep );
-
- } // rof
-
- this->ActualWidgetId = actor->GetSliceNumber( );
- this->Widgets[ this->ActualWidgetId ]->EnabledOn( );
-}
-
-// -------------------------------------------------------------------------
-cpPluginsWidgets::SplineWidget::TWidgetData::
-~TWidgetData( )
-{
}
-*/
// eof - $RCSfile$