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