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