X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FInterface%2FBaseMPRWidget.cxx;h=052e374f51c879794a222e1cf336e59eecca1a66;hb=f654620df52b811be7bd263a1775c93d29c69a65;hp=e7f270ce7700de29c530d35d531570b840bb976e;hpb=24dc7fa44ff75dc9336d703b8243ce1e52ff3429;p=cpPlugins.git diff --git a/lib/cpPlugins/Interface/BaseMPRWidget.cxx b/lib/cpPlugins/Interface/BaseMPRWidget.cxx index e7f270c..052e374 100644 --- a/lib/cpPlugins/Interface/BaseMPRWidget.cxx +++ b/lib/cpPlugins/Interface/BaseMPRWidget.cxx @@ -3,9 +3,25 @@ #ifdef cpPlugins_Interface_QT4 #include +#include +#include +#include #include #include +double cpPlugins::Interface::BaseMPRWidget:: +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 } +}; + // ------------------------------------------------------------------------- cpPlugins::Interface::BaseMPRWidget:: BaseMPRWidget( QWidget* parent ) @@ -49,73 +65,57 @@ cpPlugins::Interface::BaseMPRWidget:: // ------------------------------------------------------------------------- bool cpPlugins::Interface::BaseMPRWidget:: -AddImage( - vtkImageData* image, const std::string& name, const std::string& parent +AddData( + cpPlugins::Interface::DataObject* data, const std::string& name, + const std::string& parent ) { if( name == "" ) return( false ); - if( parent == "" ) - this->DeleteAllData( ); - auto iIt = this->m_Data.find( name ); if( iIt == this->m_Data.end( ) ) { - // Update tree if( parent != "" ) { auto pIt = this->m_Data.find( parent ); - if( pIt != this->m_Data.end( ) ) - this->m_Tree[ name ] = parent; - else + if( pIt == this->m_Data.end( ) ) return( false ); - } - else - this->m_MainImage = name; - + + } // fi + // Add new data - Data nd; - nd.Tag = Data::IMAGE; - nd.Image = image; - this->m_Data[ name ] = nd; + this->m_Data[ name ].SetSourceDataObject( data ); // Add to tree view - this->_UpdateItem( name, parent ); + this->_UpdateTreeItem( name, parent ); return( true ); } else return( false ); } +// ------------------------------------------------------------------------- +const std::string& cpPlugins::Interface::BaseMPRWidget:: +GetMainImage( ) const +{ + return( this->m_MainImage ); +} + // ------------------------------------------------------------------------- bool cpPlugins::Interface::BaseMPRWidget:: -AddMesh( - vtkPolyData* mesh, const std::string& name, const std::string& parent - ) +SetMainImage( const std::string& name ) { - if( name == "" || parent == "" ) - return( false ); - auto iIt = this->m_Data.find( name ); - if( iIt == this->m_Data.end( ) ) + if( iIt != this->m_Data.end( ) ) { - // Add new data - Data nd; - nd.Tag = Data::MESH; - nd.Mesh.Configure( mesh ); - this->m_Data[ name ] = nd; - - // Update tree - auto pIt = this->m_Data.find( parent ); - if( pIt != this->m_Data.end( ) ) - this->m_Tree[ name ] = parent; + if( iIt->second.Tag == Data::IMAGE ) + { + this->m_MainImage = name; + return( true ); + } else return( false ); - - // Add to tree view - this->_UpdateItem( name, parent ); - return( true ); } else return( false ); @@ -148,14 +148,14 @@ DeleteData( const std::string& name ) this->DeleteData( *dIt ); // Delete from tree widget - QTreeWidgetItem* item = this->_FindItem( name ); + 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 } @@ -163,7 +163,7 @@ DeleteData( const std::string& name ) void cpPlugins::Interface::BaseMPRWidget:: DeleteAllData( ) { - this->m_MPRObjects->ClearAll( ); + this->m_MPRObjects->Clear( ); this->m_Data.clear( ); this->m_Tree.clear( ); this->m_UI->LoadedData->clear( ); @@ -176,16 +176,18 @@ 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( ) ) + /* + 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 + if( iIt->second.Tag == Data::IMAGE ) + { + } + else if( iIt->second.Tag == Data::MESH ) + { + } // fi + */ } // ------------------------------------------------------------------------- @@ -198,20 +200,39 @@ ShowData( const std::string& name ) if( iIt->second.Tag == Data::IMAGE ) { - this->m_MPRObjects->AddImage( iIt->second.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( ); - + /* TODO + 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 cpPlugins::Interface::BaseMPRWidget:: +HideData( const std::string& name ) +{ +} + // ------------------------------------------------------------------------- vtkRenderWindowInteractor* cpPlugins::Interface::BaseMPRWidget:: GetInteractor( unsigned int i ) @@ -237,7 +258,7 @@ GetInteractor( unsigned int i ) ) { // Update tree view - QTreeWidgetItem* new_item = this->_UpdateItem( name, parent ); + QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent ); if( new_item == NULL ) return( false ); @@ -260,7 +281,7 @@ GetInteractor( unsigned int i ) ) { // Update tree view - QTreeWidgetItem* new_item = this->_UpdateItem( name, parent ); + QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent ); if( new_item == NULL ) return( false ); @@ -282,7 +303,7 @@ GetInteractor( unsigned int i ) ) { // Update tree view - QTreeWidgetItem* new_item = this->_UpdateItem( name, parent ); + QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent ); if( new_item == NULL ) return( false ); @@ -331,10 +352,12 @@ GetSelectedData( ) const // ------------------------------------------------------------------------- QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget:: -_FindItem( const std::string& name ) const +_FindItemInTree( const std::string& name ) const { QList< QTreeWidgetItem* > items = - this->m_UI->LoadedData->findItems( name.c_str( ), Qt::MatchExactly ); + this->m_UI->LoadedData->findItems( + name.c_str( ), Qt::MatchExactly | Qt::MatchRecursive + ); if( items.size( ) > 0 ) return( items[ 0 ] ); else @@ -343,16 +366,16 @@ _FindItem( const std::string& name ) const // ------------------------------------------------------------------------- QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget:: -_UpdateItem( const std::string& name, const std::string& parent ) +_UpdateTreeItem( const std::string& name, const std::string& parent ) { // Update tree view QTreeWidgetItem* new_item = NULL; if( parent != "" ) { - QTreeWidgetItem* parent_item = this->_FindItem( parent ); + QTreeWidgetItem* parent_item = this->_FindItemInTree( parent ); if( parent_item != NULL ) { - QTreeWidgetItem* old_item = this->_FindItem( name ); + QTreeWidgetItem* old_item = this->_FindItemInTree( name ); if( old_item == NULL ) { new_item = @@ -451,6 +474,107 @@ Configure( vtkPolyData* pd ) this->Actor->DeferLODConstructionOff( ); } +// ------------------------------------------------------------------------- +cpPlugins::Interface::BaseMPRWidget::Data:: +Data( ) +{ + this->Tag = Data::IMAGE; + this->Source = NULL; + this->Image = NULL; +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::BaseMPRWidget::Data:: +~Data( ) +{ +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface::BaseMPRWidget:: +Data& cpPlugins::Interface::BaseMPRWidget::Data:: +operator=( const Data& data ) +{ + this->Tag = data.Tag; + this->Source = data.Source; + if( this->Tag == Data::IMAGE ) + this->Image = data.Image; + else if( this->Tag == Data::MESH ) + this->Mesh = data.Mesh; + return( *this ); +} + +// ------------------------------------------------------------------------- +cpPlugins::Interface:: +DataObject* cpPlugins::Interface::BaseMPRWidget::Data:: +GetSourceDataObject( ) +{ + return( this->Source ); +} + +// ------------------------------------------------------------------------- +const cpPlugins::Interface:: +DataObject* cpPlugins::Interface::BaseMPRWidget::Data:: +GetSourceDataObject( ) const +{ + return( this->Source ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::Interface::BaseMPRWidget::Data:: +SetSourceDataObject( cpPlugins::Interface::DataObject* dobj ) +{ + typedef cpPlugins::Interface::Image _TImage; + typedef cpPlugins::Interface::Mesh _TMesh; + + this->Source = dobj; + _TImage* image = dynamic_cast< _TImage* >( dobj ); + if( image != NULL ) + { + this->Tag = Data::IMAGE; + this->Image = image->GetVTK< vtkImageData >( ); + } + else + { + _TMesh* mesh = dynamic_cast< _TMesh* >( dobj ); + if( mesh == NULL ) + return; + + this->Tag = Data::MESH; + this->Mesh.Configure( mesh->GetVTK< vtkPolyData >( ) ); + + } // fi +} + +// ------------------------------------------------------------------------- +vtkImageData* cpPlugins::Interface::BaseMPRWidget::Data:: +GetImage( ) +{ + if( this->Tag == Data::IMAGE ) + return( this->Image ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +vtkPolyData* cpPlugins::Interface::BaseMPRWidget::Data:: +GetMesh( ) +{ + if( this->Tag == Data::MESH ) + return( this->Mesh.Mesh ); + else + return( NULL ); +} + +// ------------------------------------------------------------------------- +vtkProp* cpPlugins::Interface::BaseMPRWidget::Data:: +GetMeshActor( ) +{ + if( this->Tag == Data::MESH ) + return( this->Mesh.Actor ); + else + return( NULL ); +} + #endif // cpPlugins_Interface_QT4 // eof - $RCSfile$