]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/Interface/BaseMPRWidget.h
6cb89f305816a6c83270df8659d00a3fcef50736
[cpPlugins.git] / lib / cpPlugins / Interface / BaseMPRWidget.h
1 #ifndef __CPPLUGINS__INTERFACE__BASEMPRWIDGET__H__
2 #define __CPPLUGINS__INTERFACE__BASEMPRWIDGET__H__
3
4 #include <cpPlugins/Interface/cpPlugins_Interface_Export.h>
5 #include <cpPlugins/Interface/Config.h>
6
7 #ifdef cpPlugins_Interface_QT4
8
9 #include <map>
10 #include <string>
11
12 #include <QWidget>
13
14 #include <vtkSmartPointer.h>
15 #include <vtkImageData.h>
16 #include <vtkPolyDataMapper.h>
17 #include <vtkPolyDataNormals.h>
18 #include <vtkQuadricLODActor.h>
19 #include <vtkStripper.h>
20
21 #include <cpExtensions/Visualization/MPRObjects.h>
22
23 // -------------------------------------------------------------------------
24 class QTreeWidgetItem;
25 class QVTKWidget;
26
27 namespace Ui
28 {
29   class BaseMPRWidget;
30 }
31
32 // -------------------------------------------------------------------------
33 namespace cpPlugins
34 {
35   namespace Interface
36   {
37     /**
38      */
39     class cpPlugins_Interface_EXPORT BaseMPRWidget
40       : public QWidget
41     {
42       Q_OBJECT;
43
44     public:
45       typedef cpExtensions::Visualization::MPRObjects TMPRObjects;
46
47       typedef TMPRObjects::TStyle                   TStyle;
48       typedef TMPRObjects::TMouseCommand            TMouseCommand;
49       typedef TMPRObjects::TMouseWheelCommand       TMouseWheelCommand;
50       typedef TMPRObjects::TKeyCommand              TKeyCommand;
51       typedef TMPRObjects::TVoidCommand             TVoidCommand;
52       typedef TMPRObjects::TMouseMoveCommand        TMouseMoveCommand;
53       typedef TMPRObjects::TMouseClickCommand       TMouseClickCommand;
54       typedef TMPRObjects::TMouseDoubleClickCommand TMouseDoubleClickCommand;
55       typedef TMPRObjects::TExposeCommand           TExposeCommand;
56       typedef TMPRObjects::TConfigureCommand        TConfigureCommand;
57       typedef TMPRObjects::TEnterCommand            TEnterCommand;
58       typedef TMPRObjects::TLeaveCommand            TLeaveCommand;
59
60     public:
61       explicit BaseMPRWidget( QWidget* parent = 0 );
62       virtual ~BaseMPRWidget( );
63
64       // Data management
65       bool AddImage(
66         vtkImageData* image,
67         const std::string& name,
68         const std::string& parent = ""
69         );
70       bool AddMesh(
71         vtkPolyData* mesh,
72         const std::string& name,
73         const std::string& parent
74         );
75       void DeleteData( const std::string& name );
76       void DeleteAllData( );
77
78       // Some visualization accessors
79       void SetDataColor(
80         const std::string& name,
81         const double& r,
82         const double& g,
83         const double& b
84         );
85       void ShowData( const std::string& name );
86
87       vtkRenderWindowInteractor* GetInteractor( unsigned int i );
88
89       /*
90         bool ShowImage(
91         vtkImageData* image,
92         const std::string& name,
93         const std::string& parent = ""
94         );
95         bool ShowImage(
96         vtkImageData* image,
97         const std::string& name,
98         const std::string& parent,
99         const double& r, const double& g, const double& b
100         );
101         bool ShowMesh(
102         vtkPolyData* mesh,
103         const std::string& name,
104         const std::string& parent
105         );
106         bool ShowMesh(
107         vtkPolyData* mesh,
108         const std::string& name,
109         const std::string& parent,
110         const double& r, const double& g, const double& b
111         );
112         void ClearAll( );
113       */
114
115       // Visual objects accessors
116       std::string GetSelectedData( ) const;
117
118     protected:
119       QTreeWidgetItem* _FindItem( const std::string& name ) const;
120       QTreeWidgetItem* _UpdateItem(
121         const std::string& name,
122         const std::string& parent
123         );
124
125       /* TODO
126          void _Add3DActor( vtkProp3D* prop );
127       */
128
129     private slots:
130       void _SyncBottom( int a, int b );
131       void _SyncTop( int a, int b );
132
133     protected:
134       Ui::BaseMPRWidget*             m_UI;
135       vtkSmartPointer< TMPRObjects > m_MPRObjects;
136       QVTKWidget*                    m_VTK[ 4 ];
137
138       struct PolyDataActor
139       {
140         vtkPolyData*        Mesh;
141         vtkPolyDataNormals* Normals;
142         vtkStripper*        Stripper;
143         vtkPolyDataMapper*  Mapper;
144         vtkQuadricLODActor* Actor;
145
146         PolyDataActor( );
147         virtual ~PolyDataActor( );
148         void Configure( vtkPolyData* pd );
149       };
150
151       struct Data
152       {
153         enum { IMAGE, MESH } Tag;
154         union
155         {
156           vtkImageData* Image;
157           PolyDataActor Mesh;
158         };
159
160         Data( ) { }
161         virtual ~Data( ) { }
162
163         inline Data& operator=( const Data& data )
164           {
165             this->Tag = data.Tag;
166             if( this->Tag == Data::IMAGE )
167               this->Image = data.Image;
168             else if( this->Tag == Data::MESH )
169               this->Mesh = data.Mesh;
170             return( *this );
171           }
172
173         inline vtkImageData* GetImage( )
174           {
175             if( this->Tag == Data::IMAGE )
176               return( this->Image );
177             else
178               return( NULL );
179           }
180         inline vtkPolyData* GetMesh( )
181           {
182             if( this->Tag == Data::MESH )
183               return( this->Mesh.Mesh );
184             else
185               return( NULL );
186           }
187         inline vtkProp* GetMeshActor( )
188           {
189             if( this->Tag == Data::MESH )
190               return( this->Mesh.Actor );
191             else
192               return( NULL );
193           }
194       };
195
196       std::string m_MainImage;
197       std::map< std::string, Data >        m_Data;
198       std::map< std::string, std::string > m_Tree;
199     };
200
201   } // ecapseman
202
203 } // ecapseman
204
205 #endif // cpPlugins_Interface_QT4
206
207 #endif // __CPPLUGINS__INTERFACE__BASEMPRWIDGET__H__
208
209 // eof - $RCSfile$