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 )
208 // -------------------------------------------------------------------------
209 vtkRenderWindowInteractor* cpPlugins::Interface::BaseMPRWidget::
210 GetInteractor( unsigned int i )
214 if( this->m_VTK[ i ] != NULL )
215 return( this->m_VTK[ i ]->GetInteractor( ) );
223 // -------------------------------------------------------------------------
225 bool cpPlugins::Interface::BaseMPRWidget::
228 const std::string& name,
229 const std::string& parent
233 QTreeWidgetItem* new_item = this->_UpdateItem( name, parent );
234 if( new_item == NULL )
237 // Associate new data
238 this->m_Images[ name ] = image;
239 this->m_Tree[ name ] = parent;
241 // Show image and return
242 this->m_MPRObjects->AddImage( image );
246 // -------------------------------------------------------------------------
247 bool cpPlugins::Interface::BaseMPRWidget::
250 const std::string& name,
251 const std::string& parent,
252 const double& r, const double& g, const double& b
256 QTreeWidgetItem* new_item = this->_UpdateItem( name, parent );
257 if( new_item == NULL )
260 // Associate new data
261 this->m_Images[ name ] = image;
262 this->m_Tree[ name ] = parent;
264 // Show image and return
265 this->m_MPRObjects->AddImage( image );
269 // -------------------------------------------------------------------------
270 bool cpPlugins::Interface::BaseMPRWidget::
273 const std::string& name,
274 const std::string& parent
278 QTreeWidgetItem* new_item = this->_UpdateItem( name, parent );
279 if( new_item == NULL )
282 // Associate new data
283 PolyDataActor* actor = new PolyDataActor( mesh );
284 this->m_Meshes[ name ] = actor;
285 this->m_Tree[ name ] = parent;
288 this->_Add3DActor( actor->Actor );
292 // -------------------------------------------------------------------------
293 bool cpPlugins::Interface::BaseMPRWidget::
296 const std::string& name,
297 const std::string& parent,
298 const double& r, const double& g, const double& b
304 // -------------------------------------------------------------------------
305 void cpPlugins::Interface::BaseMPRWidget::
308 this->m_MPRObjects->ClearAll( );
309 this->m_Images.clear( );
310 this->m_Meshes.clear( );
314 // -------------------------------------------------------------------------
315 std::string cpPlugins::Interface::BaseMPRWidget::
316 GetSelectedData( ) const
318 QTreeWidgetItem* item = this->m_UI->LoadedData->currentItem( );
320 return( item->text( 0 ).toStdString( ) );
325 // -------------------------------------------------------------------------
326 QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget::
327 _FindItem( const std::string& name ) const
329 QList< QTreeWidgetItem* > items =
330 this->m_UI->LoadedData->findItems( name.c_str( ), Qt::MatchExactly );
331 if( items.size( ) > 0 )
332 return( items[ 0 ] );
337 // -------------------------------------------------------------------------
338 QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget::
339 _UpdateItem( const std::string& name, const std::string& parent )
342 QTreeWidgetItem* new_item = NULL;
345 QTreeWidgetItem* parent_item = this->_FindItem( parent );
346 if( parent_item != NULL )
348 QTreeWidgetItem* old_item = this->_FindItem( name );
349 if( old_item == NULL )
352 new QTreeWidgetItem( parent_item, QStringList( name.c_str( ) ) );
353 parent_item->setExpanded( true );
361 new_item = new QTreeWidgetItem(
362 ( QTreeWidgetItem* )( NULL ), QStringList( name.c_str( ) )
364 this->m_UI->LoadedData->addTopLevelItem( new_item );
370 // -------------------------------------------------------------------------
372 void cpPlugins::Interface::BaseMPRWidget::
373 _Add3DActor( vtkProp3D* prop )
376 this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
379 ren->AddActor( prop );
380 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
384 // -------------------------------------------------------------------------
385 void cpPlugins::Interface::BaseMPRWidget::
386 _SyncBottom( int a, int b )
388 this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) );
391 // -------------------------------------------------------------------------
392 void cpPlugins::Interface::BaseMPRWidget::
393 _SyncTop( int a, int b )
395 this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) );
398 // -------------------------------------------------------------------------
399 void cpPlugins::Interface::BaseMPRWidget::PolyDataActor::
400 Configure( vtkPolyData* pd )
406 pd->GetScalarRange( range );
408 this->Normals = vtkSmartPointer< vtkPolyDataNormals >::New( );
409 this->Stripper = vtkSmartPointer< vtkStripper >::New( );
410 this->Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
411 this->Actor = vtkSmartPointer< vtkQuadricLODActor >::New( );
414 this->Normals->SetInputData( pd );
415 this->Normals->SetFeatureAngle( 60.0 );
416 this->Stripper->SetInputConnection( this->Normals->GetOutputPort( ) );
417 this->Mapper->SetInputConnection( this->Stripper->GetOutputPort( ) );
418 this->Mapper->UseLookupTableScalarRangeOff( );
419 this->Mapper->SetScalarRange(
420 range[ 0 ], ( ( range[ 1 ] - range[ 0 ] ) * 0.75 ) + range[ 0 ]
422 this->Actor->SetMapper( this->Mapper );
423 this->Actor->DeferLODConstructionOff( );
426 #endif // cpPlugins_Interface_QT4