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 ),
16 this->m_UI->setupUi( this );
18 // Configure VTK widgets
19 this->m_VTK[ 0 ] = this->m_UI->VTK01;
20 this->m_VTK[ 1 ] = this->m_UI->VTK00;
21 this->m_VTK[ 2 ] = this->m_UI->VTK10;
22 this->m_VTK[ 3 ] = this->m_UI->VTK11;
24 this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( );
25 this->m_MPRObjects->SetRenderWindows(
26 this->m_VTK[ 0 ]->GetRenderWindow( ),
27 this->m_VTK[ 1 ]->GetRenderWindow( ),
28 this->m_VTK[ 2 ]->GetRenderWindow( ),
29 this->m_VTK[ 3 ]->GetRenderWindow( )
34 this->m_UI->TopSplitter, SIGNAL( splitterMoved( int, int ) ),
35 this, SLOT( _SyncBottom( int, int ) )
38 this->m_UI->BottomSplitter, SIGNAL( splitterMoved( int, int ) ),
39 this, SLOT( _SyncTop( int, int ) )
43 // -------------------------------------------------------------------------
44 cpPlugins::Interface::BaseMPRWidget::
50 // -------------------------------------------------------------------------
51 bool cpPlugins::Interface::BaseMPRWidget::
53 vtkImageData* image, const std::string& name, const std::string& parent
60 this->DeleteAllData( );
62 auto iIt = this->m_Data.find( name );
63 if( iIt == this->m_Data.end( ) )
68 auto pIt = this->m_Data.find( parent );
69 if( pIt != this->m_Data.end( ) )
70 this->m_Tree[ name ] = parent;
75 this->m_MainImage = name;
81 this->m_Data[ name ] = nd;
84 this->_UpdateItem( name, parent );
91 // -------------------------------------------------------------------------
92 bool cpPlugins::Interface::BaseMPRWidget::
94 vtkPolyData* mesh, const std::string& name, const std::string& parent
97 if( name == "" || parent == "" )
100 auto iIt = this->m_Data.find( name );
101 if( iIt == this->m_Data.end( ) )
106 nd.Mesh.Configure( mesh );
107 this->m_Data[ name ] = nd;
110 auto pIt = this->m_Data.find( parent );
111 if( pIt != this->m_Data.end( ) )
112 this->m_Tree[ name ] = parent;
117 this->_UpdateItem( name, parent );
124 // -------------------------------------------------------------------------
125 void cpPlugins::Interface::BaseMPRWidget::
126 DeleteData( const std::string& name )
128 auto iIt = this->m_Data.find( name );
129 if( iIt != this->m_Data.end( ) )
131 this->m_Data.erase( iIt );
134 std::vector< std::string > to_erase;
135 auto tIt = this->m_Tree.begin( );
136 for( ; tIt != this->m_Tree.end( ); ++tIt )
137 if( tIt->second == name )
138 to_erase.push_back( tIt->first );
141 tIt = this->m_Tree.find( name );
142 if( tIt != this->m_Tree.end( ) )
143 this->m_Tree.erase( tIt );
146 auto dIt = to_erase.begin( );
147 for( ; dIt != to_erase.end( ); ++dIt )
148 this->DeleteData( *dIt );
150 // Delete from tree widget
151 QTreeWidgetItem* item = this->_FindItem( name );
153 this->m_UI->LoadedData->removeItemWidget( item, 0 );
155 // Reset main image, just in case
156 if( this->m_Data.size( ) == 0 )
157 this->m_MainImage = "";
162 // -------------------------------------------------------------------------
163 void cpPlugins::Interface::BaseMPRWidget::
166 this->m_MPRObjects->ClearAll( );
167 this->m_Data.clear( );
168 this->m_Tree.clear( );
169 this->m_UI->LoadedData->clear( );
170 this->m_MainImage = "";
173 // -------------------------------------------------------------------------
174 void cpPlugins::Interface::BaseMPRWidget::
176 const std::string& name, const double& r, const double& g, const double& b
179 auto iIt = this->m_Data.find( name );
180 if( iIt == this->m_Data.end( ) )
183 if( iIt->second.Tag == Data::IMAGE )
186 else if( iIt->second.Tag == Data::MESH )
191 // -------------------------------------------------------------------------
192 void cpPlugins::Interface::BaseMPRWidget::
193 ShowData( const std::string& name )
195 auto iIt = this->m_Data.find( name );
196 if( iIt == this->m_Data.end( ) )
199 if( iIt->second.Tag == Data::IMAGE )
201 this->m_MPRObjects->AddImage( iIt->second.Image );
203 else if( iIt->second.Tag == Data::MESH )
206 this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
209 ren->AddActor( iIt->second.GetMeshActor( ) );
210 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
215 // -------------------------------------------------------------------------
216 vtkRenderWindowInteractor* cpPlugins::Interface::BaseMPRWidget::
217 GetInteractor( unsigned int i )
221 if( this->m_VTK[ i ] != NULL )
222 return( this->m_VTK[ i ]->GetInteractor( ) );
230 // -------------------------------------------------------------------------
232 bool cpPlugins::Interface::BaseMPRWidget::
235 const std::string& name,
236 const std::string& parent
240 QTreeWidgetItem* new_item = this->_UpdateItem( name, parent );
241 if( new_item == NULL )
244 // Associate new data
245 this->m_Images[ name ] = image;
246 this->m_Tree[ name ] = parent;
248 // Show image and return
249 this->m_MPRObjects->AddImage( image );
253 // -------------------------------------------------------------------------
254 bool cpPlugins::Interface::BaseMPRWidget::
257 const std::string& name,
258 const std::string& parent,
259 const double& r, const double& g, const double& b
263 QTreeWidgetItem* new_item = this->_UpdateItem( name, parent );
264 if( new_item == NULL )
267 // Associate new data
268 this->m_Images[ name ] = image;
269 this->m_Tree[ name ] = parent;
271 // Show image and return
272 this->m_MPRObjects->AddImage( image );
276 // -------------------------------------------------------------------------
277 bool cpPlugins::Interface::BaseMPRWidget::
280 const std::string& name,
281 const std::string& parent
285 QTreeWidgetItem* new_item = this->_UpdateItem( name, parent );
286 if( new_item == NULL )
289 // Associate new data
290 PolyDataActor* actor = new PolyDataActor( mesh );
291 this->m_Meshes[ name ] = actor;
292 this->m_Tree[ name ] = parent;
295 this->_Add3DActor( actor->Actor );
299 // -------------------------------------------------------------------------
300 bool cpPlugins::Interface::BaseMPRWidget::
303 const std::string& name,
304 const std::string& parent,
305 const double& r, const double& g, const double& b
311 // -------------------------------------------------------------------------
312 void cpPlugins::Interface::BaseMPRWidget::
315 this->m_MPRObjects->ClearAll( );
316 this->m_Images.clear( );
317 this->m_Meshes.clear( );
321 // -------------------------------------------------------------------------
322 std::string cpPlugins::Interface::BaseMPRWidget::
323 GetSelectedData( ) const
325 QTreeWidgetItem* item = this->m_UI->LoadedData->currentItem( );
327 return( item->text( 0 ).toStdString( ) );
332 // -------------------------------------------------------------------------
333 QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget::
334 _FindItem( const std::string& name ) const
336 QList< QTreeWidgetItem* > items =
337 this->m_UI->LoadedData->findItems( name.c_str( ), Qt::MatchExactly );
338 if( items.size( ) > 0 )
339 return( items[ 0 ] );
344 // -------------------------------------------------------------------------
345 QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget::
346 _UpdateItem( const std::string& name, const std::string& parent )
349 QTreeWidgetItem* new_item = NULL;
352 QTreeWidgetItem* parent_item = this->_FindItem( parent );
353 if( parent_item != NULL )
355 QTreeWidgetItem* old_item = this->_FindItem( name );
356 if( old_item == NULL )
359 new QTreeWidgetItem( parent_item, QStringList( name.c_str( ) ) );
360 parent_item->setExpanded( true );
368 new_item = new QTreeWidgetItem(
369 ( QTreeWidgetItem* )( NULL ), QStringList( name.c_str( ) )
371 this->m_UI->LoadedData->addTopLevelItem( new_item );
377 // -------------------------------------------------------------------------
379 void cpPlugins::Interface::BaseMPRWidget::
380 _Add3DActor( vtkProp3D* prop )
383 this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
386 ren->AddActor( prop );
387 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
391 // -------------------------------------------------------------------------
392 void cpPlugins::Interface::BaseMPRWidget::
393 _SyncBottom( int a, int b )
395 this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) );
398 // -------------------------------------------------------------------------
399 void cpPlugins::Interface::BaseMPRWidget::
400 _SyncTop( int a, int b )
402 this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) );
405 // -------------------------------------------------------------------------
406 cpPlugins::Interface::BaseMPRWidget::PolyDataActor::
416 // -------------------------------------------------------------------------
417 cpPlugins::Interface::BaseMPRWidget::PolyDataActor::
420 if( this->Actor != NULL ) this->Actor->Delete( );
421 if( this->Mapper != NULL ) this->Mapper->Delete( );
422 if( this->Stripper != NULL ) this->Stripper->Delete( );
423 if( this->Normals != NULL ) this->Normals->Delete( );
426 // -------------------------------------------------------------------------
427 void cpPlugins::Interface::BaseMPRWidget::PolyDataActor::
428 Configure( vtkPolyData* pd )
434 pd->GetScalarRange( range );
436 this->Normals = vtkPolyDataNormals::New( );
437 this->Stripper = vtkStripper::New( );
438 this->Mapper = vtkPolyDataMapper::New( );
439 this->Actor = vtkQuadricLODActor::New( );
442 this->Normals->SetInputData( pd );
443 this->Normals->SetFeatureAngle( 60.0 );
444 this->Stripper->SetInputConnection( this->Normals->GetOutputPort( ) );
445 this->Mapper->SetInputConnection( this->Stripper->GetOutputPort( ) );
446 this->Mapper->UseLookupTableScalarRangeOff( );
447 this->Mapper->SetScalarRange(
448 range[ 0 ], ( ( range[ 1 ] - range[ 0 ] ) * 0.75 ) + range[ 0 ]
450 this->Actor->SetMapper( this->Mapper );
451 this->Actor->DeferLODConstructionOff( );
454 #endif // cpPlugins_Interface_QT4