mirror of https://github.com/CGAL/cgal
Move some examples from Polyhedron to Stream_support
(as they don't make use of CGAL::Polyhedron_3)
This commit is contained in:
parent
d620198049
commit
5ca88dedc3
|
|
@ -1,100 +0,0 @@
|
|||
// Convert from OFF format to OpenInventor (.iv) format.
|
||||
|
||||
#include <CGAL/IO/Verbose_ostream.h>
|
||||
#include <CGAL/IO/Inventor_ostream.h>
|
||||
#include <CGAL/IO/File_writer_inventor.h>
|
||||
#include <CGAL/IO/generic_copy_OFF.h>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool dummy_switch = false;
|
||||
bool verbose = false;
|
||||
|
||||
// main function with standard unix commandline arguments
|
||||
// ------------------------------------------------------
|
||||
int main( int argc, char **argv) {
|
||||
int n = 0; // number of filenames
|
||||
char *filename[2];
|
||||
bool help = false;
|
||||
for (int i = 1; i < argc; i++) { // check commandline options
|
||||
if ( strcmp( "-v", argv[i]) == 0)
|
||||
verbose = true;
|
||||
else if ( (strcmp( "-h", argv[i]) == 0) ||
|
||||
(strcmp( "-help", argv[i]) == 0))
|
||||
help = true;
|
||||
else if ( n < 2 ) {
|
||||
filename[ n++] = argv[i];
|
||||
} else {
|
||||
++n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n > 2) || help) {
|
||||
if ( ! help)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
|
||||
<< endl;
|
||||
cerr << " convert a CGAL object (OFF) to Open Inventor .iv "
|
||||
"format." << endl;
|
||||
cerr << " -v verbose." << endl;
|
||||
exit( ! help);
|
||||
}
|
||||
|
||||
CGAL::Verbose_ostream vout( verbose);
|
||||
vout << argv[0] << ": verbosity on." << endl;
|
||||
|
||||
const char* iname = "cin";
|
||||
istream* p_in = &cin;
|
||||
ifstream in;
|
||||
if ( n > 0) {
|
||||
in.open( filename[0]);
|
||||
p_in = ∈
|
||||
iname = filename[0];
|
||||
}
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< iname
|
||||
<< "' for reading." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
const char* oname = "cout";
|
||||
ostream* p_out = &cout;
|
||||
ofstream out;
|
||||
if ( n > 1) {
|
||||
out.open( filename[1]);
|
||||
p_out = &out;
|
||||
oname = filename[1];
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< oname
|
||||
<< "' for writing." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
vout << "CGAL::generic_copy_OFF( " << iname << ", " << oname
|
||||
<< ") ...." << endl;
|
||||
CGAL::Inventor_ostream os( *p_out);
|
||||
CGAL::File_writer_inventor writer;
|
||||
CGAL::generic_copy_OFF( *p_in, *p_out, writer);
|
||||
if(!os) return EXIT_FAILURE;
|
||||
os.close();
|
||||
vout << " .... done." << endl;
|
||||
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << " read error: while reading file '"
|
||||
<< iname << "'." << endl;
|
||||
exit( 1);
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << " write error: while writing file '"
|
||||
<< oname << "'." << endl;
|
||||
exit( 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// EOF //
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
// Copies a file in OFF format.
|
||||
|
||||
#include <CGAL/IO/Verbose_ostream.h>
|
||||
#include <CGAL/IO/File_writer_OFF.h>
|
||||
#include <CGAL/IO/generic_copy_OFF.h>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool verbose = false;
|
||||
bool binary = false;
|
||||
bool skel = false;
|
||||
bool noc = false;
|
||||
|
||||
// main function with standard unix commandline arguments
|
||||
// ------------------------------------------------------
|
||||
int main( int argc, char **argv) {
|
||||
int n = 0; // number of filenames
|
||||
char *filename[2];
|
||||
bool help = false;
|
||||
for (int i = 1; i < argc; i++) { // check commandline options
|
||||
if ( strcmp( "-v", argv[i]) == 0)
|
||||
verbose = true;
|
||||
else if ( strcmp( "-b", argv[i]) == 0)
|
||||
binary = true;
|
||||
else if ( strcmp( "-skel", argv[i]) == 0)
|
||||
skel = true;
|
||||
else if ( strcmp( "-noc", argv[i]) == 0)
|
||||
noc = true;
|
||||
else if ( (strcmp( "-h", argv[i]) == 0) ||
|
||||
(strcmp( "-help", argv[i]) == 0))
|
||||
help = true;
|
||||
else if ( n < 2 ) {
|
||||
filename[ n++] = argv[i];
|
||||
} else {
|
||||
++n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n > 2) || help) {
|
||||
if ( ! help)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
|
||||
<< endl;
|
||||
cerr << " copy an object in OFF." << endl;
|
||||
cerr << " -b binary (default is ASCII)." << endl;
|
||||
cerr << " -skel Geomview SKEL format." << endl;
|
||||
cerr << " -noc no comments in file." << endl;
|
||||
cerr << " -v verbose." << endl;
|
||||
exit( ! help);
|
||||
}
|
||||
|
||||
CGAL::Verbose_ostream vout( verbose);
|
||||
vout << argv[0] << ": verbosity on." << endl;
|
||||
|
||||
const char* iname = "cin";
|
||||
istream* p_in = &cin;
|
||||
ifstream in;
|
||||
if ( n > 0) {
|
||||
in.open( filename[0]);
|
||||
p_in = ∈
|
||||
iname = filename[0];
|
||||
}
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< iname
|
||||
<< "' for reading." << endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
const char* oname = "cout";
|
||||
ostream* p_out = &cout;
|
||||
ofstream out;
|
||||
if ( n > 1) {
|
||||
out.open( filename[1]);
|
||||
p_out = &out;
|
||||
oname = filename[1];
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< oname
|
||||
<< "' for writing." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
vout << "CGAL::generic_copy_OFF( " << iname << ", " << oname
|
||||
<< (binary ? ", binary" : ", ASCII") << ") ...." << endl;
|
||||
CGAL::File_header_OFF header( binary, noc, skel, verbose);
|
||||
CGAL::File_writer_OFF writer( header);
|
||||
CGAL::generic_copy_OFF( *p_in, *p_out, writer);
|
||||
vout << " .... done." << endl;
|
||||
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << " read error: while reading file '"
|
||||
<< iname << "'." << endl;
|
||||
exit( 1);
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << " write error: while writing file '"
|
||||
<< oname << "'." << endl;
|
||||
exit( 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// EOF //
|
||||
|
|
@ -1,163 +0,0 @@
|
|||
// Convert from OFF format to StereoLithography StL format.
|
||||
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/IO/Verbose_ostream.h>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool verbose = false;
|
||||
bool binary = false;
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef Kernel::Vector_3 Vector;
|
||||
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
|
||||
typedef Polyhedron::Vertex_iterator Vertex_iterator;
|
||||
typedef Polyhedron::Facet_iterator Facet_iterator;
|
||||
typedef Polyhedron::Halfedge_handle Halfedge_handle;
|
||||
|
||||
|
||||
// main function with standard unix commandline arguments
|
||||
// ------------------------------------------------------
|
||||
int main( int argc, char **argv) {
|
||||
int n = 0; // number of filenames
|
||||
char *filename[2];
|
||||
bool help = false;
|
||||
for (int i = 1; i < argc; i++) { // check commandline options
|
||||
if ( strcmp( "-v", argv[i]) == 0)
|
||||
verbose = true;
|
||||
else if ( strcmp( "-b", argv[i]) == 0)
|
||||
binary = true;
|
||||
else if ( (strcmp( "-h", argv[i]) == 0) ||
|
||||
(strcmp( "-help", argv[i]) == 0))
|
||||
help = true;
|
||||
else if ( n < 2 ) {
|
||||
filename[ n++] = argv[i];
|
||||
} else {
|
||||
++n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n > 2) || help) {
|
||||
if ( ! help)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
|
||||
<< endl;
|
||||
cerr << " convert a CGAL object (OFF) to StereoLithography StL "
|
||||
"format." << endl;
|
||||
cerr << " -v verbose." << endl;
|
||||
cerr << " -b binary." << endl;
|
||||
exit( ! help);
|
||||
}
|
||||
|
||||
CGAL::Verbose_ostream vout( verbose);
|
||||
vout << argv[0] << ": verbosity on." << endl;
|
||||
|
||||
const char* iname = "cin";
|
||||
istream* p_in = &cin;
|
||||
ifstream in;
|
||||
if ( n > 0) {
|
||||
in.open( filename[0]);
|
||||
p_in = ∈
|
||||
iname = filename[0];
|
||||
}
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< iname
|
||||
<< "' for reading." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
vout << "Reading polyhedron ..." << endl;
|
||||
Polyhedron P;
|
||||
(*p_in) >> P;
|
||||
vout << " .... done." << endl;
|
||||
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << " read error: while reading file '"<< iname << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
const char* oname = "cout";
|
||||
ostream* p_out = &cout;
|
||||
ofstream out;
|
||||
if ( n > 1) {
|
||||
out.open( filename[1]);
|
||||
p_out = &out;
|
||||
oname = filename[1];
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< oname
|
||||
<< "' for writing." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
vout << "Write file ...." << endl;
|
||||
*p_out << "solid " << oname << endl;
|
||||
|
||||
// find "bottom/left/front" corner to translate into positive octant
|
||||
Vertex_iterator vi = P.vertices_begin();
|
||||
Point p = vi->point();
|
||||
double minx = p.x();
|
||||
double miny = p.y();
|
||||
double minz = p.z();
|
||||
for ( ; vi != P.vertices_end(); ++vi) {
|
||||
p = vi->point();
|
||||
if ( p.x() < minx)
|
||||
minx = p.x();
|
||||
if ( p.y() < miny)
|
||||
miny = p.y();
|
||||
if ( p.z() < minz)
|
||||
minz = p.z();
|
||||
}
|
||||
// translate into positive octant
|
||||
Vector trans( -minx, -miny, -minz);
|
||||
for ( Vertex_iterator i = P.vertices_begin(); i != P.vertices_end(); ++i) {
|
||||
i->point() = i->point() + trans;
|
||||
}
|
||||
// write triangles
|
||||
for ( Facet_iterator i = P.facets_begin(); i != P.facets_end(); ++i) {
|
||||
Halfedge_handle h = i->halfedge();
|
||||
if ( h->next()->next()->next() != h) {
|
||||
cerr << argv[0] << " format error: polyhedron in file '"<<
|
||||
iname << "' is not triangulated." << endl;
|
||||
exit( 1);
|
||||
}
|
||||
Point p = h->vertex()->point();
|
||||
Point q = h->next()->vertex()->point();
|
||||
Point r = h->next()->next()->vertex()->point();
|
||||
// compute normal
|
||||
Vector n = CGAL::cross_product( q-p, r-p);
|
||||
Vector norm = n / std::sqrt( n * n);
|
||||
*p_out << " facet normal " << norm << endl;
|
||||
*p_out << " outer loop " << endl;
|
||||
*p_out << " vertex " << p << endl;
|
||||
*p_out << " vertex " << q << endl;
|
||||
*p_out << " vertex " << r << endl;
|
||||
*p_out << " endloop " << endl;
|
||||
*p_out << " endfacet " << endl;
|
||||
}
|
||||
|
||||
*p_out << "endsolid " << oname << endl;
|
||||
vout << " .... done." << endl;
|
||||
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << " read error: while reading file '"<< iname << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] <<" write error: while writing file '"<< oname << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// EOF //
|
||||
|
|
@ -1,113 +0,0 @@
|
|||
// Convert from OFF format to VRML (.wrl) 1.0 or 2.0 format.
|
||||
|
||||
#include <CGAL/IO/Verbose_ostream.h>
|
||||
#include <CGAL/IO/VRML_1_ostream.h>
|
||||
#include <CGAL/IO/VRML_2_ostream.h>
|
||||
#include <CGAL/IO/File_writer_inventor.h>
|
||||
#include <CGAL/IO/File_writer_VRML_2.h>
|
||||
#include <CGAL/IO/generic_copy_OFF.h>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool verbose = false;
|
||||
int version = 1;
|
||||
|
||||
// main function with standard unix commandline arguments
|
||||
// ------------------------------------------------------
|
||||
int main( int argc, char **argv) {
|
||||
int n = 0; // number of filenames
|
||||
char *filename[2];
|
||||
bool help = false;
|
||||
for (int i = 1; i < argc; i++) { // check commandline options
|
||||
if ( strcmp( "-v", argv[i]) == 0)
|
||||
verbose = true;
|
||||
else if ( strcmp( "-2", argv[i]) == 0)
|
||||
version = 2;
|
||||
else if ( (strcmp( "-h", argv[i]) == 0) ||
|
||||
(strcmp( "-help", argv[i]) == 0))
|
||||
help = true;
|
||||
else if ( n < 2 ) {
|
||||
filename[ n++] = argv[i];
|
||||
} else {
|
||||
++n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n > 2) || help) {
|
||||
if ( ! help)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
|
||||
<< endl;
|
||||
cerr << " convert a CGAL object (OFF) to VRML .wrl format."
|
||||
<< endl;
|
||||
cerr << " -2 VRML 2.0 (default is VRML 1.0)." << endl;
|
||||
cerr << " -v verbose." << endl;
|
||||
exit( ! help);
|
||||
}
|
||||
|
||||
CGAL::Verbose_ostream vout( verbose);
|
||||
vout << argv[0] << ": verbosity on." << endl;
|
||||
|
||||
const char* iname = "cin";
|
||||
istream* p_in = &cin;
|
||||
ifstream in;
|
||||
if ( n > 0) {
|
||||
in.open( filename[0]);
|
||||
p_in = ∈
|
||||
iname = filename[0];
|
||||
}
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< iname
|
||||
<< "' for reading." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
const char* oname = "cout";
|
||||
ostream* p_out = &cout;
|
||||
ofstream out;
|
||||
if ( n > 1) {
|
||||
out.open( filename[1]);
|
||||
p_out = &out;
|
||||
oname = filename[1];
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< oname
|
||||
<< "' for writing." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
vout << "CGAL::generic_copy_OFF( " << iname << ", " << oname
|
||||
<< ", V" << version << " ) ...." << endl;
|
||||
if ( version == 1) {
|
||||
CGAL::VRML_1_ostream os( *p_out);
|
||||
CGAL::File_writer_inventor writer;
|
||||
CGAL::generic_copy_OFF( *p_in, *p_out, writer);
|
||||
if(!os) return EXIT_FAILURE;
|
||||
os.close();
|
||||
} else {
|
||||
CGAL::VRML_2_ostream os( *p_out);
|
||||
CGAL::File_writer_VRML_2 writer;
|
||||
CGAL::generic_copy_OFF( *p_in, *p_out, writer);
|
||||
if(!os) return EXIT_FAILURE;
|
||||
os.close();
|
||||
}
|
||||
vout << " .... done." << endl;
|
||||
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << " read error: while reading file '"<< iname << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] <<" write error: while writing file '"<< oname << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// EOF //
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
// Convert from OFF format to Wavefront (.obj) format.
|
||||
|
||||
#include <CGAL/IO/Verbose_ostream.h>
|
||||
#include <CGAL/IO/File_writer_wavefront.h>
|
||||
#include <CGAL/IO/generic_copy_OFF.h>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool verbose = false;
|
||||
|
||||
// main function with standard unix commandline arguments
|
||||
// ------------------------------------------------------
|
||||
int main( int argc, char **argv) {
|
||||
int n = 0; // number of filenames
|
||||
char *filename[2];
|
||||
bool help = false;
|
||||
for (int i = 1; i < argc; i++) { // check commandline options
|
||||
if ( strcmp( "-v", argv[i]) == 0)
|
||||
verbose = true;
|
||||
else if ( (strcmp( "-h", argv[i]) == 0) ||
|
||||
(strcmp( "-help", argv[i]) == 0))
|
||||
help = true;
|
||||
else if ( n < 2 ) {
|
||||
filename[ n++] = argv[i];
|
||||
} else {
|
||||
++n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n > 2) || help) {
|
||||
if ( ! help)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
|
||||
<< endl;
|
||||
cerr << " convert a CGAL object (OFF) to Wavefront obj format."
|
||||
<< endl;
|
||||
cerr << " -v verbose." << endl;
|
||||
exit( ! help);
|
||||
}
|
||||
|
||||
CGAL::Verbose_ostream vout( verbose);
|
||||
vout << argv[0] << ": verbosity on." << endl;
|
||||
|
||||
const char* iname = "cin";
|
||||
istream* p_in = &cin;
|
||||
ifstream in;
|
||||
if ( n > 0) {
|
||||
in.open( filename[0]);
|
||||
p_in = ∈
|
||||
iname = filename[0];
|
||||
}
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< iname
|
||||
<< "' for reading." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
const char* oname = "cout";
|
||||
ostream* p_out = &cout;
|
||||
ofstream out;
|
||||
if ( n > 1) {
|
||||
out.open( filename[1]);
|
||||
p_out = &out;
|
||||
oname = filename[1];
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< oname
|
||||
<< "' for writing." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
vout << "CGAL::generic_copy_OFF( " << iname << ", " << oname
|
||||
<< ") ...." << endl;
|
||||
CGAL::File_writer_wavefront writer;
|
||||
CGAL::generic_copy_OFF( *p_in, *p_out, writer);
|
||||
vout << " .... done." << endl;
|
||||
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << " read error: while reading file '"<< iname << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] <<" write error: while writing file '"<< oname << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// EOF //
|
||||
|
|
@ -1,127 +0,0 @@
|
|||
// computes bbox of an OFF object.
|
||||
|
||||
#include <CGAL/Bbox_3.h>
|
||||
#include <CGAL/IO/Verbose_ostream.h>
|
||||
#include <CGAL/IO/File_scanner_OFF.h>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cfloat>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool verbose = false;
|
||||
bool unitcube = false;
|
||||
|
||||
// main function with standard unix commandline arguments
|
||||
// ------------------------------------------------------
|
||||
int main( int argc, char **argv) {
|
||||
int n = 0; // number of filenames
|
||||
char *filename[1] = { NULL }; // stop compiler warning (too hard to rewrite the code to avoid it)
|
||||
bool help = false;
|
||||
for (int i = 1; i < argc; i++) { // check commandline options
|
||||
if ( strcmp( "-v", argv[i]) == 0)
|
||||
verbose = true;
|
||||
else if ( strcmp( "-unit", argv[i]) == 0)
|
||||
unitcube = true;
|
||||
else if ( (strcmp( "-h", argv[i]) == 0) ||
|
||||
(strcmp( "-help", argv[i]) == 0))
|
||||
help = true;
|
||||
else if ( n < 1 ) {
|
||||
filename[ n++] = argv[i];
|
||||
} else {
|
||||
n++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n > 1) || help) {
|
||||
if ( ! help)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
|
||||
<< endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile>]" << endl;
|
||||
cerr << " computes the bbox of the coordinates of an OFF object."
|
||||
<< endl;
|
||||
cerr << " -unit prints transformation to unit cube." << endl;
|
||||
cerr << " (can be used with 'off_transform')" << endl;
|
||||
cerr << " -v verbose." << endl;
|
||||
exit( ! help);
|
||||
}
|
||||
|
||||
CGAL::Verbose_ostream verr( verbose);
|
||||
verr << argv[0] << ": verbosity on." << endl;
|
||||
|
||||
const char* name = "cin";
|
||||
istream* p_in = &cin;
|
||||
ifstream in;
|
||||
if ( n > 0) {
|
||||
in.open( filename[0]);
|
||||
p_in = ∈
|
||||
name = filename[0];
|
||||
}
|
||||
if ( ! * p_in) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< name
|
||||
<< "' for reading." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
verr << "CGAL::File_scanner_OFF( " << name << ") ...." << endl;
|
||||
CGAL::File_scanner_OFF scanner( * p_in);
|
||||
if ( ! * p_in) {
|
||||
cerr << argv[0] << ": error: file '"<< name
|
||||
<< "' is not in OFF format." << endl;
|
||||
std::abort();
|
||||
}
|
||||
if ( scanner.size_of_vertices() <= 0) {
|
||||
cerr << argv[0] << ": error: file '"<< name
|
||||
<< "' has no vertices." << endl;
|
||||
std::abort();
|
||||
}
|
||||
size_t v = scanner.size_of_vertices();
|
||||
CGAL::Bbox_3 bbox;
|
||||
double x, y, z;
|
||||
scanner.scan_vertex( x, y, z);
|
||||
bbox = CGAL::Bbox_3( x,y,z, x,y,z);
|
||||
v--;
|
||||
while (v--) {
|
||||
scanner.scan_vertex( x, y, z);
|
||||
bbox = bbox + CGAL::Bbox_3( x,y,z, x,y,z);
|
||||
scanner.skip_to_next_vertex( scanner.size_of_vertices() - v - 1);
|
||||
}
|
||||
verr << ".... done." << scanner.size_of_vertices() << " points read."
|
||||
<< endl;
|
||||
|
||||
if ( !in) {
|
||||
cerr << argv[0] << " read error: while reading file '"<< name << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
if ( ! unitcube) {
|
||||
cout << bbox.xmin() << " " << bbox.ymin() << " " << bbox.zmin()
|
||||
<< '\n';
|
||||
cout << bbox.xmax() << " " << bbox.ymax() << " " << bbox.zmax()
|
||||
<< endl;
|
||||
} else {
|
||||
double s = DBL_MAX;
|
||||
double d = bbox.xmax() - bbox.xmin();
|
||||
if ( d > 0 && 2/d < s)
|
||||
s = 2/d;
|
||||
d = bbox.ymax() - bbox.ymin();
|
||||
if ( d > 0 && 2/d < s)
|
||||
s = 2/d;
|
||||
d = bbox.zmax() - bbox.zmin();
|
||||
if ( d > 0 && 2/d < s)
|
||||
s = 2/d;
|
||||
if ( s == DBL_MAX)
|
||||
s = 1;
|
||||
cout << "-trans " << (-(bbox.xmin() + bbox.xmax())/2)
|
||||
<< " " << (-(bbox.ymin() + bbox.ymax())/2)
|
||||
<< " " << (-(bbox.zmin() + bbox.zmax())/2)
|
||||
<< " -scale " << s << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// EOF //
|
||||
|
|
@ -1,206 +0,0 @@
|
|||
// Glue vertices of a polyhedron together that have equal coordinate values.
|
||||
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/IO/Verbose_ostream.h>
|
||||
#include <CGAL/IO/File_scanner_OFF.h>
|
||||
#include <CGAL/IO/File_writer_OFF.h>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef Kernel::Vector_3 Vector;
|
||||
struct Vertex {
|
||||
Point point;
|
||||
Vector normal;
|
||||
int index;
|
||||
};
|
||||
typedef vector<Vertex> Vertex_vector;
|
||||
typedef Vertex_vector::iterator VIterator;
|
||||
|
||||
struct VertexComp {
|
||||
bool operator()( const Vertex* v, const Vertex* w) const {
|
||||
return ( v->point.x() < w->point.x() ||
|
||||
(v->point.x() == w->point.x() && v->point.y() < w->point.y()) ||
|
||||
(v->point.x() == w->point.x() && (v->point.y() == w->point.y()
|
||||
&& v->point.z() < w->point.z())));
|
||||
}
|
||||
};
|
||||
|
||||
bool verbose = false;
|
||||
bool binary = false;
|
||||
bool skel = false;
|
||||
bool noc = false;
|
||||
|
||||
// main function with standard unix commandline arguments
|
||||
// ------------------------------------------------------
|
||||
int main( int argc, char **argv) {
|
||||
int n = 0; // number of filenames
|
||||
char *filename[2];
|
||||
bool help = false;
|
||||
for (int i=1 ; i < argc; i++) { // check commandline options
|
||||
if ( strcmp( "-v", argv[i]) == 0)
|
||||
verbose = true;
|
||||
else if ( strcmp( "-b", argv[i]) == 0)
|
||||
binary = true;
|
||||
else if ( strcmp( "-skel", argv[i]) == 0)
|
||||
skel = true;
|
||||
else if ( strcmp( "-noc", argv[i]) == 0)
|
||||
noc = true;
|
||||
else if ( (strcmp( "-h", argv[i]) == 0) ||
|
||||
(strcmp( "-help", argv[i]) == 0))
|
||||
help = true;
|
||||
else if ( n < 2 ) {
|
||||
filename[ n++] = argv[i];
|
||||
} else {
|
||||
++n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n > 2) || help) {
|
||||
if ( ! help)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
|
||||
<< endl;
|
||||
cerr << " glues vertices of equal coordinates together." << endl;
|
||||
cerr << " -b binary output (default is ASCII)." << endl;
|
||||
cerr << " -skel Geomview SKEL format." << endl;
|
||||
cerr << " -noc no comments in file." << endl;
|
||||
cerr << " -v verbose." << endl;
|
||||
exit( ! help);
|
||||
}
|
||||
|
||||
CGAL::Verbose_ostream vout( verbose);
|
||||
vout << argv[0] << ": verbosity on." << endl;
|
||||
|
||||
const char* name = "<cin>";
|
||||
istream* p_in = &cin;
|
||||
ifstream in;
|
||||
if ( n > 0) {
|
||||
in.open( filename[0]);
|
||||
p_in = ∈
|
||||
name = filename[0];
|
||||
}
|
||||
if ( !in) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< name
|
||||
<< "' for reading." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
CGAL::File_scanner_OFF scanner( * p_in);
|
||||
if ( ! (*p_in)) {
|
||||
cerr << " " << endl;
|
||||
cerr << argv[0] << ": input error: file format is not in OFF." << endl;
|
||||
std::abort();
|
||||
}
|
||||
Vertex_vector vertices;
|
||||
vector<Vertex*> sorted_vertices;
|
||||
// Avoid any reallocation
|
||||
vertices.reserve( scanner.size_of_vertices());
|
||||
sorted_vertices.reserve( scanner.size_of_vertices());
|
||||
|
||||
float x, y, z;
|
||||
for (std::size_t i = 0; i < scanner.size_of_vertices(); i++) {
|
||||
Vertex vertex;
|
||||
scanner.scan_vertex( x, y, z);
|
||||
vertex.point = Point( x, y, z);
|
||||
//scanner.scan_normal( x, y, z);
|
||||
vertex.normal = Vector( x, y, z);
|
||||
scanner.skip_to_next_vertex( i);
|
||||
vertex.index = -1;
|
||||
vertices.push_back( vertex);
|
||||
sorted_vertices.push_back( & vertices.back());
|
||||
}
|
||||
vout << scanner.size_of_vertices() << " vertices read." << endl;
|
||||
|
||||
sort( sorted_vertices.begin(), sorted_vertices.end(), VertexComp());
|
||||
int current_index = 0;
|
||||
sorted_vertices[0]->index = 0;
|
||||
for (std::size_t i = 1; i < scanner.size_of_vertices(); i++) {
|
||||
if ( sorted_vertices[i]->point != sorted_vertices[i-1]->point)
|
||||
current_index++;
|
||||
sorted_vertices[i]->index = current_index;
|
||||
}
|
||||
current_index++;
|
||||
vout << "Merged to " << current_index << " vertices." << endl;
|
||||
|
||||
const char* oname = "<cout>";
|
||||
ostream* p_out = &cout;
|
||||
ofstream out;
|
||||
if ( n > 1) {
|
||||
out.open( filename[1]);
|
||||
p_out = &out;
|
||||
oname = filename[1];
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< oname
|
||||
<< "' for writing." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
vout << "CGAL::File_writer_OFF( " << (binary ? ", binary" : ", ASCII")
|
||||
<< ") ...." << endl;
|
||||
CGAL::File_header_OFF header( binary, noc, skel, verbose);
|
||||
CGAL::File_writer_OFF writer( header);
|
||||
writer.write_header(*p_out,
|
||||
current_index,
|
||||
0,
|
||||
scanner.size_of_facets(),
|
||||
scanner.has_normals());
|
||||
vector<Vertex*>::iterator v = sorted_vertices.begin();
|
||||
writer.write_vertex((*v)->point.x(), (*v)->point.y(), (*v)->point.z());
|
||||
if ( scanner.has_normals()) {
|
||||
writer.write_normal((*v)->normal.x(),
|
||||
(*v)->normal.y(),
|
||||
(*v)->normal.z());
|
||||
}
|
||||
++v;
|
||||
for ( ; v != sorted_vertices.end(); ++v) {
|
||||
if ( (*v)->index != (*(v-1))->index) {
|
||||
writer.write_vertex( (*v)->point.x(),
|
||||
(*v)->point.y(),
|
||||
(*v)->point.z());
|
||||
if ( scanner.has_normals()) {
|
||||
writer.write_normal( (*v)->normal.x(),
|
||||
(*v)->normal.y(),
|
||||
(*v)->normal.z());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy facets and translate vertex indices.
|
||||
writer.write_facet_header();
|
||||
for (std::size_t i = 0; i < scanner.size_of_facets(); i++) {
|
||||
std::size_t no; // number of vertices of a facet.
|
||||
scanner.scan_facet( no, i);
|
||||
writer.write_facet_begin( no);
|
||||
for ( std::size_t j = 0; j < no; j++) {
|
||||
std::size_t index;
|
||||
scanner.scan_facet_vertex_index( index, i);
|
||||
writer.write_facet_vertex_index( vertices[index].index);
|
||||
}
|
||||
scanner.skip_to_next_facet( i);
|
||||
writer.write_facet_end();
|
||||
}
|
||||
writer.write_footer();
|
||||
vout << " .... done." << endl;
|
||||
|
||||
if ( ! * p_in) {
|
||||
cerr << argv[0] << " read error: while reading file '"<< name << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << " write error: while writing file '"<< oname
|
||||
<< "'." << endl;
|
||||
exit( 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,164 +0,0 @@
|
|||
// Applies translation and scaling to an OFF object.
|
||||
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/IO/Verbose_ostream.h>
|
||||
#include <CGAL/IO/File_scanner_OFF.h>
|
||||
#include <CGAL/IO/File_writer_OFF.h>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef Kernel::Vector_3 Vector;
|
||||
|
||||
bool verbose = false;
|
||||
bool binary = false;
|
||||
bool skel = false;
|
||||
bool noc = false;
|
||||
|
||||
double transx = 0.0;
|
||||
double transy = 0.0;
|
||||
double transz = 0.0;
|
||||
double scale = 1.0;
|
||||
|
||||
// main function with standard unix commandline arguments
|
||||
// ------------------------------------------------------
|
||||
int main( int argc, char **argv) {
|
||||
int n = 0; // number of filenames
|
||||
char *filename[2];
|
||||
bool help = false;
|
||||
for (int i = 1; i < argc; i++) { // check commandline options
|
||||
if ( strcmp( "-v", argv[i]) == 0)
|
||||
verbose = true;
|
||||
else if ( strcmp( "-b", argv[i]) == 0)
|
||||
binary = true;
|
||||
else if ( strcmp( "-skel", argv[i]) == 0)
|
||||
skel = true;
|
||||
else if ( strcmp( "-noc", argv[i]) == 0)
|
||||
noc = true;
|
||||
else if ( strcmp( "-scale", argv[i]) == 0) {
|
||||
i++;
|
||||
if ( i < argc) {
|
||||
scale = atof( argv[i]);
|
||||
} else {
|
||||
cerr << argv[0] << ": error: -scale needs a double parameter."
|
||||
<< endl;
|
||||
help = true;
|
||||
}
|
||||
} else if ( strcmp( "-trans", argv[i]) == 0) {
|
||||
i++;
|
||||
if ( i+2 < argc) {
|
||||
transx = atof( argv[i]);
|
||||
i++;
|
||||
transy = atof( argv[i]);
|
||||
i++;
|
||||
transz = atof( argv[i]);
|
||||
} else {
|
||||
cerr << argv[0] << ": error: -trans needs three double "
|
||||
"parameters." << endl;
|
||||
help = true;
|
||||
}
|
||||
} else if ( (strcmp( "-h", argv[i]) == 0) ||
|
||||
(strcmp( "-help", argv[i]) == 0))
|
||||
help = true;
|
||||
else if ( n < 2 ) {
|
||||
filename[ n++] = argv[i];
|
||||
} else {
|
||||
++n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n > 2) || help) {
|
||||
if ( ! help)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
|
||||
<< endl;
|
||||
cerr << " transforms coordinate values of an OFF object."
|
||||
<< endl;
|
||||
cerr << " -trans <x> <y> <y> translation." << endl;
|
||||
cerr << " -scale <s> uniform scaling." << endl;
|
||||
cerr << " -b binary (default is ASCII)."
|
||||
<< endl;
|
||||
cerr << " -skel Geomview SKEL format." << endl;
|
||||
cerr << " -noc no comments in file." << endl;
|
||||
cerr << " -v verbose." << endl;
|
||||
exit( ! help);
|
||||
}
|
||||
|
||||
CGAL::Verbose_ostream verr( verbose);
|
||||
verr << argv[0] << ": verbosity on." << endl;
|
||||
|
||||
const char* name = "cin";
|
||||
istream* p_in = &cin;
|
||||
ifstream in;
|
||||
if ( n > 0) {
|
||||
in.open( filename[0]);
|
||||
p_in = ∈
|
||||
name = filename[0];
|
||||
}
|
||||
if ( ! * p_in) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< name
|
||||
<< "' for reading." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
verr << "CGAL::File_scanner_OFF( " << name << ") ...." << endl;
|
||||
CGAL::File_scanner_OFF scanner( * p_in);
|
||||
if ( ! * p_in) {
|
||||
cerr << argv[0] << ": error: file '"<< name
|
||||
<< "' is not in OFF format." << endl;
|
||||
std::abort();
|
||||
}
|
||||
verr << "CGAL::File_writer_OFF( ..." << endl;
|
||||
const char* oname = "cout";
|
||||
ostream* p_out = &cout;
|
||||
ofstream out;
|
||||
if ( n > 1) {
|
||||
out.open( filename[1]);
|
||||
p_out = &out;
|
||||
oname = filename[1];
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< oname
|
||||
<< "' for writing." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
CGAL::File_header_OFF header( binary, noc, skel, verbose);
|
||||
CGAL::File_writer_OFF writer( header);
|
||||
writer.write_header( * p_out,
|
||||
scanner.size_of_vertices(),
|
||||
scanner.size_of_halfedges(),
|
||||
scanner.size_of_facets());
|
||||
|
||||
Vector v( transx, transy, transz);
|
||||
for ( std::size_t k = 0; k < scanner.size_of_vertices(); ++k) {
|
||||
double x, y, z;
|
||||
scanner.scan_vertex( x, y, z);
|
||||
Point q( x, y, z);
|
||||
q = q + v;
|
||||
q = CGAL::ORIGIN + ( (q - CGAL::ORIGIN) * scale );
|
||||
scanner.skip_to_next_vertex( k);
|
||||
writer.write_vertex( q.x(), q.y(), q.z());
|
||||
}
|
||||
verr << " .... done." << scanner.size_of_vertices() << " points read."
|
||||
<< endl;
|
||||
|
||||
if ( ! *p_in) {
|
||||
cerr << argv[0] << " read error: while reading file '"<< name << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
writer.write_facet_header();
|
||||
* p_out << endl;
|
||||
char c;
|
||||
while ( (*p_in).get(c))
|
||||
* p_out << c;
|
||||
return 0;
|
||||
}
|
||||
// EOF //
|
||||
|
|
@ -27,6 +27,16 @@ if ( CGAL_FOUND )
|
|||
create_single_source_cgal_program( "read_WKT.cpp" )
|
||||
|
||||
create_single_source_cgal_program( "read_xml.cpp" )
|
||||
|
||||
create_single_source_cgal_program( "iv2off.cpp" )
|
||||
create_single_source_cgal_program( "off2iv.cpp" )
|
||||
create_single_source_cgal_program( "off2off.cpp" )
|
||||
create_single_source_cgal_program( "off2stl.cpp" )
|
||||
create_single_source_cgal_program( "off2vrml.cpp" )
|
||||
create_single_source_cgal_program( "off2wav.cpp" )
|
||||
create_single_source_cgal_program( "off_bbox.cpp" )
|
||||
create_single_source_cgal_program( "off_glue.cpp" )
|
||||
create_single_source_cgal_program( "off_transform.cpp" )
|
||||
|
||||
else ()
|
||||
message(STATUS "This project requires the CGAL library, and will not be compiled.")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,100 @@
|
|||
// Convert from OFF format to OpenInventor (.iv) format.
|
||||
|
||||
#include <CGAL/IO/Verbose_ostream.h>
|
||||
#include <CGAL/IO/Inventor_ostream.h>
|
||||
#include <CGAL/IO/File_writer_inventor.h>
|
||||
#include <CGAL/IO/generic_copy_OFF.h>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool dummy_switch = false;
|
||||
bool verbose = false;
|
||||
|
||||
// main function with standard unix commandline arguments
|
||||
// ------------------------------------------------------
|
||||
int main( int argc, char **argv) {
|
||||
int n = 0; // number of filenames
|
||||
char *filename[2];
|
||||
bool help = false;
|
||||
for (int i = 1; i < argc; i++) { // check commandline options
|
||||
if ( strcmp( "-v", argv[i]) == 0)
|
||||
verbose = true;
|
||||
else if ( (strcmp( "-h", argv[i]) == 0) ||
|
||||
(strcmp( "-help", argv[i]) == 0))
|
||||
help = true;
|
||||
else if ( n < 2 ) {
|
||||
filename[ n++] = argv[i];
|
||||
} else {
|
||||
++n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n > 2) || help) {
|
||||
if ( ! help)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
|
||||
<< endl;
|
||||
cerr << " convert a CGAL object (OFF) to Open Inventor .iv "
|
||||
"format." << endl;
|
||||
cerr << " -v verbose." << endl;
|
||||
exit( ! help);
|
||||
}
|
||||
|
||||
CGAL::Verbose_ostream vout( verbose);
|
||||
vout << argv[0] << ": verbosity on." << endl;
|
||||
|
||||
const char* iname = "cin";
|
||||
istream* p_in = &cin;
|
||||
ifstream in;
|
||||
if ( n > 0) {
|
||||
in.open( filename[0]);
|
||||
p_in = ∈
|
||||
iname = filename[0];
|
||||
}
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< iname
|
||||
<< "' for reading." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
const char* oname = "cout";
|
||||
ostream* p_out = &cout;
|
||||
ofstream out;
|
||||
if ( n > 1) {
|
||||
out.open( filename[1]);
|
||||
p_out = &out;
|
||||
oname = filename[1];
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< oname
|
||||
<< "' for writing." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
vout << "CGAL::generic_copy_OFF( " << iname << ", " << oname
|
||||
<< ") ...." << endl;
|
||||
CGAL::Inventor_ostream os( *p_out);
|
||||
CGAL::File_writer_inventor writer;
|
||||
CGAL::generic_copy_OFF( *p_in, *p_out, writer);
|
||||
if(!os) return EXIT_FAILURE;
|
||||
os.close();
|
||||
vout << " .... done." << endl;
|
||||
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << " read error: while reading file '"
|
||||
<< iname << "'." << endl;
|
||||
exit( 1);
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << " write error: while writing file '"
|
||||
<< oname << "'." << endl;
|
||||
exit( 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// EOF //
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
// Copies a file in OFF format.
|
||||
|
||||
#include <CGAL/IO/Verbose_ostream.h>
|
||||
#include <CGAL/IO/File_writer_OFF.h>
|
||||
#include <CGAL/IO/generic_copy_OFF.h>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool verbose = false;
|
||||
bool binary = false;
|
||||
bool skel = false;
|
||||
bool noc = false;
|
||||
|
||||
// main function with standard unix commandline arguments
|
||||
// ------------------------------------------------------
|
||||
int main( int argc, char **argv) {
|
||||
int n = 0; // number of filenames
|
||||
char *filename[2];
|
||||
bool help = false;
|
||||
for (int i = 1; i < argc; i++) { // check commandline options
|
||||
if ( strcmp( "-v", argv[i]) == 0)
|
||||
verbose = true;
|
||||
else if ( strcmp( "-b", argv[i]) == 0)
|
||||
binary = true;
|
||||
else if ( strcmp( "-skel", argv[i]) == 0)
|
||||
skel = true;
|
||||
else if ( strcmp( "-noc", argv[i]) == 0)
|
||||
noc = true;
|
||||
else if ( (strcmp( "-h", argv[i]) == 0) ||
|
||||
(strcmp( "-help", argv[i]) == 0))
|
||||
help = true;
|
||||
else if ( n < 2 ) {
|
||||
filename[ n++] = argv[i];
|
||||
} else {
|
||||
++n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n > 2) || help) {
|
||||
if ( ! help)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
|
||||
<< endl;
|
||||
cerr << " copy an object in OFF." << endl;
|
||||
cerr << " -b binary (default is ASCII)." << endl;
|
||||
cerr << " -skel Geomview SKEL format." << endl;
|
||||
cerr << " -noc no comments in file." << endl;
|
||||
cerr << " -v verbose." << endl;
|
||||
exit( ! help);
|
||||
}
|
||||
|
||||
CGAL::Verbose_ostream vout( verbose);
|
||||
vout << argv[0] << ": verbosity on." << endl;
|
||||
|
||||
const char* iname = "cin";
|
||||
istream* p_in = &cin;
|
||||
ifstream in;
|
||||
if ( n > 0) {
|
||||
in.open( filename[0]);
|
||||
p_in = ∈
|
||||
iname = filename[0];
|
||||
}
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< iname
|
||||
<< "' for reading." << endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
const char* oname = "cout";
|
||||
ostream* p_out = &cout;
|
||||
ofstream out;
|
||||
if ( n > 1) {
|
||||
out.open( filename[1]);
|
||||
p_out = &out;
|
||||
oname = filename[1];
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< oname
|
||||
<< "' for writing." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
vout << "CGAL::generic_copy_OFF( " << iname << ", " << oname
|
||||
<< (binary ? ", binary" : ", ASCII") << ") ...." << endl;
|
||||
CGAL::File_header_OFF header( binary, noc, skel, verbose);
|
||||
CGAL::File_writer_OFF writer( header);
|
||||
CGAL::generic_copy_OFF( *p_in, *p_out, writer);
|
||||
vout << " .... done." << endl;
|
||||
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << " read error: while reading file '"
|
||||
<< iname << "'." << endl;
|
||||
exit( 1);
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << " write error: while writing file '"
|
||||
<< oname << "'." << endl;
|
||||
exit( 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// EOF //
|
||||
|
|
@ -0,0 +1,163 @@
|
|||
// Convert from OFF format to StereoLithography StL format.
|
||||
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/IO/Verbose_ostream.h>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool verbose = false;
|
||||
bool binary = false;
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef Kernel::Vector_3 Vector;
|
||||
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
|
||||
typedef Polyhedron::Vertex_iterator Vertex_iterator;
|
||||
typedef Polyhedron::Facet_iterator Facet_iterator;
|
||||
typedef Polyhedron::Halfedge_handle Halfedge_handle;
|
||||
|
||||
|
||||
// main function with standard unix commandline arguments
|
||||
// ------------------------------------------------------
|
||||
int main( int argc, char **argv) {
|
||||
int n = 0; // number of filenames
|
||||
char *filename[2];
|
||||
bool help = false;
|
||||
for (int i = 1; i < argc; i++) { // check commandline options
|
||||
if ( strcmp( "-v", argv[i]) == 0)
|
||||
verbose = true;
|
||||
else if ( strcmp( "-b", argv[i]) == 0)
|
||||
binary = true;
|
||||
else if ( (strcmp( "-h", argv[i]) == 0) ||
|
||||
(strcmp( "-help", argv[i]) == 0))
|
||||
help = true;
|
||||
else if ( n < 2 ) {
|
||||
filename[ n++] = argv[i];
|
||||
} else {
|
||||
++n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n > 2) || help) {
|
||||
if ( ! help)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
|
||||
<< endl;
|
||||
cerr << " convert a CGAL object (OFF) to StereoLithography StL "
|
||||
"format." << endl;
|
||||
cerr << " -v verbose." << endl;
|
||||
cerr << " -b binary." << endl;
|
||||
exit( ! help);
|
||||
}
|
||||
|
||||
CGAL::Verbose_ostream vout( verbose);
|
||||
vout << argv[0] << ": verbosity on." << endl;
|
||||
|
||||
const char* iname = "cin";
|
||||
istream* p_in = &cin;
|
||||
ifstream in;
|
||||
if ( n > 0) {
|
||||
in.open( filename[0]);
|
||||
p_in = ∈
|
||||
iname = filename[0];
|
||||
}
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< iname
|
||||
<< "' for reading." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
vout << "Reading polyhedron ..." << endl;
|
||||
Polyhedron P;
|
||||
(*p_in) >> P;
|
||||
vout << " .... done." << endl;
|
||||
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << " read error: while reading file '"<< iname << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
const char* oname = "cout";
|
||||
ostream* p_out = &cout;
|
||||
ofstream out;
|
||||
if ( n > 1) {
|
||||
out.open( filename[1]);
|
||||
p_out = &out;
|
||||
oname = filename[1];
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< oname
|
||||
<< "' for writing." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
vout << "Write file ...." << endl;
|
||||
*p_out << "solid " << oname << endl;
|
||||
|
||||
// find "bottom/left/front" corner to translate into positive octant
|
||||
Vertex_iterator vi = P.vertices_begin();
|
||||
Point p = vi->point();
|
||||
double minx = p.x();
|
||||
double miny = p.y();
|
||||
double minz = p.z();
|
||||
for ( ; vi != P.vertices_end(); ++vi) {
|
||||
p = vi->point();
|
||||
if ( p.x() < minx)
|
||||
minx = p.x();
|
||||
if ( p.y() < miny)
|
||||
miny = p.y();
|
||||
if ( p.z() < minz)
|
||||
minz = p.z();
|
||||
}
|
||||
// translate into positive octant
|
||||
Vector trans( -minx, -miny, -minz);
|
||||
for ( Vertex_iterator i = P.vertices_begin(); i != P.vertices_end(); ++i) {
|
||||
i->point() = i->point() + trans;
|
||||
}
|
||||
// write triangles
|
||||
for ( Facet_iterator i = P.facets_begin(); i != P.facets_end(); ++i) {
|
||||
Halfedge_handle h = i->halfedge();
|
||||
if ( h->next()->next()->next() != h) {
|
||||
cerr << argv[0] << " format error: polyhedron in file '"<<
|
||||
iname << "' is not triangulated." << endl;
|
||||
exit( 1);
|
||||
}
|
||||
Point p = h->vertex()->point();
|
||||
Point q = h->next()->vertex()->point();
|
||||
Point r = h->next()->next()->vertex()->point();
|
||||
// compute normal
|
||||
Vector n = CGAL::cross_product( q-p, r-p);
|
||||
Vector norm = n / std::sqrt( n * n);
|
||||
*p_out << " facet normal " << norm << endl;
|
||||
*p_out << " outer loop " << endl;
|
||||
*p_out << " vertex " << p << endl;
|
||||
*p_out << " vertex " << q << endl;
|
||||
*p_out << " vertex " << r << endl;
|
||||
*p_out << " endloop " << endl;
|
||||
*p_out << " endfacet " << endl;
|
||||
}
|
||||
|
||||
*p_out << "endsolid " << oname << endl;
|
||||
vout << " .... done." << endl;
|
||||
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << " read error: while reading file '"<< iname << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] <<" write error: while writing file '"<< oname << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// EOF //
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
// Convert from OFF format to VRML (.wrl) 1.0 or 2.0 format.
|
||||
|
||||
#include <CGAL/IO/Verbose_ostream.h>
|
||||
#include <CGAL/IO/VRML_1_ostream.h>
|
||||
#include <CGAL/IO/VRML_2_ostream.h>
|
||||
#include <CGAL/IO/File_writer_inventor.h>
|
||||
#include <CGAL/IO/File_writer_VRML_2.h>
|
||||
#include <CGAL/IO/generic_copy_OFF.h>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool verbose = false;
|
||||
int version = 1;
|
||||
|
||||
// main function with standard unix commandline arguments
|
||||
// ------------------------------------------------------
|
||||
int main( int argc, char **argv) {
|
||||
int n = 0; // number of filenames
|
||||
char *filename[2];
|
||||
bool help = false;
|
||||
for (int i = 1; i < argc; i++) { // check commandline options
|
||||
if ( strcmp( "-v", argv[i]) == 0)
|
||||
verbose = true;
|
||||
else if ( strcmp( "-2", argv[i]) == 0)
|
||||
version = 2;
|
||||
else if ( (strcmp( "-h", argv[i]) == 0) ||
|
||||
(strcmp( "-help", argv[i]) == 0))
|
||||
help = true;
|
||||
else if ( n < 2 ) {
|
||||
filename[ n++] = argv[i];
|
||||
} else {
|
||||
++n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n > 2) || help) {
|
||||
if ( ! help)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
|
||||
<< endl;
|
||||
cerr << " convert a CGAL object (OFF) to VRML .wrl format."
|
||||
<< endl;
|
||||
cerr << " -2 VRML 2.0 (default is VRML 1.0)." << endl;
|
||||
cerr << " -v verbose." << endl;
|
||||
exit( ! help);
|
||||
}
|
||||
|
||||
CGAL::Verbose_ostream vout( verbose);
|
||||
vout << argv[0] << ": verbosity on." << endl;
|
||||
|
||||
const char* iname = "cin";
|
||||
istream* p_in = &cin;
|
||||
ifstream in;
|
||||
if ( n > 0) {
|
||||
in.open( filename[0]);
|
||||
p_in = ∈
|
||||
iname = filename[0];
|
||||
}
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< iname
|
||||
<< "' for reading." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
const char* oname = "cout";
|
||||
ostream* p_out = &cout;
|
||||
ofstream out;
|
||||
if ( n > 1) {
|
||||
out.open( filename[1]);
|
||||
p_out = &out;
|
||||
oname = filename[1];
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< oname
|
||||
<< "' for writing." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
vout << "CGAL::generic_copy_OFF( " << iname << ", " << oname
|
||||
<< ", V" << version << " ) ...." << endl;
|
||||
if ( version == 1) {
|
||||
CGAL::VRML_1_ostream os( *p_out);
|
||||
CGAL::File_writer_inventor writer;
|
||||
CGAL::generic_copy_OFF( *p_in, *p_out, writer);
|
||||
if(!os) return EXIT_FAILURE;
|
||||
os.close();
|
||||
} else {
|
||||
CGAL::VRML_2_ostream os( *p_out);
|
||||
CGAL::File_writer_VRML_2 writer;
|
||||
CGAL::generic_copy_OFF( *p_in, *p_out, writer);
|
||||
if(!os) return EXIT_FAILURE;
|
||||
os.close();
|
||||
}
|
||||
vout << " .... done." << endl;
|
||||
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << " read error: while reading file '"<< iname << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] <<" write error: while writing file '"<< oname << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// EOF //
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
// Convert from OFF format to Wavefront (.obj) format.
|
||||
|
||||
#include <CGAL/IO/Verbose_ostream.h>
|
||||
#include <CGAL/IO/File_writer_wavefront.h>
|
||||
#include <CGAL/IO/generic_copy_OFF.h>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool verbose = false;
|
||||
|
||||
// main function with standard unix commandline arguments
|
||||
// ------------------------------------------------------
|
||||
int main( int argc, char **argv) {
|
||||
int n = 0; // number of filenames
|
||||
char *filename[2];
|
||||
bool help = false;
|
||||
for (int i = 1; i < argc; i++) { // check commandline options
|
||||
if ( strcmp( "-v", argv[i]) == 0)
|
||||
verbose = true;
|
||||
else if ( (strcmp( "-h", argv[i]) == 0) ||
|
||||
(strcmp( "-help", argv[i]) == 0))
|
||||
help = true;
|
||||
else if ( n < 2 ) {
|
||||
filename[ n++] = argv[i];
|
||||
} else {
|
||||
++n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n > 2) || help) {
|
||||
if ( ! help)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
|
||||
<< endl;
|
||||
cerr << " convert a CGAL object (OFF) to Wavefront obj format."
|
||||
<< endl;
|
||||
cerr << " -v verbose." << endl;
|
||||
exit( ! help);
|
||||
}
|
||||
|
||||
CGAL::Verbose_ostream vout( verbose);
|
||||
vout << argv[0] << ": verbosity on." << endl;
|
||||
|
||||
const char* iname = "cin";
|
||||
istream* p_in = &cin;
|
||||
ifstream in;
|
||||
if ( n > 0) {
|
||||
in.open( filename[0]);
|
||||
p_in = ∈
|
||||
iname = filename[0];
|
||||
}
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< iname
|
||||
<< "' for reading." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
const char* oname = "cout";
|
||||
ostream* p_out = &cout;
|
||||
ofstream out;
|
||||
if ( n > 1) {
|
||||
out.open( filename[1]);
|
||||
p_out = &out;
|
||||
oname = filename[1];
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< oname
|
||||
<< "' for writing." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
vout << "CGAL::generic_copy_OFF( " << iname << ", " << oname
|
||||
<< ") ...." << endl;
|
||||
CGAL::File_writer_wavefront writer;
|
||||
CGAL::generic_copy_OFF( *p_in, *p_out, writer);
|
||||
vout << " .... done." << endl;
|
||||
|
||||
if ( !*p_in) {
|
||||
cerr << argv[0] << " read error: while reading file '"<< iname << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] <<" write error: while writing file '"<< oname << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// EOF //
|
||||
|
|
@ -0,0 +1,127 @@
|
|||
// computes bbox of an OFF object.
|
||||
|
||||
#include <CGAL/Bbox_3.h>
|
||||
#include <CGAL/IO/Verbose_ostream.h>
|
||||
#include <CGAL/IO/File_scanner_OFF.h>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cfloat>
|
||||
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool verbose = false;
|
||||
bool unitcube = false;
|
||||
|
||||
// main function with standard unix commandline arguments
|
||||
// ------------------------------------------------------
|
||||
int main( int argc, char **argv) {
|
||||
int n = 0; // number of filenames
|
||||
char *filename[1] = { NULL }; // stop compiler warning (too hard to rewrite the code to avoid it)
|
||||
bool help = false;
|
||||
for (int i = 1; i < argc; i++) { // check commandline options
|
||||
if ( strcmp( "-v", argv[i]) == 0)
|
||||
verbose = true;
|
||||
else if ( strcmp( "-unit", argv[i]) == 0)
|
||||
unitcube = true;
|
||||
else if ( (strcmp( "-h", argv[i]) == 0) ||
|
||||
(strcmp( "-help", argv[i]) == 0))
|
||||
help = true;
|
||||
else if ( n < 1 ) {
|
||||
filename[ n++] = argv[i];
|
||||
} else {
|
||||
n++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n > 1) || help) {
|
||||
if ( ! help)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
|
||||
<< endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile>]" << endl;
|
||||
cerr << " computes the bbox of the coordinates of an OFF object."
|
||||
<< endl;
|
||||
cerr << " -unit prints transformation to unit cube." << endl;
|
||||
cerr << " (can be used with 'off_transform')" << endl;
|
||||
cerr << " -v verbose." << endl;
|
||||
exit( ! help);
|
||||
}
|
||||
|
||||
CGAL::Verbose_ostream verr( verbose);
|
||||
verr << argv[0] << ": verbosity on." << endl;
|
||||
|
||||
const char* name = "cin";
|
||||
istream* p_in = &cin;
|
||||
ifstream in;
|
||||
if ( n > 0) {
|
||||
in.open( filename[0]);
|
||||
p_in = ∈
|
||||
name = filename[0];
|
||||
}
|
||||
if ( ! * p_in) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< name
|
||||
<< "' for reading." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
verr << "CGAL::File_scanner_OFF( " << name << ") ...." << endl;
|
||||
CGAL::File_scanner_OFF scanner( * p_in);
|
||||
if ( ! * p_in) {
|
||||
cerr << argv[0] << ": error: file '"<< name
|
||||
<< "' is not in OFF format." << endl;
|
||||
std::abort();
|
||||
}
|
||||
if ( scanner.size_of_vertices() <= 0) {
|
||||
cerr << argv[0] << ": error: file '"<< name
|
||||
<< "' has no vertices." << endl;
|
||||
std::abort();
|
||||
}
|
||||
size_t v = scanner.size_of_vertices();
|
||||
CGAL::Bbox_3 bbox;
|
||||
double x, y, z;
|
||||
scanner.scan_vertex( x, y, z);
|
||||
bbox = CGAL::Bbox_3( x,y,z, x,y,z);
|
||||
v--;
|
||||
while (v--) {
|
||||
scanner.scan_vertex( x, y, z);
|
||||
bbox = bbox + CGAL::Bbox_3( x,y,z, x,y,z);
|
||||
scanner.skip_to_next_vertex( scanner.size_of_vertices() - v - 1);
|
||||
}
|
||||
verr << ".... done." << scanner.size_of_vertices() << " points read."
|
||||
<< endl;
|
||||
|
||||
if ( !in) {
|
||||
cerr << argv[0] << " read error: while reading file '"<< name << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
if ( ! unitcube) {
|
||||
cout << bbox.xmin() << " " << bbox.ymin() << " " << bbox.zmin()
|
||||
<< '\n';
|
||||
cout << bbox.xmax() << " " << bbox.ymax() << " " << bbox.zmax()
|
||||
<< endl;
|
||||
} else {
|
||||
double s = DBL_MAX;
|
||||
double d = bbox.xmax() - bbox.xmin();
|
||||
if ( d > 0 && 2/d < s)
|
||||
s = 2/d;
|
||||
d = bbox.ymax() - bbox.ymin();
|
||||
if ( d > 0 && 2/d < s)
|
||||
s = 2/d;
|
||||
d = bbox.zmax() - bbox.zmin();
|
||||
if ( d > 0 && 2/d < s)
|
||||
s = 2/d;
|
||||
if ( s == DBL_MAX)
|
||||
s = 1;
|
||||
cout << "-trans " << (-(bbox.xmin() + bbox.xmax())/2)
|
||||
<< " " << (-(bbox.ymin() + bbox.ymax())/2)
|
||||
<< " " << (-(bbox.zmin() + bbox.zmax())/2)
|
||||
<< " -scale " << s << endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
// EOF //
|
||||
|
|
@ -0,0 +1,206 @@
|
|||
// Glue vertices of a polyhedron together that have equal coordinate values.
|
||||
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/IO/Verbose_ostream.h>
|
||||
#include <CGAL/IO/File_scanner_OFF.h>
|
||||
#include <CGAL/IO/File_writer_OFF.h>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef Kernel::Vector_3 Vector;
|
||||
struct Vertex {
|
||||
Point point;
|
||||
Vector normal;
|
||||
int index;
|
||||
};
|
||||
typedef vector<Vertex> Vertex_vector;
|
||||
typedef Vertex_vector::iterator VIterator;
|
||||
|
||||
struct VertexComp {
|
||||
bool operator()( const Vertex* v, const Vertex* w) const {
|
||||
return ( v->point.x() < w->point.x() ||
|
||||
(v->point.x() == w->point.x() && v->point.y() < w->point.y()) ||
|
||||
(v->point.x() == w->point.x() && (v->point.y() == w->point.y()
|
||||
&& v->point.z() < w->point.z())));
|
||||
}
|
||||
};
|
||||
|
||||
bool verbose = false;
|
||||
bool binary = false;
|
||||
bool skel = false;
|
||||
bool noc = false;
|
||||
|
||||
// main function with standard unix commandline arguments
|
||||
// ------------------------------------------------------
|
||||
int main( int argc, char **argv) {
|
||||
int n = 0; // number of filenames
|
||||
char *filename[2];
|
||||
bool help = false;
|
||||
for (int i=1 ; i < argc; i++) { // check commandline options
|
||||
if ( strcmp( "-v", argv[i]) == 0)
|
||||
verbose = true;
|
||||
else if ( strcmp( "-b", argv[i]) == 0)
|
||||
binary = true;
|
||||
else if ( strcmp( "-skel", argv[i]) == 0)
|
||||
skel = true;
|
||||
else if ( strcmp( "-noc", argv[i]) == 0)
|
||||
noc = true;
|
||||
else if ( (strcmp( "-h", argv[i]) == 0) ||
|
||||
(strcmp( "-help", argv[i]) == 0))
|
||||
help = true;
|
||||
else if ( n < 2 ) {
|
||||
filename[ n++] = argv[i];
|
||||
} else {
|
||||
++n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n > 2) || help) {
|
||||
if ( ! help)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
|
||||
<< endl;
|
||||
cerr << " glues vertices of equal coordinates together." << endl;
|
||||
cerr << " -b binary output (default is ASCII)." << endl;
|
||||
cerr << " -skel Geomview SKEL format." << endl;
|
||||
cerr << " -noc no comments in file." << endl;
|
||||
cerr << " -v verbose." << endl;
|
||||
exit( ! help);
|
||||
}
|
||||
|
||||
CGAL::Verbose_ostream vout( verbose);
|
||||
vout << argv[0] << ": verbosity on." << endl;
|
||||
|
||||
const char* name = "<cin>";
|
||||
istream* p_in = &cin;
|
||||
ifstream in;
|
||||
if ( n > 0) {
|
||||
in.open( filename[0]);
|
||||
p_in = ∈
|
||||
name = filename[0];
|
||||
}
|
||||
if ( !in) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< name
|
||||
<< "' for reading." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
CGAL::File_scanner_OFF scanner( * p_in);
|
||||
if ( ! (*p_in)) {
|
||||
cerr << " " << endl;
|
||||
cerr << argv[0] << ": input error: file format is not in OFF." << endl;
|
||||
std::abort();
|
||||
}
|
||||
Vertex_vector vertices;
|
||||
vector<Vertex*> sorted_vertices;
|
||||
// Avoid any reallocation
|
||||
vertices.reserve( scanner.size_of_vertices());
|
||||
sorted_vertices.reserve( scanner.size_of_vertices());
|
||||
|
||||
float x, y, z;
|
||||
for (std::size_t i = 0; i < scanner.size_of_vertices(); i++) {
|
||||
Vertex vertex;
|
||||
scanner.scan_vertex( x, y, z);
|
||||
vertex.point = Point( x, y, z);
|
||||
//scanner.scan_normal( x, y, z);
|
||||
vertex.normal = Vector( x, y, z);
|
||||
scanner.skip_to_next_vertex( i);
|
||||
vertex.index = -1;
|
||||
vertices.push_back( vertex);
|
||||
sorted_vertices.push_back( & vertices.back());
|
||||
}
|
||||
vout << scanner.size_of_vertices() << " vertices read." << endl;
|
||||
|
||||
sort( sorted_vertices.begin(), sorted_vertices.end(), VertexComp());
|
||||
int current_index = 0;
|
||||
sorted_vertices[0]->index = 0;
|
||||
for (std::size_t i = 1; i < scanner.size_of_vertices(); i++) {
|
||||
if ( sorted_vertices[i]->point != sorted_vertices[i-1]->point)
|
||||
current_index++;
|
||||
sorted_vertices[i]->index = current_index;
|
||||
}
|
||||
current_index++;
|
||||
vout << "Merged to " << current_index << " vertices." << endl;
|
||||
|
||||
const char* oname = "<cout>";
|
||||
ostream* p_out = &cout;
|
||||
ofstream out;
|
||||
if ( n > 1) {
|
||||
out.open( filename[1]);
|
||||
p_out = &out;
|
||||
oname = filename[1];
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< oname
|
||||
<< "' for writing." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
vout << "CGAL::File_writer_OFF( " << (binary ? ", binary" : ", ASCII")
|
||||
<< ") ...." << endl;
|
||||
CGAL::File_header_OFF header( binary, noc, skel, verbose);
|
||||
CGAL::File_writer_OFF writer( header);
|
||||
writer.write_header(*p_out,
|
||||
current_index,
|
||||
0,
|
||||
scanner.size_of_facets(),
|
||||
scanner.has_normals());
|
||||
vector<Vertex*>::iterator v = sorted_vertices.begin();
|
||||
writer.write_vertex((*v)->point.x(), (*v)->point.y(), (*v)->point.z());
|
||||
if ( scanner.has_normals()) {
|
||||
writer.write_normal((*v)->normal.x(),
|
||||
(*v)->normal.y(),
|
||||
(*v)->normal.z());
|
||||
}
|
||||
++v;
|
||||
for ( ; v != sorted_vertices.end(); ++v) {
|
||||
if ( (*v)->index != (*(v-1))->index) {
|
||||
writer.write_vertex( (*v)->point.x(),
|
||||
(*v)->point.y(),
|
||||
(*v)->point.z());
|
||||
if ( scanner.has_normals()) {
|
||||
writer.write_normal( (*v)->normal.x(),
|
||||
(*v)->normal.y(),
|
||||
(*v)->normal.z());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Copy facets and translate vertex indices.
|
||||
writer.write_facet_header();
|
||||
for (std::size_t i = 0; i < scanner.size_of_facets(); i++) {
|
||||
std::size_t no; // number of vertices of a facet.
|
||||
scanner.scan_facet( no, i);
|
||||
writer.write_facet_begin( no);
|
||||
for ( std::size_t j = 0; j < no; j++) {
|
||||
std::size_t index;
|
||||
scanner.scan_facet_vertex_index( index, i);
|
||||
writer.write_facet_vertex_index( vertices[index].index);
|
||||
}
|
||||
scanner.skip_to_next_facet( i);
|
||||
writer.write_facet_end();
|
||||
}
|
||||
writer.write_footer();
|
||||
vout << " .... done." << endl;
|
||||
|
||||
if ( ! * p_in) {
|
||||
cerr << argv[0] << " read error: while reading file '"<< name << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << " write error: while writing file '"<< oname
|
||||
<< "'." << endl;
|
||||
exit( 1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,164 @@
|
|||
// Applies translation and scaling to an OFF object.
|
||||
|
||||
#include <CGAL/Simple_cartesian.h>
|
||||
#include <CGAL/IO/Verbose_ostream.h>
|
||||
#include <CGAL/IO/File_scanner_OFF.h>
|
||||
#include <CGAL/IO/File_writer_OFF.h>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef CGAL::Simple_cartesian<double> Kernel;
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef Kernel::Vector_3 Vector;
|
||||
|
||||
bool verbose = false;
|
||||
bool binary = false;
|
||||
bool skel = false;
|
||||
bool noc = false;
|
||||
|
||||
double transx = 0.0;
|
||||
double transy = 0.0;
|
||||
double transz = 0.0;
|
||||
double scale = 1.0;
|
||||
|
||||
// main function with standard unix commandline arguments
|
||||
// ------------------------------------------------------
|
||||
int main( int argc, char **argv) {
|
||||
int n = 0; // number of filenames
|
||||
char *filename[2];
|
||||
bool help = false;
|
||||
for (int i = 1; i < argc; i++) { // check commandline options
|
||||
if ( strcmp( "-v", argv[i]) == 0)
|
||||
verbose = true;
|
||||
else if ( strcmp( "-b", argv[i]) == 0)
|
||||
binary = true;
|
||||
else if ( strcmp( "-skel", argv[i]) == 0)
|
||||
skel = true;
|
||||
else if ( strcmp( "-noc", argv[i]) == 0)
|
||||
noc = true;
|
||||
else if ( strcmp( "-scale", argv[i]) == 0) {
|
||||
i++;
|
||||
if ( i < argc) {
|
||||
scale = atof( argv[i]);
|
||||
} else {
|
||||
cerr << argv[0] << ": error: -scale needs a double parameter."
|
||||
<< endl;
|
||||
help = true;
|
||||
}
|
||||
} else if ( strcmp( "-trans", argv[i]) == 0) {
|
||||
i++;
|
||||
if ( i+2 < argc) {
|
||||
transx = atof( argv[i]);
|
||||
i++;
|
||||
transy = atof( argv[i]);
|
||||
i++;
|
||||
transz = atof( argv[i]);
|
||||
} else {
|
||||
cerr << argv[0] << ": error: -trans needs three double "
|
||||
"parameters." << endl;
|
||||
help = true;
|
||||
}
|
||||
} else if ( (strcmp( "-h", argv[i]) == 0) ||
|
||||
(strcmp( "-help", argv[i]) == 0))
|
||||
help = true;
|
||||
else if ( n < 2 ) {
|
||||
filename[ n++] = argv[i];
|
||||
} else {
|
||||
++n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((n > 2) || help) {
|
||||
if ( ! help)
|
||||
cerr << "Error: in parameter list" << endl;
|
||||
cerr << "Usage: " << argv[0] << " [<options>] [<infile> [<outfile>]]"
|
||||
<< endl;
|
||||
cerr << " transforms coordinate values of an OFF object."
|
||||
<< endl;
|
||||
cerr << " -trans <x> <y> <y> translation." << endl;
|
||||
cerr << " -scale <s> uniform scaling." << endl;
|
||||
cerr << " -b binary (default is ASCII)."
|
||||
<< endl;
|
||||
cerr << " -skel Geomview SKEL format." << endl;
|
||||
cerr << " -noc no comments in file." << endl;
|
||||
cerr << " -v verbose." << endl;
|
||||
exit( ! help);
|
||||
}
|
||||
|
||||
CGAL::Verbose_ostream verr( verbose);
|
||||
verr << argv[0] << ": verbosity on." << endl;
|
||||
|
||||
const char* name = "cin";
|
||||
istream* p_in = &cin;
|
||||
ifstream in;
|
||||
if ( n > 0) {
|
||||
in.open( filename[0]);
|
||||
p_in = ∈
|
||||
name = filename[0];
|
||||
}
|
||||
if ( ! * p_in) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< name
|
||||
<< "' for reading." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
verr << "CGAL::File_scanner_OFF( " << name << ") ...." << endl;
|
||||
CGAL::File_scanner_OFF scanner( * p_in);
|
||||
if ( ! * p_in) {
|
||||
cerr << argv[0] << ": error: file '"<< name
|
||||
<< "' is not in OFF format." << endl;
|
||||
std::abort();
|
||||
}
|
||||
verr << "CGAL::File_writer_OFF( ..." << endl;
|
||||
const char* oname = "cout";
|
||||
ostream* p_out = &cout;
|
||||
ofstream out;
|
||||
if ( n > 1) {
|
||||
out.open( filename[1]);
|
||||
p_out = &out;
|
||||
oname = filename[1];
|
||||
}
|
||||
if ( !*p_out) {
|
||||
cerr << argv[0] << ": error: cannot open file '"<< oname
|
||||
<< "' for writing." <<endl;
|
||||
exit( 1);
|
||||
}
|
||||
|
||||
CGAL::File_header_OFF header( binary, noc, skel, verbose);
|
||||
CGAL::File_writer_OFF writer( header);
|
||||
writer.write_header( * p_out,
|
||||
scanner.size_of_vertices(),
|
||||
scanner.size_of_halfedges(),
|
||||
scanner.size_of_facets());
|
||||
|
||||
Vector v( transx, transy, transz);
|
||||
for ( std::size_t k = 0; k < scanner.size_of_vertices(); ++k) {
|
||||
double x, y, z;
|
||||
scanner.scan_vertex( x, y, z);
|
||||
Point q( x, y, z);
|
||||
q = q + v;
|
||||
q = CGAL::ORIGIN + ( (q - CGAL::ORIGIN) * scale );
|
||||
scanner.skip_to_next_vertex( k);
|
||||
writer.write_vertex( q.x(), q.y(), q.z());
|
||||
}
|
||||
verr << " .... done." << scanner.size_of_vertices() << " points read."
|
||||
<< endl;
|
||||
|
||||
if ( ! *p_in) {
|
||||
cerr << argv[0] << " read error: while reading file '"<< name << "'."
|
||||
<< endl;
|
||||
exit( 1);
|
||||
}
|
||||
writer.write_facet_header();
|
||||
* p_out << endl;
|
||||
char c;
|
||||
while ( (*p_in).get(c))
|
||||
* p_out << c;
|
||||
return 0;
|
||||
}
|
||||
// EOF //
|
||||
Loading…
Reference in New Issue