#ifdef cpExtensions_QT4
#include <cpExtensions/ui_SimpleMPRWidget.h>
+#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
-/* TODO
- #include <vtkProperty.h>
- #include <vtkRendererCollection.h>
- double cpExtensions::QT::SimpleMPRWidget::
- cm_Colors[ 8 ][ 3 ] =
- {
- { 1.0, 0.0, 0.0 },
- { 0.0, 1.0, 0.0 },
- { 0.0, 0.0, 1.0 },
- { 0.0, 1.0, 1.0 },
- { 1.0, 0.0, 1.0 },
- { 1.0, 1.0, 0.0 },
- { 1.0, 0.5, 0.0 },
- { 1.0, 0.0, 0.5 }
- };
-*/
+// -------------------------------------------------------------------------
+cpExtensions::QT::SimpleMPRWidget::_3DInteractorStyle*
+cpExtensions::QT::SimpleMPRWidget::_3DInteractorStyle::
+New( )
+{
+ return( new _3DInteractorStyle( ) );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::SimpleMPRWidget::_3DInteractorStyle::
+OnKeyPress( )
+{
+ vtkRenderWindowInteractor* i = this->Interactor;
+ std::string key = i->GetKeySym( );
+ if( key == "r" || key == "R" )
+ {
+ this->CurrentRenderer->ResetCamera( );
+ i->Render( );
+
+ } // fi
+}
// -------------------------------------------------------------------------
cpExtensions::QT::SimpleMPRWidget::
SimpleMPRWidget( QWidget* parent )
: QWidget( parent ),
m_UI( new Ui::SimpleMPRWidget )
- /*
- ,
- m_MainImage( "" )
- */
{
this->m_UI->setupUi( this );
// Configure VTK widgets
- this->m_VTK[ 0 ] = this->m_UI->VTK01;
- this->m_VTK[ 1 ] = this->m_UI->VTK00;
- this->m_VTK[ 2 ] = this->m_UI->VTK10;
- this->m_VTK[ 3 ] = this->m_UI->VTK11;
-
+ this->m_VTK[ 0 ] = this->m_UI->VTK_X;
+ this->m_VTK[ 1 ] = this->m_UI->VTK_Y;
+ this->m_VTK[ 2 ] = this->m_UI->VTK_Z;
+ this->m_VTK[ 3 ] = this->m_UI->VTK_3D;
for( unsigned int i = 0; i < 4; ++i )
{
this->m_Renderers[ i ] = vtkSmartPointer< vtkRenderer >::New( );
- this->m_VTK[ i ]->GetRenderWindow( )->AddRenderer( this->m_Renderers[ i ] );
+ this->m_VTK[ i ]->GetRenderWindow( )->
+ AddRenderer( this->m_Renderers[ i ] );
} // rof
-
- /*
- this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( );
- this->m_MPRObjects->SetRenderWindows(
- this->m_VTK[ 0 ]->GetRenderWindow( ),
- this->m_VTK[ 1 ]->GetRenderWindow( ),
- this->m_VTK[ 2 ]->GetRenderWindow( ),
- this->m_VTK[ 3 ]->GetRenderWindow( )
- );
- */
+ vtkSmartPointer< _3DInteractorStyle > style =
+ vtkSmartPointer< _3DInteractorStyle >::New( );
+ this->m_VTK[ 3 ]->GetRenderWindow( )->
+ GetInteractor( )->SetInteractorStyle( style );
+ style->SetCurrentRenderer( this->m_Renderers[ 3 ] );
// Connect slots
QObject::connect(
cpExtensions::QT::SimpleMPRWidget::
~SimpleMPRWidget( )
{
+ this->Clear( );
delete this->m_UI;
}
this->m_3DSlices[ i ]->Clear( );
} // rof
- this->m_PolyDatas.clear( );
+ this->m_NamedActors.clear( );
}
// -------------------------------------------------------------------------
void cpExtensions::QT::SimpleMPRWidget::
-SetMainImage( vtkImageData* image )
+SetMainImage( vtkImageData* image, const std::string& name )
{
+ this->Clear( );
for( unsigned int i = 0; i < 3; ++i )
{
- this->m_2DSlices[ i ] = vtkSmartPointer< TActors >::New( );
+ this->m_2DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( );
this->m_2DSlices[ i ]->SetInputData( image, i );
this->m_2DSlices[ i ]->PushInto( this->m_Renderers[ i ] );
this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( )->
SetInteractorStyle( this->m_2DSlices[ i ]->GetStyle( ) );
- this->m_3DSlices[ i ] = vtkSmartPointer< TActors >::New( );
+ this->m_3DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( );
this->m_3DSlices[ i ]->SetInputData( image, i );
this->m_3DSlices[ i ]->PushInto( this->m_Renderers[ 3 ] );
this->m_3DSlices[ i ]->SetStyle(
)
);
+ this->m_NamedActors[ name ].insert(
+ this->m_2DSlices[ i ]->GetImageActor( )
+ );
+ this->m_NamedActors[ name ].insert(
+ this->m_3DSlices[ i ]->GetImageActor( )
+ );
+
} // rof
+ this->_AssociateSlices( );
+}
+// -------------------------------------------------------------------------
+void cpExtensions::QT::SimpleMPRWidget::
+SetMainActor( vtkImageActor* actor, const std::string& name )
+{
+ this->Clear( );
+ vtkImageData* image = NULL;
for( unsigned int i = 0; i < 3; ++i )
{
- for( unsigned int j = 0; j < 3; ++j )
+ this->m_2DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( );
+ if( i == 0 )
{
- if( i != j )
- this->m_2DSlices[ i ]->AssociateSlice( this->m_2DSlices[ j ] );
- this->m_2DSlices[ i ]->AssociateSlice( this->m_3DSlices[ j ] );
+ this->m_2DSlices[ i ]->SetInputActor( actor, i );
+ image = this->m_2DSlices[ i ]->GetInputData( );
+ }
+ else
+ this->m_2DSlices[ i ]->SetInputData( image, i );
+ this->m_2DSlices[ i ]->PushInto( this->m_Renderers[ i ] );
+ this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( )->
+ SetInteractorStyle( this->m_2DSlices[ i ]->GetStyle( ) );
- } // rof
+ this->m_3DSlices[ i ] = vtkSmartPointer< TSliceActors >::New( );
+ this->m_3DSlices[ i ]->SetInputData( image, i );
+ this->m_3DSlices[ i ]->PushInto( this->m_Renderers[ 3 ] );
+ this->m_3DSlices[ i ]->SetStyle(
+ dynamic_cast< vtkInteractorStyle* >(
+ this->m_Renderers[ 3 ]->GetRenderWindow( )->
+ GetInteractor( )->GetInteractorStyle( )
+ )
+ );
+
+ this->m_NamedActors[ name ].insert(
+ this->m_2DSlices[ i ]->GetImageActor( )
+ );
+ this->m_NamedActors[ name ].insert(
+ this->m_3DSlices[ i ]->GetImageActor( )
+ );
} // rof
- for( unsigned int i = 0; i < 3; ++i )
+ this->_AssociateSlices( );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::SimpleMPRWidget::
+AddImage( vtkImageData* image, const std::string& name )
+{
+ std::cerr << "SimpleMPR: adding image" << std::endl;
+ std::exit( 1 );
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::SimpleMPRWidget::
+AddImageActor( vtkImageActor* actor, const std::string& name )
+{
+ unsigned int i = 0;
+ bool cont = true;
+ while( i < 3 && cont )
{
- this->m_2DSlices[ i ]->GetStyle( )->
- SetCurrentRenderer( this->m_Renderers[ i ] );
- this->m_Renderers[ i ]->ResetCamera( );
- this->m_VTK[ i ]->GetRenderWindow( )->Render( );
+ if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
+ {
+ if( this->m_2DSlices[ i ]->GetImageActor( ) != NULL )
+ {
+ // TODO: add image actor
+ }
+ else
+ cont = false;
+
+ } // fi
+ i++;
} // rof
- this->m_Renderers[ 3 ]->ResetCamera( );
- this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
+
+ // Add if no actors were found
+ if( cont )
+ this->SetMainActor( actor, name );
}
// -------------------------------------------------------------------------
void cpExtensions::QT::SimpleMPRWidget::
-AddMesh( vtkPolyData* mesh )
+AddMesh( vtkPolyData* mesh, const std::string& name )
{
- PolyDataActor a;
- a.Configure( mesh );
- this->m_PolyDatas[ mesh ] = a;
- this->m_Renderers[ 3 ]->AddViewProp( a.Actor );
+ std::cerr << "SimpleMPR: adding mesh" << std::endl;
+ std::exit( 1 );
+ /* TODO
+ PolyDataActor a;
+ a.Configure( mesh );
+ this->m_PolyDatas[ mesh ] = a;
+ this->m_Renderers[ 3 ]->AddViewProp( a.Actor );
+
+ bool has_main_image = false;
+ for( unsigned int i = 0; i < 3; ++i )
+ {
+ if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
+ {
+ if( this->m_2DSlices[ i ]->GetInputData( ) != NULL )
+ {
+ has_main_image = true;
+ this->m_2DSlices[ i ]->AddMesh( mesh );
+ this->m_2DSlices[ i ]->Render( );
+
+ } // fi
+
+ } // fi
- bool has_main_image = false;
+ } // rof
+ if( !has_main_image )
+ this->m_Renderers[ 3 ]->ResetCamera( );
+ this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
+ */
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::SimpleMPRWidget::
+AddMeshActor( vtkProp3D* actor, const std::string& name )
+{
+ if( actor != NULL )
+ {
+ std::cout << name << " " << actor << std::endl;
+
+ this->m_Renderers[ 3 ]->AddViewProp( actor );
+ this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
+ this->m_NamedActors[ name ].insert( actor );
+ std::cout << "Size: " << this->m_NamedActors.size( ) << " " << this->m_NamedActors[ name ].size( ) << std::endl;
+
+
+ double bounds[ 6 ];
+ this->m_Renderers[ 3 ]->ComputeVisiblePropBounds( bounds );
+ std::cout
+ << bounds[ 0 ] << " " << bounds[ 1 ] << " "
+ << bounds[ 2 ] << " " << bounds[ 3 ] << " "
+ << bounds[ 4 ] << " " << bounds[ 5 ] << std::endl;
+
+ } // fi
+}
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::SimpleMPRWidget::
+AddActor( vtkProp* actor, const std::string& name )
+{
+ auto ia = dynamic_cast< vtkImageActor* >( actor );
+ if( ia == NULL )
+ {
+ auto ma = dynamic_cast< vtkProp3D* >( actor );
+ if( ma != NULL )
+ this->AddMeshActor( ma, name );
+ }
+ else
+ this->AddImageActor( ia, name );
+}
+
+// -------------------------------------------------------------------------
+const cpExtensions::QT::SimpleMPRWidget::
+TActors& cpExtensions::QT::SimpleMPRWidget::
+GetActors( const std::string& name ) const
+{
+ static const TActors empty;
+ auto i = this->m_NamedActors.find( name );
+ if( i != this->m_NamedActors.end( ) )
+ return( i->second );
+ else
+ return( empty );
+}
+
+// -------------------------------------------------------------------------
+vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget::
+GetInteractor( unsigned int i )
+{
+ if( i < 4 )
+ return( this->m_VTK[ i ]->GetRenderWindow( )->GetInteractor( ) );
+ else
+ return( NULL );
+}
+
+// -------------------------------------------------------------------------
+vtkRenderer* cpExtensions::QT::SimpleMPRWidget::
+GetRenderer( unsigned int i )
+{
+ if( i < 4 )
+ return( this->m_Renderers[ i ] );
+ else
+ return( NULL );
+}
+
+// -------------------------------------------------------------------------
+vtkRenderWindow* cpExtensions::QT::SimpleMPRWidget::
+GetRenderWindow( unsigned int i )
+{
+ if( i < 4 )
+ {
+ if( this->m_Renderers[ i ].GetPointer( ) != NULL )
+ return( this->m_Renderers[ i ]->GetRenderWindow( ) );
+ else
+ return( NULL );
+ }
+ else
+ return( NULL );
+}
+
+// -------------------------------------------------------------------------
+/* TODO
+ std::vector< std::pair< vtkImageActor*, vtkRenderer* > >
+ cpExtensions::QT::SimpleMPRWidget::
+ GetMainImageActors( )
+ {
+ std::vector< std::pair< vtkImageActor*, vtkRenderer* > > actors;
+ for( unsigned int i = 0; i < 3; ++i )
+ {
+ actors.push_back(
+ std::pair< vtkImageActor*, vtkRenderer* >(
+ this->m_2DSlices[ i ]->GetImageActor( ),
+ this->m_Renderers[ i ]
+ )
+ );
+ actors.push_back(
+ std::pair< vtkImageActor*, vtkRenderer* >(
+ this->m_3DSlices[ i ]->GetImageActor( ),
+ this->m_Renderers[ 3 ]
+ )
+ );
+
+ } // rof
+ return( actors );
+ }
+*/
+
+// -------------------------------------------------------------------------
+/* TODO
+ vtkActor* cpExtensions::QT::SimpleMPRWidget::
+ GetActor( vtkPolyData* mesh )
+ {
+ auto i = this->m_PolyDatas.find( mesh );
+ if( i != this->m_PolyDatas.end( ) )
+ return( i->second.Actor.GetPointer( ) );
+ else
+ return( NULL );
+ }
+*/
+
+// -------------------------------------------------------------------------
+void cpExtensions::QT::SimpleMPRWidget::
+_AssociateSlices( )
+{
for( unsigned int i = 0; i < 3; ++i )
{
- if( this->m_2DSlices[ i ].GetPointer( ) != NULL )
+ for( unsigned int j = 0; j < 3; ++j )
{
- if( this->m_2DSlices[ i ]->GetInputData( ) != NULL )
- {
- has_main_image = true;
- this->m_2DSlices[ i ]->AddMesh( mesh );
- this->m_2DSlices[ i ]->Render( );
+ if( i != j )
+ this->m_2DSlices[ i ]->AssociateSlice( this->m_2DSlices[ j ] );
+ this->m_2DSlices[ i ]->AssociateSlice( this->m_3DSlices[ j ] );
- } // fi
+ } // rof
- } // fi
+ } // rof
+ for( unsigned int i = 0; i < 3; ++i )
+ {
+ this->m_2DSlices[ i ]->GetStyle( )->
+ SetCurrentRenderer( this->m_Renderers[ i ] );
+ this->m_Renderers[ i ]->ResetCamera( );
+ this->m_VTK[ i ]->GetRenderWindow( )->Render( );
} // rof
- if( !has_main_image )
- this->m_Renderers[ 3 ]->ResetCamera( );
+ this->m_Renderers[ 3 ]->ResetCamera( );
this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
}