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