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         InsertPoint_id(ibak,x,y,z);
00071 
00072         return ibak;
00073 }
00074 // ----------------------------------------------------------------------------
00075 void manualBaseModel::InsertPoint_id(int id, double x, double y, double z)
00076 {
00077         manualPoint *mp = new manualPoint();
00078         mp->SetPoint(x,y,z);
00079         std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + id;
00080         _lstPoints.insert(itNum,mp);
00081 }
00082 // ----------------------------------------------------------------------------
00083 
00084 void manualBaseModel::DeletePoint(int i)
00085 {
00086         std::vector<manualPoint*>::iterator itNum = _lstPoints.begin() + i;
00087    _lstPoints.erase(itNum);
00088 }
00089 // ----------------------------------------------------------------------------
00090 void manualBaseModel::DeleteAllPoints()
00091 {
00092         int i,size=_lstPoints.size();
00093         for (i=0;i<size;i++){
00094            _lstPoints.erase( _lstPoints.begin() );
00095         }
00096 }
00097 // ----------------------------------------------------------------------------
00098 
00099 void manualBaseModel::MovePoint(int i,double dx,double dy,double dz)
00100 {
00101         manualPoint *mp=_lstPoints[i];
00102         double x=mp->GetX()+dx;
00103         double y=mp->GetY()+dy;
00104         double z=mp->GetZ()+dz;
00105         mp->SetPoint(x,y,z);
00106 }
00107 // ----------------------------------------------------------------------------
00108 void manualBaseModel::MoveLstPoints(double dx,double dy,double dz)
00109 {
00110         // ToDo
00111 }
00112 // ----------------------------------------------------------------------------
00113 void manualBaseModel::MoveAllPoints(double dx,double dy,double dz)
00114 {
00115         int i,size=_lstPoints.size();
00116         for (i=0;i<size;i++){
00117                 MovePoint(i,dx,dy,dz);
00118         }
00119 }
00120 
00121 // ----------------------------------------------------------------------------
00122 // type=-1  x,y,z
00123 // type=0       y,z
00124 // type=1       x,z
00125 // type=2       x,y
00126 int      manualBaseModel::GetIdPoint(double x, double y, double z, int i_range,int type)
00127 {
00128         double range = i_range+1;
00129 
00130         double xx,yy,zz,dd,ddmin=9999999;
00131         int ibak=-1;
00132         int i,size=_lstPoints.size();
00133         for (i=0;i<size;i++){
00134                 manualPoint *mp=_lstPoints[i];
00135                 xx=mp->GetX();
00136                 yy=mp->GetY();
00137                 zz=mp->GetZ();
00138 
00139                 if (type==-1)
00140                 {
00141                         if ((fabs(xx-x)<range) && (fabs(yy-y)<range) && (fabs(zz-z)<range)) {
00142                            dd=sqrt(   (xx-x)*(xx-x) + (yy-y)*(yy-y) + (zz-z)*(zz-z) );
00143                            if (dd<ddmin){
00144                                    ddmin=dd;
00145                                    ibak=i;
00146                            }
00147                         }
00148                 }
00149                 if (type==0)
00150                 {
00151                         if ((fabs(yy-y)<range) && (fabs(zz-z)<range)) {
00152                            dd=sqrt(   (yy-y)*(yy-y) + (zz-z)*(zz-z) );
00153                            if (dd<ddmin){
00154                                    ddmin=dd;
00155                                    ibak=i;
00156                            }
00157                         }
00158                 }
00159                 if (type==1)
00160                 {
00161                         if ((fabs(xx-x)<range) && (fabs(zz-z)<range)) {
00162                            dd=sqrt(   (xx-x)*(xx-x)  + (zz-z)*(zz-z) );
00163                            if (dd<ddmin){
00164                                    ddmin=dd;
00165                                    ibak=i;
00166                            }
00167                         }
00168                 }
00169                 if (type==2)
00170                 {
00171                         if ((fabs(xx-x)<range) && (fabs(yy-y)<range) ) {
00172                            dd=sqrt(   (xx-x)*(xx-x) + (yy-y)*(yy-y)  );
00173                            if (dd<ddmin){
00174                                    ddmin=dd;
00175                                    ibak=i;
00176                            }
00177                         }
00178                 }
00179         }
00180         return ibak;
00181 }
00182 // ----------------------------------------------------------------------------
00183 int      manualBaseModel::IsPoint(double x, double y)
00184 {
00185         double xx,yy/*,zz*/;
00186         bool exists=false;
00187         int i,size=_lstPoints.size();
00188         for (i=0;i<size;i++){
00189                 manualPoint *mp=_lstPoints[i];
00190                 xx=mp->GetX();
00191                 yy=mp->GetY();
00192 
00193                 //RaC Be Careful!! Cast to have a point like the one in the params 27-09-09
00194                 if(x==(int)xx && y==(int)yy )
00195                 {
00196                         exists=true;
00197                 }
00198         }
00199         return exists;
00200 }
00201 // ----------------------------------------------------------------------------
00202 manualPoint* manualBaseModel::GetManualPoint(int id)
00203 {
00204         return _lstPoints[id];
00205 }
00206 // ----------------------------------------------------------------------------
00207 int manualBaseModel::GetSizeLstPoints()
00208 {
00209         return _lstPoints.size();
00210 }
00211 
00212 // ----------------------------------------------------------------------------
00213 manualBaseModel * manualBaseModel :: Clone() // virtual
00214 {
00215         manualBaseModel * clone = new manualBaseModel();
00216         CopyAttributesTo(clone);
00217         return clone;
00218 }
00219 
00220 // ----------------------------------------------------------------------------
00221 int manualBaseModel::GetTypeModel() //virtual
00222 {
00223         // 0 spline
00224         // 1 spline
00225         // 2 rectangle
00226         // 3 circle
00227         // 4 BullEye
00228         // 5 BullEyeSector
00229         // 6 Line
00230         // 7 Points
00231         return 7;
00232 }
00233 
00234 // ---------------------------------------------------------------------------
00235 
00236 void manualBaseModel::CopyAttributesTo( manualBaseModel * cloneObject)
00237 {
00238         int i, size = GetSizeLstPoints();
00239         for( i=0; i<size; i++ )
00240         {
00241                 cloneObject->AddManualPoint( GetManualPoint( i )->Clone() );
00242         }
00243 }
00244 
00245 // ---------------------------------------------------------------------------
00246 void manualBaseModel::AddManualPoint( manualPoint* theManualPoint )
00247 {
00248         _lstPoints.push_back( theManualPoint );
00249 }
00250 // ---------------------------------------------------------------------------
00251 void manualBaseModel::Open(FILE *ff)    // virtual
00252 {
00253 }
00254 // ---------------------------------------------------------------------------
00255 void manualBaseModel::Save(FILE *ff)    // virtual
00256 {
00257 }
00258 // ---------------------------------------------------------------------------
00259 void manualBaseModel::SaveData(FILE *ff)// virtual
00260 {
00261 }
00262 
00263 
00264 // ---------------------------------------------------------------------------
00265 void manualBaseModel::SetNumberOfPointsSpline(int size)
00266 {
00267         _sizePointsContour = size;
00268 }
00269 // ---------------------------------------------------------------------------
00270 double manualBaseModel::GetPathSize()
00271 {
00272         return 0.0;
00273 }
00274 // ---------------------------------------------------------------------------
00275 void manualBaseModel::Transform_Ax_Plus_B (double Ax, double Bx, double Ay, double By)
00276 {
00277 }
00278 // ---------------------------------------------------------------------------
00279 void manualBaseModel::GetSpline_i_Point(int i, double *x, double *y, double *z)
00280 {
00281         //RaC 20-09-09 IF it's a points contour
00282         if(GetTypeModel()==7){
00283                 if (_lstPoints.size()==0)
00284                 {
00285                         *x      = 0;
00286                         *y      = 0;
00287                         *z      = 0;
00288                 }
00289                 else
00290                 {
00291                         manualPoint     *mp;
00292                         mp      = _lstPoints[i];
00293                         *x      = mp->GetX();
00294                         *y      = mp->GetY();
00295                         *z      = mp->GetZ();
00296                 }
00297         }
00298 }
00299 
00300 void manualBaseModel::GetSpline_t_Point(double t, double *x, double *y, double *z)
00301 {
00302 }
00303 
00304 // ---------------------------------------------------------------------------
00305 int     manualBaseModel::GetNumberOfPointsSpline()
00306 {
00307 
00308         //RaC 20-09-09 IF it's a points contour
00309         if(GetTypeModel()==7){
00310                 return _lstPoints.size();
00311         }
00312         return _sizePointsContour;
00313 }
00314 
00315 // ---------------------------------------------------------------------------
00316 void manualBaseModel::UpdateSpline()
00317 {
00318 }
00319 
00320 // ---------------------------------------------------------------------------
00321 std::vector<manualBaseModel*> manualBaseModel::ExploseModel(  )
00322 {
00323         std::vector<manualBaseModel*> lstTmp;
00324         lstTmp.push_back(this);
00325         return lstTmp;
00326 }
00327 
00328 // ---------------------------------------------------------------------------
00329 double manualBaseModel::GetPathArea()
00330 {
00331         return 0.0;
00332 }
00333 void manualBaseModel::GetNearestPointAndNormal(double *p, double *rp,  double *rn)
00334 {
00335 }
00336 void manualBaseModel::SetCloseContour(bool closeContour)
00337 {
00338 }
00339 bool manualBaseModel::IfCloseContour()
00340 {
00341         return false;
00342 }
00343 //CMRU 17-08-09----------------------------------------------------------------------------
00344 void manualBaseModel::SetLabel(std::string newLabel)
00345 {
00346 }
00347 
00348 void manualBaseModel::SetRealSize(double newRealSize) 
00349 {
00350 }
00351 
00352 double manualBaseModel::GetRealSize()
00353 {
00354         return -1;
00355 }
00356 
00357 std::string manualBaseModel::GetLabel()
00358 {
00359         return "";
00360 }
00361 void manualBaseModel::OpenData(FILE *ff)
00362 {
00363 }
00364 //----------------------------------------------------------------------------

Generated on 20 Oct 2010 for creaMaracasVisu_lib by  doxygen 1.6.1