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