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