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