From d5f559170c6674cf5534a9818d4a3a8a1e598165 Mon Sep 17 00:00:00 2001 From: salinasd Date: Fri, 12 Dec 2014 09:14:20 +0000 Subject: modif off reader +skbl geometry git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@349 636b058d-ea47-450e-bf9e-a15bfbe3eedb --- src/Contraction/example/Rips_contraction.cpp | 37 +-- .../gudhi/Skeleton_blocker_geometric_complex.h | 3 +- src/common/include/gudhi/Off_reader.h | 22 +- src/common/include/gudhi/iofile.h | 340 ++++++++++----------- 4 files changed, 201 insertions(+), 201 deletions(-) diff --git a/src/Contraction/example/Rips_contraction.cpp b/src/Contraction/example/Rips_contraction.cpp index acfb516d..59cdec97 100644 --- a/src/Contraction/example/Rips_contraction.cpp +++ b/src/Contraction/example/Rips_contraction.cpp @@ -48,25 +48,28 @@ void build_rips(ComplexType& complex, double offset){ complex.add_edge(*p,*q); } +int main (int argc, char *argv[]) +{ + if (argc!=3){ + std::cerr << "Usage "< off_reader(name_file,complex,true); + Skeleton_blocker_off_reader off_reader(argv[1],complex,true); if(!off_reader.is_valid()){ - std::cerr << "Unable to read file:"<()); contractor.contract_edges(); - std::cerr << "Resulting complex has "<< + std::cout << "Resulting complex has "<< complex.num_vertices()<<" vertices, "<< complex.num_edges()<<"edges and "<< complex.num_blockers()<<" blockers"<. - * + * */ @@ -113,18 +113,26 @@ private: bool is_off_file = (line.find("OFF") != std::string::npos); bool is_noff_file = (line.find("nOFF") != std::string::npos); - if(!is_off_file && !is_noff_file) return false; + if(!is_off_file && !is_noff_file) { + std::cerr << line<> off_info_.num_vertices >> off_info_.num_faces >> off_info_.num_edges)) + if(!(iss >> off_info_.num_vertices >> off_info_.num_faces >> off_info_.num_edges)){ + std::cerr << "incorrect number of vertices/faces/edges\n"; return false; + } } else - if(!(iss >> off_info_.dim >> off_info_.num_vertices >> off_info_.num_faces >> off_info_.num_edges)) + if(!(iss >> off_info_.dim >> off_info_.num_vertices >> off_info_.num_faces >> off_info_.num_edges)){ + std::cerr << "incorrect number of vertices/faces/edges\n"; return false; + } off_visitor.init(off_info_.dim,off_info_.num_vertices,off_info_.num_faces,off_info_.num_edges); return true; @@ -134,7 +142,7 @@ private: uncomment_line.clear(); do std::getline(stream_, uncomment_line); - while(uncomment_line[0] == '%'); + while(uncomment_line[0] == '%');// || uncomment_line.empty()); return (uncomment_line.size()>0 && uncomment_line[0] != '%'); } diff --git a/src/common/include/gudhi/iofile.h b/src/common/include/gudhi/iofile.h index b939d45b..9139a3cd 100644 --- a/src/common/include/gudhi/iofile.h +++ b/src/common/include/gudhi/iofile.h @@ -14,176 +14,176 @@ -//todo use my new visitor based off instead -/** - * @brief OFF reader, save the content of the file (vertices and maximal faces) in 'complex'. - * The class Complex has to handle the following operations: - * - void add_vertex(double[dim],int dim) - * - void add_face(int dimension ,int[dimension] vertices) - * Source from : http://www.holmes3d.net/graphics/offfiles/OFFLoading.txt - * - * @todo todo ignore comments in the file -> # comment - */ -template inline -bool general_read_off_file(const std::string & file_name, Complex& complex){ - // Declare temporary variables to read data into. - // If the read goes well, we'll copy these into - // our class variables, overwriting what used to - // be there. If it doesn't, we won't have messed up - // our previous data structures. - int tempNumPoints = 0; // Number of x,y,z coordinate triples - int tempNumFaces = 0; // Number of polygon sets - int tempNumEdges = 0; // Unused, except for reading. - int tempDimPoints = 0; - double** tempPoints = NULL; // An array of x,y,z coordinates. - int** tempFaces = NULL; // An array of arrays of point - // pointers. Each entry in this - // is an array of integers. Each - // integer in that array is the - // index of the x, y, and z - // coordinates in the corresponding - // arrays. - int* tempFaceSizes = NULL; // An array of polygon point counts. - // Each of the arrays in the tempFaces - // array may be of different lengths. - // This array corresponds to that - // array, and gives their lengths. - int i; // Generic loop variable. - bool goodLoad = true; // Set to false if the file appears - // not to be a valid OFF file. - char tempBuf[128]; // A buffer for reading strings - // from the file. - - // Create an input file stream for the file the CArchive - // is connected to. This allows use of the overloaded - // extraction operator for conversion from string - // data to doubles and ints. - std::ifstream ifs (file_name.c_str(), std::ios::in); - if(!ifs.is_open()) { - std::cerr << "Unable to open file " << file_name << std::endl; - return false; - } - - // Grab the first string. If it's "OFF", we think this - // is an OFF file and continue. Otherwise we give up. - ifs >> tempBuf; - if (strcmp(tempBuf, "OFF") != 0) { - goodLoad = false; - std::cerr << "No OFF preambule\n"; - } - - // Read the sizes for our two arrays, and the third - // int on the line. If the important two are zero - // sized, this is a messed up OFF file. Otherwise, - // we setup our temporary arrays. - if (goodLoad) { - ifs >> tempNumPoints >> tempNumFaces >> tempNumEdges; - if (tempNumPoints < 1 || tempNumFaces < 0) { - // If either of these were negative, we make - // sure that both are set to zero. This is - // important for later deleting our temporary - // storage. - goodLoad = false; - std::cerr << "tempNumPoints < 1 || tempNumFaces < 0\n"; - tempNumPoints = 0; - tempNumFaces = 0; - } else { - tempPoints = new double*[tempNumPoints]; - tempFaces = new int*[tempNumFaces]; - tempFaceSizes = new int[tempNumFaces]; - } - } - - if (goodLoad) { - // Load all of the points. - - // we start by loading the first one - // the case is difference because then we dont know the dimension by advance - // we discover the point dimension by reading the first line - std::string lineFirstPoint; - std::getline(ifs, lineFirstPoint); - while(lineFirstPoint.size()<3){ - std::getline(ifs, lineFirstPoint); - } - - // we store the first point in a temporary list - std::istringstream lineFirstPointStream(lineFirstPoint); - std::list firstTempPoint; - double coord; - while(lineFirstPointStream>>coord){ - firstTempPoint.push_back(coord); - ++tempDimPoints; - } - // we store the point in our points array - tempPoints[0]=new double[tempDimPoints]; - for( int j = 0 ; j>tempPoints[i][j]; - } - } - - // Load all of the faces. - for (i = 0; i < tempNumFaces; i++) { - // This tells us how many points make up - // this face. - ifs >> tempFaceSizes[i]; - // So we declare a new array of that size - tempFaces[i] = new int[tempFaceSizes[i]]; - // And load its elements with the vertex indices. - for (int j = 0; j < tempFaceSizes[i]; j++) { - ifs >> tempFaces[i][j]; - } - // Clear out any face color data by reading up to - // the newline. 128 is probably considerably more - // space than necessary, but better safe than - // sorry. - ifs.getline(tempBuf, 128); - } - } - - // Here is where we copy the data from the temp - // structures into our permanent structures. We - // probably will do some more processing on the - // data at the same time. This code you must fill - // in on your own. - if (goodLoad) { - // we save vertices first in the complex - for (i = 0; i < tempNumPoints; i++) - complex.add_vertex(tempPoints[i],tempDimPoints); - - // we save faces - for (i = 0; i < tempNumFaces; i++) { - for (int j = 0; j < tempFaceSizes[i]; j++) - complex.add_face(tempFaceSizes[i],tempFaces[i]); - } - } - - // Now that we're done, we have to make sure we - // free our dynamic memory. - for (i = 0; i < tempNumPoints; i++) { - delete []tempPoints[i]; - } - delete []tempPoints; - - for (i = 0; i < tempNumFaces; i++) { - delete tempFaces[i]; - } - delete []tempFaces; - delete []tempFaceSizes; - - // Clean up our ifstream. The MFC framework will - // take care of the CArchive. - ifs.close(); - - return goodLoad; -} +////todo use my new visitor based off instead +///** +// * @brief OFF reader, save the content of the file (vertices and maximal faces) in 'complex'. +// * The class Complex has to handle the following operations: +// * - void add_vertex(double[dim],int dim) +// * - void add_face(int dimension ,int[dimension] vertices) +// * Source from : http://www.holmes3d.net/graphics/offfiles/OFFLoading.txt +// * +// * @todo todo ignore comments in the file -> # comment +// */ +//template inline +//bool general_read_off_file(const std::string & file_name, Complex& complex){ +// // Declare temporary variables to read data into. +// // If the read goes well, we'll copy these into +// // our class variables, overwriting what used to +// // be there. If it doesn't, we won't have messed up +// // our previous data structures. +// int tempNumPoints = 0; // Number of x,y,z coordinate triples +// int tempNumFaces = 0; // Number of polygon sets +// int tempNumEdges = 0; // Unused, except for reading. +// int tempDimPoints = 0; +// double** tempPoints = NULL; // An array of x,y,z coordinates. +// int** tempFaces = NULL; // An array of arrays of point +// // pointers. Each entry in this +// // is an array of integers. Each +// // integer in that array is the +// // index of the x, y, and z +// // coordinates in the corresponding +// // arrays. +// int* tempFaceSizes = NULL; // An array of polygon point counts. +// // Each of the arrays in the tempFaces +// // array may be of different lengths. +// // This array corresponds to that +// // array, and gives their lengths. +// int i; // Generic loop variable. +// bool goodLoad = true; // Set to false if the file appears +// // not to be a valid OFF file. +// char tempBuf[128]; // A buffer for reading strings +// // from the file. +// +// // Create an input file stream for the file the CArchive +// // is connected to. This allows use of the overloaded +// // extraction operator for conversion from string +// // data to doubles and ints. +// std::ifstream ifs (file_name.c_str(), std::ios::in); +// if(!ifs.is_open()) { +// std::cerr << "Unable to open file " << file_name << std::endl; +// return false; +// } +// +// // Grab the first string. If it's "OFF", we think this +// // is an OFF file and continue. Otherwise we give up. +// ifs >> tempBuf; +// if (strcmp(tempBuf, "OFF") != 0) { +// goodLoad = false; +// std::cerr << "No OFF preambule\n"; +// } +// +// // Read the sizes for our two arrays, and the third +// // int on the line. If the important two are zero +// // sized, this is a messed up OFF file. Otherwise, +// // we setup our temporary arrays. +// if (goodLoad) { +// ifs >> tempNumPoints >> tempNumFaces >> tempNumEdges; +// if (tempNumPoints < 1 || tempNumFaces < 0) { +// // If either of these were negative, we make +// // sure that both are set to zero. This is +// // important for later deleting our temporary +// // storage. +// goodLoad = false; +// std::cerr << "tempNumPoints < 1 || tempNumFaces < 0\n"; +// tempNumPoints = 0; +// tempNumFaces = 0; +// } else { +// tempPoints = new double*[tempNumPoints]; +// tempFaces = new int*[tempNumFaces]; +// tempFaceSizes = new int[tempNumFaces]; +// } +// } +// +// if (goodLoad) { +// // Load all of the points. +// +// // we start by loading the first one +// // the case is difference because then we dont know the dimension by advance +// // we discover the point dimension by reading the first line +// std::string lineFirstPoint; +// std::getline(ifs, lineFirstPoint); +// while(lineFirstPoint.size()<3){ +// std::getline(ifs, lineFirstPoint); +// } +// +// // we store the first point in a temporary list +// std::istringstream lineFirstPointStream(lineFirstPoint); +// std::list firstTempPoint; +// double coord; +// while(lineFirstPointStream>>coord){ +// firstTempPoint.push_back(coord); +// ++tempDimPoints; +// } +// // we store the point in our points array +// tempPoints[0]=new double[tempDimPoints]; +// for( int j = 0 ; j>tempPoints[i][j]; +// } +// } +// +// // Load all of the faces. +// for (i = 0; i < tempNumFaces; i++) { +// // This tells us how many points make up +// // this face. +// ifs >> tempFaceSizes[i]; +// // So we declare a new array of that size +// tempFaces[i] = new int[tempFaceSizes[i]]; +// // And load its elements with the vertex indices. +// for (int j = 0; j < tempFaceSizes[i]; j++) { +// ifs >> tempFaces[i][j]; +// } +// // Clear out any face color data by reading up to +// // the newline. 128 is probably considerably more +// // space than necessary, but better safe than +// // sorry. +// ifs.getline(tempBuf, 128); +// } +// } +// +// // Here is where we copy the data from the temp +// // structures into our permanent structures. We +// // probably will do some more processing on the +// // data at the same time. This code you must fill +// // in on your own. +// if (goodLoad) { +// // we save vertices first in the complex +// for (i = 0; i < tempNumPoints; i++) +// complex.add_vertex(tempPoints[i],tempDimPoints); +// +// // we save faces +// for (i = 0; i < tempNumFaces; i++) { +// for (int j = 0; j < tempFaceSizes[i]; j++) +// complex.add_face(tempFaceSizes[i],tempFaces[i]); +// } +// } +// +// // Now that we're done, we have to make sure we +// // free our dynamic memory. +// for (i = 0; i < tempNumPoints; i++) { +// delete []tempPoints[i]; +// } +// delete []tempPoints; +// +// for (i = 0; i < tempNumFaces; i++) { +// delete tempFaces[i]; +// } +// delete []tempFaces; +// delete []tempFaceSizes; +// +// // Clean up our ifstream. The MFC framework will +// // take care of the CArchive. +// ifs.close(); +// +// return goodLoad; +//} template -- cgit v1.2.3