]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxVtkMPR3DView.cxx
f97208ad6349cf9f34c76ce52d8602453ed6e516
[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         {
188                 
189 //EED 21 mars 2012  FLIP probleme  ..PLOP..
190 //EED 13 may 2013  FLIP probleme  ..PLOP..
191                 _wxvtk3Dbaseview->GetCamera()->Roll(180);
192                 _wxvtk3Dbaseview->GetCamera()->Yaw(180+30);
193                 _wxvtk3Dbaseview->GetCamera()->Pitch(-22);
194
195                 _wxvtk3Dbaseview->GetRenderer()->ResetCamera ();
196                 _wxvtk3Dbaseview->GetCamera()->Dolly(2.0);
197                 
198         }else{
199                 
200                 /*double x = (spc[0])*(origin[0]+(((double)ext[1]-(double)ext[0])/2.0));
201                 double y = (spc[1])*(origin[1]+(double)ext[3]);
202                 double z = (spc[2])*(origin[2]+(((double)ext[5]-(double)ext[4])/2.0));*/
203                 /*double x0=(spc[0])*((double)ext[0]+origin[0]);
204                 double x1=(spc[0])*((double)ext[1]+origin[0]);
205                 double y0=(spc[1])*((double)ext[2]+origin[1]);
206                 double y1=(spc[1])*((double)ext[3]+origin[1]);
207                 double z0=(spc[2])*((double)ext[4]+origin[2]);
208                 double z1=(spc[2])*((double)ext[5]+origin[2]);*/
209                 
210                 double x0=(spc[0])*((double)ext[0]);
211                 double x1=(spc[0])*((double)ext[1]);
212                 double y0=(spc[1])*((double)ext[2]);
213                 double y1=(spc[1])*((double)ext[3]);
214                 double z0=(spc[2])*((double)ext[4]);
215                 double z1=(spc[2])*((double)ext[5]);
216
217                 _wxvtk3Dbaseview->GetRenderer()->ResetCamera(x0,x1,y0,y1,z0,z1);
218                 //_wxvtk3Dbaseview->GetCamera()->SetPosition(x,y,z);
219                 _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);      
220         }       
221 }
222
223 //-------------------------------------------------------------------
224 void wxVtkMPR3DView::Configure()
225 {
226         vtkImageData *imageData = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
227
228         _wxvtk3Dbaseview->Configure();
229         _wxvtkmpr3DviewCntrlPanel->UpdateControlPanel();
230
231 //EED 27 Mai 2009
232 //      _wxvtk3Dbaseview->GetRenderer()->Clear();
233
234         // Actors are added to the renderer.
235         vtkActor* _outlineActor = _vtkmpr3Ddataviewer->GetOutlineActor();
236         _wxvtk3Dbaseview->GetRenderer()->AddActor( _outlineActor );
237 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(0)  );    // _saggital
238 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(1)  );    // _axial
239 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(2)  );    // _coronal
240
241
242         
243         // vtkPointWidget
244         //if(_myCallback!=NULL){
245                 //_myCallback->Delete();
246
247         //}
248         vtkmyPWCallback_3DPointWidget *_myCallback = vtkmyPWCallback_3DPointWidget::New();
249         _myCallback->SetWxVtkMPR3DView(this);
250
251
252         if(imageData){
253                 if(_pointWidget==NULL){
254                         _pointWidget = vtkPointWidget::New();
255                 }
256                 _pointWidget->SetInput( imageData );
257                 _myCallback->SetVtkPointWidget(_pointWidget);
258                 _pointWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
259                 _pointWidget->AllOff();
260                 _pointWidget->PlaceWidget();
261
262                 _pointWidget->AddObserver(vtkCommand::InteractionEvent,_myCallback);
263
264                 if(_planeWidget==NULL)
265                 {
266                         _planeWidget = vtkPlaneWidget::New();
267                 }
268                 _planeWidget->SetInput( imageData );
269
270                 _myCallback->SetVtkPlaneWidget(_planeWidget);
271
272                 _planeWidget->NormalToXAxisOn();
273                 _planeWidget->SetResolution(50);
274                 _planeWidget->SetRepresentationToOutline();
275
276                 int dim[3];
277
278                 imageData->GetDimensions(dim);
279                 int px=(dim[0]/2);
280                 int py=(dim[1]/2);
281                 int pz=(dim[2]/2);
282                 int dd=20;
283                 _planeWidget->PlaceWidget( px-dd , px+dd , py-dd , py+dd , pz-dd , pz+dd );
284
285                 if(_vtkplane==NULL){
286                         _vtkplane = vtkPolyData::New();
287
288                         _probe = vtkProbeFilter::New();
289                         _probe->SetInput(_vtkplane);
290
291                         _contourMapper = vtkPolyDataMapper::New();
292
293                         _contourMapper->SetInput( _probe->GetPolyDataOutput() );
294
295                         _contourPlaneActor = vtkActor::New();
296                         _contourPlaneActor->SetMapper(_contourMapper);
297
298                         _contourPlaneActor->VisibilityOff();
299
300                         _planeWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
301                         _planeWidget->AddObserver(vtkCommand::InteractionEvent,_myCallback);
302
303                         _planeWidget->Off();
304                         _wxvtk3Dbaseview->GetRenderer()->AddActor( _contourPlaneActor );
305
306                 }
307
308                 _planeWidget->GetPolyData(_vtkplane);
309                 _probe->SetSource( imageData );
310                 _contourMapper->SetScalarRange( imageData->GetScalarRange() );
311
312         ConfigureFreePlanes();
313         }
314
315 //      _pointWidget->SetPosition( x,y,z );
316
317 //EED01 29Mars2009
318 // MACOS probleme vtk-window out of wx-window
319 //      _pointWidget->On();
320
321 // PlaneWidget
322
323
324 // An initial camera view is created.  The Dolly() method moves
325         // the camera towards the FocalPoint, thereby enlarging the image.
326         _wxvtk3Dbaseview->GetRenderer()->SetActiveCamera(_wxvtk3Dbaseview->GetCamera());
327
328         // Note that when camera movement occurs (as it does in the Dolly()
329         // method), the clipping planes often need adjusting. Clipping planes
330         // consist of two planes: near and far along the view direction. The
331         // near plane clips out objects in front of the plane; the far plane
332         // clips out objects behind the plane. This way only what is drawn
333         // between the planes is actually rendered.
334         _wxvtk3Dbaseview->GetRenderer()->ResetCameraClippingRange();
335
336         this->ResetCamera();
337
338
339         // Set a background color for the renderer and set the size of the
340         // render window (expressed in pixels).
341         _wxvtk3Dbaseview->GetRenderer()->SetBackground( 0.36 , 0.36 , 0.36 );
342 //EED 23oct2010 _wxvtk3Dbaseview->GetRenWin()->SetSize(400, 400);
343
344 }
345
346 //-------------------------------------------------------------------
347 void wxVtkMPR3DView::ConfigureFreePlanes()
348 {
349
350         // The shared picker enables us to use 3 planes at one time
351         // and gets the picking order right
352         vtkCellPicker* picker = vtkCellPicker::New();
353         picker->SetTolerance(0.005);
354
355         // The 3 image plane widgets
356         _planeWidgetX = GetPlaneWidget('x', 1, 0, 0, picker);
357         _planeWidgetY = GetPlaneWidget('y', 1, 1, 0, picker);
358         _planeWidgetZ = GetPlaneWidget('z', 0, 0, 1, picker);
359
360         _planeWidgetY->SetLookupTable(_planeWidgetX->GetLookupTable());
361         _planeWidgetZ->SetLookupTable(_planeWidgetX->GetLookupTable());
362
363         picker->UnRegister(NULL);
364
365         // ColorWindow ColorLevel Callback
366         vtkWindowLevelImagePlaneWidgetCallback *wlipwc  = vtkWindowLevelImagePlaneWidgetCallback::New();
367         wlipwc->_wxvtkmpr3Dview                                                 = this;
368         _planeWidgetX->AddObserver(vtkCommand::WindowLevelEvent, wlipwc );
369         _planeWidgetY->AddObserver(vtkCommand::WindowLevelEvent, wlipwc );
370         _planeWidgetZ->AddObserver(vtkCommand::WindowLevelEvent, wlipwc );
371         
372         // Cursor Callback
373         _planeWidgetX->AddObserver(vtkCommand::InteractionEvent, wlipwc );
374         _planeWidgetY->AddObserver(vtkCommand::InteractionEvent, wlipwc );
375         _planeWidgetZ->AddObserver(vtkCommand::InteractionEvent, wlipwc );      
376 }
377
378 //-------------------------------------------------------------------
379 vtkImagePlaneWidget* wxVtkMPR3DView::GetPlaneWidget(unsigned char activationkey, double r, double g, double b, vtkCellPicker* picker)
380 {
381         vtkProperty* prop1                                      = 0;
382         vtkImagePlaneWidget* planeWidget        = 0;
383         planeWidget                                                     = vtkImagePlaneWidget::New();
384         planeWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
385         planeWidget->EnabledOff();
386         vtkImageData *image                                     = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
387         int xMin = 0, xMax = 0, yMin = 0, yMax = 0, zMin = 0, zMax = 0;
388         double xSpacing = 0, ySpacing = 0, zSpacing = 0;
389         if(image)
390         {
391                 planeWidget->SetInput( image );
392                 image->GetExtent(xMin, xMax, yMin, yMax, zMin, zMax);
393                 image->GetSpacing(xSpacing, ySpacing, zSpacing);
394         }
395
396         if (activationkey=='x')
397         {
398                 planeWidget->SetPlaneOrientationToXAxes();
399                 planeWidget->SetSlicePosition((xMax+xMin)/2.*xSpacing);
400         }
401
402         if (activationkey=='y')
403         {
404                 planeWidget->SetPlaneOrientationToYAxes();
405                 planeWidget->SetSlicePosition((yMax+yMin)/2.*ySpacing);
406         }
407
408         if (activationkey=='z')
409         {
410                 planeWidget->SetPlaneOrientationToZAxes();
411                 planeWidget->SetSlicePosition((zMax+zMin)/2.*zSpacing);
412         }
413
414         planeWidget->DisplayTextOn();
415         planeWidget->SetPicker(picker);
416         planeWidget->SetKeyPressActivationValue(activationkey);
417         prop1 = planeWidget->GetPlaneProperty();
418         prop1->SetColor(r, g, b);
419         return planeWidget;
420 }
421
422 //-------------------------------------------------------------------
423 void wxVtkMPR3DView::SetFreePlanesOrtho()
424 {
425         _planeWidgetX->SetPlaneOrientationToXAxes();
426         _planeWidgetY->SetPlaneOrientationToYAxes();
427         _planeWidgetZ->SetPlaneOrientationToZAxes();
428         vtkInteractorStyleBaseView *isbv = (vtkInteractorStyleBaseView*)GetWxvtk3Dbaseview()->GetInteractorStyleBaseView();
429         isbv->SetParent_refresh_waiting();
430         isbv->EvaluateToRefresh();
431 }
432
433 //-------------------------------------------------------------------
434 void wxVtkMPR3DView::FreePlaneVisible(int plane, bool ok)
435 {
436         if(_planeWidgetX)
437         {
438                 if ((plane==1) && (ok==true)) _planeWidgetX->EnabledOn();
439                 if ((plane==2) && (ok==true)) _planeWidgetY->EnabledOn();
440                 if ((plane==3) && (ok==true)) _planeWidgetZ->EnabledOn();
441                 if ((plane==1) && (ok==false)) _planeWidgetX->EnabledOff();
442                 if ((plane==2) && (ok==false)) _planeWidgetY->EnabledOff();
443                 if ((plane==3) && (ok==false)) _planeWidgetZ->EnabledOff();
444         }
445 }
446
447 //-------------------------------------------------------------------
448 void wxVtkMPR3DView::FreePlaneInteraction(bool ok)
449 {
450         if(_planeWidgetX)
451         {
452                 if (ok==true)
453                 {
454                         _planeWidgetX->InteractionOn();
455                         _planeWidgetY->InteractionOn();
456                         _planeWidgetZ->InteractionOn();
457                 } else {
458                         _planeWidgetX->InteractionOff();
459                         _planeWidgetY->InteractionOff();
460                         _planeWidgetZ->InteractionOff();
461                 }
462         } // if _planeWidgetX
463 }
464
465
466
467 //-------------------------------------------------------------------
468 void wxVtkMPR3DView::setColorTransferFunction(vtkColorTransferFunction* colortable)
469 {
470         GetVtkMPR3DDataViewer ()->setColorTransferFunction(colortable);
471 }
472
473 //-------------------------------------------------------------------
474 void wxVtkMPR3DView::Refresh()   // virtual
475 {
476         _vtkmpr3Ddataviewer     ->      Refresh();
477         if (_wxvtkmpr3DviewCntrlPanel!=NULL)
478         {
479                 _wxvtkmpr3DviewCntrlPanel->Refresh();
480         }
481
482 }
483
484 //-------------------------------------------------------------------
485 void wxVtkMPR3DView::RefreshView()   // virtual
486 {
487         double spc[3];
488         vtkImageData *image = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
489
490         if(image){
491                 image->GetSpacing(spc);
492         }else{
493                 spc[0] = 0;
494                 spc[1] = 0;
495                 spc[2] = 0;
496         }
497         //this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetSpacing(spc);
498
499         //double nx=1,ny=0,nz=0; // JPRx
500         Refresh();
501         double x=GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetX();
502         double y=GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetY();
503         double z=GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetZ();
504
505         SetColorWindow( _vtkmpr3Ddataviewer->GetVtkMPRBaseData()->GetColorWindow() );
506         SetColorLevel( _vtkmpr3Ddataviewer->GetVtkMPRBaseData()->GetColorLevel() );
507
508
509         double normal[3];
510         // FreePlaneX
511         _planeWidgetX->GetNormal(normal);
512         if ((normal[0]==1)&&(normal[1]==0)&&(normal[2]==0))
513         {
514                 _planeWidgetX->SetSlicePosition( x*spc[0] );
515         }
516         // FreePlaneY
517         _planeWidgetY->GetNormal(normal);
518         if ((normal[0]==0)&&(normal[1]==1)&&(normal[2]==0))
519         {
520                 _planeWidgetY->SetSlicePosition( y*spc[1] );
521         }
522         // FreePlaneZ
523         _planeWidgetZ->GetNormal(normal);
524         if ((normal[0]==0)&&(normal[1]==0)&&(normal[2]==1))
525         {
526                 _planeWidgetZ->SetSlicePosition( z*spc[2] );
527         }
528                 
529         x=x*spc[0];
530         y=y*spc[1];
531         z=z*spc[2];
532
533         if(_pointWidget){
534                 _pointWidget->SetPosition( x,y,z );
535                 double in[3];
536                 double normal[3];
537                 vtkTransform *transform = GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetTransformOrientation();
538                 in[0]=1;                in[1]=0;                        in[2]=0;
539                 transform->TransformPoint(in,normal);
540                 _planeWidget->SetNormal( normal[0],normal[1],normal[2] );
541                 _planeWidget->SetCenter( x,y,z );
542                 _planeWidget->UpdatePlacement();
543                 _planeWidget->GetPolyData(_vtkplane);
544         }
545 }
546
547 //-------------------------------------------------------------------
548 wxPanel* wxVtkMPR3DView::CreateControlPanel(wxWindow *parent, bool align)
549 {
550         _wxvtkmpr3DviewCntrlPanel = new wxVtkMPR3DViewCntrlPanel(parent,this, align);
551         return _wxvtkmpr3DviewCntrlPanel;
552 }
553 //-------------------------------------------------------------------
554 vtkMPR3DDataViewer* wxVtkMPR3DView::GetVtkMPR3DDataViewer()
555 {
556         return _vtkmpr3Ddataviewer;
557 }
558 //-------------------------------------------------------------------
559 wxVtk3DBaseView* wxVtkMPR3DView::GetWxvtk3Dbaseview() throw (char*)
560 {
561         if(_wxvtk3Dbaseview==NULL){
562                 throw "wxVtk3DBaseView* wxVtkMPR3DView::GetWxvtk3Dbaseview() _wxvtk3Dbaseview=NULL";
563         }
564         return _wxvtk3Dbaseview;
565 }
566 //-------------------------------------------------------------------
567
568 //-------------------------------------------------------------------
569 void wxVtkMPR3DView::VisibleImageActor(int idPosition, bool visible){
570         /*if(visible == false)
571                 printf("CPR: wxVtkMPR3DView::VisibleImageActor-> visibleActor == false \n");
572         else
573         {
574                 printf("CPR: wxVtkMPR3DView::VisibleImageActor-> visibleActor == true\n");
575                 printf("CPR: wxVtkMPR3DView::VisibleImageActor-> idPosition == %d\n", idPosition);
576         }
577         */
578         if (visible!=_vtkmpr3Ddataviewer->GetVisiblePosition(idPosition)){
579                 if (visible==false){
580                         _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkmpr3Ddataviewer->GetImageActor(idPosition)  );
581                 } else {
582                         _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(idPosition)  );
583                 }
584                 _vtkmpr3Ddataviewer->SetVisiblePosition(idPosition,visible);
585         }
586 }
587
588
589 //-------------------------------------------------------------------
590 void wxVtkMPR3DView::VisiblePointWidget( bool visible )
591 {
592         if(_pointWidget){
593                 if (visible==true)
594                 {
595                         _pointWidget->On();
596                 } else {
597                         _pointWidget->Off();
598                 }
599         }
600 }
601
602 //-------------------------------------------------------------------
603 void wxVtkMPR3DView::VisiblePlaneWidget( bool visible )
604 {
605         if(_planeWidget){
606                 if (visible==true)
607                 {
608                         _planeWidget->On();
609                         _contourPlaneActor->VisibilityOn();
610
611                 } else {
612                         _planeWidget->Off();
613                         _contourPlaneActor->VisibilityOff();
614                 }
615         }
616 }
617
618 //CPR: Method added 30 Nov 2009
619 void wxVtkMPR3DView::showOutlineActor(bool value)
620 {
621         vtkActor* _outlineActor = _vtkmpr3Ddataviewer->GetOutlineActor();
622         if(value == true)
623         {
624                 _wxvtk3Dbaseview->GetRenderer()->AddActor( _outlineActor );
625         }
626         else
627         {
628                 _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _outlineActor );
629         }
630 }
631
632 //-------------------------------------------------------------------
633 void wxVtkMPR3DView::SetVtkMPR3DDataViewer(vtkMPR3DDataViewer *vtkmpr3Ddataviewer)
634 {
635         _vtkmpr3Ddataviewer = vtkmpr3Ddataviewer;
636 }
637
638 //-------------------------------------------------------------------
639 void wxVtkMPR3DView::InitOrientationPointWidget()
640 {
641         this->_planeWidget->SetNormal(1,0,0);
642 }
643
644 //-------------------------------------------------------------------
645 void wxVtkMPR3DView::SetColorWindow(double colorWindow)
646 {
647         double colorLevel = _planeWidgetX->GetLevel();
648         _planeWidgetX->SetWindowLevel(colorWindow,colorLevel);
649 }
650
651 //-------------------------------------------------------------------
652 void wxVtkMPR3DView::SetColorLevel(double colorLevel)
653 {
654         double colorWindow = _planeWidgetX->GetWindow();
655         _planeWidgetX->SetWindowLevel(colorWindow,colorLevel);
656 }
657
658 //-------------------------------------------------------------------
659 // EED 25 Janvier 2007 testLoic
660 void wxVtkMPR3DView::TestLoic1()
661 {
662
663         int sizeIma     = 128;
664   double dimIma = sizeIma*2;
665
666         vtkImageData *vtkimagedata =  this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
667
668         double spc[3];
669         vtkimagedata->GetSpacing(spc);
670
671         vtkimagedata->Update();
672
673
674          double p[3], n[3];
675      this->_planeWidget->GetOrigin(p);
676      this->_planeWidget->GetNormal(n);
677
678
679
680     vtkPlaneSource* pSource = vtkPlaneSource::New( );
681     pSource->SetResolution( sizeIma - 1, sizeIma - 1 );
682     pSource->SetOrigin( p[ 0 ], p[ 1 ], p[ 2 ] );
683     pSource->SetPoint1( p[ 0 ] + dimIma - 1.0, p[ 1 ], p[ 2 ] );
684     pSource->SetPoint2( p[ 0 ], p[ 1 ]+ dimIma - 1.0 , p[ 2 ] );
685     pSource->Update( );
686     pSource->SetCenter( p[ 0 ], p[ 1 ], p[ 2 ] );
687     pSource->SetNormal( n[ 0 ], n[ 1 ], n[ 2 ] );
688     pSource->Update( );
689
690     vtkProbeFilter* slices = vtkProbeFilter::New();
691     slices->SetInput( ( vtkDataSet* )pSource->GetOutput( ) );
692     slices->SetSource( vtkimagedata );
693     slices->Update( );
694     pSource->Delete( );
695
696         vtkStructuredPoints   *stPoints = vtkStructuredPoints::New();
697         stPoints -> GetPointData( )->SetScalars(  slices->GetOutput()->GetPointData()->GetScalars()  );
698         stPoints -> SetDimensions( sizeIma, sizeIma, 1 );
699         stPoints -> SetScalarType( vtkimagedata->GetScalarType() );
700         stPoints -> SetScalarTypeToShort();
701         stPoints -> Update();
702
703         vtkImageChangeInformation  *change = vtkImageChangeInformation ::New();
704         change    -> SetInput( stPoints );
705         change    -> Update();    //important
706
707         double _range[2];
708         vtkimagedata->GetScalarRange(_range);
709    vtkWindowLevelLookupTable *_bwlookup = vtkWindowLevelLookupTable::New( );
710    _bwlookup->SetHueRange( 0 , 1 );
711    _bwlookup->SetNumberOfColors( (int)(_range[1] - _range[0] + 1) );
712    _bwlookup->SetTableRange( _range[0] , _range[1] );
713    _bwlookup->SetSaturationRange( 0 , 0 );
714    _bwlookup->SetValueRange( 0 , 1 );
715    _bwlookup->SetAlphaRange( 1 , 1 );
716    _bwlookup->Build( );
717
718    vtkLookupTable * _collookup = vtkLookupTable::New( );
719    _collookup->SetNumberOfColors( 256 );
720    _collookup->SetTableRange( 0 , 255 );
721    _collookup->Build( );
722    _collookup->SetTableValue( 0  , 1 , 0 , 0 , 1 );
723    _collookup->SetTableValue(128 , 0 , 0 , 1 , 1 );
724    _collookup->SetTableValue(255 , 0 , 1 , 0 , 1 );
725
726
727         vtkMetaImageWriter *writer = vtkMetaImageWriter::New( );
728         writer->SetInput( stPoints );
729         writer->SetFileName( "C:/Users/Images/temp_EED/image.mhd" );
730         writer->SetFileDimensionality( 2 );
731         writer->Write( );
732
733
734
735         vtkDataSetMapper *_3DSliceMapper = vtkDataSetMapper::New( );
736         _3DSliceMapper->SetInput(change->GetOutput( ) );
737         _3DSliceMapper->SetLookupTable( _bwlookup );
738         _3DSliceMapper->SetScalarRange( _range );
739         _3DSliceMapper->ImmediateModeRenderingOn( );
740
741         vtkActor *_3DSliceActor = vtkActor::New( );
742         _3DSliceActor->SetMapper( _3DSliceMapper );
743
744  // The usual rendering stuff.
745   vtkCamera *camera = vtkCamera::New();
746       camera->SetPosition(1,1,1);
747       camera->SetFocalPoint(0,0,0);
748
749   vtkRenderer *renderer = vtkRenderer::New();
750   vtkRenderWindow *renWin = vtkRenderWindow::New();
751     renWin->AddRenderer(renderer);
752
753   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
754     iren->SetRenderWindow(renWin);
755
756   renderer->AddActor( _3DSliceActor );
757       renderer->SetActiveCamera(camera);
758       renderer->ResetCamera();
759       renderer->SetBackground(1,1,1);
760
761   renWin->SetSize(300,300);
762
763   // interact with data
764   renWin->Render();
765   iren->Start();
766
767
768
769
770
771 }
772
773 //-------------------------------------------------------------------
774 // EED 25 Janvier 2007 testLoic
775 void wxVtkMPR3DView::TestLoic2()
776 {
777 /*
778  vtkVectorNorm *vecMagnitude = vtkVectorNorm::New();
779                 vecMagnitude->SetInput(VtkMainGrid);
780                 vecMagnitude->NormalizeOff();
781                 vecMagnitude->Update();
782 */
783
784         vtkPlane *slicePlane = vtkPlane::New();
785                                 this->_planeWidget->GetPlane( slicePlane );
786
787
788         vtkCutter* sliceCutter = vtkCutter::New();
789                 vtkImageData *vtkimagedata =  this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
790                 sliceCutter->SetInput( vtkimagedata );
791                 sliceCutter->SetCutFunction( slicePlane );
792
793 //EED
794 //        vtkLookupTable *lut = BuildHueWeightBaseMap();
795
796
797         vtkPolyDataMapper *slice = vtkPolyDataMapper::New();
798                 slice->SetInput( sliceCutter->GetOutput() );
799         double range[2];
800 // EED
801 //                slice->Update();
802                                   vtkimagedata->GetScalarRange(range);
803 //                vecMagnitude->GetOutput()->GetScalarRange( range );
804 //                range[1] *= 0.7; // reduce the upper range by 30%
805 //                slice->SetScalarRange( range );
806 //                slice->SetLookupTable( lut );
807
808 //       vtkActor *sliceActor = vtkActor::New();
809 //                sliceActor->SetMapper( slice );
810
811         vtkPolyDataMapper *contourMapper = vtkPolyDataMapper::New();
812                 contourMapper->SetInput( sliceCutter->GetOutput() );
813                 contourMapper->SetScalarRange( range );
814   //              contourMapper->SetLookupTable( lut );
815
816
817         vtkActor *contourActor = vtkActor::New();
818                 contourActor->SetMapper( contourMapper );
819
820
821
822  // The usual rendering stuff.
823   vtkCamera *camera = vtkCamera::New();
824       camera->SetPosition(1,1,1);
825       camera->SetFocalPoint(0,0,0);
826
827   vtkRenderer *renderer = vtkRenderer::New();
828   vtkRenderWindow *renWin = vtkRenderWindow::New();
829     renWin->AddRenderer(renderer);
830
831   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
832     iren->SetRenderWindow(renWin);
833
834   renderer->AddActor( contourActor );
835 //  renderer->AddActor(cubeActor);
836       renderer->SetActiveCamera(camera);
837       renderer->ResetCamera();
838       renderer->SetBackground(1,1,1);
839
840   renWin->SetSize(300,300);
841
842   // interact with data
843   renWin->Render();
844   iren->Start();
845 }
846
847
848