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
88 QTreeWidgetItem* new_item = this->_UpdateItem( name, parent );
89 if( new_item == NULL )
93 this->m_Images[ name ] = image;
94 this->m_Tree[ name ] = parent;
96 // Show image and return
97 this->m_MPRObjects->AddImage( image );
101 // -------------------------------------------------------------------------
102 bool cpPlugins::Interface::BaseMPRWidget::
105 const std::string& name,
106 const std::string& parent
110 QTreeWidgetItem* new_item = this->_UpdateItem( name, parent );
111 if( new_item == NULL )
114 // Associate new data
115 PolyDataActor* actor = new PolyDataActor( mesh );
116 this->m_Meshes[ name ] = actor;
117 this->m_Tree[ name ] = parent;
120 this->_Add3DActor( actor->Actor );
124 // -------------------------------------------------------------------------
125 bool cpPlugins::Interface::BaseMPRWidget::
128 const std::string& name,
129 const std::string& parent,
130 const double& r, const double& g, const double& b
136 // -------------------------------------------------------------------------
137 void cpPlugins::Interface::BaseMPRWidget::
141 this->m_MPRObjects->ClearAll( );
142 this->m_Images.clear( );
143 this->m_Meshes.clear( );
147 // -------------------------------------------------------------------------
148 std::string cpPlugins::Interface::BaseMPRWidget::
149 GetSelectedData( ) const
151 QTreeWidgetItem* item = this->m_UI->LoadedData->currentItem( );
153 return( item->text( 0 ).toStdString( ) );
158 // -------------------------------------------------------------------------
159 QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget::
160 _FindItem( const std::string& name ) const
162 QList< QTreeWidgetItem* > items =
163 this->m_UI->LoadedData->findItems( name.c_str( ), Qt::MatchExactly );
164 if( items.size( ) > 0 )
165 return( items[ 0 ] );
170 // -------------------------------------------------------------------------
171 QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget::
172 _UpdateItem( const std::string& name, const std::string& parent )
175 QTreeWidgetItem* new_item = NULL;
178 QTreeWidgetItem* parent_item = this->_FindItem( parent );
179 if( parent_item != NULL )
181 QTreeWidgetItem* old_item = this->_FindItem( name );
182 if( old_item == NULL )
185 new QTreeWidgetItem( parent_item, QStringList( name.c_str( ) ) );
186 parent_item->setExpanded( true );
194 new_item = new QTreeWidgetItem(
195 ( QTreeWidgetItem* )( NULL ), QStringList( name.c_str( ) )
197 this->m_UI->LoadedData->addTopLevelItem( new_item );
203 // -------------------------------------------------------------------------
204 void cpPlugins::Interface::BaseMPRWidget::
205 _Add3DActor( vtkProp3D* prop )
208 this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
211 ren->AddActor( prop );
212 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
215 // -------------------------------------------------------------------------
216 void cpPlugins::Interface::BaseMPRWidget::
217 _SyncBottom( int a, int b )
219 this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) );
222 // -------------------------------------------------------------------------
223 void cpPlugins::Interface::BaseMPRWidget::
224 _SyncTop( int a, int b )
226 this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) );
229 // -------------------------------------------------------------------------
230 cpPlugins::Interface::BaseMPRWidget::PolyDataActor::
231 PolyDataActor( vtkPolyData* pd )
237 pd->GetScalarRange( range );
239 this->Normals = vtkSmartPointer< vtkPolyDataNormals >::New( );
240 this->Stripper = vtkSmartPointer< vtkStripper >::New( );
241 this->Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
242 this->Actor = vtkSmartPointer< vtkQuadricLODActor >::New( );
244 this->Normals->SetInputData( pd );
245 this->Normals->SetFeatureAngle( 60.0 );
246 this->Stripper->SetInputConnection( this->Normals->GetOutputPort( ) );
247 this->Mapper->SetInputConnection( this->Stripper->GetOutputPort( ) );
248 this->Mapper->UseLookupTableScalarRangeOff( );
249 this->Mapper->SetScalarRange(
250 range[ 0 ], ( ( range[ 1 ] - range[ 0 ] ) * 0.75 ) + range[ 0 ]
252 this->Actor->SetMapper( this->Mapper );
253 this->Actor->DeferLODConstructionOff( );
256 #endif // cpPlugins_Interface_QT4