Fix Box_intersection_d, Minkowski_sum_2, Nef_3, Surface_mesh, Straight_skeleton, Triangulation_3

This commit is contained in:
Andreas Fabri 2018-02-23 11:35:58 +00:00
parent 42c26be666
commit f7ba8ff4df
7 changed files with 68 additions and 93 deletions

View File

@ -23,6 +23,14 @@
// enable invariant checking
#define CGAL_SEGMENT_TREE_CHECK_INVARIANTS 1
#ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE 1
#endif
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS 1
#endif
#include <CGAL/box_intersection_d.h>
#include <CGAL/Timer.h>
#include <iostream>

View File

@ -2,14 +2,6 @@
#define CGAL_BOX_INTERSECTION_D_UTIL_H
#ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE 1
#endif
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS 1
#endif
#include <vector>
#include <algorithm> // for pair
#include <cmath>

View File

@ -3,6 +3,7 @@
#ifndef CGAL_USE_CORE
#include <iostream>
#include <sstream>
int main ()
{
@ -24,15 +25,6 @@ int main ()
#include <list>
#ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE 1
#endif
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS 1
#endif
typedef CGAL::CORE_algebraic_number_traits Nt_traits;
typedef Nt_traits::Rational Rational;
typedef Nt_traits::Algebraic Algebraic;
@ -91,8 +83,10 @@ int main (int argc, char **argv)
// Read the offset radius.
int numer, denom;
if (sscanf (argv[i+1], "%d/%d", &numer, &denom) != 2)
char c;
std::istringstream iss(argv[i+1]);
iss >> numer >> c >> denom;
if (! iss.good())
{
std::cerr << "Invalid radius: " << argv[i+1] << std::endl;
return (1);

View File

@ -34,6 +34,7 @@
#include <CGAL/Nef_S2/SM_point_locator.h>
#include <fstream>
#include <cassert>
#include <string>
namespace CGAL {
@ -143,13 +144,10 @@ private:
}
bool does_nef3_equals_file(Nef_polyhedron& N, const char* name) {
char* fullname = new char[std::strlen(datadir)+std::strlen(name)+1];
std::strcpy(fullname, datadir);
std::strcat(fullname, name);
std::string fullname = std::string(datadir) + std::string(name);
std::ofstream out("data/temp.nef3");
out << N;
bool b = are_files_equal("data/temp.nef3",fullname);
delete [] fullname;
bool b = are_files_equal("data/temp.nef3",fullname.c_str());
return b;
}
@ -163,14 +161,11 @@ private:
}
Nef_polyhedron load_nef3(const char* name) {
char* fullname = new char[std::strlen(datadir)+std::strlen(name)+1];
std::strcpy(fullname, datadir);
std::strcat(fullname, name);
std::ifstream input(fullname);
std::string fullname = std::string(datadir) + std::string(name);
std::ifstream input(fullname.c_str());
assert(input.good());
Nef_polyhedron tmp;
input >> tmp;
delete[] fullname;
return tmp;
}

View File

@ -27,8 +27,10 @@
#include <CGAL/basic.h>
#include <CGAL/algorithm.h>
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <boost/format.hpp>
namespace CGAL {
@ -140,24 +142,24 @@ private:
std::string get_entity_handle()
{
char lBuff[64];
sprintf(lBuff,"%5x",mHandle++);
return std::string(lBuff);
std::ostringstream oss;
oss << boost::format("%5x") % mHandle++;
return oss.str();
}
std::string to_str ( int aN )
{
char lBuff[64];
sprintf(lBuff,"%6d",aN);
return std::string(lBuff);
std::ostringstream oss;
oss << boost::format("%6d") % aN;
return oss.str();
}
std::string to_str ( double aN )
{
char lBuff[64];
sprintf(lBuff,"%6.6f",aN);
return std::string(lBuff);
std::ostringstream oss;
oss << boost::format("%6.6f") % aN;
return oss.str();
}
void insert_line ( Line_iterator aPos, std::string aLine )

View File

@ -29,7 +29,8 @@
//== INCLUDES =================================================================
#include <string>
#include <cstdio>
#include <fstream>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <vector>
@ -51,17 +52,14 @@ namespace CGAL {
namespace internal {
// helper function
template <typename T> void read(FILE* in, T& t)
template <typename T> void read(std::istream& in, T& t)
{
std::size_t err = 0;
err = fread(&t, 1, sizeof(t), in);
if(err != 0)
throw std::runtime_error("fread error");
in.read(reinterpret_cast<char*>(&t), sizeof(t));
}
template <typename Point_3>
bool read_off_binary(Surface_mesh<Point_3>& mesh,
FILE* in,
std::istream& in,
const bool has_normals,
const bool has_texcoords)
{
@ -95,7 +93,7 @@ bool read_off_binary(Surface_mesh<Point_3>& mesh,
// read vertices: pos [normal] [color] [texcoord]
for (i=0; i<nV && !feof(in); ++i)
for (i=0; i<nV && in.good(); ++i)
{
// position
internal::read(in, p);
@ -139,7 +137,7 @@ bool read_off_binary(Surface_mesh<Point_3>& mesh,
template <typename Point_3>
bool read_off_ascii(Surface_mesh<Point_3>& mesh,
FILE* in,
std::istream& in,
const bool has_normals,
const bool has_texcoords)
{
@ -150,9 +148,8 @@ bool read_off_ascii(Surface_mesh<Point_3>& mesh,
typedef typename K::Vector_3 Texture_coordinate;
boost::array<double, 3> buffer;
char line[100], *lp;
unsigned int i, j, items, idx;
int nc;
std::string line;
unsigned int i, j, idx;
unsigned int nV, nF, nE;
typename Mesh::Vertex_index v;
@ -163,28 +160,29 @@ bool read_off_ascii(Surface_mesh<Point_3>& mesh,
if (has_normals) normals = mesh.template add_property_map<typename Mesh::Vertex_index, Normal>("v:normal").first;
if (has_texcoords) texcoords = mesh.template add_property_map<typename Mesh::Vertex_index, Texture_coordinate>("v:texcoord").first;
int c;
char c;
do {
c = getc(in);
c = in.get();
if(c == '#'){
fgets(line, 100, in);
getline(in,line);
} else {
ungetc(c,in);
in.putback(c);
break;
}
}while(1);
// #Vertice, #Faces, #Edges
items = fscanf(in, "%d %d %d\n", (int*)&nV, (int*)&nF, (int*)&nE);
in >> nV >> nF >> nE;
getline(in,line); // reads eol
mesh.clear();
mesh.reserve(nV, (std::max)(3*nV, nE), nF);
// read vertices: pos [normal] [color] [texcoord]
for (i=0; i<nV && !feof(in); ++i)
for (i=0; i<nV && in.good(); ++i)
{
// read line
lp = fgets(line, 100, in);
getline(in, line);
if(line[0] == '#') // if the first column is a # we are looking at a comment line
{
--i;
@ -192,28 +190,21 @@ bool read_off_ascii(Surface_mesh<Point_3>& mesh,
}
// position
items = sscanf(lp, "%lf %lf %lf%n", &(buffer[0]), &buffer[1], &buffer[2], &nc);
CGAL_assertion(items==3);
std::istringstream iss(line);
iss >> iformat(buffer[0]) >> iformat(buffer[1]) >> iformat(buffer[2]);
v = mesh.add_vertex(Point_3(buffer[0], buffer[1], buffer[2]));
lp += nc;
// normal
if (has_normals)
{
if (sscanf(lp, "%lf %lf %lf%n", &buffer[0], &buffer[1], &buffer[2], &nc) == 3)
{
normals[v] = Vector_3(buffer[0], buffer[1], buffer[2]);
}
lp += nc;
iss >> iformat(buffer[0]) >> iformat(buffer[1]) >> iformat(buffer[2]);
}
// tex coord
if (has_texcoords)
{
items = sscanf(lp, "%lf %lf%n", &buffer[0], &buffer[1], &nc);
CGAL_assertion(items == 2);
iss >> iformat(buffer[0]) >> iformat(buffer[1]);
texcoords[v] = Vector_3(buffer[0], buffer[1], 0.0);
lp += nc;
}
}
@ -222,7 +213,7 @@ bool read_off_ascii(Surface_mesh<Point_3>& mesh,
for (i=0; i<nF; ++i)
{
// read line
lp = fgets(line, 100, in);
getline(in, line);
if(line[0] == '#') // if the first column is a # we are looking at a comment line
{
--i;
@ -230,18 +221,15 @@ bool read_off_ascii(Surface_mesh<Point_3>& mesh,
}
// #vertices
items = sscanf(lp, "%d%n", (int*)&nV, &nc);
CGAL_assertion(items == 1);
std::istringstream iss(line);
iss >> nV;
vertices.resize(nV);
lp += nc;
// indices
for (j=0; j<nV; ++j)
{
items = sscanf(lp, "%d%n", (int*)&idx, &nc);
CGAL_assertion(items == 1);
iss >> idx;
vertices[j] = typename Mesh::Vertex_index(idx);
lp += nc;
}
if(!mesh.add_face(vertices).is_valid()) {
@ -249,7 +237,6 @@ bool read_off_ascii(Surface_mesh<Point_3>& mesh,
return false;
}
}
CGAL_USE(items);
return true;
}
}
@ -279,7 +266,7 @@ bool read_off_ascii(Surface_mesh<Point_3>& mesh,
template <typename K>
bool read_off(Surface_mesh<K>& mesh, const std::string& filename)
{
char line[100];
std::string line;
bool has_texcoords = false;
bool has_normals = false;
bool has_hcoords = false;
@ -287,25 +274,24 @@ bool read_off(Surface_mesh<K>& mesh, const std::string& filename)
bool is_binary = false;
// open file (in ASCII mode)
FILE* in = std::fopen(filename.c_str(), "r");
std::ifstream in(filename.c_str());
if (!in) return false;
// read header: [ST][C][N][4][n]OFF BINARY
char *c = std::fgets(line, 100, in);
CGAL_assertion(c != NULL);
c = line;
std::getline(in,line);
const char *c = line.c_str();
if (c[0] == 'S' && c[1] == 'T') { has_texcoords = true; c += 2; }
if (c[0] == 'N') { has_normals = true; ++c; }
if (c[0] == '4') { has_hcoords = true; ++c; }
if (c[0] == 'n') { has_dim = true; ++c; }
if (strncmp(c, "OFF", 3) != 0) { std::fclose(in); return false; } // no OFF
if (strncmp(c, "OFF", 3) != 0) { in.close(); return false; } // no OFF
if (strncmp(c+4, "BINARY", 6) == 0) is_binary = true;
// homogeneous coords, and vertex dimension != 3 are not supported
if (has_hcoords || has_dim)
{
std::fclose(in);
in.close();
return false;
}
@ -313,10 +299,9 @@ bool read_off(Surface_mesh<K>& mesh, const std::string& filename)
// if binary: reopen file in binary mode
if (is_binary)
{
std::fclose(in);
in = std::fopen(filename.c_str(), "rb");
c = std::fgets(line, 100, in);
CGAL_assertion(c != NULL);
in.close();
in.open(filename.c_str(), std::ios::binary);
std::getline(in,line);
}
// read as ASCII or binary
@ -324,8 +309,7 @@ bool read_off(Surface_mesh<K>& mesh, const std::string& filename)
internal::read_off_binary(mesh, in, has_normals, has_texcoords) :
internal::read_off_ascii(mesh, in, has_normals, has_texcoords));
std::fclose(in);
in.close();
return ok;
}

View File

@ -343,10 +343,10 @@ int main(int argc, char **argv)
boost::int32_t seed0 = 42, seed1 = 43, seed2 = 42, seed3 = 42;
// You can also pass seeds on the command line.
if (argc > 1) std::sscanf (argv[1], "%d", &seed0);
if (argc > 2) std::sscanf (argv[2], "%d", &seed1);
if (argc > 3) std::sscanf (argv[3], "%d", &seed2);
if (argc > 4) std::sscanf (argv[4], "%d", &seed3);
if (argc > 1) { std::istringstream iss(argv[1]); iss >>seed0; }
if (argc > 2) { std::istringstream iss(argv[2]); iss >>seed1; }
if (argc > 3) { std::istringstream iss(argv[3]); iss >>seed2; }
if (argc > 4) { std::istringstream iss(argv[4]); iss >>seed3; }
Cls T;
point_set points;