]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMPRWidget.cxx
BUG histogram
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / wxMPRWidget.cxx
1 /*=========================================================================
2
3   Program:   wxMaracas
4   Module:    $RCSfile: wxMPRWidget.cxx,v $
5   Language:  C++
6   Date:      $Date: 2009/05/07 15:35:46 $
7   Version:   $Revision: 1.13 $
8
9   Copyright: (c) 2002, 2003
10   License:
11
12      This software is distributed WITHOUT ANY WARRANTY; without even
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14      PURPOSE.  See the above copyright notice for more information.
15
16 =========================================================================*/
17
18
19 #include <vtkObjectFactory.h>
20 #include <vtkInteractorStyleSwitch.h>
21 #include <vtkCamera.h>
22 #include <vtkImageActor.h>
23 #include <vtkRenderer.h>
24 #include <vtkRenderWindowInteractor.h>
25 #include <vtkRenderWindow.h>
26
27 #include <vtkRenderer.h>
28 #include <vtkImageViewer2.h> 
29 #include <vtkInteractorStyleImage.h> 
30
31 #include <vtkProperty.h> 
32 #include <vtkPolyData.h> 
33 #include <vtkDataSet.h> 
34 #include <vtkStripper.h>
35 #include <vtkCellArray.h> 
36 #include <vtkPointData.h> 
37 #include <vtkInteractorStyleTrackballCamera.h>
38
39 #include <vtkPlanes.h>
40 #include <vtkProbeFilter.h>
41 #include <vtkPlane.h>
42 #include <vtkPointPicker.h>
43
44
45 #include "vtkClosePolyData.h"
46 #include <vtkTriangleFilter.h>
47 #include <vtkSTLWriter.h>
48 #include <vtkPolyDataConnectivityFilter.h>
49
50 // EED 25 Janvier 2007  -  TestLoic
51 #include <vtkCutter.h>
52 #include <vtkWindowLevelLookupTable.h>
53 #include <vtkLookupTable.h>
54 #include <vtkMetaImageWriter.h>
55
56
57
58 #include "wxMPRWidget.h"
59 #include "wxVTKRenderWindowInteractor.h"
60 #include "UtilVtk3DGeometriSelection.h"
61 #include "../kernel/marDicomBase.h"
62
63
64 #include <wx/wx.h>
65 #include <wx/notebook.h>
66 #include <wx/colordlg.h>
67
68 #include "matrix.h"
69 #include <string>
70 #include <stdio.h>
71
72
73
74 #include "pPlotter/HistogramDialog.h"
75
76 //-------------------------------------------------------------------
77 //-------------------------------------------------------------------
78 //-------------------------------------------------------------------
79
80 idAlBeRa::idAlBeRa(int id, double radio,int deltavoxel)
81 {
82         _id                     = id;
83         _radio          = radio;
84         _deltavoxel = deltavoxel;
85 }
86
87
88 //-------------------------------------------------------------------
89 //-------------------------------------------------------------------
90 //-------------------------------------------------------------------
91
92 vtkInteractorStyleSphere::vtkInteractorStyleSphere()
93 {
94         _stateRadio  = false;
95         _stateRotate = false;
96 }
97
98 //---------------------------------------------------------------------------
99
100 vtkInteractorStyleSphere::~vtkInteractorStyleSphere()
101 {
102 }
103
104
105 //---------------------------------------------------------------------------
106
107 bool  vtkInteractorStyleSphere::OnRightButtonDown()
108 {
109         if ((_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==0) && (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==0) )
110         {
111                 _stateRadio     = true;
112                 //_fordwareX    = this->Interactor->GetEventPosition()[0];
113                 _fordwareY      = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
114
115                 wxSphereView *wxsphereview = (wxSphereView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView());
116
117                 _radio = wxsphereview->GetRadio();
118         }
119
120         return true;
121 }
122
123 //---------------------------------------------------------------------------
124
125 bool  vtkInteractorStyleSphere::OnRightButtonUp() 
126 {
127         if (_stateRadio==true)
128         {
129                 wxSphereView *wxsphereview = (wxSphereView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView());
130                 wxsphereview->SetDeltaVoxel(1);
131                 double radio=wxsphereview->GetRadio();
132                 wxsphereview->GetIdOfImage(radio+0.1);
133                 wxsphereview->GetIdOfImage(radio+0.2);
134                 wxsphereview->GetIdOfImage(radio-0.1);
135                 wxsphereview->GetIdOfImage(radio-0.2);
136
137                 wxsphereview->RefreshView();
138                 _stateRadio = false;
139         }
140
141         return true;
142 }
143 //---------------------------------------------------------------------------
144
145 bool vtkInteractorStyleSphere::OnLeftButtonDown()
146 {
147         _stateRotate    = true;
148         _fordwareX              = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];
149         _fordwareY              = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
150         return true;
151 }
152
153
154 //---------------------------------------------------------------------------
155
156 bool  vtkInteractorStyleSphere::OnLeftButtonUp() 
157 {
158         wxSphereView *wxsphereview = (wxSphereView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView());
159         if (_stateRotate==true){
160                 int fx  = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];
161                 int fy  = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
162
163                 if ((_fordwareX==fx)&&(_fordwareY==fy)){
164                         double x=fx,y=fy,z=1;
165                         _vtkInteractorStyleBaseView->TransformCoordinate(x,y,z);            
166                         wxsphereview->SetXYZtoParent(x,y);
167                         wxCommandEvent newevent(wxEVT_COMMAND_MENU_SELECTED,12121);
168                         wxsphereview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent);
169                 } else {
170                         wxsphereview->RotationEnd();
171                 }
172                 wxsphereview->RefreshView();
173                 _stateRotate = false;
174         }
175
176         return true;
177 }
178
179
180 //---------------------------------------------------------------------------
181
182 bool  vtkInteractorStyleSphere::OnMouseMove () 
183 {
184         wxSphereView *wxsphereview = (wxSphereView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView());
185         if (_stateRotate==true)
186         {
187                 bool ok_v, ok_ang;
188                 ok_v=false;
189                 ok_ang=false;
190                 if (_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==1)
191                 {
192                         ok_v = true;
193                 }
194                 if (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==1)
195                 {
196                         ok_ang = true;
197                 }
198             int fx = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];
199         int fy = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
200                 wxsphereview->RotationStart( fx - _fordwareX , -(fy - _fordwareY) , ok_v, ok_ang);
201                 wxsphereview->RefreshView();
202         } 
203         if (_stateRadio==true)
204         {           
205                 //int fx = this->Interactor->GetEventPosition()[0];
206         int fy = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
207                 double dif=(fy-_fordwareY) / 10.0;
208                 wxsphereview->SetRadio( _radio + dif );
209                 wxsphereview->SetDeltaVoxel(3);
210                 wxsphereview->RefreshView();
211         }
212
213         return true;
214 }
215
216
217
218 //-------------------------------------------------------------------
219 //-------------------------------------------------------------------
220 //-------------------------------------------------------------------
221
222 wxSphereView::wxSphereView( wxWindow *parent, vtkMPRBaseData *vtkmprbasedata, vtkImageData *imageData )
223 : wxVtk2DBaseView(parent)
224 {
225         _delta                          =       1;
226         _vtkmprbasedata         =       vtkmprbasedata;
227         _imageDataOriginal      =       imageData;
228
229         _imageSphere            =       vtkImageData::New();
230         _imageSphere->SetDimensions (150,150,500);
231         _imageSphere->SetScalarTypeToUnsignedShort();
232         _imageSphere->AllocateScalars();   
233         _imageSphere->Update();   
234
235
236         vtkBaseData *vtkbasedata = new vtkBaseData();
237         vtkbasedata->SetMarImageData( new marImageData(_imageSphere) );
238         this->SetVtkBaseData(vtkbasedata);
239
240     _transform                  =       vtkTransform::New();
241     _transform1                 =       vtkTransform::New();
242     _transform2                 =       vtkTransform::New();
243         _transform ->Identity();
244         _transform1->Identity();
245         _transform2->Identity();
246
247         _radio=25;
248 }
249
250 //-------------------------------------------------------------------
251
252 wxSphereView::~wxSphereView()
253 {
254         _transform  -> Delete();
255         _transform1 -> Delete();
256         _transform2 -> Delete();
257         ResetlstId();
258 }
259
260 //----------------------------------------------------------------------------
261
262 double wxSphereView::GetRadio()
263 {
264         return _radio;
265 }
266
267 //----------------------------------------------------------------------------
268
269 void wxSphereView::SetRadio(double radio)
270 {
271         if (radio<0)
272         {
273                 radio=0;
274         }
275         _radio=radio;
276 }
277
278 //----------------------------------------------------------------------------
279
280 void wxSphereView::Configure()
281 {
282         wxVtk2DBaseView::Configure();
283
284         _vtkinteractorstylesphere = new vtkInteractorStyleSphere();
285         GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _vtkinteractorstylesphere );
286         double points[4][3];
287
288 // EED purify 12/sep/2006
289         int i,j;
290         for (i=0;i<4;i++)
291         {
292                 for (j=0;j<3;j++)
293                 {
294                         points[i][j]=0;
295                 }
296         }
297
298         InitSphere(points);
299         DefineImageSphere();
300 }
301
302 //----------------------------------------------------------------------------
303
304 void wxSphereView::RefreshPoint()
305 {
306         double x        = _vtkmprbasedata->GetX() - _centerX;
307         double y        = _vtkmprbasedata->GetY() - _centerY;
308         double z        = _vtkmprbasedata->GetZ() - _centerZ;
309         double alpha= atan2(x,z);
310         double beta = atan2( y , sqrt(z*z+x*x) );
311
312         alpha           = alpha*180/3.1416;
313         beta            = beta*180/3.1416;
314
315         _transform1->Identity();
316         _transform1->RotateY(alpha);
317         _transform1->RotateX(-beta);
318
319         _radio= sqrt(x*x + y*y +z*z);
320
321         RefreshView();
322 }
323
324 //----------------------------------------------------------------------------
325
326 void wxSphereView::RefreshView()
327 {
328         DefineImageSphere();
329         wxVtk2DBaseView::Refresh();
330 }
331
332 //----------------------------------------------------------------------------
333
334 void wxSphereView::RotationEnd()
335 {
336         _transform1->RotateWXYZ(_ang,_vxb,_vyb,0);
337         _transform2->Identity();
338         SetDeltaVoxel(1);
339         ResetlstId();
340 }
341
342 //----------------------------------------------------------------------------
343
344 void wxSphereView::RotationStart(double vx, double vy, bool ok_v, bool ok_ang)
345 {
346         if (ok_ang==false)
347         {
348                 _ang = -sqrt( vx*vx + vy*vy ) / 1.0;
349         }
350
351         if (ok_v==false){
352                 _vxb=-vy;
353                 _vyb=vx;
354         }
355
356         _transform2->Identity();
357         _transform2->RotateWXYZ(_ang,_vxb,_vyb,0);
358         SetDeltaVoxel(3);
359         ResetlstId();
360 }
361
362 //----------------------------------------------------------------------------
363
364 void wxSphereView::GetPointSphere(double p[3],double r1,double angA,double angB)
365 {
366         double in[3],out[3];
367         in[0]=0;   
368         in[1]=r1;   
369         in[2]=0;
370         vtkTransform *transform = vtkTransform::New();
371         transform->Identity();
372         transform->RotateX(angB);
373         transform->RotateZ(angA);
374         transform->TransformPoint(in,out);
375         p[0]=out[0];
376         p[1]=out[1];
377         p[2]=out[2];
378         transform->Delete(); 
379 }
380
381 //----------------------------------------------------------------------------
382
383 void wxSphereView::RotatePointOverTheSphere( double pp[3], double p[3],double cc[3])
384 {
385
386         double out[3];
387         _transform->TransformPoint(p,out);
388         pp[0] = out[0] + cc[0];
389         pp[1] = out[1] + cc[1];
390         pp[2] = out[2] + cc[2];
391
392 }
393
394 //----------------------------------------------------------------------------
395
396 void wxSphereView::TransferePoints(double pp1[3],double pp2[3],double AngX,double AngY,vtkImageData *image)
397 {
398         double t;
399         double difX = pp2[0]-pp1[0];
400         double difY = pp2[1]-pp1[1];
401         double difZ = pp2[2]-pp1[2];
402
403         double  max             = 200;
404
405         int dimOrg[3];
406         int dimRes[3];
407         int z;
408         _imageDataOriginal->GetDimensions(dimOrg);              
409         image->GetDimensions(dimRes);           
410
411         int i;
412         double x1=pp1[0];
413         double y1=pp1[1];
414         double z1=pp1[2];
415         int xx=-1,yy=-1,zz=-1;
416
417         for (i=0;i<max;i++)
418         {
419                 t  = i/max;
420                 xx = (int) (x1+t*difX);
421                 yy = (int) (y1+t*difY);
422                 zz = (int) (z1+t*difZ);
423
424                 z=i;
425                 if ((xx>=0) && (xx<dimOrg[0]) && (yy>=0) && (yy<dimOrg[1]) && (zz>=0) && (zz<dimOrg[2]) &&
426                         (AngX>=0) && (AngX<dimRes[0]) && (AngY>=0) && (AngY<dimRes[1]) && (z>=0) && (z<dimRes[2]) )
427                 {
428                         unsigned short *pOrg=(unsigned short*)_imageDataOriginal->GetScalarPointer (xx,yy,zz); 
429                         unsigned short *pRes=(unsigned short*)image->GetScalarPointer( (int)AngX , (int)AngY , z ); 
430                         *pRes=*pOrg;
431                 }
432         }
433 }
434
435 //----------------------------------------------------------------------------
436
437 void wxSphereView::ResetlstId()
438 {
439         int i,size=_lstId.size();
440         for (i=size-1;i>=0;i--)
441         {
442                 delete _lstId[i];
443         }
444         _lstId.clear();
445 }
446
447 //----------------------------------------------------------------------------
448
449 int wxSphereView::GetIdOfImage(double radio)
450 {
451         int id=0;
452         int dim[3];     
453         _imageSphere->GetDimensions(dim);       
454         int sizeMaxList = dim[2];
455         // Search in list >> alpha beta radio
456         int i,size=_lstId.size();
457         for (i=0; i<size;i++)
458         {
459                 //idAlBeRa *tmp=_lstId[i]; // JPRx
460                 if ((_lstId[i]->_radio==radio) && (_lstId[i]->_deltavoxel==_delta)) 
461                 {
462                         return _lstId[i]->_id;
463                 }
464         }
465         if (size>sizeMaxList)
466         {
467                 delete _lstId[size-1];
468                 _lstId.pop_back(); 
469         }
470         if (size!=0){
471                 id=_lstId[0]->_id+1;
472                 id = id % sizeMaxList;
473         } else {
474                 id = 0;
475         }
476
477         FiltreImage(id,radio);
478         _lstId.insert(_lstId.begin(),1,new idAlBeRa(id,radio,_delta) ); 
479
480         return id;
481 }
482
483 //----------------------------------------------------------------------------
484
485 void wxSphereView::DefineImageSphere()
486 {
487         int id;
488         id=GetIdOfImage( _radio );
489         GetVtkBaseData()->SetZ( id );
490 }
491
492
493 //----------------------------------------------------------------------------
494 void wxSphereView::SetDeltaVoxel(int delta)
495 {
496         _delta=delta;
497 }
498
499 //----------------------------------------------------------------------------
500 void wxSphereView::SetVoxel(double i, double j, int delta,double id,  unsigned short gris)
501 {
502         int ii,jj,delta2;
503         unsigned short *pRes;
504         int dimRes[3];
505         _imageSphere->GetDimensions(dimRes);
506
507         delta2=delta-1;
508         for ( ii=(int)(i-delta2) ; ii<=(int)(i+delta2) ; ii++ )
509         {
510                 for ( jj=(int)(j-delta2) ; jj<=(int)(j+delta2) ; jj++ )
511                 {
512                         if ( (ii>=0)&&(ii<dimRes[0]) &&  
513                                  (jj>=0)&&(jj<dimRes[1]) )
514                         {
515                                 pRes = (unsigned short*)_imageSphere->GetScalarPointer( ii , jj , (int)id );
516                                 *pRes=gris;
517                         }
518                 }
519         }
520
521 }
522
523 //----------------------------------------------------------------------------
524
525 void wxSphereView::SetXYZtoParent(double i, double j)
526 {
527
528         double factor = 0.75;
529         double radio2   = _radio*_radio;
530         double pxx,pyy,d2x,d2y;
531         double cc[3],p[3],pp[3];
532         cc[0]=_centerX;
533         cc[1]=_centerY;
534         cc[2]=_centerZ;
535         double aa;
536         int dimRes[3],dimOrig[3];
537         _imageSphere->GetDimensions(dimRes);
538         d2x=dimRes[0]/2;
539         d2y=dimRes[1]/2;
540         _imageDataOriginal->GetDimensions(dimOrig);
541
542         p[0]  = (i - d2x)*factor;
543         pxx=p[0]*p[0];
544         p[1]  = (j - d2y)*factor;
545         pyy=p[1]*p[1];
546         aa = pxx + pyy;
547         if (radio2>aa){
548                 aa=radio2-aa;
549                 p[2]  = sqrt(aa);
550                 RotatePointOverTheSphere( pp, p,cc);
551                 if ( (pp[0]>=0) && (pp[0]<dimOrig[0]) && 
552                          (pp[1]>=0) && (pp[1]<dimOrig[1]) && 
553                          (pp[2]>=0) && (pp[2]<dimOrig[2]) )
554                 {
555                         if (_vtkmprbasedata){
556                                 _vtkmprbasedata->SetX(pp[0]);
557                                 _vtkmprbasedata->SetY(pp[1]);
558                                 _vtkmprbasedata->SetZ(pp[2]);
559                         }
560                 }
561         }
562 }
563
564
565 //----------------------------------------------------------------------------
566
567 void wxSphereView::FiltreImageB(int id, double radio, bool ok,int deltaTMP)
568 {       
569         double factor = 0.75;
570         double radioB   = radio/3;
571         double radio2   = radio*radio;
572         double pxx,pyy,d2x,d2y;
573         double cc[3],p[3],pp[3];
574         cc[0]=_centerX;
575         cc[1]=_centerY;
576         cc[2]=_centerZ;
577         double aa;
578         unsigned short *pOrig;
579         int dimRes[3],dimOrig[3];
580         double i,j;
581         int ext[6];
582         _imageSphere->GetExtent(ext);
583         _imageSphere->GetDimensions(dimRes);
584         //JCP 24 - 04 -09
585         //_imageSphere->SetExtent(0,dimRes[0]-1,0,dimRes[1]-1,0,dimRes[2]-1);
586         _imageSphere->SetExtent(ext);
587         //JCP 24 - 04 -09
588         d2x=dimRes[0]/2;
589         d2y=dimRes[1]/2;
590 //      double deltaTMP=_delta;
591         _imageDataOriginal->GetDimensions(dimOrig);
592
593         int start,end;
594         int limitA,limitB;
595         limitA  = (int) ( (-radioB/factor)+d2x );
596         limitB  = (int) ( (radioB/factor)+d2x );
597         if (ok==true){
598                 start   = limitA;
599                 end             = limitB;
600         } else {
601                 start=0;
602                 end=dimRes[0];
603         }
604
605         for ( i=start ; i<end ; i=i+deltaTMP )
606         {
607                 p[0]  = (i - d2x)*factor;
608                 pxx=p[0]*p[0];
609                 for (j=start;j<end;j=j+deltaTMP)
610                 {
611                         p[1]  = (j - d2y)*factor;
612                         pyy=p[1]*p[1];
613                         aa = pxx + pyy;
614
615                         if  (( ((ok==false) && (!((i>limitA) && (i<limitB) && (j>limitA) && (j<limitB)))) )
616                                     ||
617                                         (ok==true))
618                         {
619                                 if (radio2>aa){
620                                         aa=radio2-aa;
621                                         p[2]  = sqrt(aa);
622                                         RotatePointOverTheSphere( pp, p,cc);
623                                         if ( (pp[0]>=0) && (pp[0]<dimOrig[0]) && 
624                                                  (pp[1]>=0) && (pp[1]<dimOrig[1]) && 
625                                                  (pp[2]>=0) && (pp[2]<dimOrig[2]) )
626                                         {
627                                                 pOrig=(unsigned short*)_imageDataOriginal->GetScalarPointer( (int)(pp[0]) , (int)(pp[1]) , (int)(pp[2]) ); 
628                                                 SetVoxel(i,j,deltaTMP,id,*pOrig);
629                                         } else {
630                                                 SetVoxel(i,j,deltaTMP,id,2000);
631                                         }
632                                 } else {
633                                         SetVoxel(i,j,deltaTMP,id,0);
634                                 }
635                         }
636                 }
637         }
638
639         _imageSphere->Modified();  
640         _imageSphere->Update();
641 }
642
643
644
645
646 //----------------------------------------------------------------------------
647
648 void wxSphereView::FiltreImage(int id, double radio)
649 {
650
651         _transform -> Identity();
652         _transform -> Concatenate(_transform1);
653         _transform -> Concatenate(_transform2);
654
655         FiltreImageB(id,radio,false, _delta);
656         FiltreImageB(id,radio,true, 1);
657 }
658
659
660 //----------------------------------------------------------------------------
661
662 /*
663 void wxSphereView::FiltreImage(int id, double radio)
664 {
665         double radio2   = radio*radio;
666         double radio2TMP= (radio/2)*(radio/2);
667         double pxx,pyy,d2x,d2y;
668         double cc[3],p[3],pp[3];
669         cc[0]=_centerX;
670         cc[1]=_centerY;
671         cc[2]=_centerZ;
672         double aa;
673         unsigned short *pOrig;
674         int dimRes[3],dimOrig[3];
675         double i,j;
676         _imageSphere->GetDimensions(dimRes);
677         _imageSphere->SetExtent(0,dimRes[0]-1,0,dimRes[1]-1,0,dimRes[2]-1);
678         d2x=dimRes[0]/2;
679         d2y=dimRes[1]/2;
680         double deltaTMP=_delta;
681         _imageDataOriginal->GetDimensions(dimOrig);
682
683         for ( i=0 ; i<dimRes[0] ; i=i+deltaTMP )
684         {
685                 p[0]  = (i - d2x)*0.75;
686                 pxx=p[0]*p[0];
687                 for (j=0;j<dimRes[1];j=j+deltaTMP)
688                 {
689                         p[1]  = (j - d2y)*0.75;
690                         pyy=p[1]*p[1];
691                         aa = pxx + pyy;
692
693                         if (aa>radio2TMP)
694                         {
695                                 if (radio2>aa){
696                                         aa=radio2-aa;
697                                         p[2]  = sqrt(aa);
698                                         RotatePointOverTheSphere( pp, p,cc);
699                                         if ( (pp[0]>=0) && (pp[0]<dimOrig[0]) && 
700                                                  (pp[1]>=0) && (pp[1]<dimOrig[1]) && 
701                                                  (pp[2]>=0) && (pp[2]<dimOrig[2]) )
702                                         {
703                                                 pOrig=(unsigned short*)_imageDataOriginal->GetScalarPointer( pp[0] , pp[1] , pp[2] ); 
704                                                 SetVoxel(i,j,deltaTMP,id,*pOrig);
705                                         } else {
706                                                 SetVoxel(i,j,deltaTMP,id,2000);
707                                         }
708                                 } else {
709                                         SetVoxel(i,j,deltaTMP,id,0);
710                                 }
711                         }
712                 }
713         }
714
715
716         deltaTMP=1;
717         for ( i=0 ; i<dimRes[0] ; i=i+deltaTMP )
718         {
719                 p[0]  = (i - d2x)*0.75;
720                 pxx=p[0]*p[0];
721                 for (j=0;j<dimRes[1];j=j+deltaTMP)
722                 {
723                         p[1]  = (j - d2y)*0.75;
724                         pyy=p[1]*p[1];
725                         aa = pxx + pyy;
726                         if (aa<=radio2TMP)
727                         {
728                                 if (radio2>aa){
729                                         aa=radio2-aa;
730                                         p[2]  = sqrt(aa);
731                                         RotatePointOverTheSphere( pp, p,cc);
732                                         if ( (pp[0]>=0) && (pp[0]<dimOrig[0]) && 
733                                                  (pp[1]>=0) && (pp[1]<dimOrig[1]) && 
734                                                  (pp[2]>=0) && (pp[2]<dimOrig[2]) )
735                                         {
736                                                 pOrig=(unsigned short*)_imageDataOriginal->GetScalarPointer( pp[0] , pp[1] , pp[2] ); 
737                                                 SetVoxel(i,j,deltaTMP,id,*pOrig);
738                                         } else {
739                                                 SetVoxel(i,j,deltaTMP,id,2000);
740                                         }
741                                 } else {
742                                         SetVoxel(i,j,deltaTMP,id,0);
743                                 }
744                         }
745                 }
746         }
747
748         _imageSphere->Modified();  
749         _imageSphere->Update();
750 }
751 */
752 /*
753 void wxSphereView::FiltreImage(vtkImageData *imageSphere)
754 {
755         int dim[3],i,j,k;
756         imageSphere->GetDimensions(dim);
757         for (i=0;i<dim[0];i++)
758         {
759                 for (j=0;j<dim[1];j++)
760                 {
761                         for (k=0;k<dim[2];k++)
762                         {
763                                 unsigned short *pRes=(unsigned short*)imageSphere->GetScalarPointer (i,j,k); 
764                                 *pRes=0;
765                         }
766                 }
767         }
768
769         double deltaA=90;
770         double cc[3],p1[3],p2[3],pp1[3],pp2[3];
771         cc[0]=_centerX;
772         cc[1]=_centerY;
773         cc[2]=_centerZ;
774         double r1       = _sl_radio->GetValue() - _sl_thickness->GetValue()/2;
775         double r2       = _sl_radio->GetValue() + _sl_thickness->GetValue()/2;
776         if (r1<10)
777         {
778                 r1=10;
779         }
780         double alpha= _sl_alpha->GetValue();
781         double beta     = _sl_beta->GetValue();
782
783         double angA,angB;
784         for (angA=-deltaA;angA<deltaA;angA++)
785         {
786                 for (angB=-deltaA;angB<deltaA;angB++)
787                 {
788                         GetPointSphere(p1,r1,angA,angB);
789                         GetPointSphere(p2,r2,angA,angB);
790                         RotatePointOverTheSphere( pp1, alpha, beta, p1 ,cc );
791                         RotatePointOverTheSphere( pp2, alpha, beta, p2 ,cc );
792                         TransferePoints(pp1,pp2,angA+alpha+180,angB+beta+90,imageSphere);
793                 }
794         }
795 }
796 */
797
798
799 //----------------------------------------------------------------------------
800
801 void wxSphereView::InitSphere(double points[4][3])
802 {
803         double cc[3];
804     double r = SphereFindCenter(points,cc); // 4-points , center
805     if (r > 0)
806     {
807         _centerX        = (int)(cc[0]);
808         _centerY        = (int)(cc[1]);
809         _centerZ        = (int)(cc[2]);
810     } else {
811                 int dim[3];
812                 _imageDataOriginal->GetDimensions(dim);
813         _centerX        = (int)(dim[0]/2);
814         _centerY        = (int)(dim[1]/2);
815         _centerZ        = (int)(dim[2]/2);
816         }
817 }
818
819 //----------------------------------------------------------------------------
820
821 // Calculate center and radius of sphere given four points
822 // http://home.att.net/~srschmitt/script_sphere_solver.html
823 // source code HTML <script language=JavaScript>
824 double wxSphereView::SphereFindCenter(double P[4][3], double cc[3])
825 {
826     int i;
827     double r, m11, m12, m13, m14, m15;
828         double a[4][4];
829
830     for (i = 0; i < 4; i++)                    // find minor 11
831     {
832         a[i][0] = P[i][0];
833         a[i][1] = P[i][1];
834         a[i][2] = P[i][2];
835         a[i][3] = 1;
836     }
837     m11 = determinant( a, 4 );
838
839     for (i = 0; i < 4; i++)                    // find minor 12 
840     {
841         a[i][0] = P[i][0]*P[i][0] + P[i][1]*P[i][1] + P[i][2]*P[i][2];
842         a[i][1] = P[i][1];
843         a[i][2] = P[i][2];
844         a[i][3] = 1;
845     }
846     m12 = determinant( a, 4 );
847
848     for (i = 0; i < 4; i++)                    // find minor 13
849     {
850         a[i][0] = P[i][0]*P[i][0] + P[i][1]*P[i][1] + P[i][2]*P[i][2];
851         a[i][1] = P[i][0];
852         a[i][2] = P[i][2];
853         a[i][3] = 1;
854     }
855     m13 = determinant( a, 4 );
856
857     for (i = 0; i < 4; i++)                    // find minor 14
858     {
859         a[i][0] = P[i][0]*P[i][0] + P[i][1]*P[i][1] + P[i][2]*P[i][2];
860         a[i][1] = P[i][0];
861         a[i][2] = P[i][1];
862         a[i][3] = 1;
863     }
864     m14 = determinant( a, 4 );
865
866
867     for (i = 0; i < 4; i++)                    // find minor 15
868     {
869         a[i][0] = P[i][0]*P[i][0] + P[i][1]*P[i][1] + P[i][2]*P[i][2];
870         a[i][1] = P[i][0];
871         a[i][2] = P[i][1];
872         a[i][3] = P[i][2];
873     }
874     m15 = determinant( a, 4 );
875
876     if (m11 == 0)
877     {
878         r = 0;
879     }
880     else
881     {
882                 // center of sphere
883         cc[0] =  0.5*m12/m11;   //cx                  
884         cc[1] = -0.5*m13/m11;   //cy
885         cc[2] =  0.5*m14/m11;   //cz
886                 // Sphere radio 
887         r  = sqrt( cc[0]*cc[0] + cc[1]*cc[1] + cc[2]*cc[2] - m15/m11 );
888     }
889
890     return r;                                  // the radius
891 }
892 //----------------------------------------------------------------------------
893
894 //  Recursive definition of determinate using expansion by minors.
895 double wxSphereView::determinant(double a[4][4], int n)
896 {
897     int i, j, j1, j2;
898     double d;
899         double m[4][4];
900
901         for (i=0;i<4;i++)
902         {
903                 for (j=0;j<4;j++)
904                 {
905                         m[i][j]=0;
906                 }
907         }
908
909     if (n == 2)                                // terminate recursion
910     {
911         d = a[0][0]*a[1][1] - a[1][0]*a[0][1];
912     }
913     else 
914     {
915         d = 0;
916         for (j1 = 0; j1 < n; j1++ )            // do each column
917         {
918             for (i = 1; i < n; i++)            // create minor
919             {
920                 j2 = 0;
921                 for (j = 0; j < n; j++)
922                 {
923                     if (j == j1) continue;
924                     m[i-1][j2] = a[i][j];
925                     j2++;
926                 }
927             }
928             
929             // sum (+/-)cofactor * minor  
930             d = d + pow(-1.0, j1)*a[0][j1]*determinant( m, n-1 );
931         }
932     }
933
934     return d;
935 }
936
937
938
939
940 //-------------------------------------------------------------------
941 //-------------------------------------------------------------------
942 //-------------------------------------------------------------------
943
944 vtkInteractorStylePlane2D::vtkInteractorStylePlane2D()
945 {
946         _stateRotate=false;
947 }
948 //---------------------------------------------------------------------------
949 vtkInteractorStylePlane2D::~vtkInteractorStylePlane2D()
950 {
951 }
952
953 //---------------------------------------------------------------------------
954 bool vtkInteractorStylePlane2D::GetStateRotate()
955 {
956         return _stateRotate;
957 }
958
959 //---------------------------------------------------------------------------
960 bool  vtkInteractorStylePlane2D::OnLeftButtonDown()  // vitual
961 {
962         _stateRotate = true;
963         _fordwareX = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];
964         _fordwareY = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
965         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView());
966         vtkplane2Dview->RotationStart();
967
968         return true;
969 }
970
971 //---------------------------------------------------------------------------
972 bool vtkInteractorStylePlane2D::OnLeftButtonUp() // virtual
973 {
974         if (_stateRotate==true)
975         {
976                 _stateRotate = false;
977                 vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView());
978                 vtkplane2Dview->ResetBack();
979 //              this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
980         }
981
982         return true;
983 }
984
985 //---------------------------------------------------------------------------
986 bool  vtkInteractorStylePlane2D::OnRightButtonUp()  // virtual
987 {
988         if (_stateRotate==true){
989                 //vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView()); // JPRx
990
991 // EED Borrame
992 //              vtkplane2Dview->RotationEnd();
993
994                 _stateRotate = false;
995         }
996
997         return true;
998 }
999 //---------------------------------------------------------------------------
1000 bool  vtkInteractorStylePlane2D::OnMouseMove () // virtual 
1001 {
1002         bool ok_v, ok_ang;
1003         if (_stateRotate==true){
1004                 ok_v=false;
1005                 ok_ang=false;
1006                 if (_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==1)
1007                 {
1008                         ok_v=true;
1009                 }
1010                 if (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==1)
1011                 {
1012                         ok_ang=true;
1013                 }
1014             int fx = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];
1015         int fy = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
1016                 vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView());
1017                 vtkplane2Dview->RotationDrag( fx - _fordwareX , fy - _fordwareY , ok_v , ok_ang);
1018                 this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
1019         } 
1020         return true;
1021 }
1022 //-------------------------------------------------------------------
1023 bool vtkInteractorStylePlane2D::OnLeftDClick() // virtual
1024 {
1025         int fx = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];
1026         int fy = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
1027         double xx=fx;
1028         double yy=fy;
1029         double zz=0;
1030
1031         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView());
1032         vtkMPRBaseData *vtkmprbasedata = vtkplane2Dview->GetVtkmprbasedata();
1033
1034         vtkplane2Dview->TransfromeCoordViewWorld2(xx,yy,zz);
1035
1036         vtkmprbasedata->SetX( xx );
1037         vtkmprbasedata->SetY( yy );
1038         vtkmprbasedata->SetZ( zz );
1039         this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
1040
1041         return true;
1042 }
1043 //-------------------------------------------------------------------
1044 //-------------------------------------------------------------------
1045 //-------------------------------------------------------------------
1046
1047 vtkPlane2DView::vtkPlane2DView( wxWindow *parent)
1048 : wxVtk2DBaseView(parent)
1049 {
1050
1051         _backX                                  =       -99999;
1052         _backY                                  =       -99999;
1053         _backZ                                  =       -99999;
1054
1055         _backOrient[0]                  =       -99999;
1056         _backOrient[1]                  =       -99999;
1057         _backOrient[2]                  =       -99999;
1058         _backOrient[3]                  =       -99999;
1059
1060         _active                                 =   true;
1061         _mip_visualization              =       true;
1062         _mip_width                              =       2;
1063
1064     _transform1                         =       vtkTransform::New();
1065     _transform2                         =       vtkTransform::New();
1066         _transform1->Identity();
1067         _transform2->Identity();
1068
1069         _sizeIma                                =       200;
1070
1071         _pSource                                =       NULL;
1072         _3Dslices                               =       NULL;
1073         _stPoints                               =       NULL;
1074         _change                                 =       NULL;
1075         _imageResult                    =       NULL;
1076
1077         // line horizontal
1078     _pts                        = NULL;
1079     _lineActor          = NULL;
1080         _lineMapper             = NULL;
1081         _pd                             = NULL;
1082
1083         _interactorstyleplane2D =       false;
1084 }
1085 //-------------------------------------------------------------------
1086 vtkPlane2DView::~vtkPlane2DView()
1087 {
1088         ResetPlane();
1089
1090         // Horizontal Line
1091     if (_pts            != NULL)        {       _pts                    -> Delete(); }
1092     if (_lineActor      != NULL)        {       _lineActor              -> Delete(); }
1093     if (_lineMapper     != NULL)        {       _lineMapper             -> Delete(); }
1094     if (_pd                     != NULL)        {       _pd                             -> Delete(); }
1095
1096         _transform1             -> Delete();
1097         _transform2             -> Delete();
1098 }
1099
1100 //-------------------------------------------------------------------
1101 void vtkPlane2DView::ResetBack()
1102 {
1103                 _backX=-1;
1104                 _backY=-1;
1105                 _backZ=-1;
1106                 _backOrient[0]=-1;
1107                 _backOrient[1]=-1;
1108                 _backOrient[2]=-1;
1109                 _backOrient[3]=-1;
1110 }
1111
1112 //-------------------------------------------------------------------
1113 void vtkPlane2DView::ResetPlane(){
1114         if (_pSource    !=NULL) { _pSource      -> Delete();    }
1115         if (_3Dslices   !=NULL) { _3Dslices     -> Delete();    }
1116         if (_stPoints   !=NULL) { _stPoints     -> Delete();    }
1117         if (_change             !=NULL) { _change       -> Delete();    }
1118 }
1119 //-------------------------------------------------------------------
1120 vtkMPRBaseData *vtkPlane2DView::GetVtkmprbasedata()
1121 {
1122         return (vtkMPRBaseData*)GetVtkBaseData();
1123 }
1124
1125 //-------------------------------------------------------------------
1126 void vtkPlane2DView::SetPSource(int sizeIma){
1127         int dimIma      = sizeIma; 
1128
1129         double x = GetVtkmprbasedata()->GetX();
1130         double y = GetVtkmprbasedata()->GetY();
1131         double z = GetVtkmprbasedata()->GetZ();
1132
1133         double spc[3];
1134         vtkImageData *imagedata = GetVtkmprbasedata()->GetImageData();
1135         imagedata->GetSpacing(spc);
1136         x=x*spc[0];
1137         y=y*spc[1];
1138         z=z*spc[2];
1139
1140
1141         vtkMPRBaseData  *mprbasedata = (vtkMPRBaseData*)this->GetVtkBaseData();
1142         vtkTransform    *transform       = mprbasedata->GetTransformOrientation();
1143
1144         double in[3];  // temp
1145         double pA[3];
1146         double pB[3];
1147         in[0]=1;                in[1]=0;                        in[2]=0;
1148         transform->TransformPoint(in,_n);
1149
1150         in[0]=0;        in[1]=dimIma-1;         in[2] = 0;
1151         transform->TransformPoint(in,pA);
1152
1153         in[0]=0;        in[1]=0;                in[2]=dimIma-1;
1154         transform->TransformPoint(in,pB);
1155
1156     _pSource -> SetPoint1( pA   );
1157     _pSource -> SetPoint2( pB   );
1158
1159         _pSource -> SetOrigin( 0        , 0             , 0             );
1160     _pSource -> SetResolution( sizeIma-1 , sizeIma -1 );
1161         _pSource -> Update();
1162         _pSource -> SetCenter( x, y, z );
1163     _pSource -> SetNormal( _n );
1164     _pSource -> Update( );
1165
1166 // EED Borrame
1167 //      transform->Delete();
1168
1169 }
1170
1171 //-------------------------------------------------------------------
1172 void vtkPlane2DView::ExtractPlane() 
1173 {
1174
1175         double x = GetVtkmprbasedata()->GetX();
1176         double y = GetVtkmprbasedata()->GetY();
1177         double z = GetVtkmprbasedata()->GetZ();
1178
1179         double spc[3];
1180         vtkImageData *imagedata = GetVtkmprbasedata()->GetImageData();
1181         imagedata->GetSpacing(spc);
1182         x=x*spc[0];
1183         y=y*spc[1];
1184         z=z*spc[2];
1185
1186         vtkTransform *transform = GetVtkmprbasedata()->GetTransformOrientation();
1187         double orientation[4];
1188         transform->GetOrientationWXYZ(orientation);
1189
1190         bool okOrientation=true;
1191         if ((orientation[0]!=_backOrient[0]) || (orientation[1]!=_backOrient[1]) ||
1192                 (orientation[2]!=_backOrient[2]) || (orientation[3]!=_backOrient[3]))
1193         {
1194                 okOrientation=false;
1195         }
1196
1197         bool okPosicion=true;
1198         if ( (x!=_backX) || (y!=_backY) || (z!=_backZ) )
1199         {
1200                 okPosicion=false;
1201         }
1202
1203         if ((okPosicion==false) || (okOrientation==false) ) {
1204                 if (_active==true){
1205
1206                         bool ok = false;
1207
1208                         if ( _mip_visualization==true )
1209                         {
1210                                 if (_interactorstyleplane2D!=NULL)
1211                                 {
1212                                         if (_interactorstyleplane2D->GetStateRotate()==false )
1213                                         {
1214                                                 ok=true;
1215                                         }
1216                                 }
1217                         }
1218 //                      ok=true;
1219
1220                         if (ok==true)
1221                         {
1222                                 Extract_MIP_PlaneVTK();
1223                         } else {
1224                                 Extract_One_PlaneVTK();
1225                         } // ok
1226
1227                 } // active
1228                 _backX=x;
1229                 _backY=y;
1230                 _backZ=z;
1231                 _backOrient[0]=orientation[0];
1232                 _backOrient[1]=orientation[1];
1233                 _backOrient[2]=orientation[2];
1234                 _backOrient[3]=orientation[3];
1235         } //okPosition okOrientation
1236 }
1237
1238 //-------------------------------------------------------------------
1239
1240 void vtkPlane2DView::Extract_One_PlaneVTK()
1241 {
1242         vtkImageData *imagedata = GetVtkmprbasedata()->GetImageData();
1243         SetPSource(_sizeIma);
1244         _3Dslices -> SetInput( ( vtkDataSet* )_pSource->GetOutput( ) );
1245         _3Dslices -> SetSource( imagedata );
1246         _3Dslices -> Update( );
1247         _stPoints -> GetPointData( )->SetScalars(  _3Dslices->GetOutput()->GetPointData()->GetScalars()  );
1248         _stPoints -> SetDimensions( _sizeIma, _sizeIma, 1 );
1249         _stPoints -> SetScalarType( imagedata->GetScalarType() );
1250         _stPoints -> SetScalarTypeToShort();
1251         _stPoints -> Update();
1252 //      _change   -> SetInput( _stPoints );  
1253 //      _change   -> Update();    //important
1254         _imageViewer2XYZ->GetVtkImageViewer2()->SetInput ( _stPoints );
1255 //      _imageViewer2XYZ->GetVtkImageViewer2()->SetInput ( _change->GetOutput() );
1256         //      vtkImageActor *imageActor = _imageViewer2XYZ->GetVtkImageViewer2()->GetImageActor();
1257 }
1258
1259 //-------------------------------------------------------------------
1260
1261 void vtkPlane2DView::Extract_MIP_PlaneVTK( /*double heightDefinition*/ )
1262 {
1263
1264         int mipWidth;
1265         double sp;
1266         int sizeWidth = (_mip_width*2)+1 ;
1267         int deltaPixel;
1268         int iWidth,itmp,tmpSizeWith;
1269
1270         double spc[3];
1271         vtkImageData *imagedata = GetVtkmprbasedata()->GetImageData();
1272         SetPSource(_sizeIma);
1273         imagedata->GetSpacing(spc);
1274
1275         bool heightDefinition=false;
1276         if (_mip_width<3)
1277         {
1278                 heightDefinition=true;
1279         }
1280
1281         if (heightDefinition==true)
1282         {
1283                 mipWidth        =       _mip_width;
1284                 sp                      =       spc[0];
1285                 deltaPixel      =       1;
1286         } else {
1287                 mipWidth        =       2;
1288                 tmpSizeWith =   (mipWidth*2) + 1;
1289                 sp                      =       (spc[0]*sizeWidth)/tmpSizeWith;
1290                 sizeWidth       =       tmpSizeWith;
1291                 deltaPixel      =       4;
1292         }
1293
1294
1295
1296         std::vector< vtkProbeFilter* > slicesLST;
1297
1298         _pSource->Push( -mipWidth * sp );
1299         _pSource->Update();
1300
1301         for ( iWidth=0 ; iWidth<sizeWidth ; iWidth++ )
1302         {       
1303                 vtkProbeFilter *slice = vtkProbeFilter::New();
1304                 slice -> SetInput( ( vtkDataSet* )_pSource->GetOutput( ) );
1305                 slice -> SetSource( imagedata );
1306                 slice -> Update( );
1307                 slicesLST.push_back( slice );
1308                 _pSource->Push( sp );
1309         }
1310         
1311         if (_imageResult ==NULL)
1312         {
1313                 _imageResult = vtkImageData::New();
1314                 _imageResult -> SetDimensions(_sizeIma,_sizeIma,1);
1315                 _imageResult -> SetSpacing(1,1,1);
1316                 _imageResult -> SetScalarType( imagedata->GetScalarType() );
1317                 _imageResult -> SetExtent(0,_sizeIma-1,0,_sizeIma-1,0,0);
1318                 _imageResult -> SetWholeExtent(0,_sizeIma-1,0,_sizeIma-1,0,0);
1319                 _imageResult -> AllocateScalars();
1320                 _imageResult -> Update();
1321         }
1322
1323         unsigned short *pTemp;
1324         unsigned short *pResult;
1325         pResult = (unsigned short*)_imageResult->GetScalarPointer( 0 , 0 , 0 ); 
1326
1327         int iPixels , sizePixels = _sizeIma*_sizeIma;
1328         for(iPixels=0 ; iPixels<sizePixels ; iPixels=iPixels+deltaPixel)
1329         {
1330
1331                 pTemp = (unsigned short*)slicesLST[0]->GetOutput()->GetPointData()->GetScalars()->GetVoidPointer(0);
1332
1333                 pResult = (unsigned short*)_imageResult->GetScalarPointer( 0 , 0 , 0 ); 
1334                 pResult[iPixels] = pTemp[iPixels];
1335
1336                 for (iWidth=1;iWidth<sizeWidth;iWidth++)
1337                 {
1338                         pTemp = (unsigned short*)slicesLST[iWidth]->GetOutput()->GetPointData()->GetScalars()->GetVoidPointer(0);
1339
1340                         if (pResult[iPixels]< pTemp[iPixels])
1341                         {
1342                                 pResult[iPixels] = pTemp[iPixels];
1343                         }
1344                 }
1345
1346                 if (deltaPixel!=1)
1347                 {
1348                         for (itmp=1;itmp<deltaPixel;itmp++)
1349                         {
1350                                 pResult[iPixels+itmp] = pResult[iPixels];
1351                         }
1352                 }
1353
1354         }
1355
1356         for (iWidth=0;iWidth<sizeWidth;iWidth++)
1357         {       
1358                 slicesLST[iWidth]->Delete();
1359         }
1360
1361         _imageResult->Modified();
1362         _imageViewer2XYZ->GetVtkImageViewer2()->SetInput ( _imageResult );
1363
1364 }
1365
1366 //-------------------------------------------------------------------
1367 void vtkPlane2DView::Configure( )
1368 {
1369         wxVtk2DBaseView::Configure(false);
1370
1371         HorizontalLine();
1372 // Borrame
1373 //      CircleLine();
1374
1375         _pSource         = vtkPlaneSource::New( );
1376     _3Dslices    = vtkProbeFilter::New( ) ;
1377         _stPoints        = vtkStructuredPoints::New( );
1378         _change          = vtkImageChangeInformation::New();
1379
1380         wxVTKRenderWindowInteractor *iren               = GetWxVTKRenderWindowInteractor();
1381         ExtractPlane();
1382 //      SetActive(false);
1383         _imageViewer2XYZ -> GetVtkImageViewer2()        -> SetupInteractor ( iren );
1384
1385         SetInteractorStyleImage( vtkInteractorStyleBaseView2D::New() );
1386
1387         _interactorstyleplane2D = new vtkInteractorStylePlane2D();
1388         GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _interactorstyleplane2D );
1389
1390         vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
1391         
1392         camera->SetViewUp               (       0                       ,       1                               ,       0       );
1393         camera->SetPosition             ((0+_sizeIma)/2 , (0+_sizeIma)/2        , 10000 ); 
1394         
1395         camera->SetFocalPoint   ((0+_sizeIma)/2 , (0+_sizeIma)/2        ,       0       ); 
1396         camera->SetClippingRange(0.01, 100000);
1397         camera->ComputeViewPlaneNormal();
1398         camera->SetParallelScale( _sizeIma/3.0 );
1399
1400         // text information over the graphic window
1401         _vtkInfoTextImage                                               = new vtkInfoTextImage();
1402         _vtkInfoTextImageInteractorPlane2D              = new vtkInfoTextImageInteractorPlane2D();
1403         _vtkInfoTextImage->SetWxVtk2DBaseView(this);
1404         _vtkInfoTextImage->SetMarImageData(  GetVtkmprbasedata()->GetMarImageData() );
1405         _vtkInfoTextImageInteractorPlane2D->SetModelVtkInfoTextImage(_vtkInfoTextImage);        
1406         _vtkInfoTextImage->Configure();
1407         this->GetInteractorStyleBaseView()->AddInteractorStyleMaracas(_vtkInfoTextImageInteractorPlane2D);
1408
1409
1410 }
1411
1412 //-------------------------------------------------------------------
1413 void vtkPlane2DView::HorizontalLine()
1414 {
1415 // Axe Horizontal
1416         _pts = vtkPoints::New();
1417         _pts->SetNumberOfPoints(2);
1418         _pts->SetPoint(0, -1000 , -1000 , -1000 );
1419         _pts->SetPoint(1,  1000 ,  1000 ,  1000 );
1420         vtkCellArray *lines = vtkCellArray::New();
1421         lines->InsertNextCell(2);
1422         lines->InsertCellPoint(0);
1423         lines->InsertCellPoint(1);
1424         _pd = vtkPolyData::New();
1425     _pd->SetPoints( _pts );
1426     _pd->SetLines( lines );
1427         lines->Delete();  //do not delete lines ??
1428         _lineActor                                      =       vtkActor::New();
1429     _lineMapper                                 =       vtkPolyDataMapper::New();
1430         _lineMapper->SetInput(_pd);
1431         _lineMapper->ImmediateModeRenderingOn();
1432         _lineActor->SetMapper(_lineMapper);
1433         _lineActor->GetProperty()->BackfaceCullingOn();
1434         _lineActor->GetProperty()->SetDiffuseColor(0,0,1);
1435         _lineActor->GetProperty()->SetLineWidth(2);
1436         _lineActor->GetProperty()->SetOpacity(0);
1437     _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineActor );
1438 }
1439
1440 //-------------------------------------------------------------------
1441 void vtkPlane2DView::RotationStart()
1442 {
1443         vtkMPRBaseData  *mprbasedata = (vtkMPRBaseData*)this->GetVtkBaseData();
1444         vtkTransform    *transform       = mprbasedata->GetTransformOrientation();
1445         _transform1->SetMatrix( transform->GetMatrix() );
1446 }
1447 //-------------------------------------------------------------------
1448 void vtkPlane2DView::RotationDrag(double vx, double vy, bool ok_v, bool ok_ang)
1449
1450         if (ok_ang==false)
1451         {
1452                 _ang =sqrt( vx*vx + vy*vy ) / 1.5;
1453         }
1454
1455         if (ok_v==false){
1456                 _vxb=-vy;
1457                 _vyb=vx;
1458         }
1459         _transform2->Identity();
1460         _transform2->RotateWXYZ(_ang,0,_vxb,_vyb);
1461
1462         vtkMPRBaseData  *mprbasedata = (vtkMPRBaseData*)this->GetVtkBaseData();
1463         vtkTransform *transform          =      vtkTransform::New();
1464         transform->Identity();
1465         transform->Concatenate(_transform1);
1466         transform->Concatenate(_transform2);
1467         mprbasedata->InitTransformOrientation(transform);
1468         transform->Delete();
1469
1470         // Refresh Horizontal Line
1471         _pts->SetPoint( 0 , (_sizeIma/2) - _vxb*2       , (_sizeIma/2) - _vyb*2 , 1 );
1472         _pts->SetPoint( 1 , (_sizeIma/2) + _vxb*2       , (_sizeIma/2) + _vyb*2 , 1 );
1473 //      RefreshCircleLine();
1474 }
1475
1476 //-------------------------------------------------------------------
1477 void vtkPlane2DView::Refresh(  )
1478 {
1479         ExtractPlane();
1480         wxVtkBaseView::Refresh();
1481 }
1482 //-------------------------------------------------------------------
1483 void vtkPlane2DView::SetImgSize( int imgSize )
1484 {
1485         _sizeIma = imgSize;
1486 }
1487 //-------------------------------------------------------------------
1488 int vtkPlane2DView::GetImgSize()
1489 {
1490         return _sizeIma;
1491 }
1492 //-------------------------------------------------------------------
1493 int     vtkPlane2DView::GetActualSlice()  // virtual 
1494 {
1495         _cx = GetVtkmprbasedata()->GetX();
1496         _cy = GetVtkmprbasedata()->GetY();
1497         _cz = GetVtkmprbasedata()->GetZ();
1498         return 0;
1499 }
1500
1501 //-------------------------------------------------------------------
1502
1503 bool vtkPlane2DView::GetMipVisualization()
1504 {
1505         return _mip_visualization;
1506 }
1507
1508 //-------------------------------------------------------------------
1509 int vtkPlane2DView::GetMipWidth()
1510 {
1511         return _mip_width;
1512 }
1513
1514 //-------------------------------------------------------------------
1515 void vtkPlane2DView::SetActualSlice(int slice)  // Virtual
1516 {
1517         double dir=(double)slice/3.0;
1518         GetVtkmprbasedata()->SetX( _cx + (_n[0]*dir) );
1519         GetVtkmprbasedata()->SetY( _cy + (_n[1]*dir) );
1520         GetVtkmprbasedata()->SetZ( _cz + (_n[2]*dir) );
1521 }
1522 //---------------------------------------------------------------------------
1523 vtkInteractorStylePlane2D       *vtkPlane2DView::GetInteractorstyleplane2D()
1524 {
1525         return this->_interactorstyleplane2D;
1526 }
1527 //---------------------------------------------------------------------------
1528 void vtkPlane2DView::SetActive(bool active)
1529 {
1530         _active = active;
1531 }
1532
1533 //---------------------------------------------------------------------------
1534
1535 void vtkPlane2DView::SetMipVisualization(bool ok)
1536 {
1537         _mip_visualization=ok;
1538 }
1539
1540 //---------------------------------------------------------------------------
1541
1542 void vtkPlane2DView::SetMipWidth(int value)
1543 {
1544         _mip_width=value;
1545 }
1546
1547 //---------------------------------------------------------------------------
1548 void vtkPlane2DView::SetVisibleLine(bool ok)
1549 {
1550         double opacity;
1551         if (ok==true)
1552         {
1553                 opacity=1;
1554         } else {
1555                 opacity=0;
1556         }
1557         _lineActor->GetProperty()->SetOpacity(opacity);
1558 }
1559 // ----------------------------------------------------------------------------
1560 void vtkPlane2DView::TransfromeCoordViewWorld2(double &X, double &Y, double &Z)
1561 {
1562         double spc[3];
1563         GetVtkmprbasedata()->GetImageData()->GetSpacing(spc);
1564
1565         double xx = X;
1566         double yy = Y;
1567         double zz = 0;
1568
1569         TransfromeCoordScreenToWorld(xx,yy,zz);
1570
1571
1572         vtkTransform *transf1 = vtkTransform::New();
1573         transf1->Identity();
1574         vtkTransform *transf2 = GetVtkmprbasedata()->GetTransformOrientation();
1575         transf1->Concatenate(transf2->GetMatrix());
1576         double in[4], out[4];
1577         double center = GetImgSize() / 2;
1578         in[0] = 0;
1579         in[1] = xx - center;
1580         in[2] = yy - center;
1581         in[3] = 0;
1582
1583         transf1->MultiplyPoint(in,out);
1584         transf1->Delete();
1585
1586         X = out[0] + GetVtkmprbasedata()->GetX() ;
1587         Y = out[1] + GetVtkmprbasedata()->GetY() ;
1588         Z = out[2] + GetVtkmprbasedata()->GetZ() ;
1589
1590 }
1591
1592 //-------------------------------------------------------------------
1593 //-------------------------------------------------------------------
1594 //-------------------------------------------------------------------
1595 vtkInfoTextImageInteractorPlane2D::vtkInfoTextImageInteractorPlane2D()
1596 {
1597 }
1598 //-------------------------------------------------------------------
1599 vtkInfoTextImageInteractorPlane2D::~vtkInfoTextImageInteractorPlane2D()
1600 {
1601 }
1602 //-------------------------------------------------------------------
1603 bool vtkInfoTextImageInteractorPlane2D::OnMouseMove()
1604 {
1605         int X,Y;
1606         wxVTKRenderWindowInteractor *wxVTKiren;
1607         wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
1608         wxVTKiren->GetEventPosition(X,Y);
1609
1610         int z = (int) (_vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetVtkBaseData()->GetZ());
1611         double xx=X,yy=Y,zz=z;
1612
1613 // --> dif
1614         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)_vtkInteractorStyleBaseView->GetWxVtk2DBaseView();
1615         vtkplane2Dview->TransfromeCoordViewWorld2(xx,yy,zz);
1616
1617         GetVtkInfoTextImage()->PutWindowLevel();
1618         GetVtkInfoTextImage()->PutColorLevel();
1619         GetVtkInfoTextImage()->PutPosition( (int)xx , (int)yy , (int)zz );
1620         GetVtkInfoTextImage()->PutPixelIntensity( (int)xx , (int)yy , (int)zz );
1621
1622         this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
1623         return true;
1624 }
1625
1626 // ----------------------------------------------------------------------------
1627 // ----------------------------------------------------------------------------
1628 // ----------------------------------------------------------------------------
1629 manualViewPerpPlaneContour::manualViewPerpPlaneContour()
1630 {
1631 }
1632 // ----------------------------------------------------------------------------
1633 manualViewPerpPlaneContour::~manualViewPerpPlaneContour()
1634 {
1635 }
1636
1637
1638 // ----------------------------------------------------------------------------
1639 manualViewPerpPlaneContour * manualViewPerpPlaneContour :: Clone()
1640 {
1641         manualViewPerpPlaneContour * clone = new manualViewPerpPlaneContour();
1642         CopyAttributesTo(clone);
1643         return clone;
1644 }
1645
1646 // ---------------------------------------------------------------------------
1647
1648 void manualViewPerpPlaneContour::CopyAttributesTo( manualViewPerpPlaneContour * cloneObject)
1649 {
1650         // Fathers object
1651         manualViewContour::CopyAttributesTo(cloneObject);
1652 }
1653
1654
1655
1656
1657 // ----------------------------------------------------------------------------
1658 void manualViewPerpPlaneContour::UpdateViewPoint(int id)
1659 {  // virtual
1660         double x,y,z;
1661         manualPoint *mp = _manContModel->GetManualPoint(id);
1662         x = mp->GetX();
1663         y = mp->GetY();
1664         z = mp->GetZ();
1665         FilterCordinateXYZ(x,y,z);
1666
1667         _lstViewPoints[id]->SetPositionXY( x , y ,GetRange(), z );
1668         if ((z>=-1) && (z<=1))
1669         {
1670                 _lstViewPoints[id]->GetVtkActor()->VisibilityOn();
1671         } else {
1672                 _lstViewPoints[id]->GetVtkActor()->VisibilityOff();
1673         }
1674 }
1675 // ----------------------------------------------------------------------------
1676 void manualViewPerpPlaneContour::FilterCordinateXYZ (double &x, double &y, double &z)
1677 {
1678         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)( this->GetWxVtkBaseView() );
1679         vtkMPRBaseData *vtkmprbasedata = vtkplane2Dview->GetVtkmprbasedata();
1680         vtkTransform *transf1 = vtkTransform::New();
1681         vtkTransform *transf2 = vtkmprbasedata->GetTransformOrientation();
1682         transf1->SetMatrix( transf2->GetMatrix() ); 
1683         transf1->Inverse();
1684
1685         double in[4], out[4];
1686         double center = vtkplane2Dview->GetImgSize() / 2;
1687
1688         in[0] = x - vtkmprbasedata->GetX();
1689         in[1] = y - vtkmprbasedata->GetY();
1690         in[2] = z - vtkmprbasedata->GetZ();
1691         in[3] = 0;
1692
1693         transf1->MultiplyPoint(in,out);
1694         z = out[0];
1695         x = out[1]+center;
1696         y = out[2]+center;
1697
1698         double spc[3];
1699         this->GetWxVtkBaseView()->GetSpacing(spc);
1700         x = x / spc[0];
1701         y = y / spc[1];
1702         z = z / spc[2];
1703
1704         transf1->Delete();
1705 }
1706
1707 // ----------------------------------------------------------------------------
1708 void manualViewPerpPlaneContour::TransfromeCoordViewWorld( double &X,double &Y,double &Z,int type )
1709 {
1710         Z = 0;
1711         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)( this->GetWxVtkBaseView() );
1712         vtkplane2Dview->TransfromeCoordViewWorld2(X,Y,Z);
1713 }
1714
1715
1716 // ----------------------------------------------------------------------------
1717 void manualViewPerpPlaneContour::RefreshContour() // virtual
1718 {
1719 //      manualViewContour::RefreshContour();
1720
1721         double pp1[3];
1722         double pp2[3];
1723         double u;
1724                 
1725 // JSTG 25-02-08 ----------------------------------------------------------
1726 //              tt;
1727 //--------------------------------------------------------
1728
1729         double pp[3];
1730         double ppB[3];
1731         double ppC[3];
1732         ppB[0] = 999999;
1733         double dist,distMin = 99999999;
1734
1735         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)( this->GetWxVtkBaseView() );
1736         double center = vtkplane2Dview->GetImgSize() / 2;
1737
1738         int i,np,nps;
1739         np              = GetNumberOfPoints( );
1740
1741 //JSTG 25-02-08 ------------------------------------------
1742         //double t,delta;
1743     //nps               = GetNumberOfPointsSpline(); 
1744         nps = _manContModel->GetNumberOfPointsSpline();
1745         //delta = ( double ) ( np  ) / ( double ) ( nps-1  );
1746         _manContModel->UpdateSpline();
1747 //--------------------------------------------------------
1748
1749         if ( np >= 2 )
1750         {
1751                 for( i = 0; i < nps; i++ ) 
1752                 {
1753 // JSTG 25-02-08 ----------------------------------------------------------
1754                         //t     = delta * (double)i ;
1755                         //tt    = delta * (double)(i+1) ;
1756                         //_manContModel->GetSplinePoint(t ,pp1[0],pp1[1],pp1[2]);
1757                         //_manContModel->GetSplinePoint(tt,pp2[0],pp2[1],pp2[2]);
1758                         _manContModel->GetSpline_i_Point(i ,&pp1[0],&pp1[1],&pp1[2]);
1759                         _manContModel->GetSpline_i_Point(i+1,&pp2[0],&pp2[1],&pp2[2]);
1760 //--------------------------------------------------------------------------
1761                         FilterCordinateXYZ(pp1[0],pp1[1],pp1[2]);
1762                         FilterCordinateXYZ(pp2[0],pp2[1],pp2[2]);
1763                         if (pp2[2]*pp1[2]<=0)
1764                         {
1765                                 if (pp1[2]-pp2[2]!=0) { 
1766                                         u = -pp2[2] / (pp1[2]-pp2[2]);
1767                                 } else  {
1768                                         u=9999999;
1769                                 }
1770                                 pp[0]    = ( pp1[0]-pp2[0] )*u + pp2[0];
1771                                 pp[1]    = ( pp1[1]-pp2[1] )*u + pp2[1];
1772                                 pp[2]    = ( pp1[2]-pp2[2] )*u + pp2[2];
1773                                 ppC[0] = pp[0] - center;
1774                                 ppC[1] = pp[1] - center;
1775                                 ppC[2] = pp[2] ;
1776                                 dist = sqrt( ppC[0]*ppC[0] + ppC[1]*ppC[1] + ppC[2]*ppC[2] );
1777                                 if (dist<distMin)
1778                                 {
1779                                         distMin=dist;
1780                                         ppB[0] = pp[0];
1781                                         ppB[1] = pp[1];
1782                                         ppB[2] = pp[2];
1783                                 }
1784                         }
1785
1786                 }// for 
1787         } else {
1788                         _pts->SetPoint(0, 0 , 0 , 0);   
1789                         _pts->SetPoint(1, 0 , 0 , 0);   
1790         } // if
1791
1792 //EED 27 sep 2006
1793         ppB[0]=ppB[0]*_spc[0];
1794         ppB[1]=ppB[1]*_spc[1];
1795
1796         _pts->SetPoint( 0, ppB[0]   , ppB[1]+1 , 1 );   
1797         _pts->SetPoint( 1, ppB[0]   , ppB[1]-1 , 1 );   
1798         _pts->SetPoint( 2, ppB[0]   , ppB[1]   , 1 );   
1799         _pts->SetPoint( 3, ppB[0]-1 , ppB[1]   , 1 );   
1800         _pts->SetPoint( 4, ppB[0]+1 , ppB[1]   , 1 );   
1801
1802
1803         for( i = 5; i < nps; i++ ) 
1804         {
1805                 _pts->SetPoint( i, ppB[0] , ppB[1] , 1 );       
1806         }
1807
1808 }
1809
1810 //---------------------------------------------------------------------------
1811 bool manualViewPerpPlaneContour::ifTouchContour( int x, int y, int z)
1812 {
1813         bool ok=false;
1814         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)( this->GetWxVtkBaseView() );
1815         double X=x;
1816         double Y=y;
1817         double Z=z;
1818         vtkplane2Dview->TransfromeCoordScreenToWorld(X,Y,Z);
1819         double ppA[3];
1820         _pts->GetPoint(0, ppA);
1821         if (sqrt( (ppA[0]-X)*(ppA[0]-X) + (ppA[1]-Y)*(ppA[1]-Y) ) <=2)
1822         {
1823                 ok = true;
1824         }
1825         return ok;
1826 }
1827
1828
1829 //---------------------------------------------------------------------------
1830 //---------------------------------------------------------------------------
1831 //---------------------------------------------------------------------------
1832 vtkInteractorStyleMPRView::vtkInteractorStyleMPRView()
1833 {
1834         _stateMoveAxisX = false;
1835         _stateMoveAxisY = false;
1836         _stateMoveAxisZ = false;
1837 }
1838 //---------------------------------------------------------------------------
1839 vtkInteractorStyleMPRView::~vtkInteractorStyleMPRView()
1840 {
1841 }
1842
1843
1844 //---------------------------------------------------------------------------
1845 bool  vtkInteractorStyleMPRView::OnLeftDClick () // virtual
1846 {
1847         wxVtkMPR2DView *wxvtkmpr2Dview = (wxVtkMPR2DView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView());
1848         double x = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];
1849         double y = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
1850         double z = 1;
1851         _vtkInteractorStyleBaseView->TransformCoordinate(x,y,z);            
1852         wxvtkmpr2Dview->MoveX(x,y,z);
1853         wxvtkmpr2Dview->MoveY(x,y,z);
1854         wxvtkmpr2Dview->MoveZ(x,y,z);
1855         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
1856         wxvtkmpr2Dview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
1857         wxCommandEvent newevent2(wxEVT_COMMAND_MENU_SELECTED,12122);  // Doble click
1858         wxvtkmpr2Dview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent2);
1859
1860         return true;
1861 }
1862 //---------------------------------------------------------------------------
1863 bool  vtkInteractorStyleMPRView::OnLeftButtonDown () 
1864 {
1865         wxVtkMPR2DView *wxvtkmpr2Dview = (wxVtkMPR2DView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView());
1866         double x        = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];
1867         double y        = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
1868         double z        = 1;
1869         //double xx     = x;  // JPRx
1870         //double yy     = y;  // JPRx
1871         _vtkInteractorStyleBaseView->TransformCoordinate(x,y,z);            
1872
1873 /*EED Borrame
1874         if ((_xBack==xx) && (_yBack==yy))
1875         {
1876                 wxvtkmpr2Dview->MoveX(x,y,z);
1877                 wxvtkmpr2Dview->MoveY(x,y,z);
1878                 wxvtkmpr2Dview->MoveZ(x,y,z);
1879                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
1880                 wxvtkmpr2Dview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
1881                 wxCommandEvent newevent2(wxEVT_COMMAND_MENU_SELECTED,12122);  // Doble click
1882                 wxvtkmpr2Dview->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent2);
1883         }
1884
1885         _xBack=xx;      
1886         _yBack=yy;
1887 */
1888
1889         _stateMoveAxisX = wxvtkmpr2Dview->IfMouseTouchX(x,y,z);
1890         _stateMoveAxisY = wxvtkmpr2Dview->IfMouseTouchY(x,y,z);
1891         _stateMoveAxisZ = wxvtkmpr2Dview->IfMouseTouchZ(x,y,z);
1892
1893         return true;
1894 }
1895 //---------------------------------------------------------------------------
1896 bool  vtkInteractorStyleMPRView::OnLeftButtonUp () 
1897 {
1898         if (_stateMoveAxisX==true) 
1899         {
1900                 _stateMoveAxisX=false;
1901         }
1902         if (_stateMoveAxisY==true) 
1903         {
1904                 _stateMoveAxisY=false;
1905         }
1906         if (_stateMoveAxisZ==true) 
1907         {
1908                 _stateMoveAxisZ=false;
1909         }
1910         return true;
1911 }
1912 //---------------------------------------------------------------------------
1913 bool  vtkInteractorStyleMPRView::OnMouseMove () 
1914 {
1915         double x = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];
1916         double y = _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
1917
1918         double z=1;
1919         _vtkInteractorStyleBaseView->TransformCoordinate(x,y,z);            
1920         wxVtkMPR2DView *wxvtkmpr2Dview = (wxVtkMPR2DView*)(_vtkInteractorStyleBaseView->GetWxVtk2DBaseView());
1921 //      wxvtkmpr2Dview->TransfromeCoordViewWorld(x,y,z);            
1922
1923         wxvtkmpr2Dview->ChangeAxisColor(x,y,z);
1924
1925         if ((_stateMoveAxisX==true) || (_stateMoveAxisY==true)  || (_stateMoveAxisZ==true) )
1926         {
1927                 if (_stateMoveAxisX==true) 
1928                 {
1929                         wxvtkmpr2Dview-> MoveX(x,y,z);
1930                 }
1931                 if (_stateMoveAxisY==true) 
1932                 {
1933                         wxvtkmpr2Dview->MoveY(x,y,z);
1934                 }
1935                 if (_stateMoveAxisZ==true) 
1936                 {
1937                         wxvtkmpr2Dview->MoveZ(x,y,z);
1938                 }
1939
1940                 this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
1941         }
1942         return true;
1943 }
1944 //-------------------------------------------------------------------
1945 //-------------------------------------------------------------------
1946 //-------------------------------------------------------------------
1947 wxVtkMPR2DView::wxVtkMPR2DView( wxWindow *parent, int direction)
1948  :wxVtk2DBaseView(parent)
1949 {
1950         _backX                  = -99999;
1951         _backY                  = -99999;
1952         _backZ                  = -99999;
1953         _direction              = direction;
1954         _ptsA                   = NULL;
1955         _lineAActor             = NULL;
1956         _lineAMapper    = NULL;
1957         _pdA                    = NULL;
1958         _ptsB                   = NULL;
1959         _lineBActor             = NULL;
1960         _lineBMapper    = NULL;
1961         _pdB                    = NULL;
1962 }
1963
1964 //-------------------------------------------------------------------
1965 wxVtkMPR2DView::~wxVtkMPR2DView()
1966 {
1967         if (_ptsA!=NULL)        { _ptsA         -> Delete(); }
1968         if (_lineAActor!=NULL)  { _lineAActor   -> Delete(); }
1969         if (_lineAMapper!=NULL) { _lineAMapper  -> Delete(); }
1970         if (_pdA!=NULL)         { _pdA          -> Delete(); }
1971         if (_ptsB!=NULL)        { _ptsB         -> Delete(); }
1972         if (_lineBActor!=NULL)  { _lineBActor   -> Delete(); }
1973         if (_lineBMapper!=NULL) { _lineBMapper  -> Delete(); }
1974         if (_pdB!=NULL)         { _pdB          -> Delete(); }
1975 }
1976 //-------------------------------------------------------------------
1977 vtkMPRBaseData *wxVtkMPR2DView::GetVtkmprbasedata()
1978 {
1979         return (vtkMPRBaseData*)GetVtkBaseData();
1980 }
1981 //-------------------------------------------------------------------
1982 void wxVtkMPR2DView::Configure(){
1983         wxVtk2DBaseView::Configure();
1984
1985         _interactorstylemprview = new vtkInteractorStyleMPRView();
1986         GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _interactorstylemprview );
1987
1988         int x1,x2,y1,y2,z1,z2;
1989         GetVtkmprbasedata()     -> GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
1990
1991         double spc[3];
1992         vtkImageData* img =  GetVtkmprbasedata()->GetImageData();
1993         if(img!=NULL){
1994                 img->GetSpacing(spc);
1995                 x1 = (int)(x1*spc[0]);
1996                 y1 = (int)(y1*spc[1]);
1997                 z1 = (int)(z1*spc[2]);
1998
1999                 x2 = (int)(x2*spc[0]);
2000                 y2 = (int)(y2*spc[1]);
2001                 z2 = (int)(z2*spc[2]);
2002
2003                 _visibleAxis = true;
2004
2005         // Axe A
2006                 _ptsA = vtkPoints::New();
2007                 _ptsA->SetNumberOfPoints(2);
2008                 _ptsA->SetPoint(0, -1000        , -1000 , -1000 );
2009                 _ptsA->SetPoint(1,  1000        ,  1000 ,  1000 );
2010                 vtkCellArray *linesA;
2011                 linesA = vtkCellArray::New();
2012                 linesA->InsertNextCell(2);
2013                 linesA->InsertCellPoint(0);
2014                 linesA->InsertCellPoint(1);
2015                 _pdA = vtkPolyData::New();
2016                 _pdA->SetPoints( _ptsA );
2017                 _pdA->SetLines( linesA );
2018                 linesA->Delete();  //do not delete lines ??
2019                 _lineAActor                                             =       vtkActor::New();
2020                 _lineAMapper                                    =       vtkPolyDataMapper::New();
2021                 _lineAMapper->SetInput(_pdA);
2022                 _lineAMapper->ImmediateModeRenderingOn();
2023                 _lineAActor->SetMapper(_lineAMapper);
2024 //              _lineAActor->GetProperty()->BackfaceCullingOn();
2025                 _lineAActor->GetProperty()->SetDiffuseColor(1,0,0);
2026                 _lineAActor->GetProperty()->SetLineWidth(2);
2027                 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
2028
2029         // Axe B
2030                 _ptsB = vtkPoints::New();
2031                 _ptsB->SetNumberOfPoints(2);
2032                 _ptsB->SetPoint(0, -1000        , -1000 , -1000 );
2033                 _ptsB->SetPoint(1,  1000        ,  1000 ,  1000 );
2034                 vtkCellArray *linesB;
2035                 linesB = vtkCellArray::New();
2036                 linesB->InsertNextCell(2);
2037                 linesB->InsertCellPoint(0);
2038                 linesB->InsertCellPoint(1);
2039                 _pdB = vtkPolyData::New();
2040                 _pdB->SetPoints( _ptsB );
2041                 _pdB->SetLines( linesB );
2042                 linesB->Delete();  //do not delete lines ??
2043                 _lineBActor                                             =       vtkActor::New();
2044                 _lineBMapper                                    =       vtkPolyDataMapper::New();
2045                 _lineBMapper->SetInput(_pdB);
2046                 _lineBMapper->ImmediateModeRenderingOn();
2047                 _lineBActor->SetMapper(_lineBMapper);
2048 //              _lineBActor->GetProperty()->BackfaceCullingOn();
2049                 _lineBActor->GetProperty()->SetDiffuseColor(1,0,0);
2050                 _lineBActor->GetProperty()->SetLineWidth(2);
2051                 _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
2052
2053         
2054                 vtkCamera *camera =_imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->GetActiveCamera();
2055                 
2056 //EED 17Avril2009
2057 /*              
2058                 if (_direction==0) {
2059                         camera->SetViewUp               (   0   ,    -1         ,     0         );
2060                         camera->SetPosition             ( -10000,(y1+y2)/2      , (z1+z2)/2     ); 
2061                         camera->SetFocalPoint   (   0   , (y1+y2)/2     , (z1+z2)/2     );
2062                         camera->SetParallelScale( (z2-z1)/3.0 );
2063                 }
2064
2065                 if (_direction==1) { 
2066                         camera->SetViewUp               (       0               ,       0       ,       -1              );
2067                         camera->SetPosition             ((x1+x2)/2      , 10000 , (z1+z2)/2     ); 
2068                         camera->SetFocalPoint   ((x1+x2)/2      ,   0   , (z1+z2)/2     );
2069                         camera->SetParallelScale( (x2-x1)/3.0 );
2070                 }
2071
2072                 if (_direction==2) { 
2073                         camera->SetViewUp               (       0               ,       -1              ,       0       );
2074                         camera->SetPosition             ((x1+x2)/2      , (y1+y2)/2     , -10000); 
2075                         camera->SetFocalPoint   ((x1+x2)/2      , (y1+y2)/2     ,       0       ); 
2076                         camera->SetParallelScale( (x2-x1)/3.0 );
2077                 }
2078  */
2079
2080                 if (_direction==0) {
2081                         camera->SetViewUp               (   0   ,     1         ,     0         );
2082                         camera->SetPosition             (  10000,(y1+y2)/2      , (z1+z2)/2     ); 
2083                         camera->SetFocalPoint   (   0   , (y1+y2)/2     , (z1+z2)/2     );
2084                         camera->SetParallelScale( (z2-z1)/3.0 );
2085                 }
2086                 
2087                 if (_direction==1) { 
2088                         camera->SetViewUp               (       0               ,       0       ,       -1              );
2089                         camera->SetPosition             ((x1+x2)/2      , 10000 , (z1+z2)/2     ); 
2090                         camera->SetFocalPoint   ((x1+x2)/2      ,   0   , (z1+z2)/2     );
2091                         camera->SetParallelScale( (x2-x1)/3.0 );
2092                 }
2093                 
2094                 if (_direction==2) { 
2095                         camera->SetViewUp               (       0               ,       1               ,       0       );
2096                         camera->SetPosition             ((x1+x2)/2      , (y1+y2)/2     ,  10000); 
2097                         camera->SetFocalPoint   ((x1+x2)/2      , (y1+y2)/2     ,       0       ); 
2098                         camera->SetParallelScale( (x2-x1)/3.0 );
2099                 }
2100                 
2101                 
2102                 
2103         }
2104
2105 //      _imageViewer2XYZ->GetVtkImageViewer2()->SetColorWindow (160);
2106 //      _imageViewer2XYZ->GetVtkImageViewer2()->SetColorLevel (800);
2107
2108 }
2109
2110 void wxVtkMPR2DView::SetVisibleAxis(bool ok)
2111 {
2112         if (ok!=_visibleAxis)
2113         {
2114                 _visibleAxis=ok;
2115                 if (_visibleAxis==true)
2116                 {
2117                         _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineAActor );
2118                         _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineBActor );
2119                 }
2120                 if (_visibleAxis==false)
2121                 {
2122                         _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineAActor );
2123                         _imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->RemoveActor( _lineBActor );
2124                 }
2125
2126         }
2127 }
2128
2129 //-------------------------------------------------------------------
2130 void wxVtkMPR2DView::Refresh() 
2131 {
2132         //wxVtk2DBaseView::Refresh();
2133
2134
2135         //vtkImageViewer2 *IV2=_imageViewer2XYZ->GetVtkImageViewer2(); // JPRx
2136         //vtkCamera *camera = IV2->GetRenderer()->GetActiveCamera(); // JPRx
2137
2138
2139
2140         int x1,x2,y1,y2,z1,z2;
2141         GetVtkmprbasedata()->GetDimensionExtention(&x1,&x2,&y1,&y2,&z1,&z2);
2142         double spc[3];
2143         
2144         vtkImageData* img = GetVtkmprbasedata()->GetImageData();
2145         if(img!=NULL){
2146                 img->GetSpacing(spc);
2147                 x1 =  (int)(x1*spc[0]);
2148                 y1 =  (int)(y1*spc[1]);
2149                 z1 =  (int)(z1*spc[2]);
2150
2151                 x2 =  (int)(x2*spc[0]);
2152                 y2 =  (int)(y2*spc[1]);
2153                 z2 =  (int)(z2*spc[2]);
2154
2155                 int x = (int)(GetVtkmprbasedata()->GetX());
2156                 int y = (int)(GetVtkmprbasedata()->GetY());
2157                 int z = (int)(GetVtkmprbasedata()->GetZ());
2158
2159                 x =  (int)(x*spc[0]);
2160                 y =  (int)(y*spc[1]);
2161                 z =  (int)(z*spc[2]);
2162
2163
2164
2165                 if ((x!=_backX) || (y!=_backY) || (z!=_backZ)) {
2166
2167                         if (_direction==0) { 
2168                                 _imageViewer2XYZ->SetXSlice( (int)(GetVtkmprbasedata()->GetX()) ); 
2169                                 _ptsA->SetPoint(0, -x2, y1  , z );
2170                                 _ptsA->SetPoint(1, -x2, y2  , z );
2171                                 _ptsB->SetPoint(0, -x2, y   , z1);
2172                                 _ptsB->SetPoint(1, -x2, y   , z2);
2173                         }
2174                         if (_direction==1) { 
2175                                 _imageViewer2XYZ->SetYSlice( (int)(GetVtkmprbasedata()->GetY()) ); 
2176                             _ptsA->SetPoint(0, x1 , y2 , z );
2177                                 _ptsA->SetPoint(1, x2 , y2 , z );
2178                                 _ptsB->SetPoint(0, x  , y2 , z1);
2179                                 _ptsB->SetPoint(1, x  , y2 , z2);
2180                         }
2181                         if (_direction==2) { 
2182                                 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) ); 
2183                                 _imageViewer2XYZ->SetZSlice( (int)(GetVtkmprbasedata()->GetZ()) ); 
2184                         //      _ptsA->SetPoint(0, x1 , y , -z2 );
2185                         //      _ptsA->SetPoint(1, x2 , y , -z2 );
2186                         //      _ptsB->SetPoint(0, x  , y1, -z2 );
2187                         //      _ptsB->SetPoint(1, x  , y2, -z2 );
2188                                 
2189                                 _ptsA->SetPoint(0, x1 , y , z2 );
2190                                 _ptsA->SetPoint(1, x2 , y , z2 );
2191                                 _ptsB->SetPoint(0, x  , y1, z2 );
2192                                 _ptsB->SetPoint(1, x  , y2, z2 );
2193                         }
2194                         _backX=x;
2195                         _backY=y;
2196                         _backZ=z;
2197                 }
2198                 wxVtkBaseView::Refresh();
2199         }
2200 }
2201 //-------------------------------------------------------------------
2202 int wxVtkMPR2DView::GetActualSlice()   // virtual
2203 {
2204         int result;
2205         if (_direction==0) 
2206         { 
2207                 result = (int)(GetVtkmprbasedata()->GetX());
2208         }
2209         if (_direction==1) 
2210         { 
2211                 result = (int)(GetVtkmprbasedata()->GetY());
2212         }
2213         if (_direction==2) 
2214         { 
2215                 result = (int)(GetVtkmprbasedata()->GetZ());
2216         }
2217         return result;
2218 }
2219 //-------------------------------------------------------------------
2220 void wxVtkMPR2DView::SetActualSlice(int slice)   // virtual
2221 {
2222         if (_direction==0) 
2223         { 
2224                 GetVtkmprbasedata()->SetX(slice);
2225         }
2226         if (_direction==1) 
2227         { 
2228                 GetVtkmprbasedata()->SetY(slice);
2229         }
2230         if (_direction==2) 
2231         { 
2232                 GetVtkmprbasedata()->SetZ(slice);
2233         }
2234 }
2235 //-------------------------------------------------------------------
2236 bool wxVtkMPR2DView::IfMouseTouchX(double x, double y, double z)
2237 {
2238         double delta=5;
2239         bool result=false;
2240         if (_direction==0) 
2241         { 
2242         }
2243         if (_direction==1) 
2244         { 
2245                 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
2246                 {
2247                         result = true;
2248                 }
2249         }
2250         if (_direction==2) 
2251         { 
2252                 if (( x<GetVtkmprbasedata()->GetX()+delta ) && ( x>GetVtkmprbasedata()->GetX()-delta ))
2253                 {
2254                         result = true;
2255                 }
2256         }
2257         return result;
2258 }
2259 //-------------------------------------------------------------------
2260 bool wxVtkMPR2DView::IfMouseTouchY(double x, double y, double z)
2261 {
2262         double delta=5;
2263         bool result=false;
2264         if (_direction==0) 
2265         { 
2266                 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
2267                 {
2268                         result = true;
2269                 }
2270         }
2271         if (_direction==1) 
2272         { 
2273         }
2274         if (_direction==2) 
2275         { 
2276                 if (( y<GetVtkmprbasedata()->GetY()+delta ) && ( y>GetVtkmprbasedata()->GetY()-delta ))
2277                 {
2278                         result = true;
2279                 }
2280         }
2281         return result;
2282 }
2283 //-------------------------------------------------------------------
2284 bool wxVtkMPR2DView::IfMouseTouchZ(double x, double y, double z)
2285 {
2286         double delta=5;
2287         bool result=false;
2288         if (_direction==0) 
2289         { 
2290                 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
2291                 {
2292                         result = true;
2293                 }
2294         }
2295         if (_direction==1) 
2296         { 
2297                 if (( z<GetVtkmprbasedata()->GetZ()+delta ) && ( z>GetVtkmprbasedata()->GetZ()-delta ))
2298                 {
2299                         result = true;
2300                 }
2301         }
2302         if (_direction==2) 
2303         { 
2304         }
2305         return result;
2306 }
2307 //-------------------------------------------------------------------
2308 void wxVtkMPR2DView::MoveX(double x, double y, double z)
2309 {
2310         if (_direction==0) 
2311         { 
2312         }
2313         if (_direction==1) 
2314         { 
2315                 GetVtkmprbasedata()->SetX(x);
2316         }
2317         if (_direction==2) 
2318         { 
2319                 GetVtkmprbasedata()->SetX(x);
2320         }
2321 }
2322 //-------------------------------------------------------------------
2323 void wxVtkMPR2DView::MoveY(double x, double y, double z)
2324 {
2325         if (_direction==0) 
2326         { 
2327                 GetVtkmprbasedata()->SetY(y);
2328         }
2329         if (_direction==1) 
2330         { 
2331         }
2332         if (_direction==2) 
2333         { 
2334                 GetVtkmprbasedata()->SetY(y);
2335         }
2336 }
2337 //-------------------------------------------------------------------
2338 void wxVtkMPR2DView::MoveZ(double x, double y, double z)
2339 {
2340         if (_direction==0) 
2341         { 
2342                 GetVtkmprbasedata()->SetZ(z);
2343         }
2344         if (_direction==1) 
2345         { 
2346                 GetVtkmprbasedata()->SetZ(z);
2347         }
2348         if (_direction==2) 
2349         { 
2350         }
2351 }
2352 //-------------------------------------------------------------------
2353 void wxVtkMPR2DView::ChangeAxisColor(double x, double y, double z)
2354 {
2355         double c1r=1,c1g=1,c1b=0;
2356         double c2r=1,c2g=0,c2b=0;
2357
2358         if (_direction==0) 
2359         { 
2360                 if (IfMouseTouchY(x,y,z)==true)
2361                 {
2362                         _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
2363                 } else {
2364                         _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
2365                 }
2366                 if (IfMouseTouchZ(x,y,z)==true)
2367                 {
2368                         _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
2369                 } else {
2370                         _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
2371                 }
2372         }
2373
2374         if (_direction==1) 
2375         { 
2376                 if (IfMouseTouchX(x,y,z)==true)
2377                 {
2378                         _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
2379                 } else {
2380                         _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
2381                 }
2382                 if (IfMouseTouchZ(x,y,z)==true)
2383                 {
2384                         _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
2385                 } else {
2386                         _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
2387                 }
2388         }
2389
2390         if (_direction==2) 
2391         { 
2392                 if (IfMouseTouchX(x,y,z)==true)
2393                 {
2394                         _lineBActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
2395                 } else {
2396                         _lineBActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
2397                 }
2398                 if (IfMouseTouchY(x,y,z)==true)
2399                 {
2400                         _lineAActor->GetProperty()->SetDiffuseColor(c1r,c1g,c1b);
2401                 } else {
2402                         _lineAActor->GetProperty()->SetDiffuseColor(c2r,c2g,c2b);
2403                 }
2404         }
2405         Refresh();
2406 }
2407 //-------------------------------------------------------------------
2408 void wxVtkMPR2DView::TransfromeCoordViewWorld(double &X, double &Y, double &Z, int type) // virtual 
2409 {
2410         wxVtkBaseView::TransfromeCoordScreenToWorld(X,Y,Z,_direction);
2411
2412         if (_direction==0)
2413         {
2414                 X = ((vtkMPRBaseData*)GetVtkBaseData())->GetX();
2415         }
2416         if (_direction==1)
2417         {
2418                 Y = ((vtkMPRBaseData*)GetVtkBaseData())->GetY();
2419         }
2420         if (_direction==2)
2421         {
2422                 Z = ((vtkMPRBaseData*)GetVtkBaseData())->GetZ();
2423         }
2424 }
2425 //-------------------------------------------------------------------
2426 //-------------------------------------------------------------------
2427 //-------------------------------------------------------------------
2428 //void boxVolumeObserver::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) {  // virtual
2429 //      if (eventId==vtkCommand::StartInteractionEvent){
2430 //              _renWin->SetDesiredUpdateRate(10);
2431 //      }
2432 //      if (eventId==vtkCommand::InteractionEvent){
2433 //              _renWin->SetDesiredUpdateRate(0.001);
2434 //      }
2435 //      if (eventId==vtkCommand::EndInteractionEvent){
2436 //              vtkPlanes *planes = vtkPlanes::New();
2437 //              vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
2438 //              boxwidget->GetPlanes(planes);
2439 //              _volumeMapper->SetClippingPlanes(planes);
2440 //              planes -> Delete();
2441 //      }
2442 //}
2443
2444 //-------------------------------------------------------------------
2445 //void boxVolumeObserver::SetRenWin( vtkRenderWindow *renWin ){
2446 //      _renWin = renWin;
2447 //}
2448 //-------------------------------------------------------------------
2449 //void boxVolumeObserver::SetVolumeMapper(vtkVolumeRayCastMapper *volumeMapper){
2450 //      _volumeMapper = volumeMapper;
2451 //}
2452
2453
2454
2455 //-------------------------------------------------------------------
2456 //-------------------------------------------------------------------
2457 //-------------------------------------------------------------------
2458 // EED 9 fev 2007
2459 void boxSurfaceObserver::Execute(vtkObject *wdg, unsigned long eventId, void* calldata) {  // virtual
2460         vtkBoxWidget *boxwidget = reinterpret_cast<vtkBoxWidget*>(wdg);
2461         boxwidget->GetPlanes(_planes);
2462
2463         if ( _vtkVolumeRayCastMapper != NULL )
2464         {
2465                 _vtkVolumeRayCastMapper->RemoveAllClippingPlanes();
2466 //              vtkPlanes *planes = vtkPlanes::New();
2467 //              boxwidget->GetPlanes(planes);
2468 //              _vtkVolumeRayCastMapper->SetClippingPlanes(planes);
2469                 _vtkVolumeRayCastMapper->SetClippingPlanes(_planes);
2470         }
2471
2472 //      _actor->VisibilityOn();
2473
2474 }
2475 //-------------------------------------------------------------------
2476 void boxSurfaceObserver::SetPlanes(vtkPlanes *planes){
2477         _planes = planes;
2478 }
2479 //-------------------------------------------------------------------
2480 void boxSurfaceObserver::SetActor(vtkProp *actor){
2481         _actor = actor;
2482 }
2483
2484 //-------------------------------------------------------------------
2485 void boxSurfaceObserver::SetvtkVolumeRayCastMapper(vtkVolumeRayCastMapper *vtkvolumeraycastmapper)
2486 {
2487         _vtkVolumeRayCastMapper = vtkvolumeraycastmapper;
2488 }
2489
2490
2491 //-------------------------------------------------------------------
2492 //-------------------------------------------------------------------
2493 //-------------------------------------------------------------------
2494
2495 wxVtkMPR3DViewCntrlPanel::wxVtkMPR3DViewCntrlPanel(wxWindow *parent, wxVtkMPR3DView *wxvtkmpr3Dview )
2496 : wxPanel(parent, -1)
2497 {
2498
2499         wxPanel *panel  = this;
2500         _wxvtkmpr3Dview = wxvtkmpr3Dview;
2501
2502         /*int maxX = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionX();
2503         int maxY = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionY();
2504         int maxZ = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionZ();*/
2505
2506         int maxX = 1;
2507         int maxY = 1;
2508         int maxZ = 1;
2509
2510         wxCheckBox              *ckBoxX                 = new wxCheckBox(panel,-1,_T("X           "));
2511                                         _positionX              = new wxSlider(panel,-1,maxX/2,0,maxX, wxDefaultPosition, wxSize(150,40), wxSL_HORIZONTAL | wxSL_LABELS);
2512         wxCheckBox              *ckBoxY                 = new wxCheckBox(panel,-1,_T("Y           "));
2513                                         _positionY              = new wxSlider(panel,-1,maxY/2,0,maxY, wxDefaultPosition, wxSize(150,40), wxSL_HORIZONTAL | wxSL_LABELS);
2514         wxCheckBox              *ckBoxZ                 = new wxCheckBox(panel,-1,_T("Z           "));
2515                                         _positionZ              = new wxSlider(panel,-1,maxZ/2,0,maxZ, wxDefaultPosition, wxSize(150,40), wxSL_HORIZONTAL | wxSL_LABELS);
2516         wxButton                *btnColorTable  = new wxButton (panel, -1, _T("Edit Color Table") );
2517
2518         _ckBoxXYZ                       = new wxCheckBox(panel,-1,_T("XYZ                  "));
2519         _ckBoxPlane                     = new wxCheckBox(panel,-1,_T("Plane"));
2520
2521         ckBoxX->SetValue(false);
2522         ckBoxY->SetValue(false);
2523         ckBoxZ->SetValue(false);
2524         _ckBoxXYZ->SetValue(false);
2525         _ckBoxPlane->SetValue(false);
2526
2527         _positionX->SetSize(400,20);
2528         _positionY->SetSize(400,20);
2529         _positionZ->SetSize(400,20);
2530
2531         Connect(ckBoxX->GetId()                 , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisX   );
2532         Connect(_positionX->GetId()             , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionX              );
2533         Connect(ckBoxY->GetId()                 , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisY   );
2534         Connect(_positionY->GetId()             , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionY              );
2535         Connect(ckBoxZ->GetId()                 , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisZ   );
2536         Connect(_positionZ->GetId()             , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionZ              );
2537         Connect(btnColorTable->GetId()  , wxEVT_COMMAND_BUTTON_CLICKED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnEditColorTable );
2538
2539         Connect(_ckBoxXYZ->GetId()  , wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisXYZ );
2540         Connect(_ckBoxPlane->GetId(), wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisiblePlane   );
2541
2542
2543         wxFlexGridSizer *sizer   = new wxFlexGridSizer(1);
2544 //      wxBoxSizer *sizer        = new wxBoxSizer(wxVERTICAL);
2545
2546 //      wxBoxSizer *sizerH4 = new wxBoxSizer(wxHORIZONTAL);
2547         wxFlexGridSizer *sizerH4 = new wxFlexGridSizer(10);
2548         wxFlexGridSizer *sizerH5 = new wxFlexGridSizer(10);
2549
2550
2551
2552 //EED 28 sep 2006
2553 //      wxFlexGridSizer *sizerH6 = new wxFlexGridSizer(10);
2554 //      wxFlexGridSizer *sizerH7 = new wxFlexGridSizer(10);
2555
2556 //      sizerH4->Add( ckBoxX            , 1, wxALL|wxEXPAND, 0);
2557 //      sizerH4->Add( new wxStaticText(panel, -1,"  ")                  , 1, wxALL|wxEXPAND, 0);
2558 //      sizerH4->Add( _positionX        , 1, wxALL|wxEXPAND, 0);
2559
2560 //      sizerH5->Add( ckBoxY            , 1, wxALL|wxEXPAND, 0);
2561 //      sizerH5->Add( new wxStaticText(panel, -1,"  ")                  , 1, wxALL|wxEXPAND, 0);
2562 //      sizerH5->Add( _positionY        , 1, wxALL|wxEXPAND, 0);
2563
2564 //      sizerH6->Add( ckBoxZ            , 1, wxALL|wxEXPAND, 0);
2565 //      sizerH6->Add( new wxStaticText(panel, -1,"  ")                  , 1, wxALL|wxEXPAND, 0);
2566 //      sizerH6->Add( _positionZ        , 1, wxALL|wxEXPAND, 0);
2567
2568 //      sizerH7->Add( _ckBoxXYZ         , 1, wxALL|wxEXPAND, 0);
2569 //      sizerH7->Add( _ckBoxPlane       , 1, wxALL|wxEXPAND, 0);
2570
2571 //      sizer->Add( sizerH4                     , 1, wxALL|wxEXPAND, 2);
2572 //      sizer->Add( sizerH5                     , 1, wxALL|wxEXPAND, 2);
2573 //      sizer->Add( sizerH6                     , 1, wxALL|wxEXPAND, 2);
2574 //      sizer->Add( sizerH7                     , 1, wxALL|wxEXPAND, 2);
2575
2576         sizerH4->Add( _positionX                                                                ,1,wxGROW                                       , 0 );
2577         sizerH4->Add( ckBoxX                                                                    ,0,wxALIGN_CENTER_VERTICAL|wxSHAPED     , 0 );
2578         sizerH4->Add( _positionY                                                                ,1,wxGROW                                       , 0 );
2579         sizerH4->Add( ckBoxY                                                                    ,0,wxALIGN_CENTER_VERTICAL|wxSHAPED     , 0 );
2580         sizerH4->Add( _positionZ                                                                ,1,wxGROW                                       , 0 );
2581         sizerH4->Add( ckBoxZ                                                                    ,0,wxALIGN_CENTER_VERTICAL|wxSHAPED     , 0 );
2582         sizerH4->Add( btnColorTable                                                             ,0,wxALIGN_CENTER_VERTICAL|wxSHAPED     , 0 );
2583
2584         sizerH5->Add( _ckBoxXYZ                         ,  1, wxALL|wxEXPAND, 0);
2585         sizerH5->Add( _ckBoxPlane                       ,  1, wxALL|wxEXPAND, 0);
2586         sizerH5->Add( new wxStaticText(panel, -1,_T("      "))                  , 1, wxALL|wxEXPAND, 0);
2587 //      sizerH5->Add( ckBoxX                            ,  1, wxALL|wxEXPAND, 0);
2588 //      sizerH5->Add( ckBoxY                            ,  1, wxALL|wxEXPAND, 0);
2589 //      sizerH5->Add( ckBoxZ                            ,  1, wxALL|wxEXPAND, 0);
2590
2591         sizer->Add( sizerH4                                     ,  1, wxALL|wxGROW, 2);
2592         sizer->Add( sizerH5                                     ,  1, wxALL|wxEXPAND, 2);
2593
2594
2595         panel->SetSize(400,50);
2596         panel->SetAutoLayout(true);
2597         panel->SetSizer(sizer);
2598         panel->Layout();
2599
2600         panel->SetEventHandler((wxEvtHandler*)this);
2601
2602         //this->UpdateControlPanel();
2603
2604 }
2605 void wxVtkMPR3DViewCntrlPanel::UpdateControlPanel()
2606 {
2607
2608         vtkMPRBaseData* basedata = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData();
2609         if(basedata != NULL){
2610
2611                 /*int maxX = basedata->GetMaxPositionX();
2612                 int maxY = basedata->GetMaxPositionY();
2613                 int maxZ = basedata->GetMaxPositionZ();*/
2614                 int x0,x1,y0,y1,z0,z1;
2615
2616                 basedata->GetDimensionExtention(&x0,&x1,&y0,&y1,&z0,&z1);
2617                 /*int maxX = x1-x0;//basedata->GetMaxPositionX();
2618                 int maxY = y1-y0;//basedata->GetMaxPositionY();
2619                 int maxZ = z1-z0;//basedata->GetMaxPositionZ();*/
2620
2621                 
2622
2623                 //std::cout<<"wxVtkMPR3DViewCntrlPanel::UpdateControlPanel() maxX="<<maxX<<" maxY="<<maxY<<" maxZ="<<maxZ<<std::endl;
2624                 /*_positionX->SetRange(0,maxX);
2625                 _positionY->SetRange(0,maxY);
2626                 _positionZ->SetRange(0,maxZ);*/
2627                 _positionX->SetRange(x0,x1);
2628                 _positionY->SetRange(y0,y1);
2629                 _positionZ->SetRange(z0,z1);
2630
2631                 _positionX->SetValue((x0+x1)/2);
2632                 _positionY->SetValue((y0+y1)/2);
2633                 _positionZ->SetValue((z0+z1)/2);
2634
2635                 _positionX->Update();
2636                 _positionY->Update();
2637                 _positionZ->Update();
2638                 this->Update();
2639         }
2640         
2641 }
2642 //-------------------------------------------------------------------
2643 wxVtkMPR3DViewCntrlPanel::~wxVtkMPR3DViewCntrlPanel()
2644 {
2645 }
2646 //-------------------------------------------------------------------
2647 void wxVtkMPR3DViewCntrlPanel::Refresh()
2648 {
2649 //      wxPanel::Refresh();
2650         _positionX->SetValue( (int)(_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetX( )) );
2651         _positionY->SetValue( (int)(_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetY( )) );
2652         _positionZ->SetValue( (int)(_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetZ( )) );
2653 }
2654 /*
2655 //-------------------------------------------------------------------
2656 int wxVtkMPR3DViewCntrlPanel::GetIdTissue()
2657 {
2658         int idTissue=-1;
2659         if (_surfA->GetValue()==true)
2660         {
2661                 idTissue=0;
2662         }
2663         if (_surfB->GetValue()==true)
2664         {
2665                 idTissue=1;
2666         }
2667         if (_surfC->GetValue()==true)
2668         {
2669                 idTissue=2;
2670         }
2671         if (_surfD->GetValue()==true)
2672         {
2673                 idTissue=3;
2674         }
2675
2676         return idTissue;
2677 }
2678 */
2679
2680 //-------------------------------------------------------------------
2681 void wxVtkMPR3DViewCntrlPanel::OnEditColorTable(wxCommandEvent& event)
2682 {
2683
2684         vtkColorTransferFunction *ctfun                 = this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetvtkColorTransferFunction(); 
2685         std::vector<double> *ctfunVectorPoint   = this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetctFunVectorPoint();
2686         std::vector<double> *ctfunVectorRed             = this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetctFunVectorRed();
2687         std::vector<double> *ctfunVectorGreen   = this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetctFunVectorGreen();
2688         std::vector<double> *ctfunVectorBlue    =   this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetctFunVectorBlue();
2689
2690         printf("EED %p wxVtkMPR3DViewCntrlPanel::OnEditColorTable ctfun %p\n", this, ctfun);    
2691         printf("EED %p wxVtkMPR3DViewCntrlPanel::OnEditColorTable ctfunVectorPoint %p\n", this, ctfunVectorPoint);      
2692         printf("EED %p wxVtkMPR3DViewCntrlPanel::OnEditColorTable ctfunVectorRed %p\n", this, ctfunVectorRed);  
2693         printf("EED %p wxVtkMPR3DViewCntrlPanel::OnEditColorTable ctfunVectorGreen %p\n", this, ctfunVectorGreen);      
2694         printf("EED %p wxVtkMPR3DViewCntrlPanel::OnEditColorTable ctfunVectorBlue %p\n", this, ctfunVectorBlue);        
2695
2696         
2697         //void *p=this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer(); // JPRx
2698
2699
2700         int i=0,xi,r,g,b;
2701         
2702         vtkImageData *imagedata = this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
2703
2704         HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Color table"),imagedata,2);
2705         
2706                 
2707         hDlg->erasePointsTransferenceFunction();        
2708         int ctfSize=ctfunVectorRed->size();
2709         if(ctfSize>0)
2710         {
2711 // MACHETE  OJO Eduardo
2712                 int i=0;
2713                         while(i<ctfSize)
2714                         {
2715                                 double gr       = (*ctfunVectorPoint)[i];
2716                                 double r        = (*ctfunVectorRed)[i];
2717                                 double g        = (*ctfunVectorGreen)[i];
2718                                 double b        = (*ctfunVectorBlue)[i];
2719                         
2720 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
2721                                 i++;
2722                         }
2723         }
2724
2725         //
2726         // when the user had changed the transference Function
2727         //
2728         
2729         //setting variables if the user wants to do refresh
2730         
2731         hDlg->setCTF(ctfun);
2732         hDlg->setMPR3Dview(_wxvtkmpr3Dview);
2733         
2734         if(hDlg->ShowModal()== wxID_OK )
2735         {       
2736                 
2737                 // -- vtkColorTransferFunction  --
2738                         ctfun->RemoveAllPoints ();
2739                         //clean colors
2740                         ctfunVectorPoint->clear();
2741                         ctfunVectorRed->clear();
2742                         ctfunVectorGreen->clear();
2743                         ctfunVectorBlue->clear();
2744
2745                         int nCTFpoints=hDlg->getSizeBarColor();
2746 // Machete .. Ojo Eduardo
2747                         i=0;    
2748                         while(i<nCTFpoints)
2749                         {
2750                                 hDlg->getDataBarColorPoint(i,xi,r,g,b);
2751                                 /*
2752                                 if (i==0)
2753                                 {
2754                                         hDlg->getDataBarColorPoint(1,xi,r,g,b);
2755                                 } 
2756                                 if (i==nCTFpoints)
2757                                 {
2758                                         hDlg->getDataBarColorPoint(i-1,xi,r,g,b);
2759                                 } 
2760                                 */
2761                                 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
2762                                 ctfunVectorPoint->push_back(xi);
2763                                 ctfunVectorRed->push_back(r/255.0);
2764                                 ctfunVectorGreen->push_back(g/255.0);
2765                                 ctfunVectorBlue->push_back(b/255.0);
2766                                 i++;
2767                                 
2768                         }
2769                         
2770         }
2771         
2772         else
2773         {
2774                 
2775                 if(hDlg->getRefreshed())
2776                 {
2777                         // -- vtkColorTransferFunction  --
2778                         ctfun->RemoveAllPoints ();
2779                         
2780                         int i=0;
2781                         int size=ctfunVectorPoint->size();
2782                         
2783                         for(i=0;i<size;i++)
2784                         {
2785                                 double grey2=(*ctfunVectorPoint)[i];
2786                                 double red =(*ctfunVectorRed)[i];
2787                                 double green =(*ctfunVectorGreen)[i];
2788                                 double blue = (*ctfunVectorBlue)[i];
2789                                 ctfun->AddRGBPoint(grey2,red,green,blue);
2790                         }
2791                  }      
2792                  
2793         }
2794
2795  hDlg->Destroy();
2796 }
2797
2798
2799 //-------------------------------------------------------------------
2800 void wxVtkMPR3DViewCntrlPanel::OnVisibleAxisX(wxCommandEvent& event)
2801 {
2802         _wxvtkmpr3Dview->VisibleImageActor(0, event.IsChecked() );
2803         _wxvtkmpr3Dview->Refresh();
2804
2805         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
2806
2807         try{
2808                 _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
2809         }catch(char* e){
2810                 std::cout<<e<<std::endl;
2811         }
2812
2813 }
2814 //-------------------------------------------------------------------
2815 void wxVtkMPR3DViewCntrlPanel::OnVisibleAxisY(wxCommandEvent& event)
2816 {
2817         _wxvtkmpr3Dview->VisibleImageActor(1, event.IsChecked() );
2818         _wxvtkmpr3Dview->Refresh();
2819
2820         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
2821         _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
2822
2823 }
2824 //-------------------------------------------------------------------
2825 void wxVtkMPR3DViewCntrlPanel::OnVisibleAxisZ(wxCommandEvent& event)
2826 {
2827         _wxvtkmpr3Dview->VisibleImageActor(2, event.IsChecked() );
2828         _wxvtkmpr3Dview->Refresh();
2829
2830         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
2831         _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
2832 }
2833
2834 //-------------------------------------------------------------------
2835 void wxVtkMPR3DViewCntrlPanel::OnVisibleAxisXYZ(wxCommandEvent& event)
2836 {
2837         _wxvtkmpr3Dview->VisiblePointWidget(event.IsChecked());
2838 }
2839
2840 //-------------------------------------------------------------------
2841 void wxVtkMPR3DViewCntrlPanel::OnVisiblePlane(wxCommandEvent& event)
2842 {
2843         _wxvtkmpr3Dview->VisiblePlaneWidget(event.IsChecked());
2844 }
2845
2846
2847 //-------------------------------------------------------------------
2848 void wxVtkMPR3DViewCntrlPanel::OnPositionX(wxScrollEvent& event)
2849 {
2850         _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetX( _positionX->GetValue() );
2851         _wxvtkmpr3Dview->RefreshView();
2852         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
2853         _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
2854 }
2855 //-------------------------------------------------------------------
2856 void wxVtkMPR3DViewCntrlPanel::OnPositionY(wxScrollEvent& event)
2857 {
2858         _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetY( _positionY->GetValue() );
2859         _wxvtkmpr3Dview->RefreshView();
2860         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
2861         _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
2862 }
2863 //-------------------------------------------------------------------
2864 void wxVtkMPR3DViewCntrlPanel::OnPositionZ(wxScrollEvent& event)
2865 {
2866         _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetZ( _positionZ->GetValue() );
2867         _wxvtkmpr3Dview->RefreshView();
2868         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
2869         _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
2870 }
2871
2872
2873 //-------------------------------------------------------------------
2874 //-------------------------------------------------------------------
2875 //-------------------------------------------------------------------
2876
2877 wxVtkClipping3DViewCntrlPanel::wxVtkClipping3DViewCntrlPanel(wxWindow *parent, wxVtkClipping3DView *wxvtkclipping3Dview )
2878 : wxPanel(parent, -1)
2879 {
2880         wxPanel *panel  = this;
2881         _wxvtkclipping3Dview    = wxvtkclipping3Dview;
2882
2883 //EEDx2.6
2884 //      wxStaticText    *text1                  = new wxStaticText(panel, -1,_T("          "));
2885 //      wxStaticText    *text2                  = new wxStaticText(panel, -1,_T("  "));
2886
2887                                         _surfA                  = new wxRadioButton(panel,-1,_T("A"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
2888                                         _surfB                  = new wxRadioButton(panel,-1,_T("B"));
2889                                         _surfC                  = new wxRadioButton(panel,-1,_T("C"));
2890                                         _surfD                  = new wxRadioButton(panel,-1,_T("D"));
2891
2892         wxCheckBox              *ckVolum                = new wxCheckBox(panel,-1,_T("Vol"));
2893         wxCheckBox              *ckBoxSurface   = new wxCheckBox(panel,-1,_T("Surface Box"));
2894         wxCheckBox              *ckBoxVolume    = new wxCheckBox(panel,-1,_T("Volume Box"));
2895
2896                                         _color                  = new wxButton(panel,-1,_T(""));
2897                                         _visible                = new wxCheckBox(panel,-1,_T("Vis"));
2898                                         _opacity                = new wxSlider(panel,-1,50,0,100, wxDefaultPosition, wxSize(800,40), wxSL_HORIZONTAL | wxSL_LABELS);
2899
2900         wxStaticText    *isoValueTitle  = new wxStaticText(panel,-1,_T("isoValue"));
2901                                         _isoValue               = new wxSlider(panel,-1,2000,110,2000, wxDefaultPosition, wxSize(800,40), wxSL_HORIZONTAL  |  wxSL_AUTOTICKS | wxSL_LABELS);
2902
2903
2904                                         _wireFrameRep   = new wxRadioButton(panel,-1,_T("WireFrame"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
2905                                         _surfaceRep             = new wxRadioButton(panel,-1,_T("Surface"));
2906
2907
2908         double range[2];
2909         vtkImageData *vtkimagedata = wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
2910         vtkimagedata->GetScalarRange( range );
2911         _isoValue->SetRange( (int)(range[1]*0.1) , (int)(range[1]) );
2912         _isoValue->SetValue( (int)(wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIsovalue(0)) );
2913
2914
2915         _isoValue->SetTickFreq(25,0);
2916
2917         _isoValueSpin   = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT  );
2918         _isoValueSpin->SetRange(1,8);
2919         _isoValueSpin->SetValue(5);
2920         Connect(_isoValueSpin->GetId()  , wxEVT_COMMAND_SLIDER_UPDATED   , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValueSpin ); 
2921
2922         wxButton *btnSTL                                = new wxButton(panel,-1,_T("Create STL File"));
2923         wxButton *btnSaveRaw                    = new wxButton(panel,-1,_T("Save Raw Volume"));
2924
2925         wxButton *btnVolumeFunctions    = new wxButton(panel,-1,_T("Read Volume Functions"));
2926
2927
2928         Connect(btnSTL->GetId()                         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnCreateFileSTL    ); 
2929         Connect(btnSaveRaw->GetId()                     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnSaveRawVolume    ); 
2930         Connect(btnVolumeFunctions->GetId()     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnVolumeFunctions  ); 
2931
2932
2933         wxButton *btnMeshVTKLoad        = new wxButton(panel,-1,_T("Load Mesh"));
2934         Connect(btnMeshVTKLoad->GetId() , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnMeshVTKLoad      ); 
2935
2936
2937 /*
2938         int maxX = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionX();
2939         int maxY = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionY();
2940         int maxZ = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionZ();
2941         wxCheckBox              *ckBoxX                 = new wxCheckBox(panel,-1,"X");
2942                                         _positionX              = new wxSlider(panel,-1,maxX/2,0,maxX, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
2943         wxCheckBox              *ckBoxY                 = new wxCheckBox(panel,-1,"Y");
2944                                         _positionY              = new wxSlider(panel,-1,maxY/2,0,maxY, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
2945         wxCheckBox              *ckBoxZ                 = new wxCheckBox(panel,-1,"Z");
2946                                         _positionZ              = new wxSlider(panel,-1,maxZ/2,0,maxZ, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
2947 */
2948
2949 //      ckVolum->Enable(false);
2950         ckBoxSurface->SetValue(false);
2951         ckBoxVolume->SetValue(false);
2952         _color->SetSize(40,20);
2953         _opacity->SetSize(370,20);
2954 //      ckBoxX->SetValue(true);
2955 //      ckBoxY->SetValue(true);
2956 //      ckBoxZ->SetValue(true);
2957         _surfA->SetValue(true);
2958         _wireFrameRep->SetValue(false);
2959         _surfaceRep->SetValue(true);
2960         _visible->SetValue(false);
2961 //      _positionX->SetSize(400,20);
2962 //      _positionY->SetSize(400,20);
2963 //      _positionZ->SetSize(400,20);
2964
2965         Connect(ckVolum->GetId()                , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleVolume                             );
2966         Connect(ckBoxVolume->GetId()    , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume                  );
2967
2968         Connect(_surfA->GetId()                 , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface                                       );
2969         Connect(_surfB->GetId()                 , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface                                       );
2970         Connect(_surfC->GetId()                 , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface                                       );
2971         Connect(_surfD->GetId()                 , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface                                       );
2972         Connect(ckBoxSurface->GetId()   , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleBoxSurface                 );
2973
2974         Connect(_wireFrameRep->GetId()  , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame        );
2975         Connect(_surfaceRep->GetId()    , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame        );
2976
2977         Connect(_color->GetId()                 , wxEVT_COMMAND_BUTTON_CLICKED            , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnColor                                             );
2978         Connect(_visible->GetId()               , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleSurface                    );
2979         Connect(_opacity->GetId()               , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnOpacity                                   );
2980
2981 //EED 27Dic2007
2982 //      Connect(_isoValue->GetId()              , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValue                                  );
2983         Connect(_isoValue->GetId()              , wxEVT_SCROLL_THUMBRELEASE               , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValue                                          );
2984
2985 /*
2986         Connect(ckBoxX->GetId()     , wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisX   );
2987         Connect(_positionX->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionX              );
2988         Connect(ckBoxY->GetId()     , wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisY   );
2989         Connect(_positionY->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionY              );
2990         Connect(ckBoxZ->GetId()     , wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisZ   );
2991         Connect(_positionZ->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionZ              );
2992 */
2993
2994         wxFlexGridSizer *sizer   = new wxFlexGridSizer(1);
2995         wxFlexGridSizer *sizerH0 = new wxFlexGridSizer(20);
2996         wxFlexGridSizer *sizerH1 = new wxFlexGridSizer(20);
2997         wxFlexGridSizer *sizerH2 = new wxFlexGridSizer(10);
2998         wxFlexGridSizer *sizerH3 = new wxFlexGridSizer(10);
2999         //wxFlexGridSizer *sizerH4 = new wxFlexGridSizer(10); // JPRx
3000         //wxFlexGridSizer *sizerH5 = new wxFlexGridSizer(10); // JPRx
3001         //wxFlexGridSizer *sizerH6 = new wxFlexGridSizer(10); // JPRx
3002
3003         sizerH0->Add( ckVolum                                                                   , 1, wxALL|wxEXPAND, 0);
3004         sizerH0->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
3005         sizerH0->Add( ckBoxVolume                                                               , 1, wxALL|wxEXPAND, 0);
3006         sizerH0->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
3007         sizerH0->Add( btnVolumeFunctions                                                , 1, wxALL|wxEXPAND, 0);
3008         sizerH0->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
3009         sizerH0->Add( btnMeshVTKLoad                                                    , 1, wxALL|wxEXPAND, 0);
3010
3011
3012         sizerH1->Add( _surfA                                                                    , 1, wxALL|wxEXPAND, 0);
3013         sizerH1->Add( new wxStaticText(panel, -1,_T("  "))                      , 1, wxALL|wxEXPAND, 0);
3014         sizerH1->Add( _surfB                                                                    , 1, wxALL|wxEXPAND, 0);
3015         sizerH1->Add( new wxStaticText(panel, -1,_T("  "))                      , 1, wxALL|wxEXPAND, 0);
3016         sizerH1->Add( _surfC                                                                    , 1, wxALL|wxEXPAND, 0);
3017         sizerH1->Add( new wxStaticText(panel, -1,_T("  "))                      , 1, wxALL|wxEXPAND, 0);
3018         sizerH1->Add( _surfD                                                                    , 1, wxALL|wxEXPAND, 0);
3019         sizerH1->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
3020         sizerH1->Add( ckBoxSurface                                                              , 1, wxALL|wxEXPAND, 0);
3021         sizerH1->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
3022         sizerH1->Add( btnSTL                                                                    , 1, wxALL|wxEXPAND, 0);
3023         sizerH1->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
3024         sizerH1->Add( btnSaveRaw                                                                , 1, wxALL|wxEXPAND, 0);
3025
3026
3027 //      sizerH2->Add( new wxStaticText(panel, -1,_T("          ")                       , 1, wxALL|wxEXPAND, 0);
3028         sizerH2->Add( _color                            , 1, wxALL|wxEXPAND, 0);
3029         sizerH2->Add( new wxStaticText(panel, -1,_T("          "))                      , 1, wxALL|wxEXPAND, 0);
3030         sizerH2->Add( _visible                          , 1, wxALL|wxEXPAND, 0);
3031         sizerH2->Add( new wxStaticText(panel, -1,_T("          "))                      , 1, wxALL|wxEXPAND, 0);
3032
3033         
3034         sizerH2->Add( _wireFrameRep                             , 1,wxSHAPED | wxALIGN_CENTER_VERTICAL , 0);
3035         sizerH2->Add( new wxStaticText(panel, -1,_T("   "))                                     , 1, wxALL|wxEXPAND, 0);
3036         sizerH2->Add( _surfaceRep                               , 1,wxSHAPED | wxALIGN_CENTER_VERTICAL , 0);
3037         sizerH2->Add( new wxStaticText(panel, -1,_T("          "))                      , 1, wxALL|wxEXPAND, 0);
3038         
3039         sizerH2->Add( _opacity                          , 1, wxALL|wxEXPAND, 0);
3040
3041
3042         sizerH3->Add( isoValueTitle                     , 1, wxALL|wxEXPAND, 0);
3043         sizerH3->Add( _isoValueSpin                     , 1, wxALL|wxEXPAND, 0);
3044         sizerH3->Add( _isoValue                         , 1, wxALL|wxEXPAND, 0);
3045
3046 /*
3047         sizerH4->Add( ckBoxX            , 1, wxALL|wxEXPAND, 0);
3048         sizerH4->Add( text2                     , 1, wxALL|wxEXPAND, 0);
3049         sizerH4->Add( _positionX                , 1, wxALL|wxEXPAND, 0);
3050
3051         sizerH5->Add( ckBoxY            , 1, wxALL|wxEXPAND, 0);
3052         sizerH5->Add( text2                     , 1, wxALL|wxEXPAND, 0);
3053         sizerH5->Add( _positionY                , 1, wxALL|wxEXPAND, 0);
3054
3055         sizerH6->Add( ckBoxZ            , 1, wxALL|wxEXPAND, 0);
3056         sizerH6->Add( text2                     , 1, wxALL|wxEXPAND, 0);
3057         sizerH6->Add( _positionZ                , 1, wxALL|wxEXPAND, 0);
3058 */
3059         sizer->Add( sizerH0 , 1, wxALL|wxEXPAND, 2);
3060         sizer->Add( sizerH1 , 1, wxALL|wxEXPAND, 2);
3061         sizer->Add( sizerH2 , 1, wxALL|wxEXPAND, 2);
3062         sizer->Add( sizerH3 , 1, wxALL|wxEXPAND, 2);
3063 //      sizer->Add( sizerH4 , 1, wxALL|wxEXPAND, 2);
3064 //      sizer->Add( sizerH5 , 1, wxALL|wxEXPAND, 2);
3065 //      sizer->Add( sizerH6 , 1, wxALL|wxEXPAND, 2);
3066
3067         panel->SetSize(300,60);
3068         panel->SetAutoLayout(true);
3069         panel->SetSizer(sizer);
3070         panel->Layout();
3071
3072         panel->SetEventHandler((wxEvtHandler*)this);
3073
3074 }
3075 //-------------------------------------------------------------------
3076 wxVtkClipping3DViewCntrlPanel::~wxVtkClipping3DViewCntrlPanel()
3077 {
3078 }
3079 //-------------------------------------------------------------------
3080 void wxVtkClipping3DViewCntrlPanel::Refresh()
3081 {
3082 //      wxPanel::Refresh();
3083 /*
3084         _positionX->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetX( ) );
3085         _positionY->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetY( ) );
3086         _positionZ->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetZ( ) );
3087 */
3088 }
3089 //-------------------------------------------------------------------
3090 int wxVtkClipping3DViewCntrlPanel::GetIdTissue()
3091 {
3092         int idTissue=-1;
3093         if (_surfA->GetValue()==true)
3094         {
3095                 idTissue=0;
3096         }
3097         if (_surfB->GetValue()==true)
3098         {
3099                 idTissue=1;
3100         }
3101         if (_surfC->GetValue()==true)
3102         {
3103                 idTissue=2;
3104         }
3105         if (_surfD->GetValue()==true)
3106         {
3107                 idTissue=3;
3108         }
3109
3110         return idTissue;
3111 }
3112 /*
3113 //-------------------------------------------------------------------
3114 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisX(wxCommandEvent& event)
3115 {
3116         _wxvtkclipping3Dview->VisibleImageActor(0, event.IsChecked() );
3117         _wxvtkclipping3Dview->Refresh();
3118 }
3119 //-------------------------------------------------------------------
3120 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisY(wxCommandEvent& event)
3121 {
3122         _wxvtkclipping3Dview->VisibleImageActor(1, event.IsChecked() );
3123         _wxvtkclipping3Dview->Refresh();
3124 }
3125 //-------------------------------------------------------------------
3126 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisZ(wxCommandEvent& event)
3127 {
3128         _wxvtkclipping3Dview->VisibleImageActor(2, event.IsChecked() );
3129         _wxvtkclipping3Dview->Refresh();
3130 }
3131 */
3132
3133 //-------------------------------------------------------------------
3134 void wxVtkClipping3DViewCntrlPanel::OnSurface(wxCommandEvent& event)
3135 {
3136         int idTissue=GetIdTissue();
3137         if (idTissue!=-1)
3138         {
3139                 // Color
3140                 vtkActor *tmpActor;
3141                 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
3142                 double rgb[3];
3143                 tmpActor->GetProperty()->GetColor( rgb );
3144                 wxColour colour( (int)(rgb[0]*255) , (int)(rgb[1]*255) , (int)(rgb[2]*255) );
3145                 _color->SetBackgroundColour(colour);
3146
3147                 // Visible
3148                 _visible->SetValue(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVisibleTissue(idTissue));
3149
3150                 // Opacity
3151                 _opacity->SetValue( (int)(tmpActor->GetProperty()->GetOpacity()*100) );
3152
3153                 // Representation Type  WireFrame / Surface
3154                 _surfaceRep->SetValue(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRepresentationType(idTissue)); 
3155                 _wireFrameRep->SetValue(!_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRepresentationType(idTissue)); 
3156
3157                 // isoValue
3158                 int isoValue= (int)(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIsovalue(idTissue));
3159                 _isoValue->SetValue(isoValue);
3160         }
3161 }
3162
3163
3164 //-------------------------------------------------------------------
3165 void wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame(wxCommandEvent& event)
3166 {
3167         int idTissue=GetIdTissue();
3168         if (idTissue!=-1)
3169         {
3170                 _wxvtkclipping3Dview->SetRepSurfaceWireFrame(idTissue , _surfaceRep->GetValue() );
3171
3172                 _wxvtkclipping3Dview->Refresh();
3173
3174                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3175                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3176
3177         }
3178 }
3179
3180 //-------------------------------------------------------------------
3181 void wxVtkClipping3DViewCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
3182 {
3183         _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked()  );
3184         _wxvtkclipping3Dview->Refresh();
3185
3186         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3187         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3188 }
3189 //-------------------------------------------------------------------
3190 void wxVtkClipping3DViewCntrlPanel::OnVisibleBoxSurface(wxCommandEvent& event)
3191 {
3192         _wxvtkclipping3Dview->SetVisibleBoxSurface(event.IsChecked() );
3193         _wxvtkclipping3Dview->Refresh();
3194 }
3195 //-------------------------------------------------------------------
3196 void wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
3197 {
3198         _wxvtkclipping3Dview->SetVisibleBoxVolume(event.IsChecked() );
3199         _wxvtkclipping3Dview->Refresh();
3200 }
3201 //-------------------------------------------------------------------
3202 void wxVtkClipping3DViewCntrlPanel::OnColor(wxCommandEvent& event)
3203 {
3204         int idTissue=GetIdTissue();
3205         if (idTissue!=-1)
3206         {
3207 // EED 17 Janvier 2007
3208                 wxColourDialog dlgColour(this);
3209 //              dlgColour.ShowModal();
3210                 if( dlgColour.ShowModal( ) == wxID_OK ) 
3211                 {
3212                         vtkActor *tmpActor;
3213                         tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
3214                         float r=dlgColour.GetColourData().GetColour().Red()/255;
3215                         float g=dlgColour.GetColourData().GetColour().Green()/255;
3216                         float b=dlgColour.GetColourData().GetColour().Blue()/255;
3217                         tmpActor->GetProperty()->SetColor( r , g , b );
3218                         _color->SetBackgroundColour(dlgColour.GetColourData().GetColour());
3219
3220                         _wxvtkclipping3Dview->Refresh();
3221
3222                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3223                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3224                 }
3225         }
3226 }
3227 //-------------------------------------------------------------------
3228 void wxVtkClipping3DViewCntrlPanel::OnVisibleSurface(wxCommandEvent& event)
3229 {
3230         int idTissue=GetIdTissue();
3231         if (idTissue!=-1)
3232         {
3233                 _wxvtkclipping3Dview->VisibleActor(idTissue, _visible->GetValue());
3234
3235                 _wxvtkclipping3Dview->Refresh();
3236
3237                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3238                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3239         }
3240 }
3241 //-------------------------------------------------------------------
3242 void wxVtkClipping3DViewCntrlPanel::OnOpacity(wxScrollEvent& event)
3243 {
3244         int idTissue=GetIdTissue();
3245         if (idTissue!=-1)
3246         {
3247                 vtkActor *tmpActor;
3248                 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
3249                 float opacity=_opacity->GetValue();
3250                 tmpActor->GetProperty()->SetOpacity( opacity/100 );
3251
3252                 _wxvtkclipping3Dview->Refresh();
3253
3254                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3255                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3256         }
3257 }
3258
3259 //----------------------------------------------------------------------------
3260 void wxVtkClipping3DViewCntrlPanel::OnIsoValueSpin(wxScrollEvent& event)
3261 {
3262         int value = _isoValue->GetValue();
3263         int delta= (int)pow( 4 , _isoValueSpin->GetValue() );
3264         int min=value - delta/2;
3265         int max=value + delta/2;
3266         if (min<0)
3267         {
3268                 min=0;
3269                 max=delta;
3270         }
3271         _isoValue->SetRange(min,max);
3272 }
3273
3274
3275 //------------------------------------------------------------------------
3276 void wxVtkClipping3DViewCntrlPanel::OnIsoValue(wxScrollEvent& event)
3277 {
3278         wxBusyCursor wait;
3279
3280         int idTissue=GetIdTissue();
3281         if (idTissue!=-1)
3282         {
3283                 int isoValue=_isoValue->GetValue();
3284                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->SetIsovalue(idTissue,isoValue);
3285 //              wxString tmpStr;
3286 //              tmpStr.Printf("%d",isoValue);
3287         
3288                 _wxvtkclipping3Dview->Refresh();
3289
3290                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3291                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3292         }
3293
3294 }
3295 //-------------------------------------------------------------------
3296 void wxVtkClipping3DViewCntrlPanel::OnBtnCreateFileSTL(wxCommandEvent& event)
3297 {
3298
3299         int idTissue=GetIdTissue();
3300         if (idTissue==-1)
3301         {
3302                 idTissue=0;
3303         }
3304
3305
3306         wxString dirSTL = wxGetHomeDir( ) ;
3307         wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
3308
3309         if( dialog.ShowModal( ) == wxID_OK ) 
3310         {
3311            
3312         
3313                 // ------------------------------------------------------------------------
3314                 //  1.  GENERATE STL FILES
3315                 // ------------------------------------------------------------------------
3316 //              const char* fileprefix = "c:\\Creatis\\";
3317                 std::string prefix = (const char*) (dialog.GetPath().mb_str() );
3318                 std::string filename;
3319
3320                 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
3321
3322         vtkTriangleFilter *filtro = vtkTriangleFilter::New();
3323
3324
3325                 filtro->SetInput( this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueClipper(idTissue)->GetOutput() );
3326                 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
3327         pdcf->SetInput( filtro->GetOutput() );
3328         vtkClosePolyData *cpd = vtkClosePolyData::New();
3329         cpd->SetInput( pdcf->GetOutput() );
3330
3331                 // 1.2 se escribe a disco el archivo stl de la superficie interna
3332         cpd->Update();
3333         vtkSTLWriter *writer = vtkSTLWriter::New();
3334         writer->SetInput( cpd->GetOutput() );
3335                 filename =prefix;
3336         writer->SetFileName(filename.c_str());
3337         writer->SetFileTypeToASCII();
3338         writer->Write();
3339         writer->Delete();
3340
3341    
3342         filtro->Delete();
3343         cpd->Delete();
3344         pdcf->Delete();
3345         }
3346
3347 }
3348
3349 //EED 30 Janvier 2007
3350 //-------------------------------------------------------------------
3351 void wxVtkClipping3DViewCntrlPanel::OnBtnSaveRawVolume(wxCommandEvent& event)
3352 {
3353         wxFileDialog dialog(this, _T("Choose a file"), _T(""), _T(""), _T("*.maracas"), wxSAVE );
3354         if (dialog.ShowModal() == wxID_OK)
3355         {
3356                 std::string directory = (const char*) (dialog.GetDirectory().mb_str() );
3357                 std::string filename  = (const char*) (dialog.GetFilename().mb_str() );
3358                 float rescalaSlope           =  1;
3359                 float rescalaIntercept       =  0;
3360                 vtkMPRBaseData *vtkmprbasedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData();
3361                 vtkImageData *vtkimagedata       = vtkmprbasedata->GetImageData();
3362                 int dim[3];
3363                 vtkimagedata->GetDimensions(dim);
3364                 int voi[6];
3365                 voi[0]=0;
3366                 voi[1]=dim[0];
3367                 voi[2]=0;
3368                 voi[3]=dim[1];
3369                 voi[4]=0;
3370                 voi[5]=dim[2];
3371 //EED 10 oct 2007 MaracasVisu pour bbMaracasvisu
3372                 marRAW2Files marraw2;
3373                 marraw2.saveVolume(directory,filename,vtkimagedata,voi,rescalaSlope,rescalaIntercept);
3374         }
3375 }
3376
3377 //EED 22 Fevrier 2007
3378 //-------------------------------------------------------------------
3379 void wxVtkClipping3DViewCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
3380 {
3381         
3382         int /*i=0,*/ xi,yi,r,g,b;  // JPRx
3383         vtkColorTransferFunction* ctfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetColorTransferenceFunction();
3384         vtkPiecewiseFunction* tfun      = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTransferencefunction();
3385         std::vector<double>* gtf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValuesTransferenceFVector();
3386         std::vector<double>* itf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIntensityValuesTransferenceFVector();
3387         std::vector<double>* greyctf    = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValueColorsOfColorTransferenceFVector();
3388         std::vector<double>* rctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRedColorsOfColorTransferenceFVector();
3389         std::vector<double>* gctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreenColorsOfColorTransferenceFVector();
3390         std::vector<double>* bctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetBlueColorsOfColorTransferenceFVector();
3391         vtkImageData *imagedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
3392
3393         
3394         
3395         //use for update in the refresh
3396         /*
3397         vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
3398         vtkVolume* newvol       =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
3399         */
3400
3401         /*
3402         MMLR BORRAME 
3403         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
3404         if (dialog.ShowModal() == wxID_OK)
3405         {
3406                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
3407                 
3408         
3409         }
3410         */
3411
3412         HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
3413         // 
3414         // put in a method
3415         //
3416         int tfSize=gtf->size();
3417                 if(tfSize>0)
3418                 {
3419                         int i=0;
3420                         hDlg->erasePointsTransferenceFunction();
3421                         while(i<tfSize)
3422                         {
3423                                 double g=(*gtf)[i];
3424                                 double in=(*itf)[i];
3425                                 hDlg->addPointToTransferenceFunction(g,in*100);
3426                                 i++;
3427                         }
3428                         
3429                 }
3430
3431         int ctfSize=rctf->size();
3432         if(ctfSize>0)
3433         {
3434                 int i=0;
3435                         while(i<ctfSize)
3436                         {
3437                                 double gr=(*greyctf)[i];
3438                                 double r=(*rctf)[i];
3439                                 double g=(*gctf)[i];
3440                                 double b=(*bctf)[i];
3441                                 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
3442                                 i++;
3443                         }
3444         }
3445         //setting variables if the user wants to do refresh
3446         hDlg->setCTF(ctfun);
3447         hDlg->setTF(tfun);
3448         hDlg->setClipping3DView(_wxvtkclipping3Dview);
3449         /*
3450         hDlg->setVolume(newvol);
3451         hDlg->setVolumeMapper(volumeMapper);
3452         */
3453         //
3454         // when the user had changed the transference Function
3455         //
3456         if(hDlg->ShowModal()== wxID_OK )
3457         {       
3458                         // -- vtkPiecewiseFunction --
3459                         tfun->RemoveAllPoints();
3460                         gtf->clear();
3461                         itf->clear();
3462                 
3463                         int nTFPoints=hDlg->getSizeTransferenceFunction();
3464                         int i=0;
3465                         while(i<nTFPoints)
3466                         {
3467                                 hDlg->getTransferenceFunctionPoint(i,xi,yi);
3468                                 tfun->AddPoint( xi , yi/100.0 );
3469                                 gtf->push_back(xi);
3470                                 itf->push_back(yi/100.0);
3471                                 i++;
3472                         }       
3473                         // -- vtkColorTransferFunction  --
3474                         ctfun->RemoveAllPoints ();
3475                         //clean colors
3476                         rctf->clear();
3477                         gctf->clear();
3478                         bctf->clear();
3479                         greyctf->clear();
3480
3481                         int nCTFpoints=hDlg->getSizeBarColor();
3482                         i=0;    
3483                         while(i<nCTFpoints)
3484                         {
3485                                 hDlg->getDataBarColorPoint(i,xi,r,g,b);
3486                                 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
3487                                 rctf->push_back(r/255.0);
3488                                 gctf->push_back(g/255.0);
3489                                 bctf->push_back(b/255.0);
3490                                 greyctf->push_back(xi);
3491                                 i++;
3492                         }
3493                         //---------------------------------
3494                         // Refreshing and sending the event
3495                         //---------------------------------
3496                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
3497                         _wxvtkclipping3Dview->Refresh();
3498                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3499                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3500                         
3501                         /*
3502                         volumeMapper->Update();
3503                         newvol->Update();
3504                         */
3505         }
3506         
3507         else
3508         {
3509                 
3510                 if(hDlg->getRefreshed())
3511                 {
3512                         int i=0,size;
3513                         //--Transference Function----
3514                         tfun->RemoveAllPoints();
3515                         i=0;
3516                         size=gtf->size();
3517                         for(i=0;i<size;i++)
3518                         {
3519                                 double grey1=(*gtf)[i];
3520                                 double  in2=(*itf)[i];
3521                                 tfun->AddPoint( grey1 , in2 );
3522                         }
3523                         
3524                         // -- vtkColorTransferFunction  --
3525                         ctfun->RemoveAllPoints ();
3526                         
3527                         i=0;
3528                         size=greyctf->size();           
3529                         for(i=0;i<size;i++)
3530                         {
3531                                 double grey2=(*greyctf)[i];
3532                                 double red =(*rctf)[i];
3533                                 double green =(*gctf)[i];
3534                                 double blue = (*bctf)[i];
3535                                 ctfun->AddRGBPoint(grey2,red,green,blue);
3536                         }
3537                 
3538                         //---------------------------------
3539                         // Refreshing and sending the event
3540                         //---------------------------------
3541                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
3542                         _wxvtkclipping3Dview->Refresh();
3543                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3544                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3545                         
3546                         /*
3547                         volumeMapper->Update();
3548                         newvol->Update();
3549                         */
3550                  }
3551                  
3552         }
3553         //destroy the dialog
3554         hDlg->Destroy();
3555 }
3556
3557 //EED 23 Mai 2007
3558 //-------------------------------------------------------------------
3559 void wxVtkClipping3DViewCntrlPanel::OnBtnMeshVTKLoad(wxCommandEvent& event)
3560 {
3561         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.vtk"), wxOPEN);
3562         if (dialog.ShowModal() == wxID_OK)
3563         {
3564                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadMeshVTK( (char *)dialog.GetPath().c_str() );
3565                 _wxvtkclipping3Dview->Refresh();
3566                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3567                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3568         }
3569 }
3570
3571
3572 //-------------------------------------------------------------------
3573 //-------------------------------------------------------------------
3574 //-------------------------------------------------------------------
3575
3576
3577 wxVtkMPR3DView::wxVtkMPR3DView( wxVtk3DBaseView *wxvtk3Dbaseview )
3578 {
3579         _wxvtk3Dbaseview                        =       wxvtk3Dbaseview;
3580         _vtkmpr3Ddataviewer                     =       NULL;
3581         _wxvtkmpr3DviewCntrlPanel       =       NULL;   
3582         _myCallback=NULL;
3583         _pointWidget=NULL;
3584         _planeWidget=NULL;
3585         _vtkplane=NULL;
3586         _probe=NULL;
3587         _contourMapper=NULL;
3588 }
3589 void wxVtkMPR3DView::RemoveActor(vtkActor* actor){      
3590
3591         _wxvtk3Dbaseview->GetRenderer()->RemoveActor(actor);    
3592
3593
3594 }
3595 void wxVtkMPR3DView::ResetCamera(int* ext, double* origin,double* spc){
3596         if(ext == NULL){
3597
3598                 _wxvtk3Dbaseview->GetRenderer()->ResetCamera ();        
3599                 _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);      
3600         }else{
3601                 /*double x = (spc[0])*(origin[0]+(((double)ext[1]-(double)ext[0])/2.0));                
3602                 double y = (spc[1])*(origin[1]+(double)ext[3]);
3603                 double z = (spc[2])*(origin[2]+(((double)ext[5]-(double)ext[4])/2.0));*/
3604                 /*double x0=(spc[0])*((double)ext[0]+origin[0]);
3605                 double x1=(spc[0])*((double)ext[1]+origin[0]);
3606                 double y0=(spc[1])*((double)ext[2]+origin[1]);
3607                 double y1=(spc[1])*((double)ext[3]+origin[1]);
3608                 double z0=(spc[2])*((double)ext[4]+origin[2]);
3609                 double z1=(spc[2])*((double)ext[5]+origin[2]);*/
3610                 double x0=(spc[0])*((double)ext[0]);
3611                 double x1=(spc[0])*((double)ext[1]);
3612                 double y0=(spc[1])*((double)ext[2]);
3613                 double y1=(spc[1])*((double)ext[3]);
3614                 double z0=(spc[2])*((double)ext[4]);
3615                 double z1=(spc[2])*((double)ext[5]);
3616                 
3617                 _wxvtk3Dbaseview->GetRenderer()->ResetCamera(x0,x1,y0,y1,z0,z1);
3618                 //_wxvtk3Dbaseview->GetCamera()->SetPosition(x,y,z);
3619                 _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);      
3620         }
3621 }
3622 void wxVtkMPR3DView::Configure(){
3623
3624         _wxvtk3Dbaseview->Configure();
3625         _wxvtkmpr3DviewCntrlPanel->UpdateControlPanel();
3626         
3627 //EED ??????  07Mai2009 
3628 //      _wxvtk3Dbaseview->GetRenderer()->Clear();               
3629         
3630         
3631         // Actors are added to the renderer. 
3632         vtkActor* _outlineActor = _vtkmpr3Ddataviewer->GetOutlineActor();
3633         _wxvtk3Dbaseview->GetRenderer()->AddActor( _outlineActor );                     
3634 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(0)  );    // _saggital
3635 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(1)  );    // _axial
3636 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(2)  );    // _coronal
3637
3638
3639         // An initial camera view is created.  The Dolly() method moves 
3640         // the camera towards the FocalPoint, thereby enlarging the image.      
3641         _wxvtk3Dbaseview->GetRenderer()->SetActiveCamera(_wxvtk3Dbaseview->GetCamera());
3642         this->ResetCamera();
3643         
3644
3645         // Set a background color for the renderer and set the size of the
3646         // render window (expressed in pixels).
3647         _wxvtk3Dbaseview->GetRenderer()->SetBackground( 0.36 , 0.36 , 0.36 );
3648         _wxvtk3Dbaseview->GetRenWin()->SetSize(400, 400);
3649
3650         // Note that when camera movement occurs (as it does in the Dolly()
3651         // method), the clipping planes often need adjusting. Clipping planes
3652         // consist of two planes: near and far along the view direction. The 
3653         // near plane clips out objects in front of the plane; the far plane
3654         // clips out objects behind the plane. This way only what is drawn
3655         // between the planes is actually rendered.
3656         _wxvtk3Dbaseview->GetRenderer()->ResetCameraClippingRange();
3657
3658
3659         // vtkPointWidget
3660         if(_myCallback!=NULL){
3661                 _myCallback->Delete();
3662
3663         }
3664         _myCallback = vtkmyPWCallback_3DPointWidget::New();
3665         _myCallback->SetWxVtkMPR3DView(this);
3666  
3667         if(_pointWidget!=NULL){
3668                 _pointWidget->Delete();
3669         }
3670         _pointWidget = vtkPointWidget::New();
3671         _myCallback->SetVtkPointWidget(_pointWidget);
3672         _pointWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() ); 
3673         _pointWidget->SetInput( GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData() );
3674         
3675         _pointWidget->AllOff();
3676         
3677         _pointWidget->PlaceWidget();
3678 //      _pointWidget->SetPosition( x,y,z ); 
3679         
3680 //EED01 29Mars2009
3681 // MACOS probleme vtk-window out of wx-window   
3682 //      _pointWidget->On();
3683         
3684         _pointWidget->AddObserver(vtkCommand::InteractionEvent,_myCallback);
3685
3686
3687 // PlaneWidget
3688         if(_planeWidget!=NULL){
3689                 _planeWidget->Delete();
3690         }
3691         _planeWidget = vtkPlaneWidget::New();
3692         _myCallback->SetVtkPlaneWidget(_planeWidget);
3693         _planeWidget->SetInput( GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData() );
3694         _planeWidget->NormalToXAxisOn();
3695         _planeWidget->SetResolution(50);
3696         _planeWidget->SetRepresentationToOutline();
3697         int dim[3];
3698         GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetDimensions(dim);
3699         int px=(dim[0]/2);
3700         int py=(dim[1]/2);
3701         int pz=(dim[2]/2);
3702         int dd=20;
3703         _planeWidget->PlaceWidget( px-dd , px+dd , py-dd , py+dd , pz-dd , pz+dd );
3704
3705
3706         if(_vtkplane==NULL){
3707                 _vtkplane = vtkPolyData::New();
3708                 
3709                 _probe = vtkProbeFilter::New();
3710                 _probe->SetInput(_vtkplane);
3711
3712                 _contourMapper = vtkPolyDataMapper::New();
3713                 
3714                 _contourMapper->SetInput( _probe->GetPolyDataOutput() );
3715
3716                 _contourPlaneActor = vtkActor::New();
3717                 _contourPlaneActor->SetMapper(_contourMapper);
3718
3719                 _contourPlaneActor->VisibilityOff();
3720
3721                 _planeWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
3722                 _planeWidget->AddObserver(vtkCommand::InteractionEvent,_myCallback);
3723
3724                 _planeWidget->Off();
3725                 _wxvtk3Dbaseview->GetRenderer()->AddActor( _contourPlaneActor );        
3726
3727         }else{
3728                 
3729         }
3730         _planeWidget->GetPolyData(_vtkplane);
3731
3732         
3733         vtkImageData *imageData = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData(); 
3734         _probe->SetSource( imageData );
3735
3736         
3737         _contourMapper->SetScalarRange( imageData->GetScalarRange() );
3738     
3739         
3740
3741                         
3742 }
3743 //-------------------------------------------------------------------
3744 wxVtkMPR3DView::~wxVtkMPR3DView()
3745 {
3746 }
3747
3748 //-------------------------------------------------------------------
3749 void wxVtkMPR3DView::Refresh()   // virtual
3750 {
3751         _vtkmpr3Ddataviewer     ->      Refresh();
3752         if (_wxvtkmpr3DviewCntrlPanel!=NULL)
3753         {
3754                 _wxvtkmpr3DviewCntrlPanel->Refresh();
3755         }
3756
3757 }
3758 //-------------------------------------------------------------------
3759 void wxVtkMPR3DView::RefreshView()   // virtual
3760 {
3761         double spc[3];
3762         this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetSpacing(spc);
3763
3764         //double nx=1,ny=0,nz=0; // JPRx
3765         Refresh();
3766         double x=GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetX();
3767         double y=GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetY();
3768         double z=GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetZ();
3769
3770         x=x*spc[0];
3771         y=y*spc[1];
3772         z=z*spc[2];
3773
3774         _pointWidget->SetPosition( x,y,z ); 
3775
3776
3777         double in[3]; 
3778         double normal[3];
3779         vtkTransform *transform = GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetTransformOrientation();
3780         in[0]=1;                in[1]=0;                        in[2]=0;
3781         transform->TransformPoint(in,normal);
3782         _planeWidget->SetNormal( normal[0],normal[1],normal[2] );
3783
3784
3785         _planeWidget->SetCenter( x,y,z );
3786         _planeWidget->UpdatePlacement();
3787         _planeWidget->GetPolyData(_vtkplane);
3788 }
3789 //-------------------------------------------------------------------
3790 wxPanel* wxVtkMPR3DView::CreateControlPanel(wxWindow *parent)
3791 {
3792         _wxvtkmpr3DviewCntrlPanel = new wxVtkMPR3DViewCntrlPanel(parent,this);
3793         return _wxvtkmpr3DviewCntrlPanel;
3794 }
3795 //-------------------------------------------------------------------
3796 vtkMPR3DDataViewer* wxVtkMPR3DView::GetVtkMPR3DDataViewer() 
3797 {
3798         return _vtkmpr3Ddataviewer; 
3799 }
3800 //-------------------------------------------------------------------
3801 wxVtk3DBaseView* wxVtkMPR3DView::GetWxvtk3Dbaseview() throw (char*)
3802 {
3803         if(_wxvtk3Dbaseview==NULL){
3804                 throw "wxVtk3DBaseView* wxVtkMPR3DView::GetWxvtk3Dbaseview() _wxvtk3Dbaseview=NULL";
3805         }
3806         return _wxvtk3Dbaseview;
3807 }
3808 //-------------------------------------------------------------------
3809
3810 //-------------------------------------------------------------------
3811 void wxVtkMPR3DView::VisibleImageActor(int idPosition, bool visible){
3812         if (visible!=_vtkmpr3Ddataviewer->GetVisiblePosition(idPosition)){
3813                 if (visible==false){
3814                         _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkmpr3Ddataviewer->GetImageActor(idPosition)  );        
3815                 } else {
3816                         _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(idPosition)  );   
3817                 }
3818                 _vtkmpr3Ddataviewer->SetVisiblePosition(idPosition,visible);
3819         }
3820 }
3821
3822
3823 //-------------------------------------------------------------------
3824 void wxVtkMPR3DView::VisiblePointWidget( bool visible )
3825 {
3826         if (visible==true)
3827         {
3828                 _pointWidget->On();
3829         } else {
3830                 _pointWidget->Off();
3831         }
3832 }
3833
3834 //-------------------------------------------------------------------
3835 void wxVtkMPR3DView::VisiblePlaneWidget( bool visible )
3836 {
3837         if (visible==true)
3838         {
3839                 _planeWidget->On();
3840                 _contourPlaneActor->VisibilityOn();
3841
3842         } else {
3843                 _planeWidget->Off();
3844                 _contourPlaneActor->VisibilityOff();
3845         }
3846 }
3847
3848 //-------------------------------------------------------------------
3849 void wxVtkMPR3DView::SetVtkMPR3DDataViewer(vtkMPR3DDataViewer *vtkmpr3Ddataviewer)
3850 {
3851         _vtkmpr3Ddataviewer = vtkmpr3Ddataviewer;
3852 }
3853
3854 //-------------------------------------------------------------------
3855 void wxVtkMPR3DView::InitOrientationPointWidget()
3856 {
3857         this->_planeWidget->SetNormal(1,0,0);           
3858 }
3859
3860
3861
3862
3863 //-------------------------------------------------------------------
3864 // EED 25 Janvier 2007 testLoic
3865 void wxVtkMPR3DView::TestLoic1()
3866 {
3867
3868         int sizeIma     = 128;
3869   double dimIma = sizeIma*2;
3870
3871         vtkImageData *vtkimagedata =  this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
3872
3873         double spc[3];
3874         vtkimagedata->GetSpacing(spc);
3875
3876         vtkimagedata->Update();
3877
3878
3879          double p[3], n[3];
3880      this->_planeWidget->GetOrigin(p);
3881      this->_planeWidget->GetNormal(n);
3882
3883
3884
3885     vtkPlaneSource* pSource = vtkPlaneSource::New( );
3886     pSource->SetResolution( sizeIma - 1, sizeIma - 1 );
3887     pSource->SetOrigin( p[ 0 ], p[ 1 ], p[ 2 ] );
3888     pSource->SetPoint1( p[ 0 ] + dimIma - 1.0, p[ 1 ], p[ 2 ] );
3889     pSource->SetPoint2( p[ 0 ], p[ 1 ]+ dimIma - 1.0 , p[ 2 ] );
3890     pSource->Update( );
3891     pSource->SetCenter( p[ 0 ], p[ 1 ], p[ 2 ] );
3892     pSource->SetNormal( n[ 0 ], n[ 1 ], n[ 2 ] );
3893     pSource->Update( );
3894
3895     vtkProbeFilter* slices = vtkProbeFilter::New();
3896     slices->SetInput( ( vtkDataSet* )pSource->GetOutput( ) );
3897     slices->SetSource( vtkimagedata );
3898     slices->Update( );
3899     pSource->Delete( );
3900
3901         vtkStructuredPoints   *stPoints = vtkStructuredPoints::New();
3902         stPoints -> GetPointData( )->SetScalars(  slices->GetOutput()->GetPointData()->GetScalars()  );
3903         stPoints -> SetDimensions( sizeIma, sizeIma, 1 );
3904         stPoints -> SetScalarType( vtkimagedata->GetScalarType() );
3905         stPoints -> SetScalarTypeToShort();
3906         stPoints -> Update();
3907
3908         vtkImageChangeInformation  *change = vtkImageChangeInformation ::New();
3909         change    -> SetInput( stPoints );  
3910         change    -> Update();    //important
3911
3912         double _range[2];
3913         vtkimagedata->GetScalarRange(_range);
3914    vtkWindowLevelLookupTable *_bwlookup = vtkWindowLevelLookupTable::New( );
3915    _bwlookup->SetHueRange( 0 , 1 );
3916    _bwlookup->SetNumberOfColors( (int)(_range[1] - _range[0] + 1) );
3917    _bwlookup->SetTableRange( _range[0] , _range[1] );
3918    _bwlookup->SetSaturationRange( 0 , 0 );
3919    _bwlookup->SetValueRange( 0 , 1 );
3920    _bwlookup->SetAlphaRange( 1 , 1 );
3921    _bwlookup->Build( );
3922  
3923    vtkLookupTable * _collookup = vtkLookupTable::New( );
3924    _collookup->SetNumberOfColors( 256 );
3925    _collookup->SetTableRange( 0 , 255 );
3926    _collookup->Build( );
3927    _collookup->SetTableValue( 0  , 1 , 0 , 0 , 1 );
3928    _collookup->SetTableValue(128 , 0 , 0 , 1 , 1 );
3929    _collookup->SetTableValue(255 , 0 , 1 , 0 , 1 );
3930
3931
3932         vtkMetaImageWriter *writer = vtkMetaImageWriter::New( );
3933         writer->SetInput( stPoints );
3934         writer->SetFileName( "C:/Users/Images/temp_EED/image.mhd" );
3935         writer->SetFileDimensionality( 2 );
3936         writer->Write( );
3937
3938
3939
3940         vtkDataSetMapper *_3DSliceMapper = vtkDataSetMapper::New( );
3941         _3DSliceMapper->SetInput(change->GetOutput( ) );
3942         _3DSliceMapper->SetLookupTable( _bwlookup );
3943         _3DSliceMapper->SetScalarRange( _range );
3944         _3DSliceMapper->ImmediateModeRenderingOn( );
3945
3946         vtkActor *_3DSliceActor = vtkActor::New( );
3947         _3DSliceActor->SetMapper( _3DSliceMapper );
3948
3949  // The usual rendering stuff.
3950   vtkCamera *camera = vtkCamera::New();
3951       camera->SetPosition(1,1,1);
3952       camera->SetFocalPoint(0,0,0);
3953
3954   vtkRenderer *renderer = vtkRenderer::New();
3955   vtkRenderWindow *renWin = vtkRenderWindow::New();
3956     renWin->AddRenderer(renderer);
3957
3958   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
3959     iren->SetRenderWindow(renWin);
3960
3961   renderer->AddActor( _3DSliceActor );
3962       renderer->SetActiveCamera(camera);
3963       renderer->ResetCamera();
3964       renderer->SetBackground(1,1,1);
3965   
3966   renWin->SetSize(300,300);
3967
3968   // interact with data
3969   renWin->Render();
3970   iren->Start();
3971
3972
3973
3974
3975
3976 }
3977
3978 //-------------------------------------------------------------------
3979 // EED 25 Janvier 2007 testLoic
3980 void wxVtkMPR3DView::TestLoic2()
3981 {
3982 /*
3983  vtkVectorNorm *vecMagnitude = vtkVectorNorm::New();
3984                 vecMagnitude->SetInput(VtkMainGrid);
3985                 vecMagnitude->NormalizeOff();
3986                 vecMagnitude->Update();
3987 */
3988
3989         vtkPlane *slicePlane = vtkPlane::New();
3990                                 this->_planeWidget->GetPlane( slicePlane );
3991
3992                 
3993         vtkCutter* sliceCutter = vtkCutter::New();
3994                 vtkImageData *vtkimagedata =  this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
3995                 sliceCutter->SetInput( vtkimagedata );
3996                 sliceCutter->SetCutFunction( slicePlane );
3997
3998 //EED
3999 //        vtkLookupTable *lut = BuildHueWeightBaseMap();
4000
4001
4002         vtkPolyDataMapper *slice = vtkPolyDataMapper::New();
4003                 slice->SetInput( sliceCutter->GetOutput() );
4004         double range[2];
4005 // EED
4006 //                slice->Update();
4007                                   vtkimagedata->GetScalarRange(range);
4008 //                vecMagnitude->GetOutput()->GetScalarRange( range );
4009 //                range[1] *= 0.7; // reduce the upper range by 30%
4010 //                slice->SetScalarRange( range );
4011 //                slice->SetLookupTable( lut );
4012
4013 //       vtkActor *sliceActor = vtkActor::New();
4014 //                sliceActor->SetMapper( slice );
4015
4016         vtkPolyDataMapper *contourMapper = vtkPolyDataMapper::New();
4017                 contourMapper->SetInput( sliceCutter->GetOutput() );
4018                 contourMapper->SetScalarRange( range );
4019   //              contourMapper->SetLookupTable( lut );
4020
4021                 
4022         vtkActor *contourActor = vtkActor::New();
4023                 contourActor->SetMapper( contourMapper );
4024
4025
4026
4027  // The usual rendering stuff.
4028   vtkCamera *camera = vtkCamera::New();
4029       camera->SetPosition(1,1,1);
4030       camera->SetFocalPoint(0,0,0);
4031
4032   vtkRenderer *renderer = vtkRenderer::New();
4033   vtkRenderWindow *renWin = vtkRenderWindow::New();
4034     renWin->AddRenderer(renderer);
4035
4036   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
4037     iren->SetRenderWindow(renWin);
4038
4039   renderer->AddActor( contourActor );
4040 //  renderer->AddActor(cubeActor);
4041       renderer->SetActiveCamera(camera);
4042       renderer->ResetCamera();
4043       renderer->SetBackground(1,1,1);
4044   
4045   renWin->SetSize(300,300);
4046
4047   // interact with data
4048   renWin->Render();
4049   iren->Start();
4050
4051
4052 }
4053
4054 //-------------------------------------------------------------------
4055 //-------------------------------------------------------------------
4056 //-------------------------------------------------------------------
4057
4058 wxVtkClipping3DView::wxVtkClipping3DView(wxVtk3DBaseView* wxvtk3Dbaseview)
4059 {
4060         _wxvtk3Dbaseview                                =       wxvtk3Dbaseview;
4061         _vtkclipping3Ddataviewer                =       NULL;
4062         _wxvtkclipping3DviewCntrlPanel  =       NULL;
4063
4064         _boxWidgetVolume                                =       NULL;
4065         _boxWidgetS1                                    =       NULL;
4066 }
4067
4068 //-------------------------------------------------------------------
4069 wxVtkClipping3DView::~wxVtkClipping3DView(){
4070         if (_boxWidgetVolume!=NULL)                              { _boxWidgetVolume     -> Delete();                                    }
4071         if (_boxWidgetS1!=NULL)                                  { _boxWidgetS1         -> Delete();                                    }
4072         if (_vtkclipping3Ddataviewer!=NULL)              { delete _vtkclipping3Ddataviewer;                     }
4073         if (_wxvtkclipping3DviewCntrlPanel!=NULL){ delete _wxvtkclipping3DviewCntrlPanel;       }
4074 }
4075 //-------------------------------------------------------------------
4076 void wxVtkClipping3DView::SetVisibleBoxSurface(bool visible)
4077 {
4078         if (visible==true){
4079                 _boxWidgetS1->On();
4080         } else {
4081                 _boxWidgetS1->Off();
4082         }
4083 }
4084 //-------------------------------------------------------------------
4085 void wxVtkClipping3DView::SetVisibleBoxVolume(bool visible)
4086 {
4087         if (_boxWidgetVolume!=NULL){
4088                 if (visible==true){
4089                         _boxWidgetVolume->On();
4090                 } else {
4091                         _boxWidgetVolume->Off();
4092                 }
4093         }
4094 }
4095 //-------------------------------------------------------------------
4096 void wxVtkClipping3DView::Refresh()
4097 {
4098         _vtkclipping3Ddataviewer->Refresh();
4099         if (_wxvtkclipping3DviewCntrlPanel!=NULL)
4100         {
4101                 _wxvtkclipping3DviewCntrlPanel->Refresh();
4102         }
4103 }
4104 //-------------------------------------------------------------------
4105 wxPanel* wxVtkClipping3DView::CreateControlPanel(wxWindow *parent)
4106 {
4107         _wxvtkclipping3DviewCntrlPanel = new wxVtkClipping3DViewCntrlPanel(parent,this);
4108         return _wxvtkclipping3DviewCntrlPanel;
4109 }
4110 //-------------------------------------------------------------------
4111 vtkClipping3DDataViewer* wxVtkClipping3DView::GetVtkClipping3DDataViewer()
4112 {
4113         return _vtkclipping3Ddataviewer; 
4114 }
4115 //-------------------------------------------------------------------
4116 void wxVtkClipping3DView::VisibleActor(int idTissue, bool visTissue){
4117         if (visTissue!=_vtkclipping3Ddataviewer->GetVisibleTissue(idTissue)){
4118                 if (visTissue==false){
4119                         _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkclipping3Ddataviewer->GetTissueActor(idTissue)  );    
4120                 } else {
4121                         _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(idTissue)  );       
4122 //                      _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(idTissue) );
4123 //                      _actor->VisibilityOn();
4124                 }
4125                 _vtkclipping3Ddataviewer->SetVisibleTissue(idTissue,visTissue);
4126         }
4127 }
4128 //-------------------------------------------------------------------
4129 void wxVtkClipping3DView::SetRepSurfaceWireFrame(int idTissue , bool representationType )
4130 {
4131         vtkActor *tmpActor;
4132         tmpActor = GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
4133
4134         if (representationType==false){
4135                 tmpActor->GetProperty()->SetRepresentationToWireframe();
4136         } else {
4137                 tmpActor->GetProperty()->SetRepresentationToSurface();
4138         }
4139
4140         _vtkclipping3Ddataviewer->SetRepresentationType(idTissue,representationType);
4141 }
4142
4143 //-------------------------------------------------------------------
4144 void wxVtkClipping3DView::VisibleVolumeActor( bool visVolume){
4145         if (visVolume!=_vtkclipping3Ddataviewer->GetVisibleVolume() ){
4146                 if (visVolume==false){
4147 //EED 31/03/2008                        
4148 //                      _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkclipping3Ddataviewer->GetVolumeActor()  );    
4149                         _wxvtk3Dbaseview->GetRenderer()->RemoveVolume( _vtkclipping3Ddataviewer->GetVolumeActor()  );   
4150                 } else {
4151 //EED 31/03/2008                        
4152 //                      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetVolumeActor() );        
4153                         _wxvtk3Dbaseview->GetRenderer()->AddVolume( _vtkclipping3Ddataviewer->GetVolumeActor() );       
4154                 }
4155                 _vtkclipping3Ddataviewer->SetVisibleVolume(visVolume);
4156         }
4157 }
4158 //-------------------------------------------------------------------
4159 wxVtk3DBaseView* wxVtkClipping3DView::GetWxvtk3Dbaseview()throw(char*)
4160 {
4161         if(_wxvtk3Dbaseview==NULL){
4162                 throw "wxVtk3DBaseView* wxVtkClipping3DView::GetWxvtk3Dbaseview() _wxvtk3Dbaseview=NULL";
4163         }
4164         return _wxvtk3Dbaseview;
4165 }
4166 //-------------------------------------------------------------------
4167 void wxVtkClipping3DView::Configure(){
4168         _wxvtk3Dbaseview->Configure();
4169
4170         // Actors are added to the renderer. 
4171         _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetOutlineActor() );                       
4172
4173         _boxWidgetS1 = vtkBoxWidget::New();
4174         _boxWidgetS1->SetInteractor( _wxvtk3Dbaseview->GetWxVTKRenderWindowInteractor() );
4175         _boxWidgetS1->SetPlaceFactor(1.25);
4176
4177
4178
4179         vtkStripper *stripper=_vtkclipping3Ddataviewer->GetTissueStripper(0);
4180         vtkPolyData *polydata= stripper->GetOutput();
4181  
4182
4183         _boxWidgetS1->SetInput( polydata );
4184         _boxWidgetS1->PlaceWidget();
4185
4186         int i;
4187         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
4188         {
4189                 _boxWidgetS1->AddObserver( vtkCommand::InteractionEvent          , _vtkclipping3Ddataviewer->GetObserverS(i) );
4190         }
4191
4192
4193
4194
4195 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(0) );                       
4196 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(3));                        
4197
4198         VisibleActor(0, false );
4199         VisibleActor(1, false );
4200         VisibleActor(2, false );
4201         VisibleActor(3, false );
4202
4203         _boxWidgetS1->HandlesOn ();
4204         
4205 //EED 29Mars2009        
4206 //      _boxWidgetS1->On();
4207         
4208         _boxWidgetS1->Off();
4209
4210         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(0) );
4211         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(1) );
4212         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(2) );
4213         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(3) );
4214         
4215 // EED 9 fev 2007
4216 // box Volume
4217         _boxWidgetVolume = vtkBoxWidget::New();
4218         _boxWidgetVolume->SetInteractor( _wxvtk3Dbaseview->GetWxVTKRenderWindowInteractor() );
4219         _boxWidgetVolume->SetPlaceFactor(1.25);
4220
4221         _boxWidgetVolume->SetInput( this->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData() );
4222         _boxWidgetVolume->PlaceWidget();
4223
4224         _boxWidgetVolume->AddObserver( vtkCommand::InteractionEvent              , _vtkclipping3Ddataviewer->GetObserverV() );
4225
4226         _boxWidgetVolume->HandlesOn ();
4227         
4228 //EED 29Mars2009        
4229 //      _boxWidgetVolume->On();
4230         
4231         _boxWidgetVolume->Off();
4232
4233
4234 //      vtkPlanes *vtkplanes=this->GetVtkClipping3DDataViewer()->GetVolumePlanes();
4235 //      _boxWidgetVolume->GetPlanes( vtkplanes );
4236
4237
4238   // An initial camera view is created.  The Dolly() method moves 
4239   // the camera towards the FocalPoint, thereby enlarging the image.
4240   _wxvtk3Dbaseview->GetRenderer()->SetActiveCamera(_wxvtk3Dbaseview->GetCamera());
4241   _wxvtk3Dbaseview->GetRenderer()->ResetCamera ();
4242   _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);
4243
4244   // Set a background color for the renderer and set the size of the
4245   // render window (expressed in pixels).
4246   _wxvtk3Dbaseview->GetRenderer()->SetBackground( 0.36 , 0.36 , 0.36 );
4247   _wxvtk3Dbaseview->GetRenWin()->SetSize(400, 400);
4248
4249   // Note that when camera movement occurs (as it does in the Dolly()
4250   // method), the clipping planes often need adjusting. Clipping planes
4251   // consist of two planes: near and far along the view direction. The 
4252   // near plane clips out objects in front of the plane; the far plane
4253   // clips out objects behind the plane. This way only what is drawn
4254   // between the planes is actually rendered.
4255   _wxvtk3Dbaseview->GetRenderer()->ResetCameraClippingRange();
4256 }
4257 //-------------------------------------------------------------------
4258 void wxVtkClipping3DView::SetVtkClipping3DDataViewer(vtkClipping3DDataViewer *vtkclipping3Ddataviewer)
4259 {
4260         _vtkclipping3Ddataviewer = vtkclipping3Ddataviewer;
4261 }
4262
4263
4264 //---------------------------------------------------------------------------
4265 //---------------------------------------------------------------------------
4266 //---------------------------------------------------------------------------
4267 vtkInteractorStyle3DView::vtkInteractorStyle3DView()
4268 {
4269 }
4270 //---------------------------------------------------------------------------
4271 vtkInteractorStyle3DView::~vtkInteractorStyle3DView()
4272 {
4273 }
4274 //---------------------------------------------------------------------------
4275 bool vtkInteractorStyle3DView::OnLeftDClick()
4276 {
4277         SelectMarchibCubePoint();
4278         return true;
4279 }
4280 //---------------------------------------------------------------------------
4281 bool vtkInteractorStyle3DView::SelectMarchibCubePoint()
4282 {
4283         bool ok=false;
4284     gtm::TVector< double > pO( 3 ), pF( 3 ), pp( 3 ), cp( 3 );
4285     gtm::TVector< double > xc( 3 );
4286     gtm::TVector< double > x1( 3 ), n1( 3 );
4287     gtm::TVector< double > x2( 3 ), n2( 3 );
4288
4289         double pickPoint[ 3 ], cameraPos[ 3 ];
4290         int eventrwi[2];
4291         vtkPointPicker* picker = vtkPointPicker::New( );        
4292         eventrwi[0]= _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];
4293         eventrwi[1]= _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
4294         vtkRenderer *pRenderer = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetRenderer();
4295         picker->Pick( eventrwi[0], eventrwi[1], 0.0, pRenderer );
4296         pRenderer->GetActiveCamera( )->GetPosition( cameraPos );
4297         picker->GetPickPosition( pickPoint );
4298         picker->Delete( );
4299
4300         pp( 0 ) = pickPoint[ 0 ]; pp( 1 ) = pickPoint[ 1 ]; pp( 2 ) = pickPoint[ 2 ];
4301     cp( 0 ) = cameraPos[ 0 ]; cp( 1 ) = cameraPos[ 1 ]; cp( 2 ) = cameraPos[ 2 ];
4302
4303
4304 //EED 27 sep 2006  (1/2)
4305 //      wxVtkMPR3DView *wxvtkmpr3Dview = (wxVtkMPR3DView *)_vtkInteractorStyleBaseView->GetWxVtk3DBaseView();
4306 //      double spc[3];
4307 //      wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetSpacing(spc);
4308
4309
4310         vtkImageData *imageData = GetWxVtkMPR3DView()->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
4311         int dim[3];
4312         double spc[3];
4313         imageData->GetDimensions(dim);
4314         imageData->GetSpacing(spc);
4315
4316
4317         vtkMarchingCubes *mcubes = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetMCubes(0);
4318         
4319
4320         UtilVtk3DGeometriSelection utilVtk3DGeometriSelection;
4321         utilVtk3DGeometriSelection.SetDimentions(dim[0],dim[1],dim[2]);
4322
4323         utilVtk3DGeometriSelection.SetMarchingCube(mcubes);
4324
4325     double fac;
4326     fac = GTM_MAX( dim[0], dim[2] );
4327
4328
4329     if( utilVtk3DGeometriSelection.FindCubePointsFromPoints(
4330       pO.GetAnsiRef( ), pF.GetAnsiRef( ),
4331       pp.GetAnsiRef( ), cp.GetAnsiRef( ) )  ) 
4332         {
4333
4334                 if( utilVtk3DGeometriSelection.GetPointAndNormalIntersection(
4335                             x1.GetAnsiRef( ), n1.GetAnsiRef( ),
4336                                 pO.GetAnsiRef( ), pF.GetAnsiRef( ) ) ) 
4337                 {
4338                     if( utilVtk3DGeometriSelection.GetPointAndNormalIntersection(
4339                               x2.GetAnsiRef( ), n2.GetAnsiRef( ),
4340                                  ( x1 - n1 ).GetAnsiRef( ), ( x1 - ( n1 * fac ) ).GetAnsiRef( )   ) ) 
4341                         {
4342                                 xc = ( x2 + x1 ) * 0.5;
4343 //EED 27 sep 2006  (2/2)
4344                                 this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetX(xc(0)/spc[0]);
4345                                 this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetY(xc(1)/spc[1]);
4346                                 this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetZ(xc(2)/spc[2]);
4347                                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
4348                                 this->_wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
4349                                 ok=true;
4350                         }
4351                 }
4352         }
4353
4354
4355         return ok;
4356 }
4357 //-------------------------------------------------------------------
4358 void vtkInteractorStyle3DView::SetWxVtkMPR3DView( wxVtkMPR3DView *wxvtkmpr3Dview )
4359 {
4360         _wxvtkmpr3Dview = wxvtkmpr3Dview;
4361 }
4362 //-------------------------------------------------------------------
4363 wxVtkMPR3DView *vtkInteractorStyle3DView::GetWxVtkMPR3DView()
4364 {
4365         return _wxvtkmpr3Dview;
4366 }
4367 //-------------------------------------------------------------------
4368 wxVtkClipping3DView *vtkInteractorStyle3DView::GetWxVtkClipping3DView()
4369 {
4370         return _wxvtkclipping3Dview;
4371 }
4372 //-------------------------------------------------------------------
4373 void vtkInteractorStyle3DView::SetWxVtkClipping3DView( wxVtkClipping3DView *wxvtkclipping3Dview)
4374 {
4375         _wxvtkclipping3Dview = wxvtkclipping3Dview;
4376 }
4377
4378
4379
4380 //-------------------------------------------------------------------
4381 //-------------------------------------------------------------------
4382 //-------------------------------------------------------------------
4383 void vtkmyPWCallback_3DPointWidget::Execute(vtkObject *caller, unsigned long, void*)
4384 {
4385         double n[3];
4386         double p[3];
4387         double delta = 0.000000001;
4388
4389         vtkInteractorStyleBaseView *isbv = _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetInteractorStyleBaseView();
4390
4391         if (caller==_pointWidget)
4392         {
4393                 _pointWidget->GetPosition(p);
4394         }
4395         if (caller==_planeWidget)
4396         {
4397                 _planeWidget->GetCenter(p);
4398                 _planeWidget->GetNormal(n);
4399                 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetNormal(n[0],n[1],n[2]);
4400         }
4401
4402         double spc[3];
4403         _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetSpacing(spc);
4404         p[0]=p[0]/spc[0];
4405         p[1]=p[1]/spc[1];
4406         p[2]=p[2]/spc[2];
4407
4408         // Orientation change
4409         if ( (fabs(n[0]-_backNormal[0])>delta) || (fabs(n[1]-_backNormal[1])>delta) || (fabs(n[2]-_backNormal[2])>delta) )
4410         {
4411                 _backNormal[0] = n[0];
4412                 _backNormal[1] = n[1];
4413                 _backNormal[2] = n[2];
4414                 isbv->SetParent_refresh_waiting();
4415         }
4416
4417         // ----------
4418
4419         double tx = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetX();
4420         double ty = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetY();
4421         double tz = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetZ();
4422
4423         // Position Change
4424         if ( (fabs(tx-p[0])>delta) || (fabs(ty-p[1])>delta) || (fabs(tz-p[2])>delta) )
4425         {
4426                 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetX( p[0] );
4427                 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetY( p[1] );
4428                 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetZ( p[2] );
4429                 vtkInteractorStyleBaseView *isbv = _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetInteractorStyleBaseView();
4430                 isbv->BlockRefresh();
4431                 isbv->vtkInteractorStyleBaseView::OnLeftButtonDown();
4432                 isbv->SetParent_refresh_waiting();
4433                 isbv->vtkInteractorStyleBaseView::OnMouseMove();
4434                 isbv->UnBlockRefresh();
4435         } 
4436         isbv->EvaluateToRefresh();
4437 }
4438 //-------------------------------------------------------------------
4439 void vtkmyPWCallback_3DPointWidget::SetWxVtkMPR3DView( wxVtkMPR3DView *wxvtkmpr3Dview )
4440 {
4441         _wxvtkmpr3Dview=wxvtkmpr3Dview;
4442 }
4443 //-------------------------------------------------------------------
4444 void vtkmyPWCallback_3DPointWidget::SetVtkPointWidget( vtkPointWidget *pointWidget )
4445 {
4446         _pointWidget=pointWidget;
4447 }
4448 //-------------------------------------------------------------------
4449 void vtkmyPWCallback_3DPointWidget::SetVtkPlaneWidget( vtkPlaneWidget *planeWidget )
4450 {
4451         _planeWidget=planeWidget;
4452 }
4453 //-------------------------------------------------------------------
4454 //-------------------------------------------------------------------
4455 //-------------------------------------------------------------------
4456
4457 wxPanelCuttingImageData::wxPanelCuttingImageData (wxWindow *parent)
4458 : wxPanel( parent, -1)
4459 {
4460         _imageData=NULL;
4461         _histogrammeVector=NULL;
4462         _wxvtk3Dbaseview=NULL;
4463         _wxvtkbaseView=NULL;
4464         CreateInterface();
4465         CreateModel();
4466         Create3DViewObjects();
4467 }
4468
4469 //-------------------------------------------------------------------
4470 wxPanelCuttingImageData::~wxPanelCuttingImageData()
4471 {
4472
4473
4474         delete _modelCube;      
4475         delete _modelSphere;    
4476         delete _modelCylinder;  
4477         _vtkcube                -> Delete();    
4478         _vtksphere              -> Delete();    
4479         _vtkcylinder    -> Delete();    
4480         _cubeMapper             -> Delete();    
4481         _sphereMapper   -> Delete();    
4482         _cylinderMapper -> Delete();    
4483         _cubeActor              -> Delete();    
4484         _sphereActor    -> Delete();    
4485         _cylinderActor  -> Delete();    
4486 //      _xyplot->RemoveAllInputs();     
4487         _xyplot                 -> Delete();    
4488         _histogrammeVector->Delete();   
4489         _renplotter->Delete();
4490         
4491         if(_wxvtkbaseView!=NULL){
4492                 delete _wxvtkbaseView;
4493         }
4494         //delete _vtkclipping3Ddataviewer;
4495         
4496
4497         //fclose(file);
4498
4499 }
4500
4501 //-------------------------------------------------------------------
4502 void wxPanelCuttingImageData::RemoveActors()
4503 {
4504         _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _actualActor );
4505 }
4506
4507
4508 //-------------------------------------------------------------------
4509 void wxPanelCuttingImageData::SetWxVtk3DBaseView( wxVtk3DBaseView * wxvtk3Dbaseview )
4510 {
4511         _wxvtk3Dbaseview=wxvtk3Dbaseview;
4512 }
4513
4514 //-------------------------------------------------------------------
4515
4516 void wxPanelCuttingImageData::SetVtkClipping3DDataViewer( vtkClipping3DDataViewer *vtkclipping3Ddataviewer )
4517 {
4518         this->_vtkclipping3Ddataviewer = vtkclipping3Ddataviewer;
4519 }
4520
4521 //-------------------------------------------------------------------
4522 void wxPanelCuttingImageData::Create3DViewObjects()
4523 {
4524         // Sphere
4525         _vtksphere              = vtkSphereSource::New();
4526         _vtksphere->SetThetaResolution (20);
4527         _vtksphere->SetPhiResolution (20);
4528         _sphereMapper   = vtkPolyDataMapper::New();
4529         _sphereMapper->SetInput( _vtksphere->GetOutput() );
4530         _sphereActor    = vtkActor::New();
4531         _sphereActor->SetMapper(_sphereMapper);
4532         _sphereActor->SetOrigin(0, 0, 0);
4533         _sphereActor->SetPosition(0, 0, 0);
4534         _sphereActor->GetProperty()->SetColor(1, 0, 0);
4535         _sphereActor->SetUserTransform( _modelSphere->GetVtkTransform() );      
4536
4537         // cube
4538         _vtkcube                = vtkCubeSource::New();
4539         _vtkcube->SetXLength (1);
4540         _vtkcube->SetYLength (1);
4541         _vtkcube->SetZLength (1);
4542         _cubeMapper             = vtkPolyDataMapper::New();
4543         _cubeMapper->SetInput( _vtkcube->GetOutput() );
4544         _cubeActor              = vtkActor::New();
4545         _cubeActor->SetMapper(_cubeMapper);
4546         _cubeActor->SetOrigin(0, 0, 0);
4547         _cubeActor->SetPosition(0, 0, 0);
4548         _cubeActor->GetProperty()->SetColor(1, 0, 0);
4549         _cubeActor->SetUserTransform( _modelCube->GetVtkTransform() );          
4550
4551         // cylinder
4552         _vtkcylinder    = vtkCylinderSource::New();
4553         _vtkcylinder->SetResolution(20);
4554         _cylinderMapper = vtkPolyDataMapper::New();
4555         _cylinderMapper->SetInput( _vtkcylinder->GetOutput() );
4556         _cylinderActor  = vtkActor::New();
4557         _cylinderActor->SetMapper(_cylinderMapper);
4558         _cylinderActor->SetOrigin(0, 0, 0);
4559         _cylinderActor->SetPosition(0, 0, 0);
4560         _cylinderActor->GetProperty()->SetColor(1, 0, 0);
4561         _cylinderActor->SetUserTransform( _modelCylinder->GetVtkTransform() );          
4562
4563
4564 }
4565
4566 //-------------------------------------------------------------------
4567 void wxPanelCuttingImageData::CreateModel()
4568 {
4569         _modelCube              = new figureCuttingCubeModel();
4570         _modelSphere    = new figureCuttingSphereModel();
4571         _modelCylinder  = new figureCuttingCylinderModel();
4572
4573 //      _modelCube->SetVtkTransform( _modelCube->GetVtkTransform()                      );
4574 //      _modelSphere->SetVtkTransform( _modelSphere->GetVtkTransform()          );
4575 //      _modelCylinder->SetVtkTransform( _modelCylinder->GetVtkTransform()      );
4576 }
4577
4578 //-------------------------------------------------------------------
4579
4580 void wxPanelCuttingImageData::InitHistogramme()
4581 {
4582         double rangeA[2];
4583         if (_imageData==NULL)
4584         {
4585                 rangeA[1]=1;
4586         } else {
4587                 _imageData->GetScalarRange(rangeA);
4588         }
4589         _xyplot->RemoveAllInputs();
4590 /*
4591         if ( _histogrammeVector!=NULL )
4592         {
4593                 _histogrammeVector -> Delete();
4594         }
4595 */
4596         _histogrammeVector =  vtkImageData::New();
4597     _histogrammeVector -> SetDimensions ( (int)(rangeA[1]),1,1 );
4598     _histogrammeVector -> SetScalarTypeToUnsignedShort();
4599     _histogrammeVector -> AllocateScalars();    
4600     _histogrammeVector -> Update(); 
4601         
4602         unsigned short *p_vol = (unsigned short*)_histogrammeVector->GetScalarPointer(0,0,0);
4603         int i,size = (int) (rangeA[1]);
4604         for (i=0; i < size; i++)
4605         {
4606                 *p_vol=0;
4607                 p_vol++;
4608         }
4609         _xyplot->SetXRange(0, rangeA[1]);
4610         _xyplot->SetYRange(0, 10);
4611         _xyplot->AddInput( _histogrammeVector );
4612 }
4613
4614 //-------------------------------------------------------------------
4615 wxWindow *wxPanelCuttingImageData::CreatePlotHistogrammeInterface()
4616 {
4617         _xyplot = vtkXYPlotActor::New();
4618         InitHistogramme();
4619         _xyplot->GetPositionCoordinate()->SetValue(0.00, 0.00, 0);
4620         _xyplot->GetPosition2Coordinate()->SetValue(1.0, 1.00, 0); //relative to Position
4621         _xyplot->SetXValuesToArcLength();
4622         _xyplot->SetNumberOfXLabels(6);
4623
4624         _xyplot->SetTitle("Histogramme");
4625         _xyplot->SetXTitle("Gray level");
4626         _xyplot->SetYTitle("Occurrences ");
4627         _xyplot->GetProperty()->SetColor(1, 0, 0);
4628         _xyplot->GetProperty()->SetPointSize(2);
4629         vtkTextProperty *tprop = _xyplot->GetTitleTextProperty();
4630         tprop->SetColor( 1,0,1 );
4631         tprop->BoldOff ();
4632         _xyplot->SetAxisTitleTextProperty(tprop);
4633         _xyplot->SetAxisLabelTextProperty(tprop);
4634         _xyplot->PlotPointsOn();
4635         _xyplot->GetProperty()->SetPointSize(3);
4636
4637         _wxvtkbaseView = new wxVtkBaseView(this);
4638         _wxvtkbaseView->Configure();
4639
4640         _renplotter = vtkRenderer::New();
4641         vtkRenderWindow *renWin = _wxvtkbaseView->GetRenWin();
4642         renWin->AddRenderer( _renplotter );
4643         _renplotter->AddActor2D( _xyplot );
4644
4645         return _wxvtkbaseView->GetWxVTKRenderWindowInteractor();
4646 }
4647
4648 //-------------------------------------------------------------------
4649
4650 void wxPanelCuttingImageData::CreateInterface()
4651 {
4652         SetSize(300,500);
4653         wxBoxSizer      *topsizer               = new wxBoxSizer(wxVERTICAL);   // Principal sizer
4654
4655         wxBoxSizer              *sizerH0        = new wxBoxSizer(wxHORIZONTAL   );  // type of segmentation figure
4656         wxBoxSizer          *sizerH2    = new wxBoxSizer(wxHORIZONTAL   );      // scale
4657         wxBoxSizer              *sizerH3        = new wxBoxSizer(wxHORIZONTAL   );      // rotation
4658         wxBoxSizer              *sizerH4        = new wxBoxSizer(wxHORIZONTAL   );  // intern extern
4659         wxBoxSizer              *sizerH5        = new wxBoxSizer(wxHORIZONTAL   );  // Isovalue
4660         wxBoxSizer              *sizerH6        = new wxBoxSizer(wxHORIZONTAL   );  // Buttons
4661         wxFlexGridSizer *sizerH7        = new wxFlexGridSizer(2                 );  // Volumic information 
4662
4663         
4664         _typeFig        = new wxChoice(this,-1);
4665         _opacityFig     = new wxSlider(this,-1,100,0,100, wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4666
4667         _scaleX         = new wxSlider(this,-1,6,0,500  , wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4668         _scaleY         = new wxSlider(this,-1,20,0,500 , wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4669         _scaleZ         = new wxSlider(this,-1,7,0,500  , wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4670
4671         _rotationX      = new wxSlider(this,-1,0,-360,360, wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4672         _rotationY      = new wxSlider(this,-1,0,-360,360, wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4673         _rotationZ      = new wxSlider(this,-1,0,-360,360, wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4674
4675         _volIntern              = new wxRadioButton(this,-1, _T("Volume intern " ));
4676         _volExtern              = new wxRadioButton(this,-1, _T("Volume extern " ));
4677
4678         _histogrammeAccumulated = new wxCheckBox(this,-1,_T("Histogramme accumulated"));
4679
4680         _isoValue                               = new wxSlider(this,-1, 200, 0,2000, wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4681         _valueBeforeIsoValue    = new wxSlider(this,-1,-1,-1,2000, wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4682         _valueAfterIsoValue             = new wxSlider(this,-1,-1,-1,2000, wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4683
4684         wxButton *btnExtract    = new wxButton(this, -1,_T("Extract"));
4685
4686         _infoToVo       = new wxStaticText(this,-1,_T("########################"));
4687         _infoSuVoA      = new wxStaticText(this,-1,_T("############"));
4688         _infoSuVo       = new wxStaticText(this,-1,_T("############"));
4689         _infoPixLe      = new wxStaticText(this,-1,_T("############"));
4690         _infoPixHi      = new wxStaticText(this,-1,_T("############"));
4691
4692
4693         
4694
4695         _typeFig->Append(_T("Cylindre"));
4696         _typeFig->Append(_T("Cube"));
4697         _typeFig->Append(_T("Sphere"));
4698         _typeFig->SetSelection(0);
4699         _volIntern->SetValue(true);
4700
4701         Connect(_typeFig->GetId()                               , wxEVT_COMMAND_CHOICE_SELECTED         , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTypeFig ); 
4702
4703         Connect(_opacityFig->GetId()                    , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnOpacityFig ); 
4704         Connect(_rotationX->GetId()                             , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
4705         Connect(_rotationY->GetId()                             , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
4706         Connect(_rotationZ->GetId()                             , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
4707         Connect(_scaleX->GetId()                                , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
4708         Connect(_scaleY->GetId()                                , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
4709         Connect(_scaleZ->GetId()                                , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
4710         Connect(btnExtract->GetId()                             , wxEVT_COMMAND_BUTTON_CLICKED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnExtract   ); 
4711          
4712
4713 //      wxStaticText *text=new wxStaticText(this,-1, " ");
4714
4715         sizerH0 -> Add( new wxStaticText(this,-1, _T("Fig. Type:   "),wxDefaultPosition, wxSize(50,20)) ,1,wxALL  ,0);
4716         sizerH0 -> Add( _typeFig                ,1,wxALL  ,0);
4717         sizerH0 -> Add( _opacityFig             ,1,wxALL|wxEXPAND  ,0);
4718
4719         sizerH2 -> Add( new wxStaticText(this,-1,_T("Scale :   "))              ,1,wxALL  ,0);
4720         sizerH2 -> Add( _scaleX         ,1,wxALL | wxEXPAND ,0 );
4721         sizerH2 -> Add( _scaleY         ,1,wxALL | wxEXPAND ,0 );
4722         sizerH2 -> Add( _scaleZ         ,1,wxALL | wxEXPAND ,0 );
4723
4724         sizerH3 -> Add( new wxStaticText(this,-1,_T("Rotation :   "))   ,1,wxALL  ,0);
4725         sizerH3 -> Add( _rotationX      ,1,wxALL | wxEXPAND ,0 );
4726         sizerH3 -> Add( _rotationY      ,1,wxALL | wxEXPAND ,0 );
4727         sizerH3 -> Add( _rotationZ      ,1,wxALL | wxEXPAND ,0 );
4728
4729
4730         sizerH4 -> Add( new wxStaticText(this,-1,_T("Intern / Extern :   "))    ,1,wxALL  ,0);
4731         sizerH4 -> Add( _volIntern                                              ,1,wxALL  ,0);
4732         sizerH4 -> Add( new wxStaticText(this,-1, _T(" "))      ,1,wxALL  ,0);
4733         sizerH4 -> Add( _volExtern                                              ,1,wxALL  ,0);
4734
4735         sizerH5 -> Add( new wxStaticText(this,-1,_T("Isovalue   "))     ,1,wxALL  ,0);
4736         sizerH5 -> Add( _isoValue                                               ,1,wxALL | wxEXPAND ,0 );
4737         sizerH5 -> Add( _valueBeforeIsoValue                    ,1,wxALL | wxEXPAND ,0 );
4738         sizerH5 -> Add( _valueAfterIsoValue                             ,1,wxALL | wxEXPAND ,0 );
4739
4740         sizerH6 -> Add( new wxStaticText(this,-1, _T(" "))              ,1,wxALL  ,0);
4741         sizerH6 -> Add( btnExtract      ,1,wxALL  ,0);
4742
4743         sizerH7 -> Add( new wxStaticText(this,-1,_T("Total Volume: "), wxDefaultPosition, wxSize(200,12))                       , 1 , wxALL  ,0);
4744         sizerH7 -> Add( _infoToVo                                                                               , 1 , wxALL  ,0);
4745         sizerH7 -> Add( new wxStaticText(this,-1,_T("SubVolume:   "), wxDefaultPosition, wxSize(200,12) )               , 1 , wxALL  ,0);
4746         sizerH7 -> Add( _infoSuVo                                                                               , 1 , wxALL  ,0);
4747         sizerH7 -> Add( new wxStaticText(this,-1,_T("SubVolume (ana.): "), wxDefaultPosition, wxSize(200,12))   , 1 , wxALL  ,0);
4748         sizerH7 -> Add( _infoSuVoA                                                                              , 1 , wxALL  ,0);
4749         sizerH7 -> Add( new wxStaticText(this,-1,_T("Pix < isovalue:   ") , wxDefaultPosition, wxSize(200,12))  , 1 , wxALL  ,0);
4750         sizerH7 -> Add( _infoPixLe                                                                              , 1 , wxALL  ,0);
4751         sizerH7 -> Add( new wxStaticText(this,-1,_T("Pix > isovalue: "), wxDefaultPosition, wxSize(200,12))     , 1 , wxALL  ,0);
4752         sizerH7 -> Add( _infoPixHi                                                                              , 1 , wxALL  ,0);
4753 //      sizerH7 -> SetMinSize(300, 120);
4754
4755         // Figure type
4756         topsizer -> Add( sizerH0 ,1,wxALL|wxEXPAND  ,0);
4757
4758         // Scale
4759         topsizer -> Add( sizerH2 ,1,wxALL|wxEXPAND  ,0);
4760
4761         // Rotation
4762         topsizer -> Add( sizerH3 ,1,wxALL|wxEXPAND  ,0);
4763
4764         // Intern / Extern
4765         topsizer -> Add( sizerH4 ,1,wxALL  ,0);
4766
4767
4768         // Isovalue limite
4769         topsizer -> Add( sizerH5 ,1,wxALL |wxEXPAND ,0);
4770
4771         // btn Extraction
4772         topsizer -> Add( sizerH6        , 1 , wxALL  ,0);
4773
4774         // Histograme
4775         topsizer -> Add( _histogrammeAccumulated ,1,  wxALL  ,0);
4776
4777         // Volumic information
4778         topsizer -> Add( sizerH7                                , 1 , wxALL|wxEXPAND   ,0);
4779
4780
4781
4782 //    wxBoxSizer *sizerHor = new wxBoxSizer(wxHORIZONTAL);
4783     wxBoxSizer *sizerHor = new wxBoxSizer(wxVERTICAL);
4784         sizerHor -> Add( topsizer                               , 1 , wxALL | wxEXPAND  ,0);
4785
4786
4787         wxWindow *panelPlotHistogramme = CreatePlotHistogrammeInterface();
4788         sizerHor -> Add( panelPlotHistogramme   , 1 , wxGROW  ,0);
4789
4790
4791         this->SetAutoLayout(true);
4792         this->SetSizer( sizerHor );      
4793         this->Layout(); 
4794 //EEDxx2.4
4795 //      this->FitInside();
4796 }
4797
4798 //-------------------------------------------------------------------
4799
4800 void wxPanelCuttingImageData::OnExtract(wxCommandEvent& event)
4801 {
4802         wxBusyCursor wait;
4803
4804         bool                    inside;
4805         bool                    volInt, volExt;
4806         int                             xx,yy,zz;
4807         unsigned short  *pOrg;
4808         unsigned short  *p_histogramme;
4809         int                             dim[3];
4810         double                  spc[3];
4811         long int                contAfter = 0;
4812         long int                contBefor = 0;
4813
4814         double min=999999999;
4815         double max=-999999999;
4816
4817         volExt=_volExtern->GetValue();
4818         volInt=_volIntern->GetValue();
4819         int isoValue                = _isoValue->GetValue();
4820         int valueBeforeIsoValue = _valueBeforeIsoValue->GetValue(); 
4821         int valueAfterIsoValue  = _valueAfterIsoValue ->GetValue(); 
4822
4823         InitHistogramme();
4824         p_histogramme = (unsigned short*)_histogrammeVector->GetScalarPointer(0,0,0);
4825
4826         _imageData->GetDimensions(dim);    
4827         _imageData->GetSpacing(spc);    
4828         _actualCuttingModel->CalculeInversMatrix();
4829
4830         for (xx=0;xx<dim[0]; xx++)
4831         {
4832                 for (yy=0;yy<dim[1]; yy++)
4833                 {
4834                         for (zz=0;zz<dim[2];zz++)
4835                         {
4836                                 inside=_actualCuttingModel->IfPointInside(xx,yy,zz);
4837                                 if (  ((inside==true)&&(volInt==true)) || ((!inside==true)&&(volExt==true)) )
4838                                 {
4839                                         pOrg=(unsigned short*)_imageData->GetScalarPointer (xx,yy,zz); 
4840
4841                                         if ((*pOrg)<isoValue)
4842                                         {
4843                                                 contBefor++;
4844                                                 if (valueBeforeIsoValue!=-1)
4845                                                 {
4846                                                         *pOrg=valueBeforeIsoValue;
4847                                                 }
4848                                         } else {
4849                                                 contAfter++;
4850                                                 if (valueAfterIsoValue!=-1)
4851                                                 {
4852                                                         *pOrg=valueAfterIsoValue;
4853                                                 } // if
4854                                         } // if isovalue
4855
4856                                         p_histogramme[*pOrg]++;
4857                                         if (*pOrg<min) min=*pOrg; 
4858                                         if (*pOrg>max) max=*pOrg; 
4859                                 } // if inside
4860                         } // for zz
4861                 } // for yy
4862         } // for xx
4863
4864
4865         // Information
4866         wxString infoToVo;
4867         wxString infoSuVo;
4868         wxString infoSuVoA;
4869         wxString infoPixLe;
4870         wxString infoPixHi;
4871
4872         double volumeUnit = spc[0]*spc[1]*spc[2];
4873         long int totalSubVolume = contBefor + contAfter;
4874         double contBeforPorc    = 100*(double)contBefor/(double)totalSubVolume;
4875         double contAfterPorc    = 100*(double)contAfter/(double)totalSubVolume;
4876         infoToVo.Printf(_T("%dx%dx%d = %d"),dim[0],dim[1],dim[2], dim[0]*dim[1]*dim[2] );
4877         infoSuVo.Printf(_T("%ld") , totalSubVolume);
4878         infoSuVoA.Printf(_T("%.2f"), _actualCuttingModel->GetTheoricVolume() );
4879         infoPixLe.Printf(_T("%ld pix.   (%.2f %s)  -  %.2f mm^3"),contBefor, contBeforPorc ,_T("%"),contBefor*volumeUnit);
4880         infoPixHi.Printf(_T("%ld pix.   (%.2f %s)  -  %.2f mm^3"),contAfter, contAfterPorc ,_T("%"),contAfter*volumeUnit);
4881
4882         _infoToVo->SetLabel(infoToVo);
4883         _infoSuVo->SetLabel(infoSuVo);
4884         _infoSuVoA->SetLabel(infoSuVoA);
4885         _infoPixLe->SetLabel(infoPixLe);
4886         _infoPixHi->SetLabel(infoPixHi);
4887
4888         // Histogram
4889         if ( _histogrammeAccumulated->GetValue()==true )
4890         {
4891                 int dimHist[3];
4892                 _histogrammeVector -> GetDimensions ( dimHist );
4893
4894                 int i,size=dimHist[0];
4895                 for (i=1; i<=size; i++)
4896                 {
4897                         p_histogramme[i] = p_histogramme[i] + p_histogramme[i-1];
4898                 }
4899         }
4900         double range[2];
4901         _histogrammeVector->Update();
4902         _histogrammeVector->GetScalarRange(range);
4903         _xyplot->SetYRange( 0   , range[1]      );
4904         _xyplot->SetXRange( min , max           );
4905
4906         _vtkclipping3Ddataviewer->RefreshSurface();
4907         _wxvtkbaseView->Refresh();
4908
4909 //      _wxvtkbaseView->RefreshView();
4910         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
4911         _wxvtkbaseView->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
4912 }
4913
4914
4915 //-------------------------------------------------------------------
4916 void wxPanelCuttingImageData::OnTypeFig(wxCommandEvent& event)
4917 {
4918         _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _actualActor );
4919
4920         if (_typeFig->GetSelection()==0){
4921                 _actualCuttingModel=_modelCylinder;
4922                 _actualActor=_cylinderActor;
4923         }
4924         if (_typeFig->GetSelection()==1){
4925                 _actualCuttingModel=_modelCube;
4926                 _actualActor=_cubeActor;
4927         }
4928         if (_typeFig->GetSelection()==2){
4929                 _actualCuttingModel=_modelSphere;
4930                 _actualActor=_sphereActor;
4931         }
4932         _wxvtk3Dbaseview->GetRenderer()->AddActor( _actualActor );
4933         RefreshOpacity();
4934         RefreshView();
4935 }
4936
4937 //-------------------------------------------------------------------
4938 void wxPanelCuttingImageData::RefreshOpacity()
4939 {
4940         double op= _opacityFig->GetValue()/100.0;
4941         _actualActor->GetProperty()->SetOpacity( op );
4942 }
4943
4944 //-------------------------------------------------------------------
4945 void wxPanelCuttingImageData::OnOpacityFig(wxScrollEvent& event)
4946 {
4947         RefreshOpacity();
4948         Refresh();
4949 }
4950 //-------------------------------------------------------------------
4951 void wxPanelCuttingImageData::RefreshView()
4952 {
4953         SetParamsOfTransformation( );
4954         Refresh();
4955 }
4956 //-------------------------------------------------------------------
4957 void wxPanelCuttingImageData::Refresh()
4958 {
4959         _wxvtk3Dbaseview->Refresh();
4960 }
4961
4962 //-------------------------------------------------------------------
4963 void wxPanelCuttingImageData::SetParamsOfTransformation( )
4964 {
4965         double spc[3];
4966         vtkImageData *vtkimagedata = _vtkmprbasedata->GetImageData();
4967         vtkimagedata->GetSpacing(spc);
4968         int px = (int) (_vtkmprbasedata->GetX() );
4969         int py = (int) (_vtkmprbasedata->GetY() );
4970         int pz = (int) (_vtkmprbasedata->GetZ() );
4971         int sx = (int) (_scaleX->GetValue() * spc[0] );
4972         int sy = (int) (_scaleY->GetValue() * spc[1] );
4973         int sz = (int) (_scaleZ->GetValue() * spc[2] );
4974         _actualCuttingModel     -> SetScale             ( sx    , sy    , sz );
4975         _actualCuttingModel     -> SetPosition  ( px    , py , pz       );
4976         _actualCuttingModel     -> SetRotation  ( _rotationX->GetValue()        , _rotationY->GetValue() , _rotationZ->GetValue()       );
4977         _actualCuttingModel     -> SetSpacing   ( spc[0]        , spc[1]    , spc[2] );
4978         _actualCuttingModel     -> CalculeMatrix();
4979 }
4980
4981 //-------------------------------------------------------------------
4982
4983 void wxPanelCuttingImageData::OnTransform(wxScrollEvent& event)
4984 {
4985         RefreshView();
4986 }
4987
4988 //-------------------------------------------------------------------
4989 void wxPanelCuttingImageData::SetVtkMPRBaseData( vtkMPRBaseData *vtkmprbasedata )
4990 {
4991         _vtkmprbasedata = vtkmprbasedata;
4992         _imageData              = _vtkmprbasedata->GetImageData();
4993 }
4994
4995 //-------------------------------------------------------------------
4996
4997 void wxPanelCuttingImageData::Configure()
4998 {
4999         _actualCuttingModel=_modelCylinder;
5000         _actualActor=_cylinderActor;
5001         _wxvtk3Dbaseview->GetRenderer()->AddActor( _actualActor );
5002         SetParamsOfTransformation();
5003         RefreshView();
5004 }
5005
5006
5007
5008 //-------------------------------------------------------------------
5009 //-------------------------------------------------------------------
5010 //-------------------------------------------------------------------
5011
5012 /*
5013 BEGIN_EVENT_TABLE( wxWidgetMesure2D , wxSplitterWindow )
5014         EVT_MENU( 12121, wxWidgetMesure2D::OnRefreshView )
5015 END_EVENT_TABLE( );
5016 */
5017 //-------------------------------------------------------------------
5018
5019 wxWidgetMesure2D::wxWidgetMesure2D( wxWindow *parent )
5020 : wxSplitterWindow( parent , -1)
5021 {
5022 // EED 27 oct 2007
5023         this->SplitHorizontally( new wxPanel(this,-1) ,  new wxPanel(this,-1), 2 );
5024         this->SetMinimumPaneSize(50);
5025 }
5026 //-------------------------------------------------------------------
5027 wxWidgetMesure2D::~wxWidgetMesure2D()
5028 {
5029 }
5030 //-------------------------------------------------------------------
5031 wxWindow *wxWidgetMesure2D::CreateWin1a(wxWindow *parent) // virtual
5032 {
5033         wxPanel *panel = new wxPanel(parent,-1);
5034
5035         _cb_messuretool  = new wxCheckBox(panel,-1,_T("Active messure tool     ")); 
5036         _cb_mt_visible   = new wxCheckBox(panel,-1,_T("Visibles    ")); 
5037         _cb_closeContour = new wxCheckBox(panel,-1,_T("Close/Open    ")); 
5038         _cb_visibleText  = new wxCheckBox(panel,-1,_T("Information    ")); 
5039
5040         _cb_mt_visible->SetValue(true);
5041         _cb_closeContour->SetValue(true);
5042         _cb_visibleText->SetValue(true);
5043
5044         wxFlexGridSizer *sizer = new wxFlexGridSizer(4);
5045
5046         sizer->Add(_cb_messuretool);
5047         sizer->Add(_cb_mt_visible);
5048         sizer->Add(_cb_closeContour);
5049         sizer->Add(_cb_visibleText);
5050
5051         panel->SetAutoLayout(true);
5052         panel->SetSizer(sizer);
5053         panel->SetSize(400,30);
5054         panel->Layout();
5055 //EEDxx2.4
5056 //      panel->FitInside();
5057
5058         Connect(_cb_messuretool->GetId()  , wxEVT_COMMAND_CHECKBOX_CLICKED        , (wxObjectEventFunction) &wxWidgetMesure2D::OnActiveMessureTool      );
5059         Connect(_cb_mt_visible->GetId()   , wxEVT_COMMAND_CHECKBOX_CLICKED        , (wxObjectEventFunction) &wxWidgetMesure2D::OnVisibleMessureTool     );
5060         Connect(_cb_closeContour->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED        , (wxObjectEventFunction) &wxWidgetMesure2D::OnCloseContour           );
5061         Connect(_cb_visibleText->GetId()  , wxEVT_COMMAND_CHECKBOX_CLICKED        , (wxObjectEventFunction) &wxWidgetMesure2D::OnVisibleInformation     );
5062
5063         return panel;
5064 }
5065
5066 //-------------------------------------------------------------------
5067 void wxWidgetMesure2D::ConfigureA(wxVtk2DBaseView *wxvtk2Dbaseview) // virtual
5068 {
5069         _wxvtk2Dbaseview = wxvtk2Dbaseview;
5070
5071         // Contorno 1
5072         _manContourControl_1    = new manualContourControler();
5073         _mContourModel_1                = new manualContourModel();
5074         _mViewContour_1                 = new manualViewContour();
5075         _mViewContour_1->SetModel( _mContourModel_1 );
5076         _mViewContour_1->SetWxVtkBaseView( _wxvtk2Dbaseview );
5077         _mViewContour_1->SetRange( 1 );
5078
5079 // EED 3 oct 2006
5080 //      double spc[3];
5081 //      _wxvtk2Dbaseview->GetSpacing( spc );
5082 //      _mViewContour_1->SetSpacing( spc );
5083
5084
5085
5086         _manContourControl_1->SetZ( 1000 );
5087         _manContourControl_1->SetModelView( _mContourModel_1 , _mViewContour_1 );
5088         _wxvtk2Dbaseview->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _manContourControl_1 );
5089         _manContourControl_1->CreateNewManualContour();
5090         _manContourControl_1->SetActive( false );
5091         _mViewContour_1->RefreshContour();
5092
5093 //EED 27 Oct 2007
5094         
5095 //      this->ReplaceWindow( this->GetWindow1() ,  CreateWin1a(this) );
5096 //      this->ReplaceWindow( this->GetWindow2() ,  _wxvtk2Dbaseview->GetWxVTKRenderWindowInteractor() );
5097 //      CreateWin1a(this->GetWindow1() );
5098
5099         wxBoxSizer *sizerA = new wxBoxSizer(wxHORIZONTAL);      
5100         sizerA->Add(  CreateWin1a( this->GetWindow1()) ,1, wxGROW );
5101         this->GetWindow1()->SetSizer(sizerA);
5102         this->SetAutoLayout(true);
5103         this->Layout();
5104
5105         wxBoxSizer *sizerB = new wxBoxSizer(wxHORIZONTAL);      
5106         sizerB->Add(  _wxvtk2Dbaseview->GetWxVTKRenderWindowInteractor()  ,1, wxGROW );
5107         this->GetWindow2()->SetSizer(sizerB);
5108         this->SetAutoLayout(true);
5109         this->Layout();
5110
5111
5112 //      this->SplitHorizontally( CreateWin1a(this) , _wxvtk2Dbaseview->GetWxVTKRenderWindowInteractor() , 2 );
5113
5114
5115 //EEDxx2.4 
5116 //      this->FitInside();
5117 }
5118
5119
5120 //-------------------------------------------------------------------
5121 void wxWidgetMesure2D::ActiveMessureTool(bool ok)
5122 {
5123         _wxvtk2Dbaseview->GetInteractorStyleBaseView()->SetActiveAllInteractors(!ok);
5124         _manContourControl_1->SetActive( ok );
5125 }
5126
5127 //-------------------------------------------------------------------
5128 void wxWidgetMesure2D::OnActiveMessureTool(wxCommandEvent& event)
5129 {
5130         ActiveMessureTool( _cb_messuretool->GetValue() );
5131         if ( _cb_messuretool->GetValue() == true )
5132         {
5133                 _cb_mt_visible->SetValue(true);
5134                 _mViewContour_1->SetVisible( _cb_mt_visible->GetValue() );
5135                 _cb_closeContour->Enable(true);
5136                 _cb_visibleText->Enable(true);
5137         } else{
5138                 _cb_closeContour->Enable(false);
5139                 _cb_visibleText->Enable(false);
5140         }
5141         _wxvtk2Dbaseview->Refresh();
5142         _wxvtk2Dbaseview->RefreshView();
5143 }
5144
5145 //-------------------------------------------------------------------
5146 void wxWidgetMesure2D::OnVisibleMessureTool(wxCommandEvent& event)
5147 {
5148         _cb_messuretool->SetValue( _cb_mt_visible->GetValue() );
5149         if (_cb_messuretool->GetValue()==true)
5150         {
5151                 _cb_closeContour->Enable(true);
5152                 _cb_visibleText->Enable(true);
5153         }
5154         ActiveMessureTool( _cb_messuretool->GetValue() );       
5155         _mViewContour_1->SetVisible( _cb_mt_visible->GetValue() );
5156         _mViewContour_1->Refresh();
5157         _wxvtk2Dbaseview->Refresh();
5158         _wxvtk2Dbaseview->RefreshView();
5159 }
5160
5161 //-------------------------------------------------------------------
5162 void wxWidgetMesure2D::OnCloseContour(wxCommandEvent& event)
5163 {
5164         _mContourModel_1->SetCloseContour( _cb_closeContour->GetValue() );
5165         _mViewContour_1->Refresh();
5166         _wxvtk2Dbaseview->Refresh();
5167         _wxvtk2Dbaseview->RefreshView();
5168
5169 }
5170 //-------------------------------------------------------------------
5171 void wxWidgetMesure2D::OnVisibleInformation(wxCommandEvent& event)
5172 {
5173         _mViewContour_1->SetShowText( _cb_visibleText->GetValue() );
5174         _mViewContour_1->Refresh();
5175         _wxvtk2Dbaseview->Refresh();
5176         _wxvtk2Dbaseview->RefreshView();
5177 }
5178 //-------------------------------------------------------------------
5179 void wxWidgetMesure2D::SetMesureScale(double mesureScale)
5180 {
5181         _mViewContour_1->SetMesureScale(mesureScale);
5182 }
5183 //-------------------------------------------------------------------
5184 manualContourModel*     wxWidgetMesure2D::GetManualContourModel()
5185 {
5186         return _mContourModel_1;
5187 }
5188
5189 //-------------------------------------------------------------------
5190 //-------------------------------------------------------------------
5191 //-------------------------------------------------------------------
5192
5193 wxWidgetMesure2D_Plane::wxWidgetMesure2D_Plane(wxWindow *parent)
5194 : wxWidgetMesure2D(parent)
5195 {
5196         // Circle 1
5197         _ptsCircle1             = NULL;
5198         _circle1Actor   = NULL;
5199         _circle1Mapper  = NULL;
5200     _pdCircle1          = NULL;
5201         // Circle 2
5202         _ptsCircle2             = NULL;
5203         _circle2Actor   = NULL;
5204         _circle2Mapper  = NULL;
5205     _pdCircle2          = NULL;
5206         // line reference 1
5207         _ptsLineRef1    = NULL;
5208         _lineRef1Actor  = NULL;
5209         _lineRef1Mapper = NULL;
5210     _pdLineRef1         = NULL;
5211         // line reference 2
5212         _ptsLineRef2    = NULL;
5213         _lineRef2Actor  = NULL;
5214         _lineRef2Mapper = NULL;
5215     _pdLineRef2         = NULL;
5216
5217 }
5218
5219 //-------------------------------------------------------------------
5220
5221 wxWidgetMesure2D_Plane::~wxWidgetMesure2D_Plane()
5222 {
5223         // Circle 1
5224     if (        _ptsCircle1             != NULL){       _ptsCircle1                     -> Delete(); }
5225     if (        _circle1Actor   != NULL){       _circle1Actor           -> Delete(); }
5226     if (        _circle1Mapper  != NULL){       _circle1Mapper          -> Delete(); }
5227     if (    _pdCircle1          != NULL){       _pdCircle1                      -> Delete(); }
5228         // Circle 2
5229     if (        _ptsCircle2             != NULL){       _ptsCircle2                     -> Delete(); }
5230     if (        _circle2Actor   != NULL){       _circle2Actor           -> Delete(); }
5231     if (        _circle2Mapper  != NULL){       _circle2Mapper          -> Delete(); }
5232     if (    _pdCircle2          != NULL){       _pdCircle2                      -> Delete(); }
5233         // line reference 1
5234     if (        _ptsLineRef1    != NULL){       _ptsLineRef1            -> Delete(); }
5235     if (        _lineRef1Actor  != NULL){       _lineRef1Actor          -> Delete(); }
5236     if (        _lineRef1Mapper != NULL){       _lineRef1Mapper         -> Delete(); }
5237      if (   _pdLineRef1         != NULL){       _pdLineRef1                     -> Delete(); }
5238         // line reference 2
5239     if (        _ptsLineRef2    != NULL){       _ptsLineRef2            -> Delete(); }
5240     if (        _lineRef2Actor  != NULL){       _lineRef2Actor          -> Delete(); }
5241     if (        _lineRef2Mapper != NULL){       _lineRef2Mapper         -> Delete(); }
5242     if (    _pdLineRef2         != NULL){       _pdLineRef2                     -> Delete(); }
5243 }
5244
5245 //-------------------------------------------------------------------
5246
5247 wxWindow *wxWidgetMesure2D_Plane::CreateWin1a(wxWindow *parent) // virtual
5248 {
5249         wxPanel *panel = new wxPanel(parent,-1);
5250
5251         _cb_circle              = new wxCheckBox(panel,-1,_T("Circle        ")); 
5252         _cb_line                = new wxCheckBox(panel,-1,_T("Rotation Axe ")); 
5253
5254
5255         wxBoxSizer *sizerA = new wxBoxSizer(wxHORIZONTAL);
5256         sizerA->Add(_cb_circle);
5257         sizerA->Add(_cb_line);
5258
5259
5260         wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
5261         sizer->Add( sizerA );
5262         sizer->Add( wxWidgetMesure2D::CreateWin1a(panel) );
5263
5264         panel->SetAutoLayout(true);
5265         panel->SetSizer(sizer);
5266         panel->SetSize(400,30);
5267         panel->Layout();
5268 //EEDxx2.4
5269 //      panel->FitInside();
5270
5271         Connect(_cb_line->GetId()        , wxEVT_COMMAND_CHECKBOX_CLICKED         , (wxObjectEventFunction) &wxWidgetMesure2D_Plane::OnActiveLine                       );
5272         Connect(_cb_circle->GetId()      , wxEVT_COMMAND_CHECKBOX_CLICKED         , (wxObjectEventFunction) &wxWidgetMesure2D_Plane::OnActiveCirlcle            );
5273
5274         return panel;
5275 }
5276
5277
5278 //-------------------------------------------------------------------
5279 void wxWidgetMesure2D_Plane::OnActiveCirlcle(wxCommandEvent& event)
5280 {
5281         SetVisibleCircle( _cb_circle->GetValue() );
5282         _wxvtk2Dbaseview->RefreshView();
5283 }
5284
5285 //-------------------------------------------------------------------
5286 void wxWidgetMesure2D_Plane::SetVisibleCircle( bool ok )
5287 {
5288         double opacity;
5289         if (ok==true)
5290         {
5291                 opacity=1;
5292         } else {
5293                 opacity=0;
5294         } 
5295         _lineRef1Actor->GetProperty()->SetOpacity( opacity );
5296         _lineRef2Actor->GetProperty()->SetOpacity( opacity );
5297         _circle1Actor->GetProperty()->SetOpacity( opacity );
5298         _circle2Actor->GetProperty()->SetOpacity( opacity );
5299 }
5300 //-------------------------------------------------------------------
5301 void wxWidgetMesure2D_Plane::OnActiveLine(wxCommandEvent& event)
5302 {
5303         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)_wxvtk2Dbaseview;
5304         vtkplane2Dview->SetVisibleLine( _cb_line->GetValue() );
5305         _wxvtk2Dbaseview->RefreshView();
5306 }
5307
5308
5309 //-------------------------------------------------------------------
5310 void wxWidgetMesure2D_Plane::ConfigureA(wxVtk2DBaseView *wxvtk2Dbaseview) // virtual
5311 {
5312         wxWidgetMesure2D::ConfigureA(wxvtk2Dbaseview);
5313         CircleLine();
5314         ConfigureCircleLine();
5315         SetVisibleCircle(false);        
5316 }
5317
5318
5319 //-------------------------------------------------------------------
5320 void wxWidgetMesure2D_Plane::ConfigureCircleLine()
5321 {
5322         double ang;
5323
5324         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)_wxvtk2Dbaseview;
5325         int sizeIma = vtkplane2Dview->GetImgSize();
5326
5327         double i,maxPts=20;
5328         double k=(360/(maxPts-1)) * (3.1416/180);
5329         double x,y,r1=5,r2=10,r3=15;
5330         for (i=0;i<maxPts;i++)
5331         {
5332                 x=cos( k*i ) ;
5333                 y=sin( k*i ) ;
5334                 _ptsCircle1->SetPoint( (int)i , (sizeIma/2) + x*r1      , (sizeIma/2) + y*r1    , 1 );
5335                 _ptsCircle2->SetPoint( (int)i , (sizeIma/2) + x*r2      , (sizeIma/2) + y*r2    , 1 );
5336         }
5337
5338         //
5339         ang=(45) * (3.1416/180);
5340         x=cos( ang ) ;
5341         y=sin( ang ) ;
5342         _ptsLineRef1->SetPoint( 0 , (sizeIma/2) + x*r3  , (sizeIma/2) + y*r3    , 1 );
5343         
5344         ang=(45+180) * (3.1416/180);
5345         x=cos( ang ) ;
5346         y=sin( ang ) ;
5347         _ptsLineRef1->SetPoint( 1 , (sizeIma/2) + x*r3  , (sizeIma/2) + y*r3    , 1 );
5348
5349         //
5350         ang=(135) * (3.1416/180);
5351         x=cos( ang ) ;
5352         y=sin( ang ) ;
5353         _ptsLineRef2->SetPoint( 0 , (sizeIma/2) + x*r3  , (sizeIma/2) + y*r3    , 1 );
5354         
5355         ang=(135+180) * (3.1416/180);
5356         x=cos( ang ) ;
5357         y=sin( ang ) ;
5358         _ptsLineRef2->SetPoint( 1 , (sizeIma/2) + x*r3  , (sizeIma/2) + y*r3    , 1 );
5359 }
5360
5361
5362
5363 //-------------------------------------------------------------------
5364 void wxWidgetMesure2D_Plane::CircleLine()
5365 {
5366         int i,maxPts=20;
5367         vtkCellArray *lines;
5368
5369         vtkImageViewer2_XYZ *imageViewer2XYZ = _wxvtk2Dbaseview->_imageViewer2XYZ;
5370         
5371
5372 // Circle 1 Horizontal
5373         _ptsCircle1 = vtkPoints::New();
5374         _ptsCircle1->SetNumberOfPoints(maxPts);
5375         lines = vtkCellArray::New();
5376         lines->InsertNextCell(maxPts);
5377         for (i=0;i<maxPts;i++)
5378         {
5379                 lines->InsertCellPoint(i);
5380                 _ptsCircle1->SetPoint(i, 0      , 0     , 0 );
5381         }
5382         lines->InsertCellPoint(0);
5383         _ptsCircle1->SetPoint(0, -1000  , -1000 , -1000 );
5384         _ptsCircle1->SetPoint(1,  1000  ,  1000 ,  1000 );
5385
5386         _pdCircle1 = vtkPolyData::New();
5387     _pdCircle1->SetPoints( _ptsCircle1 );
5388     _pdCircle1->SetLines( lines );
5389         lines->Delete();  //do not delete lines ??
5390         _circle1Actor                                   =       vtkActor::New();
5391     _circle1Mapper                                      =       vtkPolyDataMapper::New();
5392         _circle1Mapper->SetInput(_pdCircle1);
5393         _circle1Mapper->ImmediateModeRenderingOn();
5394         _circle1Actor->SetMapper(_circle1Mapper);
5395         _circle1Actor->GetProperty()->BackfaceCullingOn();
5396         _circle1Actor->GetProperty()->SetDiffuseColor(0,0,1);
5397         _circle1Actor->GetProperty()->SetLineWidth(2);
5398     imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _circle1Actor );
5399
5400 // Circle 2 Horizontal
5401         _ptsCircle2 = vtkPoints::New();
5402         _ptsCircle2->SetNumberOfPoints(maxPts);
5403         lines = vtkCellArray::New();
5404         lines->InsertNextCell(maxPts);
5405         for (i=0;i<maxPts;i++)
5406         {
5407                 lines->InsertCellPoint(i);
5408                 _ptsCircle2->SetPoint(i, 0      , 0     , 0 );
5409         }
5410         _ptsCircle2->SetPoint(0, -1000  , -1000 , -1000 );
5411         _ptsCircle2->SetPoint(1,  1000  ,  1000 ,  1000 );
5412
5413         _pdCircle2 = vtkPolyData::New();
5414     _pdCircle2->SetPoints( _ptsCircle2 );
5415     _pdCircle2->SetLines( lines );
5416         lines->Delete();  //do not delete lines ??
5417         _circle2Actor                                   =       vtkActor::New();
5418     _circle2Mapper                                      =       vtkPolyDataMapper::New();
5419         _circle2Mapper->SetInput(_pdCircle2);
5420         _circle2Mapper->ImmediateModeRenderingOn();
5421         _circle2Actor->SetMapper(_circle2Mapper);
5422         _circle2Actor->GetProperty()->BackfaceCullingOn();
5423         _circle2Actor->GetProperty()->SetDiffuseColor(0,0,1);
5424         _circle2Actor->GetProperty()->SetLineWidth(2);
5425     imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _circle2Actor );
5426
5427 // Line Referance 1
5428         _ptsLineRef1 = vtkPoints::New();
5429         _ptsLineRef1->SetNumberOfPoints(2);
5430         _ptsLineRef1->SetPoint(0, -1000 , -1000 , -1000 );
5431         _ptsLineRef1->SetPoint(1,  1000 ,  1000 ,  1000 );
5432         lines = vtkCellArray::New();
5433         lines->InsertNextCell(2);
5434         lines->InsertCellPoint(0);
5435         lines->InsertCellPoint(1);
5436
5437         _pdLineRef1 = vtkPolyData::New();
5438     _pdLineRef1->SetPoints( _ptsLineRef1 );
5439     _pdLineRef1->SetLines( lines );
5440         lines->Delete();  //do not delete lines ??
5441         _lineRef1Actor                                  =       vtkActor::New();
5442     _lineRef1Mapper                                     =       vtkPolyDataMapper::New();
5443         _lineRef1Mapper->SetInput(_pdLineRef1);
5444         _lineRef1Mapper->ImmediateModeRenderingOn();
5445         _lineRef1Actor->SetMapper(_lineRef1Mapper);
5446         _lineRef1Actor->GetProperty()->BackfaceCullingOn();
5447         _lineRef1Actor->GetProperty()->SetDiffuseColor(0,0,1);
5448         _lineRef1Actor->GetProperty()->SetLineWidth(2);
5449     imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineRef1Actor );
5450
5451 // Line Referance 2
5452         _ptsLineRef2 = vtkPoints::New();
5453         _ptsLineRef2->SetNumberOfPoints(2);
5454         _ptsLineRef2->SetPoint(0, -1000 , -1000 , -1000 );
5455         _ptsLineRef2->SetPoint(1,  1000 ,  1000 ,  1000 );
5456         lines = vtkCellArray::New();
5457         lines->InsertNextCell(2);
5458         lines->InsertCellPoint(0);
5459         lines->InsertCellPoint(1);
5460
5461         _pdLineRef2 = vtkPolyData::New();
5462     _pdLineRef2->SetPoints( _ptsLineRef2 );
5463     _pdLineRef2->SetLines( lines );
5464         lines->Delete();  //do not delete lines ??
5465         _lineRef2Actor                                  =       vtkActor::New();
5466     _lineRef2Mapper                                     =       vtkPolyDataMapper::New();
5467         _lineRef2Mapper->SetInput(_pdLineRef2);
5468         _lineRef2Mapper->ImmediateModeRenderingOn();
5469         _lineRef2Actor->SetMapper(_lineRef2Mapper);
5470         _lineRef2Actor->GetProperty()->BackfaceCullingOn();
5471         _lineRef2Actor->GetProperty()->SetDiffuseColor(0,0,1);
5472         _lineRef2Actor->GetProperty()->SetLineWidth(2);
5473     imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineRef2Actor );
5474
5475
5476 }
5477
5478
5479 //-------------------------------------------------------------------
5480 //-------------------------------------------------------------------
5481 //-------------------------------------------------------------------
5482
5483 wxWidgetMesure2D_Plane_in_MPR::wxWidgetMesure2D_Plane_in_MPR(wxWindow *parent)
5484 :wxWidgetMesure2D_Plane(parent)
5485 {
5486         _vtkplane2Dview=NULL;
5487 }
5488
5489 //-------------------------------------------------------------------
5490
5491 wxWidgetMesure2D_Plane_in_MPR::~wxWidgetMesure2D_Plane_in_MPR()
5492 {
5493 }
5494 //-------------------------------------------------------------------
5495 void wxWidgetMesure2D_Plane_in_MPR::OnActiveLink(wxCommandEvent& event)
5496 {
5497         if (_vtkplane2Dview!=NULL)
5498         {
5499                 _vtkplane2Dview->SetActive( _cb_link->GetValue() );
5500                 _vtkplane2Dview->Refresh();
5501                 _vtkplane2Dview->RefreshView();
5502         }
5503 }
5504
5505
5506 //-------------------------------------------------------------------
5507 void wxWidgetMesure2D_Plane_in_MPR::SetActiveLink(bool ok)
5508 {
5509         _cb_link->SetValue(ok);
5510         if (_vtkplane2Dview!=NULL)
5511         {
5512                 _vtkplane2Dview->SetActive( _cb_link->GetValue() );
5513         }
5514 }
5515 //-------------------------------------------------------------------
5516
5517 void wxWidgetMesure2D_Plane_in_MPR::SetVtkPlane2DView(vtkPlane2DView *vtkplane2Dview)
5518 {
5519         _vtkplane2Dview = vtkplane2Dview;
5520 }
5521
5522 //-------------------------------------------------------------------
5523
5524 wxWindow *wxWidgetMesure2D_Plane_in_MPR::CreateWin1a(wxWindow *parent) // virtual
5525 {
5526         wxPanel *panel = new wxPanel(parent,-1);
5527
5528         _cb_link                = new wxCheckBox(panel,-1,_T("LINK                    ")); 
5529         _cb_link->SetValue(true);
5530
5531         wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
5532
5533         sizer->Add(_cb_link);
5534
5535         sizer->Add( wxWidgetMesure2D_Plane::CreateWin1a(panel) );
5536
5537         panel->SetAutoLayout(true);
5538         panel->SetSizer(sizer);
5539         panel->SetSize(400,30);
5540         panel->Layout();
5541
5542 //EEDxx2.4
5543 //      panel->FitInside();
5544
5545         Connect(_cb_link->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &wxWidgetMesure2D_Plane_in_MPR::OnActiveLink );
5546
5547         return panel;
5548 }
5549
5550
5551
5552
5553 //-------------------------------------------------------------------
5554 //-------------------------------------------------------------------
5555 //-------------------------------------------------------------------
5556
5557 BEGIN_EVENT_TABLE( wxMPRWidget, wxPanel )
5558         EVT_MENU( 12121, wxMPRWidget::OnRefreshView )
5559         EVT_MENU( 12122, wxMPRWidget::OnDClickLeft  )
5560 END_EVENT_TABLE( );
5561
5562
5563
5564 wxMPRWidget::wxMPRWidget( wxWindow* parent,
5565                           marImageData *marimageData , double voxelSize)
5566 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
5567 {
5568
5569         _vtkmpr2Dview[0]                                = NULL;
5570         _vtkmpr2Dview[1]                                = NULL;
5571         _vtkmpr2Dview[2]                                = NULL;
5572         _vtkplane2Dview                                 = NULL;
5573         _widgetMesure                                   = NULL;
5574         _wxsphereview                                   = NULL;
5575         _wxvtk3Dbaseview_MPRClipping3D  = NULL;
5576         _wxvtkmpr3Dview                                 = NULL;
5577         _wxvtkclipping3Dview                    = NULL;
5578         _vtkplane2Dview_B                               = NULL;
5579         _widgetMesure_B                                 = NULL;
5580
5581         _vtkmpr2Dview_B[0]                              = NULL;
5582         _vtkmpr2Dview_B[1]                              = NULL;
5583         _vtkmpr2Dview_B[2]                              = NULL;
5584         _vtkplane2Dview_B                               = NULL;
5585         _widgetMesure_B                                 = NULL;
5586         _wxsphereview_B                                 = NULL;
5587         _wxvtk3Dbaseview_MPR3D_B                = NULL;
5588         _wxvtkmpr3Dview_B                               = NULL;
5589         _wxvtk3Dbaseview_Clipping3D_BB  = NULL;
5590         _wxvtkmpr3Dview_BB                              = NULL;
5591         _wxvtkclipping3Dview_BB                 = NULL;
5592
5593         _vtkmprbasedata                                 = NULL;
5594
5595
5596         
5597         _framePanelCutting                              = NULL; 
5598         _panelCutting                                   = NULL;
5599
5600
5601         wxBoxSizer                      *sizer          = new wxBoxSizer(wxVERTICAL  );
5602         _marImageData=NULL;
5603
5604         if(marimageData!=NULL){
5605                 _marImageData                                   = marimageData;
5606                 _voxelSize                                              = voxelSize;
5607                 _vtkmprbasedata                                 = new vtkMPRBaseData(); 
5608                 _vtkmprbasedata->SetMarImageData(_marImageData);
5609                 
5610                 
5611                 
5612
5613                 wxSplitterWindow        *pnlSplitter            = new wxSplitterWindow( this , -1);
5614                 pnlSplitter     -> SetMinimumPaneSize( 2 );
5615
5616                 wxPanel                         *MPRPanel       = CreateMPRPanel(pnlSplitter,_vtkmprbasedata);
5617                 wxPanel                         *controlPanel   = CreateControlPanel(pnlSplitter);      
5618                 pnlSplitter     -> SplitVertically( MPRPanel, controlPanel, 550 );
5619
5620                 sizer           -> Add( pnlSplitter ,1,wxGROW  ,0);
5621
5622         }          
5623
5624         //int ww,hh;
5625         //wxWindow *pp=this;
5626         //while (pp->GetParent()!=NULL) pp=pp->GetParent();
5627         //pp->GetSize(&ww,&hh);
5628         
5629         this            -> SetAutoLayout( true );
5630         this            -> SetSizer(sizer);
5631 //      sizer           ->      Fit( this );
5632         _refreshAPage=0;
5633         _refreshBPage=0;
5634
5635 }
5636 void wxMPRWidget::setImageData(vtkImageData * img, double voxelsize){
5637
5638         if(_marImageData!=NULL){
5639                 _marImageData->removeImageData(0);
5640                 _marImageData->AddImageData(img);               
5641         }else{
5642                 _marImageData = new marImageData(img);
5643         }
5644         
5645         _voxelSize                                              = voxelsize;
5646
5647         if(_vtkmprbasedata==NULL){
5648                 _vtkmprbasedata                                 = new vtkMPRBaseData(); 
5649                 _vtkmprbasedata->SetMarImageData(_marImageData);        
5650
5651                 wxSplitterWindow        *pnlSplitter            = new wxSplitterWindow( this , -1);
5652                 pnlSplitter     -> SetMinimumPaneSize( 2 );
5653
5654                 wxPanel                         *MPRPanel       = CreateMPRPanel(pnlSplitter,_vtkmprbasedata);
5655                 wxPanel                         *controlPanel   = CreateControlPanel(pnlSplitter);      
5656                 pnlSplitter     -> SplitVertically( MPRPanel, controlPanel, 550 );
5657
5658                 this->GetSizer()                -> Add( pnlSplitter ,1,wxGROW  ,0);
5659         }       
5660         
5661
5662         
5663 }
5664 //----------------------------------------------------------------------------
5665
5666 wxMPRWidget::~wxMPRWidget( )
5667 {
5668 //EEDxx2.4 DELETE
5669         if (_framePanelCutting!=NULL)
5670         {
5671                 _framePanelCutting->Close();
5672         }
5673
5674         if (_vtkmpr2Dview[0]!=NULL)                                     { delete _vtkmpr2Dview[0]; }
5675         if (_vtkmpr2Dview[1]!=NULL)                                     { delete _vtkmpr2Dview[1]; }
5676         if (_vtkmpr2Dview[2]!=NULL)                                     { delete _vtkmpr2Dview[2]; }
5677
5678         if (_vtkmpr2Dview_B[0]!=NULL)                           { delete _vtkmpr2Dview_B[0]; }
5679
5680         if (_vtkmpr2Dview_B[1]!=NULL)                           { delete _vtkmpr2Dview_B[1]; }
5681         if (_vtkmpr2Dview_B[2]!=NULL)                           { delete _vtkmpr2Dview_B[2]; }
5682
5683         if (_vtkmprbasedata!=NULL)                                      { delete _vtkmprbasedata; }
5684         if (_vtkplane2Dview!=NULL)                                      { delete _vtkplane2Dview; }
5685         if (_wxsphereview!=NULL)                                        { delete _wxsphereview; }
5686         if (_wxvtk3Dbaseview_MPRClipping3D!=NULL)       { delete _wxvtk3Dbaseview_MPRClipping3D; }
5687         if (_wxvtkmpr3Dview!=NULL)                                      { delete _wxvtkmpr3Dview; }
5688         if (_wxvtkclipping3Dview!=NULL)                         { delete _wxvtkclipping3Dview; }
5689
5690         if (_vtkplane2Dview_B!=NULL)                            { delete _vtkplane2Dview_B; }
5691         if (_wxsphereview_B!=NULL)                                      { delete _wxsphereview_B; }
5692
5693         if (_wxvtk3Dbaseview_MPR3D_B!=NULL)                     { delete _wxvtk3Dbaseview_MPR3D_B; }
5694         if (_wxvtkmpr3Dview_B!=NULL)                            { delete _wxvtkmpr3Dview_B; }
5695
5696         if (_wxvtk3Dbaseview_Clipping3D_BB!=NULL)       { delete _wxvtk3Dbaseview_Clipping3D_BB; }
5697         if (_wxvtkmpr3Dview_BB!=NULL)                           { delete _wxvtkmpr3Dview_BB; }
5698         if (_wxvtkclipping3Dview_BB!=NULL)                      { delete _wxvtkclipping3Dview_BB; }
5699 }
5700
5701 //----------------------------------------------------------------------------
5702
5703 wxPanel* wxMPRWidget::CreateControlPanel(wxWindow *parent)
5704 {
5705
5706         wxPanel *panel=new wxPanel(parent,-1);
5707
5708 //EEDxx2.4
5709 //      wxStaticText *tmpText = new wxStaticText(panel,-1,""); 
5710
5711         wxStaticText *help0Text = new wxStaticText(panel,-1,_T("General: \n  middle click : contrast\n  ctrl + middle click : rotate image\n  shift + middle click: translate image\n  ctrl + right click: zoom")); 
5712
5713         wxStaticText *help1Text = new wxStaticText(panel,-1,_T("mpr2D: \n  double click : choose a point\n  mouse right : change perpendicular slice\n  drag axis: change slice")); 
5714         
5715         wxStaticText *help2Text = new wxStaticText(panel,-1,_T("Plane: \n  drag mouse: rotate\n  ctrl + drag mouse : fix axis rotation\n  \n mouse right: change perpendicular slice \n  see split control \n     - Active/Desactivet plane tool\n     - Center market\n     - Rotation axis market\n     - 2D messure tool (open/close contour)")); 
5716
5717         wxStaticText *help3Text = new wxStaticText(panel,-1,
5718 _T("Sphere: \n  drag mouse: rotation\n  mouse right: change radio \n  click: 3D point selection in MPR 2D \n  double clicks in MPR: show surface sphere")); 
5719         
5720         wxStaticText *help4Text = new wxStaticText(panel,-1,_T("MPR3D:\n  see split control")); 
5721
5722         wxString text=_T("");
5723         text=text+_T("Clipping: \n");
5724         text=text+_T(" see split control \n");
5725         text=text+_T(" 4 MarchingCubes:  \n");
5726         text=text+_T("    color, isovalue, opacity \n");
5727         text=text+_T(" Box:\n");
5728         text=text+_T("    mouse left drag (box): rotation\n");
5729         text=text+_T("    mouse left drag (sphere): size,position\n");
5730         text=text+_T("    mouse right drag (box): box size");
5731         text=text+_T(" Axis: 3D\n");
5732         text=text+_T("    mouse drag: translate\n");
5733         text=text+_T("    shift + mouse drag: translate 2 axis\n");
5734         text=text+_T("    mouse right: scale\n");
5735         text=text+_T(" Plane 3D:\n");
5736         text=text+_T("    mouse drag perpendicular axis: rotate plane\n");
5737         text=text+_T("    mouse drag spheres: size plane\n");
5738         text=text+_T("    ctrl +mouse right over the plane: size plane\n");
5739         text=text+_T("    mouse drag plane: translate\n");
5740         text=text+_T("    middle click perpendicular axis: translate\n");
5741         wxStaticText *help5Text = new wxStaticText(panel,-1, text );
5742
5743
5744     wxFlexGridSizer *sizer  = new wxFlexGridSizer(1);
5745         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5746         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5747         sizer->Add( help0Text   );
5748
5749         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5750         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5751         sizer->Add( help1Text   );
5752
5753         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5754         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5755         sizer->Add( help2Text   );
5756
5757         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5758         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5759         sizer->Add( help3Text   );
5760
5761         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5762         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5763         sizer->Add( help4Text   );
5764
5765         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5766         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5767         sizer->Add( help5Text   );
5768         
5769         panel->SetSizer(sizer);
5770         panel->SetAutoLayout(true);
5771         panel->SetSize(350,500);
5772
5773     return panel;
5774 }
5775
5776 //----------------------------------------------------------------------------
5777
5778 void wxMPRWidget::OnPageAChanged(wxNotebookEvent & event)
5779 {
5780         _refreshAPage=event.GetSelection();
5781         Refresh();
5782         RefreshView(true);
5783 }
5784
5785 //----------------------------------------------------------------------------
5786
5787 void wxMPRWidget::OnPageBChanged(wxNotebookEvent & event)
5788 {
5789         _refreshBPage=event.GetSelection();
5790 //      Refresh(false);
5791 //      RefreshView();
5792 }
5793
5794
5795 //----------------------------------------------------------------------------
5796
5797 wxPanel* wxMPRWidget::CreateView(int type,wxWindow *parent, vtkMPRBaseData *vtkmprbasedata)
5798 {
5799         wxWindow *wxwindow;
5800         wxPanel *panel=new wxPanel(parent,-1);
5801
5802         if (type==0)
5803         {
5804                 _vtkmpr2Dview_B[0] = new wxVtkMPR2DView(panel,0);
5805                 _vtkmpr2Dview_B[0]->SetVtkBaseData(vtkmprbasedata);
5806                 wxwindow=_vtkmpr2Dview_B[0]->GetWxVTKRenderWindowInteractor();
5807         }
5808         if (type==1)
5809         {
5810                 _vtkmpr2Dview_B[1] = new wxVtkMPR2DView(panel,1);
5811                 _vtkmpr2Dview_B[1]->SetVtkBaseData(vtkmprbasedata);
5812                 wxwindow=_vtkmpr2Dview_B[1]->GetWxVTKRenderWindowInteractor();
5813         }
5814         if (type==2)
5815         {
5816                 _vtkmpr2Dview_B[2] = new wxVtkMPR2DView(panel,2);
5817                 _vtkmpr2Dview_B[2]->SetVtkBaseData(vtkmprbasedata);
5818                 wxwindow=_vtkmpr2Dview_B[2]->GetWxVTKRenderWindowInteractor();
5819         }
5820         if (type==3)
5821         {
5822                 _widgetMesure_B         = new wxWidgetMesure2D_Plane_in_MPR(panel);
5823                 _vtkplane2Dview_B       = new vtkPlane2DView( _widgetMesure_B->GetWindow2());
5824                 _widgetMesure_B->SetVtkPlane2DView( _vtkplane2Dview_B );
5825                 _vtkplane2Dview_B->SetImgSize( 200 );
5826                 _vtkplane2Dview_B->SetVtkBaseData(vtkmprbasedata);
5827                 wxwindow                        = _widgetMesure_B;
5828         }
5829         if (type==4)
5830         {
5831                 _wxsphereview_B         = new wxSphereView( panel , vtkmprbasedata, vtkmprbasedata->GetImageData() );
5832                 wxwindow=_wxsphereview_B->GetWxVTKRenderWindowInteractor();
5833         }
5834
5835         if (type==5)
5836         {
5837                 wxSplitterWindow *panelMPR3D    = new wxSplitterWindow( panel , -1);
5838                 _wxvtk3Dbaseview_MPR3D_B                = new wxVtk3DBaseView( panelMPR3D );
5839
5840                 _wxvtkmpr3Dview_B                               = new wxVtkMPR3DView(_wxvtk3Dbaseview_MPR3D_B);
5841                 vtkMPR3DDataViewer *vtkmpr3Ddataviewer = new vtkMPR3DDataViewer(); 
5842                 vtkmpr3Ddataviewer->SetVtkMPRBaseData(vtkmprbasedata);
5843                 vtkmpr3Ddataviewer->Configure();
5844                 _wxvtkmpr3Dview_B->SetVtkMPR3DDataViewer(vtkmpr3Ddataviewer);
5845
5846                 wxWindow        *window3D                       = _wxvtk3Dbaseview_MPR3D_B->GetWxVTKRenderWindowInteractor();
5847                 wxPanel         *controlPanel3D         = _wxvtkmpr3Dview_B->CreateControlPanel(panelMPR3D);
5848
5849 //EEDxx2.4
5850                 panelMPR3D      -> SetMinimumPaneSize( 5 );
5851                 panelMPR3D      -> SplitHorizontally( controlPanel3D,window3D,600  );
5852
5853                 wxwindow=panelMPR3D;
5854         }
5855
5856         if (type==6)
5857         {
5858                 wxSplitterWindow        *panelClipping3D        = new wxSplitterWindow( panel , -1);
5859                 _wxvtk3Dbaseview_Clipping3D_BB                  = new wxVtk3DBaseView( panelClipping3D );
5860
5861                 _wxvtkclipping3Dview_BB                                 = new wxVtkClipping3DView(_wxvtk3Dbaseview_Clipping3D_BB);
5862                 vtkClipping3DDataViewer *vtkclipping3Ddataviewer = new vtkClipping3DDataViewer(); 
5863                 vtkclipping3Ddataviewer->SetVtkMPRBaseData(vtkmprbasedata);
5864                 vtkclipping3Ddataviewer->Configure();
5865                 _wxvtkclipping3Dview_BB->SetVtkClipping3DDataViewer(vtkclipping3Ddataviewer);
5866
5867                 _wxvtkmpr3Dview_BB                                              = new wxVtkMPR3DView( _wxvtk3Dbaseview_Clipping3D_BB );
5868                 vtkMPR3DDataViewer *vtkmpr3Ddataviewer  = new vtkMPR3DDataViewer(); 
5869                 vtkmpr3Ddataviewer->SetVtkMPRBaseData(vtkmprbasedata);
5870                 vtkmpr3Ddataviewer->Configure();
5871                 _wxvtkmpr3Dview_BB->SetVtkMPR3DDataViewer(vtkmpr3Ddataviewer);
5872
5873                 wxWindow        *window3D                                       = _wxvtk3Dbaseview_Clipping3D_BB->GetWxVTKRenderWindowInteractor();
5874
5875                 wxPanel                 *panelControl                   = new wxPanel(panelClipping3D,-1);      
5876                 wxPanel                 *controlPanelMPR3D              = _wxvtkmpr3Dview_BB->CreateControlPanel(panelControl);
5877                 wxPanel                 *controlPanelClipping3D = _wxvtkclipping3Dview_BB->CreateControlPanel(panelControl);
5878                                  _btnCutImageData               = new wxCheckBox(panelControl,-1,_T("Cut Module"));
5879                 Connect(_btnCutImageData->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED  , (wxObjectEventFunction) &wxMPRWidget::OnCutImagaData );
5880
5881                 wxFlexGridSizer  *sizerCtrol             = new wxFlexGridSizer(1);
5882                 sizerCtrol->Add(controlPanelMPR3D               , 1, wxALL|wxEXPAND, 2);
5883                 sizerCtrol->Add(controlPanelClipping3D  , 1, wxALL|wxEXPAND, 2);
5884                 sizerCtrol->Add( _btnCutImageData               , 1, wxALL, 2);
5885
5886                 panelControl->SetAutoLayout(true);
5887                 panelControl->SetSizer(sizerCtrol);
5888                 panelControl->SetSize(400,350);
5889                 panelControl->Layout();
5890 //EEDxx2.4
5891 //              panelControl->FitInside();
5892
5893 //EEDxx2.4
5894                 panelClipping3D -> SetMinimumPaneSize( 5 );
5895                 panelClipping3D -> SplitHorizontally( panelControl , window3D , 10  );
5896                 wxwindow=panelClipping3D;
5897         }
5898
5899     wxBoxSizer *sizerH1                                                 = new wxBoxSizer(wxHORIZONTAL);
5900         sizerH1->Add(wxwindow , 1, wxALL|wxGROW, 0);
5901         panel->SetAutoLayout(true);
5902         panel->SetSizer(sizerH1);
5903         panel->SetSize(400,400);
5904         panel->Layout();
5905
5906         return panel;
5907 }
5908
5909 //----------------------------------------------------------------------------
5910
5911 wxPanel* wxMPRWidget::CreateMPRPanel(wxWindow *parent, vtkMPRBaseData *vtkmprbasedata)
5912 {
5913         wxPanel *panel=new wxPanel(parent,-1);
5914
5915         wxNotebook *notebook = new wxNotebook( panel, -1 );
5916
5917         notebook->AddPage( CreateMPRPanel4View( notebook ,vtkmprbasedata), _T("4-View") );
5918         notebook->AddPage( CreateView(0,notebook,vtkmprbasedata) , _T("Axial")          );
5919         notebook->AddPage( CreateView(1,notebook,vtkmprbasedata) , _T("Sagital")        );
5920         notebook->AddPage( CreateView(2,notebook,vtkmprbasedata) , _T("Coronal")        );
5921         notebook->AddPage( CreateView(3,notebook,vtkmprbasedata) , _T("Plane")          );
5922         notebook->AddPage( CreateView(4,notebook,vtkmprbasedata) , _T("Sphere")         );
5923         notebook->AddPage( CreateView(5,notebook,vtkmprbasedata) , _T("MPR 3D")         );
5924         notebook->AddPage( CreateView(6,notebook,vtkmprbasedata) , _T("Clipping")       );
5925         Connect(notebook->GetId()       , wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED  , (wxObjectEventFunction) &wxMPRWidget::OnPageAChanged   );
5926
5927         wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
5928         sizer->Add(notebook , 1, wxALL|wxGROW, 2);
5929         panel->SetAutoLayout(true);
5930         panel->SetSizer(sizer);
5931         panel->SetSize(400,400);
5932         panel->Layout();
5933
5934 //EEDxx2.4
5935 //      panel->FitInside();
5936
5937         panel->Refresh();
5938         return panel;
5939 }
5940
5941 //----------------------------------------------------------------------------
5942
5943 wxPanel* wxMPRWidget::CreateMPRPanel4View(wxWindow *parent, vtkMPRBaseData *vtkmprbasedata)
5944 {
5945         wxPanel *panel=new wxPanel(parent,-1);
5946
5947         // view 0
5948         _vtkmpr2Dview[0] = new wxVtkMPR2DView(panel,0);
5949         _vtkmpr2Dview[0]->SetVtkBaseData(vtkmprbasedata);
5950         wxVTKRenderWindowInteractor *iren0 = _vtkmpr2Dview[0]->GetWxVTKRenderWindowInteractor();        
5951
5952         // view 1
5953         _vtkmpr2Dview[1] = new wxVtkMPR2DView(panel,1);
5954         _vtkmpr2Dview[1]->SetVtkBaseData(vtkmprbasedata);
5955         wxVTKRenderWindowInteractor *iren1 = _vtkmpr2Dview[1]->GetWxVTKRenderWindowInteractor();        
5956
5957         // view 2
5958         _vtkmpr2Dview[2] = new wxVtkMPR2DView(panel,2);
5959         _vtkmpr2Dview[2]->SetVtkBaseData(vtkmprbasedata);
5960         wxVTKRenderWindowInteractor *iren2 = _vtkmpr2Dview[2]->GetWxVTKRenderWindowInteractor();        
5961
5962         // view 3
5963         wxNotebook *notebook = new wxNotebook( panel, -1 );
5964         notebook->SetSize(400,400);
5965
5966 // EED 27 Oct 2007
5967          // view 3.0
5968         _widgetMesure   = new wxWidgetMesure2D_Plane_in_MPR(notebook);
5969         _vtkplane2Dview = new vtkPlane2DView( _widgetMesure->GetWindow2() );
5970         _widgetMesure->SetVtkPlane2DView( _vtkplane2Dview );
5971         _vtkplane2Dview->SetImgSize( 200 );
5972         _vtkplane2Dview->SetVtkBaseData(vtkmprbasedata);
5973         notebook->AddPage( _widgetMesure, _T("Plane") );
5974
5975          // view 3.1
5976         _wxsphereview = new wxSphereView( notebook , vtkmprbasedata, vtkmprbasedata->GetImageData());
5977         wxVTKRenderWindowInteractor *iren3B = _wxsphereview->GetWxVTKRenderWindowInteractor();  
5978         notebook->AddPage( iren3B, _T("Sphere") );
5979
5980
5981          // view 3.2
5982         wxSplitterWindow *panelMPR3D    = new wxSplitterWindow( notebook , -1);
5983         _wxvtk3Dbaseview_MPRClipping3D  = new wxVtk3DBaseView( panelMPR3D );
5984
5985         _wxvtkmpr3Dview = new wxVtkMPR3DView( _wxvtk3Dbaseview_MPRClipping3D );
5986         vtkMPR3DDataViewer *vtkmpr3Ddataviewer = new vtkMPR3DDataViewer(); 
5987         vtkmpr3Ddataviewer->SetVtkMPRBaseData(vtkmprbasedata);
5988         vtkmpr3Ddataviewer->Configure();
5989         _wxvtkmpr3Dview->SetVtkMPR3DDataViewer(vtkmpr3Ddataviewer);
5990
5991
5992         _wxvtkclipping3Dview = new wxVtkClipping3DView( _wxvtk3Dbaseview_MPRClipping3D );
5993         vtkClipping3DDataViewer *vtkclipping3Ddataviewer = new vtkClipping3DDataViewer(); 
5994         vtkclipping3Ddataviewer->SetVtkMPRBaseData(vtkmprbasedata);
5995         vtkclipping3Ddataviewer->Configure();
5996         _wxvtkclipping3Dview->SetVtkClipping3DDataViewer(vtkclipping3Ddataviewer);
5997
5998
5999         wxWindow        *window3D                               = _wxvtk3Dbaseview_MPRClipping3D->GetWxVTKRenderWindowInteractor();
6000
6001         wxPanel         *panelControl                   = new wxPanel(panelMPR3D,-1);
6002         wxPanel         *controlPanelMPR3D              = _wxvtkmpr3Dview->CreateControlPanel(panelControl);
6003         wxPanel         *controlPanelClipping3D = _wxvtkclipping3Dview->CreateControlPanel(panelControl);
6004
6005
6006
6007
6008 //    wxBoxSizer         *sizerCtrol             = new wxBoxSizer(wxVERTICAL);
6009         wxFlexGridSizer  *sizerCtrol             = new wxFlexGridSizer(1);
6010         sizerCtrol->Add(controlPanelMPR3D               , 1, wxALL|wxEXPAND, 2);
6011         sizerCtrol->Add(controlPanelClipping3D  , 1, wxALL|wxEXPAND, 2);
6012
6013
6014         panelControl->SetAutoLayout(true);
6015         panelControl->SetSizer(sizerCtrol);
6016         panelControl->SetSize(400,150);
6017         panelControl->Layout();
6018
6019 //EEDxx2.4
6020         panelMPR3D      -> SetMinimumPaneSize( 5 );
6021
6022         panelMPR3D      -> SplitHorizontally( panelControl,window3D,200  );
6023
6024         notebook->AddPage( panelMPR3D, _T("MPR 3D - Clipping") );
6025
6026
6027         Connect(notebook->GetId()       , wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED  , (wxObjectEventFunction) &wxMPRWidget::OnPageBChanged   );
6028
6029         wxBoxSizer *sizerV = new wxBoxSizer(wxVERTICAL);
6030         wxBoxSizer *sizerH1= new wxBoxSizer(wxHORIZONTAL);
6031         wxBoxSizer *sizerH2= new wxBoxSizer(wxHORIZONTAL);
6032         sizerH1->Add(iren2 , 1, wxALL|wxEXPAND, 2);
6033         sizerH1->Add(iren0 , 1, wxALL|wxEXPAND, 2);
6034         sizerH2->Add(iren1 , 1, wxALL|wxEXPAND, 2);
6035 //      sizerH2->Add(iren3 , 1, wxALL|wxEXPAND, 2);
6036         sizerH2->Add(notebook , 1, wxALL|wxEXPAND, 2);
6037
6038         sizerV->Add(sizerH1, 1, wxALL|wxEXPAND, 0);
6039         sizerV->Add(sizerH2, 1, wxALL|wxEXPAND, 0);
6040
6041         panel->SetAutoLayout(true);
6042         panel->SetSizer(sizerV);
6043         panel->SetSize(400,400);
6044         panel->Layout();
6045         return panel;
6046 }
6047
6048 //----------------------------------------------------------------------------
6049 void wxMPRWidget::OnCutImagaData(wxCommandEvent &event) 
6050 {
6051         if (_btnCutImageData->GetValue()==true){                
6052        
6053                 _framePanelCutting = new wxFrame(this,-1,_T("Cutting Module"),wxDefaultPosition,wxDefaultSize,wxCAPTION|wxSTAY_ON_TOP| wxRESIZE_BORDER );
6054                 
6055                 _framePanelCutting->SetSize(550,400);
6056
6057                 _panelCutting   = new wxPanelCuttingImageData(_framePanelCutting);              
6058                 if(_wxvtk3Dbaseview_Clipping3D_BB!=NULL){
6059                         _panelCutting->SetWxVtk3DBaseView( _wxvtk3Dbaseview_Clipping3D_BB  );
6060                 }
6061                 _panelCutting->SetVtkMPRBaseData( GetVtkMPRBaseData() );
6062                 _panelCutting->SetVtkClipping3DDataViewer( this->_wxvtkclipping3Dview_BB->GetVtkClipping3DDataViewer() );
6063                 _panelCutting->Configure( );
6064 /*
6065                 wxBoxSizer *topsizer            = new wxBoxSizer(wxHORIZONTAL  );
6066                 topsizer -> Add( _panelCutting ,1,wxALL  ,0);
6067                 _framePanelCutting->SetAutoLayout(true);
6068                 _framePanelCutting->SetSizer( topsizer );      // use the sizer for layout
6069                 _framePanelCutting->Layout(); 
6070 //EEDxx2.4
6071 //              _framePanelCutting->FitInside();
6072 */
6073                 _framePanelCutting->Show();
6074
6075                 
6076         } else {
6077                 if (_framePanelCutting!=NULL){
6078                         _panelCutting->RemoveActors();                  
6079                         _framePanelCutting->Destroy();
6080                         _framePanelCutting=NULL;
6081                         _panelCutting=NULL;
6082                 }
6083         }
6084 }
6085
6086 //----------------------------------------------------------------------------
6087 void wxMPRWidget::ConfigureVTK(){
6088         int x=0,y=0,z=0;
6089
6090         if (_vtkmprbasedata!=NULL)
6091         {
6092                 _vtkmprbasedata->Configure();
6093                 x=_vtkmprbasedata                       ->      GetMaxPositionX()/2;
6094                 y=_vtkmprbasedata                       ->      GetMaxPositionY()/2;
6095                 z=_vtkmprbasedata                       ->      GetMaxPositionZ()/2;    
6096                 _vtkmprbasedata->SetX( x );
6097                 _vtkmprbasedata->SetY( y );
6098                 _vtkmprbasedata->SetZ( z );
6099         
6100         }
6101
6102         if(_vtkmpr2Dview[0]!=NULL) {_vtkmpr2Dview[0]                            ->      Configure();}
6103         if(_vtkmpr2Dview[1]!=NULL) {_vtkmpr2Dview[1]                            ->      Configure();}
6104         if(_vtkmpr2Dview[2]!=NULL) {_vtkmpr2Dview[2]                            ->      Configure();}
6105
6106
6107         if (_vtkmpr2Dview_B[0]!=NULL) { _vtkmpr2Dview_B[0]                              ->      Configure(); }
6108         if (_vtkmpr2Dview_B[1]!=NULL) { _vtkmpr2Dview_B[1]                              ->      Configure(); }
6109         if (_vtkmpr2Dview_B[2]!=NULL) { _vtkmpr2Dview_B[2]                              ->      Configure(); }
6110
6111
6112         
6113
6114         if (_vtkplane2Dview!=NULL){_vtkplane2Dview                              ->      Configure();}
6115         if (_widgetMesure!=NULL){_widgetMesure                                  ->      ConfigureA(_vtkplane2Dview);}
6116         if (_widgetMesure!=NULL){_widgetMesure                                  ->      SetActiveLink(true);}
6117         if (_widgetMesure!=NULL){_widgetMesure                                  ->      SetMesureScale( _voxelSize );}
6118         if (_wxsphereview!=NULL){_wxsphereview                                  ->      Configure();}
6119
6120         if (_wxvtk3Dbaseview_MPRClipping3D!=NULL){_wxvtk3Dbaseview_MPRClipping3D        ->  Configure();}
6121         if (_wxvtkmpr3Dview!=NULL){
6122                 _wxvtkmpr3Dview                                 ->      Configure();
6123         }
6124         if (_wxvtkclipping3Dview!=NULL){_wxvtkclipping3Dview            ->      Configure();}
6125
6126         if (_vtkplane2Dview_B!=NULL){   _vtkplane2Dview_B                       ->      Configure(); }
6127         if (_widgetMesure_B!=NULL){             _widgetMesure_B                         ->      ConfigureA( _vtkplane2Dview_B ); }
6128         if (_widgetMesure_B!=NULL){             _widgetMesure_B                         ->      SetActiveLink(true); }
6129
6130 //EEDx3
6131 //      double spc[3];
6132 //      vtkImageData *imageData = _vtkmprbasedata->GetImageData();
6133 //      imageData->Update();
6134 //      imageData->GetSpacing(spc);
6135 //      _widgetMesure_B->SetMesureScale(spc[0]);
6136
6137         if (_widgetMesure_B!=NULL)                                      {_widgetMesure_B->SetMesureScale( _voxelSize );}
6138
6139
6140         if (_wxsphereview_B!=NULL)                                      {_wxsphereview_B                                ->      Configure();}
6141
6142         if (_wxvtk3Dbaseview_MPR3D_B!=NULL)                     {_wxvtk3Dbaseview_MPR3D_B               ->  Configure();}
6143         if (_wxvtkmpr3Dview_B!=NULL)                            {_wxvtkmpr3Dview_B                              ->      Configure();}
6144
6145         if ( _wxvtk3Dbaseview_Clipping3D_BB!=NULL)      {_wxvtk3Dbaseview_Clipping3D_BB ->  Configure(); }
6146         if ( _wxvtkmpr3Dview_BB!=NULL)                          {_wxvtkmpr3Dview_BB                             ->      Configure(); }
6147         if ( _wxvtkclipping3Dview_BB!=NULL)                     {_wxvtkclipping3Dview_BB                ->      Configure(); }
6148
6149
6150         vtkInteractorStyle3DView *vtkinteractorstyle3Dview;
6151         if (_wxvtkmpr3Dview_BB!=NULL)
6152         {
6153                 vtkinteractorstyle3Dview        = new vtkInteractorStyle3DView();
6154                 vtkinteractorstyle3Dview->SetWxVtkMPR3DView(_wxvtkmpr3Dview_BB);
6155                 vtkinteractorstyle3Dview->SetWxVtkClipping3DView(_wxvtkclipping3Dview_BB);
6156         }
6157
6158         if (_wxvtk3Dbaseview_Clipping3D_BB!=NULL)
6159         {
6160                 _wxvtk3Dbaseview_Clipping3D_BB->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( vtkinteractorstyle3Dview );
6161         }
6162         
6163 //EED 29Mars2009
6164 //      RefreshView(true);
6165         
6166 }
6167
6168 //----------------------------------------------------------------------------
6169
6170 void wxMPRWidget::OnRefreshView(wxCommandEvent & event)
6171 {
6172         RefreshView();
6173 }
6174 //----------------------------------------------------------------------------
6175 void wxMPRWidget::OnDClickLeft(wxCommandEvent & event)
6176 {
6177         if (_wxsphereview!=NULL) {
6178                 _wxsphereview   -> RefreshPoint();
6179         }
6180         if (_wxsphereview_B!=NULL) {
6181                 _wxsphereview_B -> RefreshPoint();
6182         }
6183 }
6184 //----------------------------------------------------------------------------
6185 void wxMPRWidget::RefreshView(bool firsttime){
6186
6187         if (_refreshAPage == 0 )
6188         {
6189
6190                 if ((_vtkmpr2Dview[0]!=NULL) && (_vtkmpr2Dview[1]!=NULL) && (_vtkmpr2Dview[2]!=NULL) )
6191                 {
6192                         _vtkmpr2Dview[2] -> Refresh();
6193                         _vtkmpr2Dview[1] -> Refresh();
6194                         _vtkmpr2Dview[0] -> Refresh();
6195
6196                         if (firsttime==false)
6197                         {
6198                                 _vtkmpr2Dview[2] -> RefreshView();
6199                                 _vtkmpr2Dview[1] -> RefreshView();
6200                                 _vtkmpr2Dview[0] -> RefreshView();
6201                         }
6202
6203                         if (_refreshBPage == 0 )
6204                         {
6205                                 if (_vtkplane2Dview!=NULL)
6206                                 {
6207                                         _vtkplane2Dview -> Refresh();           
6208                                         if (firsttime==false)
6209                                         {
6210                                                 _vtkplane2Dview -> RefreshView();
6211                                         }
6212 //                                      _wxvtk3Dbaseview_MPR3D_B -> Refresh();
6213                                 }
6214                         }
6215                         if (_refreshBPage == 1 )
6216                         {
6217                                 //sphere
6218                         }
6219                         if (_refreshBPage == 2 )
6220                         {
6221                                 if ((_wxvtkmpr3Dview!=NULL)  && (_wxvtk3Dbaseview_MPRClipping3D!=NULL) && (_wxvtkclipping3Dview!=NULL) )
6222                                 {
6223                                         _wxvtkmpr3Dview                 -> RefreshView();
6224                                         _wxvtk3Dbaseview_MPRClipping3D  -> Refresh();
6225                                         _wxvtkclipping3Dview            -> Refresh();
6226                                 }
6227                         }
6228                 }
6229         }
6230
6231         if (_refreshAPage == 1 )
6232         {
6233                 if (_vtkmpr2Dview_B[0] !=NULL){
6234                         _vtkmpr2Dview_B[0] -> Refresh();
6235                 }
6236         }
6237         if (_refreshAPage == 2 )
6238         {
6239                 if (_vtkmpr2Dview_B[1] !=NULL){
6240                         _vtkmpr2Dview_B[1] -> Refresh();
6241                 }
6242         }
6243         if (_refreshAPage == 3 )
6244         {
6245                 if (_vtkmpr2Dview_B[2] !=NULL){
6246                         _vtkmpr2Dview_B[2] -> Refresh();
6247                 }
6248         }
6249         if (_refreshAPage == 4 )
6250         {
6251                 if (_vtkplane2Dview_B!=NULL){
6252                         _vtkplane2Dview_B -> Refresh();
6253                         if (firsttime==false)
6254                         {
6255                                 _vtkplane2Dview_B -> RefreshView();
6256                         }
6257                 }
6258         }
6259
6260         if (_refreshAPage == 5 )
6261         {
6262                 // sphere
6263         }
6264         if (_refreshAPage == 6 )
6265         {
6266                 if (_wxvtkmpr3Dview_B!=NULL){
6267                         _wxvtkmpr3Dview_B               -> Refresh();
6268                         _wxvtk3Dbaseview_MPR3D_B        -> Refresh();
6269                 }
6270         }
6271         if (_refreshAPage == 7 )
6272         {
6273                 if (_wxvtkmpr3Dview_BB!=NULL){
6274                         _wxvtkmpr3Dview_BB              -> RefreshView();
6275                         _wxvtkclipping3Dview_BB         -> Refresh();
6276                         _wxvtk3Dbaseview_Clipping3D_BB  -> Refresh();
6277                         if (_panelCutting!=NULL)
6278                         {
6279                                 _panelCutting->RefreshView();
6280                         }
6281                 }
6282         }
6283
6284 }
6285 //----------------------------------------------------------------------------
6286 vtkMPRBaseData  *wxMPRWidget::GetVtkMPRBaseData(){      
6287         return _vtkmprbasedata;
6288 }
6289 //----------------------------------------------------------------------------
6290 vtkPlane2DView *wxMPRWidget::GetVtkPlane2DView()
6291 {
6292         return _vtkplane2Dview;
6293 }
6294 //----------------------------------------------------------------------------
6295 wxVtkMPR3DView  *wxMPRWidget::GetWxvtkmpr3Dview_BB()
6296 {
6297         return _wxvtkmpr3Dview_BB;
6298 }
6299 //----------------------------------------------------------------------------
6300 wxVtkBaseView *wxMPRWidget::GetWxVtkBaseView(int page, int id)
6301 {
6302         wxVtkBaseView *result=NULL;
6303         if (page==0)
6304         {       
6305                 if ((id>=0) &&(id<=3)){
6306                         result=_vtkmpr2Dview[id];
6307                 }
6308                 if (id==3)
6309                 {
6310                         result=_vtkplane2Dview;
6311                 }
6312         }
6313         return result;
6314 }
6315 //----------------------------------------------------------------------------
6316 wxVtkMPR2DView *wxMPRWidget::GetWxvtkMPR2Dview(int direction)
6317 {
6318         return _vtkmpr2Dview[direction];
6319 }
6320
6321 //----------------------------------------------------------------------------
6322 //----------------------------------------------------------------------------
6323 //----------------------------------------------------------------------------
6324 wxMPRWidget2::wxMPRWidget2(wxWindow* parent,marImageData *marimagedata,double voxelSize)
6325 : wxMPRWidget(parent,marimagedata,voxelSize)
6326 {
6327 }
6328 //----------------------------------------------------------------------------
6329 wxMPRWidget2::~wxMPRWidget2()
6330 {
6331 }
6332 //----------------------------------------------------------------------------
6333 void wxMPRWidget2::OnRefreshView(wxCommandEvent & event) // Virtual
6334 {       
6335         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
6336     this->GetParent()->ProcessEvent(newevent1);
6337 }
6338
6339
6340 //----------------------------------------------------------------------------
6341 //----------------------------------------------------------------------------
6342 //----------------------------------------------------------------------------
6343 figureCuttingModel::figureCuttingModel()
6344 {
6345         _inversModel    = vtkTransform::New();
6346         _matrixModel    = vtkTransform::New();
6347         _matrixVisual   = vtkTransform::New();
6348
6349         _spcX=1;
6350         _spcY=1;
6351         _spcZ=1;
6352 }
6353 //----------------------------------------------------------------------------
6354 figureCuttingModel::~figureCuttingModel() // virtual
6355 {
6356         _inversModel->Delete();
6357 }
6358 //----------------------------------------------------------------------------
6359 void figureCuttingModel::SetPosition(double x,double y, double z)
6360 {
6361         _px=x;
6362         _py=y;
6363         _pz=z;
6364 }
6365 //----------------------------------------------------------------------------
6366 void figureCuttingModel::SetScale(double sx,double sy, double sz)
6367 {
6368         _sx=sx;
6369         _sy=sy;
6370         _sz=sz;
6371 }
6372 //----------------------------------------------------------------------------
6373 void figureCuttingModel::SetRotation(double alfa,double beta, double teta)
6374 {
6375         _alfa=alfa;
6376         _beta=beta;
6377         _teta=teta;
6378 }
6379
6380 //----------------------------------------------------------------------------
6381 void figureCuttingModel::CalculeMatrix()
6382 {
6383         _matrixModel->Identity();
6384         _matrixModel->Translate(_px,_py,_pz);
6385         _matrixModel->RotateY(_beta);
6386         _matrixModel->RotateX(_alfa);
6387         _matrixModel->RotateY(_teta);
6388         _matrixModel->Scale(_sx,_sy,_sz);
6389
6390         _matrixVisual->Identity();
6391         _matrixVisual->Translate( _px*_spcX  ,  _py*_spcY  ,  _pz*_spcZ  );
6392         _matrixVisual->RotateY(_beta);
6393         _matrixVisual->RotateX(_alfa);
6394         _matrixVisual->RotateY(_teta);
6395         _matrixVisual->Scale( _sx*_spcX  ,  _sy*_spcY  ,  _sz*_spcZ  );
6396
6397 }
6398
6399
6400 //----------------------------------------------------------------------------
6401 void figureCuttingModel::CalculeInversMatrix()
6402 {
6403         _inversModel->Identity ();
6404         _inversModel->Concatenate ( _matrixModel );
6405         _inversModel->Inverse();
6406 }
6407 //----------------------------------------------------------------------------
6408 bool figureCuttingModel::IfPointInside(double x, double y, double z) // virtual
6409 {
6410         return true;
6411 }
6412
6413 //----------------------------------------------------------------------------
6414 vtkTransform *figureCuttingModel::GetVtkTransform()
6415 {
6416         return _matrixVisual;
6417 }
6418
6419 //----------------------------------------------------------------------------
6420 //void figureCuttingModel::SetVtkTransform(vtkTransform *matrix)
6421 //{
6422 //      _matrixModel = matrix;
6423 //}
6424
6425 //----------------------------------------------------------------------------
6426 double figureCuttingModel::GetTheoricVolume() // virtual
6427 {
6428         return 0;
6429 }
6430
6431 //----------------------------------------------------------------------------
6432 double figureCuttingModel::GetPositionX()
6433 {
6434         return _px;
6435 }
6436 //----------------------------------------------------------------------------
6437 double figureCuttingModel::GetPositionY()
6438 {
6439         return _py;
6440 }
6441 //----------------------------------------------------------------------------
6442 double figureCuttingModel::GetPositionZ()
6443 {
6444         return _pz;
6445 }
6446 //----------------------------------------------------------------------------
6447 double figureCuttingModel::GetScaleX()
6448 {
6449         return _sx;
6450 }
6451 //----------------------------------------------------------------------------
6452 double figureCuttingModel::GetScaleY()
6453 {
6454         return _sy;
6455 }
6456 //----------------------------------------------------------------------------
6457 double figureCuttingModel::GetScaleZ()
6458 {
6459         return _sz;
6460 }
6461 //----------------------------------------------------------------------------
6462 double figureCuttingModel::GetAngleAlfa()
6463 {
6464         return _alfa;
6465 }
6466 //----------------------------------------------------------------------------
6467 double figureCuttingModel::GetAngleBeta()
6468 {
6469         return _beta;
6470 }
6471 //----------------------------------------------------------------------------
6472 double figureCuttingModel::GetAngleTeta()
6473 {
6474         return _teta;
6475 }
6476 //----------------------------------------------------------------------------
6477 char *figureCuttingModel::GetName() // virtual
6478 {
6479         return "--";
6480 }
6481
6482 //----------------------------------------------------------------------------
6483 void figureCuttingModel::SetSpacing(double spcX,double spcY, double spcZ)
6484 {
6485         _spcX = spcX;
6486         _spcY = spcY;
6487         _spcZ = spcZ;
6488 }
6489
6490 //----------------------------------------------------------------------------
6491
6492
6493 //----------------------------------------------------------------------------
6494 //----------------------------------------------------------------------------
6495 //----------------------------------------------------------------------------
6496 figureCuttingSphereModel::figureCuttingSphereModel()
6497 {
6498 }
6499 //----------------------------------------------------------------------------
6500 figureCuttingSphereModel::~figureCuttingSphereModel() // virtual
6501 {
6502 }
6503 //----------------------------------------------------------------------------
6504 bool figureCuttingSphereModel::IfPointInside(double x, double y, double z) // virtual
6505 {
6506         double in[4],out[4];
6507         in[0]=x;
6508         in[1]=y;
6509         in[2]=z;
6510         in[3]=1;
6511         _inversModel->MultiplyPoint (in, out);
6512
6513         bool result=false;
6514         if (sqrt( out[0]*out[0] + out[1]*out[1] + out[2]*out[2] )<0.5 )
6515         {
6516                 result=true;
6517         }
6518         return result;
6519 }
6520 //----------------------------------------------------------------------------
6521 double figureCuttingSphereModel::GetTheoricVolume() // virtual
6522 {
6523         double piTMP=3.14159265;
6524         return (4.0/3.0) * piTMP * (_sx/2)*(_sy/2)*(_sz/2);
6525 }
6526 //----------------------------------------------------------------------------
6527 char *figureCuttingSphereModel::GetName() // virtual
6528 {
6529         return "Sphere";
6530 }
6531
6532
6533 //----------------------------------------------------------------------------
6534 //----------------------------------------------------------------------------
6535 //----------------------------------------------------------------------------
6536 figureCuttingCubeModel::figureCuttingCubeModel()
6537 {
6538 }
6539 //----------------------------------------------------------------------------
6540 figureCuttingCubeModel::~figureCuttingCubeModel()  // virtual
6541 {
6542 }
6543 //----------------------------------------------------------------------------
6544 bool figureCuttingCubeModel::IfPointInside(double x, double y, double z) // virtual
6545 {
6546         double in[4],out[4];
6547         in[0]=x;
6548         in[1]=y;
6549         in[2]=z;
6550         in[3]=1;
6551         _inversModel->MultiplyPoint (in, out);
6552
6553         bool result=false;
6554         if ((out[0]>-0.5) && (out[0]<0.5) && (out[1]>-0.5) && (out[1]<0.5)  && (out[2]>-0.5) && (out[2]<0.5)  )
6555         {
6556                 result=true;
6557         }
6558         return result;
6559 }
6560 //----------------------------------------------------------------------------
6561 double figureCuttingCubeModel::GetTheoricVolume() // virtual
6562 {
6563         return _sx * _sy * _sz;
6564 }
6565
6566 //----------------------------------------------------------------------------
6567 char *figureCuttingCubeModel::GetName() // virtual
6568 {
6569         return "Cube";
6570 }
6571
6572 //----------------------------------------------------------------------------
6573 //----------------------------------------------------------------------------
6574 //----------------------------------------------------------------------------
6575
6576 figureCuttingCylinderModel::figureCuttingCylinderModel()
6577 {
6578 }
6579 //----------------------------------------------------------------------------
6580 figureCuttingCylinderModel::~figureCuttingCylinderModel()  // virtual
6581 {
6582 }
6583 //----------------------------------------------------------------------------
6584 bool figureCuttingCylinderModel::IfPointInside(double x, double y, double z) // virtual
6585 {
6586         double in[4],out[4];
6587         in[0]=x;
6588         in[1]=y;
6589         in[2]=z;
6590         in[3]=1;
6591         _inversModel->MultiplyPoint (in, out);
6592
6593         bool result=false;
6594         if ((sqrt( out[0]*out[0] + out[2]*out[2] )<0.5 )  && (out[1]>-0.5) && (out[1]<0.5)  )
6595         {
6596                 result=true;
6597         }
6598         return result;
6599 }
6600 //----------------------------------------------------------------------------
6601 double figureCuttingCylinderModel::GetTheoricVolume() // virtual
6602 {
6603         double piTMP=3.14159265;
6604         return piTMP*(_sx/2)*(_sz/2)*_sy;
6605 }
6606 //----------------------------------------------------------------------------
6607 char *figureCuttingCylinderModel::GetName() // virtual
6608 {
6609         return "Cylinder";
6610 }
6611 //----------------------------------------------------------------------------
6612
6613
6614
6615 // EOF - wxMPRWidget.cxx
6616
6617
6618
6619