mirror of https://github.com/CGAL/cgal
Fix Box_intersection_d, Minkowski_sum_2, Nef_3, Surface_mesh, Straight_skeleton, Triangulation_3
This commit is contained in:
parent
42c26be666
commit
f7ba8ff4df
|
|
@ -23,6 +23,14 @@
|
||||||
// enable invariant checking
|
// enable invariant checking
|
||||||
#define CGAL_SEGMENT_TREE_CHECK_INVARIANTS 1
|
#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/box_intersection_d.h>
|
||||||
#include <CGAL/Timer.h>
|
#include <CGAL/Timer.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,6 @@
|
||||||
#define CGAL_BOX_INTERSECTION_D_UTIL_H
|
#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 <vector>
|
||||||
#include <algorithm> // for pair
|
#include <algorithm> // for pair
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#ifndef CGAL_USE_CORE
|
#ifndef CGAL_USE_CORE
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
int main ()
|
int main ()
|
||||||
{
|
{
|
||||||
|
|
@ -24,15 +25,6 @@ int main ()
|
||||||
#include <list>
|
#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 CGAL::CORE_algebraic_number_traits Nt_traits;
|
||||||
typedef Nt_traits::Rational Rational;
|
typedef Nt_traits::Rational Rational;
|
||||||
typedef Nt_traits::Algebraic Algebraic;
|
typedef Nt_traits::Algebraic Algebraic;
|
||||||
|
|
@ -91,8 +83,10 @@ int main (int argc, char **argv)
|
||||||
|
|
||||||
// Read the offset radius.
|
// Read the offset radius.
|
||||||
int numer, denom;
|
int numer, denom;
|
||||||
|
char c;
|
||||||
if (sscanf (argv[i+1], "%d/%d", &numer, &denom) != 2)
|
std::istringstream iss(argv[i+1]);
|
||||||
|
iss >> numer >> c >> denom;
|
||||||
|
if (! iss.good())
|
||||||
{
|
{
|
||||||
std::cerr << "Invalid radius: " << argv[i+1] << std::endl;
|
std::cerr << "Invalid radius: " << argv[i+1] << std::endl;
|
||||||
return (1);
|
return (1);
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
#include <CGAL/Nef_S2/SM_point_locator.h>
|
#include <CGAL/Nef_S2/SM_point_locator.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace CGAL {
|
namespace CGAL {
|
||||||
|
|
||||||
|
|
@ -143,13 +144,10 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool does_nef3_equals_file(Nef_polyhedron& N, const char* name) {
|
bool does_nef3_equals_file(Nef_polyhedron& N, const char* name) {
|
||||||
char* fullname = new char[std::strlen(datadir)+std::strlen(name)+1];
|
std::string fullname = std::string(datadir) + std::string(name);
|
||||||
std::strcpy(fullname, datadir);
|
|
||||||
std::strcat(fullname, name);
|
|
||||||
std::ofstream out("data/temp.nef3");
|
std::ofstream out("data/temp.nef3");
|
||||||
out << N;
|
out << N;
|
||||||
bool b = are_files_equal("data/temp.nef3",fullname);
|
bool b = are_files_equal("data/temp.nef3",fullname.c_str());
|
||||||
delete [] fullname;
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -163,14 +161,11 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
Nef_polyhedron load_nef3(const char* name) {
|
Nef_polyhedron load_nef3(const char* name) {
|
||||||
char* fullname = new char[std::strlen(datadir)+std::strlen(name)+1];
|
std::string fullname = std::string(datadir) + std::string(name);
|
||||||
std::strcpy(fullname, datadir);
|
std::ifstream input(fullname.c_str());
|
||||||
std::strcat(fullname, name);
|
|
||||||
std::ifstream input(fullname);
|
|
||||||
assert(input.good());
|
assert(input.good());
|
||||||
Nef_polyhedron tmp;
|
Nef_polyhedron tmp;
|
||||||
input >> tmp;
|
input >> tmp;
|
||||||
delete[] fullname;
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,10 @@
|
||||||
#include <CGAL/basic.h>
|
#include <CGAL/basic.h>
|
||||||
#include <CGAL/algorithm.h>
|
#include <CGAL/algorithm.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <boost/format.hpp>
|
||||||
|
|
||||||
namespace CGAL {
|
namespace CGAL {
|
||||||
|
|
||||||
|
|
@ -140,24 +142,24 @@ private:
|
||||||
|
|
||||||
std::string get_entity_handle()
|
std::string get_entity_handle()
|
||||||
{
|
{
|
||||||
char lBuff[64];
|
std::ostringstream oss;
|
||||||
sprintf(lBuff,"%5x",mHandle++);
|
oss << boost::format("%5x") % mHandle++;
|
||||||
return std::string(lBuff);
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string to_str ( int aN )
|
std::string to_str ( int aN )
|
||||||
{
|
{
|
||||||
char lBuff[64];
|
std::ostringstream oss;
|
||||||
sprintf(lBuff,"%6d",aN);
|
oss << boost::format("%6d") % aN;
|
||||||
return std::string(lBuff);
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string to_str ( double aN )
|
std::string to_str ( double aN )
|
||||||
{
|
{
|
||||||
char lBuff[64];
|
std::ostringstream oss;
|
||||||
sprintf(lBuff,"%6.6f",aN);
|
oss << boost::format("%6.6f") % aN;
|
||||||
return std::string(lBuff);
|
return oss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void insert_line ( Line_iterator aPos, std::string aLine )
|
void insert_line ( Line_iterator aPos, std::string aLine )
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,8 @@
|
||||||
//== INCLUDES =================================================================
|
//== INCLUDES =================================================================
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdio>
|
#include <fstream>
|
||||||
|
#include <sstream>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
@ -51,17 +52,14 @@ namespace CGAL {
|
||||||
|
|
||||||
namespace internal {
|
namespace internal {
|
||||||
// helper function
|
// 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;
|
in.read(reinterpret_cast<char*>(&t), sizeof(t));
|
||||||
err = fread(&t, 1, sizeof(t), in);
|
|
||||||
if(err != 0)
|
|
||||||
throw std::runtime_error("fread error");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Point_3>
|
template <typename Point_3>
|
||||||
bool read_off_binary(Surface_mesh<Point_3>& mesh,
|
bool read_off_binary(Surface_mesh<Point_3>& mesh,
|
||||||
FILE* in,
|
std::istream& in,
|
||||||
const bool has_normals,
|
const bool has_normals,
|
||||||
const bool has_texcoords)
|
const bool has_texcoords)
|
||||||
{
|
{
|
||||||
|
|
@ -95,7 +93,7 @@ bool read_off_binary(Surface_mesh<Point_3>& mesh,
|
||||||
|
|
||||||
|
|
||||||
// read vertices: pos [normal] [color] [texcoord]
|
// read vertices: pos [normal] [color] [texcoord]
|
||||||
for (i=0; i<nV && !feof(in); ++i)
|
for (i=0; i<nV && in.good(); ++i)
|
||||||
{
|
{
|
||||||
// position
|
// position
|
||||||
internal::read(in, p);
|
internal::read(in, p);
|
||||||
|
|
@ -139,7 +137,7 @@ bool read_off_binary(Surface_mesh<Point_3>& mesh,
|
||||||
|
|
||||||
template <typename Point_3>
|
template <typename Point_3>
|
||||||
bool read_off_ascii(Surface_mesh<Point_3>& mesh,
|
bool read_off_ascii(Surface_mesh<Point_3>& mesh,
|
||||||
FILE* in,
|
std::istream& in,
|
||||||
const bool has_normals,
|
const bool has_normals,
|
||||||
const bool has_texcoords)
|
const bool has_texcoords)
|
||||||
{
|
{
|
||||||
|
|
@ -150,9 +148,8 @@ bool read_off_ascii(Surface_mesh<Point_3>& mesh,
|
||||||
typedef typename K::Vector_3 Texture_coordinate;
|
typedef typename K::Vector_3 Texture_coordinate;
|
||||||
|
|
||||||
boost::array<double, 3> buffer;
|
boost::array<double, 3> buffer;
|
||||||
char line[100], *lp;
|
std::string line;
|
||||||
unsigned int i, j, items, idx;
|
unsigned int i, j, idx;
|
||||||
int nc;
|
|
||||||
unsigned int nV, nF, nE;
|
unsigned int nV, nF, nE;
|
||||||
typename Mesh::Vertex_index v;
|
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_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;
|
if (has_texcoords) texcoords = mesh.template add_property_map<typename Mesh::Vertex_index, Texture_coordinate>("v:texcoord").first;
|
||||||
|
|
||||||
int c;
|
char c;
|
||||||
do {
|
do {
|
||||||
c = getc(in);
|
c = in.get();
|
||||||
if(c == '#'){
|
if(c == '#'){
|
||||||
fgets(line, 100, in);
|
getline(in,line);
|
||||||
} else {
|
} else {
|
||||||
ungetc(c,in);
|
in.putback(c);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}while(1);
|
}while(1);
|
||||||
|
|
||||||
// #Vertice, #Faces, #Edges
|
// #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.clear();
|
||||||
mesh.reserve(nV, (std::max)(3*nV, nE), nF);
|
mesh.reserve(nV, (std::max)(3*nV, nE), nF);
|
||||||
|
|
||||||
// read vertices: pos [normal] [color] [texcoord]
|
// read vertices: pos [normal] [color] [texcoord]
|
||||||
for (i=0; i<nV && !feof(in); ++i)
|
for (i=0; i<nV && in.good(); ++i)
|
||||||
{
|
{
|
||||||
// read line
|
// 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
|
if(line[0] == '#') // if the first column is a # we are looking at a comment line
|
||||||
{
|
{
|
||||||
--i;
|
--i;
|
||||||
|
|
@ -192,28 +190,21 @@ bool read_off_ascii(Surface_mesh<Point_3>& mesh,
|
||||||
}
|
}
|
||||||
|
|
||||||
// position
|
// position
|
||||||
items = sscanf(lp, "%lf %lf %lf%n", &(buffer[0]), &buffer[1], &buffer[2], &nc);
|
std::istringstream iss(line);
|
||||||
CGAL_assertion(items==3);
|
iss >> iformat(buffer[0]) >> iformat(buffer[1]) >> iformat(buffer[2]);
|
||||||
v = mesh.add_vertex(Point_3(buffer[0], buffer[1], buffer[2]));
|
v = mesh.add_vertex(Point_3(buffer[0], buffer[1], buffer[2]));
|
||||||
lp += nc;
|
|
||||||
|
|
||||||
// normal
|
// normal
|
||||||
if (has_normals)
|
if (has_normals)
|
||||||
{
|
{
|
||||||
if (sscanf(lp, "%lf %lf %lf%n", &buffer[0], &buffer[1], &buffer[2], &nc) == 3)
|
iss >> iformat(buffer[0]) >> iformat(buffer[1]) >> iformat(buffer[2]);
|
||||||
{
|
|
||||||
normals[v] = Vector_3(buffer[0], buffer[1], buffer[2]);
|
|
||||||
}
|
|
||||||
lp += nc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// tex coord
|
// tex coord
|
||||||
if (has_texcoords)
|
if (has_texcoords)
|
||||||
{
|
{
|
||||||
items = sscanf(lp, "%lf %lf%n", &buffer[0], &buffer[1], &nc);
|
iss >> iformat(buffer[0]) >> iformat(buffer[1]);
|
||||||
CGAL_assertion(items == 2);
|
|
||||||
texcoords[v] = Vector_3(buffer[0], buffer[1], 0.0);
|
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)
|
for (i=0; i<nF; ++i)
|
||||||
{
|
{
|
||||||
// read line
|
// 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
|
if(line[0] == '#') // if the first column is a # we are looking at a comment line
|
||||||
{
|
{
|
||||||
--i;
|
--i;
|
||||||
|
|
@ -230,18 +221,15 @@ bool read_off_ascii(Surface_mesh<Point_3>& mesh,
|
||||||
}
|
}
|
||||||
|
|
||||||
// #vertices
|
// #vertices
|
||||||
items = sscanf(lp, "%d%n", (int*)&nV, &nc);
|
std::istringstream iss(line);
|
||||||
CGAL_assertion(items == 1);
|
iss >> nV;
|
||||||
vertices.resize(nV);
|
vertices.resize(nV);
|
||||||
lp += nc;
|
|
||||||
|
|
||||||
// indices
|
// indices
|
||||||
for (j=0; j<nV; ++j)
|
for (j=0; j<nV; ++j)
|
||||||
{
|
{
|
||||||
items = sscanf(lp, "%d%n", (int*)&idx, &nc);
|
iss >> idx;
|
||||||
CGAL_assertion(items == 1);
|
|
||||||
vertices[j] = typename Mesh::Vertex_index(idx);
|
vertices[j] = typename Mesh::Vertex_index(idx);
|
||||||
lp += nc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!mesh.add_face(vertices).is_valid()) {
|
if(!mesh.add_face(vertices).is_valid()) {
|
||||||
|
|
@ -249,7 +237,6 @@ bool read_off_ascii(Surface_mesh<Point_3>& mesh,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CGAL_USE(items);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -279,7 +266,7 @@ bool read_off_ascii(Surface_mesh<Point_3>& mesh,
|
||||||
template <typename K>
|
template <typename K>
|
||||||
bool read_off(Surface_mesh<K>& mesh, const std::string& filename)
|
bool read_off(Surface_mesh<K>& mesh, const std::string& filename)
|
||||||
{
|
{
|
||||||
char line[100];
|
std::string line;
|
||||||
bool has_texcoords = false;
|
bool has_texcoords = false;
|
||||||
bool has_normals = false;
|
bool has_normals = false;
|
||||||
bool has_hcoords = false;
|
bool has_hcoords = false;
|
||||||
|
|
@ -287,25 +274,24 @@ bool read_off(Surface_mesh<K>& mesh, const std::string& filename)
|
||||||
bool is_binary = false;
|
bool is_binary = false;
|
||||||
|
|
||||||
// open file (in ASCII mode)
|
// open file (in ASCII mode)
|
||||||
FILE* in = std::fopen(filename.c_str(), "r");
|
std::ifstream in(filename.c_str());
|
||||||
if (!in) return false;
|
if (!in) return false;
|
||||||
|
|
||||||
// read header: [ST][C][N][4][n]OFF BINARY
|
// read header: [ST][C][N][4][n]OFF BINARY
|
||||||
char *c = std::fgets(line, 100, in);
|
std::getline(in,line);
|
||||||
CGAL_assertion(c != NULL);
|
const char *c = line.c_str();
|
||||||
c = line;
|
|
||||||
if (c[0] == 'S' && c[1] == 'T') { has_texcoords = true; c += 2; }
|
if (c[0] == 'S' && c[1] == 'T') { has_texcoords = true; c += 2; }
|
||||||
if (c[0] == 'N') { has_normals = true; ++c; }
|
if (c[0] == 'N') { has_normals = true; ++c; }
|
||||||
if (c[0] == '4') { has_hcoords = true; ++c; }
|
if (c[0] == '4') { has_hcoords = true; ++c; }
|
||||||
if (c[0] == 'n') { has_dim = 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;
|
if (strncmp(c+4, "BINARY", 6) == 0) is_binary = true;
|
||||||
|
|
||||||
|
|
||||||
// homogeneous coords, and vertex dimension != 3 are not supported
|
// homogeneous coords, and vertex dimension != 3 are not supported
|
||||||
if (has_hcoords || has_dim)
|
if (has_hcoords || has_dim)
|
||||||
{
|
{
|
||||||
std::fclose(in);
|
in.close();
|
||||||
return false;
|
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 binary: reopen file in binary mode
|
||||||
if (is_binary)
|
if (is_binary)
|
||||||
{
|
{
|
||||||
std::fclose(in);
|
in.close();
|
||||||
in = std::fopen(filename.c_str(), "rb");
|
in.open(filename.c_str(), std::ios::binary);
|
||||||
c = std::fgets(line, 100, in);
|
std::getline(in,line);
|
||||||
CGAL_assertion(c != NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// read as ASCII or binary
|
// 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_binary(mesh, in, has_normals, has_texcoords) :
|
||||||
internal::read_off_ascii(mesh, in, has_normals, has_texcoords));
|
internal::read_off_ascii(mesh, in, has_normals, has_texcoords));
|
||||||
|
|
||||||
|
in.close();
|
||||||
std::fclose(in);
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -343,10 +343,10 @@ int main(int argc, char **argv)
|
||||||
boost::int32_t seed0 = 42, seed1 = 43, seed2 = 42, seed3 = 42;
|
boost::int32_t seed0 = 42, seed1 = 43, seed2 = 42, seed3 = 42;
|
||||||
|
|
||||||
// You can also pass seeds on the command line.
|
// You can also pass seeds on the command line.
|
||||||
if (argc > 1) std::sscanf (argv[1], "%d", &seed0);
|
if (argc > 1) { std::istringstream iss(argv[1]); iss >>seed0; }
|
||||||
if (argc > 2) std::sscanf (argv[2], "%d", &seed1);
|
if (argc > 2) { std::istringstream iss(argv[2]); iss >>seed1; }
|
||||||
if (argc > 3) std::sscanf (argv[3], "%d", &seed2);
|
if (argc > 3) { std::istringstream iss(argv[3]); iss >>seed2; }
|
||||||
if (argc > 4) std::sscanf (argv[4], "%d", &seed3);
|
if (argc > 4) { std::istringstream iss(argv[4]); iss >>seed3; }
|
||||||
|
|
||||||
Cls T;
|
Cls T;
|
||||||
point_set points;
|
point_set points;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue