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