#include #ifdef cpPlugins_Interface_QT4 #include #include #include // ------------------------------------------------------------------------- cpPlugins::Interface::BaseMPRWidget:: BaseMPRWidget( QWidget* parent ) : QWidget( parent ), m_UI( new Ui::BaseMPRWidget ) { 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_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( this->m_UI->TopSplitter, SIGNAL( splitterMoved( int, int ) ), this, SLOT( _SyncBottom( int, int ) ) ); QObject::connect( this->m_UI->BottomSplitter, SIGNAL( splitterMoved( int, int ) ), this, SLOT( _SyncTop( int, int ) ) ); } // ------------------------------------------------------------------------- cpPlugins::Interface::BaseMPRWidget:: ~BaseMPRWidget( ) { delete this->m_UI; // Delete polydata actors std::map< std::string, PolyDataActor* >::iterator mIt = this->m_Meshes.begin( ); for( ; mIt != this->m_Meshes.end( ); ++mIt ) delete mIt->second; this->m_Meshes.clear( ); } // ------------------------------------------------------------------------- bool cpPlugins::Interface::BaseMPRWidget:: ShowImage( vtkImageData* image, const std::string& name, const std::string& parent ) { // Update tree view QTreeWidgetItem* new_item = this->_UpdateItem( 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 cpPlugins::Interface::BaseMPRWidget:: ShowImage( vtkImageData* image, const std::string& name, const std::string& parent, const double& r, const double& g, const double& b ) { // Update tree view QTreeWidgetItem* new_item = this->_UpdateItem( 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 cpPlugins::Interface::BaseMPRWidget:: ShowMesh( vtkPolyData* mesh, const std::string& name, const std::string& parent ) { // Update tree view QTreeWidgetItem* new_item = this->_UpdateItem( 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 cpPlugins::Interface::BaseMPRWidget:: ShowMesh( vtkPolyData* mesh, const std::string& name, const std::string& parent, const double& r, const double& g, const double& b ) { return false; } // ------------------------------------------------------------------------- void cpPlugins::Interface::BaseMPRWidget:: ClearAll( ) { /* this->m_MPRObjects->ClearAll( ); this->m_Images.clear( ); this->m_Meshes.clear( ); */ } // ------------------------------------------------------------------------- std::string cpPlugins::Interface::BaseMPRWidget:: GetSelectedData( ) const { QTreeWidgetItem* item = this->m_UI->LoadedData->currentItem( ); if( item != NULL ) return( item->text( 0 ).toStdString( ) ); else return( "" ); } // ------------------------------------------------------------------------- QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget:: _FindItem( const std::string& name ) const { QList< QTreeWidgetItem* > items = this->m_UI->LoadedData->findItems( name.c_str( ), Qt::MatchExactly ); if( items.size( ) > 0 ) return( items[ 0 ] ); else return( NULL ); } // ------------------------------------------------------------------------- QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget:: _UpdateItem( const std::string& name, const std::string& parent ) { // Update tree view QTreeWidgetItem* new_item = NULL; if( parent != "" ) { QTreeWidgetItem* parent_item = this->_FindItem( parent ); if( parent_item != NULL ) { QTreeWidgetItem* old_item = this->_FindItem( name ); if( old_item == NULL ) { new_item = new QTreeWidgetItem( parent_item, QStringList( name.c_str( ) ) ); parent_item->setExpanded( true ); } // fi } // fi } else { new_item = new QTreeWidgetItem( ( QTreeWidgetItem* )( NULL ), QStringList( name.c_str( ) ) ); this->m_UI->LoadedData->addTopLevelItem( new_item ); } // fi return( new_item ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::BaseMPRWidget:: _Add3DActor( vtkProp3D* prop ) { vtkRenderer* ren = this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( ); if( ren == NULL ) return; ren->AddActor( prop ); this->m_VTK[ 3 ]->GetRenderWindow( )->Render( ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::BaseMPRWidget:: _SyncBottom( int a, int b ) { this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) ); } // ------------------------------------------------------------------------- void cpPlugins::Interface::BaseMPRWidget:: _SyncTop( int a, int b ) { this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) ); } // ------------------------------------------------------------------------- cpPlugins::Interface::BaseMPRWidget::PolyDataActor:: PolyDataActor( vtkPolyData* pd ) { if( pd == NULL ) return; double range[ 2 ]; pd->GetScalarRange( range ); this->Normals = vtkSmartPointer< vtkPolyDataNormals >::New( ); this->Stripper = vtkSmartPointer< vtkStripper >::New( ); this->Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( ); this->Actor = vtkSmartPointer< vtkQuadricLODActor >::New( ); 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( ); } #endif // cpPlugins_Interface_QT4 // eof - $RCSfile$