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