1 /*# ---------------------------------------------------------------------
3 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------ */
26 #include "manualBaseModel.h"
28 // ----------------------------------------------------------------------------
29 manualBaseModel::manualBaseModel()
32 _sizePointsContour = 100; //JSTG 25-02-08 The change in the inisialization of these variable is critical.
37 // ----------------------------------------------------------------------------
38 manualBaseModel::~manualBaseModel()
40 int i,size=_lstPoints.size();
48 // ----------------------------------------------------------------------------
49 int manualBaseModel::AddPoint(double x,double y,double z)
51 manualPoint *mp = new manualPoint();
55 return _lstPoints.size()-1;
57 // ----------------------------------------------------------------------------
58 int manualBaseModel::InsertPoint(double x,double y,double z)
60 double dd,ddmin=9999999;
65 int i,ii,iii,size=_lstPoints.size();
66 double j,MaxDivisions=20,porcentage;
71 for ( i=0 ; i<size ; i++ )
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++)
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) );
97 InsertPoint_id(ibak,x,y,z);
101 // ----------------------------------------------------------------------------
102 void manualBaseModel::InsertPoint_id(int id, double x, double y, double z)
104 manualPoint *mp = new manualPoint();
106 std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + id;
107 _lstPoints.insert(itNum,mp);
109 // ----------------------------------------------------------------------------
111 void manualBaseModel::DeletePoint(int i)
113 std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + i;
114 _lstPoints.erase(itNum);
116 // ----------------------------------------------------------------------------
117 void manualBaseModel::DeleteAllPoints()
119 int i,size=_lstPoints.size();
120 for (i=0;i<size;i++){
121 _lstPoints.erase( _lstPoints.begin() );
124 // ----------------------------------------------------------------------------
126 void manualBaseModel::MovePoint(int i,double dx,double dy,double dz)
128 manualPoint *mp=_lstPoints[i];
129 double x=mp->GetX()+dx;
130 double y=mp->GetY()+dy;
131 double z=mp->GetZ()+dz;
134 // ----------------------------------------------------------------------------
135 void manualBaseModel::MoveLstPoints(double dx,double dy,double dz)
139 // ----------------------------------------------------------------------------
140 void manualBaseModel::MoveAllPoints(double dx,double dy,double dz)
142 int i,size=_lstPoints.size();
143 for (i=0;i<size;i++){
144 MovePoint(i,dx,dy,dz);
148 // ----------------------------------------------------------------------------
153 int manualBaseModel::GetIdPoint(double x, double y, double z, int i_range,int type)
155 double range = i_range+1;
157 double xx,yy,zz,dd,ddmin=9999999;
159 int i,size=_lstPoints.size();
160 for (i=0;i<size;i++){
161 manualPoint *mp=_lstPoints[i];
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) );
178 if ((fabs(yy-y)<range) && (fabs(zz-z)<range)) {
179 dd=sqrt( (yy-y)*(yy-y) + (zz-z)*(zz-z) );
188 if ((fabs(xx-x)<range) && (fabs(zz-z)<range)) {
189 dd=sqrt( (xx-x)*(xx-x) + (zz-z)*(zz-z) );
198 if ((fabs(xx-x)<range) && (fabs(yy-y)<range) ) {
199 dd=sqrt( (xx-x)*(xx-x) + (yy-y)*(yy-y) );
209 // ----------------------------------------------------------------------------
210 int manualBaseModel::IsPoint(double x, double y)
214 int i,size=_lstPoints.size();
215 for (i=0;i<size;i++){
216 manualPoint *mp=_lstPoints[i];
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 )
228 // ----------------------------------------------------------------------------
229 manualPoint* manualBaseModel::GetManualPoint(int id)
231 return _lstPoints[id];
233 // ----------------------------------------------------------------------------
234 int manualBaseModel::GetSizeLstPoints()
236 return _lstPoints.size();
239 // ----------------------------------------------------------------------------
240 manualBaseModel * manualBaseModel :: Clone() // virtual
242 manualBaseModel * clone = new manualBaseModel();
243 CopyAttributesTo(clone);
247 // ----------------------------------------------------------------------------
248 int manualBaseModel::GetTypeModel() //virtual
261 // ---------------------------------------------------------------------------
263 void manualBaseModel::CopyAttributesTo( manualBaseModel * cloneObject)
265 int i, size = GetSizeLstPoints();
266 for( i=0; i<size; i++ )
268 cloneObject->AddManualPoint( GetManualPoint( i )->Clone() );
272 // ---------------------------------------------------------------------------
273 void manualBaseModel::AddManualPoint( manualPoint* theManualPoint )
275 _lstPoints.push_back( theManualPoint );
277 // ---------------------------------------------------------------------------
278 void manualBaseModel::Open(FILE *ff) // virtual
281 // ---------------------------------------------------------------------------
282 void manualBaseModel::Save(FILE *ff) // virtual
285 // ---------------------------------------------------------------------------
286 void manualBaseModel::SaveData(FILE *ff)// virtual
291 // ---------------------------------------------------------------------------
292 void manualBaseModel::SetNumberOfPointsSpline(int size)
294 _sizePointsContour = size;
296 // ---------------------------------------------------------------------------
297 double manualBaseModel::GetPathSize(double *spc)
301 // ---------------------------------------------------------------------------
302 void manualBaseModel::Transform_Ax_Plus_B (double Ax, double Bx, double Ay, double By)
305 // ---------------------------------------------------------------------------
306 void manualBaseModel::GetSpline_i_Point(int i, double *x, double *y, double *z)
308 //RaC 20-09-09 IF it's a points contour
309 if(GetTypeModel()==7){
310 if (_lstPoints.size()==0)
327 void manualBaseModel::GetSpline_t_Point(double t, double *x, double *y, double *z)
331 // ---------------------------------------------------------------------------
332 int manualBaseModel::GetNumberOfPointsSpline()
335 //RaC 20-09-09 IF it's a points contour
336 if(GetTypeModel()==7){
337 return _lstPoints.size();
339 return _sizePointsContour;
342 // ---------------------------------------------------------------------------
343 void manualBaseModel::UpdateSpline()
347 // ---------------------------------------------------------------------------
348 std::vector<manualBaseModel*> manualBaseModel::ExploseModel( )
350 std::vector<manualBaseModel*> lstTmp;
351 lstTmp.push_back(this);
355 // ---------------------------------------------------------------------------
356 double manualBaseModel::GetPathArea( double *spc )
360 void manualBaseModel::GetNearestPointAndNormal(double *p, double *rp, double *rn)
363 void manualBaseModel::SetCloseContour(bool closeContour)
366 bool manualBaseModel::IfCloseContour()
370 //CMRU 17-08-09----------------------------------------------------------------------------
372 void manualBaseModel::SetRealSize(double newRealSize)
376 double manualBaseModel::GetRealSize()
381 void manualBaseModel::OpenData(FILE *ff)
385 void manualBaseModel::SetLabel(std::string newLabel)
390 std::string manualBaseModel::GetLabel()
395 void manualBaseModel::SetLabel2(std::string newLabel)
400 std::string manualBaseModel::GetLabel2()
407 //----------------------------------------------------------------------------