S32 check_soustraction(const IOperand &first, const IOperand &second) { S32 value1 = getValueI(first.toString()); S32 value2 = getValueI(second.toString()); long long result = (long long)value1 - (long long)value2; if (first.getType() == Int16 || second.getType() == Int16) { if ((S16)result != result) throw Erreur(Overflow); return ((S16)result); } else if (first.getType() == Int8 || second.getType() == Int8) { if ((S8)result != result) throw Erreur(Overflow); return ((S8)result); } else { if ((S32)result != result) throw Erreur(Overflow); return ((S32)result); } }
IOperand *Operand<T>::operator%(const IOperand &rhs) const { IOperand *ptr; if (rhs.getPrecision() >= Float || this->getPrecision() >= Float) { double value; if (getValueD(rhs.toString()) == 0) throw Erreur(DivByZero); value = fmod(getValueD(this->toString()), getValueD(rhs.toString())); if (this->getPrecision() >= rhs.getPrecision()) ptr = factory::new_operand(value, this->getType()); else ptr = factory::new_operand(value, rhs.getType()); } else { S32 value; if (getValueI(rhs.toString()) == 0) throw Erreur(DivByZero); value = check_modulo(*this, rhs); if (this->getPrecision() >= rhs.getPrecision()) ptr = factory::new_operand(value, this->getType()); else ptr = factory::new_operand(value, rhs.getType()); } return ptr; }
// Ajouter un objet au tableau des objets void Env_objets::addObjet(char nom1[30], Creation * new1) { int i; // test si le nom de l'objet n'est pas déjà utilisé for (i=0; i<nb_objets; i++) if (strcmp(nom1, nom[i]) == 0) Erreur("Object already declared"); strcpy(nom[nb_objets],nom1); objet[nb_objets]=new1; nb_objets++; if (nb_objets > 255) Erreur("Number of objects limited to 256"); }
// ***************************************************************************** // Renvoie des parties de l'heure système. // "1" = Heures de l'heure // "2" = minutes de l'heure // "3" = secondes de l'heure // "4" = Format long sous la forme : 14:37:40 // ***************************************************************************** char *Heure(char *fonc,char *nop) { char *retour; time_t ltime; int fonction; struct tm *gmt; time(<ime); gmt=localtime(<ime); fonction=atoi(fonc); retour=(char *)malloc(20*sizeof(char)+1); if(retour==NULL) Erreur("Heure"); switch(fonction) { case 1: sprintf(retour,"%02d",gmt->tm_hour); break; case 2: sprintf(retour,"%02d",gmt->tm_min); break; case 3: sprintf(retour,"%02d",gmt->tm_sec); break; case 4: sprintf(retour,"%02d:%02d:%02d",gmt->tm_hour,gmt->tm_min,gmt->tm_sec); break; default: sprintf(retour,"Undefined"); break; } return(retour); }
pcl::PointCloud<pcl::PointXYZ>::Ptr scnreader_model::getPartInCloud(int d, int f, QVector<int>* tailles) { pcl::PointCloud<pcl::PointXYZ>::Ptr CloudTemp(new pcl::PointCloud<pcl::PointXYZ>); //Fill the cloud and the vector tailles int i=d; while(i<=f) { if(nuage.contains(i)) { QVector <PointGL*> * v=nuage.value(i); tailles->push_back(v->size()); for(int j=0; j<v->size(); j++) { pcl::PointXYZ p(v->at(j)->getX(),v->at(j)->getY(),v->at(j)->getZ()); CloudTemp->points.push_back(p); } i++; } else throw Erreur("Interval de footpulses discontinu dans la segmentation"); } CloudTemp->width = CloudTemp->points.size(); CloudTemp->height = 1; CloudTemp->is_dense = false; CloudTemp->points.resize (CloudTemp->width * CloudTemp->height); return CloudTemp; }
int * scnreader_model::ftpMinMax() { if(!nuage.isEmpty()) { //keep values of key in nuage QList<int> cle=nuage.keys(); //initialization of min and max double min=cle.at(0); double max=cle.at(0); //we cover the vector to search xmin and max for(int i=1; i<cle.size(); i++) { if(min>cle.at(i)) min=cle.at(i); if(max<cle.at(i)) max=cle.at(i); } //we calculate the distance between them int * t; t= new int[2]; t[0]=min; t[1]=max; return t; } else Erreur("Le nuage de point est vide, nous ne pouvons determiner les footpulses de debut et de fin!"); }
void scnreader_model::SavePartInTxt(int d, int f, QString pathname) { //open the file QFile file(pathname); //If there is an error QString MesErreur=" The file"; MesErreur.push_back(pathname); MesErreur.push_back("have not been saved, check the write permission!"); //Test if you can write into the file if(file.open(QIODevice::WriteOnly )){ //if you can, initialize flu and line QTextStream flux(&file); //defines the codec of file flux.setCodec("UTF-8"); //get coordinates points of cloud and write it for(int i=d;i<=f; i++){ if(this->nuage.contains(i)) { QVector<PointGL *> * vec=this->nuage.value(i); for(int j=0;j<vec->size(); j++){ flux << QString::number(vec->at(j)->getX()) << "\t" << QString::number(vec->at(j)->getY()) << "\t" << QString::number(vec->at(j)->getZ()) << "\t" << endl; } } } file.close(); }else throw Erreur(MesErreur.toStdString()); }
QVector<PointGL *> *scnreader_model::getCloudInVect2(pcl::PointCloud<pcl::PointXYZ>::Ptr cloudTemp) { /*QVector<pcl::PointXYZ *> * v; //TODO return v;*/ throw Erreur("NOT YET IMPLEMENT, SORRY!"); }
SceneSDL::SceneSDL(int config) : m_clavier(def::NB_TOUCHES, false) { // Chargement de la SDL if (SDL_Init(SDL_INIT_VIDEO) < 0) throw Erreur(4, "Echec du chargement de la SDL"); init(config); // Chargement de la configuration par defaut }
// Méthode qui affecte une valeur à une variable x de l'objet y void Env_objets::affectation (char nom1[50], char nom2[50], Data * flo1) { int i=0; while (strcmp (nom[i], nom1) != 0) { if (i+1 >= nb_objets) Erreur("Object not declared"); i++; } objet[i]->affectation (nom2, flo1); }
void scnreader_model::planar_segmentation( int d, int f){ if(nuage.contains(d) && nuage.contains(f)) { //initialization pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients); pcl::PointIndices::Ptr inliers (new pcl::PointIndices); //vector wich contains the count of point by footpulse QVector<int>* tailles= new QVector<int>(); //temporarly cloud to do the segmentation pcl::PointCloud<pcl::PointXYZ>::Ptr CloudTemp=getPartInCloud(d,f, tailles); // Create the segmentation object pcl::SACSegmentation<pcl::PointXYZ> seg; // Optional seg.setOptimizeCoefficients (true); // Mandatory seg.setModelType (pcl::SACMODEL_PLANE); seg.setMethodType (pcl::SAC_RANSAC); seg.setDistanceThreshold (0.01); seg.setInputCloud (CloudTemp); //definded coefficients of segmentation seg.segment (*inliers, *coefficients); //if we ave no indices, throw a error if (inliers->indices.size () == 0) { throw Erreur("Could not estimate a planar model for the given dataset."); }else{ //create new cloud QVector<PointGL*>* v= getPtWithInd(d, f,inliers->indices, tailles); //add the segmentation to the hashtable std::stringstream ss; ss << "S_" << d <<"_" << f; segmentation.insert(QString::fromStdString (ss.str()), v); } } else throw Erreur("Interval de footpulses incorrect pour effectuer la segmentation"); }
S32 check_multiplication(const IOperand &first, const IOperand &second) { S32 value1 = getValueI(first.toString()); S32 value2 = getValueI(second.toString()); long long result = (long long)value1 * (long long) value2; if (first.getType() == Int32 || second.getType() == Int32) { if ((S32)result != result) throw Erreur(Overflow); else if (result / (long long)value2 != (long long)value1) throw Erreur(Overflow); return (S32)result; } else if (first.getType() == Int16 || second.getType() == Int16) { if ((S16)result != result) throw Erreur(Overflow); else if (result /(long long)value2 != (long long)value1) throw Erreur(Overflow); return (S16)result; } else { if ((S8)result != result) throw Erreur(Overflow); else if (result /(long long)value2 != (long long)value1) throw Erreur(Overflow); return (S8)result; } }
void RegionGrowing::add(PointGL point) { if(this->isdead)throw Erreur("adding in a dead region"); // if the last point have a footpulse bigger than the point if(this->points.last().getZ()>point.getZ()){ // add the rail this->points.push_back(point); // and sort by z then by x then by y std::sort(this->points.begin(),this->points.end()); }else{ // juste add it this->points.push_back(point); } }
// *************************************************************************** // Renvoie des parties de la date système. // "1" = Jour de la date (format 99) // "2" = Mois de la date (format 99) // "3" = Année de la date (au format 1995) // "4" = Format complet numéro 1. Exemple : 15/03/1995 // "5" = Libellé du mois. Exemple : Mars // "6" = Libellé du jour. Exemple : Mercredi // "7" = Numéro du jour dans la semaine. 1=Lundi 7=Dimanche // "8" = Numéro du jour (unique) dans l'année. // "9" = Format long de la date. Exemple Mercredi 15 Mars 1995 // ***************************************************************************** char *Date(char *fonc,char *nop) { char *retour; time_t ltime; int fonction; struct tm *gmt; char *tjours[]={"Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche"}; char *tmois[]={"Janvier","Fevrier","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Decembre"}; time(<ime); gmt=localtime(<ime); fonction=atoi(fonc); retour=(char *)malloc(40*sizeof(char)+1); if(retour==NULL) Erreur("Date"); switch(fonction) { case 1: sprintf(retour,"%02d",gmt->tm_mday); break; case 2: sprintf(retour,"%02d",gmt->tm_mon+1); break; case 3: sprintf(retour,"%d",gmt->tm_year+1900); break; case 4: sprintf(retour,"%02d/%02d/%d",gmt->tm_mday,gmt->tm_mon+1,gmt->tm_year+1900); break; case 5: sprintf(retour,"%s",tmois[gmt->tm_mon]); break; case 6: sprintf(retour,"%s",tjours[gmt->tm_wday-1]); break; case 7: sprintf(retour,"%d",gmt->tm_wday); break; case 8: sprintf(retour,"%d",gmt->tm_yday+1); break; case 9: sprintf(retour,"%s %d %s %d",tjours[gmt->tm_wday-1],gmt->tm_mday,tmois[gmt->tm_mon],gmt->tm_year+1900); break; default: sprintf(retour,"Undefined"); break; } return(retour); }
S32 check_addition(const IOperand &first, const IOperand &second) { S32 value1 = getValueI(first.toString()); S32 value2 = getValueI(second.toString()); S32 result = value1 + value2; if (first.getType() == Int16 || second.getType() == Int16) result = (S16)result; else if (first.getType() == Int8 || second.getType() == Int8) result = (S8)result; if (value1 == 0 || value2 == 0); else if (value1 > 0 && value2 > 0) { if (result < value1 || result < value2) throw Erreur(Overflow); } else if (getValueI(first.toString()) < 0 && getValueI(second.toString()) < 0) { if (result > value1 || result > value2) throw Erreur(Underflow); } return result; }
void SceneSDL::init(int config) { m_config = config; switch(m_config) { default: m_titre = "Test 1"; def::redefinir(200, 125, 5, true, 5); break; } // Chargement de la fenetre m_fenetre = SDL_CreateWindow(m_titre.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, def::taillePixel*def::width, def::taillePixel*def::height, 0); if (m_fenetre == NULL) throw Erreur(3, "Echec du chargement de la fenetre"); // Chargement du rendu m_rendu = SDL_CreateRenderer(m_fenetre, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (m_rendu == NULL) throw Erreur(3, "Echec du chargement du rendu"); }
// Méthode exec de la classe Web // env1 = liste des arguments passés lors de l'appel de classe void Web::exec(Data_liste *env1) { if (env1->nb_data != 8) Erreur("Web needs 8 arguments"); fprintf(yyout, "<web pos=\"%.2f %.2f %.2f %.2f\" url=\"%s\"> <solid shape=\"box\" dim=\"%.2f %.2f %.2f\"", env1->donnee[0]->get_float(), env1->donnee[1]->get_float(), env1->donnee[2]->get_float(), env1->donnee[3]->get_float(), env1->donnee[7]->nom, env1->donnee[4]->get_float(), env1->donnee[5]->get_float(), env1->donnee[6]->get_float()); ecrire_box(); fprintf(yyout, " />"); fprintf(yyout, "</web>\n"); }
/** * Transforme texte en un objet Forme * En cas d'échec retourne NULL * @param texte: le texte a transformé * @return La forme chargé ou NULL si le format n'est pas reconnu */ Forme * ChargementFormeCOR::charge(const string texte) const{ Forme * resultat; resultat = this->chargeExpertise(texte); if (resultat!=NULL) { return resultat;} else { if (this->suivant!=NULL) { return (this->suivant->charge(texte));} else { throw Erreur("Le fichier recherche n existe pas"); return NULL;} } }
void scnreader_model::enregistre(QString noms) { QFile fichier(noms); if(fichier.open(QIODevice::Append | QIODevice::Text)){ //if you can, initialize flu and line QTextStream flux(&fichier); //defines the codec of file flux.setCodec("UTF-8"); //get footpulse of switch for(int i=0;i<this->LesSwitchs.size(); i++){ int sw=this->LesSwitchs.at(i); flux << QString::number(sw) << " " << endl; } fichier.close(); } else throw Erreur(" The file finale switch.txt have not been saved, check the write permission!"); }
void scnreader_model::VideEtEnregistre(QString noms) { QFile fichier(noms); //Test if you can write into the file if(fichier.open(QIODevice::Append | QIODevice::Text )){ //if you can, initialize flu and line QTextStream flux(&fichier); //defines the codec of file flux.setCodec("UTF-8"); //get footpulse of switch int nbToWrite=this->LesSwitchs.size()-this->workWindows; for(int i=0;i<nbToWrite; i++){ int sw=this->LesSwitchs.takeFirst(); flux << QString::number(sw)<< endl; } fichier.close(); }else throw Erreur(" The file switch.txt have not been saved, check the write permission!"); }
int scnreader_model::IsFootpulse(std::string pathname){ //__________declare variables_________________ //count int cx=0; int cy=0; int cz=0; //boolean of end bool find=false; //boolean corresponding of each axe bool fx=(cy>=2 && cz>=2); bool fy=(cx>=2 && cz>=2); bool fz=(cy>=2 && cx>=2); //previous value double tx,ty,tz; //current value double vx,vy,vz; //file QFile fichier( QString(pathname.c_str()) ); // si le fichier est bien ouvert if(fichier.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream flux(&fichier); //variable contenant chaque ligne lue QString ligne; //read the first line ligne= flux.readLine(); // split the line with space as a separator character QStringList result1 =ligne.split("\t"); //test if the first line define the number of lines into the file if( result1.size()==1){ //read the second line ligne= flux.readLine(); // split the line with space as a separator character result1 =ligne.split("\t"); QString x=result1.at(0); QString y=result1.at(1); QString z=result1.at(2); //initialize value tx=x.toDouble(); ty=y.toDouble(); tz=z.toDouble(); }else if(result1.size()<3)throw Erreur(" Error reading file!"); else{ QString x=result1.at(0); QString y=result1.at(1); QString z=result1.at(2); //previous value tx=x.toDouble(); ty=y.toDouble(); tz=z.toDouble(); } //__________Cover of file's part_______________ while(!flux.atEnd() && !find) { //__________read the x, y, z //read line by line ligne= flux.readLine(); // split the line with space as a separator character QStringList result =ligne.split("\t"); //convert coordonated Qstring to double coordinates to compare //test if the first line define the number of lines into the file if(result.size()<3)throw Erreur(" Error reading file!"); else{ QString x=result.at(0); QString y=result.at(1); QString z=result.at(2); //convert coordonated Qstring to double coordinates to compare vx=x.toDouble(); vy=y.toDouble(); vz=z.toDouble(); //compare the current and the previous value if(cx<2) if(tx!=vx) { cx++; } if(cy<2) if(ty!=vy) { cy++; } if(cz<2) if(tz!=vz) { cz++; } //update the future previous value tx=vx; ty=vy; tz=vz; } //update of booleans fx=(cy>=2 && cz>=2); fy=(cx>=2 && cz>=2); fz=(cy>=2 && cx>=2); find= fx || fy || fz; } //close file fichier.close(); // create cloud point and cloud file pcl }else throw Erreur("the file "+pathname +"have not been opened!"); //return the number corresponding of the good axe return (0*fx+1*fy+2*fz); }
void scnreader_model::loadCloudFromTXT2(std::string pathname){ int footpulse=IsFootpulse(pathname); QFile fichier( QString(pathname.c_str()) ); if(fichier.open(QIODevice::ReadOnly | QIODevice::Text)) // ce si le fichier n'est pas ouvert { QTextStream flux(&fichier); QString ligne; // variable contenant chaque ligne lue // number of line in the file int nline=10000000; int counter=0; // create progress dialog to inform the user of progress if the task has done is too long QProgressDialog progress("Loading cloud...", "Stop loading", 0, nline, 0); //said that the window is modal progress.setWindowModality(Qt::WindowModal); PointGL * p; int ftpcourant=-1; QVector<PointGL *>* v; while(!flux.atEnd()) { //Increment the counter counter++; //update progress Dialog if(counter%(nline/100)==0) progress.setValue(counter); ligne= flux.readLine(); // split the line with space as a separator character QStringList result =ligne.split("\t"); //convert coordonated Qstring to double coordinates to add in vector //test if the first line define the number of lines into the file if( result.size()==1){ nline=result.at(0).toInt(); //update maximum of progress dialog progress.setMaximum(nline); }else if(result.size()<3)throw Erreur(" Error reading file!"); else{ QString x=result.at(0); QString y=result.at(1); QString z=result.at(2); if(footpulse==0) { p=new PointGL(z.toDouble(),y.toDouble(),x.toDouble()); } else if(footpulse==1) { p=new PointGL(x.toDouble(),z.toDouble(),y.toDouble()); } else { p=new PointGL(x.toDouble(),y.toDouble(),z.toDouble()); } if(ftpcourant==-1) { //we update footpulse ftpcourant=(int) p->getZ(); //we create a new vector v= new QVector<PointGL *>(); //which we add to the hashtable nuage.insert(ftpcourant, v); //then we add the new point v->push_back(p); } else { //we update footpulse ftpcourant=(int) p->getZ(); //if a vector with this footpulse exists if(nuage.contains(ftpcourant)) { //we the vector which corresponding to point's footpulse v= nuage.value(ftpcourant); //then we add the new point v->push_back(p); } else { //we create a new vector v= new QVector<PointGL *>(); //which we add to the hashtable nuage.insert(ftpcourant, v); //then we add the new point v->push_back(p); } } } //if user want to stop loading, the reading is finished if (progress.wasCanceled()) break; } int * t=ftpMinMax(); this->ftpd=t[0]; this->ftpf=t[1]; //close automatically the progress dialog progress.setValue(nline); //close file fichier.close(); //create tracks createRail(); // return cloud; }else throw Erreur("the file "+pathname +"have not been opened!"); }
Operand<T>::Operand() : _type(Int8) { throw Erreur(NoEnoughOperand); }
QVector<PointGL *>* scnreader_model::getPtWithInd(int d, int f, std::vector<int> indices, QVector<int>* tailles) { //create new cloud QVector<PointGL*>* v= new QVector<PointGL*>(); // Fill in the cloud data // Generate the data for (size_t i = 0; i < indices.size (); ++i) { //vector which contains points corresponding to a footpulse QVector<PointGL*>* vec; //indice of point which is contained in segmentation int indiceC=indices[i]; //indice to know what vector to use int ind=0; int nb; //sum of size of previous vectors if(ind<tailles->size()) { nb=tailles->at(ind); } else { std::stringstream ss; ss << "Erreur dans TAILLE pas initialise, pour l'emplacement "<<ind<< " car vecteur de taille: "<<tailles->size(); std::string message=ss.str(); throw Erreur(message); } //int nb=tailles->at(ind); //we grow up the ind to find the good vector where the point find while(ind<(f-d) && indiceC>=nb) { ind++; if(ind<tailles->size()) { nb+=tailles->at(ind); } else { std::stringstream ss; ss << "Erreur dans TAILLE pour l'emplacement "<<ind<< " car vecteur de taille: "<<tailles->size(); std::string message=ss.str(); throw Erreur(message); } // nb+=tailles->at(ind); } //we keep the vector corresponding vec=nuage.value(d+ind); //we add the pointer of the corresponding point if(ind>0) { int num=indiceC-nb+tailles->at(ind); if(num<vec->size()) { v->push_back(vec->at(num)); } else { std::stringstream ss; ss << "Erreur dans VEC pour l'emplacement "<<num<< " car vecteur de taille: "<<vec->size(); std::string message=ss.str(); throw Erreur(message); } } else v->push_back(vec->at(indiceC)); } return v; }
void scnreader_model::createRail() { QString noms=this->nomFile; noms.push_back("_switch.txt"); //open the file QFile file(noms); if(!this->nuage.isEmpty()) { if(this->cfs || !file.exists()) { // //---------------JJ // if(ftpf>this->ftpd+500) // ftpf=this->ftpd+500; // //----------------- //---------------initialize footpulses which determine the beginning and the end of window----------- int dw=this->ftpd+1; int fw; if(this->ftpf-this->ftpd<workWindows) fw=this->ftpf; else fw=this->ftpd+workWindows; std::cout << dw << " - " << fw<<std::endl; //-------------------------------we initialize Listerail---------------------------------------------- //create rails with the first footpulse RailCluster r (0.18,0.08,1.5,*this->nuage.value(this->ftpd)); RailCluster rc=r; this->lesRails.addRail(r); //and we add the others until the footpulse fw, so window is ftpd - (fw-1) for(int i=dw; i<fw;i++) { RailCluster r2(0.18,0.08,1.5,* (this->nuage.value(i)), rc); rc=r2; this->lesRails.addRail(r2); } //cleanNoise(fw); this->optimization(); //we keep detected switch in this window int nbswitch=this->lesRailsOptimize.getSwitchDetected().size(); for(int i=0; i<nbswitch;i++) { int ftp=this->lesRailsOptimize.getSwitchDetected().at(i); if(!this->LesSwitchs.contains(ftp)) { this->LesSwitchs.push_back(ftp); } } //we reinit lesRailsOptimize et resultRansac this->lesRailsOptimize.clear(); this->resultRANSAC->clear(); //we continue to cover all the cloud with a window which we move footpulse by footpulse while(fw<=this->ftpd+3)//this->ftpf { //we add a new track and remove the first in track in window RailCluster r2(0.18,0.08,1.5,* (this->nuage.value(fw)), rc); rc=r2; this->lesRails.addRail(r2); //we do the treatment to detect switchs in this window this->optimization(); //we keep detected switch in this window nbswitch=this->lesRailsOptimize.getSwitchDetected().size(); for(int i=0; i<nbswitch;i++) { int ftp=this->lesRailsOptimize.getSwitchDetected().at(i); //we verify that the size of vector doesn't exceed the cvector's capacity if(this->LesSwitchs.size()<this->capacity) { if(!this->LesSwitchs.contains(ftp)) this->LesSwitchs.push_back(ftp); } //if it exceeds else { //----------------we write footpulses in a text file VideEtEnregistre(noms); } } //we reinit lesRailsOptimize et resultRansac //this->lesRailsOptimize.clear(); //this->resultRANSAC->clear(); //we move the window dw++; fw++; } //----------------we write footpulses of switch in a text file this->enregistre(noms); } } else throw Erreur("Les rails n'ont pas pu etre crees car le nuage de points est vide."); }