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();
47 // ----------------------------------------------------------------------------
48 int manualBaseModel::AddPoint(double x,double y,double z)
50 manualPoint *mp = new manualPoint();
54 return _lstPoints.size()-1;
56 // ----------------------------------------------------------------------------
57 int manualBaseModel::InsertPoint(double x,double y,double z)
59 double dd,ddmin=9999999;
64 int i,ii,iii,size=_lstPoints.size();
65 double j,MaxDivisions=20,porcentage;
70 for ( i=0 ; i<size ; i++ )
74 x1=_lstPoints[ii]->GetX();
75 y1=_lstPoints[ii]->GetY();
76 z1=_lstPoints[ii]->GetZ();
77 x2=_lstPoints[iii]->GetX();
78 y2=_lstPoints[iii]->GetY();
79 z2=_lstPoints[iii]->GetZ();
80 for (j=0; j<=MaxDivisions; j++)
82 porcentage=(j/MaxDivisions);
83 xx=(x2-x1)*porcentage+x1;
84 yy=(y2-y1)*porcentage+y1;
85 zz=(z2-z1)*porcentage+z1;
86 dd=sqrt( (xx-x)*(xx-x) + (yy-y)*(yy-y) + (zz-z)*(zz-z) );
96 InsertPoint_id(ibak,x,y,z);
100 // ----------------------------------------------------------------------------
101 void manualBaseModel::InsertPoint_id(int id, double x, double y, double z)
103 manualPoint *mp = new manualPoint();
105 std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + id;
106 _lstPoints.insert(itNum,mp);
108 // ----------------------------------------------------------------------------
110 void manualBaseModel::DeletePoint(int i)
112 std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + i;
113 _lstPoints.erase(itNum);
115 // ----------------------------------------------------------------------------
116 void manualBaseModel::DeleteAllPoints()
118 int i,size=_lstPoints.size();
119 for (i=0;i<size;i++){
120 _lstPoints.erase( _lstPoints.begin() );
123 // ----------------------------------------------------------------------------
125 void manualBaseModel::MovePoint(int i,double dx,double dy,double dz)
127 manualPoint *mp=_lstPoints[i];
128 double x=mp->GetX()+dx;
129 double y=mp->GetY()+dy;
130 double z=mp->GetZ()+dz;
133 // ----------------------------------------------------------------------------
134 void manualBaseModel::MoveLstPoints(double dx,double dy,double dz)
138 // ----------------------------------------------------------------------------
139 void manualBaseModel::MoveAllPoints(double dx,double dy,double dz)
141 int i,size=_lstPoints.size();
142 for (i=0;i<size;i++){
143 MovePoint(i,dx,dy,dz);
147 // ----------------------------------------------------------------------------
152 int manualBaseModel::GetIdPoint(double x, double y, double z, int i_range,int type)
154 double range = i_range+1;
156 double xx,yy,zz,dd,ddmin=9999999;
158 int i,size=_lstPoints.size();
159 for (i=0;i<size;i++){
160 manualPoint *mp=_lstPoints[i];
167 if ((fabs(xx-x)<range) && (fabs(yy-y)<range) && (fabs(zz-z)<range)) {
168 dd=sqrt( (xx-x)*(xx-x) + (yy-y)*(yy-y) + (zz-z)*(zz-z) );
177 if ((fabs(yy-y)<range) && (fabs(zz-z)<range)) {
178 dd=sqrt( (yy-y)*(yy-y) + (zz-z)*(zz-z) );
187 if ((fabs(xx-x)<range) && (fabs(zz-z)<range)) {
188 dd=sqrt( (xx-x)*(xx-x) + (zz-z)*(zz-z) );
197 if ((fabs(xx-x)<range) && (fabs(yy-y)<range) ) {
198 dd=sqrt( (xx-x)*(xx-x) + (yy-y)*(yy-y) );
208 // ----------------------------------------------------------------------------
209 int manualBaseModel::IsPoint(double x, double y)
213 int i,size=_lstPoints.size();
214 for (i=0;i<size;i++){
215 manualPoint *mp=_lstPoints[i];
219 //RaC Be Careful!! Cast to have a point like the one in the params 27-09-09
220 if(x==(int)xx && y==(int)yy )
227 // ----------------------------------------------------------------------------
228 manualPoint* manualBaseModel::GetManualPoint(int id)
230 return _lstPoints[id];
232 // ----------------------------------------------------------------------------
233 int manualBaseModel::GetSizeLstPoints()
235 return _lstPoints.size();
238 // ----------------------------------------------------------------------------
239 manualBaseModel * manualBaseModel :: Clone() // virtual
241 manualBaseModel * clone = new manualBaseModel();
242 CopyAttributesTo(clone);
246 // ----------------------------------------------------------------------------
247 int manualBaseModel::GetTypeModel() //virtual
260 // ---------------------------------------------------------------------------
262 void manualBaseModel::CopyAttributesTo( manualBaseModel * cloneObject)
264 int i, size = GetSizeLstPoints();
265 for( i=0; i<size; i++ )
267 cloneObject->AddManualPoint( GetManualPoint( i )->Clone() );
271 // ---------------------------------------------------------------------------
272 void manualBaseModel::AddManualPoint( manualPoint* theManualPoint )
274 _lstPoints.push_back( theManualPoint );
276 // ---------------------------------------------------------------------------
277 void manualBaseModel::Open(FILE *ff) // virtual
280 // ---------------------------------------------------------------------------
281 void manualBaseModel::Save(FILE *ff) // virtual
284 // ---------------------------------------------------------------------------
285 void manualBaseModel::SaveData(FILE *ff)// virtual
290 // ---------------------------------------------------------------------------
291 void manualBaseModel::SetNumberOfPointsSpline(int size)
293 _sizePointsContour = size;
295 // ---------------------------------------------------------------------------
296 double manualBaseModel::GetPathSize(double *spc)
300 // ---------------------------------------------------------------------------
301 void manualBaseModel::Transform_Ax_Plus_B (double Ax, double Bx, double Ay, double By)
304 // ---------------------------------------------------------------------------
305 void manualBaseModel::GetSpline_i_Point(int i, double *x, double *y, double *z)
307 //RaC 20-09-09 IF it's a points contour
308 if(GetTypeModel()==7){
309 if (_lstPoints.size()==0)
326 void manualBaseModel::GetSpline_t_Point(double t, double *x, double *y, double *z)
330 // ---------------------------------------------------------------------------
331 int manualBaseModel::GetNumberOfPointsSpline()
334 //RaC 20-09-09 IF it's a points contour
335 if(GetTypeModel()==7){
336 return _lstPoints.size();
338 return _sizePointsContour;
341 // ---------------------------------------------------------------------------
342 void manualBaseModel::UpdateSpline()
346 // ---------------------------------------------------------------------------
347 std::vector<manualBaseModel*> manualBaseModel::ExploseModel( )
349 std::vector<manualBaseModel*> lstTmp;
350 lstTmp.push_back(this);
354 // ---------------------------------------------------------------------------
355 double manualBaseModel::GetPathArea( double *spc )
359 void manualBaseModel::GetNearestPointAndNormal(double *p, double *rp, double *rn)
362 void manualBaseModel::SetCloseContour(bool closeContour)
365 bool manualBaseModel::IfCloseContour()
369 //CMRU 17-08-09----------------------------------------------------------------------------
370 void manualBaseModel::SetLabel(std::string newLabel)
374 void manualBaseModel::SetRealSize(double newRealSize)
378 double manualBaseModel::GetRealSize()
383 std::string manualBaseModel::GetLabel()
387 void manualBaseModel::OpenData(FILE *ff)
390 //----------------------------------------------------------------------------