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