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