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