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