1 #include <cpPlugins/Interface/BaseMPRWidget.h>
3 #ifdef cpPlugins_Interface_QT4
5 #include <cpPlugins/Interface/ui_BaseMPRWidget.h>
6 #include <cpPlugins/Interface/DataObject.h>
7 #include <cpPlugins/Interface/Image.h>
8 #include <cpPlugins/Interface/Mesh.h>
9 #include <QTreeWidgetItem>
10 #include <vtkRendererCollection.h>
12 // -------------------------------------------------------------------------
13 cpPlugins::Interface::BaseMPRWidget::
14 BaseMPRWidget( QWidget* parent )
16 m_UI( new Ui::BaseMPRWidget ),
19 this->m_UI->setupUi( this );
21 // Configure VTK widgets
22 this->m_VTK[ 0 ] = this->m_UI->VTK01;
23 this->m_VTK[ 1 ] = this->m_UI->VTK00;
24 this->m_VTK[ 2 ] = this->m_UI->VTK10;
25 this->m_VTK[ 3 ] = this->m_UI->VTK11;
27 this->m_MPRObjects = vtkSmartPointer< TMPRObjects >::New( );
28 this->m_MPRObjects->SetRenderWindows(
29 this->m_VTK[ 0 ]->GetRenderWindow( ),
30 this->m_VTK[ 1 ]->GetRenderWindow( ),
31 this->m_VTK[ 2 ]->GetRenderWindow( ),
32 this->m_VTK[ 3 ]->GetRenderWindow( )
37 this->m_UI->TopSplitter, SIGNAL( splitterMoved( int, int ) ),
38 this, SLOT( _SyncBottom( int, int ) )
41 this->m_UI->BottomSplitter, SIGNAL( splitterMoved( int, int ) ),
42 this, SLOT( _SyncTop( int, int ) )
46 // -------------------------------------------------------------------------
47 cpPlugins::Interface::BaseMPRWidget::
53 // -------------------------------------------------------------------------
54 bool cpPlugins::Interface::BaseMPRWidget::
56 cpPlugins::Interface::DataObject* data, const std::string& name,
57 const std::string& parent
63 auto iIt = this->m_Data.find( name );
64 if( iIt == this->m_Data.end( ) )
68 auto pIt = this->m_Data.find( parent );
69 if( pIt == this->m_Data.end( ) )
75 this->m_Data[ name ].SetSourceDataObject( data );
78 this->_UpdateTreeItem( name, parent );
85 // -------------------------------------------------------------------------
86 bool cpPlugins::Interface::BaseMPRWidget::
87 SetMainImage( const std::string& name )
89 auto iIt = this->m_Data.find( name );
90 if( iIt != this->m_Data.end( ) )
92 if( iIt->second.Tag == Data::IMAGE )
94 this->m_MainImage = name;
104 // -------------------------------------------------------------------------
105 void cpPlugins::Interface::BaseMPRWidget::
106 DeleteData( const std::string& name )
108 auto iIt = this->m_Data.find( name );
109 if( iIt != this->m_Data.end( ) )
111 this->m_Data.erase( iIt );
114 std::vector< std::string > to_erase;
115 auto tIt = this->m_Tree.begin( );
116 for( ; tIt != this->m_Tree.end( ); ++tIt )
117 if( tIt->second == name )
118 to_erase.push_back( tIt->first );
121 tIt = this->m_Tree.find( name );
122 if( tIt != this->m_Tree.end( ) )
123 this->m_Tree.erase( tIt );
126 auto dIt = to_erase.begin( );
127 for( ; dIt != to_erase.end( ); ++dIt )
128 this->DeleteData( *dIt );
130 // Delete from tree widget
131 QTreeWidgetItem* item = this->_FindItemInTree( name );
133 this->m_UI->LoadedData->removeItemWidget( item, 0 );
135 // Reset main image, just in case
136 if( this->m_Data.size( ) == 0 )
137 this->m_MainImage = "";
142 // -------------------------------------------------------------------------
143 void cpPlugins::Interface::BaseMPRWidget::
146 this->m_MPRObjects->Clear( );
147 this->m_Data.clear( );
148 this->m_Tree.clear( );
149 this->m_UI->LoadedData->clear( );
150 this->m_MainImage = "";
153 // -------------------------------------------------------------------------
154 void cpPlugins::Interface::BaseMPRWidget::
156 const std::string& name, const double& r, const double& g, const double& b
160 auto iIt = this->m_Data.find( name );
161 if( iIt == this->m_Data.end( ) )
164 if( iIt->second.Tag == Data::IMAGE )
167 else if( iIt->second.Tag == Data::MESH )
173 // -------------------------------------------------------------------------
174 void cpPlugins::Interface::BaseMPRWidget::
175 ShowData( const std::string& name )
177 auto iIt = this->m_Data.find( name );
178 if( iIt == this->m_Data.end( ) )
181 if( iIt->second.Tag == Data::IMAGE )
183 // TODO: this->m_MPRObjects->AddImage( iIt->second.Image );
186 else if( iIt->second.Tag == Data::MESH )
190 this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
193 ren->AddActor( iIt->second.GetMeshActor( ) );
194 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
199 // -------------------------------------------------------------------------
200 void cpPlugins::Interface::BaseMPRWidget::
201 HideData( const std::string& name )
205 // -------------------------------------------------------------------------
206 vtkRenderWindowInteractor* cpPlugins::Interface::BaseMPRWidget::
207 GetInteractor( unsigned int i )
211 if( this->m_VTK[ i ] != NULL )
212 return( this->m_VTK[ i ]->GetInteractor( ) );
220 // -------------------------------------------------------------------------
222 bool cpPlugins::Interface::BaseMPRWidget::
225 const std::string& name,
226 const std::string& parent
230 QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent );
231 if( new_item == NULL )
234 // Associate new data
235 this->m_Images[ name ] = image;
236 this->m_Tree[ name ] = parent;
238 // Show image and return
239 this->m_MPRObjects->AddImage( image );
243 // -------------------------------------------------------------------------
244 bool cpPlugins::Interface::BaseMPRWidget::
247 const std::string& name,
248 const std::string& parent,
249 const double& r, const double& g, const double& b
253 QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent );
254 if( new_item == NULL )
257 // Associate new data
258 this->m_Images[ name ] = image;
259 this->m_Tree[ name ] = parent;
261 // Show image and return
262 this->m_MPRObjects->AddImage( image );
266 // -------------------------------------------------------------------------
267 bool cpPlugins::Interface::BaseMPRWidget::
270 const std::string& name,
271 const std::string& parent
275 QTreeWidgetItem* new_item = this->_UpdateTreeItem( name, parent );
276 if( new_item == NULL )
279 // Associate new data
280 PolyDataActor* actor = new PolyDataActor( mesh );
281 this->m_Meshes[ name ] = actor;
282 this->m_Tree[ name ] = parent;
285 this->_Add3DActor( actor->Actor );
289 // -------------------------------------------------------------------------
290 bool cpPlugins::Interface::BaseMPRWidget::
293 const std::string& name,
294 const std::string& parent,
295 const double& r, const double& g, const double& b
301 // -------------------------------------------------------------------------
302 void cpPlugins::Interface::BaseMPRWidget::
305 this->m_MPRObjects->ClearAll( );
306 this->m_Images.clear( );
307 this->m_Meshes.clear( );
311 // -------------------------------------------------------------------------
312 std::string cpPlugins::Interface::BaseMPRWidget::
313 GetSelectedData( ) const
315 QTreeWidgetItem* item = this->m_UI->LoadedData->currentItem( );
317 return( item->text( 0 ).toStdString( ) );
322 // -------------------------------------------------------------------------
323 QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget::
324 _FindItemInTree( const std::string& name ) const
326 QList< QTreeWidgetItem* > items =
327 this->m_UI->LoadedData->findItems( name.c_str( ), Qt::MatchExactly );
328 if( items.size( ) > 0 )
329 return( items[ 0 ] );
334 // -------------------------------------------------------------------------
335 QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget::
336 _UpdateTreeItem( const std::string& name, const std::string& parent )
339 QTreeWidgetItem* new_item = NULL;
342 QTreeWidgetItem* parent_item = this->_FindItemInTree( parent );
343 if( parent_item != NULL )
345 QTreeWidgetItem* old_item = this->_FindItemInTree( name );
346 if( old_item == NULL )
349 new QTreeWidgetItem( parent_item, QStringList( name.c_str( ) ) );
350 parent_item->setExpanded( true );
358 new_item = new QTreeWidgetItem(
359 ( QTreeWidgetItem* )( NULL ), QStringList( name.c_str( ) )
361 this->m_UI->LoadedData->addTopLevelItem( new_item );
367 // -------------------------------------------------------------------------
369 void cpPlugins::Interface::BaseMPRWidget::
370 _Add3DActor( vtkProp3D* prop )
373 this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
376 ren->AddActor( prop );
377 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
381 // -------------------------------------------------------------------------
382 void cpPlugins::Interface::BaseMPRWidget::
383 _SyncBottom( int a, int b )
385 this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) );
388 // -------------------------------------------------------------------------
389 void cpPlugins::Interface::BaseMPRWidget::
390 _SyncTop( int a, int b )
392 this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) );
395 // -------------------------------------------------------------------------
396 cpPlugins::Interface::BaseMPRWidget::PolyDataActor::
406 // -------------------------------------------------------------------------
407 cpPlugins::Interface::BaseMPRWidget::PolyDataActor::
410 if( this->Actor != NULL ) this->Actor->Delete( );
411 if( this->Mapper != NULL ) this->Mapper->Delete( );
412 if( this->Stripper != NULL ) this->Stripper->Delete( );
413 if( this->Normals != NULL ) this->Normals->Delete( );
416 // -------------------------------------------------------------------------
417 void cpPlugins::Interface::BaseMPRWidget::PolyDataActor::
418 Configure( vtkPolyData* pd )
424 pd->GetScalarRange( range );
426 this->Normals = vtkPolyDataNormals::New( );
427 this->Stripper = vtkStripper::New( );
428 this->Mapper = vtkPolyDataMapper::New( );
429 this->Actor = vtkQuadricLODActor::New( );
432 this->Normals->SetInputData( pd );
433 this->Normals->SetFeatureAngle( 60.0 );
434 this->Stripper->SetInputConnection( this->Normals->GetOutputPort( ) );
435 this->Mapper->SetInputConnection( this->Stripper->GetOutputPort( ) );
436 this->Mapper->UseLookupTableScalarRangeOff( );
437 this->Mapper->SetScalarRange(
438 range[ 0 ], ( ( range[ 1 ] - range[ 0 ] ) * 0.75 ) + range[ 0 ]
440 this->Actor->SetMapper( this->Mapper );
441 this->Actor->DeferLODConstructionOff( );
444 // -------------------------------------------------------------------------
445 cpPlugins::Interface::BaseMPRWidget::Data::
448 this->Tag = Data::IMAGE;
453 // -------------------------------------------------------------------------
454 cpPlugins::Interface::BaseMPRWidget::Data::
459 // -------------------------------------------------------------------------
460 cpPlugins::Interface::BaseMPRWidget::
461 Data& cpPlugins::Interface::BaseMPRWidget::Data::
462 operator=( const Data& data )
464 this->Tag = data.Tag;
465 this->Source = data.Source;
466 if( this->Tag == Data::IMAGE )
467 this->Image = data.Image;
468 else if( this->Tag == Data::MESH )
469 this->Mesh = data.Mesh;
473 // -------------------------------------------------------------------------
474 cpPlugins::Interface::
475 DataObject* cpPlugins::Interface::BaseMPRWidget::Data::
476 GetSourceDataObject( )
478 return( this->Source );
481 // -------------------------------------------------------------------------
482 const cpPlugins::Interface::
483 DataObject* cpPlugins::Interface::BaseMPRWidget::Data::
484 GetSourceDataObject( ) const
486 return( this->Source );
489 // -------------------------------------------------------------------------
490 void cpPlugins::Interface::BaseMPRWidget::Data::
491 SetSourceDataObject( cpPlugins::Interface::DataObject* dobj )
493 typedef cpPlugins::Interface::Image _TImage;
494 typedef cpPlugins::Interface::Mesh _TMesh;
497 _TImage* image = dynamic_cast< _TImage* >( dobj );
500 this->Tag = Data::IMAGE;
501 this->Image = image->GetVTK< vtkImageData >( );
505 _TMesh* mesh = dynamic_cast< _TMesh* >( dobj );
509 this->Tag = Data::MESH;
510 this->Mesh.Configure( mesh->GetVTK< vtkPolyData >( ) );
515 // -------------------------------------------------------------------------
516 vtkImageData* cpPlugins::Interface::BaseMPRWidget::Data::
519 if( this->Tag == Data::IMAGE )
520 return( this->Image );
525 // -------------------------------------------------------------------------
526 vtkPolyData* cpPlugins::Interface::BaseMPRWidget::Data::
529 if( this->Tag == Data::MESH )
530 return( this->Mesh.Mesh );
535 // -------------------------------------------------------------------------
536 vtkProp* cpPlugins::Interface::BaseMPRWidget::Data::
539 if( this->Tag == Data::MESH )
540 return( this->Mesh.Actor );
545 #endif // cpPlugins_Interface_QT4