1 #include <cpPlugins/Interface/BaseMPRWidget.h>
3 #ifdef cpPlugins_Interface_QT4
5 #include <cpPlugins/Interface/ui_BaseMPRWidget.h>
6 #include <QTreeWidgetItem>
7 #include <vtkRendererCollection.h>
9 // -------------------------------------------------------------------------
10 cpPlugins::Interface::BaseMPRWidget::
11 BaseMPRWidget( QWidget* parent )
13 m_UI( new Ui::BaseMPRWidget )
15 this->m_UI->setupUi( this );
17 // Configure VTK widgets
18 this->m_VTK[ 0 ] = this->m_UI->VTK01;
19 this->m_VTK[ 1 ] = this->m_UI->VTK00;
20 this->m_VTK[ 2 ] = this->m_UI->VTK10;
21 this->m_VTK[ 3 ] = this->m_UI->VTK11;
23 this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( );
24 this->m_MPRObjects->SetRenderWindows(
25 this->m_VTK[ 0 ]->GetRenderWindow( ),
26 this->m_VTK[ 1 ]->GetRenderWindow( ),
27 this->m_VTK[ 2 ]->GetRenderWindow( ),
28 this->m_VTK[ 3 ]->GetRenderWindow( )
33 this->m_UI->TopSplitter, SIGNAL( splitterMoved( int, int ) ),
34 this, SLOT( _SyncBottom( int, int ) )
37 this->m_UI->BottomSplitter, SIGNAL( splitterMoved( int, int ) ),
38 this, SLOT( _SyncTop( int, int ) )
42 // -------------------------------------------------------------------------
43 cpPlugins::Interface::BaseMPRWidget::
48 // Delete polydata actors
49 std::map< std::string, PolyDataActor* >::iterator mIt =
50 this->m_Meshes.begin( );
51 for( ; mIt != this->m_Meshes.end( ); ++mIt )
53 this->m_Meshes.clear( );
56 // -------------------------------------------------------------------------
57 bool cpPlugins::Interface::BaseMPRWidget::
60 const std::string& name,
61 const std::string& parent
65 QTreeWidgetItem* new_item = this->_UpdateItem( name, parent );
66 if( new_item == NULL )
70 this->m_Images[ name ] = image;
71 this->m_Tree[ name ] = parent;
73 // Show image and return
74 this->m_MPRObjects->AddImage( image );
78 // -------------------------------------------------------------------------
79 bool cpPlugins::Interface::BaseMPRWidget::
82 const std::string& name,
83 const std::string& parent,
84 const double& r, const double& g, const double& b
89 // -------------------------------------------------------------------------
90 bool cpPlugins::Interface::BaseMPRWidget::
93 const std::string& name,
94 const std::string& parent
98 QTreeWidgetItem* new_item = this->_UpdateItem( name, parent );
99 if( new_item == NULL )
102 // Associate new data
103 PolyDataActor* actor = new PolyDataActor( mesh );
104 this->m_Meshes[ name ] = actor;
105 this->m_Tree[ name ] = parent;
108 this->_Add3DActor( actor->Actor );
112 // -------------------------------------------------------------------------
113 bool cpPlugins::Interface::BaseMPRWidget::
116 const std::string& name,
117 const std::string& parent,
118 const double& r, const double& g, const double& b
123 // -------------------------------------------------------------------------
124 void cpPlugins::Interface::BaseMPRWidget::
128 this->m_MPRObjects->ClearAll( );
129 this->m_Images.clear( );
130 this->m_Meshes.clear( );
134 // -------------------------------------------------------------------------
135 std::string cpPlugins::Interface::BaseMPRWidget::
136 GetSelectedData( ) const
138 QTreeWidgetItem* item = this->m_UI->LoadedData->currentItem( );
140 return( item->text( 0 ).toStdString( ) );
145 // -------------------------------------------------------------------------
146 QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget::
147 _FindItem( const std::string& name ) const
149 QList< QTreeWidgetItem* > items =
150 this->m_UI->LoadedData->findItems( name.c_str( ), Qt::MatchExactly );
151 if( items.size( ) > 0 )
152 return( items[ 0 ] );
157 // -------------------------------------------------------------------------
158 QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget::
159 _UpdateItem( const std::string& name, const std::string& parent )
162 QTreeWidgetItem* new_item = NULL;
165 QTreeWidgetItem* parent_item = this->_FindItem( parent );
166 if( parent_item != NULL )
168 QTreeWidgetItem* old_item = this->_FindItem( name );
169 if( old_item == NULL )
172 new QTreeWidgetItem( parent_item, QStringList( name.c_str( ) ) );
173 parent_item->setExpanded( true );
181 new_item = new QTreeWidgetItem(
182 ( QTreeWidgetItem* )( NULL ), QStringList( name.c_str( ) )
184 this->m_UI->LoadedData->addTopLevelItem( new_item );
190 // -------------------------------------------------------------------------
191 void cpPlugins::Interface::BaseMPRWidget::
192 _Add3DActor( vtkProp3D* prop )
195 this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
198 ren->AddActor( prop );
199 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
202 // -------------------------------------------------------------------------
203 void cpPlugins::Interface::BaseMPRWidget::
204 _SyncBottom( int a, int b )
206 this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) );
209 // -------------------------------------------------------------------------
210 void cpPlugins::Interface::BaseMPRWidget::
211 _SyncTop( int a, int b )
213 this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) );
216 // -------------------------------------------------------------------------
217 cpPlugins::Interface::BaseMPRWidget::PolyDataActor::
218 PolyDataActor( vtkPolyData* pd )
224 pd->GetScalarRange( range );
226 this->Normals = vtkSmartPointer< vtkPolyDataNormals >::New( );
227 this->Stripper = vtkSmartPointer< vtkStripper >::New( );
228 this->Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
229 this->Actor = vtkSmartPointer< vtkQuadricLODActor >::New( );
231 this->Normals->SetInputData( pd );
232 this->Normals->SetFeatureAngle( 60.0 );
233 this->Stripper->SetInputConnection( this->Normals->GetOutputPort( ) );
234 this->Mapper->SetInputConnection( this->Stripper->GetOutputPort( ) );
235 this->Mapper->UseLookupTableScalarRangeOff( );
236 this->Mapper->SetScalarRange(
237 range[ 0 ], ( ( range[ 1 ] - range[ 0 ] ) * 0.75 ) + range[ 0 ]
239 this->Actor->SetMapper( this->Mapper );
240 this->Actor->DeferLODConstructionOff( );
243 #endif // cpPlugins_Interface_QT4