]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/manualContour.cpp
compila
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / manualContour.cpp
1
2 #include <vtkActor.h> 
3 #include <vtkProperty.h>
4
5 #include <vtkCellArray.h>
6 #include <vtkRenderer.h>
7 #include <vtkCoordinate.h>
8 #include <vtkTextProperty.h>
9 #include <vtkTextActor.h>
10 #include <vtkProperty2D.h>
11 #include <vtkPointPicker.h>
12 #include "widgets/UtilVtk3DGeometriSelection.h"
13
14
15 #include "manualContour.h"
16
17
18 // ----------------------------------------------------------------------------
19 // ----------------------------------------------------------------------------
20 // ----------------------------------------------------------------------------
21
22 manualPoint::manualPoint(){
23 }
24 // ----------------------------------------------------------------------------
25 manualPoint::~manualPoint(){
26 }
27 // ----------------------------------------------------------------------------
28 void manualPoint::SetPoint(double x,double y,double z){
29         _x=x;
30         _y=y;
31         _z=z;
32 }
33 // ----------------------------------------------------------------------------
34 void manualPoint::SetPointX(double x){
35         _x=x;
36 }
37 // ----------------------------------------------------------------------------
38 void manualPoint::SetPointY(double y){
39         _y=y;
40 }
41 // ----------------------------------------------------------------------------
42 void manualPoint::SetPointZ(double z){
43         _z=z;
44 }
45 // ----------------------------------------------------------------------------
46 double manualPoint::GetX(){
47         return _x;
48 }
49 // ----------------------------------------------------------------------------
50 double manualPoint::GetY(){
51         return _y;
52 }
53 // ----------------------------------------------------------------------------
54 double manualPoint::GetZ(){
55         return _z;
56 }
57 // ----------------------------------------------------------------------------
58 manualPoint * manualPoint :: Clone()
59 {
60         manualPoint * clone = new manualPoint();
61         clone->SetPoint( GetX(), GetY(), GetZ());
62         return clone;
63 }
64
65
66 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
68 // ----------------------------------------------------------------------------
69
70 manualContourModelCircle::manualContourModelCircle()
71 : manualContourModel()
72 {
73 }
74
75 manualContourModelCircle::~manualContourModelCircle()
76 {
77 }
78
79
80 // ----------------------------------------------------------------------------
81 manualContourModelCircle * manualContourModelCircle :: Clone()  // virtual 
82 {
83         manualContourModelCircle * clone = new manualContourModelCircle();
84         CopyAttributesTo(clone);
85         return clone;
86 }
87
88 // ---------------------------------------------------------------------------
89
90 void manualContourModelCircle::CopyAttributesTo( manualContourModelCircle * cloneObject)
91 {
92         // Fathers object
93         manualContourModel::CopyAttributesTo(cloneObject);
94 }
95
96 //----------------------------------------------------------------
97 int manualContourModelCircle::GetTypeModel() //virtual 
98 {
99         return 3;
100 }
101
102 //----------------------------------------------------------------
103 void manualContourModelCircle::GetSpline_i_Point(int i, double *x, double *y, double *z) // virtal
104 {
105         double angle = _deltaAngle*i;
106         *x = _radio*cos(angle) + _centerX;
107         *y = _radio*sin(angle) + _centerY;
108         *z = _centerZ;
109 }
110
111 //
112 // ---------------------------------------------------------------------------
113 void manualContourModelCircle::UpdateSpline() // virtal
114 {
115         manualPoint     *mpA,*mpB;
116         double difX,difY;
117     int np      = GetSizeLstPoints( );
118         int nps = GetNumberOfPointsSpline();
119         _deltaAngle=(3.14159265*2)/(nps-1);
120
121         if (np==2){
122                 mpA                     = GetManualPoint(0);
123                 mpB                     = GetManualPoint(1);
124                 difX            = mpA->GetX() - mpB->GetX();
125                 difY            = mpA->GetY() - mpB->GetY();
126                 _radio          = sqrt( difX*difX + difY*difY );
127                 _centerX        = mpA->GetX();
128                 _centerY        = mpA->GetY();
129                 _centerZ        = mpA->GetZ();
130         } else {
131                 _radio          = -1;
132                 _centerX        = -1;
133                 _centerY        = -1;
134                 _centerZ        = -1;
135         }
136 }
137
138
139 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
141 // ----------------------------------------------------------------------------
142 manualContourModelBullEye::manualContourModelBullEye()
143 : manualContourModel()
144 {
145         _numberPointsSlineBySector=101;   // impaire
146 }
147
148 manualContourModelBullEye::~manualContourModelBullEye()
149 {
150 }
151
152
153 // ----------------------------------------------------------------------------
154 manualContourModelBullEye * manualContourModelBullEye :: Clone()  // virtual 
155 {
156         manualContourModelBullEye * clone = new manualContourModelBullEye();
157         CopyAttributesTo(clone);
158         return clone;
159 }
160
161 // ---------------------------------------------------------------------------
162
163 void manualContourModelBullEye::CopyAttributesTo( manualContourModelBullEye * cloneObject)
164 {
165         // Fathers object
166         manualContourModel::CopyAttributesTo(cloneObject);
167 }
168
169 //----------------------------------------------------------------
170 int manualContourModelBullEye::GetTypeModel() //virtual 
171 {
172         return 4;
173 }
174
175 //----------------------------------------------------------------
176 int     manualContourModelBullEye::GetNumberOfPointsSplineSectorBulleEje()
177 {
178         return _numberPointsSlineBySector;
179 }
180
181 //----------------------------------------------------------------
182 void manualContourModelBullEye::SetNumberOfPointsSplineSectorBulleEje(int numpoints)
183 {
184         this->_numberPointsSlineBySector = numpoints;
185 }
186
187 //----------------------------------------------------------------
188 void manualContourModelBullEye::AddSector(      double radioA,
189                                                 double radioB,
190                                                 double ang,
191                                                 double angDelta)
192 {
193         manualContourModelBullEyeSector *modelSector = new manualContourModelBullEyeSector();
194         modelSector->SetSector(radioA,radioB,ang,angDelta);
195         modelSector->SetNumberOfPointsSpline( this->GetNumberOfPointsSplineSectorBulleEje() );
196         _lstModelBullEyeSector.push_back(modelSector);
197 }
198
199 //----------------------------------------------------------------
200 manualContourModelBullEyeSector * manualContourModelBullEye::GetModelSector(int id)
201 {
202         return _lstModelBullEyeSector[id];
203 }
204
205 //----------------------------------------------------------------
206 void manualContourModelBullEye::GetSector(int id,       
207                                                 double *radioA,
208                                                 double *radioB,
209                                                 double *ang,
210                                                 double *angDelta)
211 {
212         _lstModelBullEyeSector[id]->GetSector(radioA,radioB,ang,angDelta);
213 }
214
215 void manualContourModelBullEye::UpdateSpline() // virtual
216 {
217         manualContourModel::UpdateSpline();
218
219         if (this->GetSizeLstPoints()>2){
220                 double cx,cy;
221                 double ww,hh;
222                 manualPoint *mpA = GetManualPoint(0);
223                 manualPoint *mpB = GetManualPoint(2);
224                 cx = (mpA->GetX() + mpB->GetX()) / 2.0;
225                 cy = (mpA->GetY() + mpB->GetY()) / 2.0;
226                 ww = fabs( mpA->GetX() - mpB->GetX() )/2.0;
227                 hh = fabs( mpA->GetY() - mpB->GetY() )/2.0;
228                 int i,size = _lstModelBullEyeSector.size();
229                 for (i=0;i<size;i++)
230                 {
231                         _lstModelBullEyeSector[i]->SetCenter(cx,cy);
232                         _lstModelBullEyeSector[i]->SetSize(ww,hh);
233                 } // for
234         }
235 }
236
237
238 //----------------------------------------------------------------
239 void manualContourModelBullEye::ResetSectors()
240 {
241         int i,size=_lstModelBullEyeSector.size();
242         for (i=0;i<size;i++)
243         {
244                 delete _lstModelBullEyeSector[i];
245         }
246         _lstModelBullEyeSector.clear();
247 }
248
249 //----------------------------------------------------------------
250 int manualContourModelBullEye::GetSizeOfSectorLst()
251 {
252         return _lstModelBullEyeSector.size();
253 }
254
255 //----------------------------------------------------------------
256 void manualContourModelBullEye::Save(FILE *ff) // virtual
257 {
258         manualContourModel::Save(ff); 
259         int i,size = GetSizeOfSectorLst();
260         fprintf(ff,"numberOfSections %d \n",size);
261         for ( i=0 ; i<size ; i++ )
262         {
263                 _lstModelBullEyeSector[i]->Save(ff);
264         }
265 }
266
267 //----------------------------------------------------------------
268 void manualContourModelBullEye::Open(FILE *ff) // virtual
269 {
270         manualContourModel::Open(ff); 
271
272         ResetSectors();
273
274         char tmp[255];
275         int i;
276         int numberOfSections;
277 //      double radioA,radioB,ang,deltaAng;
278
279         fscanf(ff,"%s",tmp); // NumberOfSections
280         fscanf(ff,"%s",tmp); // ##
281         numberOfSections = atoi(tmp);  
282         for (i=0;i<numberOfSections;i++)
283         {
284                 AddSector(0,1,90,0);
285                 _lstModelBullEyeSector[i]->Open(ff);
286         }
287
288 }
289
290 // ----------------------------------------------------------------------------
291 std::vector<manualContourModel*> manualContourModelBullEye::ExploseModel(  )
292 {
293 //EED004
294         std::vector<manualContourModel*> lstTmp;
295         int i,iSize=_lstModelBullEyeSector.size();
296         for (i=0;i<iSize;i++)
297         {
298                 lstTmp.push_back( _lstModelBullEyeSector[i] );
299         }
300         return lstTmp;
301 }
302
303
304 // ----------------------------------------------------------------------------
305 // ----------------------------------------------------------------------------
306 // ----------------------------------------------------------------------------
307 manualContourModelBullEyeSector::manualContourModelBullEyeSector()
308 : manualContourModel()
309 {
310 }
311
312 manualContourModelBullEyeSector::~manualContourModelBullEyeSector()
313 {
314 }
315
316
317 // ----------------------------------------------------------------------------
318 manualContourModelBullEyeSector * manualContourModelBullEyeSector :: Clone()  // virtual 
319 {
320         manualContourModelBullEyeSector * clone = new manualContourModelBullEyeSector();
321         CopyAttributesTo(clone);
322         return clone;
323 }
324
325 // ---------------------------------------------------------------------------
326
327 void manualContourModelBullEyeSector::CopyAttributesTo( manualContourModelBullEyeSector * cloneObject)
328 {
329         // Fathers object
330         manualContourModel::CopyAttributesTo(cloneObject);
331 }
332
333 //----------------------------------------------------------------
334 int manualContourModelBullEyeSector::GetTypeModel() //virtual 
335 {
336         return 5;
337 }
338
339
340 //----------------------------------------------------------------
341 void manualContourModelBullEyeSector::SetSector(        double radioA,
342                                                 double radioB,
343                                                 double ang,
344                                                 double angDelta)
345 {
346         _radioA         = radioA;
347         _radioB         = radioB;
348         _ang            = ang*3.14159265/180.0;
349         _angDelta       = angDelta*3.14159265/180.0;
350 }
351
352 //----------------------------------------------------------------
353 void manualContourModelBullEyeSector::GetSector(        
354                                                 double *radioA,
355                                                 double *radioB,
356                                                 double *ang,
357                                                 double *angDelta)
358 {
359         *radioA         = _radioA;
360         *radioB         = _radioB;
361         *ang            = _ang;
362         *angDelta       = _angDelta;
363 }
364
365 // ----------------------------------------------------------------------------
366 void manualContourModelBullEyeSector::SetCenter(double cx,double cy)
367 {
368         _cx = cx;
369         _cy = cy;
370 }
371
372 //----------------------------------------------------------------
373 void manualContourModelBullEyeSector::SetSize(double ww,double hh)
374 {
375         _ww = ww;
376         _hh = hh;
377 }
378
379 //----------------------------------------------------------------
380 void manualContourModelBullEyeSector::GetSpline_i_Point(int i, double *x, double *y, double *z)
381 {
382 //EED004
383
384         int ii,nps;
385 //      double x,y,z;
386         double ang,angcos, angsin;
387         double radio;
388
389         nps     =  GetNumberOfPointsSpline() - 3;
390
391         if (i==GetNumberOfPointsSpline()-1)
392         {
393                 i=0;
394         }
395
396         if (i<=nps/2)
397         {
398                 ii=i;
399                 radio=_radioA;
400         } else {
401                 ii=nps-i+1;
402                 radio=_radioB;
403         }
404         ang = ((double)ii/(nps/2))*_angDelta + _ang;
405         angcos =  cos(ang);
406         angsin =  sin(ang);
407
408         *x = _ww*radio*angcos + _cx;
409         *y = _hh*radio*angsin + _cy;
410         *z= -900;
411 }
412
413 //----------------------------------------------------------------
414 void manualContourModelBullEyeSector::Save(FILE *ff) // virtual
415 {
416         manualContourModel::Save(ff); 
417         fprintf(ff,"rA= %f rB= %f ang= %f deltaAng= %f\n", _radioA,_radioB, _ang , _angDelta);
418 }
419
420 //----------------------------------------------------------------
421 void manualContourModelBullEyeSector::Open(FILE *ff) // virtual
422 {
423         char tmp[255];
424         fscanf(ff,"%s",tmp); // TypeModel
425         fscanf(ff,"%s",tmp); // ##
426
427         manualContourModel::Open(ff); 
428
429
430         fscanf(ff,"%s",tmp); // radioA=
431         fscanf(ff,"%s",tmp); // radioA
432         _radioA = atof(tmp);  
433
434         fscanf(ff,"%s",tmp); // radioB=
435         fscanf(ff,"%s",tmp); // radioB
436         _radioB = atof(tmp);  
437
438         fscanf(ff,"%s",tmp); // ang=
439         fscanf(ff,"%s",tmp); // ang
440         _ang = atof(tmp);  
441
442         fscanf(ff,"%s",tmp); // deltaAng=
443         fscanf(ff,"%s",tmp); // deltaAng
444         _angDelta = atof(tmp);  
445 }
446
447
448
449 // ---------------------------------------------------------------------------
450 // ---------------------------------------------------------------------------
451 // ---------------------------------------------------------------------------
452 // ---------------------------------------------------------------------------
453
454 //JSTG 25-02-08 --------------------------------------------------
455 manualContourModelRoi::manualContourModelRoi()
456 : manualContourModel()
457 {
458         SetNumberOfPointsSpline(5);
459 }
460
461 manualContourModelRoi::~manualContourModelRoi()
462 {
463 }
464
465
466 // ----------------------------------------------------------------------------
467 manualContourModelRoi * manualContourModelRoi :: Clone()  // virtual 
468 {
469         manualContourModelRoi * clone = new manualContourModelRoi();
470         CopyAttributesTo(clone);
471         return clone;
472 }
473
474 // ---------------------------------------------------------------------------
475
476 void manualContourModelRoi::CopyAttributesTo( manualContourModelRoi * cloneObject)
477 {
478         // Fathers object
479         manualContourModel::CopyAttributesTo(cloneObject);
480 }
481
482 //----------------------------------------------------------------
483 int manualContourModelRoi::GetTypeModel() //virtual 
484 {
485         return 2;
486 }
487
488 //----------------------------------------------------------------
489
490
491 // ----------------------------------------------------------------------------
492 // ----------------------------------------------------------------------------
493 // ----------------------------------------------------------------------------
494
495 manualContourModel::manualContourModel()
496 {
497     _cntSplineX = vtkKochanekSpline::New( );
498     _cntSplineY = vtkKochanekSpline::New( );
499     _cntSplineZ = vtkKochanekSpline::New( );
500
501         this->SetCloseContour(true);
502
503     _cntSplineX->SetDefaultTension( 0 ); 
504         _cntSplineX->SetDefaultBias( 0 ); 
505         _cntSplineX->SetDefaultContinuity( 0 ); 
506
507     _cntSplineY->SetDefaultTension( 0 ); 
508         _cntSplineY->SetDefaultBias( 0 ); 
509         _cntSplineY->SetDefaultContinuity( 0 );
510
511     _cntSplineZ->SetDefaultTension( 0 ); 
512         _cntSplineZ->SetDefaultBias( 0 ); 
513         _cntSplineZ->SetDefaultContinuity( 0 );
514
515 //JSTG 25-02-08 -------------------------------------------------------------------------------------------------
516
517         // this parameter is reset in the  VIRTUAL manualContourBaseControler::Configure
518         _sizePointsContour      = 100;                  //JSTG 25-02-08 The change in the inisialization of these variable is critical.
519
520         _delta_JSTG                     = 0.0;
521 //---------------------------------------------------------------------------------------------------------------
522 }
523
524 // ----------------------------------------------------------------------------
525 manualContourModel::~manualContourModel()
526 {
527         int i,size=_lstPoints.size();
528         for (i=0;i<size; i++){
529                 delete _lstPoints[i];
530         }
531         _lstPoints.clear();
532
533         _cntSplineX->Delete();
534         _cntSplineY->Delete();
535         _cntSplineZ->Delete();
536 }
537 // ----------------------------------------------------------------------------
538 int manualContourModel::AddPoint(double x,double y,double z)
539 {
540    manualPoint *mp = new manualPoint();
541    mp->SetPoint(x,y,z);
542    AddManualPoint(mp);
543    //UpdateSpline();
544
545    return _lstPoints.size()-1;
546 }
547 // ----------------------------------------------------------------------------
548 int manualContourModel::InsertPoint(double x,double y,double z)
549 {
550         double dd,ddmin=9999999;
551         int    ibak=0;
552         double xx,x1,x2;
553         double yy,y1,y2;
554         double zz,z1,z2;
555         int i,ii,iii,size=_lstPoints.size();
556         double j,MaxDivisions=20,porcentage;
557         int sizeB=size;
558
559         if (_closeContour==false)
560         {
561                 size=size-1;
562         }
563
564         double jbak;
565
566         for ( i=0 ; i<size ; i++ )
567         {
568                 ii=i % sizeB ;
569                 iii=(i+1) % sizeB;
570                 x1=_lstPoints[ii]->GetX();
571                 y1=_lstPoints[ii]->GetY();
572                 z1=_lstPoints[ii]->GetZ();
573                 x2=_lstPoints[iii]->GetX();
574                 y2=_lstPoints[iii]->GetY();
575                 z2=_lstPoints[iii]->GetZ();
576                 for (j=0; j<=MaxDivisions; j++)
577                 {
578                         porcentage=(j/MaxDivisions);
579                         xx=(x2-x1)*porcentage+x1;
580                         yy=(y2-y1)*porcentage+y1;
581                         zz=(z2-z1)*porcentage+z1;
582                         dd=sqrt( (xx-x)*(xx-x) + (yy-y)*(yy-y) + (zz-z)*(zz-z) );
583                         if ( dd<ddmin )
584                         {
585                                 ddmin=dd;
586                                 ibak=iii;
587                                 jbak=j;
588                         }
589                 }
590         }
591
592         if (_closeContour==false)
593         {
594                 if ( (ibak==1) && (jbak==0) )
595                 {
596                         ibak=0;
597                 }
598                 if ( ( ibak==size ) && ( jbak==MaxDivisions ) )
599                 {
600                         ibak=sizeB;
601                 }
602         }
603
604
605 //JSTG - 25-04-08 ----------------------------------------------------------
606         //manualPoint *mp = new manualPoint();
607         //mp->SetPoint(x,y,z);
608         //std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + ibak;
609         //_lstPoints.insert(itNum,mp);  
610         InsertPoint_id(ibak,x,y,z);
611 //----------------------------------------------------------------------------
612
613         return ibak;
614 }
615 // ----------------------------------------------------------------------------
616 void manualContourModel::InsertPoint_id(int id, double x, double y, double z)
617 {
618         manualPoint *mp = new manualPoint();
619         mp->SetPoint(x,y,z);
620         std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + id;
621         _lstPoints.insert(itNum,mp);
622 }
623 // ----------------------------------------------------------------------------
624
625 void manualContourModel::DeletePoint(int i)
626 {
627         std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + i;
628    _lstPoints.erase(itNum);
629 }
630 // ----------------------------------------------------------------------------
631 void manualContourModel::DeleteAllPoints()
632 {
633         int i,size=_lstPoints.size();
634         for (i=0;i<size;i++){
635            _lstPoints.erase( _lstPoints.begin() );
636         }
637         this->UpdateSpline();
638 }
639 // ----------------------------------------------------------------------------
640
641 void manualContourModel::MovePoint(int i,double dx,double dy,double dz)
642 {
643         manualPoint *mp=_lstPoints[i];
644         double x=mp->GetX()+dx;
645         double y=mp->GetY()+dy;
646         double z=mp->GetZ()+dz;
647         mp->SetPoint(x,y,z);
648 }
649 // ----------------------------------------------------------------------------
650 void manualContourModel::MoveLstPoints(double dx,double dy,double dz)
651 {
652         // ToDo
653 }
654 // ----------------------------------------------------------------------------
655 void manualContourModel::MoveAllPoints(double dx,double dy,double dz)
656 {
657         int i,size=_lstPoints.size();
658         for (i=0;i<size;i++){
659                 MovePoint(i,dx,dy,dz);
660         }
661 }
662
663
664 // ----------------------------------------------------------------------------
665
666 // type=-1  x,y,z
667 // type=0       x,y
668 // type=1       y,z
669 // type=2       x,z
670 int      manualContourModel::GetIdPoint(double x, double y, double z, int i_range,int type)  
671 {
672         double range = i_range+1;
673
674         double xx,yy,zz,dd,ddmin=9999999;
675         int ibak=-1;
676         int i,size=_lstPoints.size();
677         for (i=0;i<size;i++){
678                 manualPoint *mp=_lstPoints[i];
679                 xx=mp->GetX();
680                 yy=mp->GetY();
681                 zz=mp->GetZ();
682
683                 if (type==-1)
684                 {
685                         if ((fabs(xx-x)<range) && (fabs(yy-y)<range) && (fabs(zz-z)<range)) {
686                            dd=sqrt(   (xx-x)*(xx-x) + (yy-y)*(yy-y) + (zz-z)*(zz-z) ); 
687                            if (dd<ddmin){
688                                    ddmin=dd;
689                                    ibak=i;
690                            }
691                         }
692                 }
693                 if (type==0)
694                 {
695                         if ((fabs(yy-y)<range) && (fabs(zz-z)<range)) {
696                            dd=sqrt(   (yy-y)*(yy-y) + (zz-z)*(zz-z) ); 
697                            if (dd<ddmin){
698                                    ddmin=dd;
699                                    ibak=i;
700                            }
701                         }
702                 }
703                 if (type==1)
704                 {
705                         if ((fabs(xx-x)<range) && (fabs(zz-z)<range)) {
706                            dd=sqrt(   (xx-x)*(xx-x)  + (zz-z)*(zz-z) ); 
707                            if (dd<ddmin){
708                                    ddmin=dd;
709                                    ibak=i;
710                            }
711                         }
712                 }
713                 if (type==2)
714                 {
715                         if ((fabs(xx-x)<range) && (fabs(yy-y)<range) ) {
716                            dd=sqrt(   (xx-x)*(xx-x) + (yy-y)*(yy-y)  ); 
717                            if (dd<ddmin){
718                                    ddmin=dd;
719                                    ibak=i;
720                            }
721                         }
722                 }
723         }
724         return ibak;
725 }
726 // ----------------------------------------------------------------------------
727 manualPoint* manualContourModel::GetManualPoint(int id)
728 {
729         return _lstPoints[id];
730 }
731 // ----------------------------------------------------------------------------
732 int manualContourModel::GetSizeLstPoints()
733 {
734         return _lstPoints.size();
735 }
736 //----------------------------------------------------------------------------
737 int manualContourModel::GetNumberOfPointsSpline()
738 {
739         return _sizePointsContour;
740 }
741 //----------------------------------------------------------------------------
742 void manualContourModel::SetNumberOfPointsSpline(int size)
743 {
744         _sizePointsContour = size;
745 }
746
747
748 // ----------------------------------------------------------------------------
749
750 void manualContourModel::SetCloseContour(bool closeContour)
751 {
752         _closeContour = closeContour;
753         if (_closeContour==true)
754         {
755                 _cntSplineX->ClosedOn(); 
756                 _cntSplineY->ClosedOn();
757                 _cntSplineZ->ClosedOn();
758         } else {
759                 _cntSplineX->ClosedOff(); 
760                 _cntSplineY->ClosedOff();
761                 _cntSplineZ->ClosedOff();
762         }
763 }
764
765 // ----------------------------------------------------------------------------
766 bool manualContourModel::IfCloseContour()
767 {
768         return _closeContour;
769 }
770
771 // ----------------------------------------------------------------------------
772
773 void manualContourModel::UpdateSpline() // virtual
774 {
775         int i, np;
776     np  = _lstPoints.size();
777         manualPoint     *mp;
778         _cntSplineX->RemoveAllPoints();
779         _cntSplineY->RemoveAllPoints();
780         _cntSplineZ->RemoveAllPoints();
781     for( i = 0; i < np; i++ ) {
782                 mp = GetManualPoint(i);
783         _cntSplineX->AddPoint( i, mp->GetX() );
784         _cntSplineY->AddPoint( i, mp->GetY() );
785         _cntSplineZ->AddPoint( i, mp->GetZ() );
786     } //  rof
787
788 //JSTG 25-02-08 ---------------------------------------------------------------------------------------------
789         if (this->_closeContour==true)
790         {
791                 _delta_JSTG = (double) (np) / double (_sizePointsContour - 1);  //Without the -1 the curve is not close
792         } else {
793                 _delta_JSTG = (double) (np-1) / double (_sizePointsContour );  //Without the -1 the curve is not close
794         }
795 //-----------------------------------------------------------------------------------------------------------
796 }
797
798 //---------------------------------------------------------------------------------
799
800 /*void manualContourModel::GetSplineiPoint(int i, double &x, double &y, double &z)
801 {
802         double delta=(double)(_lstPoints.size()) / (double)(_sizePointsContour);        
803         double t = delta*(double)i;
804         GetSplinePoint(t, x, y, z);
805 }*/
806
807 //-----------------------------------------------------------------------------
808
809 //JSTG 25-02-08 ---------------------------------------------------------------
810 void manualContourModel::GetSpline_i_Point(int i, double *x, double *y, double *z) // virtal
811 {
812         GetSpline_t_Point(i*_delta_JSTG,x,y,z);
813 }
814
815 // ----------------------------------------------------------------------------
816
817 //JSTG 25-02-08 ---------------------------------------------------------------
818 void manualContourModel::GetSpline_t_Point(double t, double *x, double *y, double *z)
819 {
820                 if (_lstPoints.size()==0)
821         {
822                 *x      = 0;
823                 *y      = 0;
824                 *z      = 0;
825         }
826         if (_lstPoints.size()==1)
827         {
828                 manualPoint     *mp;
829                 mp      = GetManualPoint(0);
830                 *x      = mp->GetX();
831                 *y      = mp->GetY();
832                 *z      = mp->GetZ();
833         }
834         if (_lstPoints.size()>=2)
835         {
836                 *x      = _cntSplineX->Evaluate(t); 
837                 *y      = _cntSplineY->Evaluate(t); 
838                 *z      = _cntSplineZ->Evaluate(t); 
839         }
840 }
841
842 // ----------------------------------------------------------------------------
843
844
845 /*void manualContourModel::GetSplinePoint(double t, double &x, double &y, double &z)
846 {
847         if (_lstPoints.size()==0)
848         {
849                 x       = 0;
850                 y       = 0;
851                 z       = 0;
852         }
853         if (_lstPoints.size()==1)
854         {
855                 manualPoint     *mp;
856                 mp      = GetManualPoint(0);
857                 x       = mp->GetX();
858                 y       = mp->GetY();
859                 z       = mp->GetZ();
860         }
861         if (_lstPoints.size()>=2)
862         {
863                 x       = _cntSplineX->Evaluate(t); 
864                 y       = _cntSplineY->Evaluate(t); 
865                 z       = _cntSplineZ->Evaluate(t); 
866         }
867 }*/
868 // ----------------------------------------------------------------------------
869 double manualContourModel::GetPathSize()
870 {
871         double result = 0;
872         double x1,y1,z1;
873         double x2,y2,z2;
874
875 // JSTG 25-02-08 -----------------------------
876         //double t,delta;
877         //int i,np,nps;
878         int i;
879 //--------------------------------------------
880
881         if (_lstPoints.size()==2)
882         {
883                 x1=_lstPoints[0]->GetX();
884                 y1=_lstPoints[0]->GetY();
885                 z1=_lstPoints[0]->GetZ();
886                 x2=_lstPoints[1]->GetX();
887                 y2=_lstPoints[1]->GetY();
888                 z2=_lstPoints[1]->GetZ();
889                 result = sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1) );
890         }
891         if (_lstPoints.size()>2)
892         {
893
894 // JSTG 25-02-08 ------------------------------------------             
895                 //np  = _lstPoints.size( );
896                 //nps = 200; 
897                 //delta=( double ) ( np  ) / ( double ) ( nps  );
898                 UpdateSpline();
899                 //GetSplinePoint(0,x1,y1,z1);
900                 GetSpline_i_Point(0,&x1,&y1,&z1);
901
902                 //for( i = 1; i < nps; i++ )
903                 for( i = 1; i < GetNumberOfPointsSpline(); i++ )
904                 {
905                         //t = delta * (double)i;
906                         //GetSplinePoint(t,x2,y2,z2);
907                         GetSpline_i_Point(i,&x2,&y2,&z2);
908 //---------------------------------------------------------
909                         result=result + sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1) );
910                         x1=x2;
911                         y1=y2;
912                         z1=z2;
913                 }// for 
914         }
915
916         return result;
917 }
918 // ----------------------------------------------------------------------------
919 double manualContourModel::GetPathArea()
920 {
921         double result = 555;
922         if ((_lstPoints.size()>=3) && IfCloseContour()==true )
923         {
924                 double area;
925 //JSTG 25-02-08 ---------------------------------------------
926                 //double ti,tj;
927 //-----------------------------------------------------------
928                 double x1,y1,z1;
929                 double x2,y2,z2;
930                 bool okArea=true;
931                 int i, j;
932          
933                 // This uses Green's theorem:
934                 // A = 1/2 * sum( xiyi+1 - xi+1yi); pO == pN
935                 // A < 0 -> A = |A| (a negative value could raise because points are
936                 // given in clockwise order).
937
938 //JSTG 25-02-08 -------------------------------------------------
939                 //int np  = _lstPoints.size( );
940                 //int nps = 200;
941                 int nps = GetNumberOfPointsSpline();
942                 //double delta=( double ) ( np  ) / ( double ) ( nps  );
943                 UpdateSpline();
944                 for( i = 0, area = 0.0; i < nps; i++ ) 
945                 {
946                         j = ( i + 1 ) % nps;
947                         //ti = delta * (double)i;
948                         //tj = delta * (double)j;
949                         //GetSplinePoint(ti,x1,y1,z1);
950                         //GetSplinePoint(tj,x2,y2,z2);
951                         GetSpline_i_Point(i,&x1,&y1,&z1);
952                         GetSpline_i_Point(j,&x2,&y2,&z2);
953 //----------------------------------------------------------------
954                         area +=
955                                         (x1 * y2 ) -
956                                         ( x2 * y1 );
957                         if (z1!=z2)
958                         {
959                                 okArea=false;
960                         }
961                 }// for 
962                 area /= 2.0;
963                 area = fabs( area );
964
965 /*
966                 for( i = 0, area = 0.0; i < _lstPoints.size(); i++ ) 
967                 {
968                         j = ( i + 1 ) % _lstPoints.size();
969                         //  Area
970                         area +=
971                                         (_lstPoints[i]->GetX() * _lstPoints[j]->GetY() ) -
972                                         ( _lstPoints[j]->GetX() * _lstPoints[i]->GetY() );
973                         if (_lstPoints[0]->GetZ()!=_lstPoints[i]->GetZ())
974                         {
975                                 okArea=false;
976                         }
977                 } // rof
978                 area /= 2.0;
979                 area = fabs( area );
980 */
981
982                 if (okArea==true)
983                 {
984                         result = area;
985                 } else {
986                         result = -1;
987                 }
988
989         } else {
990                 result = 0;
991         }
992         return result;
993 }
994
995 // ----------------------------------------------------------------------------
996 // p[x,y,z]   :  data in 
997 // rp[x,y,z]  :  data out  result point 
998 // rn[x,y,z]  :  data out   result normal
999
1000 void manualContourModel::GetNearestPointAndNormal(double *p, double *rp,  double *rn)
1001 {
1002         double  distMin=999999999;
1003         double  dist,dx,dy,dz;
1004         double  x1,y1,z1;
1005         double  x2,y2,z2;
1006         int             i,np,nps;
1007
1008 //JSTG 25-02-08 -------------------
1009         //double  tback;
1010         int iback;
1011         //double        t,delta;
1012 //---------------------------------
1013
1014         np      = _lstPoints.size( );
1015         if (np>=2)
1016         {
1017 // JSTG 25-02-08 ------------------------------------------
1018                 //nps           = 200; 
1019                 nps = GetNumberOfPointsSpline();
1020                 //delta = ( double ) ( np  ) / ( double ) ( nps  );
1021                 UpdateSpline();
1022                 //GetSplinePoint(0,x1,y1,z1);
1023                 GetSpline_i_Point(0,&x1,&y1,&z1);
1024                 for( i = 0; i < nps; i++ ) 
1025                 {
1026                         //t = delta * (double)i;
1027                         //GetSplinePoint(t,x1,y1,z1);
1028                         GetSpline_i_Point(i,&x1,&y1,&z1);
1029 //----------------------------------------------------------
1030                         dx= x1-p[0];
1031                         dy= y1-p[1];
1032                         dz= z1-p[2];
1033                         dist = sqrt( dx*dx + dy*dy + dz*dz );
1034                         if (dist<distMin) 
1035                         {
1036                                 distMin  = dist;
1037 //JSTG                  tback = t;
1038                                 iback = i;
1039                                 rp[0] = x1;
1040                                 rp[1] = y1;
1041                                 rp[2] = z1;
1042                                 rn[0] = x2-x1;
1043                                 rn[1] = y2-y1;
1044                                 rn[2] = z2-z1;
1045                         }
1046                         x2=x1;
1047                         y2=y1;
1048                         z2=z1;
1049                 }// for 
1050
1051 // JSTG 25-02-08 ------------------------------------------
1052                 //if (tback==0)
1053                 if (iback==0)
1054                 {
1055                         //t = delta * (double)1.0;
1056                         //GetSplinePoint(t,x1,y1,z1);
1057                         GetSpline_i_Point(i,&x1,&y1,&z1);
1058 //----------------------------------------------------------
1059                         rn[0]=rp[0]-x1;
1060                         rn[1]=rp[1]-y1;
1061                         rn[2]=rp[2]-z1;
1062                 }
1063         } 
1064         else 
1065         {
1066                 rp[0] = 0;
1067                 rp[1] = 0;
1068                 rp[2] = 0;
1069                 rn[0] = -1;
1070                 rn[1] = 0;
1071                 rn[2] = 0;
1072         }
1073 }
1074
1075 // ----------------------------------------------------------------------------
1076 manualContourModel * manualContourModel :: Clone() // virtual
1077 {
1078         manualContourModel * clone = new manualContourModel();
1079         CopyAttributesTo(clone);
1080         return clone;
1081 }
1082
1083 // ----------------------------------------------------------------------------
1084 void manualContourModel::Open(FILE *ff) // virtual
1085 {
1086         char tmp[255];
1087         int i;
1088         int numberOfControlPoints;
1089         double x,y,z;
1090
1091         fscanf(ff,"%s",tmp); // NumberOfControlPoints
1092         fscanf(ff,"%s",tmp); // ##
1093         numberOfControlPoints = atoi(tmp);  
1094         for (i=0;i<numberOfControlPoints;i++)
1095         {
1096                 fscanf(ff,"%s",tmp); // X
1097                 x = atof(tmp);  
1098                 fscanf(ff,"%s",tmp); // Y
1099                 y = atof(tmp);  
1100                 fscanf(ff,"%s",tmp); // Z
1101                 z = atof(tmp);  
1102                 AddPoint(x,y,z);
1103         }
1104 }
1105
1106
1107 // ----------------------------------------------------------------------------
1108 int manualContourModel::GetTypeModel() //virtual 
1109 {
1110         // 0 spline
1111         // 1 spline
1112         // 2 rectangle
1113         // 3 circle
1114         // 4 BullEye
1115         // 5 BullEyeSector
1116         return 1;
1117 }
1118
1119 // ----------------------------------------------------------------------------
1120 void manualContourModel::Save(FILE *ff) // virtual
1121 {
1122         int i,size=_lstPoints.size();
1123         fprintf(ff,"TypeModel %d\n", GetTypeModel() );
1124         fprintf(ff,"NumberOfControlPoints %d\n",size);
1125         for (i=0;i<size;i++)
1126         {
1127                 manualPoint *mp=_lstPoints[i];
1128                 fprintf(ff,"%f %f %f\n", mp->GetX(), mp->GetY(), mp->GetZ() );
1129         }
1130 }
1131
1132
1133 // ---------------------------------------------------------------------------
1134
1135 void manualContourModel::CopyAttributesTo( manualContourModel * cloneObject)
1136 {
1137         // Fathers object
1138         //XXXX::CopyAttributesTo(cloneObject);
1139
1140         cloneObject->SetCloseContour( this->IfCloseContour() );
1141         int i, size = GetSizeLstPoints();
1142         for( i=0; i<size; i++ )
1143         {
1144                 cloneObject->AddManualPoint( GetManualPoint( i )->Clone() );
1145         }
1146         cloneObject->SetNumberOfPointsSpline( GetNumberOfPointsSpline () ); 
1147         cloneObject->SetCloseContour( _closeContour );
1148         cloneObject->UpdateSpline();
1149 }
1150
1151
1152 // ---------------------------------------------------------------------------
1153 void manualContourModel::AddManualPoint( manualPoint* theManualPoint )//private
1154 {
1155         _lstPoints.push_back( theManualPoint );
1156 }
1157
1158 std::vector<manualContourModel*> manualContourModel::ExploseModel(  )
1159 {
1160         std::vector<manualContourModel*> lstTmp;
1161         lstTmp.push_back(this);
1162         return lstTmp;
1163 }
1164
1165
1166 // ---------------------------------------------------------------------------
1167 // ----------------------------------------------------------------------------
1168 // ----------------------------------------------------------------------------
1169
1170 //int manualViewPoint::range=1;
1171
1172
1173 manualViewPoint::manualViewPoint(wxVtkBaseView *wxvtkbaseview){
1174         _selected                = false;
1175         _posibleSelected = false;
1176         _pts                     = NULL;
1177         _pd                              = NULL;
1178         _pointVtkActor   = NULL;
1179         _bboxMapper              = NULL;
1180         _wxvtkbaseview   = wxvtkbaseview;
1181         _spc[0]                  = 1;
1182         _spc[1]                  = 1;
1183         _spc[2]                  = 1;
1184
1185         _widthline               = 1;
1186
1187 }
1188 // ----------------------------------------------------------------------------
1189 manualViewPoint::~manualViewPoint(){
1190         DeleteVtkObjects();
1191 }
1192
1193 // ----------------------------------------------------------------------------
1194 void manualViewPoint::SetWidthLine( double width)
1195 {
1196         _widthline = width;
1197 }
1198
1199 // ----------------------------------------------------------------------------
1200 void manualViewPoint::SetSelected(bool selected){
1201         _selected=selected;
1202 }
1203 // ----------------------------------------------------------------------------
1204 void manualViewPoint::SetPosibleSelected(bool posibleSelected){
1205         _posibleSelected=posibleSelected;       
1206 }
1207 // ----------------------------------------------------------------------------
1208 bool manualViewPoint::GetSelected(){
1209         return _selected;
1210 }
1211 // ----------------------------------------------------------------------------
1212 bool manualViewPoint::GetPosibleSelected(){
1213         return _posibleSelected;
1214 }
1215 // ----------------------------------------------------------------------------
1216 void manualViewPoint::DeleteVtkObjects(){
1217         if (_pointVtkActor      !=NULL)         { _pointVtkActor->Delete(); }
1218         if (_bboxMapper         !=NULL)         { _bboxMapper   ->Delete();     }
1219         if (_pts                        !=NULL)         { _pts                  ->Delete();     }
1220         if (_pd                         !=NULL)         { _pd                   ->Delete();     }
1221         _pointVtkActor  =       NULL;
1222         _bboxMapper             =       NULL;
1223         _pts                    =       NULL;
1224         _pd                             =       NULL;
1225 }
1226
1227
1228
1229 // ----------------------------------------------------------------------------
1230 vtkActor* manualViewPoint::CreateVtkPointActor()
1231 {
1232         DeleteVtkObjects();
1233
1234         _pts = vtkPoints::New();
1235         _pts->SetNumberOfPoints(8);
1236         _pts->SetPoint(0, -1000 , -1000 , 0 );
1237         _pts->SetPoint(1,  1000 , -1000 , 0     );
1238         _pts->SetPoint(2,  1000 ,  1000 , 0 );
1239         _pts->SetPoint(3, -1000 ,  1000 , 0 );
1240         _pts->SetPoint(4, -1000 ,  1000 , 0 );
1241         _pts->SetPoint(5, -1000 ,  1000 , 0 );
1242         _pts->SetPoint(6, -1000 ,  1000 , 0 );
1243         _pts->SetPoint(7, -1000 ,  1000 , 0 );
1244
1245         vtkCellArray *lines = vtkCellArray::New();
1246         lines->InsertNextCell(17);
1247         lines->InsertCellPoint(0);
1248         lines->InsertCellPoint(1);
1249         lines->InsertCellPoint(2);
1250         lines->InsertCellPoint(3);
1251         lines->InsertCellPoint(0);
1252         lines->InsertCellPoint(4);
1253         lines->InsertCellPoint(5);
1254         lines->InsertCellPoint(6);
1255         lines->InsertCellPoint(7);
1256         lines->InsertCellPoint(4);
1257         lines->InsertCellPoint(0);
1258         lines->InsertCellPoint(3);
1259         lines->InsertCellPoint(7);
1260         lines->InsertCellPoint(6);
1261         lines->InsertCellPoint(2);
1262         lines->InsertCellPoint(1);
1263         lines->InsertCellPoint(5);
1264
1265         _pd = vtkPolyData::New();
1266         _pd->SetPoints( _pts );
1267         _pd->SetLines( lines );
1268         lines->Delete();  //do not delete lines ??
1269
1270         _pointVtkActor  =       vtkActor::New();
1271     _bboxMapper         =       vtkPolyDataMapper::New();
1272
1273         _bboxMapper->SetInput(_pd);
1274         _bboxMapper->ImmediateModeRenderingOn();
1275         _pointVtkActor->SetMapper(_bboxMapper);
1276         _pointVtkActor->GetProperty()->BackfaceCullingOn();
1277         UpdateColorActor();
1278         _pd->ComputeBounds();
1279
1280         return _pointVtkActor;
1281 }
1282 // ----------------------------------------------------------------------------
1283 vtkActor* manualViewPoint::GetVtkActor(){
1284         return _pointVtkActor;
1285 }
1286 // ----------------------------------------------------------------------------
1287 void manualViewPoint::SetPositionXY(double x, double y,double i_range,double posZ)
1288 {
1289 //      double range=0.2; // i_range;
1290 //      double range=(double)manualViewPoint::range;
1291
1292         double range=i_range;
1293
1294 //EED 27 sep 2006
1295         x        = x * _spc[0];
1296         y        = y * _spc[1];
1297         posZ = posZ * _spc[2];
1298
1299         if (_pts!=NULL){
1300                 _pts->SetPoint(0, x-range, y+range, posZ-range);
1301                 _pts->SetPoint(1, x+range, y+range, posZ-range);
1302                 _pts->SetPoint(2, x+range, y-range, posZ-range);
1303                 _pts->SetPoint(3, x-range, y-range, posZ-range);
1304                 _pts->SetPoint(4, x-range, y+range, posZ+range);
1305                 _pts->SetPoint(5, x+range, y+range, posZ+range);
1306                 _pts->SetPoint(6, x+range, y-range, posZ+range);
1307                 _pts->SetPoint(7, x-range, y-range, posZ+range);
1308         }
1309 }
1310
1311
1312 // ----------------------------------------------------------------------------
1313 void manualViewPoint::UpdateColorActor()
1314 {
1315         if (_pointVtkActor!=NULL){
1316 //EED03
1317                 _pointVtkActor->GetProperty()->SetLineWidth( _widthline );
1318                 _pointVtkActor->GetProperty()->SetDiffuseColor(1,0,0);
1319                 if (_posibleSelected==true){
1320                         _pointVtkActor->GetProperty()->SetDiffuseColor(1,1,0);
1321                 }
1322         }
1323 }
1324 // ----------------------------------------------------------------------------
1325 void manualViewPoint::GetSpacing(double spc[3])
1326 {
1327         spc[0] = _spc[0];
1328         spc[1] = _spc[1];
1329         spc[2] = _spc[2];
1330 }
1331 // ----------------------------------------------------------------------------
1332 void manualViewPoint::SetSpacing(double spc[3])
1333 {
1334         _spc[0] = spc[0];
1335         _spc[1] = spc[1];
1336         _spc[2] = spc[2];
1337 }
1338
1339
1340
1341 // ----------------------------------------------------------------------------
1342 // ----------------------------------------------------------------------------
1343 // ----------------------------------------------------------------------------
1344
1345 manualViewContour::manualViewContour()
1346 {
1347         _id_viewPoint_for_text  =       0;
1348         _mesureScale                    =       1;
1349         _initialConoturModel = new manualContourModel();
1350 }
1351 // ----------------------------------------------------------------------------
1352 manualViewContour::~manualViewContour()
1353 {
1354         delete _initialConoturModel;
1355 }
1356 // ----------------------------------------------------------------------------
1357
1358 // ----------------------------------------------------------------------------
1359 manualViewContour * manualViewContour :: Clone()
1360 {
1361         manualViewContour * clone = new manualViewContour();
1362         CopyAttributesTo(clone);
1363         return clone;
1364 }
1365
1366 // ---------------------------------------------------------------------------
1367
1368 void manualViewContour::CopyAttributesTo( manualViewContour * cloneObject)
1369 {
1370         // Call to Fathers object
1371         manualViewBaseContour::CopyAttributesTo(cloneObject);
1372         
1373         cloneObject->SetMesureScale(_mesureScale);
1374 }
1375
1376 // ---------------------------------------------------------------------------
1377
1378 int manualViewContour::GetType() // virtual
1379 {
1380         return 1;
1381 }
1382
1383 // ----------------------------------------------------------------------------
1384
1385 void manualViewContour::Save(FILE *pFile)
1386 {
1387         manualViewBaseContour::Save(pFile);
1388 }
1389
1390 // ----------------------------------------------------------------------------
1391
1392 void manualViewContour::Open(FILE *pFile)
1393 {
1394 }
1395
1396
1397
1398 // ----------------------------------------------------------------------------
1399 void manualViewContour::RefreshContour() // virtual
1400 {
1401
1402         int i,np,nps;
1403
1404 //JSTG 25-02-08 --------------------
1405         //double t,delta, x,y,z;
1406         double x,y,z;
1407 //----------------------------------
1408
1409         _manContModel->UpdateSpline();
1410     np  = GetNumberOfPoints( );
1411         //nps = GetNumberOfPointsSpline(); 
1412     nps = _manContModel->GetNumberOfPointsSpline();             
1413         //delta=( double ) ( np  ) / ( double ) ( nps-1  );             //JSTG 25-02-08
1414
1415 //printf ("EED manualViewContour::RefreshContour>> %d %d \n", np,nps);
1416
1417         if ( _pts!=NULL )
1418         {
1419                 if (np>=2  )
1420                 {
1421                         for( i = 0; i < nps; i++ ) 
1422                         {
1423 //JSTG 25-02-08 ------------------------------------------------                                
1424                                 //t = delta * (double)i;
1425                                 //_manContModel->GetSplinePoint(t,x,y,z);
1426                                 _manContModel->GetSpline_i_Point(i,&x,&y,&z);
1427 //--------------------------------------------------------------
1428         // EED 27 sep 2006
1429         //                      _pts->SetPoint(i, x,y,z );      
1430                                 _pts->SetPoint(i , x*_spc[0] , y*_spc[1] , z*_spc[2] );  
1431 //if (i%15==0)
1432 //{
1433 //      printf ("EED manualViewContour::RefreshContour>> %d : %f %f %f \n", i,x,y,z);
1434 //}
1435
1436
1437                         }// for 
1438                 } 
1439                 else 
1440                 {
1441                                 _pts->SetPoint(0, 0 , 0 , 0);   
1442                                 _pts->SetPoint(1, 0 , 0 , 0);   
1443                 } // if
1444         }
1445 }
1446
1447 // ----------------------------------------------------------------------------
1448 void manualViewContour::RefreshText()  // virtual
1449 {
1450
1451         if ((_textActor!=NULL) && ( _textActor->GetProperty()->GetOpacity()!=0 )){
1452                 int size = GetNumberOfPoints();
1453                 char text[50];
1454                 char resultText[50];
1455                 strcpy(resultText," ");
1456                 if (size==2)
1457                 {
1458                         strcpy(resultText,"L= ");
1459                         gcvt ( _mesureScale * this->_manContModel->GetPathSize() , 5, text );
1460                         strcat(resultText,text);
1461                 }
1462                 if (size>2)
1463                 {
1464                         if (_manContModel->IfCloseContour()==true)
1465                         {
1466                                 strcpy(resultText,"P= ");
1467                                 gcvt ( _mesureScale * this->_manContModel->GetPathSize() , 5, text );
1468                                 strcat(resultText,text);
1469                                 gcvt ( _mesureScale * _mesureScale * this->_manContModel->GetPathArea() , 5, text );
1470                                 strcat(resultText,"   A= ");
1471                                 strcat(resultText,text);
1472                         } else {
1473                                 strcpy(resultText,"L= ");
1474                                 gcvt (  _mesureScale * this->_manContModel->GetPathSize() , 5, text );
1475                                 strcat(resultText,text);
1476                         }
1477                 }
1478
1479                 _textActor -> SetInput(resultText);
1480
1481                 if (size>=1){
1482
1483                         int i;
1484                         for (i=0; i<size; i++)
1485                         {
1486                                 if (_lstViewPoints[i]->GetPosibleSelected()==true)
1487                                 {
1488                                         _id_viewPoint_for_text = i;
1489                                 }
1490                         }
1491
1492                         int id = _id_viewPoint_for_text;
1493                         double px = _manContModel->GetManualPoint(id)->GetX();
1494                         double py = _manContModel->GetManualPoint(id)->GetY();
1495
1496                         //EED 27 sep 2006
1497                         px=px*_spc[0];
1498                         py=py*_spc[1];
1499
1500                         _textActor->SetPosition(px+GetRange()+1,py);
1501                 }
1502
1503         }
1504 }
1505
1506 // ----------------------------------------------------------------------------
1507 bool manualViewContour::ifTouchContour(int x,int y,int z){
1508         bool result=false;
1509         double xx=x;
1510         double yy=y;
1511         double zz=z;
1512         double ppA[3];
1513         double ppB[3];
1514         double d1,d2,d3;
1515         TransfromeCoordViewWorld(xx,yy,zz);
1516
1517 //EED 27 sep 2006
1518         xx = xx * _spc[0];
1519         yy = yy * _spc[1];
1520         zz = zz * _spc[2];
1521
1522
1523     unsigned int i, nps,nps_t;
1524     nps   = _sizePointsContour; 
1525         if (this->_manContModel->IfCloseContour()==true) 
1526         {
1527                 nps_t = nps; 
1528         } else {
1529                 nps_t = nps-1; 
1530         }
1531
1532     for( i = 0; i < nps_t; i++ ) {
1533                 _pts->GetPoint(i%nps, ppA);
1534                 _pts->GetPoint((i+1)%nps, ppB);
1535                 d1= sqrt( (ppA[0]-xx)*(ppA[0]-xx) + (ppA[1]-yy)*(ppA[1]-yy) + (ppA[2]-zz)*(ppA[2]-zz));
1536                 d2= sqrt( (ppB[0]-xx)*(ppB[0]-xx) + (ppB[1]-yy)*(ppB[1]-yy) + (ppB[2]-zz)*(ppB[2]-zz));
1537                 d3= sqrt( (ppB[0]-ppA[0])*(ppB[0]-ppA[0]) + (ppB[1]-ppA[1])*(ppB[1]-ppA[1]) + (ppB[2]-ppA[2])*(ppB[2]-ppA[2]));
1538                 if (  ((d1+d2)>=d3) &&  ((d1+d2)<=d3*1.3) ) {
1539                         result=true;
1540                         i=nps;
1541                 }
1542         } 
1543         return result;
1544 }
1545
1546 // ----------------------------------------------------------------------------
1547 void manualViewContour::DeletePoint(int id) // virtual 
1548 {
1549         if (_lstViewPoints.size()>2)
1550         {
1551                 manualViewBaseContour::DeletePoint( id );
1552         }
1553 }
1554 // ----------------------------------------------------------------------------
1555
1556 void manualViewContour::ClearPoint(int id)
1557 {
1558         manualViewBaseContour::DeletePoint( id );
1559 }
1560
1561 //-------------------------------------------------------------------
1562 void manualViewContour::SetMesureScale(double mesureScale)
1563 {
1564         _mesureScale = mesureScale;
1565 }
1566 //-------------------------------------------------------------------
1567 void manualViewContour::InitMove(int x, int y, int z)
1568 {
1569         _initialConoturModel->DeleteAllPoints();
1570         
1571         manualPoint *mp = NULL;
1572         double XX=x;
1573         double YY=y;
1574         double ZZ=z;
1575         TransfromeCoordViewWorld(XX,YY,ZZ);
1576                 
1577         int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
1578         for ( i=0; i<manualPointsSZ; i++ )
1579         {
1580                 mp = _manContModel->GetManualPoint( i );
1581                 this->_initialConoturModel->AddPoint( mp->GetX() - XX, mp->GetY() - YY, mp->GetZ() );
1582         }               
1583 }
1584 //-------------------------------------------------------------------
1585 void manualViewContour::MoveContour(int x, int y, int z)
1586 {
1587         manualPoint *mpOrigin = NULL;
1588         manualPoint *mpMoving = NULL;
1589         double XX=x;
1590         double YY=y;
1591         double ZZ=z;
1592         
1593         TransfromeCoordViewWorld(XX,YY,ZZ);
1594
1595         int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
1596         for ( i=0; i<manualPointsSZ; i++ )
1597         {
1598                 mpOrigin = _manContModel->GetManualPoint( i );
1599                 mpMoving = _initialConoturModel->GetManualPoint(i);
1600                 mpOrigin->SetPoint( mpMoving->GetX()+XX, mpMoving->GetY() + YY, mpMoving->GetZ() );
1601         }       
1602         UpdateViewPoints();     
1603 }
1604 void manualViewContour::MoveContour(int horizontalUnits, int verticalUnits )
1605 {
1606         manualPoint *mpOrigin = NULL;
1607
1608         int i, manualPointsSZ = _manContModel->GetSizeLstPoints();
1609         for ( i=0; i<manualPointsSZ; i++ )
1610         {
1611                 mpOrigin = _manContModel->GetManualPoint( i );
1612                 mpOrigin->SetPoint( mpOrigin->GetX()+horizontalUnits, mpOrigin->GetY()+verticalUnits, mpOrigin->GetZ() );
1613         }       
1614         UpdateViewPoints();             
1615 }
1616 // ----------------------------------------------------------------------------
1617 // ----------------------------------------------------------------------------
1618 // ----------------------------------------------------------------------------
1619
1620
1621 manualView3VContour::manualView3VContour(int type)
1622 {
1623         _type=type;
1624 // JSTG 25-02-08 ------------------------------
1625         //_manContModel= new manualContourModel();
1626 //---------------------------------------------
1627 }
1628 // ----------------------------------------------------------------------------
1629 manualView3VContour::~manualView3VContour()
1630 {
1631 }
1632
1633
1634
1635 // ----------------------------------------------------------------------------
1636 manualView3VContour * manualView3VContour :: Clone()
1637 {
1638         manualView3VContour * clone = new manualView3VContour( GetType() );
1639         CopyAttributesTo(clone);
1640         return clone;
1641 }
1642
1643 // ---------------------------------------------------------------------------
1644
1645 void manualView3VContour::CopyAttributesTo( manualView3VContour * cloneObject)
1646 {
1647         // Fathers object
1648         manualViewContour::CopyAttributesTo(cloneObject);
1649 }
1650
1651 int manualView3VContour::GetType()
1652 {
1653         return _type;
1654 }
1655
1656 // ----------------------------------------------------------------------------
1657 void manualView3VContour::FilterCordinateXYZ(double &x,double &y,double &z)
1658 {
1659         if (_type==0)
1660         {
1661                 x=-1000;
1662         }
1663         if (_type==1)
1664         {
1665                 y=500;
1666         }
1667         if (_type==2)
1668         {
1669                 z=-1000;
1670         }
1671 }
1672 // ----------------------------------------------------------------------------
1673
1674 void manualView3VContour::RefreshContour()  // virtula
1675 {
1676         manualViewContour::RefreshContour();
1677         int i;
1678         double pp[3];
1679 // JSTG 25-02-08 ----------------------------------------
1680         //int nps = GetNumberOfPointsSpline();
1681         int nps = _manContModel->GetNumberOfPointsSpline();
1682 //-------------------------------------------------------
1683         for( i = 0; i < nps; i++ ) 
1684         {
1685                 _pts->GetPoint( i, pp );
1686                 FilterCordinateXYZ(pp[0],pp[1],pp[2]);
1687
1688 //EED 27 sep 2006
1689                 _pts->SetPoint( i, pp[0] , pp[1] ,pp[2] );      
1690         }
1691
1692 }
1693
1694 // ----------------------------------------------------------------------------
1695
1696 void manualView3VContour::UpdateViewPoint(int id){  // virtual
1697         double x,y,z;
1698         manualPoint             *mp             = _manContModel->GetManualPoint(id);
1699         x=mp->GetX();
1700         y=mp->GetY();
1701         z=mp->GetZ();
1702
1703         FilterCordinateXYZ(x,y,z);
1704         _lstViewPoints[id]->SetPositionXY( x , y ,GetRange(), z );
1705 }
1706
1707 // ----------------------------------------------------------------------------
1708
1709 int     manualView3VContour::GetIdPoint(int x, int y, int z) // virtual
1710 {
1711         int ii=-1;
1712         if (_manContModel!=NULL){
1713                 double xx=x;
1714                 double yy=y;
1715                 double zz=z;
1716                 TransfromeCoordViewWorld(xx,yy,zz,-1);
1717                 ii=_manContModel->GetIdPoint(xx,yy,zz,GetRange(),_type);
1718         }
1719         return ii;
1720 }
1721
1722 // ----------------------------------------------------------------------------
1723 bool manualView3VContour::ifTouchContour(int x,int y,int z){ // virtual
1724         bool result=false;
1725         double xx=x;
1726         double yy=y;
1727         double zz=z;
1728         double ppA[3];
1729         double ppB[3];
1730         double d1,d2,d3;
1731         TransfromeCoordViewWorld(xx,yy,zz,-1);
1732
1733 //EED 27 sep 2006
1734         xx = xx * _spc[0];
1735         yy = yy * _spc[1];
1736         zz = zz * _spc[2];
1737
1738     unsigned int i, nps,nps_t;
1739     nps   = _sizePointsContour; 
1740         if (this->_manContModel->IfCloseContour()==true) 
1741         {
1742                 nps_t = nps; 
1743         } else {
1744                 nps_t = nps-1; 
1745         }
1746         FilterCordinateXYZ(xx,yy,zz);
1747
1748     for( i = 0; i < nps_t; i++ ) {
1749                 _pts->GetPoint(i%nps, ppA);
1750                 _pts->GetPoint((i+1)%nps, ppB);
1751                 FilterCordinateXYZ(ppA[0],ppA[1],ppA[2]);
1752                 FilterCordinateXYZ(ppB[0],ppB[1],ppB[2]);
1753                 d1= sqrt( (ppA[0]-xx)*(ppA[0]-xx) + (ppA[1]-yy)*(ppA[1]-yy) + (ppA[2]-zz)*(ppA[2]-zz));
1754                 d2= sqrt( (ppB[0]-xx)*(ppB[0]-xx) + (ppB[1]-yy)*(ppB[1]-yy) + (ppB[2]-zz)*(ppB[2]-zz));
1755                 d3= sqrt( (ppB[0]-ppA[0])*(ppB[0]-ppA[0]) + (ppB[1]-ppA[1])*(ppB[1]-ppA[1]) + (ppB[2]-ppA[2])*(ppB[2]-ppA[2]));
1756                 if (  ((d1+d2)>=d3) &&  ((d1+d2)<=d3*1.3) ) {
1757                         result=true;
1758                         i=nps;
1759                 }
1760         } 
1761         return result;
1762 }
1763 // ----------------------------------------------------------------------------
1764 // ----------------------------------------------------------------------------
1765 // ----------------------------------------------------------------------------
1766 manualView3DContour::manualView3DContour()
1767 {
1768 }
1769 // ----------------------------------------------------------------------------
1770 manualView3DContour::~manualView3DContour()
1771 {
1772 }
1773
1774 // ----------------------------------------------------------------------------
1775 manualView3DContour * manualView3DContour :: Clone()
1776 {
1777         manualView3DContour * clone = new manualView3DContour();
1778         CopyAttributesTo(clone);
1779         return clone;
1780 }
1781
1782 // ---------------------------------------------------------------------------
1783 void manualView3DContour::CopyAttributesTo( manualView3DContour * cloneObject)
1784 {
1785         // Fathers object
1786         manualViewContour::CopyAttributesTo(cloneObject);
1787
1788         cloneObject->SetDimensions ( _w , _h , _d );
1789 }
1790 // ----------------------------------------------------------------------------
1791 void manualView3DContour::SetDimensions(int w, int h, int d)
1792 {
1793         _w = w;
1794         _h = h;
1795         _d = d;
1796 }
1797 // ----------------------------------------------------------------------------
1798 void manualView3DContour::TransfromeCoordViewWorld(double &X, double &Y, double &Z, int type)
1799 {
1800         X = _vtkmprbasedata->GetX();
1801         Y = _vtkmprbasedata->GetY();
1802         Z = _vtkmprbasedata->GetZ();
1803 }
1804 // ----------------------------------------------------------------------------
1805 void manualView3DContour::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
1806 {
1807         _vtkmprbasedata = vtkmprbasedata;
1808 }
1809 // ----------------------------------------------------------------------------
1810 int manualView3DContour::GetIdPoint2(int x, int y)
1811 {
1812         int id = -1;
1813         double p[3],pA[3],pB[3];
1814
1815         double pickPoint[ 3 ], cameraPos[ 3 ];
1816         vtkPointPicker* picker = vtkPointPicker::New( );        
1817         vtkRenderer *pRenderer = this->GetWxVtkBaseView()->GetRenderer();
1818         picker->Pick( x, y, 0.0, pRenderer );
1819         pRenderer->GetActiveCamera( )->GetPosition( cameraPos );
1820         picker->GetPickPosition( pickPoint );
1821         picker->Delete( );
1822
1823         UtilVtk3DGeometriSelection utilVtk3Dgeometriselection;
1824         utilVtk3Dgeometriselection.SetDimentions(_w,_h,_d);
1825
1826         if( utilVtk3Dgeometriselection.FindCubePointsFromPoints( pA, pB, pickPoint, cameraPos )  ) 
1827         {
1828                 double dist,distMin=999999999;
1829                 int i,size=this->_manContModel->GetSizeLstPoints();
1830                 for (i=0;i<size;i++)
1831                 {
1832                         manualPoint *mp = this->_manContModel->GetManualPoint(i);
1833                         p[0] = mp->GetX();
1834                         p[1] = mp->GetY();
1835                         p[2] = mp->GetZ();
1836                         dist=utilVtk3Dgeometriselection.DistanceMinPointToLine(p,pA,pB);
1837                         if ( (dist<=2*GetRange()) && (dist<distMin) )
1838                         {
1839                                 distMin = dist;
1840                                 id              = i;
1841                         }
1842                 }
1843         }
1844         return id;
1845 }
1846 // ----------------------------------------------------------------------------
1847 int manualView3DContour::SelectPosiblePoint ( int x, int y, int z )// virtual
1848 {
1849         SelectAllPossibleSelected(false);
1850         int id=GetIdPoint2(x,y);
1851         if (id!=-1)
1852         {
1853                 SetPointPosibleSelected(id,true);
1854         }
1855         return id;
1856 }
1857
1858
1859
1860
1861 // ----------------------------------------------------------------------------
1862 // ----------------------------------------------------------------------------
1863 // ----------------------------------------------------------------------------
1864
1865
1866
1867
1868 // ----------------------------------------------------------------------------
1869 // ----------------------------------------------------------------------------
1870 // ----------------------------------------------------------------------------
1871 manualViewBullEyeSector::manualViewBullEyeSector()
1872 {
1873 }
1874
1875 // ----------------------------------------------------------------------------
1876 void manualViewBullEyeSector::RefreshContour()
1877 {
1878 //EED004
1879         int i,nps;
1880         double x,y,z;
1881 //----------------------------------
1882
1883         _manContModel->UpdateSpline();
1884     nps = _manContModel->GetNumberOfPointsSpline();             
1885
1886         if ( _pts!=NULL )
1887         {
1888                 for( i = 0; i < nps; i++ ) 
1889                 {
1890                         _manContModel->GetSpline_i_Point(i,&x,&y,&z);
1891                         _pts->SetPoint(i , x*_spc[0] , y*_spc[1] , z*_spc[2] );  
1892                 }// for 
1893         }
1894
1895 }
1896
1897 // ----------------------------------------------------------------------------
1898 // ----------------------------------------------------------------------------
1899 // ----------------------------------------------------------------------------
1900
1901
1902 manualViewBullEye::manualViewBullEye()
1903 {
1904 }
1905
1906 // ----------------------------------------------------------------------------
1907 manualViewBullEye::~manualViewBullEye()
1908 {
1909         // BullEye(s)
1910         int i,size=lstSectorBullEye.size();
1911         for (i=0;i<size;i++)
1912         {
1913                 delete lstSectorBullEye[i];
1914         }
1915         lstSectorBullEye.clear();
1916 }
1917
1918
1919 // ----------------------------------------------------------------------------
1920 manualViewBullEye * manualViewBullEye :: Clone()
1921 {
1922         manualViewBullEye * clone = new manualViewBullEye();
1923         CopyAttributesTo(clone);
1924         return clone;
1925 }
1926
1927 // ---------------------------------------------------------------------------
1928
1929 void manualViewBullEye::CopyAttributesTo( manualViewBullEye * cloneObject)
1930 {
1931         // Fathers object
1932         manualViewBaseContour::CopyAttributesTo(cloneObject);
1933 }
1934
1935
1936 // ----------------------------------------------------------------------------
1937 int manualViewBullEye::GetType() // virtual
1938 {
1939         return 4;
1940 }
1941
1942
1943 // ----------------------------------------------------------------------------
1944 void manualViewBullEye::RefreshContour() // virtual
1945
1946         // External Rectangle
1947         manualViewRoi::RefreshContour();
1948
1949         _manContModel->UpdateSpline();
1950     int np      = GetNumberOfPoints( );
1951         // Refres sectors of BullEye(s)
1952
1953         if (np>=2  )
1954         {
1955                 int i,size = lstSectorBullEye.size();
1956                 for (i=0;i<size;i++)
1957                 {
1958                         lstSectorBullEye[i]->RefreshContour();
1959                 } // for
1960         } // if
1961
1962
1963 }
1964
1965 // ----------------------------------------------------------------------------
1966 void manualViewBullEye::ConstructVTKObjects() // virtual
1967 {
1968         manualViewRoi::ConstructVTKObjects();
1969
1970         double spc[3];
1971         this->GetSpacing(spc);
1972         manualViewBullEyeSector *mvbc;
1973         manualContourModelBullEye *mcmbe = (manualContourModelBullEye*)this->_manContModel;
1974         int i,size = mcmbe->GetSizeOfSectorLst();
1975         for ( i=0 ; i<size ; i++ )
1976         {
1977                 mvbc = new manualViewBullEyeSector();
1978                 mvbc->SetModel( mcmbe->GetModelSector(i) );
1979                 mvbc->SetWxVtkBaseView( this->GetWxVtkBaseView()  );
1980                 mvbc->SetRange( 2 );
1981                 mvbc->SetZ( 1000 );
1982                 mvbc->SetSpacing(spc);
1983                 mvbc->SetColorNormalContour(1, 0, 0);
1984 //              mvbc->SetColorEditContour(0.5, 0.5, 0.5);
1985 //              mvbc->SetColorSelectContour(1, 0.8, 0);
1986                 mvbc->SetWidthLine( this->GetWidthLine()  );
1987 //EED004
1988                 mvbc->ConstructVTKObjects();
1989                 lstSectorBullEye.push_back( mvbc );
1990         }
1991
1992
1993 }
1994
1995 // ----------------------------------------------------------------------------
1996 void manualViewBullEye::AddSplineActor()  // virtual
1997 {
1998         manualViewRoi::AddSplineActor();
1999         int i,size=lstSectorBullEye.size();
2000         for (i=0;i<size;i++)
2001         {
2002                 lstSectorBullEye[i]->AddSplineActor();
2003         }
2004 }
2005
2006 // ----------------------------------------------------------------------------
2007 void manualViewBullEye::RemoveSplineActor()  // virtual
2008 {
2009         manualViewRoi::RemoveSplineActor();
2010         int i,size=lstSectorBullEye.size();
2011         for (i=0;i<size;i++)
2012         {
2013                 lstSectorBullEye[i]->RemoveSplineActor();
2014         }
2015 }
2016
2017
2018 // ----------------------------------------------------------------------------
2019 // ----------------------------------------------------------------------------
2020 // ----------------------------------------------------------------------------
2021
2022 manualViewRoi::manualViewRoi()
2023 {
2024         _sizePointsContour=5;
2025 }
2026 // ----------------------------------------------------------------------------
2027 manualViewRoi::~manualViewRoi()
2028 {
2029 }
2030
2031
2032 // ----------------------------------------------------------------------------
2033 manualViewRoi * manualViewRoi :: Clone()
2034 {
2035         manualViewRoi * clone = new manualViewRoi();
2036         CopyAttributesTo(clone);
2037         return clone;
2038 }
2039
2040 // ---------------------------------------------------------------------------
2041
2042 void manualViewRoi::CopyAttributesTo( manualViewRoi * cloneObject)
2043 {
2044         // Fathers object
2045         manualViewBaseContour::CopyAttributesTo(cloneObject);
2046 }
2047
2048 // ----------------------------------------------------------------------------
2049 void manualViewRoi::RefreshContour() // virtual
2050 {
2051     unsigned int i,ii, np;
2052     np  = GetNumberOfPoints( );
2053         if ( np > 0)
2054         {
2055                 if (np>=2)
2056                 {
2057                         manualPoint     *mp;
2058                         for( i = 0; i < np+1; i++ ) {
2059                                 ii=i%np;
2060                                 mp = _manContModel->GetManualPoint(ii);
2061
2062         //EEDx6
2063                                 double XX=mp->GetX(),YY=mp->GetY(),ZZ=mp->GetZ();
2064         //                      wxVtk2DBaseView *wxvtk2Dbasevie = (wxVtk2DBaseView*)this->GetWxVtkBaseView();
2065         //                      wxvtk2Dbasevie->TransformCoordinate_spacing_ModelToView(XX,YY,ZZ);
2066
2067         //EED 27 sep 2007
2068         //                      _pts->SetPoint(i, XX,YY,ZZ );   
2069                                 _pts->SetPoint(i, XX*_spc[0] , YY*_spc[1] , ZZ*_spc[2] );       
2070                         } //  rof
2071
2072                 } else {
2073                                 _pts->SetPoint(0, 0 , 0 , 0);   
2074                                 _pts->SetPoint(1, 0 , 0 , 0);   
2075                 } // if
2076         }
2077 }
2078
2079 // ----------------------------------------------------------------------------
2080 int manualViewRoi::GetType() // virtual
2081 {
2082         return 2;
2083 }
2084
2085 // ----------------------------------------------------------------------------
2086
2087 void manualViewRoi::GetMinMax(double &minX,double &minY, double &maxX, double &maxY)
2088 {
2089         double  pp[3];
2090         manualPoint *mp;  
2091     unsigned int i;
2092         
2093         minX=99999;
2094         minY=99999;
2095         maxX=-99999;
2096         maxY=-99999;
2097
2098         unsigned int size=(unsigned int) _manContModel->GetSizeLstPoints();
2099
2100         for( i = 0; i < size; i++ ) 
2101         {
2102
2103                 mp=_manContModel->GetManualPoint(i);
2104                 pp[0]=mp->GetX();
2105                 pp[1]=mp->GetY();
2106  
2107                 // min X
2108                 if (pp[0]<minX) 
2109                 {
2110                         minX=pp[0];
2111                 }
2112                 //min Y
2113                 if (pp[1]<minY) 
2114                 {
2115                         minY=pp[1];
2116                 }
2117                 //max X
2118                 if (pp[0]>maxX) 
2119                 {
2120                         maxX=pp[0];
2121                 }
2122                 // max Y
2123                 if (pp[1]>maxY) 
2124                 {
2125                         maxY=pp[1];
2126                 }
2127         }
2128
2129         if ( size<1 )
2130         {
2131                 minX=0;
2132                 maxX=0;
2133                 minY=0;
2134                 maxY=0;
2135         }
2136
2137
2138 // ----------------------------------------------------------------------------
2139
2140 bool manualViewRoi::ifTouchContour(int x,int y, int z) // virtual 
2141 {
2142         bool    result=false;
2143         double  px1=99999,py1=99999,px2=-9999,py2=-99999;
2144
2145         GetMinMax(px1,py1, px2, py2);
2146
2147         double xx=x;
2148         double yy=y;
2149         double zz=z;
2150         TransfromeCoordViewWorld(xx,yy,zz);
2151
2152         bool ok1=false;
2153         bool ok2=false;
2154         double ddx=GetRange();
2155         double ddy=GetRange();
2156
2157         if ((xx>px1-ddx)&&(xx<px2+ddx) &&  (yy>py1-ddy)&&(yy<py2+ddy))
2158         {
2159                 ok1=true;
2160         }
2161
2162         if ((xx>px1+ddx)&&(xx<px2-ddx) &&  (yy>py1+ddy)&&(yy<py2-ddy))
2163         {
2164                 ok2=true;
2165         }
2166
2167         if ((ok1==true) && (ok2==false))
2168         {
2169                 result=true;
2170         }
2171
2172         return result;
2173 }
2174
2175
2176 // ----------------------------------------------------------------------------
2177
2178 void manualViewRoi::InitMove(int x, int y, int z)  // virtual
2179 {
2180         manualPoint *mp;
2181         double XX=x;
2182         double YY=y;
2183         double ZZ=z;
2184         TransfromeCoordViewWorld(XX,YY,ZZ);
2185
2186         if (_manContModel->GetSizeLstPoints()==4){
2187                 mp = _manContModel->GetManualPoint(0);
2188                 _dp0[0]= mp->GetX() - XX;
2189                 _dp0[1]= mp->GetY() - YY;
2190                 _dp0[2]= mp->GetZ();
2191
2192                 mp = _manContModel->GetManualPoint(1);
2193                 _dp1[0]= mp->GetX() - XX;
2194                 _dp1[1]= mp->GetY() - YY;
2195                 _dp1[2]= mp->GetZ();
2196
2197                 mp = _manContModel->GetManualPoint(2);
2198                 _dp2[0]= mp->GetX() - XX;
2199                 _dp2[1]= mp->GetY() - YY;
2200                 _dp2[2]= mp->GetZ();
2201
2202                 mp = _manContModel->GetManualPoint(3);
2203                 _dp3[0]= mp->GetX() - XX;
2204                 _dp3[1]= mp->GetY() - YY;
2205                 _dp3[2]= mp->GetZ();
2206         }
2207 }
2208
2209 // ----------------------------------------------------------------------------
2210
2211 void manualViewRoi::MoveContour(int x, int y, int z) // virtual 
2212 {
2213         manualPoint *mp;
2214         double XX=x;
2215         double YY=y;
2216         double ZZ=z;
2217         TransfromeCoordViewWorld(XX,YY,ZZ);
2218
2219         mp = _manContModel->GetManualPoint(0);
2220         mp->SetPoint(_dp0[0]+XX,_dp0[1]+YY,_dp0[2]);
2221
2222         mp = _manContModel->GetManualPoint(1);
2223         mp->SetPoint(_dp1[0]+XX,_dp1[1]+YY,_dp0[2]);
2224
2225         mp = _manContModel->GetManualPoint(2);
2226         mp->SetPoint(_dp2[0]+XX,_dp2[1]+YY,_dp0[2]);
2227
2228         mp = _manContModel->GetManualPoint(3);
2229         mp->SetPoint(_dp3[0]+XX,_dp3[1]+YY,_dp0[2]);
2230
2231         UpdateViewPoint(0);
2232         UpdateViewPoint(1);
2233         UpdateViewPoint(2);
2234         UpdateViewPoint(3);     
2235
2236 }
2237
2238
2239
2240 // ----------------------------------------------------------------------------
2241 // ----------------------------------------------------------------------------
2242 // ----------------------------------------------------------------------------
2243
2244 // EED08
2245
2246 manualViewCircle::manualViewCircle()
2247 {
2248 //      _sizePointsContour=5;   // default 100
2249 }
2250 // ----------------------------------------------------------------------------
2251 manualViewCircle::~manualViewCircle()
2252 {
2253 }
2254
2255
2256 // ----------------------------------------------------------------------------
2257 manualViewCircle * manualViewCircle :: Clone()
2258 {
2259         manualViewCircle * clone = new manualViewCircle();
2260         CopyAttributesTo(clone);
2261         return clone;
2262 }
2263
2264 // ---------------------------------------------------------------------------
2265
2266 void manualViewCircle::CopyAttributesTo( manualViewCircle * cloneObject)
2267 {
2268         // Fathers object
2269         manualViewBaseContour::CopyAttributesTo(cloneObject);
2270 }
2271
2272
2273 // ----------------------------------------------------------------------------
2274 /*
2275 void manualViewCircle::RefreshContour(){ // virtual
2276
2277         manualPoint     *mpA,*mpB;
2278     unsigned int i, np,nps;
2279         double angle,radio;
2280         double difX,difY;
2281         double XX,YY,ZZ;
2282     np  = GetNumberOfPoints( );
2283         nps = _manContModel->GetNumberOfPointsSpline();
2284         double deltaAngle=(3.14159265*2)/(nps-1);
2285         if ( np > 0)
2286         {
2287                 if (np==2)
2288                 {
2289                         mpA             = _manContModel->GetManualPoint(0);
2290                         mpB             = _manContModel->GetManualPoint(1);
2291                         difX    = mpA->GetX() - mpB->GetX();
2292                         difY    = mpA->GetY() - mpB->GetY();
2293                         radio   = sqrt( difX*difX + difY*difY );
2294                         manualContourModelCircle *manContModelCir = (manualContourModelCircle*)_manContModel;
2295                         manContModelCir->SetRadio(radio);
2296
2297                         for( i = 0; i < nps; i++ ) {
2298                                 manContModelCir->GetSpline_i_Point(i, &XX, &YY, &ZZ);
2299 //                              angle = deltaAngle*i;
2300 //                              XX = cos(angle)*radio+mpA->GetX();
2301 //                              YY = sin(angle)*radio+mpA->GetY();
2302                                 ZZ = mpA->GetZ();
2303                                 _pts->SetPoint(i, XX*_spc[0] , YY*_spc[1] , ZZ*_spc[2] );       
2304                         } //  rof
2305                 } else {
2306                                 _pts->SetPoint(0, 0 , 0 , 0);   
2307                                 _pts->SetPoint(1, 0 , 0 , 0);   
2308                 } // if
2309         }
2310 }
2311 */
2312
2313 // ----------------------------------------------------------------------------
2314 int manualViewCircle::GetType() // virtual
2315 {
2316         return 3;
2317 }
2318
2319 // ----------------------------------------------------------------------------
2320
2321 void manualViewCircle::GetMinMax(double &minX,double &minY, double &maxX, double &maxY)
2322 {
2323         manualPoint     *mpA,*mpB;
2324     unsigned int  np;
2325         double radio;
2326         double difX,difY;
2327     np  = GetNumberOfPoints( );
2328         if (np==2)
2329         {
2330                 mpA             = _manContModel->GetManualPoint(0);
2331                 mpB             = _manContModel->GetManualPoint(1);
2332                 difX    = mpA->GetX() - mpB->GetX();
2333                 difY    = mpA->GetY() - mpB->GetY();
2334                 radio   = sqrt( difX*difX + difY*difY );
2335                 minX=mpA->GetX()-radio;
2336                 minY=mpA->GetY()-radio;
2337                 maxX=mpA->GetX()+radio;
2338                 maxY=mpA->GetY()+radio;
2339         } else {
2340                 minX=0;
2341                 maxX=0;
2342                 minY=0;
2343                 maxY=0;
2344         }
2345
2346
2347 /*
2348 // ----------------------------------------------------------------------------
2349 bool manualViewCircle::ifTouchContour(int x,int y, int z) // virtual 
2350 {
2351         bool    result=false;
2352         double  px1=99999,py1=99999,px2=-9999,py2=-99999;
2353
2354         GetMinMax(px1,py1, px2, py2);
2355
2356         double xx=x;
2357         double yy=y;
2358         double zz=z;
2359         TransfromeCoordViewWorld(xx,yy,zz);
2360
2361         bool ok1=false;
2362         bool ok2=false;
2363         double ddx=GetRange();
2364         double ddy=GetRange();
2365
2366         if ((xx>px1-ddx)&&(xx<px2+ddx) &&  (yy>py1-ddy)&&(yy<py2+ddy))
2367         {
2368                 ok1=true;
2369         }
2370
2371         if ((xx>px1+ddx)&&(xx<px2-ddx) &&  (yy>py1+ddy)&&(yy<py2-ddy))
2372         {
2373                 ok2=true;
2374         }
2375
2376         if ((ok1==true) && (ok2==false))
2377         {
2378                 result=true;
2379         }
2380
2381         return result;
2382 }
2383 */
2384
2385 // ----------------------------------------------------------------------------
2386
2387 void manualViewCircle::InitMove(int x, int y, int z)  // virtual
2388 {
2389         manualPoint *mp;
2390         double XX=x;
2391         double YY=y;
2392         double ZZ=z;
2393         TransfromeCoordViewWorld(XX,YY,ZZ);
2394
2395         if (_manContModel->GetSizeLstPoints()==2){
2396                 mp = _manContModel->GetManualPoint(0);
2397                 _dp0[0]= mp->GetX() - XX;
2398                 _dp0[1]= mp->GetY() - YY;
2399                 _dp0[2]= mp->GetZ();
2400
2401                 mp = _manContModel->GetManualPoint(1);
2402                 _dp1[0]= mp->GetX() - XX;
2403                 _dp1[1]= mp->GetY() - YY;
2404                 _dp1[2]= mp->GetZ();
2405 /*
2406                 mp = _manContModel->GetManualPoint(2);
2407                 _dp2[0]= mp->GetX() - XX;
2408                 _dp2[1]= mp->GetY() - YY;
2409                 _dp2[2]= mp->GetZ();
2410
2411                 mp = _manContModel->GetManualPoint(3);
2412                 _dp3[0]= mp->GetX() - XX;
2413                 _dp3[1]= mp->GetY() - YY;
2414                 _dp3[2]= mp->GetZ();
2415 */
2416         }
2417 }
2418
2419
2420 // ----------------------------------------------------------------------------
2421 void manualViewCircle::MoveContour(int x, int y, int z) // virtual 
2422 {
2423         manualPoint *mp;
2424         double XX=x;
2425         double YY=y;
2426         double ZZ=z;
2427         TransfromeCoordViewWorld(XX,YY,ZZ);
2428
2429         mp = _manContModel->GetManualPoint(0);
2430         mp->SetPoint(_dp0[0]+XX,_dp0[1]+YY,_dp0[2]);
2431
2432         mp = _manContModel->GetManualPoint(1);
2433         mp->SetPoint(_dp1[0]+XX,_dp1[1]+YY,_dp0[2]);
2434
2435 //      mp = _manContModel->GetManualPoint(2);
2436 //      mp->SetPoint(_dp2[0]+XX,_dp2[1]+YY,_dp0[2]);
2437
2438 //      mp = _manContModel->GetManualPoint(3);
2439 //      mp->SetPoint(_dp3[0]+XX,_dp3[1]+YY,_dp0[2]);
2440
2441         UpdateViewPoint(0);
2442         UpdateViewPoint(1);
2443 //      UpdateViewPoint(2);
2444 //      UpdateViewPoint(3);     
2445
2446 }
2447
2448
2449
2450
2451
2452
2453 // ----------------------------------------------------------------------------
2454 // ----------------------------------------------------------------------------
2455 // ----------------------------------------------------------------------------
2456
2457
2458 manualViewBaseContour::manualViewBaseContour()
2459 {
2460         _show_text                      = true; 
2461         _textActor                      = NULL;
2462         _manContModel           = NULL;
2463         _wxvtkbaseview          = NULL;
2464         _selected                       = false;
2465         _posibleSelected        = false;
2466         _viewControlPoints      = false;
2467         _pts                            = NULL;
2468         _pd                                     = NULL;
2469         _contourVtkActor        = NULL;
2470         _bboxMapper                     = NULL;
2471         _range                          = 1;
2472         _sizePointsContour      = 100;
2473         _spc[0]                         = 1;
2474         _spc[1]                         = 1;
2475         _spc[2]                         = 1;
2476
2477         _coulorEdit_r           = 1;
2478         _coulorEdit_g           = 1;
2479         _coulorEdit_b           = 0;
2480
2481         _coulorNormal_r         = 1;    
2482         _coulorNormal_g         = 0;
2483         _coulorNormal_b         = 1;
2484
2485         _coulorSelection_r      = 0;
2486         _coulorSelection_g      = 1;
2487         _coulorSelection_b      = 0;
2488
2489         _widthline                      = 1;
2490
2491 }
2492 // ----------------------------------------------------------------------------
2493 manualViewBaseContour::~manualViewBaseContour()
2494 {
2495         int i,size=_lstViewPoints.size();
2496         for (i=0;i<size; i++){
2497                 delete _lstViewPoints[i];
2498         }
2499         _lstViewPoints.clear();
2500 }
2501 // ----------------------------------------------------------------------------
2502
2503
2504 int manualViewBaseContour::GetType() // virtual
2505 {
2506 // Information...
2507 //int manualViewBaseContour::GetType()          0;
2508 //int manualViewContour::GetType()                      1;
2509 //int manualViewRoi::GetType()                          2;
2510 //int manualViewCircle::GetType()                       3;
2511 //int manualViewStar::GetType()                         4;
2512
2513
2514         return 0;
2515 }
2516 // ----------------------------------------------------------------------------
2517
2518 void manualViewBaseContour::Save(FILE *pFile)
2519 {
2520         fprintf(pFile,"TypeView %d\n", GetType() );
2521 }
2522
2523 // ----------------------------------------------------------------------------
2524 void manualViewBaseContour::Open(FILE *pFile)
2525 {
2526 }
2527
2528 // ----------------------------------------------------------------------------
2529 void manualViewBaseContour :: AddCompleteContourActor(  bool ifControlPoints )
2530 {
2531         _viewControlPoints = ifControlPoints;
2532          vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
2533          //Adding the spline
2534          AddSplineActor();
2535
2536          AddTextActor();
2537          //Adding each control point
2538          if( ifControlPoints )
2539                 AddControlPoints();
2540          RefreshContour();
2541          Refresh();
2542 }
2543 // ---------------------------------------------------------------------------
2544
2545 void manualViewBaseContour :: RemoveCompleteContourActor()
2546 {       
2547         vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
2548          //Removing the spline
2549         RemoveSplineActor();
2550         RemoveTextActor();
2551         
2552         //Removing each point
2553         RemoveControlPoints();
2554         RefreshContour();
2555         Refresh();
2556 }
2557 // ---------------------------------------------------------------------------
2558 manualViewBaseContour *  manualViewBaseContour :: Clone( )//virtual
2559 {
2560         manualViewBaseContour * clone = new manualViewBaseContour();
2561         CopyAttributesTo(clone);
2562         return clone;
2563
2564 }
2565
2566 // ---------------------------------------------------------------------------
2567
2568 void manualViewBaseContour::CopyAttributesTo( manualViewBaseContour * cloneObject)
2569 {
2570         // Fathers object
2571         //XXXX::CopyAttributesTo(cloneObject);
2572         
2573         cloneObject-> SetWxVtkBaseView( this->_wxvtkbaseview );
2574         cloneObject-> SetSelected( this->GetSelected() );
2575         cloneObject-> SetPosibleSelected( this->GetPosibleSelected() );
2576         cloneObject-> SetIfViewControlPoints( this->GetIfViewControlPoints() );
2577         cloneObject-> SetRange( this->GetRange() );
2578         cloneObject-> SetZ( this->GetZ() );
2579         cloneObject-> SetSpacing( _spc );
2580         cloneObject-> SetColorNormalContour( _coulorNormal_r, _coulorNormal_g, _coulorNormal_b );
2581         cloneObject-> SetColorEditContour( _coulorEdit_r, _coulorEdit_g, _coulorEdit_b );
2582         cloneObject-> SetColorSelectContour( _coulorSelection_r, _coulorSelection_g, _coulorSelection_b );      
2583
2584         int i, size = _lstViewPoints.size(); 
2585         for ( i=0; i<size; i++ )
2586         {
2587                 cloneObject->AddPoint(  );
2588         }
2589 }
2590
2591 // ----------------------------------------------------------------------------
2592 void manualViewBaseContour :: AddSplineActor()
2593 {
2594         vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
2595         if (_contourVtkActor!=NULL)
2596                 theRenderer->AddActor( _contourVtkActor  );
2597 }
2598 // ----------------------------------------------------------------------------
2599 void manualViewBaseContour :: RemoveSplineActor() // virtual
2600 {
2601         vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
2602         if (_contourVtkActor!=NULL)
2603                 theRenderer->RemoveActor( _contourVtkActor );
2604 }
2605 // ----------------------------------------------------------------------------
2606 void manualViewBaseContour :: RemoveControlPoints()
2607 {       
2608         if (_wxvtkbaseview!=NULL){
2609                 vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
2610                 int i,size=_lstViewPoints.size();
2611                 for (i=0;i<size; i++)
2612                 {
2613                         vtkActor * pointActor = _lstViewPoints[i]->GetVtkActor();
2614                         theRenderer->RemoveActor( pointActor );
2615                 } // for        
2616         } // if
2617         SetIfViewControlPoints( false );        
2618 }
2619 // ----------------------------------------------------------------------------
2620 void manualViewBaseContour :: AddControlPoints()
2621 {
2622         vtkRenderer * theRenderer = _wxvtkbaseview->GetRenderer();
2623         SetIfViewControlPoints( true ); 
2624          if( _viewControlPoints )
2625          {
2626                 int i,size=_lstViewPoints.size();
2627                 for (i=0;i<size; i++)
2628                 {
2629                         vtkActor * pointActor = _lstViewPoints[i]->GetVtkActor();
2630                         theRenderer->AddActor( pointActor );
2631                 }        
2632          }
2633 }
2634 // ----------------------------------------------------------------------------
2635 void manualViewBaseContour::AddTextActor()
2636 {
2637         _wxvtkbaseview->GetRenderer()->AddActor2D( _textActor );
2638 }
2639 // ----------------------------------------------------------------------------
2640 void manualViewBaseContour::RemoveTextActor()
2641 {
2642         _wxvtkbaseview->GetRenderer()->RemoveActor2D( _textActor );
2643 }
2644 // ----------------------------------------------------------------------------
2645 void manualViewBaseContour::DeleteVtkObjects()
2646 {
2647         if ( _contourVtkActor   != NULL )       { _contourVtkActor  -> Delete(); }
2648         if ( _bboxMapper                != NULL )       { _bboxMapper           -> Delete(); }
2649         if ( _pts                               != NULL )       { _pts                          -> Delete(); }
2650         if ( _pd                                != NULL )       { _pd                           -> Delete(); }
2651         _contourVtkActor        = NULL;
2652         _bboxMapper                     = NULL;
2653         _pts                            = NULL;
2654         _pd                                     = NULL;
2655 }
2656
2657
2658 // ----------------------------------------------------------------------------
2659 void manualViewBaseContour::SetWidthLine(double width)
2660 {
2661         _widthline = width;
2662         this->UpdateColorActor();
2663
2664         // for the control points
2665         int id, size = _lstViewPoints.size();
2666         for( id=0; id<size; id++)
2667         {
2668                 this->_lstViewPoints[id]->SetWidthLine(_widthline);
2669         }
2670
2671 }
2672
2673 // ----------------------------------------------------------------------------
2674 double manualViewBaseContour::GetWidthLine()
2675 {
2676         return _widthline;
2677 }
2678
2679 // ----------------------------------------------------------------------------
2680 void manualViewBaseContour::ConstructVTKObjects()
2681 {
2682 //JSTG 29-02-08 -----------------------------------------------
2683         //int i , nps = _sizePointsContour;
2684         int i; 
2685         int nps = _manContModel->GetNumberOfPointsSpline();
2686 //-------------------------------------------------------------
2687         DeleteVtkObjects();
2688         _pts = vtkPoints::New();
2689         _pts->SetNumberOfPoints(nps);
2690
2691         for (i=0 ; i<nps ; i++){
2692                 _pts->SetPoint(i,       0       , 0     , 0 );
2693         } 
2694         // This is for the boundaring inicialisation 
2695         _pts->SetPoint(0,       -1000   , -1000 , -1000 );
2696         _pts->SetPoint(1,       1000    , 1000  , 1000 );
2697
2698         vtkCellArray *lines = vtkCellArray::New();
2699         lines->InsertNextCell( nps /* +1 */ );
2700         for ( i=0 ; i<nps+1 ; i++ ){
2701                 lines->InsertCellPoint(i % nps );
2702         }
2703
2704         _pd = vtkPolyData::New();
2705         _pd->SetPoints( _pts );
2706         _pd->SetLines( lines );
2707         lines->Delete();  //do not delete lines ??
2708
2709         _contourVtkActor        =       vtkActor::New();
2710     _bboxMapper                 =       vtkPolyDataMapper::New();
2711     _bboxMapper->ScalarVisibilityOff( );
2712
2713         _bboxMapper->SetInput(_pd);
2714         _bboxMapper->ImmediateModeRenderingOn();
2715         _contourVtkActor->SetMapper(_bboxMapper);
2716         _contourVtkActor->GetProperty()->BackfaceCullingOff();
2717
2718         UpdateColorActor();
2719
2720         _pd->ComputeBounds();
2721
2722         //      Text
2723         _textActor = vtkTextActor::New();
2724 //      _textActor->SetDisplayPosition(200, 200);
2725         _textActor->SetInput("");
2726         // Set coordinates to match the old vtkScaledTextActor default value
2727 //      _textActor->GetPosition2Coordinate()->SetCoordinateSystemToNormalizedViewport();
2728 //      _textActor->GetPosition2Coordinate()->SetValue( 0.2 , 0.2 );
2729         _textActor->GetPositionCoordinate()->SetCoordinateSystemToWorld ();
2730 //      _textActor->GetPositionCoordinate()->SetValue( 0.8 , 0.8 );
2731
2732         vtkTextProperty *tprop = _textActor->GetTextProperty();
2733         tprop->SetFontSize(14);
2734         tprop->SetFontFamilyToArial();
2735         tprop->SetColor(0, 0, 1);       
2736 }
2737 // ----------------------------------------------------------------------------
2738 void manualViewBaseContour::CreateNewContour()
2739 {
2740         ConstructVTKObjects();
2741         /*
2742         _wxvtkbaseview->GetRenderer()->AddActor( _contourVtkActor );
2743         _wxvtkbaseview->GetRenderer()->AddActor2D(_textActor);*/
2744         AddCompleteContourActor();
2745 }
2746 // ----------------------------------------------------------------------------
2747 void manualViewBaseContour::UpdateViewPoint(int id) // virtual
2748 {  
2749         manualPoint             *mp             = _manContModel->GetManualPoint(id);
2750
2751 //EEDx6
2752                         double XX=mp->GetX(),YY=mp->GetY(),ZZ=mp->GetZ();
2753 //                      wxVtk2DBaseView *wxvtk2Dbasevie = (wxVtk2DBaseView*)this->GetWxVtkBaseView();
2754 //                      wxvtk2Dbasevie->TransformCoordinate_spacing_ModelToView(XX,YY,ZZ);
2755
2756         _lstViewPoints[id]->SetPositionXY( XX , YY ,_range, ZZ );
2757 }
2758
2759 // ----------------------------------------------------------------------------
2760 void manualViewBaseContour :: UpdateViewPoints()
2761 {
2762         int id, size = _lstViewPoints.size();
2763         for( id=0; id<size; id++)
2764         {
2765                 UpdateViewPoint( id );
2766         }
2767 }
2768
2769 // ----------------------------------------------------------------------------
2770 void manualViewBaseContour::AddPoint()
2771 {
2772         manualViewPoint *mvp    = new manualViewPoint( this->GetWxVtkBaseView() );
2773         AddPoint( mvp );
2774 }
2775 // ----------------------------------------------------------------------------
2776 void manualViewBaseContour::AddPoint( manualViewPoint * manualViewPoint )
2777 {
2778         _lstViewPoints.push_back( manualViewPoint );
2779
2780         // EED 3 oct 2006
2781         manualViewPoint->SetSpacing(_spc);
2782
2783         vtkActor *actor = manualViewPoint->CreateVtkPointActor();
2784         _wxvtkbaseview->GetRenderer()->AddActor( actor );
2785 }
2786
2787 // ----------------------------------------------------------------------------
2788 void manualViewBaseContour::InsertPoint(int id)
2789 {
2790         manualViewPoint         *mvp    = new manualViewPoint( this->GetWxVtkBaseView() );
2791
2792 // EED 3 oct 2006
2793         mvp->SetSpacing(_spc);
2794
2795         std::vector<manualViewPoint*>::iterator itNum = _lstViewPoints.begin() + id;
2796         _lstViewPoints.insert(itNum,mvp);
2797         _wxvtkbaseview->GetRenderer()->AddActor( mvp->CreateVtkPointActor() );
2798 }
2799 // ----------------------------------------------------------------------------
2800 void manualViewBaseContour::DeleteContour()
2801 {
2802         RemoveCompleteContourActor();
2803         /*if (_contourVtkActor!=NULL){
2804                 _wxvtkbaseview->GetRenderer()->RemoveActor( _contourVtkActor );
2805         }*/
2806         DeleteVtkObjects();
2807         int i,size=_lstViewPoints.size();
2808         for (i=0;i<size;i++){
2809                 manualViewBaseContour::DeletePoint(0);
2810         }
2811         Refresh();
2812 }
2813 // ----------------------------------------------------------------------------
2814 void manualViewBaseContour::DeletePoint(int id) // virtual 
2815
2816         int size=_lstViewPoints.size();
2817         if ( (id>=0) && (id<size) ){
2818                 manualViewPoint         *mvp    =_lstViewPoints[id];
2819 //EED ups1
2820 //              _handlePicker->DeletePickList(mvp->GetVtkActor());
2821                 _wxvtkbaseview->GetRenderer()->RemoveActor( mvp->GetVtkActor() );
2822                 std::vector<manualViewPoint*>::iterator itNum = _lstViewPoints.begin() + id;
2823                 _lstViewPoints.erase(itNum);
2824                 delete mvp;
2825                 Refresh();
2826         }
2827 }
2828 // ----------------------------------------------------------------------------
2829 void manualViewBaseContour::DeletePoint(int x, int y, int z)
2830 {
2831         int id=GetIdPoint(x,y,z);
2832         if (id!=-1){
2833                 DeletePoint(id);
2834         }
2835 }
2836 // ----------------------------------------------------------------------------
2837 void manualViewBaseContour::SetSelected(bool selected)
2838 {
2839         _selected=selected;
2840 }
2841 // ----------------------------------------------------------------------------
2842 void manualViewBaseContour::SetPosibleSelected(bool posibleSelected)
2843 {
2844         _posibleSelected=posibleSelected;       
2845 }
2846 // ----------------------------------------------------------------------------
2847 bool manualViewBaseContour::GetEditable()
2848 {
2849         return *_editable;
2850 }
2851 // ----------------------------------------------------------------------------
2852 void manualViewBaseContour::SetEditable( bool * condition )
2853 {
2854         _editable = condition;
2855 }
2856 // ----------------------------------------------------------------------------
2857 bool manualViewBaseContour::GetSelected()
2858 {
2859         return _selected;
2860 }
2861 // ----------------------------------------------------------------------------
2862 bool manualViewBaseContour::GetPosibleSelected()
2863 {
2864         return _posibleSelected;
2865 }
2866 // ----------------------------------------------------------------------------
2867 void manualViewBaseContour::DeleteSelectedPoints()
2868 {
2869         int i,size=_lstViewPoints.size();
2870         for (i=size-1;i>=0;i--){
2871                 if (_lstViewPoints[i]->GetSelected()==true){
2872                         DeletePoint(i);
2873                 }
2874         }
2875         Refresh();
2876 }
2877 // ----------------------------------------------------------------------------
2878 void manualViewBaseContour::SelectPoint(int i, bool select)
2879 {
2880         _lstViewPoints[i]->SetSelected(select);
2881 }
2882 // ----------------------------------------------------------------------------
2883 void manualViewBaseContour::SelectLstPoints()
2884 {
2885         // ToDo
2886 }
2887 // ----------------------------------------------------------------------------
2888 void manualViewBaseContour::SelectAllPoints(bool select)
2889 {
2890         int i,size=_lstViewPoints.size();
2891         for (i=0;i<size;i++){
2892                 SelectPoint(i,select);
2893         }
2894 }
2895 //-----------------------------------------------------------------------------
2896 void manualViewBaseContour:: SetIfViewControlPoints(bool ifShow)
2897 {       
2898         _viewControlPoints = ifShow;    
2899 }
2900 // ----------------------------------------------------------------------------
2901 bool manualViewBaseContour:: GetIfViewControlPoints()
2902 {
2903         return _viewControlPoints;
2904 }
2905
2906 // ----------------------------------------------------------------------------
2907 void manualViewBaseContour::SetPointPosibleSelected(int id,bool select)
2908 {
2909         _lstViewPoints[id]->SetPosibleSelected(select);
2910 }
2911 // ----------------------------------------------------------------------------
2912 void manualViewBaseContour::SetPointSelected(int id,bool select)
2913 {
2914         _lstViewPoints[id]->SetSelected(select);
2915 }
2916 // ----------------------------------------------------------------------------
2917 void manualViewBaseContour::SelectAllPossibleSelected(bool select)
2918 {
2919         int i,size=_lstViewPoints.size();
2920         for (i=0;i<size;i++){
2921                 SetPointPosibleSelected(i,select);
2922         }
2923 }
2924 // ----------------------------------------------------------------------------
2925 int manualViewBaseContour::SelectPosiblePoint(int x, int y, int z)  // virtual
2926 {
2927         SelectAllPossibleSelected(false);
2928
2929     int id = GetIdPoint(x,y,z);
2930         if (id!=-1)
2931         {
2932                 SetPointPosibleSelected(id,true);
2933         }
2934         return id;
2935 }
2936 // ----------------------------------------------------------------------------
2937 bool manualViewBaseContour::SelectPosibleContour(int x, int y, int z)
2938 {
2939         bool result=false;
2940         SetPosibleSelected(result);
2941     int id = GetIdPoint(x,y,z);
2942         if( !GetEditable() && !_selected && id!= -1)
2943         {
2944                 result=true;
2945                 SetPosibleSelected(result);
2946         }
2947         else
2948         {
2949                 if ( (GetEditable()==true) && (id==-1 ) && (this->_lstViewPoints.size()>=2) )
2950                 {
2951                         if (ifTouchContour(x,y,z)==true)
2952                         {
2953                                 result=true;
2954                                 SetPosibleSelected(result);
2955                         }
2956                 }
2957
2958                 if (GetEditable()==false)
2959                 {
2960                         if (ifTouchContour(x,y,z)==true)
2961                         {
2962                                 result=true;
2963                                 SetPosibleSelected(result);
2964                         }
2965                 }
2966         
2967
2968         }
2969         return result;
2970 }
2971 // ----------------------------------------------------------------------------
2972 bool manualViewBaseContour::ifTouchContour(int x,int y, int z) // virtual
2973 {
2974         return false;
2975 }
2976 // ----------------------------------------------------------------------------
2977 void manualViewBaseContour::UnSelectPoint(int i){
2978         _lstViewPoints[i]->SetSelected(false);
2979         Refresh();
2980 }
2981 // ----------------------------------------------------------------------------
2982 void manualViewBaseContour::UnSelectLstPoints(){
2983         // ToDo
2984 }
2985 // ----------------------------------------------------------------------------
2986 void manualViewBaseContour::UnSelectAllPoints(){
2987         int i,size=_lstViewPoints.size();
2988         for (i=0;i<size;i++){
2989                 UnSelectPoint(i);
2990         }
2991         Refresh();
2992 }
2993 // ----------------------------------------------------------------------------
2994 void manualViewBaseContour::SetModel(manualContourModel *manContModel){
2995         _manContModel=manContModel;
2996 }
2997 // ----------------------------------------------------------------------------
2998 void manualViewBaseContour::SetWxVtkBaseView(wxVtkBaseView *wxvtkbaseview){
2999         _wxvtkbaseview = wxvtkbaseview;
3000 }
3001 // ----------------------------------------------------------------------------
3002 void manualViewBaseContour::RefreshContour()  // Virtual
3003 {
3004 }
3005 // ----------------------------------------------------------------------------
3006 double* manualViewBaseContour::GetVectorPointsXManualContour(){
3007         double pp[3];
3008         int i,size = _sizePointsContour;
3009         double *vx = (double*)malloc(sizeof(double)*size);
3010         for (i=0;i<size;i++){
3011                 _pts->GetPoint(i,pp);
3012                 vx[i]=pp[0];
3013         }       
3014         return vx;
3015 }
3016 // ----------------------------------------------------------------------------
3017 double* manualViewBaseContour::GetVectorPointsYManualContour()
3018 {
3019         double pp[3];
3020         int i,size = _sizePointsContour;
3021         double *vy = (double*)malloc(sizeof(double)*size);
3022         for (i=0;i<size;i++){
3023                 _pts->GetPoint(i,pp);
3024                 vy[i]=pp[1];
3025         }       
3026         return vy;
3027 }
3028 // ----------------------------------------------------------------------------
3029 double* manualViewBaseContour::GetVectorPointsZManualContour()
3030 {
3031         double pp[3];
3032         int i,size = _sizePointsContour;
3033         double *vz = (double*)malloc(sizeof(double)*size);
3034         for (i=0;i<size;i++){
3035                 _pts->GetPoint(i,pp);
3036                 vz[i]=pp[2];
3037         }       
3038         return vz;
3039 }
3040 // ----------------------------------------------------------------------------
3041 void manualViewBaseContour::Refresh() // virtual
3042 {
3043         if (_contourVtkActor!=NULL){
3044                 RefreshContour();
3045         }
3046         int i,size=_lstViewPoints.size();
3047         for (i=0;i<size;i++){
3048                 UpdateViewPoint(i);
3049                 _lstViewPoints[i]->UpdateColorActor();
3050         }
3051         UpdateColorActor();
3052
3053         if (_show_text==true) 
3054         {
3055                 RefreshText();
3056         }
3057
3058         vtkRenderWindowInteractor *vri = _wxvtkbaseview->GetWxVTKRenderWindowInteractor ();
3059         if (vri==NULL)
3060         {
3061                 _wxvtkbaseview->GetRenWin()->Render();
3062         }
3063
3064 }
3065 // ----------------------------------------------------------------------------
3066 void manualViewBaseContour::RefreshText()  // virtual
3067 {
3068         if( _textActor!=NULL)
3069                 _textActor -> SetInput(" ");
3070 }
3071 // ----------------------------------------------------------------------------
3072 void manualViewBaseContour::SetColorNormalContour(double r, double g, double b)
3073 {
3074         _coulorNormal_r = r;
3075         _coulorNormal_g = g;
3076         _coulorNormal_b = b;
3077 }
3078 // ----------------------------------------------------------------------------
3079 void manualViewBaseContour::GetColorNormalContour(double &r, double &g, double &b)
3080 {
3081         r = _coulorNormal_r;
3082         g = _coulorNormal_g;
3083         b = _coulorNormal_b;
3084 }
3085 // ----------------------------------------------------------------------------
3086 void manualViewBaseContour::SetColorEditContour(double r, double g, double b)
3087 {
3088         _coulorEdit_r = r;
3089         _coulorEdit_g = g;
3090         _coulorEdit_b = b;
3091 }
3092 // ----------------------------------------------------------------------------
3093 void manualViewBaseContour::GetColorEditContour(double &r, double &g, double &b)
3094 {
3095         r = _coulorEdit_r;
3096         g = _coulorEdit_g;
3097         b = _coulorEdit_b;
3098 }
3099 // ----------------------------------------------------------------------------
3100 void manualViewBaseContour::SetColorSelectContour(double r, double g, double b)
3101 {
3102         _coulorSelection_r = r;
3103         _coulorSelection_g = g;
3104         _coulorSelection_b = b;
3105 }
3106 // ----------------------------------------------------------------------------
3107 void manualViewBaseContour::GetColorSelectContour(double &r, double &g, double &b)
3108 {
3109         r = _coulorSelection_r;
3110         g = _coulorSelection_g;
3111         b = _coulorSelection_b;
3112 }
3113 // ----------------------------------------------------------------------------
3114 void manualViewBaseContour::UpdateColorActor()
3115 {
3116         if (_contourVtkActor!=NULL)
3117         {
3118                 _contourVtkActor->GetProperty()->SetLineWidth( _widthline );
3119                 _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorNormal_r , _coulorNormal_g , _coulorNormal_b );
3120                 if (_posibleSelected || (_posibleSelected && GetEditable() ) )
3121                 {
3122                         _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorEdit_r , _coulorEdit_g , _coulorEdit_b );
3123                 }
3124                 if( _selected )
3125                 {
3126                         _contourVtkActor->GetProperty()->SetDiffuseColor( _coulorSelection_r , _coulorSelection_g , _coulorSelection_b );
3127                 }
3128         }
3129 }
3130 // ----------------------------------------------------------------------------
3131 int     manualViewBaseContour::GetIdPoint(int x, int y, int z) // virtual
3132 {
3133         int ii = -1;
3134         if (_manContModel!=NULL){
3135                 double xx = x;
3136                 double yy = y;
3137                 double zz = z;
3138                 TransfromeCoordViewWorld(xx,yy,zz);
3139                 ii=_manContModel->GetIdPoint(xx,yy,zz,_range,-1);
3140         }
3141         return ii;
3142 }
3143
3144 // ----------------------------------------------------------------------------
3145
3146
3147 int manualViewBaseContour::GetNumberOfPoints()
3148 {
3149         return _lstViewPoints.size();
3150 }
3151
3152 // ----------------------------------------------------------------------------
3153
3154 //JSTG 25-02-08 ---------------------------------------------------------------
3155 /*int manualViewBaseContour::GetNumberOfPointsSpline()
3156 {
3157         return _sizePointsContour;
3158 }*/
3159 //----------------------------------------------------------------------------
3160
3161 //JSTG 25-02-08 ---------------------------------------------------------------
3162 /*void manualViewBaseContour::SetNumberOfPointsSpline(int size)
3163 {
3164         _sizePointsContour = size;
3165 }*/
3166 //----------------------------------------------------------------------------
3167 // virtual
3168 void manualViewBaseContour::TransfromeCoordViewWorld(double &X, double &Y, double &Z, int type)  // Virtual
3169 {
3170         _wxvtkbaseview->TransfromeCoordScreenToWorld(X, Y, Z, type);
3171
3172
3173 //EED 27 sep 2007
3174 //   //EEDx6
3175 //      wxVtk2DBaseView *wxvtk2Dbaseview = (wxVtk2DBaseView*)_wxvtkbaseview;
3176 //      wxvtk2Dbaseview->TransformCoordinate_spacing_ModelToView(X,Y,Z); 
3177
3178 }
3179 // ----------------------------------------------------------------------------
3180 void manualViewBaseContour::SetRange(int range)
3181 {
3182         _range=range;
3183 }
3184 // ----------------------------------------------------------------------------
3185 int     manualViewBaseContour::GetRange()
3186 {
3187         return _range;
3188 }
3189 // ----------------------------------------------------------------------------
3190 void manualViewBaseContour::SetZ(int z)
3191 {
3192 //      _Z=z;
3193 }
3194 // ----------------------------------------------------------------------------
3195 int     manualViewBaseContour::GetZ()
3196 {
3197 //      return _Z;
3198         return 0;
3199 }
3200 // ----------------------------------------------------------------------------
3201 void manualViewBaseContour::InitMove(int x, int y, int z) // virtual
3202 {
3203
3204 }
3205 // ----------------------------------------------------------------------------
3206 void manualViewBaseContour::MoveContour(int x, int y, int z) // virtual
3207 {       
3208 }
3209 // ----------------------------------------------------------------------------
3210 void manualViewBaseContour::MoveContour(int horizontalUnits, int verticalUnits )// virtual
3211 {
3212
3213 }
3214 // ----------------------------------------------------------------------------
3215 void manualViewBaseContour::GetMinMax( double &minX,double &minY, double &minZ, double &maxX, double &maxY, double &maxZ )// virtual
3216 {
3217         double  pp[3];
3218         manualPoint *mp;  
3219         int i;
3220         int size=_manContModel->GetSizeLstPoints();
3221         minX=99999;
3222         minY=99999;
3223         maxX=-99999;
3224         maxY=-99999;
3225         bool ifFindZ = minZ!=-1.0 && maxZ!=-1.0;
3226         if ( ifFindZ )
3227         {
3228                 minZ=99999;
3229                 maxZ=-99999;
3230         }
3231         for( i = 0; i < size; i++ ) 
3232         {
3233                 mp=_manContModel->GetManualPoint(i);
3234                 pp[0]=mp->GetX();
3235                 pp[1]=mp->GetY();
3236                 if ( ifFindZ )
3237                         pp[2]=mp->GetZ();
3238  
3239                 // min X
3240                 if (pp[0]<minX) 
3241                 {
3242                         minX=pp[0];
3243                 }
3244                 //min Y
3245                 if (pp[1]<minY) 
3246                 {
3247                         minY=pp[1];
3248                 }
3249                 //max X
3250                 if (pp[0]>maxX) 
3251                 {
3252                         maxX=pp[0];
3253                 }
3254                 // max Y
3255                 if (pp[1]>maxY) 
3256                 {
3257                         maxY=pp[1];
3258                 }
3259                 if ( ifFindZ )
3260                 {
3261                         // min Z
3262                         if (pp[2]<minZ) 
3263                         {
3264                                 minZ=pp[2];
3265                         }
3266                         // max Z
3267                         if (pp[2]>maxZ) 
3268                         {
3269                                 maxZ=pp[2];
3270                         }
3271                 }               
3272         }
3273         if ( size<1 )
3274         {
3275                 minX = 0;
3276                 maxX = 0;
3277
3278                 minY = 0;
3279                 maxY = 0;
3280
3281                 minZ = 0;
3282                 maxZ = 0;
3283         }
3284 }
3285 // ----------------------------------------------------------------------------
3286 void manualViewBaseContour::ClearContour()
3287 {
3288         if (_contourVtkActor!=NULL){
3289                 _wxvtkbaseview->GetRenderer()->RemoveActor( _contourVtkActor );
3290         }
3291         DeleteVtkObjects();
3292         int i,size=_lstViewPoints.size();
3293         for (i=0;i<size;i++){
3294                 ClearPoint(0);
3295         }
3296         Refresh();
3297 }
3298 // ----------------------------------------------------------------------------
3299 void manualViewBaseContour::ClearPoint(int id)
3300 {
3301         DeletePoint(id);
3302 }
3303 // ----------------------------------------------------------------------------
3304 void manualViewBaseContour::SetVisible(bool ok)
3305 {
3306         double opacity;
3307         if (ok==true)
3308         {
3309                 opacity=1;
3310         } else {
3311                 opacity=0;
3312         }
3313
3314         vtkActor *actor;
3315         int i,size=_lstViewPoints.size();
3316         for (i=0;i<size;i++){
3317                 actor = _lstViewPoints[i]->GetVtkActor();
3318                 actor->GetProperty()->SetOpacity( opacity );
3319         }
3320         _contourVtkActor->GetProperty()->SetOpacity( opacity );
3321         _textActor->GetProperty()->SetOpacity( opacity );
3322         _textActor->SetInput(" ");
3323
3324 }
3325 // ----------------------------------------------------------------------------
3326 void manualViewBaseContour::SetShowText(bool ok)
3327 {
3328         _show_text = ok;
3329         if (_show_text==false)
3330         {
3331                 _textActor->SetInput(" ");
3332         }
3333 }
3334 // ----------------------------------------------------------------------------
3335 wxVtkBaseView *manualViewBaseContour::GetWxVtkBaseView()
3336 {
3337         return this->_wxvtkbaseview;
3338 }
3339 // ----------------------------------------------------------------------------
3340 void manualViewBaseContour::GetSpacing(double spc[3])
3341 {
3342         spc[0] = _spc[0];
3343         spc[1] = _spc[1];
3344         spc[2] = _spc[2];
3345 }
3346 // ----------------------------------------------------------------------------
3347 void manualViewBaseContour::SetSpacing(double spc[3])
3348 {
3349         _spc[0] = spc[0];
3350         _spc[1] = spc[1];
3351         _spc[2] = spc[2];
3352 }
3353
3354
3355 // ----------------------------------------------------------------------------
3356 // ----------------------------------------------------------------------------
3357 // ----------------------------------------------------------------------------
3358
3359 // _type = 0  Sagital  
3360 // _type = 1  Coronal 
3361 // _type = 2  Axial   
3362 // _type = -1 View 3D
3363
3364 manualContour3VControler::manualContour3VControler(int type)
3365 {
3366         _type=type;
3367
3368 //EEDhh
3369 //      _manViewBaseCont1 = NULL;
3370 //      _manViewBaseCont2 = NULL;
3371 //      _manViewBaseCont3 = NULL;
3372 }
3373 //----------------------------------------------------------------------------
3374 manualContour3VControler::~manualContour3VControler()
3375 {
3376 }
3377
3378 // ----------------------------------------------------------------------------
3379 manualContour3VControler * manualContour3VControler :: Clone()  // virtual 
3380 {
3381         manualContour3VControler * clone = new manualContour3VControler( this->GetType() );
3382         CopyAttributesTo(clone);
3383         return clone;
3384 }
3385
3386 // ---------------------------------------------------------------------------
3387 void manualContour3VControler::CopyAttributesTo( manualContour3VControler * cloneObject)
3388 {
3389         // Fathers object
3390         manualContourControler::CopyAttributesTo(cloneObject);
3391
3392         cloneObject->SetVtkMPRBaseData( this->GetVtkMPRBaseData() );
3393
3394         // Remember to add ManualViewBaseContour with "AddManualViewBaseContour"
3395
3396 }
3397 // ----------------------------------------------------------------------------
3398 int manualContour3VControler::GetType()
3399 {
3400         return _type;
3401 }
3402
3403 // ----------------------------------------------------------------------------
3404 void manualContour3VControler::AddPoint_Others()
3405 {
3406         manualViewBaseContour *mvbc;
3407         int i,size=this->_lstManualViewBaseContour.size();
3408         for ( i = 0 ; i < size ; i++ )
3409         {
3410                 mvbc = _lstManualViewBaseContour[i]; 
3411                 mvbc->AddPoint();
3412         }
3413
3414 // EEDhh
3415 //      if (_manViewBaseCont1!=NULL){
3416 //              _manViewBaseCont1->AddPoint(); 
3417 //              _manViewBaseCont2->AddPoint(); 
3418 //              _manViewBaseCont3->AddPoint();
3419 //              this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
3420 //      }
3421
3422         this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
3423 }
3424 // ----------------------------------------------------------------------------
3425 void manualContour3VControler::AddPoint( int x, int y, int z ) // virtual
3426 {
3427
3428         z=(int)_vtkmprbasedata->GetZ();
3429         if (GetManualContourModel()!=NULL){
3430                 double  xx      = x;
3431                 double  yy      = y;
3432                 double  zz      = z;
3433                 GetManualViewBaseContour()->TransfromeCoordViewWorld(xx,yy,zz,_type);
3434
3435                 if (_type==0)
3436                 {
3437                         xx=_vtkmprbasedata->GetX();
3438                 }
3439
3440                 if (_type==1)
3441                 {
3442                         yy=_vtkmprbasedata->GetY();
3443                 }
3444
3445
3446                 int     id              = GetManualContourModel()->AddPoint(xx,yy,zz);
3447                 GetManualViewBaseContour()->AddPoint(); 
3448                 AddPoint_Others();
3449
3450         }
3451 }
3452
3453 // ----------------------------------------------------------------------------
3454 void manualContour3VControler::InsertPoint_Others(int id)
3455 {
3456
3457         manualViewBaseContour *mvbc;
3458         int i,size=this->_lstManualViewBaseContour.size();
3459         for ( i = 0 ; i < size ; i++ )
3460         {
3461                 mvbc = _lstManualViewBaseContour[i]; 
3462                 mvbc->InsertPoint(id);
3463         }
3464
3465 /*EEDhh
3466         if (_manViewBaseCont1!=NULL){
3467                 _manViewBaseCont1->InsertPoint(id);                             
3468                 _manViewBaseCont2->InsertPoint(id);                             
3469                 _manViewBaseCont3->InsertPoint(id);                             
3470                 this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
3471         }
3472 */
3473
3474         this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
3475
3476 }
3477 // ----------------------------------------------------------------------------
3478 void manualContour3VControler::InsertPoint(int x, int y, int z)
3479 {
3480         int id=-1;
3481         if (GetManualContourModel()!=NULL){
3482                 if (GetManualContourModel()->GetSizeLstPoints()>1){
3483                         z=(int)_vtkmprbasedata->GetZ();
3484                         double                          xx              = x;
3485                         double                          yy              = y;
3486                         double                          zz              = z;
3487                         GetManualViewBaseContour()->TransfromeCoordViewWorld(xx,yy,zz,_type);
3488                         if (_type==0)
3489                         {
3490                                 xx=_vtkmprbasedata->GetX();
3491                         }       
3492
3493                         if (_type==1)
3494                         {
3495                                 yy=_vtkmprbasedata->GetY();
3496                         }
3497
3498                         id      = GetManualContourModel()->InsertPoint(xx,yy,zz);
3499
3500                         GetManualViewBaseContour()->InsertPoint(id);    
3501                         InsertPoint_Others(0);  
3502
3503                 } else {
3504                         AddPoint(x,y,z);        
3505                 }
3506         }
3507 }
3508 // ----------------------------------------------------------------------------
3509
3510 // EEDhh
3511 /*
3512 void manualContour3VControler::SetModelView (   manualContourModel *manContModel, 
3513                                                                                                 manualViewBaseContour *manViewBaseCont0, 
3514                                                                                                 manualViewBaseContour *manViewBaseCont1, 
3515                                                                                                 manualViewBaseContour *manViewBaseCont2,
3516                                                                                                 manualViewBaseContour *manViewBaseCont3)
3517 {
3518         manualContourControler::SetModelView(manContModel,manViewBaseCont0);
3519         _manViewBaseCont1 = manViewBaseCont1;
3520         _manViewBaseCont2 = manViewBaseCont2;
3521         _manViewBaseCont3 = manViewBaseCont3;
3522 }
3523 */
3524
3525 // ----------------------------------------------------------------------------
3526 void manualContour3VControler::AddManualViewBaseContour( manualViewBaseContour *manViewBaseCont )
3527 {
3528         _lstManualViewBaseContour.push_back( manViewBaseCont );
3529 }
3530
3531 // ----------------------------------------------------------------------------
3532 void manualContour3VControler::SetVtkMPRBaseData (vtkMPRBaseData *vtkmprbasedata )
3533 {
3534         _vtkmprbasedata=vtkmprbasedata;
3535 }
3536 // ----------------------------------------------------------------------------
3537 vtkMPRBaseData *manualContour3VControler::GetVtkMPRBaseData()
3538 {
3539         return _vtkmprbasedata;
3540 }
3541 // ----------------------------------------------------------------------------
3542 void manualContour3VControler::SetPoint( int id ,int x ,int y ,int z ) // virtual
3543 {
3544         z=(int)_vtkmprbasedata->GetZ();
3545         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
3546                 double xx = x;
3547                 double yy = y;
3548                 double zz = z;
3549                 GetManualViewBaseContour()->TransfromeCoordViewWorld(xx,yy,zz,_type);
3550
3551                 if (_type==0)
3552                 {
3553                         xx=_vtkmprbasedata->GetX();
3554                 }
3555                 if (_type==1)
3556                 {
3557                         yy=_vtkmprbasedata->GetY();
3558                 }
3559
3560                 manualPoint     *mp     = GetManualContourModel()->GetManualPoint(id);
3561                 mp->SetPoint(xx,yy,zz);
3562
3563         }
3564 }
3565 // ----------------------------------------------------------------------------
3566 void manualContour3VControler::DeleteActualMousePoint_Others(int id)
3567 {
3568         manualViewBaseContour *mvbc;
3569         int i,size=this->_lstManualViewBaseContour.size();
3570         for ( i = 0 ; i < size ; i++ )
3571         {
3572                 mvbc = _lstManualViewBaseContour[i]; 
3573                 mvbc->DeletePoint(id);  
3574                 mvbc->Refresh();
3575         }
3576
3577 /*
3578         if (_manViewBaseCont1!=NULL){
3579                 _manViewBaseCont1->DeletePoint(id);  
3580                 _manViewBaseCont2->DeletePoint(id);  
3581                 _manViewBaseCont3->DeletePoint(id);
3582         
3583                 _manViewBaseCont1->Refresh();
3584                 _manViewBaseCont2->Refresh();
3585                 _manViewBaseCont3->Refresh();
3586                 
3587                 this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
3588         }
3589 */
3590         this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
3591 }
3592 // ----------------------------------------------------------------------------
3593 void manualContour3VControler::DeleteActualMousePoint(int x, int y)// virtual
3594
3595         int id=GetManualViewBaseContour()->GetIdPoint ( x , y , GetZ() );
3596         if (id!=-1){
3597                 manualContourBaseControler::DeleteActualMousePoint( x , y );
3598                 DeleteActualMousePoint_Others( id );
3599         }
3600 }
3601 // ----------------------------------------------------------------------------
3602 void manualContour3VControler::MouseMove_Others(int id) // virtual
3603 {
3604         manualViewBaseContour *mvbc;
3605         int i,size=this->_lstManualViewBaseContour.size();
3606         for ( i = 0 ; i < size ; i++ )
3607         {
3608                 mvbc = _lstManualViewBaseContour[i]; 
3609                 mvbc->SelectAllPossibleSelected(false);
3610                 if (id!=-1)
3611                 {       
3612                         mvbc->SetPointPosibleSelected(id,true);
3613                 }
3614                 mvbc->SetPosibleSelected  (  GetManualViewBaseContour()->GetPosibleSelected()  );   
3615                 mvbc->Refresh();
3616         }
3617         
3618 // EEDhh
3619 /*      
3620         if (_manViewBaseCont1!=NULL){
3621                 _manViewBaseCont1->SelectAllPossibleSelected(false);
3622                 _manViewBaseCont2->SelectAllPossibleSelected(false);
3623                 _manViewBaseCont3->SelectAllPossibleSelected(false);
3624                 if (id!=-1){            
3625                         _manViewBaseCont1->SetPointPosibleSelected(id,true);
3626                         _manViewBaseCont2->SetPointPosibleSelected(id,true);
3627                         _manViewBaseCont3->SetPointPosibleSelected(id,true);
3628                 } 
3629                 _manViewBaseCont1->SetPosibleSelected  (  GetManualViewBaseContour()->GetPosibleSelected()  );   
3630                 _manViewBaseCont2->SetPosibleSelected  (  GetManualViewBaseContour()->GetPosibleSelected()  );   
3631                 _manViewBaseCont3->SetPosibleSelected  (  GetManualViewBaseContour()->GetPosibleSelected()  );   
3632
3633                 _manViewBaseCont1->Refresh();
3634                 _manViewBaseCont2->Refresh();
3635                 _manViewBaseCont3->Refresh();
3636
3637                 this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
3638         }
3639 */
3640         this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
3641
3642 }
3643
3644 // ----------------------------------------------------------------------------
3645 void manualContour3VControler::MouseMove(int x, int y) // virtual
3646 {
3647         manualContourControler::MouseMove( x , y );
3648         int id=GetManualViewBaseContour()->GetIdPoint(x,y,GetZ());
3649         MouseMove_Others( id );
3650 }
3651
3652 // ----------------------------------------------------------------------------
3653 void manualContour3VControler::OnChar_Others()
3654 {
3655         manualViewBaseContour *mvbc;
3656         int i,size=this->_lstManualViewBaseContour.size();
3657         for ( i = 0 ; i < size ; i++ )
3658         {
3659                 mvbc = _lstManualViewBaseContour[i]; 
3660                 mvbc->Refresh();
3661         }
3662 // EEDhh
3663 /*
3664                 _manViewBaseCont1->Refresh();
3665                 _manViewBaseCont2->Refresh();
3666                 _manViewBaseCont3->Refresh();
3667 */
3668         this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
3669 }
3670 // ----------------------------------------------------------------------------
3671 bool manualContour3VControler::OnChar()
3672 {
3673         manualContourControler::OnChar();
3674         OnChar_Others();
3675         return true;
3676 }
3677 // ----------------------------------------------------------------------------
3678 void manualContour3VControler::ResetContour() // virtual
3679 {
3680         manualContourControler::ResetContour();
3681         ResetContour_Others();
3682 }
3683
3684 // ----------------------------------------------------------------------------
3685 void manualContour3VControler::ResetContour_Others()
3686 {
3687         manualViewBaseContour *mvbc;
3688         int i,size=this->_lstManualViewBaseContour.size();
3689         for ( i = 0 ; i < size ; i++ )
3690         {
3691                 mvbc = _lstManualViewBaseContour[i]; 
3692                 mvbc->DeleteContour();
3693                 mvbc->CreateNewContour();
3694         }
3695
3696 // EEDhh
3697 /*
3698         _manViewBaseCont1->DeleteContour();
3699         _manViewBaseCont2->DeleteContour();
3700         _manViewBaseCont3->DeleteContour();
3701         _manViewBaseCont1->CreateNewContour();
3702         _manViewBaseCont2->CreateNewContour();
3703         _manViewBaseCont3->CreateNewContour();
3704 */
3705 }
3706
3707 // ----------------------------------------------------------------------------
3708 // ----------------------------------------------------------------------------
3709 // ----------------------------------------------------------------------------
3710 manualContour3DControler::manualContour3DControler()
3711 {
3712 }
3713 // ----------------------------------------------------------------------------
3714 manualContour3DControler::~manualContour3DControler()
3715 {
3716 }
3717 // ----------------------------------------------------------------------------
3718 manualContour3DControler * manualContour3DControler :: Clone()  // virtual 
3719 {
3720         manualContour3DControler * clone = new manualContour3DControler();
3721         CopyAttributesTo(clone);
3722         return clone;
3723 }
3724
3725 // ---------------------------------------------------------------------------
3726 void manualContour3DControler::CopyAttributesTo( manualContour3DControler * cloneObject)
3727 {
3728         // Fathers object
3729         manualContourControler::CopyAttributesTo(cloneObject);
3730
3731         cloneObject->SetVtkMPRBaseData( this->GetVtkMPRBaseData() );
3732 }
3733
3734 // ----------------------------------------------------------------------------
3735 bool  manualContour3DControler::OnLeftButtonDown()
3736 {
3737         int X,Y;
3738         wxVTKRenderWindowInteractor *wxVTKiren;
3739         wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk3DBaseView()->GetWxVTKRenderWindowInteractor();
3740         wxVTKiren->GetEventPosition(X,Y);
3741         MouseClickLeft(X,Y);
3742         return true;
3743 }
3744 // ----------------------------------------------------------------------------
3745 void manualContour3DControler::ResetOrientationPlane()
3746 {
3747         double p[3],rp[3],rn[3];
3748         p[0] = this->GetVtkMPRBaseData()->GetX(  );
3749         p[1] = this->GetVtkMPRBaseData()->GetY(  );
3750         p[2] = this->GetVtkMPRBaseData()->GetZ(  );
3751         this->GetManualContourModel()->GetNearestPointAndNormal(p,rp,rn);
3752         this->GetVtkMPRBaseData()->SetNormal(rn[0],rn[1],rn[2]);
3753 }
3754 // ----------------------------------------------------------------------------
3755 void manualContour3DControler::MouseClickLeft(int x, int y) // virtual
3756 {
3757         manualView3DContour *manualview3Dcontour=(manualView3DContour*)GetManualViewBaseContour();
3758         int id=manualview3Dcontour->GetIdPoint2(x,y);
3759         if ( (GetState()==0) && (id!=-1) )
3760         {
3761                 manualPoint *mp = this->GetManualContourModel()->GetManualPoint(id);
3762
3763                 this->GetVtkMPRBaseData()->SetX( mp->GetX() );
3764                 this->GetVtkMPRBaseData()->SetY( mp->GetY() );
3765                 this->GetVtkMPRBaseData()->SetZ( mp->GetZ() );
3766                 ResetOrientationPlane();
3767                 this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
3768         }
3769
3770
3771         manualContourControler::MouseClickLeft(x,y);
3772
3773
3774 // ----------------------------------------------------------------------------
3775 bool manualContour3DControler::OnChar()
3776 {
3777         bool ok=true;
3778         manualContourControler::OnChar();
3779         char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
3780         if (keyCode==32){
3781                 ok=false;
3782                 ResetOrientationPlane();
3783                 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
3784         }
3785         return ok;
3786 }
3787
3788 // ----------------------------------------------------------------------------
3789 void manualContour3DControler::SetVtkMPRBaseData (vtkMPRBaseData *vtkmprbasedata )
3790 {
3791         _vtkmprbasedata=vtkmprbasedata;
3792 }
3793 // ----------------------------------------------------------------------------
3794 vtkMPRBaseData *manualContour3DControler::GetVtkMPRBaseData()
3795 {
3796         return _vtkmprbasedata;
3797 }
3798
3799 // ----------------------------------------------------------------------------
3800 void manualContour3DControler::InsertPoint(int x, int y, int z ) // virtual
3801 {
3802         manualContourControler::InsertPoint(  x,  y,  z );
3803         ResetOrientationPlane();
3804 }
3805
3806
3807
3808 // ----------------------------------------------------------------------------
3809 // ----------------------------------------------------------------------------
3810 // ----------------------------------------------------------------------------
3811
3812 manualContour3V3DControler::manualContour3V3DControler()
3813 {
3814 }
3815 // ----------------------------------------------------------------------------
3816 manualContour3V3DControler::~manualContour3V3DControler()
3817 {
3818 }
3819
3820 // ----------------------------------------------------------------------------
3821 manualContour3V3DControler * manualContour3V3DControler :: Clone()  // virtual 
3822 {
3823         manualContour3V3DControler * clone = new manualContour3V3DControler();
3824         CopyAttributesTo(clone);
3825         return clone;
3826 }
3827
3828 // ---------------------------------------------------------------------------
3829 void manualContour3V3DControler::CopyAttributesTo( manualContour3V3DControler * cloneObject)
3830 {
3831         // Fathers object
3832         manualContour3DControler::CopyAttributesTo(cloneObject);
3833
3834         cloneObject->SetManualContour3VControler( this->GetManualContour3VControler() );
3835 }
3836 // ----------------------------------------------------------------------------
3837 void manualContour3V3DControler::InsertPoint(int x, int y, int z ) // virtual
3838 {
3839         manualContour3DControler::InsertPoint(  x,  y,  z );
3840         _manualcontour3Vcontroler->InsertPoint_Others(0);
3841 }
3842 // ----------------------------------------------------------------------------
3843 void manualContour3V3DControler::AddPoint( int x, int y, int z )
3844 {
3845         manualContour3DControler::AddPoint(  x,  y,  z );
3846         _manualcontour3Vcontroler->AddPoint_Others();
3847 }
3848 // ----------------------------------------------------------------------------
3849 void manualContour3V3DControler::DeleteActualMousePoint(int x, int y)
3850 {
3851         int id = GetManualViewBaseContour()->GetIdPoint ( x , y , GetZ() );
3852         manualContour3DControler::DeleteActualMousePoint( x , y );
3853         _manualcontour3Vcontroler->DeleteActualMousePoint_Others(id);
3854 }
3855 // ----------------------------------------------------------------------------
3856 void manualContour3V3DControler::MouseMove( int x, int y )
3857 {
3858         int ss =this->_vtkInteractorStyleBaseView->vtkInteractorStyle::GetState();
3859         if ((this->GetState()!=7) && (ss!=1)){
3860                 manualContour3DControler::MouseMove( x , y );
3861                 int id = GetManualViewBaseContour()->GetIdPoint ( x , y , GetZ() );
3862                 _manualcontour3Vcontroler->MouseMove_Others(id);
3863         }
3864 }
3865 // ----------------------------------------------------------------------------
3866 void manualContour3V3DControler::SetManualContour3VControler(manualContour3VControler *manualcontour3Vcontroler)
3867 {
3868         _manualcontour3Vcontroler = manualcontour3Vcontroler;
3869 }
3870 // ----------------------------------------------------------------------------
3871 manualContour3VControler *manualContour3V3DControler::GetManualContour3VControler()
3872 {
3873         return _manualcontour3Vcontroler;
3874 }
3875 // ----------------------------------------------------------------------------
3876 bool manualContour3V3DControler::OnChar() // virtual
3877 {
3878         if (manualContour3DControler::OnChar()==false )
3879         {
3880                 _manualcontour3Vcontroler->OnChar_Others();
3881         }
3882         return true;
3883 }
3884
3885 // ----------------------------------------------------------------------------
3886 void manualContour3V3DControler::ResetContour() // virtual 
3887 {
3888         manualContourControler::ResetContour();
3889         _manualcontour3Vcontroler->ResetContour_Others();
3890 }
3891
3892
3893 // ----------------------------------------------------------------------------
3894 // ----------------------------------------------------------------------------
3895 // ----------------------------------------------------------------------------
3896
3897 // _state = 0  // ..nothing..
3898 // _state = 1  // move with add point
3899 // _state = 5  // move 
3900 // _state = 6  // move with insert point
3901 // _state = 7  // move with non selection
3902
3903 manualContourControler::manualContourControler()
3904 {
3905         _easyCreation = true;
3906         
3907 }
3908 // ----------------------------------------------------------------------------
3909 manualContourControler::~manualContourControler()
3910 {
3911 }
3912 // ----------------------------------------------------------------------------
3913 manualContourControler * manualContourControler :: Clone()  // virtual 
3914 {
3915         manualContourControler * clone = new manualContourControler();
3916         CopyAttributesTo(clone);
3917         return clone;
3918 }
3919 // ---------------------------------------------------------------------------
3920 void manualContourControler::CopyAttributesTo( manualContourControler * cloneObject)
3921 {
3922         // Fathers object
3923         manualContourBaseControler::CopyAttributesTo(cloneObject);
3924         cloneObject->SetEasyCreation( this->GetEasyCreation() );
3925 }
3926
3927 // ----------------------------------------------------------------------------
3928 void manualContourControler::Configure() //virtual
3929 {
3930  //     this->_manContModel->SetNumberOfPointsSpline(100);
3931 }
3932
3933 // ----------------------------------------------------------------------------
3934 void manualContourControler::MouseClickLeft(int x, int y){
3935
3936                         
3937         bool ok = false;
3938         int z   = GetZ();
3939         int size= GetManualViewBaseContour()->GetNumberOfPoints();
3940
3941         // Insert a Control Point with shift+ClickLeft
3942         int tt = GetState();
3943         vtkRenderWindowInteractor *vtkrenderwindowinteractor = _vtkInteractorStyleBaseView->GetInteractor();
3944 //EED3131
3945         if( IsEditable() )
3946         {
3947                 if ( (_vtkInteractorStyleBaseView!=NULL) && (GetState()==0) && ( (vtkrenderwindowinteractor!=NULL) && (vtkrenderwindowinteractor->GetShiftKey()==1) ) ) 
3948                 { 
3949                         ok=true;
3950                         InsertPoint(x,y,z);
3951                         size++;
3952                 }
3953                 // Start to Insert Control Points with ClickLeft (Empty contour)
3954                 if ((GetState()==0) && (size==0) && (_easyCreation==true) )
3955                 { 
3956                         ok=true;
3957                         SetState(1); 
3958                         AddPoint(x,y,z);
3959                 }
3960                 // Continuie to Insert Control Points with ClickLeft (After being empty the contour)
3961                 if ((GetState()==1) && (_easyCreation==true) )  
3962                 { 
3963                         ok=true;
3964                         AddPoint(x,y,z);
3965                         _bakIdPoint=GetNumberOfPointsManualContour() - 1;
3966                 }
3967                 // Insert Control Points IF Contour si Selected
3968                 if ((GetState()==0) && GetManualViewBaseContour()->GetPosibleSelected() )       
3969                 {               
3970                         ok=true;
3971                         InsertPoint(x,y,z);
3972                         _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);
3973                         SetState(6);
3974                 }
3975                 // Chose id of Control Point to be move
3976                 if ( (GetState()==0 || GetState()==6) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)!=-1 ) )
3977                 {
3978                         ok=true;
3979                         _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);    
3980                         SetState(5);
3981                 }
3982                 // If nothing selected _state=7
3983                 if ( (GetState()==0) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)==-1 ) )
3984                 {
3985                         //ok=true;
3986                         _bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);    
3987                         SetState(7);
3988                 }
3989         }
3990         else
3991         {
3992                 SetPosibleToMove( true );
3993                 GetManualViewBaseContour()->SetSelected( GetManualViewBaseContour()->GetPosibleSelected() );
3994         }       
3995         if ( GetState() == 0 && GetManualViewBaseContour()->GetPosibleSelected() )
3996         {               
3997                 SetMoving( true );
3998                 ok=true;                
3999                 GetManualViewBaseContour()->InitMove(x,y,z);
4000                 SetState(6);
4001         }               
4002         if (ok==true)
4003         {
4004                 GetManualViewBaseContour()->Refresh();
4005         }
4006 }
4007 // ----------------------------------------------------------------------------
4008 void manualContourControler::MouseMove(int x, int y) // virtual
4009 {
4010         int z=GetZ();
4011         GetManualViewBaseContour()->SelectPosiblePoint(x,y,z);
4012         GetManualViewBaseContour()->SelectPosibleContour(x,y,z);        
4013         if (GetState()==1){     SetPoint( _bakIdPoint , x , y ,z); }
4014         if (GetState()==5){     SetPoint( _bakIdPoint , x , y ,z); }
4015         if ( GetState()==6 && !IsEditable() && GetPosibleToMove() &&IsMoving() )
4016         {               
4017                 GetManualViewBaseContour()->MoveContour(x,y,z);
4018         }
4019         if (GetState()!=7 || GetManualViewBaseContour()->GetPosibleSelected() ){
4020                 GetManualViewBaseContour()->Refresh();
4021                 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
4022         }
4023         if (!IsEditable())
4024         {
4025                 GetManualViewBaseContour()->RemoveControlPoints();
4026                 GetManualViewBaseContour()->RemoveTextActor();
4027                 GetManualViewBaseContour()->Refresh();
4028                 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
4029         }
4030
4031 }
4032
4033 // ----------------------------------------------------------------------------
4034 void manualContourControler::MouseDLeft( int x, int y)//virtual 
4035 {
4036         manualContourBaseControler::MouseDLeft( x, y);  
4037         if ( IsEditable() )
4038         {
4039                 GetManualViewBaseContour()->AddControlPoints();
4040                 GetManualViewBaseContour()->AddTextActor();
4041                 GetManualViewBaseContour()->Refresh();
4042                 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
4043         }       
4044 }
4045 // ----------------------------------------------------------------------------
4046 void manualContourControler::SetEasyCreation(bool easyCreation)
4047 {
4048         _easyCreation=easyCreation;
4049 }
4050 // ----------------------------------------------------------------------------
4051 bool manualContourControler::GetEasyCreation()
4052 {
4053         return _easyCreation;
4054 }
4055
4056
4057 // ----------------------------------------------------------------------------
4058 // ----------------------------------------------------------------------------
4059 // ----------------------------------------------------------------------------
4060 manualContourPerpPlaneControler::manualContourPerpPlaneControler()
4061 {
4062         _flagMouseMove = true;
4063 }
4064 // ----------------------------------------------------------------------------
4065 manualContourPerpPlaneControler::~manualContourPerpPlaneControler()
4066 {
4067 }
4068 // ----------------------------------------------------------------------------
4069 manualContourPerpPlaneControler * manualContourPerpPlaneControler :: Clone()  // virtual 
4070 {
4071         manualContourPerpPlaneControler * clone = new manualContourPerpPlaneControler();
4072         CopyAttributesTo(clone);
4073         return clone;
4074 }
4075
4076 // ---------------------------------------------------------------------------
4077 void manualContourPerpPlaneControler::CopyAttributesTo( manualContourPerpPlaneControler * cloneObject)
4078 {
4079         // Fathers object
4080         manualContourControler::CopyAttributesTo(cloneObject);
4081
4082         cloneObject->SetVtkMPRBaseData( this->GetVtkMPRBaseData() );
4083         cloneObject->SetManualContour3VControler( this->GetManualContour3VControler() );
4084         cloneObject->SetVtkInteractorStylePlane2D( this->GetVtkInteractorStylePlane2D() );
4085 }
4086
4087 // ----------------------------------------------------------------------------
4088 void manualContourPerpPlaneControler::SetVtkMPRBaseData(vtkMPRBaseData *vtkmprbasedata)
4089 {
4090         _vtkmprbasedata = vtkmprbasedata;
4091 }
4092
4093 // ----------------------------------------------------------------------------
4094 vtkMPRBaseData *manualContourPerpPlaneControler::GetVtkMPRBaseData()
4095 {
4096         return _vtkmprbasedata;
4097 }
4098
4099
4100 // ----------------------------------------------------------------------------
4101 void manualContourPerpPlaneControler::InsertPoint(int x, int y, int z ) // virtual
4102 {
4103         manualContourControler::InsertPoint(  x,  y,  z );
4104         _manualcontour3Vcontroler->InsertPoint_Others(0);
4105 }
4106 // ----------------------------------------------------------------------------
4107 void manualContourPerpPlaneControler::AddPoint( int x, int y, int z )
4108 {
4109         manualContourControler::AddPoint(  x,  y,  z );
4110         _manualcontour3Vcontroler->AddPoint_Others();
4111 }
4112 // ----------------------------------------------------------------------------
4113 void manualContourPerpPlaneControler::DeleteActualMousePoint(int x, int y)
4114 {
4115         int id = GetManualViewBaseContour()->GetIdPoint ( x , y , GetZ() );
4116         manualContourControler::DeleteActualMousePoint( x , y );
4117         _manualcontour3Vcontroler->DeleteActualMousePoint_Others(id);
4118 }
4119 // ----------------------------------------------------------------------------
4120 void manualContourPerpPlaneControler::MouseMove( int x, int y )
4121 {
4122         _flagMouseMove = true;
4123         int ss =this->_vtkInteractorStyleBaseView->vtkInteractorStyle::GetState();
4124         if ((this->GetState()!=7) && (ss!=1)){
4125                 manualContourControler::MouseMove( x , y );
4126                 int id = GetManualViewBaseContour()->GetIdPoint ( x , y , GetZ() );
4127                 if (id!=-1)
4128                 {
4129                         _manualcontour3Vcontroler->MouseMove_Others(id);
4130                         _flagMouseMove = false;
4131                 }
4132         }
4133 }
4134 // ----------------------------------------------------------------------------
4135 void manualContourPerpPlaneControler::SetManualContour3VControler(manualContour3VControler *manualcontour3Vcontroler)
4136 {
4137         _manualcontour3Vcontroler = manualcontour3Vcontroler;
4138 }
4139 // ----------------------------------------------------------------------------
4140 manualContour3VControler * manualContourPerpPlaneControler::GetManualContour3VControler()
4141 {
4142         return _manualcontour3Vcontroler;
4143 }
4144 // ----------------------------------------------------------------------------
4145 bool manualContourPerpPlaneControler::OnChar() // virtual
4146 {
4147         if (manualContourControler::OnChar()==false )
4148         {
4149                 _manualcontour3Vcontroler->OnChar_Others();
4150         }
4151         return true;
4152 }
4153 // ----------------------------------------------------------------------------
4154 bool manualContourPerpPlaneControler::OnMouseMove() //  virtual 
4155 {
4156         manualContourControler::OnMouseMove();
4157         return _flagMouseMove;
4158 }
4159 // ----------------------------------------------------------------------------
4160 bool manualContourPerpPlaneControler::OnLeftDClick() //         virtual 
4161 {
4162         manualContourControler::OnLeftDClick();
4163         return _flagMouseDClick;
4164 }
4165 // ----------------------------------------------------------------------------
4166 void manualContourPerpPlaneControler::ResetContour() // virtual 
4167 {
4168         manualContourControler::ResetContour();
4169         _manualcontour3Vcontroler->ResetContour_Others();
4170 }
4171
4172 // ----------------------------------------------------------------------------
4173 void manualContourPerpPlaneControler::MouseDLeft( int x, int y) // virtual 
4174 {
4175         _flagMouseDClick=true;
4176         manualContourControler::MouseDLeft(x,y);
4177
4178         if (GetManualViewBaseContour()->ifTouchContour(x,y,0)==true)
4179         {
4180                 _flagMouseDClick = false;
4181                 _vtkinteractorstyleplane2D->OnLeftDClick();
4182                 ResetOrientationPlane();
4183                 this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
4184         }
4185
4186 //      int id=GetManualViewBaseContour()->GetIdPoint(x,y,GetZ());
4187 //              if ( (GetState()==0) && (id!=-1) )
4188 //      {
4189 //              manualPoint *mp = this->GetManualContourModel()->GetManualPoint(id);
4190 //              _vtkmprbasedata->SetX( mp->GetX() );
4191 //              _vtkmprbasedata->SetY( mp->GetY() );
4192 //              _vtkmprbasedata->SetZ( mp->GetZ() );
4193 //              ResetOrientationPlane();
4194 //              this->_vtkInteractorStyleBaseView->SetParent_refresh_waiting();
4195 //      } 
4196 }
4197
4198
4199
4200 // ----------------------------------------------------------------------------
4201 void manualContourPerpPlaneControler::ResetOrientationPlane()
4202 {
4203         double p[3],rp[3],rn[3];
4204         p[0] = _vtkmprbasedata->GetX(  );
4205         p[1] = _vtkmprbasedata->GetY(  );
4206         p[2] = _vtkmprbasedata->GetZ(  );
4207         this->GetManualContourModel()->GetNearestPointAndNormal(p,rp,rn);
4208
4209         _vtkmprbasedata->SetNormal(rn[0],rn[1],rn[2]);
4210 }
4211
4212 // ----------------------------------------------------------------------------
4213 void manualContourPerpPlaneControler::SetVtkInteractorStylePlane2D(InteractorStyleMaracas *vtkinteractorstyleplane2D)
4214 {
4215         _vtkinteractorstyleplane2D = vtkinteractorstyleplane2D;
4216 }
4217 // ----------------------------------------------------------------------------
4218 InteractorStyleMaracas * manualContourPerpPlaneControler::GetVtkInteractorStylePlane2D()
4219 {
4220         return _vtkinteractorstyleplane2D;
4221 }
4222
4223 // ----------------------------------------------------------------------------
4224 // ----------------------------------------------------------------------------
4225 // ----------------------------------------------------------------------------
4226
4227 // _state = 0  // ..nothing..
4228 // _state = 5  // move point
4229 // _state = 6  // move all
4230 // _state = 7  // Empty mouse drag
4231
4232 manualRoiControler::manualRoiControler()
4233 {
4234 }
4235 // ----------------------------------------------------------------------------
4236 manualRoiControler::~manualRoiControler()
4237 {
4238 }
4239 // ----------------------------------------------------------------------------
4240 manualRoiControler * manualRoiControler :: Clone()  // virtual 
4241 {
4242         manualRoiControler * clone = new manualRoiControler();
4243         CopyAttributesTo(clone);
4244         return clone;
4245 }
4246
4247 // ---------------------------------------------------------------------------
4248 void manualRoiControler::CopyAttributesTo( manualRoiControler * cloneObject)
4249 {
4250         // Fathers object
4251         manualContourBaseControler::CopyAttributesTo(cloneObject);
4252 }
4253
4254 // ----------------------------------------------------------------------------
4255 void manualRoiControler::Configure() //virtual
4256 {
4257         this->GetManualContourModel()->SetNumberOfPointsSpline(5);
4258 }
4259
4260 // ----------------------------------------------------------------------------
4261 void manualRoiControler::MouseClickLeft(int x, int y){
4262         int z = GetZ();
4263         if ( (GetState()==0) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)!=-1 ) ){
4264                 bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);     
4265                 SetState(5);
4266         }
4267         if ((GetState()==0) && (GetManualViewBaseContour()->GetPosibleSelected()==true))        { 
4268                 GetManualViewBaseContour()->InitMove(x,y,z);
4269                 SetState(6);
4270         }
4271         int size=GetManualViewBaseContour()->GetNumberOfPoints();
4272         if (GetState()==0) { 
4273                 if (size==0){
4274                         AddPoint(x,y,z); 
4275                         AddPoint(x,y,z); 
4276                         AddPoint(x,y,z); 
4277                         AddPoint(x,y,z); 
4278                 } else {
4279                         SetPoint(0,x,y,z); 
4280                         SetPoint(1,x,y,z); 
4281                         SetPoint(2,x,y,z); 
4282                         SetPoint(3,x,y,z); 
4283                 }
4284                 bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);     
4285                 SetState(5);
4286         }
4287         GetManualViewBaseContour()->Refresh();
4288 }
4289 // ----------------------------------------------------------------------------
4290 void manualRoiControler::MouseMove(int x, int y) // virtual
4291 {
4292         int z=GetZ();
4293
4294 //      this->_vtkInteractorStyleBaseView->
4295
4296         GetManualViewBaseContour()->SelectPosibleContour(x,y,z);
4297         GetManualViewBaseContour()->SelectPosiblePoint(x,y,z);
4298
4299         if (GetState()==5){     
4300                 SetPoint( bakIdPoint , x , y ,z); 
4301                 if (bakIdPoint==0)
4302                 {
4303                         SetPointX( 1 , x ); 
4304                         SetPointY( 3 , y ); 
4305                 }
4306                 if (bakIdPoint==1)
4307                 {
4308                         SetPointX( 0 , x ); 
4309                         SetPointY( 2 , y ); 
4310                 }
4311                 if (bakIdPoint==2)
4312                 {
4313                         SetPointX( 3 , x ); 
4314                         SetPointY( 1 , y ); 
4315                 }
4316                 if (bakIdPoint==3)
4317                 {
4318                         SetPointX( 2 , x ); 
4319                         SetPointY( 0 , y ); 
4320                 }
4321         }
4322         if (GetState()==6){     
4323                 GetManualViewBaseContour()->MoveContour(x,y,z);
4324         }
4325         GetManualViewBaseContour()->Refresh();
4326 }
4327 // ----------------------------------------------------------------------------
4328 void manualRoiControler::DeleteActualMousePoint(int x, int y)  // virtual
4329
4330 }
4331 // ----------------------------------------------------------------------------
4332 void manualRoiControler::InitRoi(int ww, int hh, double porcentage)
4333 {
4334         int zz;
4335         manualPoint *mp;
4336
4337         if (GetManualContourModel()->GetSizeLstPoints() ==0)
4338         {
4339                 zz = GetZ();
4340                 AddPoint(0,0,zz);
4341                 AddPoint(0,0,zz);
4342                 AddPoint(0,0,zz);
4343                 AddPoint(0,0,zz);
4344         }
4345
4346         double pp1=porcentage;
4347         double pp2=1-porcentage;
4348
4349         mp = GetManualContourModel()->GetManualPoint(2);
4350         zz=(int)mp->GetZ();
4351         mp->SetPoint(ww*pp1,hh*pp1,zz);
4352
4353         mp = GetManualContourModel()->GetManualPoint(1);
4354         zz=(int)mp->GetZ();
4355         mp->SetPoint(ww*pp2,hh*pp1,zz);
4356
4357         mp = GetManualContourModel()->GetManualPoint(0);
4358         zz=(int)mp->GetZ();
4359         mp->SetPoint(ww*pp2,hh*pp2,zz);
4360
4361         mp = GetManualContourModel()->GetManualPoint(3);
4362         zz=(int)mp->GetZ();
4363         mp->SetPoint(ww*pp1,hh*pp2,zz);
4364
4365         GetManualViewBaseContour() ->UpdateViewPoint(0);
4366         GetManualViewBaseContour() ->UpdateViewPoint(1);
4367         GetManualViewBaseContour() ->UpdateViewPoint(2);
4368         GetManualViewBaseContour() ->UpdateViewPoint(3);
4369
4370         SetState(0);
4371         GetManualViewBaseContour()->Refresh();  
4372 }       
4373
4374 // ----------------------------------------------------------------------------
4375 void manualRoiControler::SetRoi(int x1, int y1,int x2, int y2)
4376 {
4377         manualPoint *mp;
4378         InitRoi( 0 , 0 , 0.2 );
4379         mp = GetManualContourModel()->GetManualPoint(2);
4380         mp->SetPointX(x1);
4381         mp->SetPointY(y1);
4382
4383         mp = GetManualContourModel()->GetManualPoint(1);
4384         mp->SetPointX(x2);
4385         mp->SetPointY(y1);
4386
4387         mp = GetManualContourModel()->GetManualPoint(0);
4388         mp->SetPointX(x2);
4389         mp->SetPointY(y2);
4390
4391         mp = GetManualContourModel()->GetManualPoint(3);
4392         mp->SetPointX(x1);
4393         mp->SetPointY(y2);
4394
4395         GetManualViewBaseContour() ->UpdateViewPoint(0);
4396         GetManualViewBaseContour() ->UpdateViewPoint(1);
4397         GetManualViewBaseContour() ->UpdateViewPoint(2);
4398         GetManualViewBaseContour() ->UpdateViewPoint(3);
4399 }
4400
4401
4402 // ----------------------------------------------------------------------------
4403 // ----------------------------------------------------------------------------
4404 // ----------------------------------------------------------------------------
4405
4406 // EED08
4407
4408 // _state = 0  // ..nothing..
4409 // _state = 5  // move point
4410 // _state = 6  // move all
4411 // _state = 7  // Empty mouse drag
4412
4413 manualCircleControler::manualCircleControler()
4414 {
4415 }
4416 // ----------------------------------------------------------------------------
4417 manualCircleControler::~manualCircleControler()
4418 {
4419 }
4420 // ----------------------------------------------------------------------------
4421 manualCircleControler * manualCircleControler :: Clone()  // virtual 
4422 {
4423         manualCircleControler * clone = new manualCircleControler();
4424         CopyAttributesTo(clone);
4425         return clone;
4426 }
4427
4428 // ---------------------------------------------------------------------------
4429 void manualCircleControler::CopyAttributesTo( manualCircleControler * cloneObject)
4430 {
4431         // Fathers object
4432         manualContourBaseControler::CopyAttributesTo(cloneObject);
4433 }
4434
4435 // ----------------------------------------------------------------------------
4436 void manualCircleControler::Configure() //virtual
4437 {
4438 //      this->GetManualContourModel()->SetNumberOfPointsSpline(5);
4439 }
4440
4441 // ----------------------------------------------------------------------------
4442 void manualCircleControler::MouseClickLeft(int x, int y){
4443         int z = GetZ();
4444         if ( (GetState()==0) && (GetManualViewBaseContour()->GetIdPoint(x,y,z)!=-1 ) ){
4445                 bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);     
4446                 SetState(5);
4447         }
4448         if ((GetState()==0) && (GetManualViewBaseContour()->GetPosibleSelected()==true))        { 
4449                 GetManualViewBaseContour()->InitMove(x,y,z);
4450                 SetState(6);
4451         }
4452         int size=GetManualViewBaseContour()->GetNumberOfPoints();
4453         if (GetState()==0) { 
4454                 if (size==0){
4455                         AddPoint(x,y,z); 
4456                         AddPoint(x,y,z); 
4457 //                      AddPoint(x,y,z); 
4458 //                      AddPoint(x,y,z); 
4459                 } else {
4460                         SetPoint(0,x,y,z); 
4461                         SetPoint(1,x,y,z); 
4462 //                      SetPoint(2,x,y,z); 
4463 //                      SetPoint(3,x,y,z); 
4464                 }
4465                 bakIdPoint = GetManualViewBaseContour()->GetIdPoint(x,y,z);     
4466                 SetState(5);
4467         }
4468         GetManualViewBaseContour()->Refresh();
4469 }
4470 // ----------------------------------------------------------------------------
4471
4472 void manualCircleControler::MouseMove(int x, int y) // virtual
4473 {
4474         int z=GetZ();
4475
4476 //      this->_vtkInteractorStyleBaseView->
4477
4478         GetManualViewBaseContour()->SelectPosibleContour(x,y,z);
4479         GetManualViewBaseContour()->SelectPosiblePoint(x,y,z);
4480
4481         if (GetState()==5){     
4482                 SetPoint( bakIdPoint , x , y ,z); 
4483 /*
4484                 if (bakIdPoint==0)
4485                 {
4486                         SetPointX( 1 , x ); 
4487                         SetPointY( 3 , y ); 
4488                 }
4489                 if (bakIdPoint==1)
4490                 {
4491                         SetPointX( 0 , x ); 
4492                         SetPointY( 2 , y ); 
4493                 }
4494
4495                 if (bakIdPoint==2)
4496                 {
4497                         SetPointX( 3 , x ); 
4498                         SetPointY( 1 , y ); 
4499                 }
4500                 if (bakIdPoint==3)
4501                 {
4502                         SetPointX( 2 , x ); 
4503                         SetPointY( 0 , y ); 
4504                 }
4505 */
4506         }
4507         if (GetState()==6){     
4508                 GetManualViewBaseContour()->MoveContour(x,y,z);
4509         }
4510         GetManualViewBaseContour()->Refresh();
4511 }
4512
4513
4514 // ----------------------------------------------------------------------------
4515 void manualCircleControler::DeleteActualMousePoint(int x, int y)  // virtual
4516
4517 }
4518 // ----------------------------------------------------------------------------
4519
4520 void manualCircleControler::InitRoi(int ww, int hh, double porcentage)
4521 {
4522         int zz;
4523         manualPoint *mp;
4524
4525         if (GetManualContourModel()->GetSizeLstPoints() ==0)
4526         {
4527                 zz = GetZ();
4528                 AddPoint(0,0,zz);
4529                 AddPoint(0,0,zz);
4530 //              AddPoint(0,0,zz);
4531 //              AddPoint(0,0,zz);
4532         }
4533
4534         double pp1=porcentage;
4535         double pp2=1-porcentage;
4536
4537 //      mp = GetManualContourModel()->GetManualPoint(2);
4538 //      zz=(int)mp->GetZ();
4539 //      mp->SetPoint(ww*pp1,hh*pp1,zz);
4540
4541         mp = GetManualContourModel()->GetManualPoint(1);
4542         zz=(int)mp->GetZ();
4543         mp->SetPoint(ww*pp2,hh*pp1,zz);
4544
4545         mp = GetManualContourModel()->GetManualPoint(0);
4546         zz=(int)mp->GetZ();
4547         mp->SetPoint(ww*pp2,hh*pp2,zz);
4548
4549 //      mp = GetManualContourModel()->GetManualPoint(3);
4550 //      zz=(int)mp->GetZ();
4551 //      mp->SetPoint(ww*pp1,hh*pp2,zz);
4552
4553         GetManualViewBaseContour() ->UpdateViewPoint(0);
4554         GetManualViewBaseContour() ->UpdateViewPoint(1);
4555 //      GetManualViewBaseContour() ->UpdateViewPoint(2);
4556 //      GetManualViewBaseContour() ->UpdateViewPoint(3);
4557
4558         SetState(0);
4559         GetManualViewBaseContour()->Refresh();  
4560 }       
4561
4562 // ----------------------------------------------------------------------------
4563 /*
4564 void manualCircleControler::SetRoi(int x1, int y1,int x2, int y2)
4565 {
4566         manualPoint *mp;
4567         InitRoi( 0 , 0 , 0.2 );
4568         mp = GetManualContourModel()->GetManualPoint(2);
4569         mp->SetPointX(x1);
4570         mp->SetPointY(y1);
4571
4572         mp = GetManualContourModel()->GetManualPoint(1);
4573         mp->SetPointX(x2);
4574         mp->SetPointY(y1);
4575
4576         mp = GetManualContourModel()->GetManualPoint(0);
4577         mp->SetPointX(x2);
4578         mp->SetPointY(y2);
4579
4580         mp = GetManualContourModel()->GetManualPoint(3);
4581         mp->SetPointX(x1);
4582         mp->SetPointY(y2);
4583
4584         GetManualViewBaseContour() ->UpdateViewPoint(0);
4585         GetManualViewBaseContour() ->UpdateViewPoint(1);
4586         GetManualViewBaseContour() ->UpdateViewPoint(2);
4587         GetManualViewBaseContour() ->UpdateViewPoint(3);
4588 }
4589 */
4590
4591
4592
4593 // ----------------------------------------------------------------------------
4594 // ----------------------------------------------------------------------------
4595 // ----------------------------------------------------------------------------
4596
4597
4598 manualContourBaseControler::manualContourBaseControler()
4599 {
4600         _manViewBaseCont        = NULL;
4601         _manContModel           = NULL;
4602         _state                          = 0;
4603         _z                                      = -900;
4604         _editable                       = true;
4605         _posibleToMove          = true; 
4606         _moving                         = false;
4607         _created                        = false;
4608         _keyBoardMoving         = false;
4609 }
4610 // ----------------------------------------------------------------------------
4611 manualContourBaseControler::~manualContourBaseControler()
4612 {
4613 }
4614
4615 // ----------------------------------------------------------------------------
4616 manualContourBaseControler * manualContourBaseControler :: Clone()  // virtual 
4617 {
4618         manualContourBaseControler * clone = new manualContourBaseControler();
4619         CopyAttributesTo(clone);
4620         return clone;
4621 }
4622
4623 // ---------------------------------------------------------------------------
4624
4625 void manualContourBaseControler::CopyAttributesTo( manualContourBaseControler * cloneObject)
4626 {
4627         // Fathers object
4628         InteractorStyleMaracas::CopyAttributesTo(cloneObject);
4629         cloneObject->SetZ( this->GetZ() );
4630         cloneObject->SetState( this->GetState() );
4631         cloneObject->SetEditable( this->IsEditable() );
4632         cloneObject->SetPosibleToMove( this->GetPosibleToMove() );
4633         cloneObject->SetMoving( this->IsMoving() );
4634         cloneObject->SetCompleteCreation( this->GetIfCompleteCreation() );
4635         cloneObject->SetKeyBoardMoving( this->GetKeyBoardMoving() );
4636 }
4637
4638 // ----------------------------------------------------------------------------
4639 void manualContourBaseControler::Configure() //virtual
4640 {
4641 }
4642
4643 // ----------------------------------------------------------------------------
4644 bool manualContourBaseControler::OnChar()
4645 {
4646         if ( _vtkInteractorStyleBaseView!=NULL )
4647         {
4648                 char keyCode = _vtkInteractorStyleBaseView->GetInteractor()-> GetKeyCode();
4649
4650                 int X,Y;
4651                 wxVTKRenderWindowInteractor *_wxVTKiren;
4652                 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
4653                 _wxVTKiren->GetEventPosition(X, Y);     
4654                 int Z = GetZ();
4655                 // Delete Point
4656                 if ((keyCode==8) || (keyCode==127))
4657                 {
4658
4659                         if (!GetManualViewBaseContour()->GetPosibleSelected()==true)
4660                         {
4661                                 DeleteActualMousePoint(X,Y);
4662                         }
4663                         GetManualViewBaseContour()->Refresh();
4664                         this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
4665                 }       
4666                 else
4667                 {
4668                         // Magnet 
4669                         if (keyCode==32)
4670                         {
4671                                 Magnet(X,Y);
4672                                 GetManualViewBaseContour()->Refresh();
4673                                 this->_vtkInteractorStyleBaseView->SetRefresh_waiting();
4674                         }
4675                         else if( !IsEditable() )
4676                         {               
4677                                 if ( keyCode == 'L' )
4678                                 {       
4679                                         GetManualViewBaseContour()->MoveContour( -1, 0 );       
4680                                         SetKeyBoardMoving( true );
4681                                 }
4682                                 else if ( keyCode == 'R' )
4683                                 {                       
4684                                         GetManualViewBaseContour()->MoveContour( 1, 0 );        
4685                                         SetKeyBoardMoving( true );      
4686                                 }
4687                                 else if ( keyCode == 'U' )
4688                                 {
4689                                         GetManualViewBaseContour()->MoveContour( 0, -1 );       
4690                                         SetKeyBoardMoving( true );
4691                                 }
4692                                 else if ( keyCode == 'D' )
4693                                 {
4694                                         GetManualViewBaseContour()->MoveContour( 0, 1 );        
4695                                         SetKeyBoardMoving( true );
4696                                 }
4697                                 else if ( keyCode == 'W' )//Diagonal left down
4698                                 {
4699                                         GetManualViewBaseContour()->MoveContour( -1, 1 );       
4700                                         SetKeyBoardMoving( true );
4701                                 }
4702                                 else if ( keyCode == 'Q' )//Diagonal left up
4703                                 {
4704                                         GetManualViewBaseContour()->MoveContour( -1, -1 );      
4705                                         SetKeyBoardMoving( true );
4706                                 }
4707                                 else if( keyCode == 'P' )//Diagonal right up
4708                                 {
4709                                         GetManualViewBaseContour()->MoveContour( 1, -1 );       
4710                                         SetKeyBoardMoving( true );
4711                                 }
4712                                 else if( keyCode == 'M' )//Diagonal right down
4713                                 {
4714                                         GetManualViewBaseContour()->MoveContour( 1, 1 );        
4715                                         SetKeyBoardMoving( true );
4716                                 }
4717                                 if( GetKeyBoardMoving() )
4718                                 {
4719                                         GetManualViewBaseContour()->Refresh();
4720                                         this->_vtkInteractorStyleBaseView->SetRefresh_waiting();        
4721                                 }
4722                         }
4723                 }               
4724         }
4725         return true;
4726 }
4727 // ----------------------------------------------------------------------------
4728 bool manualContourBaseControler::OnMouseMove()
4729 {
4730         if ( _vtkInteractorStyleBaseView!=NULL)
4731         {
4732                 int X,Y;
4733                 wxVTKRenderWindowInteractor *_wxVTKiren;
4734                 _wxVTKiren= _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
4735                 _wxVTKiren->GetEventPosition( X , Y );
4736
4737
4738                 if ( (_vtkInteractorStyleBaseView->GetInteractor()->GetControlKey()==0) &&
4739                         (_vtkInteractorStyleBaseView->GetInteractor()->GetShiftKey()==0) ) {
4740                         MouseMove(X,Y);
4741                 }
4742         }
4743         return true;
4744 }
4745 // ----------------------------------------------------------------------------
4746 bool manualContourBaseControler::OnLeftButtonDown()
4747 {
4748         SetKeyBoardMoving( false );
4749         if ( _vtkInteractorStyleBaseView!=NULL )
4750         {
4751                 int X,Y;
4752                 wxVTKRenderWindowInteractor *wxVTKiren;
4753                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
4754                 wxVTKiren->GetEventPosition(X,Y);
4755                 
4756                 MouseClickLeft(X,Y);
4757         }
4758         return true;
4759 }
4760 // ----------------------------------------------------------------------------
4761 bool manualContourBaseControler::OnLeftButtonUp()
4762 {
4763         if ( _vtkInteractorStyleBaseView!=NULL )
4764         {
4765                 int X,Y;
4766                 wxVTKRenderWindowInteractor *wxVTKiren;
4767                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
4768                 wxVTKiren->GetEventPosition(X,Y);
4769                 MouseReleaseLeft(X,Y);
4770         }
4771         return true;
4772 }
4773 // ----------------------------------------------------------------------------
4774 bool manualContourBaseControler::OnLeftDClick()
4775 {
4776         if ( _vtkInteractorStyleBaseView!=NULL )
4777         {
4778                 int X,Y;
4779                 wxVTKRenderWindowInteractor *wxVTKiren;
4780                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
4781                 wxVTKiren->GetEventPosition(X,Y);
4782
4783                 this->MouseDLeft(X,Y);
4784         }
4785         return true;
4786 }
4787 // ----------------------------------------------------------------------------
4788 bool manualContourBaseControler::OnMiddleButtonDown() 
4789 {
4790 //      SetKeyBoardMoving( false );
4791         if ( _vtkInteractorStyleBaseView!=NULL )
4792         {
4793                 int X,Y;
4794                 wxVTKRenderWindowInteractor *wxVTKiren;
4795                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
4796                 wxVTKiren->GetEventPosition(X,Y);
4797                 GetManualViewBaseContour()->InitMove( X, Y,GetZ());
4798         }
4799         return true;
4800 }
4801 // ----------------------------------------------------------------------------
4802 bool manualContourBaseControler::OnMiddleButtonUp()
4803 {
4804         return true;
4805 }
4806 // ----------------------------------------------------------------------------
4807 bool manualContourBaseControler::OnRightButtonDown()
4808 {
4809         if( _vtkInteractorStyleBaseView!= NULL )
4810         {
4811                 int X,Y;
4812                 wxVTKRenderWindowInteractor *wxVTKiren;
4813                 wxVTKiren = _vtkInteractorStyleBaseView->GetWxVtk2DBaseView()->GetWxVTKRenderWindowInteractor();
4814                 wxVTKiren->GetEventPosition(X, Y);
4815                 
4816                 SetCompleteCreation( true );
4817                 SetKeyBoardMoving( false );
4818                 MouseClickRight(X,Y);
4819         }
4820         return true;
4821 }
4822 // ----------------------------------------------------------------------------
4823 bool manualContourBaseControler::OnRightButtonUp()
4824 {
4825         return true;
4826 }
4827 // ----------------------------------------------------------------------------
4828 void manualContourBaseControler::SetModelView(manualContourModel *manContModel, manualViewBaseContour *manViewBaseCont){
4829         _manContModel           =       manContModel;
4830         _manViewBaseCont        =       manViewBaseCont;
4831         _manViewBaseCont->SetEditable( &_editable );
4832 }
4833 // ----------------------------------------------------------------------------
4834 manualContourModel* manualContourBaseControler::GetManualContourModel()
4835 {
4836         return _manContModel;
4837 }
4838 // ----------------------------------------------------------------------------
4839 manualViewBaseContour* manualContourBaseControler::GetManualViewBaseContour()
4840 {
4841         return _manViewBaseCont;
4842 }
4843 // ----------------------------------------------------------------------------
4844 void manualContourBaseControler::MouseClickLeft(int x, int y) // virtual
4845 {  
4846         
4847 }
4848 // ----------------------------------------------------------------------------
4849 void manualContourBaseControler::MouseClickRight(int x, int y)
4850 {
4851         if (_state==1)  
4852         { 
4853                 _state=0;
4854         }
4855         SetEditable( false );
4856         SetPosibleToMove( false );
4857         //_state = 0; 
4858         _state=7;
4859 }
4860 // ----------------------------------------------------------------------------
4861 void manualContourBaseControler::MouseReleaseLeft(int x, int y)
4862 {
4863         if (_state==5){ _state = 0; }
4864         if (_state==6){ _state = 0; }
4865         if (_state==7){ _state = 0; }   
4866         SetMoving( false );
4867         GetManualViewBaseContour()->SelectPosibleContour(x,y,GetZ());
4868         if( GetIfCompleteCreation() && IsEditable() && !GetManualViewBaseContour()->GetPosibleSelected() && (GetManualViewBaseContour()->GetIdPoint(x,y,GetZ())==-1)  )
4869         {
4870                 SetEditable( false );
4871                 SetPosibleToMove( false );              
4872         }
4873 }
4874 // ----------------------------------------------------------------------------
4875 void manualContourBaseControler::MouseDLeft(int x, int y )
4876 {
4877         if (_state==0)  
4878         { 
4879                 int z=GetZ();
4880                 GetManualViewBaseContour()->SelectPosibleContour(x,y,z);
4881                 GetManualViewBaseContour()->SelectPosiblePoint(x,y,z);
4882                 if ( GetManualViewBaseContour()->GetPosibleSelected() )
4883                 {
4884                         _editable = true;
4885                 }
4886         }
4887 }
4888 // ----------------------------------------------------------------------------
4889 void manualContourBaseControler::MouseMove(int x, int y) // virtual
4890 {
4891 }
4892 // ----------------------------------------------------------------------------
4893 void manualContourBaseControler::SetState(int state)
4894 {
4895         _state=state;
4896 }
4897 // ----------------------------------------------------------------------------
4898 int manualContourBaseControler::GetState()
4899 {
4900         return _state;
4901 }
4902 // ----------------------------------------------------------------------------
4903 bool manualContourBaseControler::IsEditable( )
4904 {
4905         return _editable;
4906 }
4907 // ----------------------------------------------------------------------------
4908 void manualContourBaseControler::SetEditable(  bool condition  )
4909 {
4910         if (GetManualViewBaseContour()!=NULL) {
4911                 if( !condition )
4912                 {
4913                         GetManualViewBaseContour()->RemoveControlPoints();
4914                 }
4915                 GetManualViewBaseContour()->SetSelected( condition );
4916         }       
4917         _editable = condition;
4918 }
4919
4920 // ----------------------------------------------------------------------------
4921 bool manualContourBaseControler::GetPosibleToMove()
4922 {
4923         return _posibleToMove;
4924 }
4925 // ----------------------------------------------------------------------------
4926 void manualContourBaseControler::SetPosibleToMove( bool condition )
4927 {
4928         _posibleToMove = condition;
4929 }
4930 // ----------------------------------------------------------------------------
4931 bool manualContourBaseControler::IsMoving()
4932 {
4933         return _moving;
4934 }
4935 // ----------------------------------------------------------------------------
4936 void manualContourBaseControler::SetMoving( bool condition )
4937 {
4938         _moving = condition;
4939 }
4940 // ----------------------------------------------------------------------------
4941 void manualContourBaseControler::SetCompleteCreation( bool condition )
4942 {
4943         _created = condition;
4944 }
4945 // ----------------------------------------------------------------------------
4946 bool manualContourBaseControler::GetIfCompleteCreation ( )
4947 {
4948         return _created;
4949 }
4950 // ----------------------------------------------------------------------------
4951 void manualContourBaseControler::SetKeyBoardMoving( bool condition )
4952 {
4953         _keyBoardMoving = condition;
4954 }
4955 // ----------------------------------------------------------------------------
4956 bool manualContourBaseControler::GetKeyBoardMoving(  )
4957 {
4958         return _keyBoardMoving;
4959 }
4960 // ----------------------------------------------------------------------------
4961 void manualContourBaseControler::CreateNewManualContour(){
4962         _manViewBaseCont->CreateNewContour();
4963 }
4964 // ----------------------------------------------------------------------------
4965 int     manualContourBaseControler::GetNumberOfPointsManualContour(){
4966         return _manViewBaseCont->GetNumberOfPoints();
4967 }
4968 // ----------------------------------------------------------------------------
4969
4970 //JSTG - 25-02-08 -------------------------------------------------------------
4971 int     manualContourBaseControler::GetNumberOfPointsSplineManualContour(){
4972         //return _manViewBaseCont->GetNumberOfPointsSpline();
4973         return _manContModel->GetNumberOfPointsSpline();
4974 }
4975 // ----------------------------------------------------------------------------
4976
4977 double* manualContourBaseControler::GetVectorPointsXManualContour(){
4978         return _manViewBaseCont->GetVectorPointsXManualContour();
4979 }
4980 // ----------------------------------------------------------------------------
4981 double* manualContourBaseControler::GetVectorPointsYManualContour(){
4982         return _manViewBaseCont->GetVectorPointsYManualContour();
4983 }
4984 // ----------------------------------------------------------------------------
4985 void manualContourBaseControler::DeleteContour(){
4986         _manViewBaseCont->DeleteContour();
4987         _manContModel->DeleteAllPoints(); 
4988 }
4989 // ----------------------------------------------------------------------------
4990 void manualContourBaseControler::DeleteActualMousePoint(int x, int y)// virtual
4991
4992         if ((_manContModel!=NULL) && (_manViewBaseCont!=NULL) )
4993         {
4994                 int id=_manViewBaseCont->GetIdPoint(x,y,GetZ());
4995                 if ((id!=-1) && (_manContModel->GetSizeLstPoints()>2) ){
4996                         _manContModel->DeletePoint(id);
4997                         _manViewBaseCont->DeletePoint(id);  
4998                 }
4999         }
5000         _state = 0;
5001 }
5002
5003 // ----------------------------------------------------------------------------
5004 void manualContourBaseControler::Magnet(int x, int y)
5005
5006         if( IsEditable())
5007         {
5008                 int id=_manViewBaseCont->GetIdPoint(x,y,GetZ());
5009                 if (GetManualContourModel()!=NULL){
5010                         double  xx      = x;
5011                         double  yy      = y;
5012                         double  zz      = GetZ();
5013                         GetManualViewBaseContour()->TransfromeCoordViewWorld(xx,yy,zz);
5014                         int                     id      = GetManualContourModel()->GetIdPoint(xx,yy,zz,32000,-1);
5015                         if (id!=-1)
5016                         {
5017                                 manualPoint     *mp     = GetManualContourModel()->GetManualPoint(id);
5018                                 mp->SetPoint(xx,yy,zz);
5019                         }
5020         //              GetManualViewBaseContour()->UpdateViewPoint(id);
5021                 }
5022                 _state = 0;
5023         }
5024 }
5025
5026 // ----------------------------------------------------------------------------
5027 void manualContourBaseControler::SetZ(int z)
5028 {
5029         _z=z;
5030 }
5031 // ----------------------------------------------------------------------------
5032 int manualContourBaseControler::GetZ()
5033 {
5034         return _z;
5035 }
5036 // ----------------------------------------------------------------------------
5037 void manualContourBaseControler::AddPoint(int x, int y, int z) // virtual
5038 {
5039         if (GetManualContourModel()!=NULL){
5040                 double  xx      = x;
5041                 double  yy      = y;
5042                 double  zz      = z;
5043                 GetManualViewBaseContour()->TransfromeCoordViewWorld(xx,yy,zz);
5044                 int     id              = GetManualContourModel()->AddPoint(xx,yy,zz);
5045                 GetManualViewBaseContour()->AddPoint(); 
5046 //              GetManualViewBaseContour()->UpdateViewPoint(id);
5047         }
5048 }
5049 // ----------------------------------------------------------------------------
5050 void manualContourBaseControler::InsertPoint(int x,int y,int z)  // virtual
5051 {
5052 //EEDzz
5053         int id=-1;
5054         if (GetManualContourModel()!=NULL){
5055                 double                          xx              = x;
5056                 double                          yy              = y;
5057                 double                          zz              = z;
5058                 GetManualViewBaseContour()->TransfromeCoordViewWorld(xx,yy,zz);
5059                 if (GetManualContourModel()->GetSizeLstPoints()>1){
5060                         id = GetManualContourModel()->InsertPoint(xx,yy,zz);
5061                         GetManualViewBaseContour()->InsertPoint(id);                            
5062 //                      GetManualViewBaseContour()->UpdateViewPoint(id);
5063                 } else {
5064                         GetManualContourModel()->AddPoint(xx,yy,zz);
5065                         GetManualViewBaseContour()->AddPoint(); 
5066 //                      AddPoint(x,y,z);        
5067 //                      GetManualViewBaseContour()->UpdateViewPoint(id);
5068                 }
5069         }
5070 }
5071
5072 // ----------------------------------------------------------------------------
5073 void manualContourBaseControler::SetPoint( int id ,int x , int y , int z){ // virtual
5074         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
5075                 double xx = x;
5076                 double yy = y;
5077                 double zz = z;
5078                 GetManualViewBaseContour()->TransfromeCoordViewWorld(xx,yy,zz);
5079                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
5080                 mp->SetPoint(xx,yy,zz);
5081                 GetManualViewBaseContour()->UpdateViewPoint(id);
5082         }
5083 }
5084 // ----------------------------------------------------------------------------
5085 void manualContourBaseControler::SetPointX( int id ,int x  ){
5086         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
5087                 double xx = x;
5088                 double yy = 0;
5089                 double zz = 0;
5090                 GetManualViewBaseContour()->TransfromeCoordViewWorld(xx,yy,zz);
5091                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
5092                 mp->SetPointX(xx);
5093                 GetManualViewBaseContour()->UpdateViewPoint(id);
5094         }
5095 }
5096 // ----------------------------------------------------------------------------
5097 void manualContourBaseControler::SetPointY( int id ,int y  ){
5098         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
5099                 double xx = 0;
5100                 double yy = y;
5101                 double zz = 0;
5102                 GetManualViewBaseContour()->TransfromeCoordViewWorld(xx,yy,zz);
5103                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
5104                 mp->SetPointY(yy);
5105                 GetManualViewBaseContour()->UpdateViewPoint(id);
5106         }
5107 }
5108 // ----------------------------------------------------------------------------
5109 void manualContourBaseControler::SetPointZ( int id ,int z  ){
5110         if ((GetManualViewBaseContour()!=NULL) && (id>=0)){
5111                 double xx = 0;
5112                 double yy = 0;
5113                 double zz = z;
5114                 GetManualViewBaseContour()->TransfromeCoordViewWorld(xx,yy,zz);
5115                 manualPoint             *mp             = _manContModel->GetManualPoint(id);
5116                 mp->SetPointZ(zz);
5117                 GetManualViewBaseContour()->UpdateViewPoint(id);
5118         }
5119 }
5120 // ----------------------------------------------------------------------------
5121 void manualContourBaseControler::ResetContour() // virtual
5122 {
5123         this->DeleteContour();
5124         GetManualViewBaseContour()->CreateNewContour();
5125         this->SetState(0);
5126 }
5127