]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/wxMPRWidget.cxx
*** empty log message ***
[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/04 07:35:42 $
7   Version:   $Revision: 1.11 $
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         //void *p=this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer(); // JPRx
2691
2692
2693         int i=0,xi,r,g,b;
2694         
2695         vtkImageData *imagedata = this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
2696
2697         HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Color table"),imagedata,2);
2698         
2699                 
2700         hDlg->erasePointsTransferenceFunction();        
2701         int ctfSize=ctfunVectorRed->size();
2702         if(ctfSize>0)
2703         {
2704 // MACHETE  OJO Eduardo
2705                 int i=0;
2706                         while(i<ctfSize)
2707                         {
2708                                 double gr       = (*ctfunVectorPoint)[i];
2709                                 double r        = (*ctfunVectorRed)[i];
2710                                 double g        = (*ctfunVectorGreen)[i];
2711                                 double b        = (*ctfunVectorBlue)[i];
2712                         
2713 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
2714                                 i++;
2715                         }
2716         }
2717
2718         //
2719         // when the user had changed the transference Function
2720         //
2721         
2722         //setting variables if the user wants to do refresh
2723         
2724         hDlg->setCTF(ctfun);
2725         hDlg->setMPR3Dview(_wxvtkmpr3Dview);
2726         
2727         if(hDlg->ShowModal()== wxID_OK )
2728         {       
2729                 
2730                 // -- vtkColorTransferFunction  --
2731                         ctfun->RemoveAllPoints ();
2732                         //clean colors
2733                         ctfunVectorPoint->clear();
2734                         ctfunVectorRed->clear();
2735                         ctfunVectorGreen->clear();
2736                         ctfunVectorBlue->clear();
2737
2738                         int nCTFpoints=hDlg->getSizeBarColor();
2739 // Machete .. Ojo Eduardo
2740                         i=0;    
2741                         while(i<nCTFpoints)
2742                         {
2743                                 hDlg->getDataBarColorPoint(i,xi,r,g,b);
2744                                 /*
2745                                 if (i==0)
2746                                 {
2747                                         hDlg->getDataBarColorPoint(1,xi,r,g,b);
2748                                 } 
2749                                 if (i==nCTFpoints)
2750                                 {
2751                                         hDlg->getDataBarColorPoint(i-1,xi,r,g,b);
2752                                 } 
2753                                 */
2754                                 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
2755                                 ctfunVectorPoint->push_back(xi);
2756                                 ctfunVectorRed->push_back(r/255.0);
2757                                 ctfunVectorGreen->push_back(g/255.0);
2758                                 ctfunVectorBlue->push_back(b/255.0);
2759                                 i++;
2760                                 
2761                         }
2762                         
2763         }
2764         
2765         else
2766         {
2767                 
2768                 if(hDlg->getRefreshed())
2769                 {
2770                         // -- vtkColorTransferFunction  --
2771                         ctfun->RemoveAllPoints ();
2772                         
2773                         int i=0;
2774                         int size=ctfunVectorPoint->size();
2775                         
2776                         for(i=0;i<size;i++)
2777                         {
2778                                 double grey2=(*ctfunVectorPoint)[i];
2779                                 double red =(*ctfunVectorRed)[i];
2780                                 double green =(*ctfunVectorGreen)[i];
2781                                 double blue = (*ctfunVectorBlue)[i];
2782                                 ctfun->AddRGBPoint(grey2,red,green,blue);
2783                         }
2784                  }      
2785                  
2786         }
2787
2788  hDlg->Destroy();
2789 }
2790
2791
2792 //-------------------------------------------------------------------
2793 void wxVtkMPR3DViewCntrlPanel::OnVisibleAxisX(wxCommandEvent& event)
2794 {
2795         _wxvtkmpr3Dview->VisibleImageActor(0, event.IsChecked() );
2796         _wxvtkmpr3Dview->Refresh();
2797
2798         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
2799
2800         try{
2801                 _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
2802         }catch(char* e){
2803                 std::cout<<e<<std::endl;
2804         }
2805
2806 }
2807 //-------------------------------------------------------------------
2808 void wxVtkMPR3DViewCntrlPanel::OnVisibleAxisY(wxCommandEvent& event)
2809 {
2810         _wxvtkmpr3Dview->VisibleImageActor(1, event.IsChecked() );
2811         _wxvtkmpr3Dview->Refresh();
2812
2813         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
2814         _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
2815
2816 }
2817 //-------------------------------------------------------------------
2818 void wxVtkMPR3DViewCntrlPanel::OnVisibleAxisZ(wxCommandEvent& event)
2819 {
2820         _wxvtkmpr3Dview->VisibleImageActor(2, event.IsChecked() );
2821         _wxvtkmpr3Dview->Refresh();
2822
2823         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
2824         _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
2825 }
2826
2827 //-------------------------------------------------------------------
2828 void wxVtkMPR3DViewCntrlPanel::OnVisibleAxisXYZ(wxCommandEvent& event)
2829 {
2830         _wxvtkmpr3Dview->VisiblePointWidget(event.IsChecked());
2831 }
2832
2833 //-------------------------------------------------------------------
2834 void wxVtkMPR3DViewCntrlPanel::OnVisiblePlane(wxCommandEvent& event)
2835 {
2836         _wxvtkmpr3Dview->VisiblePlaneWidget(event.IsChecked());
2837 }
2838
2839
2840 //-------------------------------------------------------------------
2841 void wxVtkMPR3DViewCntrlPanel::OnPositionX(wxScrollEvent& event)
2842 {
2843         _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetX( _positionX->GetValue() );
2844         _wxvtkmpr3Dview->RefreshView();
2845         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
2846         _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
2847 }
2848 //-------------------------------------------------------------------
2849 void wxVtkMPR3DViewCntrlPanel::OnPositionY(wxScrollEvent& event)
2850 {
2851         _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetY( _positionY->GetValue() );
2852         _wxvtkmpr3Dview->RefreshView();
2853         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
2854         _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
2855 }
2856 //-------------------------------------------------------------------
2857 void wxVtkMPR3DViewCntrlPanel::OnPositionZ(wxScrollEvent& event)
2858 {
2859         _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetZ( _positionZ->GetValue() );
2860         _wxvtkmpr3Dview->RefreshView();
2861         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
2862         _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
2863 }
2864
2865
2866 //-------------------------------------------------------------------
2867 //-------------------------------------------------------------------
2868 //-------------------------------------------------------------------
2869
2870 wxVtkClipping3DViewCntrlPanel::wxVtkClipping3DViewCntrlPanel(wxWindow *parent, wxVtkClipping3DView *wxvtkclipping3Dview )
2871 : wxPanel(parent, -1)
2872 {
2873         wxPanel *panel  = this;
2874         _wxvtkclipping3Dview    = wxvtkclipping3Dview;
2875
2876 //EEDx2.6
2877 //      wxStaticText    *text1                  = new wxStaticText(panel, -1,_T("          "));
2878 //      wxStaticText    *text2                  = new wxStaticText(panel, -1,_T("  "));
2879
2880                                         _surfA                  = new wxRadioButton(panel,-1,_T("A"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
2881                                         _surfB                  = new wxRadioButton(panel,-1,_T("B"));
2882                                         _surfC                  = new wxRadioButton(panel,-1,_T("C"));
2883                                         _surfD                  = new wxRadioButton(panel,-1,_T("D"));
2884
2885         wxCheckBox              *ckVolum                = new wxCheckBox(panel,-1,_T("Vol"));
2886         wxCheckBox              *ckBoxSurface   = new wxCheckBox(panel,-1,_T("Surface Box"));
2887         wxCheckBox              *ckBoxVolume    = new wxCheckBox(panel,-1,_T("Volume Box"));
2888
2889                                         _color                  = new wxButton(panel,-1,_T(""));
2890                                         _visible                = new wxCheckBox(panel,-1,_T("Vis"));
2891                                         _opacity                = new wxSlider(panel,-1,50,0,100, wxDefaultPosition, wxSize(800,40), wxSL_HORIZONTAL | wxSL_LABELS);
2892
2893         wxStaticText    *isoValueTitle  = new wxStaticText(panel,-1,_T("isoValue"));
2894                                         _isoValue               = new wxSlider(panel,-1,2000,110,2000, wxDefaultPosition, wxSize(800,40), wxSL_HORIZONTAL  |  wxSL_AUTOTICKS | wxSL_LABELS);
2895
2896
2897                                         _wireFrameRep   = new wxRadioButton(panel,-1,_T("WireFrame"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
2898                                         _surfaceRep             = new wxRadioButton(panel,-1,_T("Surface"));
2899
2900
2901         double range[2];
2902         vtkImageData *vtkimagedata = wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
2903         vtkimagedata->GetScalarRange( range );
2904         _isoValue->SetRange( (int)(range[1]*0.1) , (int)(range[1]) );
2905         _isoValue->SetValue( (int)(wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIsovalue(0)) );
2906
2907
2908         _isoValue->SetTickFreq(25,0);
2909
2910         _isoValueSpin   = new wxSlider(panel , -1,5,1,10,wxDefaultPosition , wxSize(25,45), wxSL_VERTICAL | wxSL_AUTOTICKS |wxSL_LEFT  );
2911         _isoValueSpin->SetRange(1,8);
2912         _isoValueSpin->SetValue(5);
2913         Connect(_isoValueSpin->GetId()  , wxEVT_COMMAND_SLIDER_UPDATED   , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValueSpin ); 
2914
2915         wxButton *btnSTL                                = new wxButton(panel,-1,_T("Create STL File"));
2916         wxButton *btnSaveRaw                    = new wxButton(panel,-1,_T("Save Raw Volume"));
2917
2918         wxButton *btnVolumeFunctions    = new wxButton(panel,-1,_T("Read Volume Functions"));
2919
2920
2921         Connect(btnSTL->GetId()                         , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnCreateFileSTL    ); 
2922         Connect(btnSaveRaw->GetId()                     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnSaveRawVolume    ); 
2923         Connect(btnVolumeFunctions->GetId()     , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnVolumeFunctions  ); 
2924
2925
2926         wxButton *btnMeshVTKLoad        = new wxButton(panel,-1,_T("Load Mesh"));
2927         Connect(btnMeshVTKLoad->GetId() , wxEVT_COMMAND_BUTTON_CLICKED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnBtnMeshVTKLoad      ); 
2928
2929
2930 /*
2931         int maxX = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionX();
2932         int maxY = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionY();
2933         int maxZ = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetMaxPositionZ();
2934         wxCheckBox              *ckBoxX                 = new wxCheckBox(panel,-1,"X");
2935                                         _positionX              = new wxSlider(panel,-1,maxX/2,0,maxX, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
2936         wxCheckBox              *ckBoxY                 = new wxCheckBox(panel,-1,"Y");
2937                                         _positionY              = new wxSlider(panel,-1,maxY/2,0,maxY, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
2938         wxCheckBox              *ckBoxZ                 = new wxCheckBox(panel,-1,"Z");
2939                                         _positionZ              = new wxSlider(panel,-1,maxZ/2,0,maxZ, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL | wxSL_LABELS);
2940 */
2941
2942 //      ckVolum->Enable(false);
2943         ckBoxSurface->SetValue(false);
2944         ckBoxVolume->SetValue(false);
2945         _color->SetSize(40,20);
2946         _opacity->SetSize(370,20);
2947 //      ckBoxX->SetValue(true);
2948 //      ckBoxY->SetValue(true);
2949 //      ckBoxZ->SetValue(true);
2950         _surfA->SetValue(true);
2951         _wireFrameRep->SetValue(false);
2952         _surfaceRep->SetValue(true);
2953         _visible->SetValue(false);
2954 //      _positionX->SetSize(400,20);
2955 //      _positionY->SetSize(400,20);
2956 //      _positionZ->SetSize(400,20);
2957
2958         Connect(ckVolum->GetId()                , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleVolume                             );
2959         Connect(ckBoxVolume->GetId()    , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume                  );
2960
2961         Connect(_surfA->GetId()                 , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface                                       );
2962         Connect(_surfB->GetId()                 , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface                                       );
2963         Connect(_surfC->GetId()                 , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface                                       );
2964         Connect(_surfD->GetId()                 , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnSurface                                       );
2965         Connect(ckBoxSurface->GetId()   , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleBoxSurface                 );
2966
2967         Connect(_wireFrameRep->GetId()  , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame        );
2968         Connect(_surfaceRep->GetId()    , wxEVT_COMMAND_RADIOBUTTON_SELECTED  , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame        );
2969
2970         Connect(_color->GetId()                 , wxEVT_COMMAND_BUTTON_CLICKED            , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnColor                                             );
2971         Connect(_visible->GetId()               , wxEVT_COMMAND_CHECKBOX_CLICKED          , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnVisibleSurface                    );
2972         Connect(_opacity->GetId()               , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnOpacity                                   );
2973
2974 //EED 27Dic2007
2975 //      Connect(_isoValue->GetId()              , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValue                                  );
2976         Connect(_isoValue->GetId()              , wxEVT_SCROLL_THUMBRELEASE               , (wxObjectEventFunction) &wxVtkClipping3DViewCntrlPanel::OnIsoValue                                          );
2977
2978 /*
2979         Connect(ckBoxX->GetId()     , wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisX   );
2980         Connect(_positionX->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionX              );
2981         Connect(ckBoxY->GetId()     , wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisY   );
2982         Connect(_positionY->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionY              );
2983         Connect(ckBoxZ->GetId()     , wxEVT_COMMAND_CHECKBOX_CLICKED      , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnVisibleAxisZ   );
2984         Connect(_positionZ->GetId()     , wxEVT_COMMAND_SLIDER_UPDATED            , (wxObjectEventFunction) &wxVtkMPR3DViewCntrlPanel::OnPositionZ              );
2985 */
2986
2987         wxFlexGridSizer *sizer   = new wxFlexGridSizer(1);
2988         wxFlexGridSizer *sizerH0 = new wxFlexGridSizer(20);
2989         wxFlexGridSizer *sizerH1 = new wxFlexGridSizer(20);
2990         wxFlexGridSizer *sizerH2 = new wxFlexGridSizer(10);
2991         wxFlexGridSizer *sizerH3 = new wxFlexGridSizer(10);
2992         //wxFlexGridSizer *sizerH4 = new wxFlexGridSizer(10); // JPRx
2993         //wxFlexGridSizer *sizerH5 = new wxFlexGridSizer(10); // JPRx
2994         //wxFlexGridSizer *sizerH6 = new wxFlexGridSizer(10); // JPRx
2995
2996         sizerH0->Add( ckVolum                                                                   , 1, wxALL|wxEXPAND, 0);
2997         sizerH0->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
2998         sizerH0->Add( ckBoxVolume                                                               , 1, wxALL|wxEXPAND, 0);
2999         sizerH0->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
3000         sizerH0->Add( btnVolumeFunctions                                                , 1, wxALL|wxEXPAND, 0);
3001         sizerH0->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
3002         sizerH0->Add( btnMeshVTKLoad                                                    , 1, wxALL|wxEXPAND, 0);
3003
3004
3005         sizerH1->Add( _surfA                                                                    , 1, wxALL|wxEXPAND, 0);
3006         sizerH1->Add( new wxStaticText(panel, -1,_T("  "))                      , 1, wxALL|wxEXPAND, 0);
3007         sizerH1->Add( _surfB                                                                    , 1, wxALL|wxEXPAND, 0);
3008         sizerH1->Add( new wxStaticText(panel, -1,_T("  "))                      , 1, wxALL|wxEXPAND, 0);
3009         sizerH1->Add( _surfC                                                                    , 1, wxALL|wxEXPAND, 0);
3010         sizerH1->Add( new wxStaticText(panel, -1,_T("  "))                      , 1, wxALL|wxEXPAND, 0);
3011         sizerH1->Add( _surfD                                                                    , 1, wxALL|wxEXPAND, 0);
3012         sizerH1->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
3013         sizerH1->Add( ckBoxSurface                                                              , 1, wxALL|wxEXPAND, 0);
3014         sizerH1->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
3015         sizerH1->Add( btnSTL                                                                    , 1, wxALL|wxEXPAND, 0);
3016         sizerH1->Add( new wxStaticText(panel, -1,_T("          "))      , 1, wxALL|wxEXPAND, 0);
3017         sizerH1->Add( btnSaveRaw                                                                , 1, wxALL|wxEXPAND, 0);
3018
3019
3020 //      sizerH2->Add( new wxStaticText(panel, -1,_T("          ")                       , 1, wxALL|wxEXPAND, 0);
3021         sizerH2->Add( _color                            , 1, wxALL|wxEXPAND, 0);
3022         sizerH2->Add( new wxStaticText(panel, -1,_T("          "))                      , 1, wxALL|wxEXPAND, 0);
3023         sizerH2->Add( _visible                          , 1, wxALL|wxEXPAND, 0);
3024         sizerH2->Add( new wxStaticText(panel, -1,_T("          "))                      , 1, wxALL|wxEXPAND, 0);
3025
3026         
3027         sizerH2->Add( _wireFrameRep                             , 1,wxSHAPED | wxALIGN_CENTER_VERTICAL , 0);
3028         sizerH2->Add( new wxStaticText(panel, -1,_T("   "))                                     , 1, wxALL|wxEXPAND, 0);
3029         sizerH2->Add( _surfaceRep                               , 1,wxSHAPED | wxALIGN_CENTER_VERTICAL , 0);
3030         sizerH2->Add( new wxStaticText(panel, -1,_T("          "))                      , 1, wxALL|wxEXPAND, 0);
3031         
3032         sizerH2->Add( _opacity                          , 1, wxALL|wxEXPAND, 0);
3033
3034
3035         sizerH3->Add( isoValueTitle                     , 1, wxALL|wxEXPAND, 0);
3036         sizerH3->Add( _isoValueSpin                     , 1, wxALL|wxEXPAND, 0);
3037         sizerH3->Add( _isoValue                         , 1, wxALL|wxEXPAND, 0);
3038
3039 /*
3040         sizerH4->Add( ckBoxX            , 1, wxALL|wxEXPAND, 0);
3041         sizerH4->Add( text2                     , 1, wxALL|wxEXPAND, 0);
3042         sizerH4->Add( _positionX                , 1, wxALL|wxEXPAND, 0);
3043
3044         sizerH5->Add( ckBoxY            , 1, wxALL|wxEXPAND, 0);
3045         sizerH5->Add( text2                     , 1, wxALL|wxEXPAND, 0);
3046         sizerH5->Add( _positionY                , 1, wxALL|wxEXPAND, 0);
3047
3048         sizerH6->Add( ckBoxZ            , 1, wxALL|wxEXPAND, 0);
3049         sizerH6->Add( text2                     , 1, wxALL|wxEXPAND, 0);
3050         sizerH6->Add( _positionZ                , 1, wxALL|wxEXPAND, 0);
3051 */
3052         sizer->Add( sizerH0 , 1, wxALL|wxEXPAND, 2);
3053         sizer->Add( sizerH1 , 1, wxALL|wxEXPAND, 2);
3054         sizer->Add( sizerH2 , 1, wxALL|wxEXPAND, 2);
3055         sizer->Add( sizerH3 , 1, wxALL|wxEXPAND, 2);
3056 //      sizer->Add( sizerH4 , 1, wxALL|wxEXPAND, 2);
3057 //      sizer->Add( sizerH5 , 1, wxALL|wxEXPAND, 2);
3058 //      sizer->Add( sizerH6 , 1, wxALL|wxEXPAND, 2);
3059
3060         panel->SetSize(300,60);
3061         panel->SetAutoLayout(true);
3062         panel->SetSizer(sizer);
3063         panel->Layout();
3064
3065         panel->SetEventHandler((wxEvtHandler*)this);
3066
3067 }
3068 //-------------------------------------------------------------------
3069 wxVtkClipping3DViewCntrlPanel::~wxVtkClipping3DViewCntrlPanel()
3070 {
3071 }
3072 //-------------------------------------------------------------------
3073 void wxVtkClipping3DViewCntrlPanel::Refresh()
3074 {
3075 //      wxPanel::Refresh();
3076 /*
3077         _positionX->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetX( ) );
3078         _positionY->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetY( ) );
3079         _positionZ->SetValue( _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetZ( ) );
3080 */
3081 }
3082 //-------------------------------------------------------------------
3083 int wxVtkClipping3DViewCntrlPanel::GetIdTissue()
3084 {
3085         int idTissue=-1;
3086         if (_surfA->GetValue()==true)
3087         {
3088                 idTissue=0;
3089         }
3090         if (_surfB->GetValue()==true)
3091         {
3092                 idTissue=1;
3093         }
3094         if (_surfC->GetValue()==true)
3095         {
3096                 idTissue=2;
3097         }
3098         if (_surfD->GetValue()==true)
3099         {
3100                 idTissue=3;
3101         }
3102
3103         return idTissue;
3104 }
3105 /*
3106 //-------------------------------------------------------------------
3107 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisX(wxCommandEvent& event)
3108 {
3109         _wxvtkclipping3Dview->VisibleImageActor(0, event.IsChecked() );
3110         _wxvtkclipping3Dview->Refresh();
3111 }
3112 //-------------------------------------------------------------------
3113 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisY(wxCommandEvent& event)
3114 {
3115         _wxvtkclipping3Dview->VisibleImageActor(1, event.IsChecked() );
3116         _wxvtkclipping3Dview->Refresh();
3117 }
3118 //-------------------------------------------------------------------
3119 void wxVtkClipping3DViewCntrlPanel::OnVisibleAxisZ(wxCommandEvent& event)
3120 {
3121         _wxvtkclipping3Dview->VisibleImageActor(2, event.IsChecked() );
3122         _wxvtkclipping3Dview->Refresh();
3123 }
3124 */
3125
3126 //-------------------------------------------------------------------
3127 void wxVtkClipping3DViewCntrlPanel::OnSurface(wxCommandEvent& event)
3128 {
3129         int idTissue=GetIdTissue();
3130         if (idTissue!=-1)
3131         {
3132                 // Color
3133                 vtkActor *tmpActor;
3134                 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
3135                 double rgb[3];
3136                 tmpActor->GetProperty()->GetColor( rgb );
3137                 wxColour colour( (int)(rgb[0]*255) , (int)(rgb[1]*255) , (int)(rgb[2]*255) );
3138                 _color->SetBackgroundColour(colour);
3139
3140                 // Visible
3141                 _visible->SetValue(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVisibleTissue(idTissue));
3142
3143                 // Opacity
3144                 _opacity->SetValue( (int)(tmpActor->GetProperty()->GetOpacity()*100) );
3145
3146                 // Representation Type  WireFrame / Surface
3147                 _surfaceRep->SetValue(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRepresentationType(idTissue)); 
3148                 _wireFrameRep->SetValue(!_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRepresentationType(idTissue)); 
3149
3150                 // isoValue
3151                 int isoValue= (int)(_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIsovalue(idTissue));
3152                 _isoValue->SetValue(isoValue);
3153         }
3154 }
3155
3156
3157 //-------------------------------------------------------------------
3158 void wxVtkClipping3DViewCntrlPanel::OnRepresentationSurfaceWireFrame(wxCommandEvent& event)
3159 {
3160         int idTissue=GetIdTissue();
3161         if (idTissue!=-1)
3162         {
3163                 _wxvtkclipping3Dview->SetRepSurfaceWireFrame(idTissue , _surfaceRep->GetValue() );
3164
3165                 _wxvtkclipping3Dview->Refresh();
3166
3167                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3168                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3169
3170         }
3171 }
3172
3173 //-------------------------------------------------------------------
3174 void wxVtkClipping3DViewCntrlPanel::OnVisibleVolume(wxCommandEvent& event)
3175 {
3176         _wxvtkclipping3Dview->VisibleVolumeActor( event.IsChecked()  );
3177         _wxvtkclipping3Dview->Refresh();
3178
3179         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3180         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3181 }
3182 //-------------------------------------------------------------------
3183 void wxVtkClipping3DViewCntrlPanel::OnVisibleBoxSurface(wxCommandEvent& event)
3184 {
3185         _wxvtkclipping3Dview->SetVisibleBoxSurface(event.IsChecked() );
3186         _wxvtkclipping3Dview->Refresh();
3187 }
3188 //-------------------------------------------------------------------
3189 void wxVtkClipping3DViewCntrlPanel::OnVisibleBoxVolume(wxCommandEvent& event)
3190 {
3191         _wxvtkclipping3Dview->SetVisibleBoxVolume(event.IsChecked() );
3192         _wxvtkclipping3Dview->Refresh();
3193 }
3194 //-------------------------------------------------------------------
3195 void wxVtkClipping3DViewCntrlPanel::OnColor(wxCommandEvent& event)
3196 {
3197         int idTissue=GetIdTissue();
3198         if (idTissue!=-1)
3199         {
3200 // EED 17 Janvier 2007
3201                 wxColourDialog dlgColour(this);
3202 //              dlgColour.ShowModal();
3203                 if( dlgColour.ShowModal( ) == wxID_OK ) 
3204                 {
3205                         vtkActor *tmpActor;
3206                         tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
3207                         float r=dlgColour.GetColourData().GetColour().Red()/255;
3208                         float g=dlgColour.GetColourData().GetColour().Green()/255;
3209                         float b=dlgColour.GetColourData().GetColour().Blue()/255;
3210                         tmpActor->GetProperty()->SetColor( r , g , b );
3211                         _color->SetBackgroundColour(dlgColour.GetColourData().GetColour());
3212
3213                         _wxvtkclipping3Dview->Refresh();
3214
3215                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3216                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3217                 }
3218         }
3219 }
3220 //-------------------------------------------------------------------
3221 void wxVtkClipping3DViewCntrlPanel::OnVisibleSurface(wxCommandEvent& event)
3222 {
3223         int idTissue=GetIdTissue();
3224         if (idTissue!=-1)
3225         {
3226                 _wxvtkclipping3Dview->VisibleActor(idTissue, _visible->GetValue());
3227
3228                 _wxvtkclipping3Dview->Refresh();
3229
3230                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3231                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3232         }
3233 }
3234 //-------------------------------------------------------------------
3235 void wxVtkClipping3DViewCntrlPanel::OnOpacity(wxScrollEvent& event)
3236 {
3237         int idTissue=GetIdTissue();
3238         if (idTissue!=-1)
3239         {
3240                 vtkActor *tmpActor;
3241                 tmpActor = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
3242                 float opacity=_opacity->GetValue();
3243                 tmpActor->GetProperty()->SetOpacity( opacity/100 );
3244
3245                 _wxvtkclipping3Dview->Refresh();
3246
3247                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3248                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3249         }
3250 }
3251
3252 //----------------------------------------------------------------------------
3253 void wxVtkClipping3DViewCntrlPanel::OnIsoValueSpin(wxScrollEvent& event)
3254 {
3255         int value = _isoValue->GetValue();
3256         int delta= (int)pow( 4 , _isoValueSpin->GetValue() );
3257         int min=value - delta/2;
3258         int max=value + delta/2;
3259         if (min<0)
3260         {
3261                 min=0;
3262                 max=delta;
3263         }
3264         _isoValue->SetRange(min,max);
3265 }
3266
3267
3268 //------------------------------------------------------------------------
3269 void wxVtkClipping3DViewCntrlPanel::OnIsoValue(wxScrollEvent& event)
3270 {
3271         wxBusyCursor wait;
3272
3273         int idTissue=GetIdTissue();
3274         if (idTissue!=-1)
3275         {
3276                 int isoValue=_isoValue->GetValue();
3277                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->SetIsovalue(idTissue,isoValue);
3278 //              wxString tmpStr;
3279 //              tmpStr.Printf("%d",isoValue);
3280         
3281                 _wxvtkclipping3Dview->Refresh();
3282
3283                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3284                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3285         }
3286
3287 }
3288 //-------------------------------------------------------------------
3289 void wxVtkClipping3DViewCntrlPanel::OnBtnCreateFileSTL(wxCommandEvent& event)
3290 {
3291
3292         int idTissue=GetIdTissue();
3293         if (idTissue==-1)
3294         {
3295                 idTissue=0;
3296         }
3297
3298
3299         wxString dirSTL = wxGetHomeDir( ) ;
3300         wxFileDialog dialog( this, _T("Choose a directory..."), dirSTL , _T(""), _T("*.*"), wxSAVE );
3301
3302         if( dialog.ShowModal( ) == wxID_OK ) 
3303         {
3304            
3305         
3306                 // ------------------------------------------------------------------------
3307                 //  1.  GENERATE STL FILES
3308                 // ------------------------------------------------------------------------
3309 //              const char* fileprefix = "c:\\Creatis\\";
3310                 std::string prefix = (const char*) (dialog.GetPath().mb_str() );
3311                 std::string filename;
3312
3313                 // 1.1. Se hace un filtro triangular puesto que el stl writer solo recibe poligonos triangulares.
3314
3315         vtkTriangleFilter *filtro = vtkTriangleFilter::New();
3316
3317
3318                 filtro->SetInput( this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTissueClipper(idTissue)->GetOutput() );
3319                 vtkPolyDataConnectivityFilter *pdcf = vtkPolyDataConnectivityFilter::New();
3320         pdcf->SetInput( filtro->GetOutput() );
3321         vtkClosePolyData *cpd = vtkClosePolyData::New();
3322         cpd->SetInput( pdcf->GetOutput() );
3323
3324                 // 1.2 se escribe a disco el archivo stl de la superficie interna
3325         cpd->Update();
3326         vtkSTLWriter *writer = vtkSTLWriter::New();
3327         writer->SetInput( cpd->GetOutput() );
3328                 filename =prefix;
3329         writer->SetFileName(filename.c_str());
3330         writer->SetFileTypeToASCII();
3331         writer->Write();
3332         writer->Delete();
3333
3334    
3335         filtro->Delete();
3336         cpd->Delete();
3337         pdcf->Delete();
3338         }
3339
3340 }
3341
3342 //EED 30 Janvier 2007
3343 //-------------------------------------------------------------------
3344 void wxVtkClipping3DViewCntrlPanel::OnBtnSaveRawVolume(wxCommandEvent& event)
3345 {
3346         wxFileDialog dialog(this, _T("Choose a file"), _T(""), _T(""), _T("*.maracas"), wxSAVE );
3347         if (dialog.ShowModal() == wxID_OK)
3348         {
3349                 std::string directory = (const char*) (dialog.GetDirectory().mb_str() );
3350                 std::string filename  = (const char*) (dialog.GetFilename().mb_str() );
3351                 float rescalaSlope           =  1;
3352                 float rescalaIntercept       =  0;
3353                 vtkMPRBaseData *vtkmprbasedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData();
3354                 vtkImageData *vtkimagedata       = vtkmprbasedata->GetImageData();
3355                 int dim[3];
3356                 vtkimagedata->GetDimensions(dim);
3357                 int voi[6];
3358                 voi[0]=0;
3359                 voi[1]=dim[0];
3360                 voi[2]=0;
3361                 voi[3]=dim[1];
3362                 voi[4]=0;
3363                 voi[5]=dim[2];
3364 //EED 10 oct 2007 MaracasVisu pour bbMaracasvisu
3365                 marRAW2Files marraw2;
3366                 marraw2.saveVolume(directory,filename,vtkimagedata,voi,rescalaSlope,rescalaIntercept);
3367         }
3368 }
3369
3370 //EED 22 Fevrier 2007
3371 //-------------------------------------------------------------------
3372 void wxVtkClipping3DViewCntrlPanel::OnBtnVolumeFunctions(wxCommandEvent& event)
3373 {
3374         
3375         int /*i=0,*/ xi,yi,r,g,b;  // JPRx
3376         vtkColorTransferFunction* ctfun = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetColorTransferenceFunction();
3377         vtkPiecewiseFunction* tfun      = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetTransferencefunction();
3378         std::vector<double>* gtf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValuesTransferenceFVector();
3379         std::vector<double>* itf                = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetIntensityValuesTransferenceFVector();
3380         std::vector<double>* greyctf    = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreyValueColorsOfColorTransferenceFVector();
3381         std::vector<double>* rctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetRedColorsOfColorTransferenceFVector();
3382         std::vector<double>* gctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetGreenColorsOfColorTransferenceFVector();
3383         std::vector<double>* bctf               = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetBlueColorsOfColorTransferenceFVector();
3384         vtkImageData *imagedata = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
3385
3386         //use for update in the refresh
3387         /*
3388         vtkVolumeRayCastMapper* volumeMapper = this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeMapper();
3389         vtkVolume* newvol       =this->_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetVolumeActor();
3390         */
3391
3392         /*
3393         MMLR BORRAME 
3394         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.MarVolConf"), wxOPEN);
3395         if (dialog.ShowModal() == wxID_OK)
3396         {
3397                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions( (char *)dialog.GetPath().c_str() );
3398                 
3399         
3400         }
3401         */
3402
3403         HistogramDialog* hDlg=new HistogramDialog(NULL,_T("Histogram Dialog"),imagedata,1);
3404         // 
3405         // put in a method
3406         //
3407         int tfSize=gtf->size();
3408                 if(tfSize>0)
3409                 {
3410                         int i=0;
3411                         hDlg->erasePointsTransferenceFunction();
3412                         while(i<tfSize)
3413                         {
3414                                 double g=(*gtf)[i];
3415                                 double in=(*itf)[i];
3416                                 hDlg->addPointToTransferenceFunction(g,in*100);
3417                                 i++;
3418                         }
3419                         
3420                 }
3421
3422         int ctfSize=rctf->size();
3423         if(ctfSize>0)
3424         {
3425                 int i=0;
3426                         while(i<ctfSize)
3427                         {
3428                                 double gr=(*greyctf)[i];
3429                                 double r=(*rctf)[i];
3430                                 double g=(*gctf)[i];
3431                                 double b=(*bctf)[i];
3432                                 hDlg->addColorPoint(gr,(int)(r*255),(int)(g*255),(int)(b*255));
3433                                 i++;
3434                         }
3435         }
3436         //setting variables if the user wants to do refresh
3437         hDlg->setCTF(ctfun);
3438         hDlg->setTF(tfun);
3439         hDlg->setClipping3DView(_wxvtkclipping3Dview);
3440         /*
3441         hDlg->setVolume(newvol);
3442         hDlg->setVolumeMapper(volumeMapper);
3443         */
3444         //
3445         // when the user had changed the transference Function
3446         //
3447         if(hDlg->ShowModal()== wxID_OK )
3448         {       
3449                         // -- vtkPiecewiseFunction --
3450                         tfun->RemoveAllPoints();
3451                         gtf->clear();
3452                         itf->clear();
3453                 
3454                         int nTFPoints=hDlg->getSizeTransferenceFunction();
3455                         int i=0;
3456                         while(i<nTFPoints)
3457                         {
3458                                 hDlg->getTransferenceFunctionPoint(i,xi,yi);
3459                                 tfun->AddPoint( xi , yi/100.0 );
3460                                 gtf->push_back(xi);
3461                                 itf->push_back(yi/100.0);
3462                                 i++;
3463                         }       
3464                         // -- vtkColorTransferFunction  --
3465                         ctfun->RemoveAllPoints ();
3466                         //clean colors
3467                         rctf->clear();
3468                         gctf->clear();
3469                         bctf->clear();
3470                         greyctf->clear();
3471
3472                         int nCTFpoints=hDlg->getSizeBarColor();
3473                         i=0;    
3474                         while(i<nCTFpoints)
3475                         {
3476                                 hDlg->getDataBarColorPoint(i,xi,r,g,b);
3477                                 ctfun->AddRGBPoint(xi,r/255.0,g/255.0,b/255.0 );
3478                                 rctf->push_back(r/255.0);
3479                                 gctf->push_back(g/255.0);
3480                                 bctf->push_back(b/255.0);
3481                                 greyctf->push_back(xi);
3482                                 i++;
3483                         }
3484                         //---------------------------------
3485                         // Refreshing and sending the event
3486                         //---------------------------------
3487                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
3488                         _wxvtkclipping3Dview->Refresh();
3489                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3490                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3491                         
3492                         /*
3493                         volumeMapper->Update();
3494                         newvol->Update();
3495                         */
3496         }
3497         
3498         else
3499         {
3500                 
3501                 if(hDlg->getRefreshed())
3502                 {
3503                         int i=0,size;
3504                         //--Transference Function----
3505                         tfun->RemoveAllPoints();
3506                         i=0;
3507                         size=gtf->size();
3508                         for(i=0;i<size;i++)
3509                         {
3510                                 double grey1=(*gtf)[i];
3511                                 double  in2=(*itf)[i];
3512                                 tfun->AddPoint( grey1 , in2 );
3513                         }
3514                         
3515                         // -- vtkColorTransferFunction  --
3516                         ctfun->RemoveAllPoints ();
3517                         
3518                         i=0;
3519                         size=greyctf->size();           
3520                         for(i=0;i<size;i++)
3521                         {
3522                                 double grey2=(*greyctf)[i];
3523                                 double red =(*rctf)[i];
3524                                 double green =(*gctf)[i];
3525                                 double blue = (*bctf)[i];
3526                                 ctfun->AddRGBPoint(grey2,red,green,blue);
3527                         }
3528                 
3529                         //---------------------------------
3530                         // Refreshing and sending the event
3531                         //---------------------------------
3532                         //_wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadVolumeFunctions();
3533                         _wxvtkclipping3Dview->Refresh();
3534                         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3535                         _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3536                         
3537                         /*
3538                         volumeMapper->Update();
3539                         newvol->Update();
3540                         */
3541                  }
3542                  
3543         }
3544         //destroy the dialog
3545         hDlg->Destroy();
3546 }
3547
3548 //EED 23 Mai 2007
3549 //-------------------------------------------------------------------
3550 void wxVtkClipping3DViewCntrlPanel::OnBtnMeshVTKLoad(wxCommandEvent& event)
3551 {
3552         wxFileDialog dialog(this, _T("Choose a file"), _T("c:/Maracas_configuration"),_T(""), _T("*.vtk"), wxOPEN);
3553         if (dialog.ShowModal() == wxID_OK)
3554         {
3555                 _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->ReadMeshVTK( (char *)dialog.GetPath().c_str() );
3556                 _wxvtkclipping3Dview->Refresh();
3557                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
3558                 _wxvtkclipping3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
3559         }
3560 }
3561
3562
3563 //-------------------------------------------------------------------
3564 //-------------------------------------------------------------------
3565 //-------------------------------------------------------------------
3566
3567
3568 wxVtkMPR3DView::wxVtkMPR3DView( wxVtk3DBaseView *wxvtk3Dbaseview )
3569 {
3570         _wxvtk3Dbaseview                        =       wxvtk3Dbaseview;
3571         _vtkmpr3Ddataviewer                     =       NULL;
3572         _wxvtkmpr3DviewCntrlPanel       =       NULL;   
3573         _myCallback=NULL;
3574         _pointWidget=NULL;
3575         _planeWidget=NULL;
3576         _vtkplane=NULL;
3577         _probe=NULL;
3578         _contourMapper=NULL;
3579 }
3580 void wxVtkMPR3DView::RemoveActor(vtkActor* actor){      
3581
3582         _wxvtk3Dbaseview->GetRenderer()->RemoveActor(actor);    
3583
3584
3585 }
3586 void wxVtkMPR3DView::ResetCamera(int* ext, double* origin,double* spc){
3587         if(ext == NULL){
3588
3589                 _wxvtk3Dbaseview->GetRenderer()->ResetCamera ();        
3590                 _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);      
3591         }else{
3592                 /*double x = (spc[0])*(origin[0]+(((double)ext[1]-(double)ext[0])/2.0));                
3593                 double y = (spc[1])*(origin[1]+(double)ext[3]);
3594                 double z = (spc[2])*(origin[2]+(((double)ext[5]-(double)ext[4])/2.0));*/
3595                 /*double x0=(spc[0])*((double)ext[0]+origin[0]);
3596                 double x1=(spc[0])*((double)ext[1]+origin[0]);
3597                 double y0=(spc[1])*((double)ext[2]+origin[1]);
3598                 double y1=(spc[1])*((double)ext[3]+origin[1]);
3599                 double z0=(spc[2])*((double)ext[4]+origin[2]);
3600                 double z1=(spc[2])*((double)ext[5]+origin[2]);*/
3601                 double x0=(spc[0])*((double)ext[0]);
3602                 double x1=(spc[0])*((double)ext[1]);
3603                 double y0=(spc[1])*((double)ext[2]);
3604                 double y1=(spc[1])*((double)ext[3]);
3605                 double z0=(spc[2])*((double)ext[4]);
3606                 double z1=(spc[2])*((double)ext[5]);
3607                 
3608                 _wxvtk3Dbaseview->GetRenderer()->ResetCamera(x0,x1,y0,y1,z0,z1);
3609                 //_wxvtk3Dbaseview->GetCamera()->SetPosition(x,y,z);
3610                 _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);      
3611         }
3612 }
3613 void wxVtkMPR3DView::Configure(){
3614
3615
3616         _wxvtk3Dbaseview->Configure();
3617         _wxvtkmpr3DviewCntrlPanel->UpdateControlPanel();
3618         _wxvtk3Dbaseview->GetRenderer()->Clear();               
3619         
3620         // Actors are added to the renderer. 
3621         vtkActor* _outlineActor = _vtkmpr3Ddataviewer->GetOutlineActor();
3622         _wxvtk3Dbaseview->GetRenderer()->AddActor( _outlineActor );                     
3623 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(0)  );    // _saggital
3624 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(1)  );    // _axial
3625 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(2)  );    // _coronal
3626
3627
3628         // An initial camera view is created.  The Dolly() method moves 
3629         // the camera towards the FocalPoint, thereby enlarging the image.      
3630         _wxvtk3Dbaseview->GetRenderer()->SetActiveCamera(_wxvtk3Dbaseview->GetCamera());
3631         this->ResetCamera();
3632         
3633
3634         // Set a background color for the renderer and set the size of the
3635         // render window (expressed in pixels).
3636         _wxvtk3Dbaseview->GetRenderer()->SetBackground( 0.36 , 0.36 , 0.36 );
3637         _wxvtk3Dbaseview->GetRenWin()->SetSize(400, 400);
3638
3639         // Note that when camera movement occurs (as it does in the Dolly()
3640         // method), the clipping planes often need adjusting. Clipping planes
3641         // consist of two planes: near and far along the view direction. The 
3642         // near plane clips out objects in front of the plane; the far plane
3643         // clips out objects behind the plane. This way only what is drawn
3644         // between the planes is actually rendered.
3645         _wxvtk3Dbaseview->GetRenderer()->ResetCameraClippingRange();
3646
3647
3648         // vtkPointWidget
3649         if(_myCallback!=NULL){
3650                 _myCallback->Delete();
3651
3652         }
3653         _myCallback = vtkmyPWCallback_3DPointWidget::New();
3654         _myCallback->SetWxVtkMPR3DView(this);
3655  
3656         if(_pointWidget!=NULL){
3657                 _pointWidget->Delete();
3658         }
3659         _pointWidget = vtkPointWidget::New();
3660         _myCallback->SetVtkPointWidget(_pointWidget);
3661         _pointWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() ); 
3662         _pointWidget->SetInput( GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData() );
3663         
3664         _pointWidget->AllOff();
3665         
3666         _pointWidget->PlaceWidget();
3667 //      _pointWidget->SetPosition( x,y,z ); 
3668         
3669 //EED01 29Mars2009
3670 // MACOS probleme vtk-window out of wx-window   
3671 //      _pointWidget->On();
3672         
3673         _pointWidget->AddObserver(vtkCommand::InteractionEvent,_myCallback);
3674
3675
3676 // PlaneWidget
3677         if(_planeWidget!=NULL){
3678                 _planeWidget->Delete();
3679         }
3680         _planeWidget = vtkPlaneWidget::New();
3681         _myCallback->SetVtkPlaneWidget(_planeWidget);
3682         _planeWidget->SetInput( GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData() );
3683         _planeWidget->NormalToXAxisOn();
3684         _planeWidget->SetResolution(50);
3685         _planeWidget->SetRepresentationToOutline();
3686         int dim[3];
3687         GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetDimensions(dim);
3688         int px=(dim[0]/2);
3689         int py=(dim[1]/2);
3690         int pz=(dim[2]/2);
3691         int dd=20;
3692         _planeWidget->PlaceWidget( px-dd , px+dd , py-dd , py+dd , pz-dd , pz+dd );
3693
3694
3695         if(_vtkplane==NULL){
3696                 _vtkplane = vtkPolyData::New();
3697                 
3698                 _probe = vtkProbeFilter::New();
3699                 _probe->SetInput(_vtkplane);
3700
3701                 _contourMapper = vtkPolyDataMapper::New();
3702                 
3703                 _contourMapper->SetInput( _probe->GetPolyDataOutput() );
3704
3705                 _contourPlaneActor = vtkActor::New();
3706                 _contourPlaneActor->SetMapper(_contourMapper);
3707
3708                 _contourPlaneActor->VisibilityOff();
3709
3710                 _planeWidget->SetInteractor( GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor() );
3711                 _planeWidget->AddObserver(vtkCommand::InteractionEvent,_myCallback);
3712
3713                 _planeWidget->Off();
3714                 _wxvtk3Dbaseview->GetRenderer()->AddActor( _contourPlaneActor );        
3715
3716         }else{
3717                 
3718         }
3719         _planeWidget->GetPolyData(_vtkplane);
3720
3721         
3722         vtkImageData *imageData = GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData(); 
3723         _probe->SetSource( imageData );
3724
3725         
3726         _contourMapper->SetScalarRange( imageData->GetScalarRange() );
3727     
3728         
3729
3730                         
3731 }
3732 //-------------------------------------------------------------------
3733 wxVtkMPR3DView::~wxVtkMPR3DView()
3734 {
3735 }
3736
3737 //-------------------------------------------------------------------
3738 void wxVtkMPR3DView::Refresh()   // virtual
3739 {
3740         _vtkmpr3Ddataviewer     ->      Refresh();
3741         if (_wxvtkmpr3DviewCntrlPanel!=NULL)
3742         {
3743                 _wxvtkmpr3DviewCntrlPanel->Refresh();
3744         }
3745
3746 }
3747 //-------------------------------------------------------------------
3748 void wxVtkMPR3DView::RefreshView()   // virtual
3749 {
3750         double spc[3];
3751         this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetSpacing(spc);
3752
3753         //double nx=1,ny=0,nz=0; // JPRx
3754         Refresh();
3755         double x=GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetX();
3756         double y=GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetY();
3757         double z=GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetZ();
3758
3759         x=x*spc[0];
3760         y=y*spc[1];
3761         z=z*spc[2];
3762
3763         _pointWidget->SetPosition( x,y,z ); 
3764
3765
3766         double in[3]; 
3767         double normal[3];
3768         vtkTransform *transform = GetVtkMPR3DDataViewer ()->GetVtkMPRBaseData()->GetTransformOrientation();
3769         in[0]=1;                in[1]=0;                        in[2]=0;
3770         transform->TransformPoint(in,normal);
3771         _planeWidget->SetNormal( normal[0],normal[1],normal[2] );
3772
3773
3774         _planeWidget->SetCenter( x,y,z );
3775         _planeWidget->UpdatePlacement();
3776         _planeWidget->GetPolyData(_vtkplane);
3777 }
3778 //-------------------------------------------------------------------
3779 wxPanel* wxVtkMPR3DView::CreateControlPanel(wxWindow *parent)
3780 {
3781         _wxvtkmpr3DviewCntrlPanel = new wxVtkMPR3DViewCntrlPanel(parent,this);
3782         return _wxvtkmpr3DviewCntrlPanel;
3783 }
3784 //-------------------------------------------------------------------
3785 vtkMPR3DDataViewer* wxVtkMPR3DView::GetVtkMPR3DDataViewer()
3786 {
3787         return _vtkmpr3Ddataviewer; 
3788 }
3789 //-------------------------------------------------------------------
3790 wxVtk3DBaseView* wxVtkMPR3DView::GetWxvtk3Dbaseview() throw (char*)
3791 {
3792         if(_wxvtk3Dbaseview==NULL){
3793                 throw "wxVtk3DBaseView* wxVtkMPR3DView::GetWxvtk3Dbaseview() _wxvtk3Dbaseview=NULL";
3794         }
3795         return _wxvtk3Dbaseview;
3796 }
3797 //-------------------------------------------------------------------
3798
3799 //-------------------------------------------------------------------
3800 void wxVtkMPR3DView::VisibleImageActor(int idPosition, bool visible){
3801         if (visible!=_vtkmpr3Ddataviewer->GetVisiblePosition(idPosition)){
3802                 if (visible==false){
3803                         _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkmpr3Ddataviewer->GetImageActor(idPosition)  );        
3804                 } else {
3805                         _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkmpr3Ddataviewer->GetImageActor(idPosition)  );   
3806                 }
3807                 _vtkmpr3Ddataviewer->SetVisiblePosition(idPosition,visible);
3808         }
3809 }
3810
3811
3812 //-------------------------------------------------------------------
3813 void wxVtkMPR3DView::VisiblePointWidget( bool visible )
3814 {
3815         if (visible==true)
3816         {
3817                 _pointWidget->On();
3818         } else {
3819                 _pointWidget->Off();
3820         }
3821 }
3822
3823 //-------------------------------------------------------------------
3824 void wxVtkMPR3DView::VisiblePlaneWidget( bool visible )
3825 {
3826         if (visible==true)
3827         {
3828                 _planeWidget->On();
3829                 _contourPlaneActor->VisibilityOn();
3830
3831         } else {
3832                 _planeWidget->Off();
3833                 _contourPlaneActor->VisibilityOff();
3834         }
3835 }
3836
3837 //-------------------------------------------------------------------
3838 void wxVtkMPR3DView::SetVtkMPR3DDataViewer(vtkMPR3DDataViewer *vtkmpr3Ddataviewer)
3839 {
3840         _vtkmpr3Ddataviewer = vtkmpr3Ddataviewer;
3841 }
3842
3843 //-------------------------------------------------------------------
3844 void wxVtkMPR3DView::InitOrientationPointWidget()
3845 {
3846         this->_planeWidget->SetNormal(1,0,0);           
3847 }
3848
3849
3850
3851
3852 //-------------------------------------------------------------------
3853 // EED 25 Janvier 2007 testLoic
3854 void wxVtkMPR3DView::TestLoic1()
3855 {
3856
3857         int sizeIma     = 128;
3858   double dimIma = sizeIma*2;
3859
3860         vtkImageData *vtkimagedata =  this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
3861
3862         double spc[3];
3863         vtkimagedata->GetSpacing(spc);
3864
3865         vtkimagedata->Update();
3866
3867
3868          double p[3], n[3];
3869      this->_planeWidget->GetOrigin(p);
3870      this->_planeWidget->GetNormal(n);
3871
3872
3873
3874     vtkPlaneSource* pSource = vtkPlaneSource::New( );
3875     pSource->SetResolution( sizeIma - 1, sizeIma - 1 );
3876     pSource->SetOrigin( p[ 0 ], p[ 1 ], p[ 2 ] );
3877     pSource->SetPoint1( p[ 0 ] + dimIma - 1.0, p[ 1 ], p[ 2 ] );
3878     pSource->SetPoint2( p[ 0 ], p[ 1 ]+ dimIma - 1.0 , p[ 2 ] );
3879     pSource->Update( );
3880     pSource->SetCenter( p[ 0 ], p[ 1 ], p[ 2 ] );
3881     pSource->SetNormal( n[ 0 ], n[ 1 ], n[ 2 ] );
3882     pSource->Update( );
3883
3884     vtkProbeFilter* slices = vtkProbeFilter::New();
3885     slices->SetInput( ( vtkDataSet* )pSource->GetOutput( ) );
3886     slices->SetSource( vtkimagedata );
3887     slices->Update( );
3888     pSource->Delete( );
3889
3890         vtkStructuredPoints   *stPoints = vtkStructuredPoints::New();
3891         stPoints -> GetPointData( )->SetScalars(  slices->GetOutput()->GetPointData()->GetScalars()  );
3892         stPoints -> SetDimensions( sizeIma, sizeIma, 1 );
3893         stPoints -> SetScalarType( vtkimagedata->GetScalarType() );
3894         stPoints -> SetScalarTypeToShort();
3895         stPoints -> Update();
3896
3897         vtkImageChangeInformation  *change = vtkImageChangeInformation ::New();
3898         change    -> SetInput( stPoints );  
3899         change    -> Update();    //important
3900
3901         double _range[2];
3902         vtkimagedata->GetScalarRange(_range);
3903    vtkWindowLevelLookupTable *_bwlookup = vtkWindowLevelLookupTable::New( );
3904    _bwlookup->SetHueRange( 0 , 1 );
3905    _bwlookup->SetNumberOfColors( (int)(_range[1] - _range[0] + 1) );
3906    _bwlookup->SetTableRange( _range[0] , _range[1] );
3907    _bwlookup->SetSaturationRange( 0 , 0 );
3908    _bwlookup->SetValueRange( 0 , 1 );
3909    _bwlookup->SetAlphaRange( 1 , 1 );
3910    _bwlookup->Build( );
3911  
3912    vtkLookupTable * _collookup = vtkLookupTable::New( );
3913    _collookup->SetNumberOfColors( 256 );
3914    _collookup->SetTableRange( 0 , 255 );
3915    _collookup->Build( );
3916    _collookup->SetTableValue( 0  , 1 , 0 , 0 , 1 );
3917    _collookup->SetTableValue(128 , 0 , 0 , 1 , 1 );
3918    _collookup->SetTableValue(255 , 0 , 1 , 0 , 1 );
3919
3920
3921         vtkMetaImageWriter *writer = vtkMetaImageWriter::New( );
3922         writer->SetInput( stPoints );
3923         writer->SetFileName( "C:/Users/Images/temp_EED/image.mhd" );
3924         writer->SetFileDimensionality( 2 );
3925         writer->Write( );
3926
3927
3928
3929         vtkDataSetMapper *_3DSliceMapper = vtkDataSetMapper::New( );
3930         _3DSliceMapper->SetInput(change->GetOutput( ) );
3931         _3DSliceMapper->SetLookupTable( _bwlookup );
3932         _3DSliceMapper->SetScalarRange( _range );
3933         _3DSliceMapper->ImmediateModeRenderingOn( );
3934
3935         vtkActor *_3DSliceActor = vtkActor::New( );
3936         _3DSliceActor->SetMapper( _3DSliceMapper );
3937
3938  // The usual rendering stuff.
3939   vtkCamera *camera = vtkCamera::New();
3940       camera->SetPosition(1,1,1);
3941       camera->SetFocalPoint(0,0,0);
3942
3943   vtkRenderer *renderer = vtkRenderer::New();
3944   vtkRenderWindow *renWin = vtkRenderWindow::New();
3945     renWin->AddRenderer(renderer);
3946
3947   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
3948     iren->SetRenderWindow(renWin);
3949
3950   renderer->AddActor( _3DSliceActor );
3951       renderer->SetActiveCamera(camera);
3952       renderer->ResetCamera();
3953       renderer->SetBackground(1,1,1);
3954   
3955   renWin->SetSize(300,300);
3956
3957   // interact with data
3958   renWin->Render();
3959   iren->Start();
3960
3961
3962
3963
3964
3965 }
3966
3967 //-------------------------------------------------------------------
3968 // EED 25 Janvier 2007 testLoic
3969 void wxVtkMPR3DView::TestLoic2()
3970 {
3971 /*
3972  vtkVectorNorm *vecMagnitude = vtkVectorNorm::New();
3973                 vecMagnitude->SetInput(VtkMainGrid);
3974                 vecMagnitude->NormalizeOff();
3975                 vecMagnitude->Update();
3976 */
3977
3978         vtkPlane *slicePlane = vtkPlane::New();
3979                                 this->_planeWidget->GetPlane( slicePlane );
3980
3981                 
3982         vtkCutter* sliceCutter = vtkCutter::New();
3983                 vtkImageData *vtkimagedata =  this->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
3984                 sliceCutter->SetInput( vtkimagedata );
3985                 sliceCutter->SetCutFunction( slicePlane );
3986
3987 //EED
3988 //        vtkLookupTable *lut = BuildHueWeightBaseMap();
3989
3990
3991         vtkPolyDataMapper *slice = vtkPolyDataMapper::New();
3992                 slice->SetInput( sliceCutter->GetOutput() );
3993         double range[2];
3994 // EED
3995 //                slice->Update();
3996                                   vtkimagedata->GetScalarRange(range);
3997 //                vecMagnitude->GetOutput()->GetScalarRange( range );
3998 //                range[1] *= 0.7; // reduce the upper range by 30%
3999 //                slice->SetScalarRange( range );
4000 //                slice->SetLookupTable( lut );
4001
4002 //       vtkActor *sliceActor = vtkActor::New();
4003 //                sliceActor->SetMapper( slice );
4004
4005         vtkPolyDataMapper *contourMapper = vtkPolyDataMapper::New();
4006                 contourMapper->SetInput( sliceCutter->GetOutput() );
4007                 contourMapper->SetScalarRange( range );
4008   //              contourMapper->SetLookupTable( lut );
4009
4010                 
4011         vtkActor *contourActor = vtkActor::New();
4012                 contourActor->SetMapper( contourMapper );
4013
4014
4015
4016  // The usual rendering stuff.
4017   vtkCamera *camera = vtkCamera::New();
4018       camera->SetPosition(1,1,1);
4019       camera->SetFocalPoint(0,0,0);
4020
4021   vtkRenderer *renderer = vtkRenderer::New();
4022   vtkRenderWindow *renWin = vtkRenderWindow::New();
4023     renWin->AddRenderer(renderer);
4024
4025   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
4026     iren->SetRenderWindow(renWin);
4027
4028   renderer->AddActor( contourActor );
4029 //  renderer->AddActor(cubeActor);
4030       renderer->SetActiveCamera(camera);
4031       renderer->ResetCamera();
4032       renderer->SetBackground(1,1,1);
4033   
4034   renWin->SetSize(300,300);
4035
4036   // interact with data
4037   renWin->Render();
4038   iren->Start();
4039
4040
4041 }
4042
4043 //-------------------------------------------------------------------
4044 //-------------------------------------------------------------------
4045 //-------------------------------------------------------------------
4046
4047 wxVtkClipping3DView::wxVtkClipping3DView(wxVtk3DBaseView* wxvtk3Dbaseview)
4048 {
4049         _wxvtk3Dbaseview                                =       wxvtk3Dbaseview;
4050         _vtkclipping3Ddataviewer                =       NULL;
4051         _wxvtkclipping3DviewCntrlPanel  =       NULL;
4052
4053         _boxWidgetVolume                                =       NULL;
4054         _boxWidgetS1                                    =       NULL;
4055 }
4056
4057 //-------------------------------------------------------------------
4058 wxVtkClipping3DView::~wxVtkClipping3DView(){
4059         if (_boxWidgetVolume!=NULL)                              { _boxWidgetVolume     -> Delete();                                    }
4060         if (_boxWidgetS1!=NULL)                                  { _boxWidgetS1         -> Delete();                                    }
4061         if (_vtkclipping3Ddataviewer!=NULL)              { delete _vtkclipping3Ddataviewer;                     }
4062         if (_wxvtkclipping3DviewCntrlPanel!=NULL){ delete _wxvtkclipping3DviewCntrlPanel;       }
4063 }
4064 //-------------------------------------------------------------------
4065 void wxVtkClipping3DView::SetVisibleBoxSurface(bool visible)
4066 {
4067         if (visible==true){
4068                 _boxWidgetS1->On();
4069         } else {
4070                 _boxWidgetS1->Off();
4071         }
4072 }
4073 //-------------------------------------------------------------------
4074 void wxVtkClipping3DView::SetVisibleBoxVolume(bool visible)
4075 {
4076         if (_boxWidgetVolume!=NULL){
4077                 if (visible==true){
4078                         _boxWidgetVolume->On();
4079                 } else {
4080                         _boxWidgetVolume->Off();
4081                 }
4082         }
4083 }
4084 //-------------------------------------------------------------------
4085 void wxVtkClipping3DView::Refresh()
4086 {
4087         _vtkclipping3Ddataviewer->Refresh();
4088         if (_wxvtkclipping3DviewCntrlPanel!=NULL)
4089         {
4090                 _wxvtkclipping3DviewCntrlPanel->Refresh();
4091         }
4092 }
4093 //-------------------------------------------------------------------
4094 wxPanel* wxVtkClipping3DView::CreateControlPanel(wxWindow *parent)
4095 {
4096         _wxvtkclipping3DviewCntrlPanel = new wxVtkClipping3DViewCntrlPanel(parent,this);
4097         return _wxvtkclipping3DviewCntrlPanel;
4098 }
4099 //-------------------------------------------------------------------
4100 vtkClipping3DDataViewer* wxVtkClipping3DView::GetVtkClipping3DDataViewer()
4101 {
4102         return _vtkclipping3Ddataviewer; 
4103 }
4104 //-------------------------------------------------------------------
4105 void wxVtkClipping3DView::VisibleActor(int idTissue, bool visTissue){
4106         if (visTissue!=_vtkclipping3Ddataviewer->GetVisibleTissue(idTissue)){
4107                 if (visTissue==false){
4108                         _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkclipping3Ddataviewer->GetTissueActor(idTissue)  );    
4109                 } else {
4110                         _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(idTissue)  );       
4111 //                      _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(idTissue) );
4112 //                      _actor->VisibilityOn();
4113                 }
4114                 _vtkclipping3Ddataviewer->SetVisibleTissue(idTissue,visTissue);
4115         }
4116 }
4117 //-------------------------------------------------------------------
4118 void wxVtkClipping3DView::SetRepSurfaceWireFrame(int idTissue , bool representationType )
4119 {
4120         vtkActor *tmpActor;
4121         tmpActor = GetVtkClipping3DDataViewer()->GetTissueActor(idTissue);
4122
4123         if (representationType==false){
4124                 tmpActor->GetProperty()->SetRepresentationToWireframe();
4125         } else {
4126                 tmpActor->GetProperty()->SetRepresentationToSurface();
4127         }
4128
4129         _vtkclipping3Ddataviewer->SetRepresentationType(idTissue,representationType);
4130 }
4131
4132 //-------------------------------------------------------------------
4133 void wxVtkClipping3DView::VisibleVolumeActor( bool visVolume){
4134         if (visVolume!=_vtkclipping3Ddataviewer->GetVisibleVolume() ){
4135                 if (visVolume==false){
4136 //EED 31/03/2008                        
4137 //                      _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _vtkclipping3Ddataviewer->GetVolumeActor()  );    
4138                         _wxvtk3Dbaseview->GetRenderer()->RemoveVolume( _vtkclipping3Ddataviewer->GetVolumeActor()  );   
4139                 } else {
4140 //EED 31/03/2008                        
4141 //                      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetVolumeActor() );        
4142                         _wxvtk3Dbaseview->GetRenderer()->AddVolume( _vtkclipping3Ddataviewer->GetVolumeActor() );       
4143                 }
4144                 _vtkclipping3Ddataviewer->SetVisibleVolume(visVolume);
4145         }
4146 }
4147 //-------------------------------------------------------------------
4148 wxVtk3DBaseView* wxVtkClipping3DView::GetWxvtk3Dbaseview()throw(char*)
4149 {
4150         if(_wxvtk3Dbaseview==NULL){
4151                 throw "wxVtk3DBaseView* wxVtkClipping3DView::GetWxvtk3Dbaseview() _wxvtk3Dbaseview=NULL";
4152         }
4153         return _wxvtk3Dbaseview;
4154 }
4155 //-------------------------------------------------------------------
4156 void wxVtkClipping3DView::Configure(){
4157         _wxvtk3Dbaseview->Configure();
4158
4159         // Actors are added to the renderer. 
4160         _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetOutlineActor() );                       
4161
4162         _boxWidgetS1 = vtkBoxWidget::New();
4163         _boxWidgetS1->SetInteractor( _wxvtk3Dbaseview->GetWxVTKRenderWindowInteractor() );
4164         _boxWidgetS1->SetPlaceFactor(1.25);
4165
4166
4167
4168         vtkStripper *stripper=_vtkclipping3Ddataviewer->GetTissueStripper(0);
4169         vtkPolyData *polydata= stripper->GetOutput();
4170  
4171
4172         _boxWidgetS1->SetInput( polydata );
4173         _boxWidgetS1->PlaceWidget();
4174
4175         int i;
4176         for (i=0; i< VTKMPRDATA_MAXTISSUE ; i++)
4177         {
4178                 _boxWidgetS1->AddObserver( vtkCommand::InteractionEvent          , _vtkclipping3Ddataviewer->GetObserverS(i) );
4179         }
4180
4181
4182
4183
4184 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(0) );                       
4185 //      _wxvtk3Dbaseview->GetRenderer()->AddActor( _vtkclipping3Ddataviewer->GetTissueActor(3));                        
4186
4187         VisibleActor(0, false );
4188         VisibleActor(1, false );
4189         VisibleActor(2, false );
4190         VisibleActor(3, false );
4191
4192         _boxWidgetS1->HandlesOn ();
4193         
4194 //EED 29Mars2009        
4195 //      _boxWidgetS1->On();
4196         
4197         _boxWidgetS1->Off();
4198
4199         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(0) );
4200         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(1) );
4201         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(2) );
4202         _boxWidgetS1->GetPlanes( this->GetVtkClipping3DDataViewer()->GetTissuePlanes(3) );
4203         
4204 // EED 9 fev 2007
4205 // box Volume
4206         _boxWidgetVolume = vtkBoxWidget::New();
4207         _boxWidgetVolume->SetInteractor( _wxvtk3Dbaseview->GetWxVTKRenderWindowInteractor() );
4208         _boxWidgetVolume->SetPlaceFactor(1.25);
4209
4210         _boxWidgetVolume->SetInput( this->GetVtkClipping3DDataViewer()->GetVtkMPRBaseData()->GetImageData() );
4211         _boxWidgetVolume->PlaceWidget();
4212
4213         _boxWidgetVolume->AddObserver( vtkCommand::InteractionEvent              , _vtkclipping3Ddataviewer->GetObserverV() );
4214
4215         _boxWidgetVolume->HandlesOn ();
4216         
4217 //EED 29Mars2009        
4218 //      _boxWidgetVolume->On();
4219         
4220         _boxWidgetVolume->Off();
4221
4222
4223 //      vtkPlanes *vtkplanes=this->GetVtkClipping3DDataViewer()->GetVolumePlanes();
4224 //      _boxWidgetVolume->GetPlanes( vtkplanes );
4225
4226
4227   // An initial camera view is created.  The Dolly() method moves 
4228   // the camera towards the FocalPoint, thereby enlarging the image.
4229   _wxvtk3Dbaseview->GetRenderer()->SetActiveCamera(_wxvtk3Dbaseview->GetCamera());
4230   _wxvtk3Dbaseview->GetRenderer()->ResetCamera ();
4231   _wxvtk3Dbaseview->GetCamera()->Dolly(1.5);
4232
4233   // Set a background color for the renderer and set the size of the
4234   // render window (expressed in pixels).
4235   _wxvtk3Dbaseview->GetRenderer()->SetBackground( 0.36 , 0.36 , 0.36 );
4236   _wxvtk3Dbaseview->GetRenWin()->SetSize(400, 400);
4237
4238   // Note that when camera movement occurs (as it does in the Dolly()
4239   // method), the clipping planes often need adjusting. Clipping planes
4240   // consist of two planes: near and far along the view direction. The 
4241   // near plane clips out objects in front of the plane; the far plane
4242   // clips out objects behind the plane. This way only what is drawn
4243   // between the planes is actually rendered.
4244   _wxvtk3Dbaseview->GetRenderer()->ResetCameraClippingRange();
4245 }
4246 //-------------------------------------------------------------------
4247 void wxVtkClipping3DView::SetVtkClipping3DDataViewer(vtkClipping3DDataViewer *vtkclipping3Ddataviewer)
4248 {
4249         _vtkclipping3Ddataviewer = vtkclipping3Ddataviewer;
4250 }
4251
4252
4253 //---------------------------------------------------------------------------
4254 //---------------------------------------------------------------------------
4255 //---------------------------------------------------------------------------
4256 vtkInteractorStyle3DView::vtkInteractorStyle3DView()
4257 {
4258 }
4259 //---------------------------------------------------------------------------
4260 vtkInteractorStyle3DView::~vtkInteractorStyle3DView()
4261 {
4262 }
4263 //---------------------------------------------------------------------------
4264 bool vtkInteractorStyle3DView::OnLeftDClick()
4265 {
4266         SelectMarchibCubePoint();
4267         return true;
4268 }
4269 //---------------------------------------------------------------------------
4270 bool vtkInteractorStyle3DView::SelectMarchibCubePoint()
4271 {
4272         bool ok=false;
4273     gtm::TVector< double > pO( 3 ), pF( 3 ), pp( 3 ), cp( 3 );
4274     gtm::TVector< double > xc( 3 );
4275     gtm::TVector< double > x1( 3 ), n1( 3 );
4276     gtm::TVector< double > x2( 3 ), n2( 3 );
4277
4278         double pickPoint[ 3 ], cameraPos[ 3 ];
4279         int eventrwi[2];
4280         vtkPointPicker* picker = vtkPointPicker::New( );        
4281         eventrwi[0]= _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[0];
4282         eventrwi[1]= _vtkInteractorStyleBaseView->GetInteractor()->GetEventPosition()[1];
4283         vtkRenderer *pRenderer = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetRenderer();
4284         picker->Pick( eventrwi[0], eventrwi[1], 0.0, pRenderer );
4285         pRenderer->GetActiveCamera( )->GetPosition( cameraPos );
4286         picker->GetPickPosition( pickPoint );
4287         picker->Delete( );
4288
4289         pp( 0 ) = pickPoint[ 0 ]; pp( 1 ) = pickPoint[ 1 ]; pp( 2 ) = pickPoint[ 2 ];
4290     cp( 0 ) = cameraPos[ 0 ]; cp( 1 ) = cameraPos[ 1 ]; cp( 2 ) = cameraPos[ 2 ];
4291
4292
4293 //EED 27 sep 2006  (1/2)
4294 //      wxVtkMPR3DView *wxvtkmpr3Dview = (wxVtkMPR3DView *)_vtkInteractorStyleBaseView->GetWxVtk3DBaseView();
4295 //      double spc[3];
4296 //      wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetSpacing(spc);
4297
4298
4299         vtkImageData *imageData = GetWxVtkMPR3DView()->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData();
4300         int dim[3];
4301         double spc[3];
4302         imageData->GetDimensions(dim);
4303         imageData->GetSpacing(spc);
4304
4305
4306         vtkMarchingCubes *mcubes = _wxvtkclipping3Dview->GetVtkClipping3DDataViewer()->GetMCubes(0);
4307         
4308
4309         UtilVtk3DGeometriSelection utilVtk3DGeometriSelection;
4310         utilVtk3DGeometriSelection.SetDimentions(dim[0],dim[1],dim[2]);
4311
4312         utilVtk3DGeometriSelection.SetMarchingCube(mcubes);
4313
4314     double fac;
4315     fac = GTM_MAX( dim[0], dim[2] );
4316
4317
4318     if( utilVtk3DGeometriSelection.FindCubePointsFromPoints(
4319       pO.GetAnsiRef( ), pF.GetAnsiRef( ),
4320       pp.GetAnsiRef( ), cp.GetAnsiRef( ) )  ) 
4321         {
4322
4323                 if( utilVtk3DGeometriSelection.GetPointAndNormalIntersection(
4324                             x1.GetAnsiRef( ), n1.GetAnsiRef( ),
4325                                 pO.GetAnsiRef( ), pF.GetAnsiRef( ) ) ) 
4326                 {
4327                     if( utilVtk3DGeometriSelection.GetPointAndNormalIntersection(
4328                               x2.GetAnsiRef( ), n2.GetAnsiRef( ),
4329                                  ( x1 - n1 ).GetAnsiRef( ), ( x1 - ( n1 * fac ) ).GetAnsiRef( )   ) ) 
4330                         {
4331                                 xc = ( x2 + x1 ) * 0.5;
4332 //EED 27 sep 2006  (2/2)
4333                                 this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetX(xc(0)/spc[0]);
4334                                 this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetY(xc(1)/spc[1]);
4335                                 this->_wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetZ(xc(2)/spc[2]);
4336                                 wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
4337                                 this->_wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
4338                                 ok=true;
4339                         }
4340                 }
4341         }
4342
4343
4344         return ok;
4345 }
4346 //-------------------------------------------------------------------
4347 void vtkInteractorStyle3DView::SetWxVtkMPR3DView( wxVtkMPR3DView *wxvtkmpr3Dview )
4348 {
4349         _wxvtkmpr3Dview = wxvtkmpr3Dview;
4350 }
4351 //-------------------------------------------------------------------
4352 wxVtkMPR3DView *vtkInteractorStyle3DView::GetWxVtkMPR3DView()
4353 {
4354         return _wxvtkmpr3Dview;
4355 }
4356 //-------------------------------------------------------------------
4357 wxVtkClipping3DView *vtkInteractorStyle3DView::GetWxVtkClipping3DView()
4358 {
4359         return _wxvtkclipping3Dview;
4360 }
4361 //-------------------------------------------------------------------
4362 void vtkInteractorStyle3DView::SetWxVtkClipping3DView( wxVtkClipping3DView *wxvtkclipping3Dview)
4363 {
4364         _wxvtkclipping3Dview = wxvtkclipping3Dview;
4365 }
4366
4367
4368
4369 //-------------------------------------------------------------------
4370 //-------------------------------------------------------------------
4371 //-------------------------------------------------------------------
4372 void vtkmyPWCallback_3DPointWidget::Execute(vtkObject *caller, unsigned long, void*)
4373 {
4374         double n[3];
4375         double p[3];
4376         double delta = 0.000000001;
4377
4378         vtkInteractorStyleBaseView *isbv = _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetInteractorStyleBaseView();
4379
4380         if (caller==_pointWidget)
4381         {
4382                 _pointWidget->GetPosition(p);
4383         }
4384         if (caller==_planeWidget)
4385         {
4386                 _planeWidget->GetCenter(p);
4387                 _planeWidget->GetNormal(n);
4388                 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetNormal(n[0],n[1],n[2]);
4389         }
4390
4391         double spc[3];
4392         _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetImageData()->GetSpacing(spc);
4393         p[0]=p[0]/spc[0];
4394         p[1]=p[1]/spc[1];
4395         p[2]=p[2]/spc[2];
4396
4397         // Orientation change
4398         if ( (fabs(n[0]-_backNormal[0])>delta) || (fabs(n[1]-_backNormal[1])>delta) || (fabs(n[2]-_backNormal[2])>delta) )
4399         {
4400                 _backNormal[0] = n[0];
4401                 _backNormal[1] = n[1];
4402                 _backNormal[2] = n[2];
4403                 isbv->SetParent_refresh_waiting();
4404         }
4405
4406         // ----------
4407
4408         double tx = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetX();
4409         double ty = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetY();
4410         double tz = _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->GetZ();
4411
4412         // Position Change
4413         if ( (fabs(tx-p[0])>delta) || (fabs(ty-p[1])>delta) || (fabs(tz-p[2])>delta) )
4414         {
4415                 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetX( p[0] );
4416                 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetY( p[1] );
4417                 _wxvtkmpr3Dview->GetVtkMPR3DDataViewer()->GetVtkMPRBaseData()->SetZ( p[2] );
4418                 vtkInteractorStyleBaseView *isbv = _wxvtkmpr3Dview->GetWxvtk3Dbaseview()->GetInteractorStyleBaseView();
4419                 isbv->BlockRefresh();
4420                 isbv->vtkInteractorStyleBaseView::OnLeftButtonDown();
4421                 isbv->SetParent_refresh_waiting();
4422                 isbv->vtkInteractorStyleBaseView::OnMouseMove();
4423                 isbv->UnBlockRefresh();
4424         } 
4425         isbv->EvaluateToRefresh();
4426 }
4427 //-------------------------------------------------------------------
4428 void vtkmyPWCallback_3DPointWidget::SetWxVtkMPR3DView( wxVtkMPR3DView *wxvtkmpr3Dview )
4429 {
4430         _wxvtkmpr3Dview=wxvtkmpr3Dview;
4431 }
4432 //-------------------------------------------------------------------
4433 void vtkmyPWCallback_3DPointWidget::SetVtkPointWidget( vtkPointWidget *pointWidget )
4434 {
4435         _pointWidget=pointWidget;
4436 }
4437 //-------------------------------------------------------------------
4438 void vtkmyPWCallback_3DPointWidget::SetVtkPlaneWidget( vtkPlaneWidget *planeWidget )
4439 {
4440         _planeWidget=planeWidget;
4441 }
4442 //-------------------------------------------------------------------
4443 //-------------------------------------------------------------------
4444 //-------------------------------------------------------------------
4445
4446 wxPanelCuttingImageData::wxPanelCuttingImageData (wxWindow *parent)
4447 : wxPanel( parent, -1)
4448 {
4449         _imageData=NULL;
4450         _histogrammeVector=NULL;
4451         _wxvtk3Dbaseview=NULL;
4452         _wxvtkbaseView=NULL;
4453         CreateInterface();
4454         CreateModel();
4455         Create3DViewObjects();
4456 }
4457
4458 //-------------------------------------------------------------------
4459 wxPanelCuttingImageData::~wxPanelCuttingImageData()
4460 {
4461
4462
4463         delete _modelCube;      
4464         delete _modelSphere;    
4465         delete _modelCylinder;  
4466         _vtkcube                -> Delete();    
4467         _vtksphere              -> Delete();    
4468         _vtkcylinder    -> Delete();    
4469         _cubeMapper             -> Delete();    
4470         _sphereMapper   -> Delete();    
4471         _cylinderMapper -> Delete();    
4472         _cubeActor              -> Delete();    
4473         _sphereActor    -> Delete();    
4474         _cylinderActor  -> Delete();    
4475 //      _xyplot->RemoveAllInputs();     
4476         _xyplot                 -> Delete();    
4477         _histogrammeVector->Delete();   
4478         _renplotter->Delete();
4479         
4480         if(_wxvtkbaseView!=NULL){
4481                 delete _wxvtkbaseView;
4482         }
4483         //delete _vtkclipping3Ddataviewer;
4484         
4485
4486         //fclose(file);
4487
4488 }
4489
4490 //-------------------------------------------------------------------
4491 void wxPanelCuttingImageData::RemoveActors()
4492 {
4493         _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _actualActor );
4494 }
4495
4496
4497 //-------------------------------------------------------------------
4498 void wxPanelCuttingImageData::SetWxVtk3DBaseView( wxVtk3DBaseView * wxvtk3Dbaseview )
4499 {
4500         _wxvtk3Dbaseview=wxvtk3Dbaseview;
4501 }
4502
4503 //-------------------------------------------------------------------
4504
4505 void wxPanelCuttingImageData::SetVtkClipping3DDataViewer( vtkClipping3DDataViewer *vtkclipping3Ddataviewer )
4506 {
4507         this->_vtkclipping3Ddataviewer = vtkclipping3Ddataviewer;
4508 }
4509
4510 //-------------------------------------------------------------------
4511 void wxPanelCuttingImageData::Create3DViewObjects()
4512 {
4513         // Sphere
4514         _vtksphere              = vtkSphereSource::New();
4515         _vtksphere->SetThetaResolution (20);
4516         _vtksphere->SetPhiResolution (20);
4517         _sphereMapper   = vtkPolyDataMapper::New();
4518         _sphereMapper->SetInput( _vtksphere->GetOutput() );
4519         _sphereActor    = vtkActor::New();
4520         _sphereActor->SetMapper(_sphereMapper);
4521         _sphereActor->SetOrigin(0, 0, 0);
4522         _sphereActor->SetPosition(0, 0, 0);
4523         _sphereActor->GetProperty()->SetColor(1, 0, 0);
4524         _sphereActor->SetUserTransform( _modelSphere->GetVtkTransform() );      
4525
4526         // cube
4527         _vtkcube                = vtkCubeSource::New();
4528         _vtkcube->SetXLength (1);
4529         _vtkcube->SetYLength (1);
4530         _vtkcube->SetZLength (1);
4531         _cubeMapper             = vtkPolyDataMapper::New();
4532         _cubeMapper->SetInput( _vtkcube->GetOutput() );
4533         _cubeActor              = vtkActor::New();
4534         _cubeActor->SetMapper(_cubeMapper);
4535         _cubeActor->SetOrigin(0, 0, 0);
4536         _cubeActor->SetPosition(0, 0, 0);
4537         _cubeActor->GetProperty()->SetColor(1, 0, 0);
4538         _cubeActor->SetUserTransform( _modelCube->GetVtkTransform() );          
4539
4540         // cylinder
4541         _vtkcylinder    = vtkCylinderSource::New();
4542         _vtkcylinder->SetResolution(20);
4543         _cylinderMapper = vtkPolyDataMapper::New();
4544         _cylinderMapper->SetInput( _vtkcylinder->GetOutput() );
4545         _cylinderActor  = vtkActor::New();
4546         _cylinderActor->SetMapper(_cylinderMapper);
4547         _cylinderActor->SetOrigin(0, 0, 0);
4548         _cylinderActor->SetPosition(0, 0, 0);
4549         _cylinderActor->GetProperty()->SetColor(1, 0, 0);
4550         _cylinderActor->SetUserTransform( _modelCylinder->GetVtkTransform() );          
4551
4552
4553 }
4554
4555 //-------------------------------------------------------------------
4556 void wxPanelCuttingImageData::CreateModel()
4557 {
4558         _modelCube              = new figureCuttingCubeModel();
4559         _modelSphere    = new figureCuttingSphereModel();
4560         _modelCylinder  = new figureCuttingCylinderModel();
4561
4562 //      _modelCube->SetVtkTransform( _modelCube->GetVtkTransform()                      );
4563 //      _modelSphere->SetVtkTransform( _modelSphere->GetVtkTransform()          );
4564 //      _modelCylinder->SetVtkTransform( _modelCylinder->GetVtkTransform()      );
4565 }
4566
4567 //-------------------------------------------------------------------
4568
4569 void wxPanelCuttingImageData::InitHistogramme()
4570 {
4571         double rangeA[2];
4572         if (_imageData==NULL)
4573         {
4574                 rangeA[1]=1;
4575         } else {
4576                 _imageData->GetScalarRange(rangeA);
4577         }
4578         _xyplot->RemoveAllInputs();
4579 /*
4580         if ( _histogrammeVector!=NULL )
4581         {
4582                 _histogrammeVector -> Delete();
4583         }
4584 */
4585         _histogrammeVector =  vtkImageData::New();
4586     _histogrammeVector -> SetDimensions ( (int)(rangeA[1]),1,1 );
4587     _histogrammeVector -> SetScalarTypeToUnsignedShort();
4588     _histogrammeVector -> AllocateScalars();    
4589     _histogrammeVector -> Update(); 
4590         
4591         unsigned short *p_vol = (unsigned short*)_histogrammeVector->GetScalarPointer(0,0,0);
4592         int i,size = (int) (rangeA[1]);
4593         for (i=0; i < size; i++)
4594         {
4595                 *p_vol=0;
4596                 p_vol++;
4597         }
4598         _xyplot->SetXRange(0, rangeA[1]);
4599         _xyplot->SetYRange(0, 10);
4600         _xyplot->AddInput( _histogrammeVector );
4601 }
4602
4603 //-------------------------------------------------------------------
4604 wxWindow *wxPanelCuttingImageData::CreatePlotHistogrammeInterface()
4605 {
4606         _xyplot = vtkXYPlotActor::New();
4607         InitHistogramme();
4608         _xyplot->GetPositionCoordinate()->SetValue(0.00, 0.00, 0);
4609         _xyplot->GetPosition2Coordinate()->SetValue(1.0, 1.00, 0); //relative to Position
4610         _xyplot->SetXValuesToArcLength();
4611         _xyplot->SetNumberOfXLabels(6);
4612
4613         _xyplot->SetTitle("Histogramme");
4614         _xyplot->SetXTitle("Gray level");
4615         _xyplot->SetYTitle("Occurrences ");
4616         _xyplot->GetProperty()->SetColor(1, 0, 0);
4617         _xyplot->GetProperty()->SetPointSize(2);
4618         vtkTextProperty *tprop = _xyplot->GetTitleTextProperty();
4619         tprop->SetColor( 1,0,1 );
4620         tprop->BoldOff ();
4621         _xyplot->SetAxisTitleTextProperty(tprop);
4622         _xyplot->SetAxisLabelTextProperty(tprop);
4623         _xyplot->PlotPointsOn();
4624         _xyplot->GetProperty()->SetPointSize(3);
4625
4626         _wxvtkbaseView = new wxVtkBaseView(this);
4627         _wxvtkbaseView->Configure();
4628
4629         _renplotter = vtkRenderer::New();
4630         vtkRenderWindow *renWin = _wxvtkbaseView->GetRenWin();
4631         renWin->AddRenderer( _renplotter );
4632         _renplotter->AddActor2D( _xyplot );
4633
4634         return _wxvtkbaseView->GetWxVTKRenderWindowInteractor();
4635 }
4636
4637 //-------------------------------------------------------------------
4638
4639 void wxPanelCuttingImageData::CreateInterface()
4640 {
4641         SetSize(300,500);
4642         wxBoxSizer      *topsizer               = new wxBoxSizer(wxVERTICAL);   // Principal sizer
4643
4644         wxBoxSizer              *sizerH0        = new wxBoxSizer(wxHORIZONTAL   );  // type of segmentation figure
4645         wxBoxSizer          *sizerH2    = new wxBoxSizer(wxHORIZONTAL   );      // scale
4646         wxBoxSizer              *sizerH3        = new wxBoxSizer(wxHORIZONTAL   );      // rotation
4647         wxBoxSizer              *sizerH4        = new wxBoxSizer(wxHORIZONTAL   );  // intern extern
4648         wxBoxSizer              *sizerH5        = new wxBoxSizer(wxHORIZONTAL   );  // Isovalue
4649         wxBoxSizer              *sizerH6        = new wxBoxSizer(wxHORIZONTAL   );  // Buttons
4650         wxFlexGridSizer *sizerH7        = new wxFlexGridSizer(2                 );  // Volumic information 
4651
4652         
4653         _typeFig        = new wxChoice(this,-1);
4654         _opacityFig     = new wxSlider(this,-1,100,0,100, wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4655
4656         _scaleX         = new wxSlider(this,-1,6,0,500  , wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4657         _scaleY         = new wxSlider(this,-1,20,0,500 , wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4658         _scaleZ         = new wxSlider(this,-1,7,0,500  , wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4659
4660         _rotationX      = new wxSlider(this,-1,0,-360,360, wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4661         _rotationY      = new wxSlider(this,-1,0,-360,360, wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4662         _rotationZ      = new wxSlider(this,-1,0,-360,360, wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4663
4664         _volIntern              = new wxRadioButton(this,-1, _T("Volume intern " ));
4665         _volExtern              = new wxRadioButton(this,-1, _T("Volume extern " ));
4666
4667         _histogrammeAccumulated = new wxCheckBox(this,-1,_T("Histogramme accumulated"));
4668
4669         _isoValue                               = new wxSlider(this,-1, 200, 0,2000, wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4670         _valueBeforeIsoValue    = new wxSlider(this,-1,-1,-1,2000, wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4671         _valueAfterIsoValue             = new wxSlider(this,-1,-1,-1,2000, wxDefaultPosition, wxSize(200,45), wxSL_HORIZONTAL | wxSL_LABELS);
4672
4673         wxButton *btnExtract    = new wxButton(this, -1,_T("Extract"));
4674
4675         _infoToVo       = new wxStaticText(this,-1,_T("########################"));
4676         _infoSuVoA      = new wxStaticText(this,-1,_T("############"));
4677         _infoSuVo       = new wxStaticText(this,-1,_T("############"));
4678         _infoPixLe      = new wxStaticText(this,-1,_T("############"));
4679         _infoPixHi      = new wxStaticText(this,-1,_T("############"));
4680
4681
4682         
4683
4684         _typeFig->Append(_T("Cylindre"));
4685         _typeFig->Append(_T("Cube"));
4686         _typeFig->Append(_T("Sphere"));
4687         _typeFig->SetSelection(0);
4688         _volIntern->SetValue(true);
4689
4690         Connect(_typeFig->GetId()                               , wxEVT_COMMAND_CHOICE_SELECTED         , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTypeFig ); 
4691
4692         Connect(_opacityFig->GetId()                    , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnOpacityFig ); 
4693         Connect(_rotationX->GetId()                             , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
4694         Connect(_rotationY->GetId()                             , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
4695         Connect(_rotationZ->GetId()                             , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
4696         Connect(_scaleX->GetId()                                , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
4697         Connect(_scaleY->GetId()                                , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
4698         Connect(_scaleZ->GetId()                                , wxEVT_COMMAND_SLIDER_UPDATED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnTransform ); 
4699         Connect(btnExtract->GetId()                             , wxEVT_COMMAND_BUTTON_CLICKED          , (wxObjectEventFunction) &wxPanelCuttingImageData::OnExtract   ); 
4700          
4701
4702 //      wxStaticText *text=new wxStaticText(this,-1, " ");
4703
4704         sizerH0 -> Add( new wxStaticText(this,-1, _T("Fig. Type:   "),wxDefaultPosition, wxSize(50,20)) ,1,wxALL  ,0);
4705         sizerH0 -> Add( _typeFig                ,1,wxALL  ,0);
4706         sizerH0 -> Add( _opacityFig             ,1,wxALL|wxEXPAND  ,0);
4707
4708         sizerH2 -> Add( new wxStaticText(this,-1,_T("Scale :   "))              ,1,wxALL  ,0);
4709         sizerH2 -> Add( _scaleX         ,1,wxALL | wxEXPAND ,0 );
4710         sizerH2 -> Add( _scaleY         ,1,wxALL | wxEXPAND ,0 );
4711         sizerH2 -> Add( _scaleZ         ,1,wxALL | wxEXPAND ,0 );
4712
4713         sizerH3 -> Add( new wxStaticText(this,-1,_T("Rotation :   "))   ,1,wxALL  ,0);
4714         sizerH3 -> Add( _rotationX      ,1,wxALL | wxEXPAND ,0 );
4715         sizerH3 -> Add( _rotationY      ,1,wxALL | wxEXPAND ,0 );
4716         sizerH3 -> Add( _rotationZ      ,1,wxALL | wxEXPAND ,0 );
4717
4718
4719         sizerH4 -> Add( new wxStaticText(this,-1,_T("Intern / Extern :   "))    ,1,wxALL  ,0);
4720         sizerH4 -> Add( _volIntern                                              ,1,wxALL  ,0);
4721         sizerH4 -> Add( new wxStaticText(this,-1, _T(" "))      ,1,wxALL  ,0);
4722         sizerH4 -> Add( _volExtern                                              ,1,wxALL  ,0);
4723
4724         sizerH5 -> Add( new wxStaticText(this,-1,_T("Isovalue   "))     ,1,wxALL  ,0);
4725         sizerH5 -> Add( _isoValue                                               ,1,wxALL | wxEXPAND ,0 );
4726         sizerH5 -> Add( _valueBeforeIsoValue                    ,1,wxALL | wxEXPAND ,0 );
4727         sizerH5 -> Add( _valueAfterIsoValue                             ,1,wxALL | wxEXPAND ,0 );
4728
4729         sizerH6 -> Add( new wxStaticText(this,-1, _T(" "))              ,1,wxALL  ,0);
4730         sizerH6 -> Add( btnExtract      ,1,wxALL  ,0);
4731
4732         sizerH7 -> Add( new wxStaticText(this,-1,_T("Total Volume: "), wxDefaultPosition, wxSize(200,12))                       , 1 , wxALL  ,0);
4733         sizerH7 -> Add( _infoToVo                                                                               , 1 , wxALL  ,0);
4734         sizerH7 -> Add( new wxStaticText(this,-1,_T("SubVolume:   "), wxDefaultPosition, wxSize(200,12) )               , 1 , wxALL  ,0);
4735         sizerH7 -> Add( _infoSuVo                                                                               , 1 , wxALL  ,0);
4736         sizerH7 -> Add( new wxStaticText(this,-1,_T("SubVolume (ana.): "), wxDefaultPosition, wxSize(200,12))   , 1 , wxALL  ,0);
4737         sizerH7 -> Add( _infoSuVoA                                                                              , 1 , wxALL  ,0);
4738         sizerH7 -> Add( new wxStaticText(this,-1,_T("Pix < isovalue:   ") , wxDefaultPosition, wxSize(200,12))  , 1 , wxALL  ,0);
4739         sizerH7 -> Add( _infoPixLe                                                                              , 1 , wxALL  ,0);
4740         sizerH7 -> Add( new wxStaticText(this,-1,_T("Pix > isovalue: "), wxDefaultPosition, wxSize(200,12))     , 1 , wxALL  ,0);
4741         sizerH7 -> Add( _infoPixHi                                                                              , 1 , wxALL  ,0);
4742 //      sizerH7 -> SetMinSize(300, 120);
4743
4744         // Figure type
4745         topsizer -> Add( sizerH0 ,1,wxALL|wxEXPAND  ,0);
4746
4747         // Scale
4748         topsizer -> Add( sizerH2 ,1,wxALL|wxEXPAND  ,0);
4749
4750         // Rotation
4751         topsizer -> Add( sizerH3 ,1,wxALL|wxEXPAND  ,0);
4752
4753         // Intern / Extern
4754         topsizer -> Add( sizerH4 ,1,wxALL  ,0);
4755
4756
4757         // Isovalue limite
4758         topsizer -> Add( sizerH5 ,1,wxALL |wxEXPAND ,0);
4759
4760         // btn Extraction
4761         topsizer -> Add( sizerH6        , 1 , wxALL  ,0);
4762
4763         // Histograme
4764         topsizer -> Add( _histogrammeAccumulated ,1,  wxALL  ,0);
4765
4766         // Volumic information
4767         topsizer -> Add( sizerH7                                , 1 , wxALL|wxEXPAND   ,0);
4768
4769
4770
4771 //    wxBoxSizer *sizerHor = new wxBoxSizer(wxHORIZONTAL);
4772     wxBoxSizer *sizerHor = new wxBoxSizer(wxVERTICAL);
4773         sizerHor -> Add( topsizer                               , 1 , wxALL | wxEXPAND  ,0);
4774
4775
4776         wxWindow *panelPlotHistogramme = CreatePlotHistogrammeInterface();
4777         sizerHor -> Add( panelPlotHistogramme   , 1 , wxGROW  ,0);
4778
4779
4780         this->SetAutoLayout(true);
4781         this->SetSizer( sizerHor );      
4782         this->Layout(); 
4783 //EEDxx2.4
4784 //      this->FitInside();
4785 }
4786
4787 //-------------------------------------------------------------------
4788
4789 void wxPanelCuttingImageData::OnExtract(wxCommandEvent& event)
4790 {
4791         wxBusyCursor wait;
4792
4793         bool                    inside;
4794         bool                    volInt, volExt;
4795         int                             xx,yy,zz;
4796         unsigned short  *pOrg;
4797         unsigned short  *p_histogramme;
4798         int                             dim[3];
4799         double                  spc[3];
4800         long int                contAfter = 0;
4801         long int                contBefor = 0;
4802
4803         double min=999999999;
4804         double max=-999999999;
4805
4806         volExt=_volExtern->GetValue();
4807         volInt=_volIntern->GetValue();
4808         int isoValue                = _isoValue->GetValue();
4809         int valueBeforeIsoValue = _valueBeforeIsoValue->GetValue(); 
4810         int valueAfterIsoValue  = _valueAfterIsoValue ->GetValue(); 
4811
4812         InitHistogramme();
4813         p_histogramme = (unsigned short*)_histogrammeVector->GetScalarPointer(0,0,0);
4814
4815         _imageData->GetDimensions(dim);    
4816         _imageData->GetSpacing(spc);    
4817         _actualCuttingModel->CalculeInversMatrix();
4818
4819         for (xx=0;xx<dim[0]; xx++)
4820         {
4821                 for (yy=0;yy<dim[1]; yy++)
4822                 {
4823                         for (zz=0;zz<dim[2];zz++)
4824                         {
4825                                 inside=_actualCuttingModel->IfPointInside(xx,yy,zz);
4826                                 if (  ((inside==true)&&(volInt==true)) || ((!inside==true)&&(volExt==true)) )
4827                                 {
4828                                         pOrg=(unsigned short*)_imageData->GetScalarPointer (xx,yy,zz); 
4829
4830                                         if ((*pOrg)<isoValue)
4831                                         {
4832                                                 contBefor++;
4833                                                 if (valueBeforeIsoValue!=-1)
4834                                                 {
4835                                                         *pOrg=valueBeforeIsoValue;
4836                                                 }
4837                                         } else {
4838                                                 contAfter++;
4839                                                 if (valueAfterIsoValue!=-1)
4840                                                 {
4841                                                         *pOrg=valueAfterIsoValue;
4842                                                 } // if
4843                                         } // if isovalue
4844
4845                                         p_histogramme[*pOrg]++;
4846                                         if (*pOrg<min) min=*pOrg; 
4847                                         if (*pOrg>max) max=*pOrg; 
4848                                 } // if inside
4849                         } // for zz
4850                 } // for yy
4851         } // for xx
4852
4853
4854         // Information
4855         wxString infoToVo;
4856         wxString infoSuVo;
4857         wxString infoSuVoA;
4858         wxString infoPixLe;
4859         wxString infoPixHi;
4860
4861         double volumeUnit = spc[0]*spc[1]*spc[2];
4862         long int totalSubVolume = contBefor + contAfter;
4863         double contBeforPorc    = 100*(double)contBefor/(double)totalSubVolume;
4864         double contAfterPorc    = 100*(double)contAfter/(double)totalSubVolume;
4865         infoToVo.Printf(_T("%dx%dx%d = %d"),dim[0],dim[1],dim[2], dim[0]*dim[1]*dim[2] );
4866         infoSuVo.Printf(_T("%ld") , totalSubVolume);
4867         infoSuVoA.Printf(_T("%.2f"), _actualCuttingModel->GetTheoricVolume() );
4868         infoPixLe.Printf(_T("%ld pix.   (%.2f %s)  -  %.2f mm^3"),contBefor, contBeforPorc ,_T("%"),contBefor*volumeUnit);
4869         infoPixHi.Printf(_T("%ld pix.   (%.2f %s)  -  %.2f mm^3"),contAfter, contAfterPorc ,_T("%"),contAfter*volumeUnit);
4870
4871         _infoToVo->SetLabel(infoToVo);
4872         _infoSuVo->SetLabel(infoSuVo);
4873         _infoSuVoA->SetLabel(infoSuVoA);
4874         _infoPixLe->SetLabel(infoPixLe);
4875         _infoPixHi->SetLabel(infoPixHi);
4876
4877         // Histogram
4878         if ( _histogrammeAccumulated->GetValue()==true )
4879         {
4880                 int dimHist[3];
4881                 _histogrammeVector -> GetDimensions ( dimHist );
4882
4883                 int i,size=dimHist[0];
4884                 for (i=1; i<=size; i++)
4885                 {
4886                         p_histogramme[i] = p_histogramme[i] + p_histogramme[i-1];
4887                 }
4888         }
4889         double range[2];
4890         _histogrammeVector->Update();
4891         _histogrammeVector->GetScalarRange(range);
4892         _xyplot->SetYRange( 0   , range[1]      );
4893         _xyplot->SetXRange( min , max           );
4894
4895         _vtkclipping3Ddataviewer->RefreshSurface();
4896         _wxvtkbaseView->Refresh();
4897
4898 //      _wxvtkbaseView->RefreshView();
4899         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
4900         _wxvtkbaseView->GetWxVTKRenderWindowInteractor()->GetParent()->ProcessEvent(newevent1);
4901 }
4902
4903
4904 //-------------------------------------------------------------------
4905 void wxPanelCuttingImageData::OnTypeFig(wxCommandEvent& event)
4906 {
4907         _wxvtk3Dbaseview->GetRenderer()->RemoveActor( _actualActor );
4908
4909         if (_typeFig->GetSelection()==0){
4910                 _actualCuttingModel=_modelCylinder;
4911                 _actualActor=_cylinderActor;
4912         }
4913         if (_typeFig->GetSelection()==1){
4914                 _actualCuttingModel=_modelCube;
4915                 _actualActor=_cubeActor;
4916         }
4917         if (_typeFig->GetSelection()==2){
4918                 _actualCuttingModel=_modelSphere;
4919                 _actualActor=_sphereActor;
4920         }
4921         _wxvtk3Dbaseview->GetRenderer()->AddActor( _actualActor );
4922         RefreshOpacity();
4923         RefreshView();
4924 }
4925
4926 //-------------------------------------------------------------------
4927 void wxPanelCuttingImageData::RefreshOpacity()
4928 {
4929         double op= _opacityFig->GetValue()/100.0;
4930         _actualActor->GetProperty()->SetOpacity( op );
4931 }
4932
4933 //-------------------------------------------------------------------
4934 void wxPanelCuttingImageData::OnOpacityFig(wxScrollEvent& event)
4935 {
4936         RefreshOpacity();
4937         Refresh();
4938 }
4939 //-------------------------------------------------------------------
4940 void wxPanelCuttingImageData::RefreshView()
4941 {
4942         SetParamsOfTransformation( );
4943         Refresh();
4944 }
4945 //-------------------------------------------------------------------
4946 void wxPanelCuttingImageData::Refresh()
4947 {
4948         _wxvtk3Dbaseview->Refresh();
4949 }
4950
4951 //-------------------------------------------------------------------
4952 void wxPanelCuttingImageData::SetParamsOfTransformation( )
4953 {
4954         double spc[3];
4955         vtkImageData *vtkimagedata = _vtkmprbasedata->GetImageData();
4956         vtkimagedata->GetSpacing(spc);
4957         int px = (int) (_vtkmprbasedata->GetX() );
4958         int py = (int) (_vtkmprbasedata->GetY() );
4959         int pz = (int) (_vtkmprbasedata->GetZ() );
4960         int sx = (int) (_scaleX->GetValue() * spc[0] );
4961         int sy = (int) (_scaleY->GetValue() * spc[1] );
4962         int sz = (int) (_scaleZ->GetValue() * spc[2] );
4963         _actualCuttingModel     -> SetScale             ( sx    , sy    , sz );
4964         _actualCuttingModel     -> SetPosition  ( px    , py , pz       );
4965         _actualCuttingModel     -> SetRotation  ( _rotationX->GetValue()        , _rotationY->GetValue() , _rotationZ->GetValue()       );
4966         _actualCuttingModel     -> SetSpacing   ( spc[0]        , spc[1]    , spc[2] );
4967         _actualCuttingModel     -> CalculeMatrix();
4968 }
4969
4970 //-------------------------------------------------------------------
4971
4972 void wxPanelCuttingImageData::OnTransform(wxScrollEvent& event)
4973 {
4974         RefreshView();
4975 }
4976
4977 //-------------------------------------------------------------------
4978 void wxPanelCuttingImageData::SetVtkMPRBaseData( vtkMPRBaseData *vtkmprbasedata )
4979 {
4980         _vtkmprbasedata = vtkmprbasedata;
4981         _imageData              = _vtkmprbasedata->GetImageData();
4982 }
4983
4984 //-------------------------------------------------------------------
4985
4986 void wxPanelCuttingImageData::Configure()
4987 {
4988         _actualCuttingModel=_modelCylinder;
4989         _actualActor=_cylinderActor;
4990         _wxvtk3Dbaseview->GetRenderer()->AddActor( _actualActor );
4991         SetParamsOfTransformation();
4992         RefreshView();
4993 }
4994
4995
4996
4997 //-------------------------------------------------------------------
4998 //-------------------------------------------------------------------
4999 //-------------------------------------------------------------------
5000
5001 /*
5002 BEGIN_EVENT_TABLE( wxWidgetMesure2D , wxSplitterWindow )
5003         EVT_MENU( 12121, wxWidgetMesure2D::OnRefreshView )
5004 END_EVENT_TABLE( );
5005 */
5006 //-------------------------------------------------------------------
5007
5008 wxWidgetMesure2D::wxWidgetMesure2D( wxWindow *parent )
5009 : wxSplitterWindow( parent , -1)
5010 {
5011 // EED 27 oct 2007
5012         this->SplitHorizontally( new wxPanel(this,-1) ,  new wxPanel(this,-1), 2 );
5013         this->SetMinimumPaneSize(50);
5014 }
5015 //-------------------------------------------------------------------
5016 wxWidgetMesure2D::~wxWidgetMesure2D()
5017 {
5018 }
5019 //-------------------------------------------------------------------
5020 wxWindow *wxWidgetMesure2D::CreateWin1a(wxWindow *parent) // virtual
5021 {
5022         wxPanel *panel = new wxPanel(parent,-1);
5023
5024         _cb_messuretool  = new wxCheckBox(panel,-1,_T("Active messure tool     ")); 
5025         _cb_mt_visible   = new wxCheckBox(panel,-1,_T("Visibles    ")); 
5026         _cb_closeContour = new wxCheckBox(panel,-1,_T("Close/Open    ")); 
5027         _cb_visibleText  = new wxCheckBox(panel,-1,_T("Information    ")); 
5028
5029         _cb_mt_visible->SetValue(true);
5030         _cb_closeContour->SetValue(true);
5031         _cb_visibleText->SetValue(true);
5032
5033         wxFlexGridSizer *sizer = new wxFlexGridSizer(4);
5034
5035         sizer->Add(_cb_messuretool);
5036         sizer->Add(_cb_mt_visible);
5037         sizer->Add(_cb_closeContour);
5038         sizer->Add(_cb_visibleText);
5039
5040         panel->SetAutoLayout(true);
5041         panel->SetSizer(sizer);
5042         panel->SetSize(400,30);
5043         panel->Layout();
5044 //EEDxx2.4
5045 //      panel->FitInside();
5046
5047         Connect(_cb_messuretool->GetId()  , wxEVT_COMMAND_CHECKBOX_CLICKED        , (wxObjectEventFunction) &wxWidgetMesure2D::OnActiveMessureTool      );
5048         Connect(_cb_mt_visible->GetId()   , wxEVT_COMMAND_CHECKBOX_CLICKED        , (wxObjectEventFunction) &wxWidgetMesure2D::OnVisibleMessureTool     );
5049         Connect(_cb_closeContour->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED        , (wxObjectEventFunction) &wxWidgetMesure2D::OnCloseContour           );
5050         Connect(_cb_visibleText->GetId()  , wxEVT_COMMAND_CHECKBOX_CLICKED        , (wxObjectEventFunction) &wxWidgetMesure2D::OnVisibleInformation     );
5051
5052         return panel;
5053 }
5054
5055 //-------------------------------------------------------------------
5056 void wxWidgetMesure2D::ConfigureA(wxVtk2DBaseView *wxvtk2Dbaseview) // virtual
5057 {
5058         _wxvtk2Dbaseview = wxvtk2Dbaseview;
5059
5060         // Contorno 1
5061         _manContourControl_1    = new manualContourControler();
5062         _mContourModel_1                = new manualContourModel();
5063         _mViewContour_1                 = new manualViewContour();
5064         _mViewContour_1->SetModel( _mContourModel_1 );
5065         _mViewContour_1->SetWxVtkBaseView( _wxvtk2Dbaseview );
5066         _mViewContour_1->SetRange( 1 );
5067
5068 // EED 3 oct 2006
5069 //      double spc[3];
5070 //      _wxvtk2Dbaseview->GetSpacing( spc );
5071 //      _mViewContour_1->SetSpacing( spc );
5072
5073
5074
5075         _manContourControl_1->SetZ( 1000 );
5076         _manContourControl_1->SetModelView( _mContourModel_1 , _mViewContour_1 );
5077         _wxvtk2Dbaseview->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( _manContourControl_1 );
5078         _manContourControl_1->CreateNewManualContour();
5079         _manContourControl_1->SetActive( false );
5080         _mViewContour_1->RefreshContour();
5081
5082 //EED 27 Oct 2007
5083         
5084 //      this->ReplaceWindow( this->GetWindow1() ,  CreateWin1a(this) );
5085 //      this->ReplaceWindow( this->GetWindow2() ,  _wxvtk2Dbaseview->GetWxVTKRenderWindowInteractor() );
5086 //      CreateWin1a(this->GetWindow1() );
5087
5088         wxBoxSizer *sizerA = new wxBoxSizer(wxHORIZONTAL);      
5089         sizerA->Add(  CreateWin1a( this->GetWindow1()) ,1, wxGROW );
5090         this->GetWindow1()->SetSizer(sizerA);
5091         this->SetAutoLayout(true);
5092         this->Layout();
5093
5094         wxBoxSizer *sizerB = new wxBoxSizer(wxHORIZONTAL);      
5095         sizerB->Add(  _wxvtk2Dbaseview->GetWxVTKRenderWindowInteractor()  ,1, wxGROW );
5096         this->GetWindow2()->SetSizer(sizerB);
5097         this->SetAutoLayout(true);
5098         this->Layout();
5099
5100
5101 //      this->SplitHorizontally( CreateWin1a(this) , _wxvtk2Dbaseview->GetWxVTKRenderWindowInteractor() , 2 );
5102
5103
5104 //EEDxx2.4 
5105 //      this->FitInside();
5106 }
5107
5108
5109 //-------------------------------------------------------------------
5110 void wxWidgetMesure2D::ActiveMessureTool(bool ok)
5111 {
5112         _wxvtk2Dbaseview->GetInteractorStyleBaseView()->SetActiveAllInteractors(!ok);
5113         _manContourControl_1->SetActive( ok );
5114 }
5115
5116 //-------------------------------------------------------------------
5117 void wxWidgetMesure2D::OnActiveMessureTool(wxCommandEvent& event)
5118 {
5119         ActiveMessureTool( _cb_messuretool->GetValue() );
5120         if ( _cb_messuretool->GetValue() == true )
5121         {
5122                 _cb_mt_visible->SetValue(true);
5123                 _mViewContour_1->SetVisible( _cb_mt_visible->GetValue() );
5124                 _cb_closeContour->Enable(true);
5125                 _cb_visibleText->Enable(true);
5126         } else{
5127                 _cb_closeContour->Enable(false);
5128                 _cb_visibleText->Enable(false);
5129         }
5130         _wxvtk2Dbaseview->Refresh();
5131         _wxvtk2Dbaseview->RefreshView();
5132 }
5133
5134 //-------------------------------------------------------------------
5135 void wxWidgetMesure2D::OnVisibleMessureTool(wxCommandEvent& event)
5136 {
5137         _cb_messuretool->SetValue( _cb_mt_visible->GetValue() );
5138         if (_cb_messuretool->GetValue()==true)
5139         {
5140                 _cb_closeContour->Enable(true);
5141                 _cb_visibleText->Enable(true);
5142         }
5143         ActiveMessureTool( _cb_messuretool->GetValue() );       
5144         _mViewContour_1->SetVisible( _cb_mt_visible->GetValue() );
5145         _mViewContour_1->Refresh();
5146         _wxvtk2Dbaseview->Refresh();
5147         _wxvtk2Dbaseview->RefreshView();
5148 }
5149
5150 //-------------------------------------------------------------------
5151 void wxWidgetMesure2D::OnCloseContour(wxCommandEvent& event)
5152 {
5153         _mContourModel_1->SetCloseContour( _cb_closeContour->GetValue() );
5154         _mViewContour_1->Refresh();
5155         _wxvtk2Dbaseview->Refresh();
5156         _wxvtk2Dbaseview->RefreshView();
5157
5158 }
5159 //-------------------------------------------------------------------
5160 void wxWidgetMesure2D::OnVisibleInformation(wxCommandEvent& event)
5161 {
5162         _mViewContour_1->SetShowText( _cb_visibleText->GetValue() );
5163         _mViewContour_1->Refresh();
5164         _wxvtk2Dbaseview->Refresh();
5165         _wxvtk2Dbaseview->RefreshView();
5166 }
5167 //-------------------------------------------------------------------
5168 void wxWidgetMesure2D::SetMesureScale(double mesureScale)
5169 {
5170         _mViewContour_1->SetMesureScale(mesureScale);
5171 }
5172 //-------------------------------------------------------------------
5173 manualContourModel*     wxWidgetMesure2D::GetManualContourModel()
5174 {
5175         return _mContourModel_1;
5176 }
5177
5178 //-------------------------------------------------------------------
5179 //-------------------------------------------------------------------
5180 //-------------------------------------------------------------------
5181
5182 wxWidgetMesure2D_Plane::wxWidgetMesure2D_Plane(wxWindow *parent)
5183 : wxWidgetMesure2D(parent)
5184 {
5185         // Circle 1
5186         _ptsCircle1             = NULL;
5187         _circle1Actor   = NULL;
5188         _circle1Mapper  = NULL;
5189     _pdCircle1          = NULL;
5190         // Circle 2
5191         _ptsCircle2             = NULL;
5192         _circle2Actor   = NULL;
5193         _circle2Mapper  = NULL;
5194     _pdCircle2          = NULL;
5195         // line reference 1
5196         _ptsLineRef1    = NULL;
5197         _lineRef1Actor  = NULL;
5198         _lineRef1Mapper = NULL;
5199     _pdLineRef1         = NULL;
5200         // line reference 2
5201         _ptsLineRef2    = NULL;
5202         _lineRef2Actor  = NULL;
5203         _lineRef2Mapper = NULL;
5204     _pdLineRef2         = NULL;
5205
5206 }
5207
5208 //-------------------------------------------------------------------
5209
5210 wxWidgetMesure2D_Plane::~wxWidgetMesure2D_Plane()
5211 {
5212         // Circle 1
5213     if (        _ptsCircle1             != NULL){       _ptsCircle1                     -> Delete(); }
5214     if (        _circle1Actor   != NULL){       _circle1Actor           -> Delete(); }
5215     if (        _circle1Mapper  != NULL){       _circle1Mapper          -> Delete(); }
5216     if (    _pdCircle1          != NULL){       _pdCircle1                      -> Delete(); }
5217         // Circle 2
5218     if (        _ptsCircle2             != NULL){       _ptsCircle2                     -> Delete(); }
5219     if (        _circle2Actor   != NULL){       _circle2Actor           -> Delete(); }
5220     if (        _circle2Mapper  != NULL){       _circle2Mapper          -> Delete(); }
5221     if (    _pdCircle2          != NULL){       _pdCircle2                      -> Delete(); }
5222         // line reference 1
5223     if (        _ptsLineRef1    != NULL){       _ptsLineRef1            -> Delete(); }
5224     if (        _lineRef1Actor  != NULL){       _lineRef1Actor          -> Delete(); }
5225     if (        _lineRef1Mapper != NULL){       _lineRef1Mapper         -> Delete(); }
5226      if (   _pdLineRef1         != NULL){       _pdLineRef1                     -> Delete(); }
5227         // line reference 2
5228     if (        _ptsLineRef2    != NULL){       _ptsLineRef2            -> Delete(); }
5229     if (        _lineRef2Actor  != NULL){       _lineRef2Actor          -> Delete(); }
5230     if (        _lineRef2Mapper != NULL){       _lineRef2Mapper         -> Delete(); }
5231     if (    _pdLineRef2         != NULL){       _pdLineRef2                     -> Delete(); }
5232 }
5233
5234 //-------------------------------------------------------------------
5235
5236 wxWindow *wxWidgetMesure2D_Plane::CreateWin1a(wxWindow *parent) // virtual
5237 {
5238         wxPanel *panel = new wxPanel(parent,-1);
5239
5240         _cb_circle              = new wxCheckBox(panel,-1,_T("Circle        ")); 
5241         _cb_line                = new wxCheckBox(panel,-1,_T("Rotation Axe ")); 
5242
5243
5244         wxBoxSizer *sizerA = new wxBoxSizer(wxHORIZONTAL);
5245         sizerA->Add(_cb_circle);
5246         sizerA->Add(_cb_line);
5247
5248
5249         wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
5250         sizer->Add( sizerA );
5251         sizer->Add( wxWidgetMesure2D::CreateWin1a(panel) );
5252
5253         panel->SetAutoLayout(true);
5254         panel->SetSizer(sizer);
5255         panel->SetSize(400,30);
5256         panel->Layout();
5257 //EEDxx2.4
5258 //      panel->FitInside();
5259
5260         Connect(_cb_line->GetId()        , wxEVT_COMMAND_CHECKBOX_CLICKED         , (wxObjectEventFunction) &wxWidgetMesure2D_Plane::OnActiveLine                       );
5261         Connect(_cb_circle->GetId()      , wxEVT_COMMAND_CHECKBOX_CLICKED         , (wxObjectEventFunction) &wxWidgetMesure2D_Plane::OnActiveCirlcle            );
5262
5263         return panel;
5264 }
5265
5266
5267 //-------------------------------------------------------------------
5268 void wxWidgetMesure2D_Plane::OnActiveCirlcle(wxCommandEvent& event)
5269 {
5270         SetVisibleCircle( _cb_circle->GetValue() );
5271         _wxvtk2Dbaseview->RefreshView();
5272 }
5273
5274 //-------------------------------------------------------------------
5275 void wxWidgetMesure2D_Plane::SetVisibleCircle( bool ok )
5276 {
5277         double opacity;
5278         if (ok==true)
5279         {
5280                 opacity=1;
5281         } else {
5282                 opacity=0;
5283         } 
5284         _lineRef1Actor->GetProperty()->SetOpacity( opacity );
5285         _lineRef2Actor->GetProperty()->SetOpacity( opacity );
5286         _circle1Actor->GetProperty()->SetOpacity( opacity );
5287         _circle2Actor->GetProperty()->SetOpacity( opacity );
5288 }
5289 //-------------------------------------------------------------------
5290 void wxWidgetMesure2D_Plane::OnActiveLine(wxCommandEvent& event)
5291 {
5292         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)_wxvtk2Dbaseview;
5293         vtkplane2Dview->SetVisibleLine( _cb_line->GetValue() );
5294         _wxvtk2Dbaseview->RefreshView();
5295 }
5296
5297
5298 //-------------------------------------------------------------------
5299 void wxWidgetMesure2D_Plane::ConfigureA(wxVtk2DBaseView *wxvtk2Dbaseview) // virtual
5300 {
5301         wxWidgetMesure2D::ConfigureA(wxvtk2Dbaseview);
5302         CircleLine();
5303         ConfigureCircleLine();
5304         SetVisibleCircle(false);        
5305 }
5306
5307
5308 //-------------------------------------------------------------------
5309 void wxWidgetMesure2D_Plane::ConfigureCircleLine()
5310 {
5311         double ang;
5312
5313         vtkPlane2DView *vtkplane2Dview = (vtkPlane2DView*)_wxvtk2Dbaseview;
5314         int sizeIma = vtkplane2Dview->GetImgSize();
5315
5316         double i,maxPts=20;
5317         double k=(360/(maxPts-1)) * (3.1416/180);
5318         double x,y,r1=5,r2=10,r3=15;
5319         for (i=0;i<maxPts;i++)
5320         {
5321                 x=cos( k*i ) ;
5322                 y=sin( k*i ) ;
5323                 _ptsCircle1->SetPoint( (int)i , (sizeIma/2) + x*r1      , (sizeIma/2) + y*r1    , 1 );
5324                 _ptsCircle2->SetPoint( (int)i , (sizeIma/2) + x*r2      , (sizeIma/2) + y*r2    , 1 );
5325         }
5326
5327         //
5328         ang=(45) * (3.1416/180);
5329         x=cos( ang ) ;
5330         y=sin( ang ) ;
5331         _ptsLineRef1->SetPoint( 0 , (sizeIma/2) + x*r3  , (sizeIma/2) + y*r3    , 1 );
5332         
5333         ang=(45+180) * (3.1416/180);
5334         x=cos( ang ) ;
5335         y=sin( ang ) ;
5336         _ptsLineRef1->SetPoint( 1 , (sizeIma/2) + x*r3  , (sizeIma/2) + y*r3    , 1 );
5337
5338         //
5339         ang=(135) * (3.1416/180);
5340         x=cos( ang ) ;
5341         y=sin( ang ) ;
5342         _ptsLineRef2->SetPoint( 0 , (sizeIma/2) + x*r3  , (sizeIma/2) + y*r3    , 1 );
5343         
5344         ang=(135+180) * (3.1416/180);
5345         x=cos( ang ) ;
5346         y=sin( ang ) ;
5347         _ptsLineRef2->SetPoint( 1 , (sizeIma/2) + x*r3  , (sizeIma/2) + y*r3    , 1 );
5348 }
5349
5350
5351
5352 //-------------------------------------------------------------------
5353 void wxWidgetMesure2D_Plane::CircleLine()
5354 {
5355         int i,maxPts=20;
5356         vtkCellArray *lines;
5357
5358         vtkImageViewer2_XYZ *imageViewer2XYZ = _wxvtk2Dbaseview->_imageViewer2XYZ;
5359         
5360
5361 // Circle 1 Horizontal
5362         _ptsCircle1 = vtkPoints::New();
5363         _ptsCircle1->SetNumberOfPoints(maxPts);
5364         lines = vtkCellArray::New();
5365         lines->InsertNextCell(maxPts);
5366         for (i=0;i<maxPts;i++)
5367         {
5368                 lines->InsertCellPoint(i);
5369                 _ptsCircle1->SetPoint(i, 0      , 0     , 0 );
5370         }
5371         lines->InsertCellPoint(0);
5372         _ptsCircle1->SetPoint(0, -1000  , -1000 , -1000 );
5373         _ptsCircle1->SetPoint(1,  1000  ,  1000 ,  1000 );
5374
5375         _pdCircle1 = vtkPolyData::New();
5376     _pdCircle1->SetPoints( _ptsCircle1 );
5377     _pdCircle1->SetLines( lines );
5378         lines->Delete();  //do not delete lines ??
5379         _circle1Actor                                   =       vtkActor::New();
5380     _circle1Mapper                                      =       vtkPolyDataMapper::New();
5381         _circle1Mapper->SetInput(_pdCircle1);
5382         _circle1Mapper->ImmediateModeRenderingOn();
5383         _circle1Actor->SetMapper(_circle1Mapper);
5384         _circle1Actor->GetProperty()->BackfaceCullingOn();
5385         _circle1Actor->GetProperty()->SetDiffuseColor(0,0,1);
5386         _circle1Actor->GetProperty()->SetLineWidth(2);
5387     imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _circle1Actor );
5388
5389 // Circle 2 Horizontal
5390         _ptsCircle2 = vtkPoints::New();
5391         _ptsCircle2->SetNumberOfPoints(maxPts);
5392         lines = vtkCellArray::New();
5393         lines->InsertNextCell(maxPts);
5394         for (i=0;i<maxPts;i++)
5395         {
5396                 lines->InsertCellPoint(i);
5397                 _ptsCircle2->SetPoint(i, 0      , 0     , 0 );
5398         }
5399         _ptsCircle2->SetPoint(0, -1000  , -1000 , -1000 );
5400         _ptsCircle2->SetPoint(1,  1000  ,  1000 ,  1000 );
5401
5402         _pdCircle2 = vtkPolyData::New();
5403     _pdCircle2->SetPoints( _ptsCircle2 );
5404     _pdCircle2->SetLines( lines );
5405         lines->Delete();  //do not delete lines ??
5406         _circle2Actor                                   =       vtkActor::New();
5407     _circle2Mapper                                      =       vtkPolyDataMapper::New();
5408         _circle2Mapper->SetInput(_pdCircle2);
5409         _circle2Mapper->ImmediateModeRenderingOn();
5410         _circle2Actor->SetMapper(_circle2Mapper);
5411         _circle2Actor->GetProperty()->BackfaceCullingOn();
5412         _circle2Actor->GetProperty()->SetDiffuseColor(0,0,1);
5413         _circle2Actor->GetProperty()->SetLineWidth(2);
5414     imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _circle2Actor );
5415
5416 // Line Referance 1
5417         _ptsLineRef1 = vtkPoints::New();
5418         _ptsLineRef1->SetNumberOfPoints(2);
5419         _ptsLineRef1->SetPoint(0, -1000 , -1000 , -1000 );
5420         _ptsLineRef1->SetPoint(1,  1000 ,  1000 ,  1000 );
5421         lines = vtkCellArray::New();
5422         lines->InsertNextCell(2);
5423         lines->InsertCellPoint(0);
5424         lines->InsertCellPoint(1);
5425
5426         _pdLineRef1 = vtkPolyData::New();
5427     _pdLineRef1->SetPoints( _ptsLineRef1 );
5428     _pdLineRef1->SetLines( lines );
5429         lines->Delete();  //do not delete lines ??
5430         _lineRef1Actor                                  =       vtkActor::New();
5431     _lineRef1Mapper                                     =       vtkPolyDataMapper::New();
5432         _lineRef1Mapper->SetInput(_pdLineRef1);
5433         _lineRef1Mapper->ImmediateModeRenderingOn();
5434         _lineRef1Actor->SetMapper(_lineRef1Mapper);
5435         _lineRef1Actor->GetProperty()->BackfaceCullingOn();
5436         _lineRef1Actor->GetProperty()->SetDiffuseColor(0,0,1);
5437         _lineRef1Actor->GetProperty()->SetLineWidth(2);
5438     imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineRef1Actor );
5439
5440 // Line Referance 2
5441         _ptsLineRef2 = vtkPoints::New();
5442         _ptsLineRef2->SetNumberOfPoints(2);
5443         _ptsLineRef2->SetPoint(0, -1000 , -1000 , -1000 );
5444         _ptsLineRef2->SetPoint(1,  1000 ,  1000 ,  1000 );
5445         lines = vtkCellArray::New();
5446         lines->InsertNextCell(2);
5447         lines->InsertCellPoint(0);
5448         lines->InsertCellPoint(1);
5449
5450         _pdLineRef2 = vtkPolyData::New();
5451     _pdLineRef2->SetPoints( _ptsLineRef2 );
5452     _pdLineRef2->SetLines( lines );
5453         lines->Delete();  //do not delete lines ??
5454         _lineRef2Actor                                  =       vtkActor::New();
5455     _lineRef2Mapper                                     =       vtkPolyDataMapper::New();
5456         _lineRef2Mapper->SetInput(_pdLineRef2);
5457         _lineRef2Mapper->ImmediateModeRenderingOn();
5458         _lineRef2Actor->SetMapper(_lineRef2Mapper);
5459         _lineRef2Actor->GetProperty()->BackfaceCullingOn();
5460         _lineRef2Actor->GetProperty()->SetDiffuseColor(0,0,1);
5461         _lineRef2Actor->GetProperty()->SetLineWidth(2);
5462     imageViewer2XYZ->GetVtkImageViewer2()->GetRenderer()->AddActor( _lineRef2Actor );
5463
5464
5465 }
5466
5467
5468 //-------------------------------------------------------------------
5469 //-------------------------------------------------------------------
5470 //-------------------------------------------------------------------
5471
5472 wxWidgetMesure2D_Plane_in_MPR::wxWidgetMesure2D_Plane_in_MPR(wxWindow *parent)
5473 :wxWidgetMesure2D_Plane(parent)
5474 {
5475         _vtkplane2Dview=NULL;
5476 }
5477
5478 //-------------------------------------------------------------------
5479
5480 wxWidgetMesure2D_Plane_in_MPR::~wxWidgetMesure2D_Plane_in_MPR()
5481 {
5482 }
5483 //-------------------------------------------------------------------
5484 void wxWidgetMesure2D_Plane_in_MPR::OnActiveLink(wxCommandEvent& event)
5485 {
5486         if (_vtkplane2Dview!=NULL)
5487         {
5488                 _vtkplane2Dview->SetActive( _cb_link->GetValue() );
5489                 _vtkplane2Dview->Refresh();
5490                 _vtkplane2Dview->RefreshView();
5491         }
5492 }
5493
5494
5495 //-------------------------------------------------------------------
5496 void wxWidgetMesure2D_Plane_in_MPR::SetActiveLink(bool ok)
5497 {
5498         _cb_link->SetValue(ok);
5499         if (_vtkplane2Dview!=NULL)
5500         {
5501                 _vtkplane2Dview->SetActive( _cb_link->GetValue() );
5502         }
5503 }
5504 //-------------------------------------------------------------------
5505
5506 void wxWidgetMesure2D_Plane_in_MPR::SetVtkPlane2DView(vtkPlane2DView *vtkplane2Dview)
5507 {
5508         _vtkplane2Dview = vtkplane2Dview;
5509 }
5510
5511 //-------------------------------------------------------------------
5512
5513 wxWindow *wxWidgetMesure2D_Plane_in_MPR::CreateWin1a(wxWindow *parent) // virtual
5514 {
5515         wxPanel *panel = new wxPanel(parent,-1);
5516
5517         _cb_link                = new wxCheckBox(panel,-1,_T("LINK                    ")); 
5518         _cb_link->SetValue(true);
5519
5520         wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
5521
5522         sizer->Add(_cb_link);
5523
5524         sizer->Add( wxWidgetMesure2D_Plane::CreateWin1a(panel) );
5525
5526         panel->SetAutoLayout(true);
5527         panel->SetSizer(sizer);
5528         panel->SetSize(400,30);
5529         panel->Layout();
5530
5531 //EEDxx2.4
5532 //      panel->FitInside();
5533
5534         Connect(_cb_link->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED, (wxObjectEventFunction) &wxWidgetMesure2D_Plane_in_MPR::OnActiveLink );
5535
5536         return panel;
5537 }
5538
5539
5540
5541
5542 //-------------------------------------------------------------------
5543 //-------------------------------------------------------------------
5544 //-------------------------------------------------------------------
5545
5546 BEGIN_EVENT_TABLE( wxMPRWidget, wxPanel )
5547         EVT_MENU( 12121, wxMPRWidget::OnRefreshView )
5548         EVT_MENU( 12122, wxMPRWidget::OnDClickLeft  )
5549 END_EVENT_TABLE( );
5550
5551
5552
5553 wxMPRWidget::wxMPRWidget( wxWindow* parent,
5554                           marImageData *marimageData , double voxelSize)
5555 : wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
5556 {
5557
5558         _vtkmpr2Dview[0]                                = NULL;
5559         _vtkmpr2Dview[1]                                = NULL;
5560         _vtkmpr2Dview[2]                                = NULL;
5561         _vtkplane2Dview                                 = NULL;
5562         _widgetMesure                                   = NULL;
5563         _wxsphereview                                   = NULL;
5564         _wxvtk3Dbaseview_MPRClipping3D  = NULL;
5565         _wxvtkmpr3Dview                                 = NULL;
5566         _wxvtkclipping3Dview                    = NULL;
5567         _vtkplane2Dview_B                               = NULL;
5568         _widgetMesure_B                                 = NULL;
5569
5570         _vtkmpr2Dview_B[0]                              = NULL;
5571         _vtkmpr2Dview_B[1]                              = NULL;
5572         _vtkmpr2Dview_B[2]                              = NULL;
5573         _vtkplane2Dview_B                               = NULL;
5574         _widgetMesure_B                                 = NULL;
5575         _wxsphereview_B                                 = NULL;
5576         _wxvtk3Dbaseview_MPR3D_B                = NULL;
5577         _wxvtkmpr3Dview_B                               = NULL;
5578         _wxvtk3Dbaseview_Clipping3D_BB  = NULL;
5579         _wxvtkmpr3Dview_BB                              = NULL;
5580         _wxvtkclipping3Dview_BB                 = NULL;
5581
5582         _vtkmprbasedata                                 = NULL;
5583
5584
5585         
5586         _framePanelCutting                              = NULL; 
5587         _panelCutting                                   = NULL;
5588
5589
5590         wxBoxSizer                      *sizer          = new wxBoxSizer(wxVERTICAL  );
5591         _marImageData=NULL;
5592
5593         if(marimageData!=NULL){
5594                 _marImageData                                   = marimageData;
5595                 _voxelSize                                              = voxelSize;
5596                 _vtkmprbasedata                                 = new vtkMPRBaseData(); 
5597                 _vtkmprbasedata->SetMarImageData(_marImageData);
5598                 
5599                 
5600                 
5601
5602                 wxSplitterWindow        *pnlSplitter            = new wxSplitterWindow( this , -1);
5603                 pnlSplitter     -> SetMinimumPaneSize( 2 );
5604
5605                 wxPanel                         *MPRPanel       = CreateMPRPanel(pnlSplitter,_vtkmprbasedata);
5606                 wxPanel                         *controlPanel   = CreateControlPanel(pnlSplitter);      
5607                 pnlSplitter     -> SplitVertically( MPRPanel, controlPanel, 550 );
5608
5609                 sizer           -> Add( pnlSplitter ,1,wxGROW  ,0);
5610
5611         }          
5612
5613         //int ww,hh;
5614         //wxWindow *pp=this;
5615         //while (pp->GetParent()!=NULL) pp=pp->GetParent();
5616         //pp->GetSize(&ww,&hh);
5617         
5618         this            -> SetAutoLayout( true );
5619         this            -> SetSizer(sizer);
5620 //      sizer           ->      Fit( this );
5621         _refreshAPage=0;
5622         _refreshBPage=0;
5623
5624 }
5625 void wxMPRWidget::setImageData(vtkImageData * img, double voxelsize){
5626
5627         if(_marImageData!=NULL){
5628                 _marImageData->removeImageData(0);
5629                 _marImageData->AddImageData(img);               
5630         }else{
5631                 _marImageData = new marImageData(img);
5632         }
5633         
5634         _voxelSize                                              = voxelsize;
5635
5636         if(_vtkmprbasedata==NULL){
5637                 _vtkmprbasedata                                 = new vtkMPRBaseData(); 
5638                 _vtkmprbasedata->SetMarImageData(_marImageData);        
5639
5640                 wxSplitterWindow        *pnlSplitter            = new wxSplitterWindow( this , -1);
5641                 pnlSplitter     -> SetMinimumPaneSize( 2 );
5642
5643                 wxPanel                         *MPRPanel       = CreateMPRPanel(pnlSplitter,_vtkmprbasedata);
5644                 wxPanel                         *controlPanel   = CreateControlPanel(pnlSplitter);      
5645                 pnlSplitter     -> SplitVertically( MPRPanel, controlPanel, 550 );
5646
5647                 this->GetSizer()                -> Add( pnlSplitter ,1,wxGROW  ,0);
5648         }       
5649         
5650
5651         
5652 }
5653 //----------------------------------------------------------------------------
5654
5655 wxMPRWidget::~wxMPRWidget( )
5656 {
5657 //EEDxx2.4 DELETE
5658         if (_framePanelCutting!=NULL)
5659         {
5660                 _framePanelCutting->Close();
5661         }
5662
5663         if (_vtkmpr2Dview[0]!=NULL)                                     { delete _vtkmpr2Dview[0]; }
5664         if (_vtkmpr2Dview[1]!=NULL)                                     { delete _vtkmpr2Dview[1]; }
5665         if (_vtkmpr2Dview[2]!=NULL)                                     { delete _vtkmpr2Dview[2]; }
5666
5667         if (_vtkmpr2Dview_B[0]!=NULL)                           { delete _vtkmpr2Dview_B[0]; }
5668
5669         if (_vtkmpr2Dview_B[1]!=NULL)                           { delete _vtkmpr2Dview_B[1]; }
5670         if (_vtkmpr2Dview_B[2]!=NULL)                           { delete _vtkmpr2Dview_B[2]; }
5671
5672         if (_vtkmprbasedata!=NULL)                                      { delete _vtkmprbasedata; }
5673         if (_vtkplane2Dview!=NULL)                                      { delete _vtkplane2Dview; }
5674         if (_wxsphereview!=NULL)                                        { delete _wxsphereview; }
5675         if (_wxvtk3Dbaseview_MPRClipping3D!=NULL)       { delete _wxvtk3Dbaseview_MPRClipping3D; }
5676         if (_wxvtkmpr3Dview!=NULL)                                      { delete _wxvtkmpr3Dview; }
5677         if (_wxvtkclipping3Dview!=NULL)                         { delete _wxvtkclipping3Dview; }
5678
5679         if (_vtkplane2Dview_B!=NULL)                            { delete _vtkplane2Dview_B; }
5680         if (_wxsphereview_B!=NULL)                                      { delete _wxsphereview_B; }
5681
5682         if (_wxvtk3Dbaseview_MPR3D_B!=NULL)                     { delete _wxvtk3Dbaseview_MPR3D_B; }
5683         if (_wxvtkmpr3Dview_B!=NULL)                            { delete _wxvtkmpr3Dview_B; }
5684
5685         if (_wxvtk3Dbaseview_Clipping3D_BB!=NULL)       { delete _wxvtk3Dbaseview_Clipping3D_BB; }
5686         if (_wxvtkmpr3Dview_BB!=NULL)                           { delete _wxvtkmpr3Dview_BB; }
5687         if (_wxvtkclipping3Dview_BB!=NULL)                      { delete _wxvtkclipping3Dview_BB; }
5688 }
5689
5690 //----------------------------------------------------------------------------
5691
5692 wxPanel* wxMPRWidget::CreateControlPanel(wxWindow *parent)
5693 {
5694
5695         wxPanel *panel=new wxPanel(parent,-1);
5696
5697 //EEDxx2.4
5698 //      wxStaticText *tmpText = new wxStaticText(panel,-1,""); 
5699
5700         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")); 
5701
5702         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")); 
5703         
5704         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)")); 
5705
5706         wxStaticText *help3Text = new wxStaticText(panel,-1,
5707 _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")); 
5708         
5709         wxStaticText *help4Text = new wxStaticText(panel,-1,_T("MPR3D:\n  see split control")); 
5710
5711         wxString text=_T("");
5712         text=text+_T("Clipping: \n");
5713         text=text+_T(" see split control \n");
5714         text=text+_T(" 4 MarchingCubes:  \n");
5715         text=text+_T("    color, isovalue, opacity \n");
5716         text=text+_T(" Box:\n");
5717         text=text+_T("    mouse left drag (box): rotation\n");
5718         text=text+_T("    mouse left drag (sphere): size,position\n");
5719         text=text+_T("    mouse right drag (box): box size");
5720         text=text+_T(" Axis: 3D\n");
5721         text=text+_T("    mouse drag: translate\n");
5722         text=text+_T("    shift + mouse drag: translate 2 axis\n");
5723         text=text+_T("    mouse right: scale\n");
5724         text=text+_T(" Plane 3D:\n");
5725         text=text+_T("    mouse drag perpendicular axis: rotate plane\n");
5726         text=text+_T("    mouse drag spheres: size plane\n");
5727         text=text+_T("    ctrl +mouse right over the plane: size plane\n");
5728         text=text+_T("    mouse drag plane: translate\n");
5729         text=text+_T("    middle click perpendicular axis: translate\n");
5730         wxStaticText *help5Text = new wxStaticText(panel,-1, text );
5731
5732
5733     wxFlexGridSizer *sizer  = new wxFlexGridSizer(1);
5734         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5735         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5736         sizer->Add( help0Text   );
5737
5738         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5739         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5740         sizer->Add( help1Text   );
5741
5742         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5743         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5744         sizer->Add( help2Text   );
5745
5746         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5747         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5748         sizer->Add( help3Text   );
5749
5750         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5751         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5752         sizer->Add( help4Text   );
5753
5754         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5755         sizer->Add( new wxStaticText(panel,-1,_T(""))   );
5756         sizer->Add( help5Text   );
5757         
5758         panel->SetSizer(sizer);
5759         panel->SetAutoLayout(true);
5760         panel->SetSize(350,500);
5761
5762     return panel;
5763 }
5764
5765 //----------------------------------------------------------------------------
5766
5767 void wxMPRWidget::OnPageAChanged(wxNotebookEvent & event)
5768 {
5769         _refreshAPage=event.GetSelection();
5770         Refresh();
5771         RefreshView(true);
5772 }
5773
5774 //----------------------------------------------------------------------------
5775
5776 void wxMPRWidget::OnPageBChanged(wxNotebookEvent & event)
5777 {
5778         _refreshBPage=event.GetSelection();
5779 //      Refresh(false);
5780 //      RefreshView();
5781 }
5782
5783
5784 //----------------------------------------------------------------------------
5785
5786 wxPanel* wxMPRWidget::CreateView(int type,wxWindow *parent, vtkMPRBaseData *vtkmprbasedata)
5787 {
5788         wxWindow *wxwindow;
5789         wxPanel *panel=new wxPanel(parent,-1);
5790
5791         if (type==0)
5792         {
5793                 _vtkmpr2Dview_B[0] = new wxVtkMPR2DView(panel,0);
5794                 _vtkmpr2Dview_B[0]->SetVtkBaseData(vtkmprbasedata);
5795                 wxwindow=_vtkmpr2Dview_B[0]->GetWxVTKRenderWindowInteractor();
5796         }
5797         if (type==1)
5798         {
5799                 _vtkmpr2Dview_B[1] = new wxVtkMPR2DView(panel,1);
5800                 _vtkmpr2Dview_B[1]->SetVtkBaseData(vtkmprbasedata);
5801                 wxwindow=_vtkmpr2Dview_B[1]->GetWxVTKRenderWindowInteractor();
5802         }
5803         if (type==2)
5804         {
5805                 _vtkmpr2Dview_B[2] = new wxVtkMPR2DView(panel,2);
5806                 _vtkmpr2Dview_B[2]->SetVtkBaseData(vtkmprbasedata);
5807                 wxwindow=_vtkmpr2Dview_B[2]->GetWxVTKRenderWindowInteractor();
5808         }
5809         if (type==3)
5810         {
5811                 _widgetMesure_B         = new wxWidgetMesure2D_Plane_in_MPR(panel);
5812                 _vtkplane2Dview_B       = new vtkPlane2DView( _widgetMesure_B->GetWindow2());
5813                 _widgetMesure_B->SetVtkPlane2DView( _vtkplane2Dview_B );
5814                 _vtkplane2Dview_B->SetImgSize( 200 );
5815                 _vtkplane2Dview_B->SetVtkBaseData(vtkmprbasedata);
5816                 wxwindow                        = _widgetMesure_B;
5817         }
5818         if (type==4)
5819         {
5820                 _wxsphereview_B         = new wxSphereView( panel , vtkmprbasedata, vtkmprbasedata->GetImageData() );
5821                 wxwindow=_wxsphereview_B->GetWxVTKRenderWindowInteractor();
5822         }
5823
5824         if (type==5)
5825         {
5826                 wxSplitterWindow *panelMPR3D    = new wxSplitterWindow( panel , -1);
5827                 _wxvtk3Dbaseview_MPR3D_B                = new wxVtk3DBaseView( panelMPR3D );
5828
5829                 _wxvtkmpr3Dview_B                               = new wxVtkMPR3DView(_wxvtk3Dbaseview_MPR3D_B);
5830                 vtkMPR3DDataViewer *vtkmpr3Ddataviewer = new vtkMPR3DDataViewer(); 
5831                 vtkmpr3Ddataviewer->SetVtkMPRBaseData(vtkmprbasedata);
5832                 vtkmpr3Ddataviewer->Configure();
5833                 _wxvtkmpr3Dview_B->SetVtkMPR3DDataViewer(vtkmpr3Ddataviewer);
5834
5835                 wxWindow        *window3D                       = _wxvtk3Dbaseview_MPR3D_B->GetWxVTKRenderWindowInteractor();
5836                 wxPanel         *controlPanel3D         = _wxvtkmpr3Dview_B->CreateControlPanel(panelMPR3D);
5837
5838 //EEDxx2.4
5839                 panelMPR3D      -> SetMinimumPaneSize( 5 );
5840                 panelMPR3D      -> SplitHorizontally( controlPanel3D,window3D,600  );
5841
5842                 wxwindow=panelMPR3D;
5843         }
5844
5845         if (type==6)
5846         {
5847                 wxSplitterWindow        *panelClipping3D        = new wxSplitterWindow( panel , -1);
5848                 _wxvtk3Dbaseview_Clipping3D_BB                  = new wxVtk3DBaseView( panelClipping3D );
5849
5850                 _wxvtkclipping3Dview_BB                                 = new wxVtkClipping3DView(_wxvtk3Dbaseview_Clipping3D_BB);
5851                 vtkClipping3DDataViewer *vtkclipping3Ddataviewer = new vtkClipping3DDataViewer(); 
5852                 vtkclipping3Ddataviewer->SetVtkMPRBaseData(vtkmprbasedata);
5853                 vtkclipping3Ddataviewer->Configure();
5854                 _wxvtkclipping3Dview_BB->SetVtkClipping3DDataViewer(vtkclipping3Ddataviewer);
5855
5856                 _wxvtkmpr3Dview_BB                                              = new wxVtkMPR3DView( _wxvtk3Dbaseview_Clipping3D_BB );
5857                 vtkMPR3DDataViewer *vtkmpr3Ddataviewer  = new vtkMPR3DDataViewer(); 
5858                 vtkmpr3Ddataviewer->SetVtkMPRBaseData(vtkmprbasedata);
5859                 vtkmpr3Ddataviewer->Configure();
5860                 _wxvtkmpr3Dview_BB->SetVtkMPR3DDataViewer(vtkmpr3Ddataviewer);
5861
5862                 wxWindow        *window3D                                       = _wxvtk3Dbaseview_Clipping3D_BB->GetWxVTKRenderWindowInteractor();
5863
5864                 wxPanel                 *panelControl                   = new wxPanel(panelClipping3D,-1);      
5865                 wxPanel                 *controlPanelMPR3D              = _wxvtkmpr3Dview_BB->CreateControlPanel(panelControl);
5866                 wxPanel                 *controlPanelClipping3D = _wxvtkclipping3Dview_BB->CreateControlPanel(panelControl);
5867                                  _btnCutImageData               = new wxCheckBox(panelControl,-1,_T("Cut Module"));
5868                 Connect(_btnCutImageData->GetId() , wxEVT_COMMAND_CHECKBOX_CLICKED  , (wxObjectEventFunction) &wxMPRWidget::OnCutImagaData );
5869
5870                 wxFlexGridSizer  *sizerCtrol             = new wxFlexGridSizer(1);
5871                 sizerCtrol->Add(controlPanelMPR3D               , 1, wxALL|wxEXPAND, 2);
5872                 sizerCtrol->Add(controlPanelClipping3D  , 1, wxALL|wxEXPAND, 2);
5873                 sizerCtrol->Add( _btnCutImageData               , 1, wxALL, 2);
5874
5875                 panelControl->SetAutoLayout(true);
5876                 panelControl->SetSizer(sizerCtrol);
5877                 panelControl->SetSize(400,350);
5878                 panelControl->Layout();
5879 //EEDxx2.4
5880 //              panelControl->FitInside();
5881
5882 //EEDxx2.4
5883                 panelClipping3D -> SetMinimumPaneSize( 5 );
5884                 panelClipping3D -> SplitHorizontally( panelControl , window3D , 10  );
5885                 wxwindow=panelClipping3D;
5886         }
5887
5888     wxBoxSizer *sizerH1                                                 = new wxBoxSizer(wxHORIZONTAL);
5889         sizerH1->Add(wxwindow , 1, wxALL|wxGROW, 0);
5890         panel->SetAutoLayout(true);
5891         panel->SetSizer(sizerH1);
5892         panel->SetSize(400,400);
5893         panel->Layout();
5894
5895         return panel;
5896 }
5897
5898 //----------------------------------------------------------------------------
5899
5900 wxPanel* wxMPRWidget::CreateMPRPanel(wxWindow *parent, vtkMPRBaseData *vtkmprbasedata)
5901 {
5902         wxPanel *panel=new wxPanel(parent,-1);
5903
5904         wxNotebook *notebook = new wxNotebook( panel, -1 );
5905
5906         notebook->AddPage( CreateMPRPanel4View( notebook ,vtkmprbasedata), _T("4-View") );
5907         notebook->AddPage( CreateView(0,notebook,vtkmprbasedata) , _T("Axial")          );
5908         notebook->AddPage( CreateView(1,notebook,vtkmprbasedata) , _T("Sagital")        );
5909         notebook->AddPage( CreateView(2,notebook,vtkmprbasedata) , _T("Coronal")        );
5910         notebook->AddPage( CreateView(3,notebook,vtkmprbasedata) , _T("Plane")          );
5911         notebook->AddPage( CreateView(4,notebook,vtkmprbasedata) , _T("Sphere")         );
5912         notebook->AddPage( CreateView(5,notebook,vtkmprbasedata) , _T("MPR 3D")         );
5913         notebook->AddPage( CreateView(6,notebook,vtkmprbasedata) , _T("Clipping")       );
5914         Connect(notebook->GetId()       , wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED  , (wxObjectEventFunction) &wxMPRWidget::OnPageAChanged   );
5915
5916         wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
5917         sizer->Add(notebook , 1, wxALL|wxGROW, 2);
5918         panel->SetAutoLayout(true);
5919         panel->SetSizer(sizer);
5920         panel->SetSize(400,400);
5921         panel->Layout();
5922
5923 //EEDxx2.4
5924 //      panel->FitInside();
5925
5926         panel->Refresh();
5927         return panel;
5928 }
5929
5930 //----------------------------------------------------------------------------
5931
5932 wxPanel* wxMPRWidget::CreateMPRPanel4View(wxWindow *parent, vtkMPRBaseData *vtkmprbasedata)
5933 {
5934         wxPanel *panel=new wxPanel(parent,-1);
5935
5936         // view 0
5937         _vtkmpr2Dview[0] = new wxVtkMPR2DView(panel,0);
5938         _vtkmpr2Dview[0]->SetVtkBaseData(vtkmprbasedata);
5939         wxVTKRenderWindowInteractor *iren0 = _vtkmpr2Dview[0]->GetWxVTKRenderWindowInteractor();        
5940
5941         // view 1
5942         _vtkmpr2Dview[1] = new wxVtkMPR2DView(panel,1);
5943         _vtkmpr2Dview[1]->SetVtkBaseData(vtkmprbasedata);
5944         wxVTKRenderWindowInteractor *iren1 = _vtkmpr2Dview[1]->GetWxVTKRenderWindowInteractor();        
5945
5946         // view 2
5947         _vtkmpr2Dview[2] = new wxVtkMPR2DView(panel,2);
5948         _vtkmpr2Dview[2]->SetVtkBaseData(vtkmprbasedata);
5949         wxVTKRenderWindowInteractor *iren2 = _vtkmpr2Dview[2]->GetWxVTKRenderWindowInteractor();        
5950
5951         // view 3
5952         wxNotebook *notebook = new wxNotebook( panel, -1 );
5953         notebook->SetSize(400,400);
5954
5955 // EED 27 Oct 2007
5956          // view 3.0
5957         _widgetMesure   = new wxWidgetMesure2D_Plane_in_MPR(notebook);
5958         _vtkplane2Dview = new vtkPlane2DView( _widgetMesure->GetWindow2() );
5959         _widgetMesure->SetVtkPlane2DView( _vtkplane2Dview );
5960         _vtkplane2Dview->SetImgSize( 200 );
5961         _vtkplane2Dview->SetVtkBaseData(vtkmprbasedata);
5962         notebook->AddPage( _widgetMesure, _T("Plane") );
5963
5964          // view 3.1
5965         _wxsphereview = new wxSphereView( notebook , vtkmprbasedata, vtkmprbasedata->GetImageData());
5966         wxVTKRenderWindowInteractor *iren3B = _wxsphereview->GetWxVTKRenderWindowInteractor();  
5967         notebook->AddPage( iren3B, _T("Sphere") );
5968
5969
5970          // view 3.2
5971         wxSplitterWindow *panelMPR3D    = new wxSplitterWindow( notebook , -1);
5972         _wxvtk3Dbaseview_MPRClipping3D  = new wxVtk3DBaseView( panelMPR3D );
5973
5974         _wxvtkmpr3Dview = new wxVtkMPR3DView( _wxvtk3Dbaseview_MPRClipping3D );
5975         vtkMPR3DDataViewer *vtkmpr3Ddataviewer = new vtkMPR3DDataViewer(); 
5976         vtkmpr3Ddataviewer->SetVtkMPRBaseData(vtkmprbasedata);
5977         vtkmpr3Ddataviewer->Configure();
5978         _wxvtkmpr3Dview->SetVtkMPR3DDataViewer(vtkmpr3Ddataviewer);
5979
5980
5981         _wxvtkclipping3Dview = new wxVtkClipping3DView( _wxvtk3Dbaseview_MPRClipping3D );
5982         vtkClipping3DDataViewer *vtkclipping3Ddataviewer = new vtkClipping3DDataViewer(); 
5983         vtkclipping3Ddataviewer->SetVtkMPRBaseData(vtkmprbasedata);
5984         vtkclipping3Ddataviewer->Configure();
5985         _wxvtkclipping3Dview->SetVtkClipping3DDataViewer(vtkclipping3Ddataviewer);
5986
5987
5988         wxWindow        *window3D                               = _wxvtk3Dbaseview_MPRClipping3D->GetWxVTKRenderWindowInteractor();
5989
5990         wxPanel         *panelControl                   = new wxPanel(panelMPR3D,-1);
5991         wxPanel         *controlPanelMPR3D              = _wxvtkmpr3Dview->CreateControlPanel(panelControl);
5992         wxPanel         *controlPanelClipping3D = _wxvtkclipping3Dview->CreateControlPanel(panelControl);
5993
5994
5995
5996
5997 //    wxBoxSizer         *sizerCtrol             = new wxBoxSizer(wxVERTICAL);
5998         wxFlexGridSizer  *sizerCtrol             = new wxFlexGridSizer(1);
5999         sizerCtrol->Add(controlPanelMPR3D               , 1, wxALL|wxEXPAND, 2);
6000         sizerCtrol->Add(controlPanelClipping3D  , 1, wxALL|wxEXPAND, 2);
6001
6002
6003         panelControl->SetAutoLayout(true);
6004         panelControl->SetSizer(sizerCtrol);
6005         panelControl->SetSize(400,150);
6006         panelControl->Layout();
6007
6008 //EEDxx2.4
6009         panelMPR3D      -> SetMinimumPaneSize( 5 );
6010
6011         panelMPR3D      -> SplitHorizontally( panelControl,window3D,200  );
6012
6013         notebook->AddPage( panelMPR3D, _T("MPR 3D - Clipping") );
6014
6015
6016         Connect(notebook->GetId()       , wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED  , (wxObjectEventFunction) &wxMPRWidget::OnPageBChanged   );
6017
6018         wxBoxSizer *sizerV = new wxBoxSizer(wxVERTICAL);
6019         wxBoxSizer *sizerH1= new wxBoxSizer(wxHORIZONTAL);
6020         wxBoxSizer *sizerH2= new wxBoxSizer(wxHORIZONTAL);
6021         sizerH1->Add(iren2 , 1, wxALL|wxEXPAND, 2);
6022         sizerH1->Add(iren0 , 1, wxALL|wxEXPAND, 2);
6023         sizerH2->Add(iren1 , 1, wxALL|wxEXPAND, 2);
6024 //      sizerH2->Add(iren3 , 1, wxALL|wxEXPAND, 2);
6025         sizerH2->Add(notebook , 1, wxALL|wxEXPAND, 2);
6026
6027         sizerV->Add(sizerH1, 1, wxALL|wxEXPAND, 0);
6028         sizerV->Add(sizerH2, 1, wxALL|wxEXPAND, 0);
6029
6030         panel->SetAutoLayout(true);
6031         panel->SetSizer(sizerV);
6032         panel->SetSize(400,400);
6033         panel->Layout();
6034         return panel;
6035 }
6036
6037 //----------------------------------------------------------------------------
6038 void wxMPRWidget::OnCutImagaData(wxCommandEvent &event) 
6039 {
6040         if (_btnCutImageData->GetValue()==true){                
6041        
6042                 _framePanelCutting = new wxFrame(this,-1,_T("Cutting Module"),wxDefaultPosition,wxDefaultSize,wxCAPTION|wxSTAY_ON_TOP| wxRESIZE_BORDER );
6043                 
6044                 _framePanelCutting->SetSize(550,400);
6045
6046                 _panelCutting   = new wxPanelCuttingImageData(_framePanelCutting);              
6047                 if(_wxvtk3Dbaseview_Clipping3D_BB!=NULL){
6048                         _panelCutting->SetWxVtk3DBaseView( _wxvtk3Dbaseview_Clipping3D_BB  );
6049                 }
6050                 _panelCutting->SetVtkMPRBaseData( GetVtkMPRBaseData() );
6051                 _panelCutting->SetVtkClipping3DDataViewer( this->_wxvtkclipping3Dview_BB->GetVtkClipping3DDataViewer() );
6052                 _panelCutting->Configure( );
6053 /*
6054                 wxBoxSizer *topsizer            = new wxBoxSizer(wxHORIZONTAL  );
6055                 topsizer -> Add( _panelCutting ,1,wxALL  ,0);
6056                 _framePanelCutting->SetAutoLayout(true);
6057                 _framePanelCutting->SetSizer( topsizer );      // use the sizer for layout
6058                 _framePanelCutting->Layout(); 
6059 //EEDxx2.4
6060 //              _framePanelCutting->FitInside();
6061 */
6062                 _framePanelCutting->Show();
6063
6064                 
6065         } else {
6066                 if (_framePanelCutting!=NULL){
6067                         _panelCutting->RemoveActors();                  
6068                         _framePanelCutting->Destroy();
6069                         _framePanelCutting=NULL;
6070                         _panelCutting=NULL;
6071                 }
6072         }
6073 }
6074
6075 //----------------------------------------------------------------------------
6076 void wxMPRWidget::ConfigureVTK(){
6077         int x=0,y=0,z=0;
6078
6079         if (_vtkmprbasedata!=NULL)
6080         {
6081                 _vtkmprbasedata->Configure();
6082                 x=_vtkmprbasedata                       ->      GetMaxPositionX()/2;
6083                 y=_vtkmprbasedata                       ->      GetMaxPositionY()/2;
6084                 z=_vtkmprbasedata                       ->      GetMaxPositionZ()/2;    
6085                 _vtkmprbasedata->SetX( x );
6086                 _vtkmprbasedata->SetY( y );
6087                 _vtkmprbasedata->SetZ( z );
6088         
6089         }
6090
6091         if(_vtkmpr2Dview[0]!=NULL) {_vtkmpr2Dview[0]                            ->      Configure();}
6092         if(_vtkmpr2Dview[1]!=NULL) {_vtkmpr2Dview[1]                            ->      Configure();}
6093         if(_vtkmpr2Dview[2]!=NULL) {_vtkmpr2Dview[2]                            ->      Configure();}
6094
6095
6096         if (_vtkmpr2Dview_B[0]!=NULL) { _vtkmpr2Dview_B[0]                              ->      Configure(); }
6097         if (_vtkmpr2Dview_B[1]!=NULL) { _vtkmpr2Dview_B[1]                              ->      Configure(); }
6098         if (_vtkmpr2Dview_B[2]!=NULL) { _vtkmpr2Dview_B[2]                              ->      Configure(); }
6099
6100
6101         
6102
6103         if (_vtkplane2Dview!=NULL){_vtkplane2Dview                              ->      Configure();}
6104         if (_widgetMesure!=NULL){_widgetMesure                                  ->      ConfigureA(_vtkplane2Dview);}
6105         if (_widgetMesure!=NULL){_widgetMesure                                  ->      SetActiveLink(true);}
6106         if (_widgetMesure!=NULL){_widgetMesure                                  ->      SetMesureScale( _voxelSize );}
6107         if (_wxsphereview!=NULL){_wxsphereview                                  ->      Configure();}
6108
6109         if (_wxvtk3Dbaseview_MPRClipping3D!=NULL){_wxvtk3Dbaseview_MPRClipping3D        ->  Configure();}
6110         if (_wxvtkmpr3Dview!=NULL){
6111                 _wxvtkmpr3Dview                                 ->      Configure();
6112         }
6113         if (_wxvtkclipping3Dview!=NULL){_wxvtkclipping3Dview            ->      Configure();}
6114
6115         if (_vtkplane2Dview_B!=NULL){   _vtkplane2Dview_B                       ->      Configure(); }
6116         if (_widgetMesure_B!=NULL){             _widgetMesure_B                         ->      ConfigureA( _vtkplane2Dview_B ); }
6117         if (_widgetMesure_B!=NULL){             _widgetMesure_B                         ->      SetActiveLink(true); }
6118
6119 //EEDx3
6120 //      double spc[3];
6121 //      vtkImageData *imageData = _vtkmprbasedata->GetImageData();
6122 //      imageData->Update();
6123 //      imageData->GetSpacing(spc);
6124 //      _widgetMesure_B->SetMesureScale(spc[0]);
6125
6126         if (_widgetMesure_B!=NULL)                                      {_widgetMesure_B->SetMesureScale( _voxelSize );}
6127
6128
6129         if (_wxsphereview_B!=NULL)                                      {_wxsphereview_B                                ->      Configure();}
6130
6131         if (_wxvtk3Dbaseview_MPR3D_B!=NULL)                     {_wxvtk3Dbaseview_MPR3D_B               ->  Configure();}
6132         if (_wxvtkmpr3Dview_B!=NULL)                            {_wxvtkmpr3Dview_B                              ->      Configure();}
6133
6134         if ( _wxvtk3Dbaseview_Clipping3D_BB!=NULL)      {_wxvtk3Dbaseview_Clipping3D_BB ->  Configure(); }
6135         if ( _wxvtkmpr3Dview_BB!=NULL)                          {_wxvtkmpr3Dview_BB                             ->      Configure(); }
6136         if ( _wxvtkclipping3Dview_BB!=NULL)                     {_wxvtkclipping3Dview_BB                ->      Configure(); }
6137
6138
6139         vtkInteractorStyle3DView *vtkinteractorstyle3Dview;
6140         if (_wxvtkmpr3Dview_BB!=NULL)
6141         {
6142                 vtkinteractorstyle3Dview        = new vtkInteractorStyle3DView();
6143                 vtkinteractorstyle3Dview->SetWxVtkMPR3DView(_wxvtkmpr3Dview_BB);
6144                 vtkinteractorstyle3Dview->SetWxVtkClipping3DView(_wxvtkclipping3Dview_BB);
6145         }
6146
6147         if (_wxvtk3Dbaseview_Clipping3D_BB!=NULL)
6148         {
6149                 _wxvtk3Dbaseview_Clipping3D_BB->GetInteractorStyleBaseView()->AddInteractorStyleMaracas( vtkinteractorstyle3Dview );
6150         }
6151         
6152 //EED 29Mars2009
6153 //      RefreshView(true);
6154         
6155 }
6156
6157 //----------------------------------------------------------------------------
6158
6159 void wxMPRWidget::OnRefreshView(wxCommandEvent & event)
6160 {
6161         RefreshView();
6162 }
6163 //----------------------------------------------------------------------------
6164 void wxMPRWidget::OnDClickLeft(wxCommandEvent & event)
6165 {
6166         if (_wxsphereview!=NULL) {
6167                 _wxsphereview   -> RefreshPoint();
6168         }
6169         if (_wxsphereview_B!=NULL) {
6170                 _wxsphereview_B -> RefreshPoint();
6171         }
6172 }
6173 //----------------------------------------------------------------------------
6174 void wxMPRWidget::RefreshView(bool firsttime){
6175
6176         if (_refreshAPage == 0 )
6177         {
6178
6179                 if ((_vtkmpr2Dview[0]!=NULL) && (_vtkmpr2Dview[1]!=NULL) && (_vtkmpr2Dview[2]!=NULL) )
6180                 {
6181                         _vtkmpr2Dview[2] -> Refresh();
6182                         _vtkmpr2Dview[1] -> Refresh();
6183                         _vtkmpr2Dview[0] -> Refresh();
6184
6185                         if (firsttime==false)
6186                         {
6187                                 _vtkmpr2Dview[2] -> RefreshView();
6188                                 _vtkmpr2Dview[1] -> RefreshView();
6189                                 _vtkmpr2Dview[0] -> RefreshView();
6190                         }
6191
6192                         if (_refreshBPage == 0 )
6193                         {
6194                                 if (_vtkplane2Dview!=NULL)
6195                                 {
6196                                         _vtkplane2Dview -> Refresh();           
6197                                         if (firsttime==false)
6198                                         {
6199                                                 _vtkplane2Dview -> RefreshView();
6200                                         }
6201 //                                      _wxvtk3Dbaseview_MPR3D_B -> Refresh();
6202                                 }
6203                         }
6204                         if (_refreshBPage == 1 )
6205                         {
6206                                 //sphere
6207                         }
6208                         if (_refreshBPage == 2 )
6209                         {
6210                                 if ((_wxvtkmpr3Dview!=NULL)  && (_wxvtk3Dbaseview_MPRClipping3D!=NULL) && (_wxvtkclipping3Dview!=NULL) )
6211                                 {
6212                                         _wxvtkmpr3Dview                 -> RefreshView();
6213                                         _wxvtk3Dbaseview_MPRClipping3D  -> Refresh();
6214                                         _wxvtkclipping3Dview            -> Refresh();
6215                                 }
6216                         }
6217                 }
6218         }
6219
6220         if (_refreshAPage == 1 )
6221         {
6222                 if (_vtkmpr2Dview_B[0] !=NULL){
6223                         _vtkmpr2Dview_B[0] -> Refresh();
6224                 }
6225         }
6226         if (_refreshAPage == 2 )
6227         {
6228                 if (_vtkmpr2Dview_B[1] !=NULL){
6229                         _vtkmpr2Dview_B[1] -> Refresh();
6230                 }
6231         }
6232         if (_refreshAPage == 3 )
6233         {
6234                 if (_vtkmpr2Dview_B[2] !=NULL){
6235                         _vtkmpr2Dview_B[2] -> Refresh();
6236                 }
6237         }
6238         if (_refreshAPage == 4 )
6239         {
6240                 if (_vtkplane2Dview_B!=NULL){
6241                         _vtkplane2Dview_B -> Refresh();
6242                         if (firsttime==false)
6243                         {
6244                                 _vtkplane2Dview_B -> RefreshView();
6245                         }
6246                 }
6247         }
6248
6249         if (_refreshAPage == 5 )
6250         {
6251                 // sphere
6252         }
6253         if (_refreshAPage == 6 )
6254         {
6255                 if (_wxvtkmpr3Dview_B!=NULL){
6256                         _wxvtkmpr3Dview_B               -> Refresh();
6257                         _wxvtk3Dbaseview_MPR3D_B        -> Refresh();
6258                 }
6259         }
6260         if (_refreshAPage == 7 )
6261         {
6262                 if (_wxvtkmpr3Dview_BB!=NULL){
6263                         _wxvtkmpr3Dview_BB              -> RefreshView();
6264                         _wxvtkclipping3Dview_BB         -> Refresh();
6265                         _wxvtk3Dbaseview_Clipping3D_BB  -> Refresh();
6266                         if (_panelCutting!=NULL)
6267                         {
6268                                 _panelCutting->RefreshView();
6269                         }
6270                 }
6271         }
6272
6273 }
6274 //----------------------------------------------------------------------------
6275 vtkMPRBaseData  *wxMPRWidget::GetVtkMPRBaseData(){      
6276         return _vtkmprbasedata;
6277 }
6278 //----------------------------------------------------------------------------
6279 vtkPlane2DView *wxMPRWidget::GetVtkPlane2DView()
6280 {
6281         return _vtkplane2Dview;
6282 }
6283 //----------------------------------------------------------------------------
6284 wxVtkMPR3DView  *wxMPRWidget::GetWxvtkmpr3Dview_BB()
6285 {
6286         return _wxvtkmpr3Dview_BB;
6287 }
6288 //----------------------------------------------------------------------------
6289 wxVtkBaseView *wxMPRWidget::GetWxVtkBaseView(int page, int id)
6290 {
6291         wxVtkBaseView *result=NULL;
6292         if (page==0)
6293         {       
6294                 if ((id>=0) &&(id<=3)){
6295                         result=_vtkmpr2Dview[id];
6296                 }
6297                 if (id==3)
6298                 {
6299                         result=_vtkplane2Dview;
6300                 }
6301         }
6302         return result;
6303 }
6304 //----------------------------------------------------------------------------
6305 wxVtkMPR2DView *wxMPRWidget::GetWxvtkMPR2Dview(int direction)
6306 {
6307         return _vtkmpr2Dview[direction];
6308 }
6309
6310 //----------------------------------------------------------------------------
6311 //----------------------------------------------------------------------------
6312 //----------------------------------------------------------------------------
6313 wxMPRWidget2::wxMPRWidget2(wxWindow* parent,marImageData *marimagedata,double voxelSize)
6314 : wxMPRWidget(parent,marimagedata,voxelSize)
6315 {
6316 }
6317 //----------------------------------------------------------------------------
6318 wxMPRWidget2::~wxMPRWidget2()
6319 {
6320 }
6321 //----------------------------------------------------------------------------
6322 void wxMPRWidget2::OnRefreshView(wxCommandEvent & event) // Virtual
6323 {       
6324         wxCommandEvent newevent1(wxEVT_COMMAND_MENU_SELECTED,12121);  // Refresh
6325     this->GetParent()->ProcessEvent(newevent1);
6326 }
6327
6328
6329 //----------------------------------------------------------------------------
6330 //----------------------------------------------------------------------------
6331 //----------------------------------------------------------------------------
6332 figureCuttingModel::figureCuttingModel()
6333 {
6334         _inversModel    = vtkTransform::New();
6335         _matrixModel    = vtkTransform::New();
6336         _matrixVisual   = vtkTransform::New();
6337
6338         _spcX=1;
6339         _spcY=1;
6340         _spcZ=1;
6341 }
6342 //----------------------------------------------------------------------------
6343 figureCuttingModel::~figureCuttingModel() // virtual
6344 {
6345         _inversModel->Delete();
6346 }
6347 //----------------------------------------------------------------------------
6348 void figureCuttingModel::SetPosition(double x,double y, double z)
6349 {
6350         _px=x;
6351         _py=y;
6352         _pz=z;
6353 }
6354 //----------------------------------------------------------------------------
6355 void figureCuttingModel::SetScale(double sx,double sy, double sz)
6356 {
6357         _sx=sx;
6358         _sy=sy;
6359         _sz=sz;
6360 }
6361 //----------------------------------------------------------------------------
6362 void figureCuttingModel::SetRotation(double alfa,double beta, double teta)
6363 {
6364         _alfa=alfa;
6365         _beta=beta;
6366         _teta=teta;
6367 }
6368
6369 //----------------------------------------------------------------------------
6370 void figureCuttingModel::CalculeMatrix()
6371 {
6372         _matrixModel->Identity();
6373         _matrixModel->Translate(_px,_py,_pz);
6374         _matrixModel->RotateY(_beta);
6375         _matrixModel->RotateX(_alfa);
6376         _matrixModel->RotateY(_teta);
6377         _matrixModel->Scale(_sx,_sy,_sz);
6378
6379         _matrixVisual->Identity();
6380         _matrixVisual->Translate( _px*_spcX  ,  _py*_spcY  ,  _pz*_spcZ  );
6381         _matrixVisual->RotateY(_beta);
6382         _matrixVisual->RotateX(_alfa);
6383         _matrixVisual->RotateY(_teta);
6384         _matrixVisual->Scale( _sx*_spcX  ,  _sy*_spcY  ,  _sz*_spcZ  );
6385
6386 }
6387
6388
6389 //----------------------------------------------------------------------------
6390 void figureCuttingModel::CalculeInversMatrix()
6391 {
6392         _inversModel->Identity ();
6393         _inversModel->Concatenate ( _matrixModel );
6394         _inversModel->Inverse();
6395 }
6396 //----------------------------------------------------------------------------
6397 bool figureCuttingModel::IfPointInside(double x, double y, double z) // virtual
6398 {
6399         return true;
6400 }
6401
6402 //----------------------------------------------------------------------------
6403 vtkTransform *figureCuttingModel::GetVtkTransform()
6404 {
6405         return _matrixVisual;
6406 }
6407
6408 //----------------------------------------------------------------------------
6409 //void figureCuttingModel::SetVtkTransform(vtkTransform *matrix)
6410 //{
6411 //      _matrixModel = matrix;
6412 //}
6413
6414 //----------------------------------------------------------------------------
6415 double figureCuttingModel::GetTheoricVolume() // virtual
6416 {
6417         return 0;
6418 }
6419
6420 //----------------------------------------------------------------------------
6421 double figureCuttingModel::GetPositionX()
6422 {
6423         return _px;
6424 }
6425 //----------------------------------------------------------------------------
6426 double figureCuttingModel::GetPositionY()
6427 {
6428         return _py;
6429 }
6430 //----------------------------------------------------------------------------
6431 double figureCuttingModel::GetPositionZ()
6432 {
6433         return _pz;
6434 }
6435 //----------------------------------------------------------------------------
6436 double figureCuttingModel::GetScaleX()
6437 {
6438         return _sx;
6439 }
6440 //----------------------------------------------------------------------------
6441 double figureCuttingModel::GetScaleY()
6442 {
6443         return _sy;
6444 }
6445 //----------------------------------------------------------------------------
6446 double figureCuttingModel::GetScaleZ()
6447 {
6448         return _sz;
6449 }
6450 //----------------------------------------------------------------------------
6451 double figureCuttingModel::GetAngleAlfa()
6452 {
6453         return _alfa;
6454 }
6455 //----------------------------------------------------------------------------
6456 double figureCuttingModel::GetAngleBeta()
6457 {
6458         return _beta;
6459 }
6460 //----------------------------------------------------------------------------
6461 double figureCuttingModel::GetAngleTeta()
6462 {
6463         return _teta;
6464 }
6465 //----------------------------------------------------------------------------
6466 char *figureCuttingModel::GetName() // virtual
6467 {
6468         return "--";
6469 }
6470
6471 //----------------------------------------------------------------------------
6472 void figureCuttingModel::SetSpacing(double spcX,double spcY, double spcZ)
6473 {
6474         _spcX = spcX;
6475         _spcY = spcY;
6476         _spcZ = spcZ;
6477 }
6478
6479 //----------------------------------------------------------------------------
6480
6481
6482 //----------------------------------------------------------------------------
6483 //----------------------------------------------------------------------------
6484 //----------------------------------------------------------------------------
6485 figureCuttingSphereModel::figureCuttingSphereModel()
6486 {
6487 }
6488 //----------------------------------------------------------------------------
6489 figureCuttingSphereModel::~figureCuttingSphereModel() // virtual
6490 {
6491 }
6492 //----------------------------------------------------------------------------
6493 bool figureCuttingSphereModel::IfPointInside(double x, double y, double z) // virtual
6494 {
6495         double in[4],out[4];
6496         in[0]=x;
6497         in[1]=y;
6498         in[2]=z;
6499         in[3]=1;
6500         _inversModel->MultiplyPoint (in, out);
6501
6502         bool result=false;
6503         if (sqrt( out[0]*out[0] + out[1]*out[1] + out[2]*out[2] )<0.5 )
6504         {
6505                 result=true;
6506         }
6507         return result;
6508 }
6509 //----------------------------------------------------------------------------
6510 double figureCuttingSphereModel::GetTheoricVolume() // virtual
6511 {
6512         double piTMP=3.14159265;
6513         return (4.0/3.0) * piTMP * (_sx/2)*(_sy/2)*(_sz/2);
6514 }
6515 //----------------------------------------------------------------------------
6516 char *figureCuttingSphereModel::GetName() // virtual
6517 {
6518         return "Sphere";
6519 }
6520
6521
6522 //----------------------------------------------------------------------------
6523 //----------------------------------------------------------------------------
6524 //----------------------------------------------------------------------------
6525 figureCuttingCubeModel::figureCuttingCubeModel()
6526 {
6527 }
6528 //----------------------------------------------------------------------------
6529 figureCuttingCubeModel::~figureCuttingCubeModel()  // virtual
6530 {
6531 }
6532 //----------------------------------------------------------------------------
6533 bool figureCuttingCubeModel::IfPointInside(double x, double y, double z) // virtual
6534 {
6535         double in[4],out[4];
6536         in[0]=x;
6537         in[1]=y;
6538         in[2]=z;
6539         in[3]=1;
6540         _inversModel->MultiplyPoint (in, out);
6541
6542         bool result=false;
6543         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)  )
6544         {
6545                 result=true;
6546         }
6547         return result;
6548 }
6549 //----------------------------------------------------------------------------
6550 double figureCuttingCubeModel::GetTheoricVolume() // virtual
6551 {
6552         return _sx * _sy * _sz;
6553 }
6554
6555 //----------------------------------------------------------------------------
6556 char *figureCuttingCubeModel::GetName() // virtual
6557 {
6558         return "Cube";
6559 }
6560
6561 //----------------------------------------------------------------------------
6562 //----------------------------------------------------------------------------
6563 //----------------------------------------------------------------------------
6564
6565 figureCuttingCylinderModel::figureCuttingCylinderModel()
6566 {
6567 }
6568 //----------------------------------------------------------------------------
6569 figureCuttingCylinderModel::~figureCuttingCylinderModel()  // virtual
6570 {
6571 }
6572 //----------------------------------------------------------------------------
6573 bool figureCuttingCylinderModel::IfPointInside(double x, double y, double z) // virtual
6574 {
6575         double in[4],out[4];
6576         in[0]=x;
6577         in[1]=y;
6578         in[2]=z;
6579         in[3]=1;
6580         _inversModel->MultiplyPoint (in, out);
6581
6582         bool result=false;
6583         if ((sqrt( out[0]*out[0] + out[2]*out[2] )<0.5 )  && (out[1]>-0.5) && (out[1]<0.5)  )
6584         {
6585                 result=true;
6586         }
6587         return result;
6588 }
6589 //----------------------------------------------------------------------------
6590 double figureCuttingCylinderModel::GetTheoricVolume() // virtual
6591 {
6592         double piTMP=3.14159265;
6593         return piTMP*(_sx/2)*(_sz/2)*_sy;
6594 }
6595 //----------------------------------------------------------------------------
6596 char *figureCuttingCylinderModel::GetName() // virtual
6597 {
6598         return "Cylinder";
6599 }
6600 //----------------------------------------------------------------------------
6601
6602
6603
6604 // EOF - wxMPRWidget.cxx
6605
6606
6607
6608