manualBaseModel.cpp

Go to the documentation of this file.
00001 #include "manualBaseModel.h"
00002 
00003 // ----------------------------------------------------------------------------
00004 manualBaseModel::manualBaseModel()
00005 {
00006 
00007         _sizePointsContour      = 100;                  //JSTG 25-02-08 The change in the inisialization of these variable is critical.
00008 
00009 }
00010 
00011 // ----------------------------------------------------------------------------
00012 manualBaseModel::~manualBaseModel()
00013 {
00014         int i,size=_lstPoints.size();
00015         for (i=0;i<size; i++){
00016                 delete _lstPoints[i];
00017         }
00018         _lstPoints.clear();
00019 
00020 }
00021 // ----------------------------------------------------------------------------
00022 int manualBaseModel::AddPoint(double x,double y,double z)
00023 {
00024    manualPoint *mp = new manualPoint();
00025    mp->SetPoint(x,y,z);
00026    AddManualPoint(mp);
00027 
00028    return _lstPoints.size()-1;
00029 }
00030 // ----------------------------------------------------------------------------
00031 int manualBaseModel::InsertPoint(double x,double y,double z)
00032 {
00033         double dd,ddmin=9999999;
00034         int    ibak=0;
00035         double xx,x1,x2;
00036         double yy,y1,y2;
00037         double zz,z1,z2;
00038         int i,ii,iii,size=_lstPoints.size();
00039         double j,MaxDivisions=20,porcentage;
00040         int sizeB=size;
00041 
00042         double jbak;
00043 
00044         for ( i=0 ; i<size ; i++ )
00045         {
00046                 ii=i % sizeB ;
00047                 iii=(i+1) % sizeB;
00048                 x1=_lstPoints[ii]->GetX();
00049                 y1=_lstPoints[ii]->GetY();
00050                 z1=_lstPoints[ii]->GetZ();
00051                 x2=_lstPoints[iii]->GetX();
00052                 y2=_lstPoints[iii]->GetY();
00053                 z2=_lstPoints[iii]->GetZ();
00054                 for (j=0; j<=MaxDivisions; j++)
00055                 {
00056                         porcentage=(j/MaxDivisions);
00057                         xx=(x2-x1)*porcentage+x1;
00058                         yy=(y2-y1)*porcentage+y1;
00059                         zz=(z2-z1)*porcentage+z1;
00060                         dd=sqrt( (xx-x)*(xx-x) + (yy-y)*(yy-y) + (zz-z)*(zz-z) );
00061                         if ( dd<ddmin )
00062                         {
00063                                 ddmin=dd;
00064                                 ibak=iii;
00065                                 jbak=j;
00066                         }
00067                 }
00068         }
00069 
00070 
00071         InsertPoint_id(ibak,x,y,z);
00072 
00073         return ibak;
00074 }
00075 // ----------------------------------------------------------------------------
00076 void manualBaseModel::InsertPoint_id(int id, double x, double y, double z)
00077 {
00078         manualPoint *mp = new manualPoint();
00079         mp->SetPoint(x,y,z);
00080         std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + id;
00081         _lstPoints.insert(itNum,mp);
00082 }
00083 // ----------------------------------------------------------------------------
00084 
00085 void manualBaseModel::DeletePoint(int i)
00086 {
00087         std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + i;
00088    _lstPoints.erase(itNum);
00089 }
00090 // ----------------------------------------------------------------------------
00091 void manualBaseModel::DeleteAllPoints()
00092 {
00093         int i,size=_lstPoints.size();
00094         for (i=0;i<size;i++){
00095            _lstPoints.erase( _lstPoints.begin() );
00096         }
00097 }
00098 // ----------------------------------------------------------------------------
00099 
00100 void manualBaseModel::MovePoint(int i,double dx,double dy,double dz)
00101 {
00102         manualPoint *mp=_lstPoints[i];
00103         double x=mp->GetX()+dx;
00104         double y=mp->GetY()+dy;
00105         double z=mp->GetZ()+dz;
00106         mp->SetPoint(x,y,z);
00107 }
00108 // ----------------------------------------------------------------------------
00109 void manualBaseModel::MoveLstPoints(double dx,double dy,double dz)
00110 {
00111         // ToDo
00112 }
00113 // ----------------------------------------------------------------------------
00114 void manualBaseModel::MoveAllPoints(double dx,double dy,double dz)
00115 {
00116         int i,size=_lstPoints.size();
00117         for (i=0;i<size;i++){
00118                 MovePoint(i,dx,dy,dz);
00119         }
00120 }
00121 
00122 
00123 // ----------------------------------------------------------------------------
00124 // type=-1  x,y,z
00125 // type=0       y,z
00126 // type=1       x,z
00127 // type=2       x,y
00128 int      manualBaseModel::GetIdPoint(double x, double y, double z, int i_range,int type)
00129 {
00130         double range = i_range+1;
00131 
00132         double xx,yy,zz,dd,ddmin=9999999;
00133         int ibak=-1;
00134         int i,size=_lstPoints.size();
00135         for (i=0;i<size;i++){
00136                 manualPoint *mp=_lstPoints[i];
00137                 xx=mp->GetX();
00138                 yy=mp->GetY();
00139                 zz=mp->GetZ();
00140 
00141                 if (type==-1)
00142                 {
00143                         if ((fabs(xx-x)<range) && (fabs(yy-y)<range) && (fabs(zz-z)<range)) {
00144                            dd=sqrt(   (xx-x)*(xx-x) + (yy-y)*(yy-y) + (zz-z)*(zz-z) );
00145                            if (dd<ddmin){
00146                                    ddmin=dd;
00147                                    ibak=i;
00148                            }
00149                         }
00150                 }
00151                 if (type==0)
00152                 {
00153                         if ((fabs(yy-y)<range) && (fabs(zz-z)<range)) {
00154                            dd=sqrt(   (yy-y)*(yy-y) + (zz-z)*(zz-z) );
00155                            if (dd<ddmin){
00156                                    ddmin=dd;
00157                                    ibak=i;
00158                            }
00159                         }
00160                 }
00161                 if (type==1)
00162                 {
00163                         if ((fabs(xx-x)<range) && (fabs(zz-z)<range)) {
00164                            dd=sqrt(   (xx-x)*(xx-x)  + (zz-z)*(zz-z) );
00165                            if (dd<ddmin){
00166                                    ddmin=dd;
00167                                    ibak=i;
00168                            }
00169                         }
00170                 }
00171                 if (type==2)
00172                 {
00173                         if ((fabs(xx-x)<range) && (fabs(yy-y)<range) ) {
00174                            dd=sqrt(   (xx-x)*(xx-x) + (yy-y)*(yy-y)  );
00175                            if (dd<ddmin){
00176                                    ddmin=dd;
00177                                    ibak=i;
00178                            }
00179                         }
00180                 }
00181         }
00182         return ibak;
00183 }
00184 // ----------------------------------------------------------------------------
00185 int      manualBaseModel::IsPoint(double x, double y)
00186 {
00187         double xx,yy,zz;
00188         bool exists=false;
00189         int i,size=_lstPoints.size();
00190         for (i=0;i<size;i++){
00191                 manualPoint *mp=_lstPoints[i];
00192                 xx=mp->GetX();
00193                 yy=mp->GetY();
00194 
00195                 //RaC Be Careful!! Cast to have a point like the one in the params 27-09-09
00196                 if(x==(int)xx && y==(int)yy )
00197                 {
00198                         exists=true;
00199                 }
00200         }
00201         return exists;
00202 
00203 }
00204 // ----------------------------------------------------------------------------
00205 manualPoint* manualBaseModel::GetManualPoint(int id)
00206 {
00207         return _lstPoints[id];
00208 }
00209 // ----------------------------------------------------------------------------
00210 int manualBaseModel::GetSizeLstPoints()
00211 {
00212         return _lstPoints.size();
00213 }
00214 
00215 // ----------------------------------------------------------------------------
00216 manualBaseModel * manualBaseModel :: Clone() // virtual
00217 {
00218         manualBaseModel * clone = new manualBaseModel();
00219         CopyAttributesTo(clone);
00220         return clone;
00221 }
00222 
00223 // ----------------------------------------------------------------------------
00224 int manualBaseModel::GetTypeModel() //virtual
00225 {
00226         // 0 spline
00227         // 1 spline
00228         // 2 rectangle
00229         // 3 circle
00230         // 4 BullEye
00231         // 5 BullEyeSector
00232         // 6 Line
00233         // 7 Points
00234         return 7;
00235 }
00236 
00237 // ---------------------------------------------------------------------------
00238 
00239 void manualBaseModel::CopyAttributesTo( manualBaseModel * cloneObject)
00240 {
00241         int i, size = GetSizeLstPoints();
00242         for( i=0; i<size; i++ )
00243         {
00244                 cloneObject->AddManualPoint( GetManualPoint( i )->Clone() );
00245         }
00246 }
00247 
00248 
00249 // ---------------------------------------------------------------------------
00250 void manualBaseModel::AddManualPoint( manualPoint* theManualPoint )
00251 {
00252         _lstPoints.push_back( theManualPoint );
00253 }
00254 
00255 void manualBaseModel::Open(FILE *ff)    // virtual
00256 {
00257 }
00258 void manualBaseModel::Save(FILE *ff)    // virtual
00259 {
00260 }
00261 
00262 void manualBaseModel::SaveData(FILE *ff)// virtual
00263 {
00264 }
00265 
00266 
00267 // ---------------------------------------------------------------------------
00268 void manualBaseModel::SetNumberOfPointsSpline(int size)
00269 {
00270         _sizePointsContour = size;
00271 }
00272 
00273 double manualBaseModel::GetPathSize()
00274 {
00275         return 0.0;
00276 }
00277 
00278 void manualBaseModel::Transform_Ax_Plus_B (double Ax, double Bx, double Ay, double By)
00279 {
00280 }
00281 
00282 void manualBaseModel::GetSpline_i_Point(int i, double *x, double *y, double *z)
00283 {
00284         //RaC 20-09-09 IF it's a points contour
00285         if(GetTypeModel()==7){
00286                 if (_lstPoints.size()==0)
00287                 {
00288                         *x      = 0;
00289                         *y      = 0;
00290                         *z      = 0;
00291                 }
00292                 else
00293                 {
00294                         manualPoint     *mp;
00295                         mp      = _lstPoints[i];
00296                         *x      = mp->GetX();
00297                         *y      = mp->GetY();
00298                         *z      = mp->GetZ();
00299                 }
00300 
00301         }
00302 
00303 }
00304 
00305 void manualBaseModel::GetSpline_t_Point(double t, double *x, double *y, double *z)
00306 {
00307 }
00308 
00309 // ---------------------------------------------------------------------------
00310 int     manualBaseModel::GetNumberOfPointsSpline()
00311 {
00312 
00313         //RaC 20-09-09 IF it's a points contour
00314         if(GetTypeModel()==7){
00315                 return _lstPoints.size();
00316         }
00317         return _sizePointsContour;
00318 }
00319 
00320 // ---------------------------------------------------------------------------
00321 void manualBaseModel::UpdateSpline()
00322 {
00323 }
00324 
00325 // ---------------------------------------------------------------------------
00326 std::vector<manualBaseModel*> manualBaseModel::ExploseModel(  )
00327 {
00328         std::vector<manualBaseModel*> lstTmp;
00329         lstTmp.push_back(this);
00330         return lstTmp;
00331 }
00332 
00333 // ---------------------------------------------------------------------------
00334 double                  manualBaseModel::GetPathArea()
00335 {
00336         return 0.0;
00337 }
00338 void                    manualBaseModel::GetNearestPointAndNormal(double *p, double *rp,  double *rn)
00339 {
00340 }
00341 void                    manualBaseModel::SetCloseContour(bool closeContour)
00342 {
00343 }
00344 bool                    manualBaseModel::IfCloseContour()
00345 {
00346         return false;
00347 }
00348 //CMRU 17-08-09----------------------------------------------------------------------------
00349 void manualBaseModel::SetLabel(std::string newLabel)
00350 {
00351 }
00352 
00353 void manualBaseModel::SetRealSize(double newRealSize) 
00354 {
00355 }
00356 
00357 double manualBaseModel::GetRealSize()
00358 {
00359         return -1;
00360 }
00361 
00362 std::string manualBaseModel::GetLabel()
00363 {
00364         return "";
00365 }
00366 void manualBaseModel::OpenData(FILE *ff)
00367 {
00368 }
00369 //----------------------------------------------------------------------------

Generated on 18 Mar 2010 for creaMaracasVisu_lib by  doxygen 1.6.1