Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question#include #include <fstream> #include <string> struct Vertex { float x,y,z; }; struct Face { Vertex *vertex; size_t nbVertex; Face() : vertex(0), nbVertex(0) {} Face(int n) : vertex(new Vertex[n]), nbVertex(n) {} ~Face() { delete[] vertex; } Face(const Face &f) : nbVertex(f.nbVertex), vertex(new Vertex[f.nbVertex]) { for(size_t i=0; i<nbVertex; i++) vertex[i]=f.vertex[i]; } Face& operator = (const Face &f) { if( this == &f ) return *this; nbVertex=f.nbVertex; delete[] vertex; vertex=new Vertex[nbVertex]; for(size_t i=0; i<nbVertex; i++) vertex[i]=f.vertex[i]; return *this; } }; class PovModel { Face *faces; size_t nbFaces; public: PovModel() : faces(0), nbFaces(0) {} PovModel(const std::string &filename) : faces(0), nbFaces(0) { load(filename); } PovModel(const PovModel &pm) : nbFaces(pm.nbFaces), faces(new Face[pm.nbFaces]) { for(size_t i=0; i<nbFaces; i++) faces[i]=pm.faces[i]; } PovModel& operator = (const PovModel &pm) { if( this == &pm ) return *this; nbFaces=pm.nbFaces; delete[] faces; faces=new Face[nbFaces]; for(size_t i=0; i<nbFaces; i++) faces[i]=pm.faces[i]; return *this; } ~PovModel() { delete[] faces; } void init(const std::string &filename); void load(const std::string &filename); void displayData() const; }; using namespace std; void PovModel::init(const string &filename) { ifstream file( filename.c_str() ); string line; while( getline(file,line) ) { while( line!="polygon {" && getline(file,line) ); nbFaces++; } faces=new Face[--nbFaces]; } void PovModel::load(const string &filename) { size_t idF=0; string line; init(filename); ifstream file( filename.c_str() ); while( getline(file,line) ) { while( line!="polygon {" && getline(file,line) ); size_t n; file >> n; faces[idF]=Face(n); for(size_t v=0; v<faces[idF].nbVertex; v++) { file.ignore(100,'<'); file >> faces[idF].vertex :dissapprove) .x; file.ignore(100,','); file >> faces[idF].vertex :dissapprove) .y; file.ignore(100,','); file >> faces[idF].vertex :dissapprove) .z; } if(++idF==nbFaces) break; } } void PovModel::displayData() const { for(size_t f=0; f<nbFaces; f++) { cout<< "polygone " << f+1 << " :\n"; for(size_t v=0; v<faces[f].nbVertex; v++) { cout<< faces[f].vertex :dissapprove) .x << " "; cout<< faces[f].vertex :dissapprove) .y << " "; cout<< faces[f].vertex :dissapprove) .z << '\n'; } cout<<'\n'; } } int main() { PovModel model("toto.pov"); model.displayData(); cout.flush(); cin.get(); }