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