X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpExtensions%2FQT%2FSimpleMPRWidget.cxx;h=f3f1eb3c10cf7bafbe6dce11a366b67e33c42666;hb=e6bef8234ffd9030c68a6786466a08cf144b7871;hp=62b92961f849085c0d37804565a73641544f6d4b;hpb=dc1614d6180dbb97486870a379ae73e2c70525a1;p=cpPlugins.git diff --git a/lib/cpExtensions/QT/SimpleMPRWidget.cxx b/lib/cpExtensions/QT/SimpleMPRWidget.cxx index 62b9296..f3f1eb3 100644 --- a/lib/cpExtensions/QT/SimpleMPRWidget.cxx +++ b/lib/cpExtensions/QT/SimpleMPRWidget.cxx @@ -3,29 +3,34 @@ #ifdef cpExtensions_QT4 #include +#include -#include -#include - -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 } -}; +/* TODO + #include + #include + 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:: SimpleMPRWidget( QWidget* parent ) : QWidget( parent ), - m_UI( new Ui::SimpleMPRWidget ), - m_MainImage( "" ) + m_UI( new Ui::SimpleMPRWidget ) + /* + , + m_MainImage( "" ) + */ { this->m_UI->setupUi( this ); @@ -35,13 +40,22 @@ SimpleMPRWidget( QWidget* parent ) this->m_VTK[ 2 ] = this->m_UI->VTK10; this->m_VTK[ 3 ] = this->m_UI->VTK11; - this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( ); - this->m_MPRObjects->SetRenderWindows( + 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 ] ); + + } // 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( ) ); + */ // Connect slots QObject::connect( @@ -61,425 +75,52 @@ cpExtensions::QT::SimpleMPRWidget:: delete this->m_UI; } -// ------------------------------------------------------------------------- -unsigned int cpExtensions::QT::SimpleMPRWidget:: -GetNumberOfData( ) const -{ - return( this->m_Data.size( ) ); -} - -// ------------------------------------------------------------------------- -bool cpExtensions::QT::SimpleMPRWidget:: -AddData( - vtkImageData* data, const std::string& name, - const std::string& parent - ) -{ - if( name == "" ) - return( false ); - - auto iIt = this->m_Data.find( name ); - if( iIt == this->m_Data.end( ) ) - { - if( parent != "" ) - { - auto pIt = this->m_Data.find( parent ); - if( pIt == this->m_Data.end( ) ) - return( false ); - - } // fi - - // Add new data - this->m_Data[ name ].SetImageData( data ); - - // Set color - auto iIt = this->m_Data.find( name ); - if( iIt != this->m_Data.end( ) ) - { - vtkActor* actor = - dynamic_cast< vtkActor* >( iIt->second.GetMeshActor( ) ); - if( actor != NULL ) - { - unsigned int idx = this->m_Data.size( ) % 8; - actor->GetProperty( )->SetColor( - Self::cm_Colors[ idx ][ 0 ], - Self::cm_Colors[ idx ][ 1 ], - Self::cm_Colors[ idx ][ 2 ] - ); - - } // fi - - } // fi - - // Add to tree view - // TODO: this->_UpdateTreeItem( name, parent ); - return( true ); - } - else - return( false ); -} - -// ------------------------------------------------------------------------- -bool cpExtensions::QT::SimpleMPRWidget:: -AddData( vtkPolyData* data, const std::string& name ) -{ - if( name == "" ) - return( false ); - - auto iIt = this->m_Data.find( name ); - if( iIt == this->m_Data.end( ) ) - { - // Add new data - this->m_Data[ name ].SetPolyData( data ); - - // Set color - auto iIt = this->m_Data.find( name ); - if( iIt != this->m_Data.end( ) ) - { - vtkActor* actor = - dynamic_cast< vtkActor* >( iIt->second.GetMeshActor( ) ); - if( actor != NULL ) - { - unsigned int idx = this->m_Data.size( ) % 8; - actor->GetProperty( )->SetColor( - Self::cm_Colors[ idx ][ 0 ], - Self::cm_Colors[ idx ][ 1 ], - Self::cm_Colors[ idx ][ 2 ] - ); - - } // fi - - } // fi - - // Add to tree view - // TODO: this->_UpdateTreeItem( name, parent ); - return( true ); - } - else - return( false ); -} - -// ------------------------------------------------------------------------- -const std::string& cpExtensions::QT::SimpleMPRWidget:: -GetMainImage( ) const -{ - return( this->m_MainImage ); -} - -// ------------------------------------------------------------------------- -bool cpExtensions::QT::SimpleMPRWidget:: -SetMainImage( const std::string& name ) -{ - auto iIt = this->m_Data.find( name ); - if( iIt != this->m_Data.end( ) ) - { - if( iIt->second.Tag == Data::IMAGE ) - { - this->m_MainImage = name; - return( true ); - } - else - return( false ); - } - else - return( false ); -} - // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: -DeleteData( const std::string& name ) -{ - auto iIt = this->m_Data.find( name ); - if( iIt != this->m_Data.end( ) ) - { - this->m_Data.erase( iIt ); - - // Get children - std::vector< std::string > to_erase; - auto tIt = this->m_Tree.begin( ); - for( ; tIt != this->m_Tree.end( ); ++tIt ) - if( tIt->second == name ) - to_erase.push_back( tIt->first ); - - // Delete from tree - tIt = this->m_Tree.find( name ); - if( tIt != this->m_Tree.end( ) ) - this->m_Tree.erase( tIt ); - - // Recursive erase - auto dIt = to_erase.begin( ); - for( ; dIt != to_erase.end( ); ++dIt ) - this->DeleteData( *dIt ); - - // Delete from tree widget - /* TODO - QTreeWidgetItem* item = this->_FindItemInTree( name ); - if( item != NULL ) - this->m_UI->LoadedData->removeItemWidget( item, 0 ); - */ - - // Reset main image, just in case - if( this->m_Data.size( ) == 0 ) - this->m_MainImage = ""; - - } // fi -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::SimpleMPRWidget:: -DeleteAllData( ) -{ - this->m_MPRObjects->Clear( ); - this->m_Data.clear( ); - this->m_Tree.clear( ); - // TODO: this->m_UI->LoadedData->clear( ); - this->m_MainImage = ""; -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::SimpleMPRWidget:: -SetDataColor( - const std::string& name, const double& r, const double& g, const double& b - ) -{ - /* - auto iIt = this->m_Data.find( name ); - if( iIt == this->m_Data.end( ) ) - return; - - if( iIt->second.Tag == Data::IMAGE ) - { - } - else if( iIt->second.Tag == Data::MESH ) - { - } // fi - */ -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::SimpleMPRWidget:: -ShowData( const std::string& name ) -{ - auto iIt = this->m_Data.find( name ); - if( iIt == this->m_Data.end( ) ) - return; - - if( iIt->second.Tag == Data::IMAGE ) - { - if( name == this->m_MainImage ) - this->m_MPRObjects->SetInputImage( iIt->second.Image ); - else - { - unsigned int i = ( this->m_MPRObjects->GetNumberOfImages( ) - 1 ) % 8; - this->m_MPRObjects->AddBinaryImage( - iIt->second.Image, - Self::cm_Colors[ i ][ 0 ], - Self::cm_Colors[ i ][ 1 ], - Self::cm_Colors[ i ][ 2 ] - ); - } - this->m_MPRObjects->Show( ); - } - else if( iIt->second.Tag == Data::MESH ) - { - vtkRenderer* ren = - this->m_VTK[ 3 ]->GetRenderWindow( )-> - GetRenderers( )->GetFirstRenderer( ); - if( ren == NULL ) - return; - ren->AddActor( iIt->second.GetMeshActor( ) ); - this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); - - } // fi -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::SimpleMPRWidget:: -HideData( const std::string& name ) -{ -} - -// ------------------------------------------------------------------------- -vtkRenderWindowInteractor* cpExtensions::QT::SimpleMPRWidget:: -GetInteractor( unsigned int i ) +SetMainImage( vtkImageData* image ) { - if( i < 4 ) - { - if( this->m_VTK[ i ] != NULL ) - return( this->m_VTK[ i ]->GetInteractor( ) ); - else - return( NULL ); - } - else - return( NULL ); -} - -// ------------------------------------------------------------------------- -/* - bool cpExtensions::QT::SimpleMPRWidget:: - ShowImage( - vtkImageData* image, - const std::string& name, - const std::string& parent - ) - { - // Update tree view - QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent ); - if( new_item == NULL ) - return( false ); - - // Associate new data - this->m_Images[ name ] = image; - this->m_Tree[ name ] = parent; - - // Show image and return - this->m_MPRObjects->AddImage( image ); - return( true ); - } - - // ------------------------------------------------------------------------- - bool cpExtensions::QT::SimpleMPRWidget:: - ShowImage( - vtkImageData* image, - const std::string& name, - const std::string& parent, - const double& r, const double& g, const double& b - ) + for( unsigned int i = 0; i < 3; ++i ) { - // Update tree view - QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent ); - if( new_item == NULL ) - return( false ); - - // Associate new data - this->m_Images[ name ] = image; - this->m_Tree[ name ] = parent; - - // Show image and return - this->m_MPRObjects->AddImage( image ); - return( true ); - } - - // ------------------------------------------------------------------------- - bool cpExtensions::QT::SimpleMPRWidget:: - ShowMesh( - vtkPolyData* mesh, - const std::string& name, - const std::string& parent - ) - { - // Update tree view - QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent ); - if( new_item == NULL ) - return( false ); - - // Associate new data - PolyDataActor* actor = new PolyDataActor( mesh ); - this->m_Meshes[ name ] = actor; - this->m_Tree[ name ] = parent; - - // Show mesh - this->_Add3DActor( actor->Actor ); - return( true ); - } - - // ------------------------------------------------------------------------- - bool cpExtensions::QT::SimpleMPRWidget:: - ShowMesh( - vtkPolyData* mesh, - const std::string& name, - const std::string& parent, - const double& r, const double& g, const double& b - ) - { - return false; - } - - // ------------------------------------------------------------------------- - void cpExtensions::QT::SimpleMPRWidget:: - ClearAll( ) - { - this->m_MPRObjects->ClearAll( ); - this->m_Images.clear( ); - this->m_Meshes.clear( ); - } -*/ - -// ------------------------------------------------------------------------- -std::string cpExtensions::QT::SimpleMPRWidget:: -GetSelectedData( ) const -{ - /* TODO - QTreeWidgetItem* item = this->m_UI->LoadedData->currentItem( ); - if( item != NULL ) - return( item->text( 0 ).toStdString( ) ); - else - */ - return( "" ); -} - -// ------------------------------------------------------------------------- -/* TODO -QTreeWidgetItem* cpExtensions::QT::SimpleMPRWidget:: -_FindItemInTree( const std::string& name ) const -{ - QList< QTreeWidgetItem* > items = - this->m_UI->LoadedData->findItems( - name.c_str( ), Qt::MatchExactly | Qt::MatchRecursive + this->m_2DSlices[ i ] = vtkSmartPointer< TActors >::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 ]->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( ) + ) ); - if( items.size( ) > 0 ) - return( items[ 0 ] ); - else - return( NULL ); -} -// ------------------------------------------------------------------------- -QTreeWidgetItem* cpExtensions::QT::SimpleMPRWidget:: -_UpdateTreeItem( const std::string& name, const std::string& parent ) -{ - // Update tree view - QTreeWidgetItem* new_item = NULL; - if( parent != "" ) + } // rof + + for( unsigned int i = 0; i < 3; ++i ) { - QTreeWidgetItem* parent_item = this->_FindItemInTree( parent ); - if( parent_item != NULL ) + for( unsigned int j = 0; j < 3; ++j ) { - QTreeWidgetItem* old_item = this->_FindItemInTree( name ); - if( old_item == NULL ) - { - new_item = - new QTreeWidgetItem( parent_item, QStringList( name.c_str( ) ) ); - parent_item->setExpanded( true ); + if( i != j ) + this->m_2DSlices[ i ]->AssociateSlice( this->m_2DSlices[ j ] ); + this->m_2DSlices[ i ]->AssociateSlice( this->m_3DSlices[ j ] ); - } // fi + } // rof - } // fi - } - else + } // rof + for( unsigned int i = 0; i < 3; ++i ) { - new_item = new QTreeWidgetItem( - ( QTreeWidgetItem* )( NULL ), QStringList( name.c_str( ) ) - ); - this->m_UI->LoadedData->addTopLevelItem( new_item ); + this->m_2DSlices[ i ]->GetStyle( )-> + SetCurrentRenderer( this->m_Renderers[ i ] ); + this->m_Renderers[ i ]->ResetCamera( ); + this->m_VTK[ i ]->GetRenderWindow( )->Render( ); - } // fi - return( new_item ); -} -*/ - -// ------------------------------------------------------------------------- -/* - void cpExtensions::QT::SimpleMPRWidget:: - _Add3DActor( vtkProp3D* prop ) - { - vtkRenderer* ren = - this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( ); - if( ren == NULL ) - return; - ren->AddActor( prop ); + } // rof + this->m_Renderers[ 3 ]->ResetCamera( ); this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); - } -*/ +} // ------------------------------------------------------------------------- void cpExtensions::QT::SimpleMPRWidget:: @@ -495,128 +136,6 @@ _SyncTop( int a, int b ) this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) ); } -// ------------------------------------------------------------------------- -cpExtensions::QT::SimpleMPRWidget::PolyDataActor:: -PolyDataActor( ) - : Mesh( NULL ), - Normals( NULL ), - Stripper( NULL ), - Mapper( NULL ), - Actor( NULL ) -{ -} - -// ------------------------------------------------------------------------- -cpExtensions::QT::SimpleMPRWidget::PolyDataActor:: -~PolyDataActor( ) -{ - if( this->Actor != NULL ) this->Actor->Delete( ); - if( this->Mapper != NULL ) this->Mapper->Delete( ); - if( this->Stripper != NULL ) this->Stripper->Delete( ); - if( this->Normals != NULL ) this->Normals->Delete( ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::SimpleMPRWidget::PolyDataActor:: -Configure( vtkPolyData* pd ) -{ - if( pd == NULL ) - return; - - double range[ 2 ]; - pd->GetScalarRange( range ); - - this->Normals = vtkPolyDataNormals::New( ); - this->Stripper = vtkStripper::New( ); - this->Mapper = vtkPolyDataMapper::New( ); - this->Actor = vtkQuadricLODActor::New( ); - - this->Mesh = pd; - this->Normals->SetInputData( pd ); - this->Normals->SetFeatureAngle( 60.0 ); - this->Stripper->SetInputConnection( this->Normals->GetOutputPort( ) ); - this->Mapper->SetInputConnection( this->Stripper->GetOutputPort( ) ); - this->Mapper->UseLookupTableScalarRangeOff( ); - this->Mapper->SetScalarRange( - range[ 0 ], ( ( range[ 1 ] - range[ 0 ] ) * 0.75 ) + range[ 0 ] - ); - this->Actor->SetMapper( this->Mapper ); - this->Actor->DeferLODConstructionOff( ); -} - -// ------------------------------------------------------------------------- -cpExtensions::QT::SimpleMPRWidget::Data:: -Data( ) -{ - this->Tag = Data::IMAGE; - this->Image = NULL; -} - -// ------------------------------------------------------------------------- -cpExtensions::QT::SimpleMPRWidget::Data:: -~Data( ) -{ -} - -// ------------------------------------------------------------------------- -cpExtensions::QT::SimpleMPRWidget:: -Data& cpExtensions::QT::SimpleMPRWidget::Data:: -operator=( const Data& data ) -{ - this->Tag = data.Tag; - if( this->Tag == Data::IMAGE ) - this->Image = data.Image; - else if( this->Tag == Data::MESH ) - this->Mesh = data.Mesh; - return( *this ); -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::SimpleMPRWidget::Data:: -SetImageData( vtkImageData* data ) -{ - this->Tag = Data::IMAGE; - this->Image = data; -} - -// ------------------------------------------------------------------------- -void cpExtensions::QT::SimpleMPRWidget::Data:: -SetPolyData( vtkPolyData* data ) -{ - this->Tag = Data::MESH; - this->Mesh.Configure( data ); -} - -// ------------------------------------------------------------------------- -vtkImageData* cpExtensions::QT::SimpleMPRWidget::Data:: -GetImage( ) -{ - if( this->Tag == Data::IMAGE ) - return( this->Image ); - else - return( NULL ); -} - -// ------------------------------------------------------------------------- -vtkPolyData* cpExtensions::QT::SimpleMPRWidget::Data:: -GetMesh( ) -{ - if( this->Tag == Data::MESH ) - return( this->Mesh.Mesh ); - else - return( NULL ); -} - -// ------------------------------------------------------------------------- -vtkProp* cpExtensions::QT::SimpleMPRWidget::Data:: -GetMeshActor( ) -{ - if( this->Tag == Data::MESH ) - return( this->Mesh.Actor ); - else - return( NULL ); -} - #endif // cpExtensions_QT4 // eof - $RCSfile$