]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkMPR3DView.cxx
ba470de5dbb039e7aba41c4190e5417975c26c5b
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxVtkMPR3DView.cxx
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 #include "wxVtkMPR3DView.h"
27
28 #include "vtkDataSetMapper.h"
29 #include "vtkPlaneSource.h"
30 #include "vtkProbeFilter.h"
31 #include "vtkStructuredPoints.h"
32 #include "vtkMetaImageWriter.h"
33 #include "vtkImageChangeInformation.h"
34 #include "vtkPointData.h"
35 #include "vtkWindowLevelLookupTable.h"
36 #include "vtkPlane.h"
37 #include "vtkCutter.h"
38 #include "vtkTransform.h"
39 #include "vtkmyPWCallback_3DPointWidget.h"
40 #include "vtkProperty.h"
41 #include "vtkCellPicker.h"
42 #include "vtkInteractorStyleBaseView.h"
43 #include <vtkImageReslice.h>
44
45
46
47 //----------------------------------------------------------------------------
48 //----------------------------------------------------------------------------
49 //----------------------------------------------------------------------------
50 class vtkWindowLevelImagePlaneWidgetCallback : public vtkCommand
51 {
52          public:
53            static vtkWindowLevelImagePlaneWidgetCallback *New()
54            { 
55                    return new vtkWindowLevelImagePlaneWidgetCallback;
56            }
57         
58            void Execute( vtkObject *caller, unsigned long ev, void *callData )
59                 {
60                         bool needRefresh=false;
61                         double slicePosition;
62                         vtkImagePlaneWidget* ipw =dynamic_cast< vtkImagePlaneWidget* >( caller );
63                     if ( ev == vtkCommand::WindowLevelEvent)
64                         {
65                                 double info[2];
66                                 ipw->GetWindowLevel(info);
67                                 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetColorWindow(info[0]);
68                                 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetColorLevel(info[1]);
69                                 needRefresh=true;
70                         } // if ev
71                    
72                    if ( ev == vtkCommand::InteractionEvent)
73                    {
74                            needRefresh=true;
75                            if (ipw->GetCursorDataStatus())
76                            {
77                                    double xyzv[4];
78                                    ipw->GetCursorData(xyzv);
79                                    _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetX(xyzv[0]);
80                                    _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetY(xyzv[1]);
81                                    _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetZ(xyzv[2]);
82                            } else {
83                                    
84                                    
85                                    vtkImageData *image = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
86                                    double spc[3];
87                                    if(image)
88                                    {
89                                            image->GetSpacing(spc);
90                                    }
91                                    
92                                    double normal[3];
93                                    slicePosition = ipw->GetSlicePosition();
94                                    ipw->GetNormal(normal);
95                                    
96                                    // FreePlaneX
97                                    if ((normal[0]==1)&&(normal[1]==0)&&(normal[2]==0))
98                                    {
99                                            _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetX( slicePosition/spc[0] );
100                                    }
101                                    // FreePlaneY
102                                    if ((normal[0]==0)&&(normal[1]==1)&&(normal[2]==0))
103                                    {
104                                            _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetY( slicePosition/spc[1] );
105                                    }
106                                    // FreePlaneZ
107                                    if ((normal[0]==0)&&(normal[1]==0)&&(normal[2]==1))
108                                    {
109                                            _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetZ( slicePosition/spc[2] );
110                                    }
111                            }// ipw->GetCursorDataStatus
112                    }// ev
113                         
114                    if (needRefresh)     
115                    {
116                            vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)_wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetInteractorStyleBaseView();
117                            isbv->SetParent_refresh_waiting();
118                            isbv->EvaluateToRefresh();
119                    }
120                         
121            } // Execute
122         
123                 vtkWindowLevelImagePlaneWidgetCallback(){}
124                 wxVtkMPR3DView *_wxvtkmpr3Dview;
125 };
126
127
128
129 //-------------------------------------------------------------------
130 //-------------------------------------------------------------------
131 //-------------------------------------------------------------------
132
133
134
135 wxVtkMPR3DView::wxVtkMPR3DView( wxVtk3DBaseView *wxvtk3Dbaseview )
136 {
137         _wxvtk3Dbaseview                        =       wxvtk3Dbaseview;
138         _vtkmpr3Ddataviewer                     =       NULL;
139         _wxvtkmpr3DviewCntrlPanel       =       NULL;
140         //_myCallback                           =       NULL;
141         _pointWidget                            =       NULL;
142         _planeWidget                            =       NULL;
143         _vtkplane                                       =       NULL;
144         _probe                                          =       NULL;
145         _contourMapper                          =       NULL;
146
147         _planeWidgetX                           =       NULL;
148         _planeWidgetY                           =       NULL;
149         _planeWidgetZ                           =       NULL;
150         //EED Fev 3 2010
151         //Free Planes
152 }
153
154
155 //-------------------------------------------------------------------
156 wxVtkMPR3DView::~wxVtkMPR3DView()
157 {
158         VisiblePointWidget( false );
159         VisiblePlaneWidget( false );
160
161         if(_pointWidget!=NULL){
162                 _pointWidget->Delete();
163         }
164         if(_planeWidget!=NULL){
165                 _planeWidget->Delete();
166         }
167
168         if(_vtkplane!=NULL){
169                 _vtkplane->Delete();
170                 _probe->Delete();
171                 _contourMapper->Delete();
172                 _contourPlaneActor->Delete();
173         }
174
175 }
176
177 //-------------------------------------------------------------------
178 void wxVtkMPR3DView::RemoveActor(vtkActor* actor)
179 {
180         _wxvtk3Dbaseview->GetRenderer()->RemoveActor(actor);
181 }
182
183 //-------------------------------------------------------------------
184 void wxVtkMPR3DView::ResetCamera(int* ext, double* origin,double* spc)
185 {
186         if(ext == NULL){
187                 _wxvtk3Dbaseview->GetRenderer()->ResetCamera ();
188                 _wxvtk3Dbaseview->GetCamera()->Dolly(2.0);
189                 
190 //EED 21 mars 2012  FLIP probleme  ..PLOP..
191                 _wxvtk3Dbaseview->GetCamera()->Roll(180);
192                 _wxvtk3Dbaseview->GetCamera()->Yaw(180+30);
193                 _wxvtk3Dbaseview->GetCamera()->Pitch(-22);
194                 
195         }else{
196                 
197                 /*double x = (spc[0])*(origin[0]+(((double)ext[1]-(double)ext[0])/2.0));
198                 double y = (spc[1])*(origin[1]+(double)ext[3]);
199                 double z = (spc[2])*(origin[2]+(((double)ext[5]-(double)ext[4])/2.0));*/
200                 /*double x0=(spc[0])*((double)ext[0]+origin[0]);
201                 double x1=(spc[0])*((double)ext[1]+origin[0]);
202                 double y0=(spc[1])*((double)ext[2]+origin[1]);
203                 double y1=(spc[1])*((double)ext[3]+origin[1]);
204                 double z0=(spc[2])*((double)ext[4]+origin[2]);
205                 double z1=(spc[2])*((double)ext[5]+origin[2]);*/
206                 
207                 double x0=(spc[0])*((double)ext[0]);
208                 double x1=(spc[0])*((double)ext[1]);
209                 double y0=(spc[1])*((double)ext[2]);
210                 double y1=(spc[1])*((double)ext[3]);
211                 double z0=(spc[2])*((double)ext[4]);
212                 double z1=(spc[2])*((double)ext[5]);
213
214                 _wxvtk3Dbaseview->GetRenderer()->ResetCamera(x0,x1,y0,y1,z0,z1);
215                 //_wxvtk3Dbaseview->GetCamera()->SetPosition(x,y,z);
216                 _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);
217                 
218         }
219         
220 }
221
222 //-------------------------------------------------------------------
223 void wxVtkMPR3DView::Configure()
224 {
225         vtkImageData *imageData = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
226
227         _wxvtk3Dbaseview->Configure();
228         _wxvtkmpr3DviewCntrlPanel->UpdateControlPanel();
229
230 //EED 27 Mai 2009
231 //      _wxvtk3Dbaseview->GetRenderer()->Clear();
232
233         // Actors are added to the renderer.
234         vtkActor* _outlineActor = _vtkmpr3Ddataviewer->GetOutlineActor();
235         _wxvtk3Dbaseview->GetRenderer()->AddActor( _outlineActor );
236 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(0)  );    // _saggital
237 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(1)  );    // _axial
238 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(2)  );    // _coronal
239
240
241         // An initial camera view is created.  The Dolly() method moves
242         // the camera towards the FocalPoint, thereby enlarging the image.
243         _wxvtk3Dbaseview->GetRenderer()->SetActiveCamera(_wxvtk3Dbaseview->GetCamera());
244         this->ResetCamera();
245
246
247         // Set a background color for the renderer and set the size of the
248         // render window (expressed in pixels).
249         _wxvtk3Dbaseview->GetRenderer()->SetBackground( 0.36 , 0.36 , 0.36 );
250 //EED 23oct2010 _wxvtk3Dbaseview->GetRenWin()->SetSize(400, 400);
251
252         // Note that when camera movement occurs (as it does in the Dolly()
253         // method), the clipping planes often need adjusting. Clipping planes
254         // consist of two planes: near and far along the view direction. The
255         // near plane clips out objects in front of the plane; the far plane
256         // clips out objects behind the plane. This way only what is drawn
257         // between the planes is actually rendered.
258         _wxvtk3Dbaseview->GetRenderer()->ResetCameraClippingRange();
259
260
261         // vtkPointWidget
262         //if(_myCallback!=NULL){
263                 //_myCallback->Delete();
264
265         //}
266         vtkmyPWCallback_3DPointWidget *_myCallback = vtkmyPWCallback_3DPointWidget::New();
267         _myCallback->SetWxVtkMPR3DView(this);
268
269
270         if(imageData){
271                 if(_pointWidget==NULL){
272                         _pointWidget = vtkPointWidget::New();
273                 }
274                 _pointWidget->SetInput( imageData );
275                 _myCallback->SetVtkPointWidget(_pointWidget);
276                 _pointWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
277                 _pointWidget->AllOff();
278                 _pointWidget->PlaceWidget();
279
280                 _pointWidget->AddObserver(vtkCommand::InteractionEvent,_myCallback);
281
282                 if(_planeWidget==NULL)
283                 {
284                         _planeWidget = vtkPlaneWidget::New();
285                 }
286                 _planeWidget->SetInput( imageData );
287
288                 _myCallback->SetVtkPlaneWidget(_planeWidget);
289
290                 _planeWidget->NormalToXAxisOn();
291                 _planeWidget->SetResolution(50);
292                 _planeWidget->SetRepresentationToOutline();
293
294                 int dim[3];
295
296                 imageData->GetDimensions(dim);
297                 int px=(dim[0]/2);
298                 int py=(dim[1]/2);
299                 int pz=(dim[2]/2);
300                 int dd=20;
301                 _planeWidget->PlaceWidget( px-dd , px+dd , py-dd , py+dd , pz-dd , pz+dd );
302
303                 if(_vtkplane==NULL){
304                         _vtkplane = vtkPolyData::New();
305
306                         _probe = vtkProbeFilter::New();
307                         _probe->SetInput(_vtkplane);
308
309                         _contourMapper = vtkPolyDataMapper::New();
310
311                         _contourMapper->SetInput( _probe->GetPolyDataOutput() );
312
313                         _contourPlaneActor = vtkActor::New();
314                         _contourPlaneActor->SetMapper(_contourMapper);
315
316                         _contourPlaneActor->VisibilityOff();
317
318                         _planeWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
319                         _planeWidget->AddObserver(vtkCommand::InteractionEvent,_myCallback);
320
321                         _planeWidget->Off();
322                         _wxvtk3Dbaseview->GetRenderer()->AddActor( _contourPlaneActor );
323
324                 }
325
326                 _planeWidget->GetPolyData(_vtkplane);
327                 _probe->SetSource( imageData );
328                 _contourMapper->SetScalarRange( imageData->GetScalarRange() );
329
330         ConfigureFreePlanes();
331         }
332
333 //      _pointWidget->SetPosition( x,y,z );
334
335 //EED01 29Mars2009
336 // MACOS probleme vtk-window out of wx-window
337 //      _pointWidget->On();
338
339 // PlaneWidget
340
341 }
342
343 //-------------------------------------------------------------------
344 void wxVtkMPR3DView::ConfigureFreePlanes()
345 {
346
347         // The shared picker enables us to use 3 planes at one time
348         // and gets the picking order right
349         vtkCellPicker* picker = vtkCellPicker::New();
350         picker->SetTolerance(0.005);
351
352         // The 3 image plane widgets
353         _planeWidgetX = GetPlaneWidget('x', 1, 0, 0, picker);
354         _planeWidgetY = GetPlaneWidget('y', 1, 1, 0, picker);
355         _planeWidgetZ = GetPlaneWidget('z', 0, 0, 1, picker);
356
357         _planeWidgetY->SetLookupTable(_planeWidgetX->GetLookupTable());
358         _planeWidgetZ->SetLookupTable(_planeWidgetX->GetLookupTable());
359
360         picker->UnRegister(NULL);
361
362         // ColorWindow ColorLevel Callback
363         vtkWindowLevelImagePlaneWidgetCallback *wlipwc  = vtkWindowLevelImagePlaneWidgetCallback::New();
364         wlipwc->_wxvtkmpr3Dview                                                 = this;
365         _planeWidgetX->AddObserver(vtkCommand::WindowLevelEvent, wlipwc );
366         _planeWidgetY->AddObserver(vtkCommand::WindowLevelEvent, wlipwc );
367         _planeWidgetZ->AddObserver(vtkCommand::WindowLevelEvent, wlipwc );
368         
369         // Cursor Callback
370         _planeWidgetX->AddObserver(vtkCommand::InteractionEvent, wlipwc );
371         _planeWidgetY->AddObserver(vtkCommand::InteractionEvent, wlipwc );
372         _planeWidgetZ->AddObserver(vtkCommand::InteractionEvent, wlipwc );      
373 }
374
375 //-------------------------------------------------------------------
376 vtkImagePlaneWidget* wxVtkMPR3DView::GetPlaneWidget(unsigned char activationkey, double r, double g, double b, vtkCellPicker* picker)
377 {
378         vtkProperty* prop1                                      = 0;
379         vtkImagePlaneWidget* planeWidget        = 0;
380         planeWidget                                                     = vtkImagePlaneWidget::New();
381         planeWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
382         planeWidget->EnabledOff();
383         vtkImageData *image                                     = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
384         int xMin = 0, xMax = 0, yMin = 0, yMax = 0, zMin = 0, zMax = 0;
385         double xSpacing = 0, ySpacing = 0, zSpacing = 0;
386         if(image)
387         {
388                 planeWidget->SetInput( image );
389                 image->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
390                 image->GetSpacing(xSpacing, ySpacing, zSpacing);
391         }
392
393         if (activationkey=='x')
394         {
395                 planeWidget->SetPlaneOrientationToXAxes();
396                 planeWidget->SetSlicePosition((xMax+xMin)/2.*xSpacing);
397         }
398
399         if (activationkey=='y')
400         {
401                 planeWidget->SetPlaneOrientationToYAxes();
402                 planeWidget->SetSlicePosition((yMax+yMin)/2.*ySpacing);
403         }
404
405         if (activationkey=='z')
406         {
407                 planeWidget->SetPlaneOrientationToZAxes();
408                 planeWidget->SetSlicePosition((zMax+zMin)/2.*zSpacing);
409         }
410
411         planeWidget->DisplayTextOn();
412         planeWidget->SetPicker(picker);
413         planeWidget->SetKeyPressActivationValue(activationkey);
414         prop1 = planeWidget->GetPlaneProperty();
415         prop1->SetColor(r, g, b);
416         return planeWidget;
417 }
418
419 //-------------------------------------------------------------------
420 void wxVtkMPR3DView::SetFreePlanesOrtho()
421 {
422         _planeWidgetX->SetPlaneOrientationToXAxes();
423         _planeWidgetY->SetPlaneOrientationToYAxes();
424         _planeWidgetZ->SetPlaneOrientationToZAxes();
425         vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)GetWxvtk3Dbaseview()->GetInteractorStyleBaseView();
426         isbv->SetParent_refresh_waiting();
427         isbv->EvaluateToRefresh();
428 }
429
430 //-------------------------------------------------------------------
431 void wxVtkMPR3DView::FreePlaneVisible(int plane, bool ok)
432 {
433         if(_planeWidgetX)
434         {
435                 if ((plane==1) && (ok==true)) _planeWidgetX->EnabledOn();
436                 if ((plane==2) && (ok==true)) _planeWidgetY->EnabledOn();
437                 if ((plane==3) && (ok==true)) _planeWidgetZ->EnabledOn();
438                 if ((plane==1) && (ok==false)) _planeWidgetX->EnabledOff();
439                 if ((plane==2) && (ok==false)) _planeWidgetY->EnabledOff();
440                 if ((plane==3) && (ok==false)) _planeWidgetZ->EnabledOff();
441         }
442 }
443
444 //-------------------------------------------------------------------
445 void wxVtkMPR3DView::FreePlaneInteraction(bool ok)
446 {
447         if(_planeWidgetX)
448         {
449                 if (ok==true)
450                 {
451                         _planeWidgetX->InteractionOn();
452                         _planeWidgetY->InteractionOn();
453                         _planeWidgetZ->InteractionOn();
454                 } else {
455                         _planeWidgetX->InteractionOff();
456                         _planeWidgetY->InteractionOff();
457                         _planeWidgetZ->InteractionOff();
458                 }
459         } // if _planeWidgetX
460 }
461
462
463
464 //-------------------------------------------------------------------
465 void wxVtkMPR3DView::setColorTransferFunction(vtkColorTransferFunction* colortable)
466 {
467         GetVtkMPR3DDataViewer ()->setColorTransferFunction(colortable);
468 }
469
470 //-------------------------------------------------------------------
471 void wxVtkMPR3DView::Refresh()   // virtual
472 {
473         _vtkmpr3Ddataviewer     ->      Refresh();
474         if (_wxvtkmpr3DviewCntrlPanel!=NULL)
475         {
476                 _wxvtkmpr3DviewCntrlPanel->Refresh();
477         }
478
479 }
480
481 //-------------------------------------------------------------------
482 void wxVtkMPR3DView::RefreshView()   // virtual
483 {
484         double spc[3];
485         vtkImageData *image = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
486
487         if(image){
488                 image->GetSpacing(spc);
489         }else{
490                 spc[0] = 0;
491                 spc[1] = 0;
492                 spc[2] = 0;
493         }
494         //this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetSpacing(spc);
495
496         //double nx=1,ny=0,nz=0; // JPRx
497         Refresh();
498         double x=GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetX();
499         double y=GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetY();
500         double z=GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetZ();
501
502         SetColorWindow( _vtkmpr3Ddataviewer->GetVtkMPRBaseData()->GetColorWindow() );
503         SetColorLevel( _vtkmpr3Ddataviewer->GetVtkMPRBaseData()->GetColorLevel() );
504
505
506         double normal[3];
507         // FreePlaneX
508         _planeWidgetX->GetNormal(normal);
509         if ((normal[0]==1)&&(normal[1]==0)&&(normal[2]==0))
510         {
511                 _planeWidgetX->SetSlicePosition( x*spc[0] );
512         }
513         // FreePlaneY
514         _planeWidgetY->GetNormal(normal);
515         if ((normal[0]==0)&&(normal[1]==1)&&(normal[2]==0))
516         {
517                 _planeWidgetY->SetSlicePosition( y*spc[1] );
518         }
519         // FreePlaneZ
520         _planeWidgetZ->GetNormal(normal);
521         if ((normal[0]==0)&&(normal[1]==0)&&(normal[2]==1))
522         {
523                 _planeWidgetZ->SetSlicePosition( z*spc[2] );
524         }
525                 
526         x=x*spc[0];
527         y=y*spc[1];
528         z=z*spc[2];
529
530         if(_pointWidget){
531                 _pointWidget->SetPosition( x,y,z );
532                 double in[3];
533                 double normal[3];
534                 vtkTransform *transform = GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetTransformOrientation();
535                 in[0]=1;                in[1]=0;                        in[2]=0;
536                 transform->TransformPoint(in,normal);
537                 _planeWidget->SetNormal( normal[0],normal[1],normal[2] );
538                 _planeWidget->SetCenter( x,y,z );
539                 _planeWidget->UpdatePlacement();
540                 _planeWidget->GetPolyData(_vtkplane);
541         }
542 }
543
544 //-------------------------------------------------------------------
545 wxPanel* wxVtkMPR3DView::CreateControlPanel(wxWindow *parent, bool align)
546 {
547         _wxvtkmpr3DviewCntrlPanel = new wxVtkMPR3DViewCntrlPanel(parent,this, align);
548         return _wxvtkmpr3DviewCntrlPanel;
549 }
550 //-------------------------------------------------------------------
551 vtkMPR3DDataViewer* wxVtkMPR3DView::GetVtkMPR3DDataViewer()
552 {
553         return _vtkmpr3Ddataviewer;
554 }
555 //-------------------------------------------------------------------
556 wxVtk3DBaseView* wxVtkMPR3DView::GetWxvtk3Dbaseview() throw (char*)
557 {
558         if(_wxvtk3Dbaseview==NULL){
559                 throw "wxVtk3DBaseView* wxVtkMPR3DView::GetWxvtk3Dbaseview() _wxvtk3Dbaseview=NULL";
560         }
561         return _wxvtk3Dbaseview;
562 }
563 //-------------------------------------------------------------------
564
565 //-------------------------------------------------------------------
566 void wxVtkMPR3DView::VisibleImageActor(int idPosition, bool visible){
567         /*if(visible == false)
568                 printf("CPR: wxVtkMPR3DView::VisibleImageActor-> visibleActor == false \n");
569         else
570         {
571                 printf("CPR: wxVtkMPR3DView::VisibleImageActor-> visibleActor == true\n");
572                 printf("CPR: wxVtkMPR3DView::VisibleImageActor-> idPosition == %d\n", idPosition);
573         }
574         */
575         if (visible!=_vtkmpr3Ddataviewer->GetVisiblePosition(idPosition)){
576                 if (visible==false){
577                         _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkmpr3Ddataviewer->GetImageActor(idPosition)  );
578                 } else {
579                         _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(idPosition)  );
580                 }
581                 _vtkmpr3Ddataviewer->SetVisiblePosition(idPosition,visible);
582         }
583 }
584
585
586 //-------------------------------------------------------------------
587 void wxVtkMPR3DView::VisiblePointWidget( bool visible )
588 {
589         if(_pointWidget){
590                 if (visible==true)
591                 {
592                         _pointWidget->On();
593                 } else {
594                         _pointWidget->Off();
595                 }
596         }
597 }
598
599 //-------------------------------------------------------------------
600 void wxVtkMPR3DView::VisiblePlaneWidget( bool visible )
601 {
602         if(_planeWidget){
603                 if (visible==true)
604                 {
605                         _planeWidget->On();
606                         _contourPlaneActor->VisibilityOn();
607
608                 } else {
609                         _planeWidget->Off();
610                         _contourPlaneActor->VisibilityOff();
611                 }
612         }
613 }
614
615 //CPR: Method added 30 Nov 2009
616 void wxVtkMPR3DView::showOutlineActor(bool value)
617 {
618         vtkActor* _outlineActor = _vtkmpr3Ddataviewer->GetOutlineActor();
619         if(value == true)
620         {
621                 _wxvtk3Dbaseview->GetRenderer()->AddActor( _outlineActor );
622         }
623         else
624         {
625                 _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _outlineActor );
626         }
627 }
628
629 //-------------------------------------------------------------------
630 void wxVtkMPR3DView::SetVtkMPR3DDataViewer(vtkMPR3DDataViewer *vtkmpr3Ddataviewer)
631 {
632         _vtkmpr3Ddataviewer = vtkmpr3Ddataviewer;
633 }
634
635 //-------------------------------------------------------------------
636 void wxVtkMPR3DView::InitOrientationPointWidget()
637 {
638         this->_planeWidget->SetNormal(1,0,0);
639 }
640
641 //-------------------------------------------------------------------
642 void wxVtkMPR3DView::SetColorWindow(double colorWindow)
643 {
644         double colorLevel = _planeWidgetX->GetLevel();
645         _planeWidgetX->SetWindowLevel(colorWindow,colorLevel);
646 }
647
648 //-------------------------------------------------------------------
649 void wxVtkMPR3DView::SetColorLevel(double colorLevel)
650 {
651         double colorWindow = _planeWidgetX->GetWindow();
652         _planeWidgetX->SetWindowLevel(colorWindow,colorLevel);
653 }
654
655 //-------------------------------------------------------------------
656 // EED 25 Janvier 2007 testLoic
657 void wxVtkMPR3DView::TestLoic1()
658 {
659
660         int sizeIma     = 128;
661   double dimIma = sizeIma*2;
662
663         vtkImageData *vtkimagedata =  this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
664
665         double spc[3];
666         vtkimagedata->GetSpacing(spc);
667
668         vtkimagedata->Update();
669
670
671          double p[3], n[3];
672      this->_planeWidget->GetOrigin(p);
673      this->_planeWidget->GetNormal(n);
674
675
676
677     vtkPlaneSource* pSource = vtkPlaneSource::New( );
678     pSource->SetResolution( sizeIma - 1, sizeIma - 1 );
679     pSource->SetOrigin( p[ 0 ], p[ 1 ], p[ 2 ] );
680     pSource->SetPoint1( p[ 0 ] + dimIma - 1.0, p[ 1 ], p[ 2 ] );
681     pSource->SetPoint2( p[ 0 ], p[ 1 ]+ dimIma - 1.0 , p[ 2 ] );
682     pSource->Update( );
683     pSource->SetCenter( p[ 0 ], p[ 1 ], p[ 2 ] );
684     pSource->SetNormal( n[ 0 ], n[ 1 ], n[ 2 ] );
685     pSource->Update( );
686
687     vtkProbeFilter* slices = vtkProbeFilter::New();
688     slices->SetInput( ( vtkDataSet* )pSource->GetOutput( ) );
689     slices->SetSource( vtkimagedata );
690     slices->Update( );
691     pSource->Delete( );
692
693         vtkStructuredPoints   *stPoints = vtkStructuredPoints::New();
694         stPoints -> GetPointData( )->SetScalars(  slices->GetOutput()->GetPointData()->GetScalars()  );
695         stPoints -> SetDimensions( sizeIma, sizeIma, 1 );
696         stPoints -> SetScalarType( vtkimagedata->GetScalarType() );
697         stPoints -> SetScalarTypeToShort();
698         stPoints -> Update();
699
700         vtkImageChangeInformation  *change = vtkImageChangeInformation ::New();
701         change    -> SetInput( stPoints );
702         change    -> Update();    //important
703
704         double _range[2];
705         vtkimagedata->GetScalarRange(_range);
706    vtkWindowLevelLookupTable *_bwlookup = vtkWindowLevelLookupTable::New( );
707    _bwlookup->SetHueRange( 0 , 1 );
708    _bwlookup->SetNumberOfColors( (int)(_range[1] - _range[0] + 1) );
709    _bwlookup->SetTableRange( _range[0] , _range[1] );
710    _bwlookup->SetSaturationRange( 0 , 0 );
711    _bwlookup->SetValueRange( 0 , 1 );
712    _bwlookup->SetAlphaRange( 1 , 1 );
713    _bwlookup->Build( );
714
715    vtkLookupTable * _collookup = vtkLookupTable::New( );
716    _collookup->SetNumberOfColors( 256 );
717    _collookup->SetTableRange( 0 , 255 );
718    _collookup->Build( );
719    _collookup->SetTableValue( 0  , 1 , 0 , 0 , 1 );
720    _collookup->SetTableValue(128 , 0 , 0 , 1 , 1 );
721    _collookup->SetTableValue(255 , 0 , 1 , 0 , 1 );
722
723
724         vtkMetaImageWriter *writer = vtkMetaImageWriter::New( );
725         writer->SetInput( stPoints );
726         writer->SetFileName( "C:/Users/Images/temp_EED/image.mhd" );
727         writer->SetFileDimensionality( 2 );
728         writer->Write( );
729
730
731
732         vtkDataSetMapper *_3DSliceMapper = vtkDataSetMapper::New( );
733         _3DSliceMapper->SetInput(change->GetOutput( ) );
734         _3DSliceMapper->SetLookupTable( _bwlookup );
735         _3DSliceMapper->SetScalarRange( _range );
736         _3DSliceMapper->ImmediateModeRenderingOn( );
737
738         vtkActor *_3DSliceActor = vtkActor::New( );
739         _3DSliceActor->SetMapper( _3DSliceMapper );
740
741  // The usual rendering stuff.
742   vtkCamera *camera = vtkCamera::New();
743       camera->SetPosition(1,1,1);
744       camera->SetFocalPoint(0,0,0);
745
746   vtkRenderer *renderer = vtkRenderer::New();
747   vtkRenderWindow *renWin = vtkRenderWindow::New();
748     renWin->AddRenderer(renderer);
749
750   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
751     iren->SetRenderWindow(renWin);
752
753   renderer->AddActor( _3DSliceActor );
754       renderer->SetActiveCamera(camera);
755       renderer->ResetCamera();
756       renderer->SetBackground(1,1,1);
757
758   renWin->SetSize(300,300);
759
760   // interact with data
761   renWin->Render();
762   iren->Start();
763
764
765
766
767
768 }
769
770 //-------------------------------------------------------------------
771 // EED 25 Janvier 2007 testLoic
772 void wxVtkMPR3DView::TestLoic2()
773 {
774 /*
775  vtkVectorNorm *vecMagnitude = vtkVectorNorm::New();
776                 vecMagnitude->SetInput(VtkMainGrid);
777                 vecMagnitude->NormalizeOff();
778                 vecMagnitude->Update();
779 */
780
781         vtkPlane *slicePlane = vtkPlane::New();
782                                 this->_planeWidget->GetPlane( slicePlane );
783
784
785         vtkCutter* sliceCutter = vtkCutter::New();
786                 vtkImageData *vtkimagedata =  this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
787                 sliceCutter->SetInput( vtkimagedata );
788                 sliceCutter->SetCutFunction( slicePlane );
789
790 //EED
791 //        vtkLookupTable *lut = BuildHueWeightBaseMap();
792
793
794         vtkPolyDataMapper *slice = vtkPolyDataMapper::New();
795                 slice->SetInput( sliceCutter->GetOutput() );
796         double range[2];
797 // EED
798 //                slice->Update();
799                                   vtkimagedata->GetScalarRange(range);
800 //                vecMagnitude->GetOutput()->GetScalarRange( range );
801 //                range[1] *= 0.7; // reduce the upper range by 30%
802 //                slice->SetScalarRange( range );
803 //                slice->SetLookupTable( lut );
804
805 //       vtkActor *sliceActor = vtkActor::New();
806 //                sliceActor->SetMapper( slice );
807
808         vtkPolyDataMapper *contourMapper = vtkPolyDataMapper::New();
809                 contourMapper->SetInput( sliceCutter->GetOutput() );
810                 contourMapper->SetScalarRange( range );
811   //              contourMapper->SetLookupTable( lut );
812
813
814         vtkActor *contourActor = vtkActor::New();
815                 contourActor->SetMapper( contourMapper );
816
817
818
819  // The usual rendering stuff.
820   vtkCamera *camera = vtkCamera::New();
821       camera->SetPosition(1,1,1);
822       camera->SetFocalPoint(0,0,0);
823
824   vtkRenderer *renderer = vtkRenderer::New();
825   vtkRenderWindow *renWin = vtkRenderWindow::New();
826     renWin->AddRenderer(renderer);
827
828   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
829     iren->SetRenderWindow(renWin);
830
831   renderer->AddActor( contourActor );
832 //  renderer->AddActor(cubeActor);
833       renderer->SetActiveCamera(camera);
834       renderer->ResetCamera();
835       renderer->SetBackground(1,1,1);
836
837   renWin->SetSize(300,300);
838
839   // interact with data
840   renWin->Render();
841   iren->Start();
842 }
843
844
845