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