]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualBaseModel.cpp
06d7f330374a88f974fd0cad4e22e5c5a591e04f
[creaMaracasVisu.git] / lib / maracasVisuLib / src / interface / wxWindows / widgets / manualContour / manualBaseModel.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 "manualBaseModel.h"
27
28 // ----------------------------------------------------------------------------
29 manualBaseModel::manualBaseModel()
30 {
31 //EED2017
32         _sizePointsContour      = 100;                  //JSTG 25-02-08 The change in the inisialization of these variable is critical.
33
34 }
35
36 // ----------------------------------------------------------------------------
37 manualBaseModel::~manualBaseModel()
38 {
39         int i,size=_lstPoints.size();
40         for (i=0;i<size; i++)
41         {
42                 delete _lstPoints[i];
43         }
44         _lstPoints.clear();
45
46 }
47 // ----------------------------------------------------------------------------
48 int manualBaseModel::AddPoint(double x,double y,double z)
49 {
50    manualPoint *mp = new manualPoint();
51    mp->SetPoint(x,y,z);
52    AddManualPoint(mp);
53
54    return _lstPoints.size()-1;
55 }
56 // ----------------------------------------------------------------------------
57 int manualBaseModel::InsertPoint(double x,double y,double z)
58 {
59         double dd,ddmin=9999999;
60         int    ibak=0;
61         double xx,x1,x2;
62         double yy,y1,y2;
63         double zz,z1,z2;
64         int i,ii,iii,size=_lstPoints.size();
65         double j,MaxDivisions=20,porcentage;
66         int sizeB=size;
67
68         double jbak;
69
70         for ( i=0 ; i<size ; i++ )
71         {
72                 ii=i % sizeB ;
73                 iii=(i+1) % sizeB;
74                 x1=_lstPoints[ii]->GetX();
75                 y1=_lstPoints[ii]->GetY();
76                 z1=_lstPoints[ii]->GetZ();
77                 x2=_lstPoints[iii]->GetX();
78                 y2=_lstPoints[iii]->GetY();
79                 z2=_lstPoints[iii]->GetZ();
80                 for (j=0; j<=MaxDivisions; j++)
81                 {
82                         porcentage=(j/MaxDivisions);
83                         xx=(x2-x1)*porcentage+x1;
84                         yy=(y2-y1)*porcentage+y1;
85                         zz=(z2-z1)*porcentage+z1;
86                         dd=sqrt( (xx-x)*(xx-x) + (yy-y)*(yy-y) + (zz-z)*(zz-z) );
87                         if ( dd<ddmin )
88                         {
89                                 ddmin=dd;
90                                 ibak=iii;
91                                 jbak=j;
92                         }
93                 }
94         }
95
96         InsertPoint_id(ibak,x,y,z);
97
98         return ibak;
99 }
100 // ----------------------------------------------------------------------------
101 void manualBaseModel::InsertPoint_id(int id, double x, double y, double z)
102 {
103         manualPoint *mp = new manualPoint();
104         mp->SetPoint(x,y,z);
105         std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + id;
106         _lstPoints.insert(itNum,mp);
107 }
108 // ----------------------------------------------------------------------------
109
110 void manualBaseModel::DeletePoint(int i)
111 {
112         std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + i;
113    _lstPoints.erase(itNum);
114 }
115 // ----------------------------------------------------------------------------
116 void manualBaseModel::DeleteAllPoints()
117 {
118         int i,size=_lstPoints.size();
119         for (i=0;i<size;i++){
120            _lstPoints.erase( _lstPoints.begin() );
121         }
122 }
123 // ----------------------------------------------------------------------------
124
125 void manualBaseModel::MovePoint(int i,double dx,double dy,double dz)
126 {
127         manualPoint *mp=_lstPoints[i];
128         double x=mp->GetX()+dx;
129         double y=mp->GetY()+dy;
130         double z=mp->GetZ()+dz;
131         mp->SetPoint(x,y,z);
132 }
133 // ----------------------------------------------------------------------------
134 void manualBaseModel::MoveLstPoints(double dx,double dy,double dz)
135 {
136         // ToDo
137 }
138 // ----------------------------------------------------------------------------
139 void manualBaseModel::MoveAllPoints(double dx,double dy,double dz)
140 {
141         int i,size=_lstPoints.size();
142         for (i=0;i<size;i++){
143                 MovePoint(i,dx,dy,dz);
144         }
145 }
146
147 // ----------------------------------------------------------------------------
148 // type=-1  x,y,z
149 // type=0       y,z
150 // type=1       x,z
151 // type=2       x,y
152 int      manualBaseModel::GetIdPoint(double x, double y, double z, int i_range,int type)
153 {
154         double range = i_range+1;
155
156         double xx,yy,zz,dd,ddmin=9999999;
157         int ibak=-1;
158         int i,size=_lstPoints.size();
159         for (i=0;i<size;i++){
160                 manualPoint *mp=_lstPoints[i];
161                 xx=mp->GetX();
162                 yy=mp->GetY();
163                 zz=mp->GetZ();
164
165                 if (type==-1)
166                 {
167                         if ((fabs(xx-x)<range) && (fabs(yy-y)<range) && (fabs(zz-z)<range)) {
168                            dd=sqrt(   (xx-x)*(xx-x) + (yy-y)*(yy-y) + (zz-z)*(zz-z) );
169                            if (dd<ddmin){
170                                    ddmin=dd;
171                                    ibak=i;
172                            }
173                         }
174                 }
175                 if (type==0)
176                 {
177                         if ((fabs(yy-y)<range) && (fabs(zz-z)<range)) {
178                            dd=sqrt(   (yy-y)*(yy-y) + (zz-z)*(zz-z) );
179                            if (dd<ddmin){
180                                    ddmin=dd;
181                                    ibak=i;
182                            }
183                         }
184                 }
185                 if (type==1)
186                 {
187                         if ((fabs(xx-x)<range) && (fabs(zz-z)<range)) {
188                            dd=sqrt(   (xx-x)*(xx-x)  + (zz-z)*(zz-z) );
189                            if (dd<ddmin){
190                                    ddmin=dd;
191                                    ibak=i;
192                            }
193                         }
194                 }
195                 if (type==2)
196                 {
197                         if ((fabs(xx-x)<range) && (fabs(yy-y)<range) ) {
198                            dd=sqrt(   (xx-x)*(xx-x) + (yy-y)*(yy-y)  );
199                            if (dd<ddmin){
200                                    ddmin=dd;
201                                    ibak=i;
202                            }
203                         }
204                 }
205         }
206         return ibak;
207 }
208 // ----------------------------------------------------------------------------
209 int      manualBaseModel::IsPoint(double x, double y)
210 {
211         double xx,yy/*,zz*/;
212         bool exists=false;
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
219                 //RaC Be Careful!! Cast to have a point like the one in the params 27-09-09
220                 if(x==(int)xx && y==(int)yy )
221                 {
222                         exists=true;
223                 }
224         }
225         return exists;
226 }
227 // ----------------------------------------------------------------------------
228 manualPoint* manualBaseModel::GetManualPoint(int id)
229 {
230         return _lstPoints[id];
231 }
232 // ----------------------------------------------------------------------------
233 int manualBaseModel::GetSizeLstPoints()
234 {
235         return _lstPoints.size();
236 }
237
238 // ----------------------------------------------------------------------------
239 manualBaseModel * manualBaseModel :: Clone() // virtual
240 {
241         manualBaseModel * clone = new manualBaseModel();
242         CopyAttributesTo(clone);
243         return clone;
244 }
245
246 // ----------------------------------------------------------------------------
247 int manualBaseModel::GetTypeModel() //virtual
248 {
249         // 0 spline
250         // 1 spline
251         // 2 rectangle
252         // 3 circle
253         // 4 BullEye
254         // 5 BullEyeSector
255         // 6 Line
256         // 7 Points
257         return 7;
258 }
259
260 // ---------------------------------------------------------------------------
261
262 void manualBaseModel::CopyAttributesTo( manualBaseModel * cloneObject)
263 {
264         int i, size = GetSizeLstPoints();
265         for( i=0; i<size; i++ )
266         {
267                 cloneObject->AddManualPoint( GetManualPoint( i )->Clone() );
268         }
269 }
270
271 // ---------------------------------------------------------------------------
272 void manualBaseModel::AddManualPoint( manualPoint* theManualPoint )
273 {
274         _lstPoints.push_back( theManualPoint );
275 }
276 // ---------------------------------------------------------------------------
277 void manualBaseModel::Open(FILE *ff)    // virtual
278 {
279 }
280 // ---------------------------------------------------------------------------
281 void manualBaseModel::Save(FILE *ff)    // virtual
282 {
283 }
284 // ---------------------------------------------------------------------------
285 void manualBaseModel::SaveData(FILE *ff)// virtual
286 {
287 }
288
289
290 // ---------------------------------------------------------------------------
291 void manualBaseModel::SetNumberOfPointsSpline(int size)
292 {
293         _sizePointsContour = size;
294 }
295 // ---------------------------------------------------------------------------
296 double manualBaseModel::GetPathSize()
297 {
298         return 0.0;
299 }
300 // ---------------------------------------------------------------------------
301 void manualBaseModel::Transform_Ax_Plus_B (double Ax, double Bx, double Ay, double By)
302 {
303 }
304 // ---------------------------------------------------------------------------
305 void manualBaseModel::GetSpline_i_Point(int i, double *x, double *y, double *z)
306 {
307         //RaC 20-09-09 IF it's a points contour
308         if(GetTypeModel()==7){
309                 if (_lstPoints.size()==0)
310                 {
311                         *x      = 0;
312                         *y      = 0;
313                         *z      = 0;
314                 }
315                 else
316                 {
317                         manualPoint     *mp;
318                         mp      = _lstPoints[i];
319                         *x      = mp->GetX();
320                         *y      = mp->GetY();
321                         *z      = mp->GetZ();
322                 }
323         }
324 }
325
326 void manualBaseModel::GetSpline_t_Point(double t, double *x, double *y, double *z)
327 {
328 }
329
330 // ---------------------------------------------------------------------------
331 int     manualBaseModel::GetNumberOfPointsSpline()
332 {
333
334         //RaC 20-09-09 IF it's a points contour
335         if(GetTypeModel()==7){
336                 return _lstPoints.size();
337         }
338         return _sizePointsContour;
339 }
340
341 // ---------------------------------------------------------------------------
342 void manualBaseModel::UpdateSpline()
343 {
344 }
345
346 // ---------------------------------------------------------------------------
347 std::vector<manualBaseModel*> manualBaseModel::ExploseModel(  )
348 {
349         std::vector<manualBaseModel*> lstTmp;
350         lstTmp.push_back(this);
351         return lstTmp;
352 }
353
354 // ---------------------------------------------------------------------------
355 double manualBaseModel::GetPathArea()
356 {
357         return 0.0;
358 }
359 void manualBaseModel::GetNearestPointAndNormal(double *p, double *rp,  double *rn)
360 {
361 }
362 void manualBaseModel::SetCloseContour(bool closeContour)
363 {
364 }
365 bool manualBaseModel::IfCloseContour()
366 {
367         return false;
368 }
369 //CMRU 17-08-09----------------------------------------------------------------------------
370 void manualBaseModel::SetLabel(std::string newLabel)
371 {
372 }
373
374 void manualBaseModel::SetRealSize(double newRealSize) 
375 {
376 }
377
378 double manualBaseModel::GetRealSize()
379 {
380         return -1;
381 }
382
383 std::string manualBaseModel::GetLabel()
384 {
385         return "";
386 }
387 void manualBaseModel::OpenData(FILE *ff)
388 {
389 }
390 //----------------------------------------------------------------------------