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
92 << r << " " << g << " " << b << std::endl;
96 // -------------------------------------------------------------------------
97 bool cpPlugins::Interface::BaseMPRWidget::
100 const std::string& name,
101 const std::string& parent
105 QTreeWidgetItem* new_item = this->_UpdateItem( name, parent );
106 if( new_item == NULL )
109 // Associate new data
110 PolyDataActor* actor = new PolyDataActor( mesh );
111 this->m_Meshes[ name ] = actor;
112 this->m_Tree[ name ] = parent;
115 this->_Add3DActor( actor->Actor );
119 // -------------------------------------------------------------------------
120 bool cpPlugins::Interface::BaseMPRWidget::
123 const std::string& name,
124 const std::string& parent,
125 const double& r, const double& g, const double& b
130 // -------------------------------------------------------------------------
131 void cpPlugins::Interface::BaseMPRWidget::
135 this->m_MPRObjects->ClearAll( );
136 this->m_Images.clear( );
137 this->m_Meshes.clear( );
141 // -------------------------------------------------------------------------
142 std::string cpPlugins::Interface::BaseMPRWidget::
143 GetSelectedData( ) const
145 QTreeWidgetItem* item = this->m_UI->LoadedData->currentItem( );
147 return( item->text( 0 ).toStdString( ) );
152 // -------------------------------------------------------------------------
153 QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget::
154 _FindItem( const std::string& name ) const
156 QList< QTreeWidgetItem* > items =
157 this->m_UI->LoadedData->findItems( name.c_str( ), Qt::MatchExactly );
158 if( items.size( ) > 0 )
159 return( items[ 0 ] );
164 // -------------------------------------------------------------------------
165 QTreeWidgetItem* cpPlugins::Interface::BaseMPRWidget::
166 _UpdateItem( const std::string& name, const std::string& parent )
169 QTreeWidgetItem* new_item = NULL;
172 QTreeWidgetItem* parent_item = this->_FindItem( parent );
173 if( parent_item != NULL )
175 QTreeWidgetItem* old_item = this->_FindItem( name );
176 if( old_item == NULL )
179 new QTreeWidgetItem( parent_item, QStringList( name.c_str( ) ) );
180 parent_item->setExpanded( true );
188 new_item = new QTreeWidgetItem(
189 ( QTreeWidgetItem* )( NULL ), QStringList( name.c_str( ) )
191 this->m_UI->LoadedData->addTopLevelItem( new_item );
197 // -------------------------------------------------------------------------
198 void cpPlugins::Interface::BaseMPRWidget::
199 _Add3DActor( vtkProp3D* prop )
202 this->m_VTK[ 3 ]->GetRenderWindow( )->GetRenderers( )->GetFirstRenderer( );
205 ren->AddActor( prop );
206 this->m_VTK[ 3 ]->GetRenderWindow( )->Render( );
209 // -------------------------------------------------------------------------
210 void cpPlugins::Interface::BaseMPRWidget::
211 _SyncBottom( int a, int b )
213 this->m_UI->BottomSplitter->setSizes( this->m_UI->TopSplitter->sizes( ) );
216 // -------------------------------------------------------------------------
217 void cpPlugins::Interface::BaseMPRWidget::
218 _SyncTop( int a, int b )
220 this->m_UI->TopSplitter->setSizes( this->m_UI->BottomSplitter->sizes( ) );
223 // -------------------------------------------------------------------------
224 cpPlugins::Interface::BaseMPRWidget::PolyDataActor::
225 PolyDataActor( vtkPolyData* pd )
231 pd->GetScalarRange( range );
233 this->Normals = vtkSmartPointer< vtkPolyDataNormals >::New( );
234 this->Stripper = vtkSmartPointer< vtkStripper >::New( );
235 this->Mapper = vtkSmartPointer< vtkPolyDataMapper >::New( );
236 this->Actor = vtkSmartPointer< vtkQuadricLODActor >::New( );
238 this->Normals->SetInputData( pd );
239 this->Normals->SetFeatureAngle( 60.0 );
240 this->Stripper->SetInputConnection( this->Normals->GetOutputPort( ) );
241 this->Mapper->SetInputConnection( this->Stripper->GetOutputPort( ) );
242 this->Mapper->UseLookupTableScalarRangeOff( );
243 this->Mapper->SetScalarRange(
244 range[ 0 ], ( ( range[ 1 ] - range[ 0 ] ) * 0.75 ) + range[ 0 ]
246 this->Actor->SetMapper( this->Mapper );
247 this->Actor->DeferLODConstructionOff( );
250 #endif // cpPlugins_Interface_QT4