]> Creatis software - creaMaracasVisu.git/blob - lib/maracasVisuLib/src/interface/wxWindows/widgets/manualContour/manualBaseModel.cpp
comment out unused
[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 // ----------------------------------------------------------------------------
203 manualPoint* manualBaseModel::GetManualPoint(int id)
204 {
205         return _lstPoints[id];
206 }
207 // ----------------------------------------------------------------------------
208 int manualBaseModel::GetSizeLstPoints()
209 {
210         return _lstPoints.size();
211 }
212
213 // ----------------------------------------------------------------------------
214 manualBaseModel * manualBaseModel :: Clone() // virtual
215 {
216         manualBaseModel * clone = new manualBaseModel();
217         CopyAttributesTo(clone);
218         return clone;
219 }
220
221 // ----------------------------------------------------------------------------
222 int manualBaseModel::GetTypeModel() //virtual
223 {
224         // 0 spline
225         // 1 spline
226         // 2 rectangle
227         // 3 circle
228         // 4 BullEye
229         // 5 BullEyeSector
230         // 6 Line
231         // 7 Points
232         return 7;
233 }
234
235 // ---------------------------------------------------------------------------
236
237 void manualBaseModel::CopyAttributesTo( manualBaseModel * cloneObject)
238 {
239         int i, size = GetSizeLstPoints();
240         for( i=0; i<size; i++ )
241         {
242                 cloneObject->AddManualPoint( GetManualPoint( i )->Clone() );
243         }
244 }
245
246
247 // ---------------------------------------------------------------------------
248 void manualBaseModel::AddManualPoint( manualPoint* theManualPoint )
249 {
250         _lstPoints.push_back( theManualPoint );
251 }
252
253 void manualBaseModel::Open(FILE *ff)    // virtual
254 {
255 }
256 void manualBaseModel::Save(FILE *ff)    // virtual
257 {
258 }
259
260 void manualBaseModel::SaveData(FILE *ff)// virtual
261 {
262 }
263
264
265 // ---------------------------------------------------------------------------
266 void manualBaseModel::SetNumberOfPointsSpline(int size)
267 {
268         _sizePointsContour = size;
269 }
270
271 double manualBaseModel::GetPathSize()
272 {
273         return 0.0;
274 }
275
276 void manualBaseModel::Transform_Ax_Plus_B (double Ax, double Bx, double Ay, double By)
277 {
278 }
279
280 void manualBaseModel::GetSpline_i_Point(int i, double *x, double *y, double *z)
281 {
282         //RaC 20-09-09 IF it's a points contour
283         if(GetTypeModel()==7){
284                 if (_lstPoints.size()==0)
285                 {
286                         *x      = 0;
287                         *y      = 0;
288                         *z      = 0;
289                 }
290                 else
291                 {
292                         manualPoint     *mp;
293                         mp      = _lstPoints[i];
294                         *x      = mp->GetX();
295                         *y      = mp->GetY();
296                         *z      = mp->GetZ();
297                 }
298
299         }
300
301 }
302
303 void manualBaseModel::GetSpline_t_Point(double t, double *x, double *y, double *z)
304 {
305 }
306
307 // ---------------------------------------------------------------------------
308 int     manualBaseModel::GetNumberOfPointsSpline()
309 {
310
311         //RaC 20-09-09 IF it's a points contour
312         if(GetTypeModel()==7){
313                 return _lstPoints.size();
314         }
315         return _sizePointsContour;
316 }
317
318 // ---------------------------------------------------------------------------
319 void manualBaseModel::UpdateSpline()
320 {
321 }
322
323 // ---------------------------------------------------------------------------
324 std::vector<manualBaseModel*> manualBaseModel::ExploseModel(  )
325 {
326         std::vector<manualBaseModel*> lstTmp;
327         lstTmp.push_back(this);
328         return lstTmp;
329 }
330
331 // ---------------------------------------------------------------------------
332 double                  manualBaseModel::GetPathArea()
333 {
334         return 0.0;
335 }
336 void                    manualBaseModel::GetNearestPointAndNormal(double *p, double *rp,  double *rn)
337 {
338 }
339 void                    manualBaseModel::SetCloseContour(bool closeContour)
340 {
341 }
342 bool                    manualBaseModel::IfCloseContour()
343 {
344         return false;
345 }
346 //CMRU 17-08-09----------------------------------------------------------------------------
347 void manualBaseModel::SetLabel(std::string newLabel)
348 {
349 }
350
351 void manualBaseModel::SetRealSize(double newRealSize) 
352 {
353 }
354
355 double manualBaseModel::GetRealSize()
356 {
357         return -1;
358 }
359
360 std::string manualBaseModel::GetLabel()
361 {
362         return "";
363 }
364 void manualBaseModel::OpenData(FILE *ff)
365 {
366 }
367 //----------------------------------------------------------------------------