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.
36 // ----------------------------------------------------------------------------
37 manualBaseModel::~manualBaseModel()
39 int i,size=_lstPoints.size();
40 for (i=0;i<size; i++){
46 // ----------------------------------------------------------------------------
47 int manualBaseModel::AddPoint(double x,double y,double z)
49 manualPoint *mp = new manualPoint();
53 return _lstPoints.size()-1;
55 // ----------------------------------------------------------------------------
56 int manualBaseModel::InsertPoint(double x,double y,double z)
58 double dd,ddmin=9999999;
63 int i,ii,iii,size=_lstPoints.size();
64 double j,MaxDivisions=20,porcentage;
69 for ( i=0 ; i<size ; i++ )
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++)
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) );
95 InsertPoint_id(ibak,x,y,z);
99 // ----------------------------------------------------------------------------
100 void manualBaseModel::InsertPoint_id(int id, double x, double y, double z)
102 manualPoint *mp = new manualPoint();
104 std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + id;
105 _lstPoints.insert(itNum,mp);
107 // ----------------------------------------------------------------------------
109 void manualBaseModel::DeletePoint(int i)
111 std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + i;
112 _lstPoints.erase(itNum);
114 // ----------------------------------------------------------------------------
115 void manualBaseModel::DeleteAllPoints()
117 int i,size=_lstPoints.size();
118 for (i=0;i<size;i++){
119 _lstPoints.erase( _lstPoints.begin() );
122 // ----------------------------------------------------------------------------
124 void manualBaseModel::MovePoint(int i,double dx,double dy,double dz)
126 manualPoint *mp=_lstPoints[i];
127 double x=mp->GetX()+dx;
128 double y=mp->GetY()+dy;
129 double z=mp->GetZ()+dz;
132 // ----------------------------------------------------------------------------
133 void manualBaseModel::MoveLstPoints(double dx,double dy,double dz)
137 // ----------------------------------------------------------------------------
138 void manualBaseModel::MoveAllPoints(double dx,double dy,double dz)
140 int i,size=_lstPoints.size();
141 for (i=0;i<size;i++){
142 MovePoint(i,dx,dy,dz);
146 // ----------------------------------------------------------------------------
151 int manualBaseModel::GetIdPoint(double x, double y, double z, int i_range,int type)
153 double range = i_range+1;
155 double xx,yy,zz,dd,ddmin=9999999;
157 int i,size=_lstPoints.size();
158 for (i=0;i<size;i++){
159 manualPoint *mp=_lstPoints[i];
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) );
176 if ((fabs(yy-y)<range) && (fabs(zz-z)<range)) {
177 dd=sqrt( (yy-y)*(yy-y) + (zz-z)*(zz-z) );
186 if ((fabs(xx-x)<range) && (fabs(zz-z)<range)) {
187 dd=sqrt( (xx-x)*(xx-x) + (zz-z)*(zz-z) );
196 if ((fabs(xx-x)<range) && (fabs(yy-y)<range) ) {
197 dd=sqrt( (xx-x)*(xx-x) + (yy-y)*(yy-y) );
207 // ----------------------------------------------------------------------------
208 int manualBaseModel::IsPoint(double x, double y)
212 int i,size=_lstPoints.size();
213 for (i=0;i<size;i++){
214 manualPoint *mp=_lstPoints[i];
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 )
226 // ----------------------------------------------------------------------------
227 manualPoint* manualBaseModel::GetManualPoint(int id)
229 return _lstPoints[id];
231 // ----------------------------------------------------------------------------
232 int manualBaseModel::GetSizeLstPoints()
234 return _lstPoints.size();
237 // ----------------------------------------------------------------------------
238 manualBaseModel * manualBaseModel :: Clone() // virtual
240 manualBaseModel * clone = new manualBaseModel();
241 CopyAttributesTo(clone);
245 // ----------------------------------------------------------------------------
246 int manualBaseModel::GetTypeModel() //virtual
259 // ---------------------------------------------------------------------------
261 void manualBaseModel::CopyAttributesTo( manualBaseModel * cloneObject)
263 int i, size = GetSizeLstPoints();
264 for( i=0; i<size; i++ )
266 cloneObject->AddManualPoint( GetManualPoint( i )->Clone() );
270 // ---------------------------------------------------------------------------
271 void manualBaseModel::AddManualPoint( manualPoint* theManualPoint )
273 _lstPoints.push_back( theManualPoint );
275 // ---------------------------------------------------------------------------
276 void manualBaseModel::Open(FILE *ff) // virtual
279 // ---------------------------------------------------------------------------
280 void manualBaseModel::Save(FILE *ff) // virtual
283 // ---------------------------------------------------------------------------
284 void manualBaseModel::SaveData(FILE *ff)// virtual
289 // ---------------------------------------------------------------------------
290 void manualBaseModel::SetNumberOfPointsSpline(int size)
292 _sizePointsContour = size;
294 // ---------------------------------------------------------------------------
295 double manualBaseModel::GetPathSize()
299 // ---------------------------------------------------------------------------
300 void manualBaseModel::Transform_Ax_Plus_B (double Ax, double Bx, double Ay, double By)
303 // ---------------------------------------------------------------------------
304 void manualBaseModel::GetSpline_i_Point(int i, double *x, double *y, double *z)
306 //RaC 20-09-09 IF it's a points contour
307 if(GetTypeModel()==7){
308 if (_lstPoints.size()==0)
325 void manualBaseModel::GetSpline_t_Point(double t, double *x, double *y, double *z)
329 // ---------------------------------------------------------------------------
330 int manualBaseModel::GetNumberOfPointsSpline()
333 //RaC 20-09-09 IF it's a points contour
334 if(GetTypeModel()==7){
335 return _lstPoints.size();
337 return _sizePointsContour;
340 // ---------------------------------------------------------------------------
341 void manualBaseModel::UpdateSpline()
345 // ---------------------------------------------------------------------------
346 std::vector<manualBaseModel*> manualBaseModel::ExploseModel( )
348 std::vector<manualBaseModel*> lstTmp;
349 lstTmp.push_back(this);
353 // ---------------------------------------------------------------------------
354 double manualBaseModel::GetPathArea()
358 void manualBaseModel::GetNearestPointAndNormal(double *p, double *rp, double *rn)
361 void manualBaseModel::SetCloseContour(bool closeContour)
364 bool manualBaseModel::IfCloseContour()
368 //CMRU 17-08-09----------------------------------------------------------------------------
369 void manualBaseModel::SetLabel(std::string newLabel)
373 void manualBaseModel::SetRealSize(double newRealSize)
377 double manualBaseModel::GetRealSize()
382 std::string manualBaseModel::GetLabel()
386 void manualBaseModel::OpenData(FILE *ff)
389 //----------------------------------------------------------------------------