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