Put (almost) the entire example code in the user manual (as requested by MK)

This commit is contained in:
Laurent Saboret 2006-03-06 19:23:46 +00:00
parent 1fe35d30e1
commit bf827e4a06
14 changed files with 202 additions and 471 deletions

5
.gitignore vendored
View File

@ -234,8 +234,10 @@ Surface_mesh_parameterization/doc_doxygen
Surface_mesh_parameterization/doc_html
Surface_mesh_parameterization/doc_pdf
Surface_mesh_parameterization/doc_ps
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/*.eps
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/*.kdev*
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/*.ncb
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/*.obj
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/*.suo
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/*_extra.*
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/*_parameterization
@ -244,10 +246,7 @@ Surface_mesh_parameterization/examples/Surface_mesh_parameterization/ProgramOutp
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/data/extras
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/debug
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/error.txt
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/mannequin-devil_floater_circle_taucs_parameterized.eps
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/release
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/rotor_floater_square_opennl_parameterized.obj
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/sphere966_authalic_square_taucs_parameterized.obj
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/test
Surface_mesh_parameterization/test/Surface_mesh_parameterization/*.kdev*
Surface_mesh_parameterization/test/Surface_mesh_parameterization/*.ncb

View File

@ -72,58 +72,10 @@ class in \ccc{polyhedron_ex_parameterization.C} example.
\subsection{Default Parameterization Example}
The code below applies the default parameterization to a
\ccc{Simple_parameterization.C} applies the default parameterization to a
\ccc{Polyhedron_3} mesh (must be a topological disk).
Eventually, it extracts the result from halfedges and prints it.
\begin{ccExampleCode}
// CGAL kernel
typedef CGAL::Cartesian<double> Kernel;
// Mesh true type and parameterization adaptors
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor;
// Defines the error codes
typedef CGAL::Parameterizer_traits_3<Parameterization_polyhedron_adaptor>
Parameterizer;
int main(int argc,char * argv[])
{
Polyhedron mesh;
// read the mesh
...
// The Surface_mesh_parameterization package needs an adaptor to handle Polyhedron_3 meshes
// The mesh must be a topological disk
Parameterization_polyhedron_adaptor mesh_adaptor(&mesh);
// Floater Mean Value Coordinates parameterization
Parameterizer::Error_code err = CGAL::parameterize(&mesh_adaptor);
if (err != Parameterizer::OK)
fprintf(stderr, "\nFATAL ERROR: parameterization error # %d\n", (int)err);
if (err == Parameterizer::OK)
{
// Raw output: dump (u,v) pairs
Polyhedron::Vertex_const_iterator pVertex;
for (pVertex = mesh.vertices_begin();
pVertex != mesh.vertices_end();
pVertex++)
{
// (u,v) pair is stored in any halfedge
double u = mesh_adaptor.info(pVertex->halfedge())->uv().x();
double v = mesh_adaptor.info(pVertex->halfedge())->uv().y();
printf("(u,v) = (%lf,%lf)\n", u, v);
}
}
}
\end{ccExampleCode}
See the complete example in \ccc{Simple_parameterization.C}.
\ccIncludeExampleCode{Surface_mesh_parameterization/Simple_parameterization.C}

View File

@ -17,63 +17,11 @@ thus the output traversal is specific to the way the (u,v) fields are implemente
\subsection{EPS Output Example}
The C++ code below gets the $(u,v)$ fields computed by a
\ccc{Complete_parameterization_example.C} is a complete parameterization
example that outputs the result as an EPS image.
It gets the $(u,v)$ fields computed by a
parameterization method over a \ccc{Polyhedron_3} mesh with a
\ccc{Parameterization_polyhedron_adaptor_3<Polyhedron_3_>} adaptor:
\begin{ccExampleCode}
\ccIncludeExampleCode{Surface_mesh_parameterization/Complete_parameterization_example.C}
// CGAL kernel
typedef CGAL::Cartesian<double> Kernel;
// Mesh true type and parameterization adaptors
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor;
...
// Dump parameterized mesh to an eps file
static bool write_file_eps(const Parameterization_polyhedron_adaptor& mesh_adaptor,
const char *pFilename,
double scale = 500.0)
{
// Get actual mesh from adaptor
const Polyhedron* mesh = mesh_adaptor.get_adapted_mesh();
FILE *pFile = fopen(pFilename,"wt");
...
// Get (u,v) pair of each halfedge (either inner or border)
for (pHalfedge = mesh->halfedges_begin();
pHalfedge != mesh->halfedges_end();
pHalfedge++)
{
double x1 = scale * mesh_adaptor.info(pHalfedge->prev())->uv().x();
double y1 = scale * mesh_adaptor.info(pHalfedge->prev())->uv().y();
double x2 = scale * mesh_adaptor.info(pHalfedge)->uv().x();
double y2 = scale * mesh_adaptor.info(pHalfedge)->uv().y();
fprintf(pFile,"%g %g %g %g E\n",x1,y1,x2,y2);
}
...
fclose(pFile);
}
int main(int argc,char * argv[])
{
Polyhedron mesh;
...
// The Surface_mesh_parameterization package needs an adaptor to handle Polyhedron_3 meshes
Parameterization_polyhedron_adaptor mesh_adaptor(&mesh);
// Parameterization
...
// Write Postscript file
write_file_eps(mesh_adaptor, output_filename);
}
\end{ccExampleCode}
See the complete example in \ccc{Taucs_parameterization.C}.

View File

@ -241,57 +241,48 @@ The associated Border Parameterization method defines only two constraints
\subsection{Discrete Authalic Parameterization Example}
The following C++ code computes a Discrete Authalic parameterization
to a \ccc{Polyhedron_3} mesh:
\ccc{Authalic_parameterization.C} computes a Discrete Authalic parameterization
over a \ccc{Polyhedron_3} mesh.
The differences with the first example \ccc{Simple_parameterization.C} are:
\begin{ccExampleCode}
// CGAL kernel
typedef CGAL::Cartesian<double> Kernel;
#include <CGAL/Discrete_authalic_parameterizer_3.h>
// Mesh true type and parameterization adaptors
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor;
...
//***************************************
// Discrete Authalic Parameterization
//***************************************
typedef CGAL::Discrete_authalic_parameterizer_3<Parameterization_polyhedron_adaptor>
Parameterizer;
Parameterizer;
int main(int argc,char * argv[])
{
Polyhedron mesh;
...
Parameterizer::Error_code err = CGAL::parameterize(mesh_adaptor, Parameterizer());
// The Surface_mesh_parameterization package needs an adaptor to handle Polyhedron_3 meshes
// The mesh must be a topological disk
Parameterization_polyhedron_adaptor mesh_adaptor(&mesh);
// Discrete Authalic Parameterization
Parameterizer::Error_code err = CGAL::parameterize(&mesh_adaptor, Parameterizer());
...
}
...
\end{ccExampleCode}
The complete example is available in
\ccc{Authalic_parameterization.C}.
\subsection{Square Border Arc Length Parameterization Example}
The following C++ code computes a Floater Mean Value Coordinates
parameterization with a Square Border Arc Length parameterization:
\ccc{Square_border_parameterization.C} computes a Floater Mean Value Coordinates
parameterization with a Square Border Arc Length parameterization.
The differences with the first example \ccc{Simple_parameterization.C} are:
\begin{ccExampleCode}
// CGAL kernel
typedef CGAL::Cartesian<double> Kernel;
#include <CGAL/Square_border_parameterizer_3.h>
// Mesh true type and parameterization adaptors
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor;
...
//***************************************
// Floater Mean Value Coordinates parameterization
// with square border
//***************************************
// Square border parameterizer
typedef CGAL::Square_border_arc_length_parameterizer_3<Parameterization_polyhedron_adaptor>
@ -299,24 +290,12 @@ typedef CGAL::Square_border_arc_length_parameterizer_3<Parameterization_polyhedr
// Floater Mean Value Coordinates parameterizer with square border
typedef CGAL::Mean_value_coordinates_parameterizer_3<Parameterization_polyhedron_adaptor,
Border_parameterizer>
Parameterizer;
Border_parameterizer>
Parameterizer;
int main(int argc,char * argv[])
{
Polyhedron mesh;
...
Parameterizer::Error_code err = CGAL::parameterize(mesh_adaptor, Parameterizer());
// The Surface_mesh_parameterization package needs an adaptor to handle Polyhedron_3 meshes
// The mesh must be a topological disk
Parameterization_polyhedron_adaptor mesh_adaptor(&mesh);
// Floater Mean Value Coordinates parameterization
// with a Square Border Arc Length Parameterization
Parameterizer::Error_code err = CGAL::parameterize(&mesh_adaptor, Parameterizer());
...
}
...
\end{ccExampleCode}
See the complete example \ccc{Square_border_parameterization.C}.

View File

@ -31,7 +31,7 @@ solvers.
\ccc{Parameterization_mesh_patch_3<ParameterizationPatchableMesh_3>}
class is responsible for virtually
{\em cutting} a patch to a \ccc{ParameterizationPatchableMesh_3} mesh,
to make it similar ffromt he interface point of view to a topological
to make it similar (from the interface point of view) to a topological
disk with a \ccc{ParameterizationMesh_3} interface.
\ccc{ParameterizationPatchableMesh_3} inherits from concept \ccc{ParameterizationMesh_3},
@ -48,63 +48,8 @@ The \ccc{ParameterizationMesh_3} interface with the Polyhedron is also model of
\subsection{Cutting a Mesh Example}
The code below virtually {\em cuts} a \ccc{Polyhedron_3} mesh to make
it a topological disk, then applies the default parameterization:
\begin{ccExampleCode}
// CGAL kernel
typedef CGAL::Cartesian<double> Kernel;
// Mesh true type and parameterization adaptors
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor;
typedef CGAL::Parameterization_mesh_patch_3<Parameterization_polyhedron_adaptor>
Mesh_patch_polyhedron;
// Parameterizers base class for this kind of mesh
typedef CGAL::Parameterizer_traits_3<Mesh_patch_polyhedron> Parameterizer;
// Type describing a border or seam as a vertex list
typedef std::list<Parameterization_polyhedron_adaptor::Vertex_handle>
Seam;
// If the mesh is a topological disk, extract its longest border,
// else compute a very simple cut to make it homeomorphic to a disk.
// Return the border/seam (empty on error)
static Seam cut_mesh(Parameterization_polyhedron_adaptor* mesh_adaptor)
{
// To be implemented by package user
...
}
int main(int argc,char * argv[])
{
Polyhedron mesh;
...
// The Surface_mesh_parameterization package needs an adaptor to handle Polyhedron_3 meshes
Parameterization_polyhedron_adaptor mesh_adaptor(&mesh);
// The parameterization methods support only meshes that
// are topological disks => we need to compute a "cutting" of the mesh
// that makes it it homeomorphic to a disk
Seam seam = cut_mesh(&mesh_adaptor);
// Create adaptor that virtually "cuts" the mesh following the 'seam' path
Mesh_patch_polyhedron mesh_patch(&mesh_adaptor,
seam.begin(),
seam.end());
// Floater Mean Value Coordinates parameterization
Parameterizer::Error_code err = CGAL::parameterize(&mesh_patch);
...
}
\end{ccExampleCode}
See the complete example in \ccc{Mesh_cutting_parameterization.C}
example.
\ccc{Mesh_cutting_parameterization.C} virtually {\em cuts} a \ccc{Polyhedron_3} mesh
to make it a topological disk, then applies the default parameterization:
\ccIncludeExampleCode{Surface_mesh_parameterization/Mesh_cutting_parameterization.C}

View File

@ -28,49 +28,41 @@ of the \ccc{SparseLinearAlgebraTraits_d} concept:
\subsection{{\sc Taucs} Solver Example}
The examples provided so far use the default sparse linear solver
OpenNL. The following C++ code computes the default parameterization
OpenNL.
\ccc{Taucs_parameterization.C} computes the default parameterization
method (Floater Mean Value Coordinates with a circular border), but
specifically instantiates the {\sc Taucs} solver:
specifically instantiates the {\sc Taucs} solver.
The differences with the first example \ccc{Simple_parameterization.C} are:
\begin{ccExampleCode}
// CGAL kernel
typedef CGAL::Cartesian<double> Kernel;
#include <CGAL/Taucs_solver_traits.h>
// Mesh true type and parameterization adaptors
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor;
...
//***************************************
// Floater Mean Value Coordinates parameterization
// (circular border) with TAUCS solver
//***************************************
// Circular border parameterizer (the default)
typedef CGAL::Circular_border_arc_length_parameterizer_3<Parameterization_polyhedron_adaptor>
Border_parameterizer;
Border_parameterizer;
// TAUCS solver
typedef CGAL::Taucs_solver_traits<double> Solver;
typedef CGAL::Taucs_solver_traits<double> Solver;
// Floater Mean Value Coordinates parameterizer (circular border)
// with TAUCS solver
// Floater Mean Value Coordinates parameterization
// (circular border) with TAUCS solver
typedef CGAL::Mean_value_coordinates_parameterizer_3<Parameterization_polyhedron_adaptor,
Border_parameterizer,
Solver>
Parameterizer;
Border_parameterizer,
Solver>
Parameterizer;
int main(int argc,char * argv[])
{
Polyhedron mesh;
...
Parameterizer::Error_code err = CGAL::parameterize(mesh_adaptor, Parameterizer());
// The Surface_mesh_parameterization package needs an adaptor to handle Polyhedron_3 meshes
// The mesh must be a topological disk
Parameterization_polyhedron_adaptor mesh_adaptor(&mesh);
// Floater Mean Value Coordinates parameterizer (circular border)
// with TAUCS solver
Parameterizer::Error_code err = CGAL::parameterize(&mesh_adaptor, Parameterizer());
...
}
...
\end{ccExampleCode}
See the complete example in \ccc{Taucs_parameterization.C}.

View File

@ -13,15 +13,14 @@
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <cassert>
// ----------------------------------------------------------------------------
// Private types
// ----------------------------------------------------------------------------
typedef CGAL::Cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef CGAL::Cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
// ----------------------------------------------------------------------------
@ -63,18 +62,18 @@ int main(int argc,char * argv[])
stream >> mesh;
//***************************************
// Create mesh adaptor
// Note: parameterization methods support only
// Create Polyhedron adaptor
// Note: no cutting => we support only
// meshes that are topological disks
//***************************************
// The Surface_mesh_parameterization package needs an adaptor to handle Polyhedron_3 meshes
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor;
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor;
Parameterization_polyhedron_adaptor mesh_adaptor(mesh);
//***************************************
// Discrete Authalic Parameterization
// (defaults are circular border and OpenNL solver)
//***************************************
typedef CGAL::Discrete_authalic_parameterizer_3<Parameterization_polyhedron_adaptor>

View File

@ -20,25 +20,22 @@
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <cassert>
// ----------------------------------------------------------------------------
// Private types
// ----------------------------------------------------------------------------
typedef CGAL::Cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef CGAL::Cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
// Mesh adaptors
// Polyhedron adaptor
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor;
typedef CGAL::Parameterization_mesh_patch_3<Parameterization_polyhedron_adaptor>
Mesh_patch_polyhedron;
Parameterization_polyhedron_adaptor;
// Type describing a border or seam as a vertex list
typedef std::list<Parameterization_polyhedron_adaptor::Vertex_handle>
Seam;
Seam;
// ----------------------------------------------------------------------------
@ -49,9 +46,7 @@ typedef std::list<Parameterization_polyhedron_adaptor::Vertex_handle>
// else compute a very simple cut to make it homeomorphic to a disk.
// Return the border of this region (empty on error)
//
// CAUTION:
// This method is provided "as is". It is very buggy and simply part of this example.
// Developers using this package should implement a more robust cut algorithm!
// CAUTION: this cutting algorithm is very naive. Write your own!
static Seam cut_mesh(Parameterization_polyhedron_adaptor& mesh_adaptor)
{
// Helper class to compute genus or extract borders
@ -101,74 +96,83 @@ static Seam cut_mesh(Parameterization_polyhedron_adaptor& mesh_adaptor)
return seam;
}
// Dump parameterized mesh to a Wavefront OBJ file
// v x y z
// f 1 2 3 4 (1-based)
//
// Implementation note: the UV is meaningless for a NON parameterized halfedge
static bool write_file_obj(Parameterization_polyhedron_adaptor& mesh_adaptor,
const char *pFilename)
// Dump parameterized mesh to an eps file
static bool write_file_eps(const Parameterization_polyhedron_adaptor& mesh_adaptor,
const char *pFilename,
double scale = 500.0)
{
Polyhedron& mesh = mesh_adaptor.get_adapted_mesh();
assert(pFilename != NULL);
const Polyhedron& mesh = mesh_adaptor.get_adapted_mesh();
std::ofstream out(pFilename);
if(!out)
return false;
CGAL::set_ascii_mode(out);
// Index all mesh vertices following the order of vertices_begin() iterator
Polyhedron::Vertex_const_iterator pVertex;
unsigned int i = 0;
for(pVertex = mesh.vertices_begin(); pVertex != mesh.vertices_end(); pVertex++)
mesh_adaptor.info(pVertex)->index(i++);
// Index all mesh half edges following the order of halfedges_begin() iterator
// compute bounding box
double xmin,xmax,ymin,ymax;
xmin = ymin = xmax = ymax = 0;
Polyhedron::Halfedge_const_iterator pHalfedge;
i = 0;
for(pHalfedge = mesh.halfedges_begin(); pHalfedge != mesh.halfedges_end(); pHalfedge++)
mesh_adaptor.info(pHalfedge)->index(i++);
// write the name of material file
out << "mtllib parameterization.mtl" << std::endl ;
// output coordinates
out << "# vertices" << std::endl ;
for(pVertex = mesh.vertices_begin(); pVertex != mesh.vertices_end(); pVertex++)
out << "v " << pVertex->point().x() << " "
<< pVertex->point().y() << " "
<< pVertex->point().z() << std::endl;
// Write UVs (1 UV / halfedge)
out << "# uv coordinates" << std::endl ;
for(pHalfedge = mesh.halfedges_begin(); pHalfedge != mesh.halfedges_end(); pHalfedge++)
for (pHalfedge = mesh.halfedges_begin();
pHalfedge != mesh.halfedges_end();
pHalfedge++)
{
Parameterization_polyhedron_adaptor::Halfedge_info* he_info = mesh_adaptor.info(pHalfedge);
if (he_info->is_parameterized())
out << "vt " << he_info->uv().x() << " " << he_info->uv().y() << std::endl;
else
out << "vt " << 0.0 << " " << 0.0 << std::endl;
double x1 = scale * mesh_adaptor.info(pHalfedge->prev())->uv().x();
double y1 = scale * mesh_adaptor.info(pHalfedge->prev())->uv().y();
double x2 = scale * mesh_adaptor.info(pHalfedge)->uv().x();
double y2 = scale * mesh_adaptor.info(pHalfedge)->uv().y();
xmin = std::min(xmin,x1);
xmin = std::min(xmin,x2);
xmax = std::max(xmax,x1);
xmax = std::max(xmax,x2);
ymax = std::max(ymax,y1);
ymax = std::max(ymax,y2);
ymin = std::min(ymin,y1);
ymin = std::min(ymin,y2);
}
// Write facets using the unique material # 1
out << "# facets" << std::endl;
out << "usemtl Mat_1" << std::endl;
Polyhedron::Facet_const_iterator pFacet;
for(pFacet = mesh.facets_begin(); pFacet != mesh.facets_end(); pFacet++)
out << "%!PS-Adobe-2.0 EPSF-2.0" << std::endl;
out << "%%BoundingBox: " << int(xmin+0.5) << " "
<< int(ymin+0.5) << " "
<< int(xmax+0.5) << " "
<< int(ymax+0.5) << std::endl;
out << "%%HiResBoundingBox: " << xmin << " "
<< ymin << " "
<< xmax << " "
<< ymax << std::endl;
out << "%%EndComments" << std::endl;
out << "gsave" << std::endl;
out << "0.1 setlinewidth" << std::endl;
// color macros
out << std::endl;
out << "% RGB color command - r g b C" << std::endl;
out << "/C { setrgbcolor } bind def" << std::endl;
out << "/white { 1 1 1 C } bind def" << std::endl;
out << "/black { 0 0 0 C } bind def" << std::endl;
// edge macro -> E
out << std::endl;
out << "% Black stroke - x1 y1 x2 y2 E" << std::endl;
out << "/E {moveto lineto stroke} bind def" << std::endl;
out << "black" << std::endl << std::endl;
// for each halfedge
for (pHalfedge = mesh.halfedges_begin();
pHalfedge != mesh.halfedges_end();
pHalfedge++)
{
Polyhedron::Halfedge_around_facet_const_circulator h = pFacet->facet_begin();
out << "f";
do {
Parameterization_polyhedron_adaptor::Halfedge_info* he_info = mesh_adaptor.info(h);
Parameterization_polyhedron_adaptor::Vertex_info* vtx_info = mesh_adaptor.info(h->vertex());
out << " " << vtx_info->index()+1;
if (he_info->is_parameterized())
out << "/" << he_info->index()+1;
}
while(++h != pFacet->facet_begin());
out << std::endl;
double x1 = scale * mesh_adaptor.info(pHalfedge->prev())->uv().x();
double y1 = scale * mesh_adaptor.info(pHalfedge->prev())->uv().y();
double x2 = scale * mesh_adaptor.info(pHalfedge)->uv().x();
double y2 = scale * mesh_adaptor.info(pHalfedge)->uv().y();
out << x1 << " " << y1 << " " << x2 << " " << y2 << " E" << std::endl;
}
/* Emit EPS trailer. */
out << "grestore" << std::endl;
out << std::endl;
out << "showpage" << std::endl;
return true;
}
@ -184,7 +188,7 @@ int main(int argc,char * argv[])
std::cerr << " Square border" << std::endl;
std::cerr << " TAUCS solver" << std::endl;
std::cerr << " Very simple cut if model is not a topological disk" << std::endl;
std::cerr << " Output: OBJ" << std::endl;
std::cerr << " Output: EPS" << std::endl;
//***************************************
// decode parameters
@ -192,7 +196,7 @@ int main(int argc,char * argv[])
if (argc-1 != 2)
{
std::cerr << "Usage: " << argv[0] << " input_file.off output_file.obj" << std::endl;
std::cerr << "Usage: " << argv[0] << " input_file.off output_file.eps" << std::endl;
return(EXIT_FAILURE);
}
@ -215,23 +219,28 @@ int main(int argc,char * argv[])
stream >> mesh;
//***************************************
// Create mesh adaptors
// Create Polyhedron adaptor
//***************************************
// The Surface_mesh_parameterization package needs an adaptor to handle Polyhedron_3 meshes
Parameterization_polyhedron_adaptor mesh_adaptor(mesh);
//***************************************
// Virtually cut mesh
//***************************************
// The parameterization methods support only meshes that
// are topological disks => we need to compute a "cutting" of the mesh
// that makes it it homeomorphic to a disk
Seam seam = cut_mesh(mesh_adaptor);
if (seam.empty())
{
fprintf(stderr, "\nFATAL ERROR: an unexpected error occurred while cutting the shape!\n\n");
std::cerr << "FATAL ERROR: an unexpected error occurred while cutting the shape" << std::endl;
return EXIT_FAILURE;
}
// Create adaptor that virtually "cuts" the mesh following the 'seam' path
// Create a second adaptor that virtually "cuts" the mesh following the 'seam' path
typedef CGAL::Parameterization_mesh_patch_3<Parameterization_polyhedron_adaptor>
Mesh_patch_polyhedron;
Mesh_patch_polyhedron mesh_patch(mesh_adaptor, seam.begin(), seam.end());
//***************************************
@ -259,10 +268,10 @@ int main(int argc,char * argv[])
// Output
//***************************************
// Write Wavefront OBJ file
// Write Postscript file
if (err == Parameterizer::OK)
{
if ( ! write_file_obj(mesh_adaptor, output_filename) )
if ( ! write_file_eps(mesh_adaptor, output_filename) )
{
std::cerr << "FATAL ERROR: cannot write file " << output_filename << std::endl;
return EXIT_FAILURE;

View File

@ -1 +1 @@
data/sphere966.off sphere966_authalic_square_taucs_parameterized.obj
data/sphere966.off sphere966_authalic_square_taucs_parameterized.eps

View File

@ -13,7 +13,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <cassert>
// ----------------------------------------------------------------------------
@ -23,14 +22,12 @@
typedef CGAL::Cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
// Mesh adaptors
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
// Polyhedron adaptor
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor;
typedef CGAL::Parameterization_mesh_patch_3<Parameterization_polyhedron_adaptor>
Mesh_patch_polyhedron;
// Type describing a border or seam as a vertex list
typedef std::list<Parameterization_polyhedron_adaptor::Vertex_handle>
typedef std::list<Parameterization_polyhedron_adaptor::Vertex_handle>
Seam;
@ -42,9 +39,7 @@ typedef std::list<Parameterization_polyhedron_adaptor::Vertex_handle>
// else compute a very simple cut to make it homeomorphic to a disk.
// Return the border of this region (empty on error)
//
// CAUTION:
// This method is provided "as is". It is very buggy and simply part of this example.
// Developers using this package should implement a more robust cut algorithm!
// CAUTION: this cutting algorithm is very naive. Write your own!
static Seam cut_mesh(Parameterization_polyhedron_adaptor& mesh_adaptor)
{
// Helper class to compute genus or extract borders
@ -53,7 +48,7 @@ static Seam cut_mesh(Parameterization_polyhedron_adaptor& mesh_adaptor)
Seam seam; // returned list
// Get refererence to Polyhedron_3 mesh
// Get reference to Polyhedron_3 mesh
Polyhedron& mesh = mesh_adaptor.get_adapted_mesh();
// Extract mesh borders and compute genus
@ -126,7 +121,7 @@ int main(int argc,char * argv[])
// Read the mesh
std::ifstream stream(input_filename);
if(!stream)
if(!stream)
{
std::cerr << "FATAL ERROR: cannot open file " << input_filename << std::endl;
return EXIT_FAILURE;
@ -135,23 +130,28 @@ int main(int argc,char * argv[])
stream >> mesh;
//***************************************
// Create mesh adaptor
// Create Polyhedron adaptor
//***************************************
// The Surface_mesh_parameterization package needs an adaptor to handle Polyhedron_3 meshes
Parameterization_polyhedron_adaptor mesh_adaptor(mesh);
//***************************************
// Virtually cut mesh
//***************************************
// The parameterization methods support only meshes that
// are topological disks => we need to compute a "cutting" of the mesh
// that makes it it homeomorphic to a disk
Seam seam = cut_mesh(mesh_adaptor);
if (seam.empty())
{
fprintf(stderr, "\nFATAL ERROR: an unexpected error occurred while cutting the shape!\n\n");
std::cerr << "FATAL ERROR: an unexpected error occurred while cutting the shape" << std::endl;
return EXIT_FAILURE;
}
// Create adaptor that virtually "cuts" the mesh following the 'seam' path
// Create a second adaptor that virtually "cuts" the mesh following the 'seam' path
typedef CGAL::Parameterization_mesh_patch_3<Parameterization_polyhedron_adaptor>
Mesh_patch_polyhedron;
Mesh_patch_polyhedron mesh_patch(mesh_adaptor, seam.begin(), seam.end());
//***************************************

View File

@ -12,7 +12,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <cassert>
// ----------------------------------------------------------------------------
@ -53,7 +52,7 @@ int main(int argc,char * argv[])
// Read the mesh
std::ifstream stream(input_filename);
if(!stream)
if(!stream)
{
std::cerr << "FATAL ERROR: cannot open file " << input_filename << std::endl;
return EXIT_FAILURE;
@ -62,21 +61,21 @@ int main(int argc,char * argv[])
stream >> mesh;
//***************************************
// Create mesh adaptor
// Note: parameterization methods support only
// Create Polyhedron adaptor
// Note: no cutting => we support only
// meshes that are topological disks
//***************************************
// The Surface_mesh_parameterization package needs an adaptor to handle Polyhedron_3 meshes
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor;
Parameterization_polyhedron_adaptor mesh_adaptor(mesh);
//***************************************
// Floater Mean Value Coordinates parameterization
// (defaults are circular border and OpenNL solver)
//***************************************
// Type that defines the error codes
// Type that defines the error codes
typedef CGAL::Parameterizer_traits_3<Parameterization_polyhedron_adaptor>
Parameterizer;

View File

@ -13,16 +13,14 @@
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <cassert>
// ----------------------------------------------------------------------------
// Private types
// ----------------------------------------------------------------------------
typedef CGAL::Cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef CGAL::Cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
// ----------------------------------------------------------------------------
@ -64,17 +62,15 @@ int main(int argc,char * argv[])
stream >> mesh;
//***************************************
// Create mesh adaptor
// Note: parameterization methods support only
// Create Polyhedron adaptor
// Note: no cutting => we support only
// meshes that are topological disks
//***************************************
// The Surface_mesh_parameterization package needs an adaptor to handle Polyhedron_3 meshes
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor;
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor;
Parameterization_polyhedron_adaptor mesh_adaptor(mesh);
//***************************************
// Floater Mean Value Coordinates parameterization
// with square border
@ -82,7 +78,7 @@ int main(int argc,char * argv[])
// Square border parameterizer
typedef CGAL::Square_border_arc_length_parameterizer_3<Parameterization_polyhedron_adaptor>
Border_parameterizer;
Border_parameterizer;
// Floater Mean Value Coordinates parameterizer with square border
typedef CGAL::Mean_value_coordinates_parameterizer_3<Parameterization_polyhedron_adaptor,

View File

@ -17,105 +17,14 @@
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <cassert>
// ----------------------------------------------------------------------------
// Private types
// ----------------------------------------------------------------------------
typedef CGAL::Cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
// Mesh adaptor
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor;
// ----------------------------------------------------------------------------
// Private functions
// ----------------------------------------------------------------------------
// Dump parameterized mesh to an eps file
static bool write_file_eps(const Parameterization_polyhedron_adaptor& mesh_adaptor,
const char *pFilename,
double scale = 500.0)
{
const Polyhedron& mesh = mesh_adaptor.get_adapted_mesh();
assert(pFilename != NULL);
std::ofstream out(pFilename);
if(!out)
return false;
CGAL::set_ascii_mode(out);
// compute bounding box
double xmin,xmax,ymin,ymax;
xmin = ymin = xmax = ymax = 0;
Polyhedron::Halfedge_const_iterator pHalfedge;
for (pHalfedge = mesh.halfedges_begin();
pHalfedge != mesh.halfedges_end();
pHalfedge++)
{
double x1 = scale * mesh_adaptor.info(pHalfedge->prev())->uv().x();
double y1 = scale * mesh_adaptor.info(pHalfedge->prev())->uv().y();
double x2 = scale * mesh_adaptor.info(pHalfedge)->uv().x();
double y2 = scale * mesh_adaptor.info(pHalfedge)->uv().y();
xmin = std::min(xmin,x1);
xmin = std::min(xmin,x2);
xmax = std::max(xmax,x1);
xmax = std::max(xmax,x2);
ymax = std::max(ymax,y1);
ymax = std::max(ymax,y2);
ymin = std::min(ymin,y1);
ymin = std::min(ymin,y2);
}
out << "%!PS-Adobe-2.0 EPSF-2.0" << std::endl;
out << "%%BoundingBox: " << int(xmin+0.5) << " "
<< int(ymin+0.5) << " "
<< int(xmax+0.5) << " "
<< int(ymax+0.5) << std::endl;
out << "%%HiResBoundingBox: " << xmin << " "
<< ymin << " "
<< xmax << " "
<< ymax << std::endl;
out << "%%EndComments" << std::endl;
out << "gsave" << std::endl;
out << "0.1 setlinewidth" << std::endl;
// color macros
out << std::endl;
out << "% RGB color command - r g b C" << std::endl;
out << "/C { setrgbcolor } bind def" << std::endl;
out << "/white { 1 1 1 C } bind def" << std::endl;
out << "/black { 0 0 0 C } bind def" << std::endl;
// edge macro -> E
out << std::endl;
out << "% Black stroke - x1 y1 x2 y2 E" << std::endl;
out << "/E {moveto lineto stroke} bind def" << std::endl;
out << "black" << std::endl << std::endl;
// for each halfedge
for (pHalfedge = mesh.halfedges_begin();
pHalfedge != mesh.halfedges_end();
pHalfedge++)
{
double x1 = scale * mesh_adaptor.info(pHalfedge->prev())->uv().x();
double y1 = scale * mesh_adaptor.info(pHalfedge->prev())->uv().y();
double x2 = scale * mesh_adaptor.info(pHalfedge)->uv().x();
double y2 = scale * mesh_adaptor.info(pHalfedge)->uv().y();
out << x1 << " " << y1 << " " << x2 << " " << y2 << " E" << std::endl;
}
/* Emit EPS trailer. */
out << "grestore" << std::endl;
out << std::endl;
out << "showpage" << std::endl;
return true;
}
typedef CGAL::Cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
// ----------------------------------------------------------------------------
@ -128,21 +37,19 @@ int main(int argc,char * argv[])
std::cerr << " Floater parameterization" << std::endl;
std::cerr << " Circle border" << std::endl;
std::cerr << " TAUCS solver" << std::endl;
std::cerr << " Output: EPS" << std::endl;
//***************************************
// decode parameters
//***************************************
if (argc-1 != 2)
if (argc-1 != 1)
{
std::cerr << "Usage: " << argv[0] << " input_file.off output_file.eps" << std::endl;
std::cerr << "Usage: " << argv[0] << " input_file.off" << std::endl;
return(EXIT_FAILURE);
}
// File names are:
// File name is:
const char* input_filename = argv[1];
const char* output_filename = argv[2];
//***************************************
// Read the mesh
@ -159,17 +66,18 @@ int main(int argc,char * argv[])
stream >> mesh;
//***************************************
// Create mesh adaptor
// Note: parameterization methods support only
// Create Polyhedron adaptor
// Note: no cutting => we support only
// meshes that are topological disks
//***************************************
// The Surface_mesh_parameterization package needs an adaptor to handle Polyhedron_3 meshes
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor;
Parameterization_polyhedron_adaptor mesh_adaptor(mesh);
//***************************************
// Floater Mean Value Coordinates parameterizer (circular border)
// with TAUCS solver
// Floater Mean Value Coordinates parameterization
// (circular border) with TAUCS solver
//***************************************
// Circular border parameterizer (the default)
@ -178,8 +86,8 @@ int main(int argc,char * argv[])
// TAUCS solver
typedef CGAL::Taucs_solver_traits<double> Solver;
// Floater Mean Value Coordinates parameterizer (circular border)
// with TAUCS solver
// Floater Mean Value Coordinates parameterization
// (circular border) with TAUCS solver
typedef CGAL::Mean_value_coordinates_parameterizer_3<Parameterization_polyhedron_adaptor,
Border_parameterizer,
Solver>
@ -193,13 +101,18 @@ int main(int argc,char * argv[])
// Output
//***************************************
// Write Postscript file
if (err == Parameterizer::OK)
{
if ( ! write_file_eps(mesh_adaptor, output_filename) )
// Raw output: dump (u,v) pairs
Polyhedron::Vertex_const_iterator pVertex;
for (pVertex = mesh.vertices_begin();
pVertex != mesh.vertices_end();
pVertex++)
{
std::cerr << "FATAL ERROR: cannot write file " << output_filename << std::endl;
return EXIT_FAILURE;
// (u,v) pair is stored in any halfedge
double u = mesh_adaptor.info(pVertex->halfedge())->uv().x();
double v = mesh_adaptor.info(pVertex->halfedge())->uv().y();
std::cout << "(u,v) = (" << u << "," << v << ")" << std::endl;
}
}

View File

@ -1 +1 @@
data/mannequin-devil.off mannequin-devil_floater_circle_taucs_parameterized.eps
data/mannequin-devil.off