]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualContourModel.cpp
Bug with complex contours
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualContour / manualContourModel.cpp
1 /*# ---------------------------------------------------------------------
2 #
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
4 #                        pour la Sant�)
5 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
6 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
7 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
8 #
9 #  This software is governed by the CeCILL-B license under French law and
10 #  abiding by the rules of distribution of free software. You can  use,
11 #  modify and/ or redistribute the software under the terms of the CeCILL-B
12 #  license as circulated by CEA, CNRS and INRIA at the following URL
13 #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
14 #  or in the file LICENSE.txt.
15 #
16 #  As a counterpart to the access to the source code and  rights to copy,
17 #  modify and redistribute granted by the license, users are provided only
18 #  with a limited warranty  and the software's author,  the holder of the
19 #  economic rights,  and the successive licensors  have only  limited
20 #  liability.
21 #
22 #  The fact that you are presently reading this means that you have had
23 #  knowledge of the CeCILL-B license and that you accept its terms.
24 # ------------------------------------------------------------------------ */
25
26 #include "manualContourModel.h"
27
28 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
30 // ----------------------------------------------------------------------------
31
32 manualContourModel::manualContourModel()
33 {
34     _cntSplineX = vtkKochanekSpline::New( );
35     _cntSplineY = vtkKochanekSpline::New( );
36     _cntSplineZ = vtkKochanekSpline::New( );
37         this->SetCloseContour(true);
38     _cntSplineX->SetDefaultTension( 0 );
39         _cntSplineX->SetDefaultBias( 0 );
40         _cntSplineX->SetDefaultContinuity( 0 );
41     _cntSplineY->SetDefaultTension( 0 );
42         _cntSplineY->SetDefaultBias( 0 );
43         _cntSplineY->SetDefaultContinuity( 0 );
44     _cntSplineZ->SetDefaultTension( 0 );
45         _cntSplineZ->SetDefaultBias( 0 );
46         _cntSplineZ->SetDefaultContinuity( 0 );
47 //JSTG 25-02-08 -------------------------------------------------------------------------------------------------
48         // this parameter is reset in the  VIRTUAL manualContourBaseControler::Configure
49         _sizePointsContour      = 500;                  //JSTG 25-02-08 The change in the inisialization of these variable is critical.
50         _delta_JSTG                     = 0.0;
51 //---------------------------------------------------------------------------------------------------------------
52 //CMRU 17-08-09 -------------------------------------------------------------------------------------------------
53         _realSize                       = 0.0;
54 //---------------------------------------------------------------------------------------------------------------
55 }
56
57 // ----------------------------------------------------------------------------
58 manualContourModel::~manualContourModel()
59 {
60         int i,size=_lstPoints.size();
61         for (i=0;i<size; i++)
62         {
63                 delete _lstPoints[i];
64         } // for i
65         _lstPoints.clear();
66         _cntSplineX->RemoveAllPoints();
67         _cntSplineY->RemoveAllPoints();
68         _cntSplineZ->RemoveAllPoints();
69         _cntSplineX->Delete();
70         _cntSplineY->Delete();
71         _cntSplineZ->Delete();
72 }
73
74 // ----------------------------------------------------------------------------
75 int manualContourModel::AddPoint(double x,double y,double z)
76 {
77    manualPoint *mp = new manualPoint();
78    mp->SetPoint(x,y,z);
79    AddManualPoint(mp);
80    //UpdateSpline();
81    return _lstPoints.size()-1;
82 }
83 // ----------------------------------------------------------------------------
84 int manualContourModel::InsertPoint(double x,double y,double z)
85 {
86         double dd,ddmin=9999999;
87         int    ibak=0;
88         double xx,x1,x2;
89         double yy,y1,y2;
90         double zz,z1,z2;
91         int i,ii,iii,size=_lstPoints.size();
92         double j,MaxDivisions=20,porcentage;
93         int sizeB=size;
94
95         if (_closeContour==false)
96         {
97                 size=size-1;
98         }
99
100         double jbak;
101
102         for ( i=0 ; i<size ; i++ )
103         {
104                 ii=i % sizeB ;
105                 iii=(i+1) % sizeB;
106                 x1=_lstPoints[ii]->GetX();
107                 y1=_lstPoints[ii]->GetY();
108                 z1=_lstPoints[ii]->GetZ();
109                 x2=_lstPoints[iii]->GetX();
110                 y2=_lstPoints[iii]->GetY();
111                 z2=_lstPoints[iii]->GetZ();
112                 for (j=0; j<=MaxDivisions; j++)
113                 {
114                         porcentage=(j/MaxDivisions);
115                         xx=(x2-x1)*porcentage+x1;
116                         yy=(y2-y1)*porcentage+y1;
117                         zz=(z2-z1)*porcentage+z1;
118                         dd=sqrt( (xx-x)*(xx-x) + (yy-y)*(yy-y) + (zz-z)*(zz-z) );
119                         if ( dd<ddmin )
120                         {
121                                 ddmin=dd;
122                                 ibak=iii;
123                                 jbak=j;
124                         }
125                 }
126         }
127
128         if (_closeContour==false)
129         {
130                 if ( (ibak==1) && (jbak==0) )
131                 {
132                         ibak=0;
133                 }
134                 if ( ( ibak==size ) && ( jbak==MaxDivisions ) )
135                 {
136                         ibak=sizeB;
137                 }
138         }
139
140
141 //JSTG - 25-04-08 ----------------------------------------------------------
142         //manualPoint *mp = new manualPoint();
143         //mp->SetPoint(x,y,z);
144         //std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + ibak;
145         //_lstPoints.insert(itNum,mp);
146         InsertPoint_id(ibak,x,y,z);
147 //----------------------------------------------------------------------------
148
149         return ibak;
150 }
151 // ----------------------------------------------------------------------------
152 void manualContourModel::InsertPoint_id(int id, double x, double y, double z)
153 {
154         manualPoint *mp = new manualPoint();
155         mp->SetPoint(x,y,z);
156         std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + id;
157         _lstPoints.insert(itNum,mp);
158 }
159 // ----------------------------------------------------------------------------
160
161 void manualContourModel::DeletePoint(int i)
162 {
163         std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + i;
164    _lstPoints.erase(itNum);
165 }
166 // ----------------------------------------------------------------------------
167 void manualContourModel::DeleteAllPoints()
168 {
169         int i,size=_lstPoints.size();
170         for (i=0;i<size;i++){
171            _lstPoints.erase( _lstPoints.begin() );
172         }
173         this->UpdateSpline();
174 }
175 // ----------------------------------------------------------------------------
176
177 void manualContourModel::MovePoint(int i,double dx,double dy,double dz)
178 {
179 printf("EED manualContourModel::MovePoint %p \n", this);
180         manualPoint *mp=_lstPoints[i];
181         double x=mp->GetX()+dx;
182         double y=mp->GetY()+dy;
183         double z=mp->GetZ()+dz;
184         mp->SetPoint(x,y,z);
185 }
186 // ----------------------------------------------------------------------------
187 void manualContourModel::MoveLstPoints(double dx,double dy,double dz)
188 {
189         // ToDo
190 }
191 // ----------------------------------------------------------------------------
192 void manualContourModel::MoveAllPoints(double dx,double dy,double dz)
193 {
194         int i,size=_lstPoints.size();
195         for (i=0;i<size;i++){
196                 MovePoint(i,dx,dy,dz);
197         }
198 }
199
200
201 // ----------------------------------------------------------------------------
202
203 // type=-1  x,y,z
204 // type=0       x,y
205 // type=1       y,z
206 // type=2       x,z
207 int      manualContourModel::GetIdPoint(double x, double y, double z, int i_range,int type)
208 {
209         double range = i_range+1;
210
211         double xx,yy,zz,dd,ddmin=9999999;
212         int ibak=-1;
213         int i,size=_lstPoints.size();
214         for (i=0;i<size;i++){
215                 manualPoint *mp=_lstPoints[i];
216                 xx=mp->GetX();
217                 yy=mp->GetY();
218                 zz=mp->GetZ();
219
220                 if (type==-1)
221                 {
222                         if ((fabs(xx-x)<range) && (fabs(yy-y)<range) && (fabs(zz-z)<range)) {
223                            dd=sqrt(   (xx-x)*(xx-x) + (yy-y)*(yy-y) + (zz-z)*(zz-z) );
224                            if (dd<ddmin){
225                                    ddmin=dd;
226                                    ibak=i;
227                            }
228                         }
229                 }
230                 if (type==0)
231                 {
232                         if ((fabs(yy-y)<range) && (fabs(zz-z)<range)) {
233                            dd=sqrt(   (yy-y)*(yy-y) + (zz-z)*(zz-z) );
234                            if (dd<ddmin){
235                                    ddmin=dd;
236                                    ibak=i;
237                            }
238                         }
239                 }
240                 if (type==1)
241                 {
242                         if ((fabs(xx-x)<range) && (fabs(zz-z)<range)) {
243                            dd=sqrt(   (xx-x)*(xx-x)  + (zz-z)*(zz-z) );
244                            if (dd<ddmin){
245                                    ddmin=dd;
246                                    ibak=i;
247                            }
248                         }
249                 }
250                 if (type==2)
251                 {
252                         if ((fabs(xx-x)<range) && (fabs(yy-y)<range) ) {
253                            dd=sqrt(   (xx-x)*(xx-x) + (yy-y)*(yy-y)  );
254                            if (dd<ddmin){
255                                    ddmin=dd;
256                                    ibak=i;
257                            }
258                         }
259                 }
260         }
261         return ibak;
262 }
263 // ----------------------------------------------------------------------------
264 manualPoint* manualContourModel::GetManualPoint(int id)
265 {
266         return _lstPoints[id];
267 }
268 // ----------------------------------------------------------------------------
269 int manualContourModel::GetSizeLstPoints()
270 {
271         return _lstPoints.size();
272 }
273 //----------------------------------------------------------------------------
274 int manualContourModel::GetNumberOfPointsSpline()
275 {
276         return _sizePointsContour;
277 }
278 //----------------------------------------------------------------------------
279 void manualContourModel::SetNumberOfPointsSpline(int size)
280 {
281         _sizePointsContour = size;
282 }
283
284 // ----------------------------------------------------------------------------
285
286 void manualContourModel::SetCloseContour(bool closeContour)
287 {
288         _closeContour = closeContour;
289         if (_closeContour==true)
290         {
291                 _cntSplineX->ClosedOn();
292                 _cntSplineY->ClosedOn();
293                 _cntSplineZ->ClosedOn();
294         } else {
295                 _cntSplineX->ClosedOff();
296                 _cntSplineY->ClosedOff();
297                 _cntSplineZ->ClosedOff();
298         }
299 }
300
301 // ----------------------------------------------------------------------------
302 bool manualContourModel::IfCloseContour()
303 {
304         return _closeContour;
305 }
306
307 // ----------------------------------------------------------------------------
308
309 void manualContourModel::UpdateSpline() // virtual
310 {
311         int i, np;
312     np  = _lstPoints.size();
313         manualPoint     *mp;
314         _cntSplineX->RemoveAllPoints();
315         _cntSplineY->RemoveAllPoints();
316         _cntSplineZ->RemoveAllPoints();
317     for( i = 0; i < np; i++ ) {
318                 mp = GetManualPoint(i);
319         _cntSplineX->AddPoint( i, mp->GetX() );
320         _cntSplineY->AddPoint( i, mp->GetY() );
321         _cntSplineZ->AddPoint( i, mp->GetZ() );
322     } //  rof
323
324 //JSTG 25-02-08 ---------------------------------------------------------------------------------------------
325         if (this->_closeContour==true)
326         {
327                 _delta_JSTG = (double) (np) / double (_sizePointsContour - 1);  //Without the -1 the curve is not close
328         } else {
329 //              _delta_JSTG = (double) (np-1) / double (_sizePointsContour );  //Without the -1 the curve is not close
330 //EED 9/7/2016          _delta_JSTG = (double) (np) / double (_sizePointsContour-1 );  //Without the -1 the curve is not close
331                 _delta_JSTG = (double) (np-1) / double (_sizePointsContour-1 );  //Without the -1 the curve is not close
332         }
333 //-----------------------------------------------------------------------------------------------------------
334 }
335
336 //---------------------------------------------------------------------------------
337
338 /*void manualContourModel::GetSplineiPoint(int i, double &x, double &y, double &z)
339 {
340         double delta=(double)(_lstPoints.size()) / (double)(_sizePointsContour);
341         double t = delta*(double)i;
342         GetSplinePoint(t, x, y, z);
343 }*/
344
345 //-----------------------------------------------------------------------------
346
347 //JSTG 25-02-08 ---------------------------------------------------------------
348 void manualContourModel::GetSpline_i_Point(int i, double *x, double *y, double *z) // virtal
349 {
350         GetSpline_t_Point(i*_delta_JSTG,x,y,z);
351 }
352
353 // ----------------------------------------------------------------------------
354
355 //JSTG 25-02-08 ---------------------------------------------------------------
356 void manualContourModel::GetSpline_t_Point(double t, double *x, double *y, double *z)
357 {
358         if (_lstPoints.size()==0)
359         {
360                 *x      = 0;
361                 *y      = 0;
362                 *z      = 0;
363         }
364         if (_lstPoints.size()==1)
365         {
366                 manualPoint     *mp;
367                 mp      = GetManualPoint(0);
368                 *x      = mp->GetX();
369                 *y      = mp->GetY();
370                 *z      = mp->GetZ();
371         }
372         if (_lstPoints.size()>=2)
373         {
374                 *x      = _cntSplineX->Evaluate(t);
375                 *y      = _cntSplineY->Evaluate(t);
376                 *z      = _cntSplineZ->Evaluate(t);
377         }
378 }
379
380 // ----------------------------------------------------------------------------
381 /*void manualContourModel::GetSplinePoint(double t, double &x, double &y, double &z)
382 {
383         if (_lstPoints.size()==0)
384         {
385                 x       = 0;
386                 y       = 0;
387                 z       = 0;
388         }
389         if (_lstPoints.size()==1)
390         {
391                 manualPoint     *mp;
392                 mp      = GetManualPoint(0);
393                 x       = mp->GetX();
394                 y       = mp->GetY();
395                 z       = mp->GetZ();
396         }
397         if (_lstPoints.size()>=2)
398         {
399                 x       = _cntSplineX->Evaluate(t);
400                 y       = _cntSplineY->Evaluate(t);
401                 z       = _cntSplineZ->Evaluate(t);
402         }
403 }*/
404
405 // ----------------------------------------------------------------------------
406 double manualContourModel::GetPathSize(double *spc)
407 {
408         double result = 0;
409         double x1,y1,z1;
410         double x2,y2,z2;
411 // JSTG 25-02-08 -----------------------------
412         //double t,delta;
413         //int i,np,nps;
414         int i;
415 //--------------------------------------------
416         if (_lstPoints.size()==2)
417         {
418                 x1 = spc[0] * _lstPoints[0]->GetX();
419                 y1 = spc[1] * _lstPoints[0]->GetY();
420                 z1 = spc[2] * _lstPoints[0]->GetZ();
421                 x2 = spc[0] * _lstPoints[1]->GetX();
422                 y2 = spc[1] * _lstPoints[1]->GetY();
423                 z2 = spc[2] * _lstPoints[1]->GetZ();
424                 result = sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1) );
425         }
426         if (_lstPoints.size()>2)
427         {
428 // JSTG 25-02-08 ------------------------------------------
429                 //np  = _lstPoints.size( );
430                 //nps = 200;
431                 //delta=( double ) ( np  ) / ( double ) ( nps  );
432                 UpdateSpline();
433                 //GetSplinePoint(0,x1,y1,z1);
434                 GetSpline_i_Point(0,&x1,&y1,&z1);
435                 x1 = spc[0] * x1; 
436                 y1 = spc[1] * y1; 
437                 z1 = spc[2] * z1; 
438                 //for( i = 1; i < nps; i++ )
439                 for( i = 1; i < GetNumberOfPointsSpline(); i++ )
440                 {
441                         //t = delta * (double)i;
442                         //GetSplinePoint(t,x2,y2,z2);
443                         GetSpline_i_Point(i,&x2,&y2,&z2);
444                         x2 = spc[0] * x2; 
445                         y2 = spc[1] * y2; 
446                         z2 = spc[2] * z2; 
447 //---------------------------------------------------------
448                         result=result + sqrt( (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) + (z2-z1)*(z2-z1) );
449                         x1=x2;
450                         y1=y2;
451                         z1=z2;
452                 }// for
453         }
454         return result;
455 }
456
457 // ----------------------------------------------------------------------------
458 double manualContourModel::GetPathArea(double *spc)
459 {
460         double result = 555;
461         if ((_lstPoints.size()>=3) && IfCloseContour()==true )
462         {
463                 double area;
464 //JSTG 25-02-08 ---------------------------------------------
465                 //double ti,tj;
466 //-----------------------------------------------------------
467                 double x1,y1,z1;
468                 double x2,y2,z2;
469                 bool okArea=true;
470                 int i, j;
471                 // This uses Green's theorem:
472                 // A = 1/2 * sum( xiyi+1 - xi+1yi); pO == pN
473                 // A < 0 -> A = |A| (a negative value could raise because points are
474                 // given in clockwise order).
475
476 //JSTG 25-02-08 -------------------------------------------------
477                 //int np  = _lstPoints.size( );
478                 //int nps = 200;
479                 int nps = GetNumberOfPointsSpline();
480                 //double delta=( double ) ( np  ) / ( double ) ( nps  );
481                 UpdateSpline();
482                 for( i = 0, area = 0.0; i < nps; i++ )
483                 {
484                         j = ( i + 1 ) % nps;
485                         //ti = delta * (double)i;
486                         //tj = delta * (double)j;
487                         //GetSplinePoint(ti,x1,y1,z1);
488                         //GetSplinePoint(tj,x2,y2,z2);
489                         GetSpline_i_Point(i,&x1,&y1,&z1);
490                         GetSpline_i_Point(j,&x2,&y2,&z2);
491 //----------------------------------------------------------------
492                         x1=spc[0]*x1;
493                         y1=spc[1]*y1;
494                         z1=spc[2]*z1;
495                         x2=spc[0]*x2;
496                         y2=spc[1]*y2;
497                         z2=spc[2]*z2;
498                         area += (x1 * y2 ) - ( x2 * y1 );
499                         if (z1!=z2)
500                         {
501                                 okArea=false;
502                         }
503                 }// for
504                 area /= 2.0;
505                 area = fabs( area );
506
507 /*
508                 for( i = 0, area = 0.0; i < _lstPoints.size(); i++ )
509                 {
510                         j = ( i + 1 ) % _lstPoints.size();
511                         //  Area
512                         area +=
513                                         (_lstPoints[i]->GetX() * _lstPoints[j]->GetY() ) -
514                                         ( _lstPoints[j]->GetX() * _lstPoints[i]->GetY() );
515                         if (_lstPoints[0]->GetZ()!=_lstPoints[i]->GetZ())
516                         {
517                                 okArea=false;
518                         }
519                 } // rof
520                 area /= 2.0;
521                 area = fabs( area );
522 */
523
524                 if (okArea==true)
525                 {
526                         result = area;
527                 } else {
528                         result = -1;
529                 }
530
531         } else {
532                 result = 0;
533         }
534         return result;
535 }
536
537 // ----------------------------------------------------------------------------
538 // p[x,y,z]   :  data in
539 // rp[x,y,z]  :  data out  result point
540 // rn[x,y,z]  :  data out   result normal
541 void manualContourModel::GetNearestPointAndNormal(double *p, double *rp,  double *rn)
542 {
543         double  distMin=999999999;
544         double  dist,dx,dy,dz;
545         double  x1,y1,z1;
546         double  x2,y2,z2;
547         int             i,np,nps;
548
549 //JSTG 25-02-08 -------------------
550         //double  tback;
551         int iback;
552         //double        t,delta;
553 //---------------------------------
554
555         np      = _lstPoints.size( );
556         if (np>=2)
557         {
558 // JSTG 25-02-08 ------------------------------------------
559                 //nps           = 200;
560                 nps = GetNumberOfPointsSpline();
561                 //delta = ( double ) ( np  ) / ( double ) ( nps  );
562                 UpdateSpline();
563                 //GetSplinePoint(0,x1,y1,z1);
564                 GetSpline_i_Point(0,&x1,&y1,&z1);
565                 for( i = 0; i < nps; i++ )
566                 {
567                         //t = delta * (double)i;
568                         //GetSplinePoint(t,x1,y1,z1);
569                         GetSpline_i_Point(i,&x1,&y1,&z1);
570 //----------------------------------------------------------
571                         dx= x1-p[0];
572                         dy= y1-p[1];
573                         dz= z1-p[2];
574                         dist = sqrt( dx*dx + dy*dy + dz*dz );
575                         if (dist<distMin)
576                         {
577                                 distMin  = dist;
578 //JSTG                  tback = t;
579                                 iback = i;
580                                 rp[0] = x1;
581                                 rp[1] = y1;
582                                 rp[2] = z1;
583                                 rn[0] = x2-x1;
584                                 rn[1] = y2-y1;
585                                 rn[2] = z2-z1;
586                         } // if
587                         x2 = x1;
588                         y2 = y1;
589                         z2 = z1;
590                 }// for
591 // JSTG 25-02-08 ------------------------------------------
592                 //if (tback==0)
593                 if (iback==0)
594                 {
595                         //t = delta * (double)1.0;
596                         //GetSplinePoint(t,x1,y1,z1);
597                         GetSpline_i_Point(i,&x1,&y1,&z1);
598 //----------------------------------------------------------
599                         rn[0] = rp[0]-x1;
600                         rn[1] = rp[1]-y1;
601                         rn[2] = rp[2]-z1;
602                 } // if iback 
603         } else {
604                 rp[0] = 0;
605                 rp[1] = 0;
606                 rp[2] = 0;
607                 rn[0] = -1;
608                 rn[1] = 0;
609                 rn[2] = 0;
610         } // if np
611 }
612
613 // ----------------------------------------------------------------------------
614 manualContourModel * manualContourModel::Clone() // virtual
615 {
616         manualContourModel * clone = new manualContourModel();
617         CopyAttributesTo(clone);
618         return clone;
619 }
620
621 // ----------------------------------------------------------------------------
622 void manualContourModel::Open(FILE *ff) // virtual
623 {
624         char tmp[255];
625         int i;
626         int numberOfControlPoints;
627         double x,y,z;
628
629         fscanf(ff,"%s",tmp); // NumberOfControlPoints
630         fscanf(ff,"%s",tmp); // ##
631         numberOfControlPoints = atoi(tmp);
632         for (i=0;i<numberOfControlPoints;i++)
633         {
634                 fscanf(ff,"%s",tmp); // X
635                 x = atof(tmp);
636                 fscanf(ff,"%s",tmp); // Y
637                 y = atof(tmp);
638                 fscanf(ff,"%s",tmp); // Z
639                 z = atof(tmp);
640                 AddPoint(x,y,z);
641         }
642 }
643
644 // ----------------------------------------------------------------------------
645 int manualContourModel::GetTypeModel() //virtual
646 {
647         // 0 spline
648         // 1 spline
649         // 2 rectangle
650         // 3 circle
651         // 4 BullEye
652         // 5 BullEyeSector
653         // 6 Line
654         return 1;
655 }
656
657 // ----------------------------------------------------------------------------
658 void manualContourModel::Save(FILE *ff) // virtual
659 {
660         int i,size=_lstPoints.size();
661         fprintf(ff,"TypeModel %d\n", GetTypeModel() );
662         fprintf(ff,"NumberOfControlPoints %d\n",size);
663         for (i=0;i<size;i++)
664         {
665                 manualPoint *mp=_lstPoints[i];
666                 fprintf(ff,"%f %f %f\n", mp->GetX(), mp->GetY(), mp->GetZ() );
667         }
668 }
669 //CMRU 03-09-09-----------------------------------------------------------------------------------------------
670 void manualContourModel::SaveData(FILE *ff)
671 {
672         std::string etiqueta = GetLabel();
673         if(etiqueta.empty())
674         {
675                 fprintf(ff,"Label: NO_LABEL\n");
676         } else {
677                 fprintf(ff,"Label: %s\n",etiqueta.c_str());
678         } // if etiqueta
679         fprintf(ff,"Real_Size: %f\n",GetRealSize());
680 }
681
682 void manualContourModel::OpenData(FILE *ff)
683 {
684         char tmp[255];
685
686         fscanf(ff,"%s",tmp); // Label:
687         fscanf(ff,"%s",tmp); // value
688         std::cout<<tmp<<std::endl;
689         //if(strcmp(tmp != "NO_LABEL") // JPR
690         if(strcmp(tmp,"NO_LABEL") != 0)
691         {
692                 SetLabel(tmp);
693         }
694         fscanf(ff,"%s",tmp); // Real_size
695         fscanf(ff,"%s",tmp);// #
696
697         //tmp.ToDouble(&tmp);
698         SetRealSize(atof(tmp));
699 }
700
701 //------------------------------------------------------------------------------------------------------------
702
703 // ---------------------------------------------------------------------------
704
705 void manualContourModel::CopyAttributesTo( manualContourModel * cloneObject)
706 {
707         // Fathers object
708         //XXXX::CopyAttributesTo(cloneObject);
709
710         cloneObject->SetCloseContour( this->IfCloseContour() );
711         int i, size = GetSizeLstPoints();
712         for( i=0; i<size; i++ )
713         {
714                 cloneObject->AddManualPoint( GetManualPoint( i )->Clone() );
715         }
716         cloneObject->SetNumberOfPointsSpline( GetNumberOfPointsSpline () );
717         cloneObject->SetCloseContour( _closeContour );
718         cloneObject->UpdateSpline();
719 }
720
721
722 // ---------------------------------------------------------------------------
723 void manualContourModel::AddManualPoint( manualPoint* theManualPoint )//private
724 {
725         _lstPoints.push_back( theManualPoint );
726 }
727
728 std::vector<manualBaseModel*> manualContourModel::ExploseModel(  )
729 {
730         std::vector<manualBaseModel*> lstTmp;
731         lstTmp.push_back(this);
732         return lstTmp;
733 }
734
735
736 // ----------------------------------------------------------------------------
737 void manualContourModel::Transform_Ax_Plus_B (double Ax, double Bx, double Ay, double By)
738 {
739         manualPoint * mp;
740
741         int i, size = GetSizeLstPoints();
742
743         for( i=0; i<size; i++ )
744         {
745                 mp = GetManualPoint( i );
746
747                 mp->SetPointX( mp->GetX()*Ax + Bx );
748                 mp->SetPointY( mp->GetY()*Ay + By );
749         }
750 }
751
752
753 //CMRU 17-08-09----------------------------------------------------------------------------
754 void manualContourModel::SetRealSize(double newRealSize) 
755 {
756         _realSize = newRealSize;
757 }
758
759 double manualContourModel::GetRealSize()
760 {
761         return _realSize;
762 }
763
764 //----------------------------------------------------------------------------