summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Contraction/example/Rips_contraction.cpp37
-rw-r--r--src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h3
-rw-r--r--src/common/include/gudhi/Off_reader.h22
-rw-r--r--src/common/include/gudhi/iofile.h340
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 "<<argv[0]<<" GUDHIPATH/src/data/sphere3D.off 0.1 to load the file GUDHIPATH/src/data/sphere3D.off and contract the Rips complex built with paremeter 0.2.\n";
+ return -1;
+ }
-
-
-void test_contraction_rips(string name_file, double offset){
boost::timer::auto_cpu_timer t;
Complex complex;
// load the points
- Skeleton_blocker_off_reader<Complex> off_reader(name_file,complex,true);
+ Skeleton_blocker_off_reader<Complex> off_reader(argv[1],complex,true);
if(!off_reader.is_valid()){
- std::cerr << "Unable to read file:"<<name_file<<std::endl;
- return;
+ std::cerr << "Unable to read file:"<<argv[1]<<std::endl;
+ return EXIT_FAILURE;
}
- std::cerr << "build the Rips complex"<<std::endl;
+ std::cout << "build the Rips complex"<<std::endl;
- build_rips(complex,offset);
+ build_rips(complex,atof(argv[2]));
- std::cerr << "Initial complex has "<<
+ std::cout << "Initial complex has "<<
complex.num_vertices()<<" vertices, and "<<
complex.num_edges()<<" edges."<<std::endl;
@@ -77,24 +80,12 @@ void test_contraction_rips(string name_file, double offset){
contraction::make_remove_popable_blockers_visitor<Profile>());
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"<<std::endl;
-
-}
-
-
-int main (int argc, char *argv[])
-{
- if (argc!=3){
- std::cerr << "Usage "<<argv[0]<<" GUDHIPATH/src/data/sphere3D.off 0.1 to load the file GUDHIPATH/src/data/sphere3D.off and contract the Rips complex built with paremeter 0.2.\n";
- return -1;
- }
-
- std::string name_file(argv[1]);
- test_contraction_rips(name_file,atof(argv[2]));
+ return EXIT_SUCCESS;
}
diff --git a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h
index 924b653c..bcaa3d8c 100644
--- a/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h
+++ b/src/Skeleton_blocker/include/gudhi/Skeleton_blocker_geometric_complex.h
@@ -46,9 +46,10 @@ public:
/**
* @brief Add a vertex to the complex with its associated point.
*/
- void add_vertex(const Point& point){
+ Vertex_handle add_vertex(const Point& point){
Vertex_handle ad = SimplifiableSkeletonblocker::add_vertex();
(*this)[ad].point() = point;
+ return ad;
}
diff --git a/src/common/include/gudhi/Off_reader.h b/src/common/include/gudhi/Off_reader.h
index a9c64f97..1c99a90a 100644
--- a/src/common/include/gudhi/Off_reader.h
+++ b/src/common/include/gudhi/Off_reader.h
@@ -1,8 +1,8 @@
/*
* Off_reader.h
* Created on: Nov 28, 2014
- * This file is part of the Gudhi Library. The Gudhi library
- * (Geometric Understanding in Higher Dimensions) is a generic C++
+ * This file is part of the Gudhi Library. The Gudhi library
+ * (Geometric Understanding in Higher Dimensions) is a generic C++
* library for computational topology.
*
* Author(s): David Salinas
@@ -21,7 +21,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ *
*/
@@ -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<<std::endl;
+ std::cerr << "missing off header\n";
+ return false;
+ }
if(!goto_next_uncomment_line(line)) return false;
std::istringstream iss(line);
if(is_off_file){
off_info_.dim = 3;
- if(!(iss >> 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<typename Complex> 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<double> 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<tempDimPoints; ++j){
- tempPoints[0][j] = firstTempPoint.front();
- firstTempPoint.pop_front();
- }
-
- // now, we know the dimension and can read safely other points
- for (i = 1; i < tempNumPoints; i++) {
- tempPoints[i] = new double[tempDimPoints];
- for (int j = 0 ; j<tempDimPoints ; ++j){
- ifs>>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<typename Complex> 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<double> 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<tempDimPoints; ++j){
+// tempPoints[0][j] = firstTempPoint.front();
+// firstTempPoint.pop_front();
+// }
+//
+// // now, we know the dimension and can read safely other points
+// for (i = 1; i < tempNumPoints; i++) {
+// tempPoints[i] = new double[tempDimPoints];
+// for (int j = 0 ; j<tempDimPoints ; ++j){
+// ifs>>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<typename Complex>