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_html
Surface_mesh_parameterization/doc_pdf Surface_mesh_parameterization/doc_pdf
Surface_mesh_parameterization/doc_ps 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/*.kdev*
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/*.ncb 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/*.suo
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/*_extra.* Surface_mesh_parameterization/examples/Surface_mesh_parameterization/*_extra.*
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/*_parameterization 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/data/extras
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/debug Surface_mesh_parameterization/examples/Surface_mesh_parameterization/debug
Surface_mesh_parameterization/examples/Surface_mesh_parameterization/error.txt 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/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/examples/Surface_mesh_parameterization/test
Surface_mesh_parameterization/test/Surface_mesh_parameterization/*.kdev* Surface_mesh_parameterization/test/Surface_mesh_parameterization/*.kdev*
Surface_mesh_parameterization/test/Surface_mesh_parameterization/*.ncb 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} \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). \ccc{Polyhedron_3} mesh (must be a topological disk).
Eventually, it extracts the result from halfedges and prints it. Eventually, it extracts the result from halfedges and prints it.
\begin{ccExampleCode} \ccIncludeExampleCode{Surface_mesh_parameterization/Simple_parameterization.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;
// 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}.

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} \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 parameterization method over a \ccc{Polyhedron_3} mesh with a
\ccc{Parameterization_polyhedron_adaptor_3<Polyhedron_3_>} adaptor: \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} \subsection{Discrete Authalic Parameterization Example}
The following C++ code computes a Discrete Authalic parameterization \ccc{Authalic_parameterization.C} computes a Discrete Authalic parameterization
to a \ccc{Polyhedron_3} mesh: over a \ccc{Polyhedron_3} mesh.
The differences with the first example \ccc{Simple_parameterization.C} are:
\begin{ccExampleCode} \begin{ccExampleCode}
// CGAL kernel #include <CGAL/Discrete_authalic_parameterizer_3.h>
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;
//***************************************
// Discrete Authalic Parameterization // Discrete Authalic Parameterization
//***************************************
typedef CGAL::Discrete_authalic_parameterizer_3<Parameterization_polyhedron_adaptor> typedef CGAL::Discrete_authalic_parameterizer_3<Parameterization_polyhedron_adaptor>
Parameterizer; Parameterizer;
int main(int argc,char * argv[]) Parameterizer::Error_code err = CGAL::parameterize(mesh_adaptor, Parameterizer());
{
Polyhedron 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);
// Discrete Authalic Parameterization
Parameterizer::Error_code err = CGAL::parameterize(&mesh_adaptor, Parameterizer());
... ...
}
\end{ccExampleCode} \end{ccExampleCode}
The complete example is available in
\ccc{Authalic_parameterization.C}.
\subsection{Square Border Arc Length Parameterization Example} \subsection{Square Border Arc Length Parameterization Example}
The following C++ code computes a Floater Mean Value Coordinates \ccc{Square_border_parameterization.C} computes a Floater Mean Value Coordinates
parameterization with a Square Border Arc Length parameterization: parameterization with a Square Border Arc Length parameterization.
The differences with the first example \ccc{Simple_parameterization.C} are:
\begin{ccExampleCode} \begin{ccExampleCode}
// CGAL kernel #include <CGAL/Square_border_parameterizer_3.h>
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; // Floater Mean Value Coordinates parameterization
// with square border
//***************************************
// Square border parameterizer // Square border parameterizer
typedef CGAL::Square_border_arc_length_parameterizer_3<Parameterization_polyhedron_adaptor> typedef CGAL::Square_border_arc_length_parameterizer_3<Parameterization_polyhedron_adaptor>
@ -302,21 +293,9 @@ typedef CGAL::Mean_value_coordinates_parameterizer_3<Parameterization_polyhedron
Border_parameterizer> Border_parameterizer>
Parameterizer; Parameterizer;
int main(int argc,char * argv[]) Parameterizer::Error_code err = CGAL::parameterize(mesh_adaptor, Parameterizer());
{
Polyhedron 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
// with a Square Border Arc Length Parameterization
Parameterizer::Error_code err = CGAL::parameterize(&mesh_adaptor, Parameterizer());
... ...
}
\end{ccExampleCode} \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>} \ccc{Parameterization_mesh_patch_3<ParameterizationPatchableMesh_3>}
class is responsible for virtually class is responsible for virtually
{\em cutting} a patch to a \ccc{ParameterizationPatchableMesh_3} mesh, {\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. disk with a \ccc{ParameterizationMesh_3} interface.
\ccc{ParameterizationPatchableMesh_3} inherits from concept \ccc{ParameterizationMesh_3}, \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} \subsection{Cutting a Mesh Example}
The code below virtually {\em cuts} a \ccc{Polyhedron_3} mesh to make \ccc{Mesh_cutting_parameterization.C} virtually {\em cuts} a \ccc{Polyhedron_3} mesh
it a topological disk, then applies the default parameterization: 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.
\ccIncludeExampleCode{Surface_mesh_parameterization/Mesh_cutting_parameterization.C}

View File

@ -28,19 +28,24 @@ of the \ccc{SparseLinearAlgebraTraits_d} concept:
\subsection{{\sc Taucs} Solver Example} \subsection{{\sc Taucs} Solver Example}
The examples provided so far use the default sparse linear solver 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 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} \begin{ccExampleCode}
// CGAL kernel #include <CGAL/Taucs_solver_traits.h>
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; // Floater Mean Value Coordinates parameterization
// (circular border) with TAUCS solver
//***************************************
// Circular border parameterizer (the default) // Circular border parameterizer (the default)
typedef CGAL::Circular_border_arc_length_parameterizer_3<Parameterization_polyhedron_adaptor> typedef CGAL::Circular_border_arc_length_parameterizer_3<Parameterization_polyhedron_adaptor>
@ -48,29 +53,16 @@ typedef CGAL::Circular_border_arc_length_parameterizer_3<Parameterization_polyhe
// TAUCS solver // TAUCS solver
typedef CGAL::Taucs_solver_traits<double> Solver; typedef CGAL::Taucs_solver_traits<double> Solver;
// Floater Mean Value Coordinates parameterizer (circular border) // Floater Mean Value Coordinates parameterization
// with TAUCS solver // (circular border) with TAUCS solver
typedef CGAL::Mean_value_coordinates_parameterizer_3<Parameterization_polyhedron_adaptor, typedef CGAL::Mean_value_coordinates_parameterizer_3<Parameterization_polyhedron_adaptor,
Border_parameterizer, Border_parameterizer,
Solver> Solver>
Parameterizer; Parameterizer;
int main(int argc,char * argv[]) Parameterizer::Error_code err = CGAL::parameterize(mesh_adaptor, Parameterizer());
{
Polyhedron 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 parameterizer (circular border)
// with TAUCS solver
Parameterizer::Error_code err = CGAL::parameterize(&mesh_adaptor, Parameterizer());
... ...
}
\end{ccExampleCode} \end{ccExampleCode}
See the complete example in \ccc{Taucs_parameterization.C}.

View File

@ -13,7 +13,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <fstream> #include <fstream>
#include <cassert>
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -63,18 +62,18 @@ int main(int argc,char * argv[])
stream >> mesh; stream >> mesh;
//*************************************** //***************************************
// Create mesh adaptor // Create Polyhedron adaptor
// Note: parameterization methods support only // Note: no cutting => we support only
// meshes that are topological disks // 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;
Parameterization_polyhedron_adaptor mesh_adaptor(mesh); Parameterization_polyhedron_adaptor mesh_adaptor(mesh);
//*************************************** //***************************************
// Discrete Authalic Parameterization // Discrete Authalic Parameterization
// (defaults are circular border and OpenNL solver)
//*************************************** //***************************************
typedef CGAL::Discrete_authalic_parameterizer_3<Parameterization_polyhedron_adaptor> typedef CGAL::Discrete_authalic_parameterizer_3<Parameterization_polyhedron_adaptor>

View File

@ -20,7 +20,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <fstream> #include <fstream>
#include <cassert>
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -30,11 +29,9 @@
typedef CGAL::Cartesian<double> Kernel; typedef CGAL::Cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron; typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
// Mesh adaptors // Polyhedron adaptor
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron> typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor; 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 // 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>
@ -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. // else compute a very simple cut to make it homeomorphic to a disk.
// Return the border of this region (empty on error) // Return the border of this region (empty on error)
// //
// CAUTION: // CAUTION: this cutting algorithm is very naive. Write your own!
// 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!
static Seam cut_mesh(Parameterization_polyhedron_adaptor& mesh_adaptor) static Seam cut_mesh(Parameterization_polyhedron_adaptor& mesh_adaptor)
{ {
// Helper class to compute genus or extract borders // Helper class to compute genus or extract borders
@ -101,74 +96,83 @@ static Seam cut_mesh(Parameterization_polyhedron_adaptor& mesh_adaptor)
return seam; return seam;
} }
// Dump parameterized mesh to a Wavefront OBJ file // Dump parameterized mesh to an eps file
// v x y z static bool write_file_eps(const Parameterization_polyhedron_adaptor& mesh_adaptor,
// f 1 2 3 4 (1-based) const char *pFilename,
// double scale = 500.0)
// Implementation note: the UV is meaningless for a NON parameterized halfedge
static bool write_file_obj(Parameterization_polyhedron_adaptor& mesh_adaptor,
const char *pFilename)
{ {
Polyhedron& mesh = mesh_adaptor.get_adapted_mesh(); const Polyhedron& mesh = mesh_adaptor.get_adapted_mesh();
assert(pFilename != NULL);
std::ofstream out(pFilename); std::ofstream out(pFilename);
if(!out) if(!out)
return false; return false;
CGAL::set_ascii_mode(out); CGAL::set_ascii_mode(out);
// Index all mesh vertices following the order of vertices_begin() iterator // compute bounding box
Polyhedron::Vertex_const_iterator pVertex; double xmin,xmax,ymin,ymax;
unsigned int i = 0; xmin = ymin = xmax = ymax = 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
Polyhedron::Halfedge_const_iterator pHalfedge; Polyhedron::Halfedge_const_iterator pHalfedge;
i = 0; for (pHalfedge = mesh.halfedges_begin();
for(pHalfedge = mesh.halfedges_begin(); pHalfedge != mesh.halfedges_end(); pHalfedge++) pHalfedge != mesh.halfedges_end();
mesh_adaptor.info(pHalfedge)->index(i++); pHalfedge++)
// 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++)
{ {
Parameterization_polyhedron_adaptor::Halfedge_info* he_info = mesh_adaptor.info(pHalfedge); double x1 = scale * mesh_adaptor.info(pHalfedge->prev())->uv().x();
if (he_info->is_parameterized()) double y1 = scale * mesh_adaptor.info(pHalfedge->prev())->uv().y();
out << "vt " << he_info->uv().x() << " " << he_info->uv().y() << std::endl; double x2 = scale * mesh_adaptor.info(pHalfedge)->uv().x();
else double y2 = scale * mesh_adaptor.info(pHalfedge)->uv().y();
out << "vt " << 0.0 << " " << 0.0 << std::endl; 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 << "%!PS-Adobe-2.0 EPSF-2.0" << std::endl;
out << "# facets" << std::endl; out << "%%BoundingBox: " << int(xmin+0.5) << " "
out << "usemtl Mat_1" << std::endl; << int(ymin+0.5) << " "
Polyhedron::Facet_const_iterator pFacet; << int(xmax+0.5) << " "
for(pFacet = mesh.facets_begin(); pFacet != mesh.facets_end(); pFacet++) << int(ymax+0.5) << std::endl;
{ out << "%%HiResBoundingBox: " << xmin << " "
Polyhedron::Halfedge_around_facet_const_circulator h = pFacet->facet_begin(); << ymin << " "
out << "f"; << xmax << " "
do { << ymax << std::endl;
Parameterization_polyhedron_adaptor::Halfedge_info* he_info = mesh_adaptor.info(h); out << "%%EndComments" << std::endl;
Parameterization_polyhedron_adaptor::Vertex_info* vtx_info = mesh_adaptor.info(h->vertex()); out << "gsave" << std::endl;
out << " " << vtx_info->index()+1; out << "0.1 setlinewidth" << std::endl;
if (he_info->is_parameterized())
out << "/" << he_info->index()+1; // color macros
}
while(++h != pFacet->facet_begin());
out << std::endl; 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; return true;
} }
@ -184,7 +188,7 @@ int main(int argc,char * argv[])
std::cerr << " Square border" << std::endl; std::cerr << " Square border" << std::endl;
std::cerr << " TAUCS solver" << std::endl; std::cerr << " TAUCS solver" << std::endl;
std::cerr << " Very simple cut if model is not a topological disk" << 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 // decode parameters
@ -192,7 +196,7 @@ int main(int argc,char * argv[])
if (argc-1 != 2) 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); return(EXIT_FAILURE);
} }
@ -215,23 +219,28 @@ int main(int argc,char * argv[])
stream >> mesh; 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); Parameterization_polyhedron_adaptor mesh_adaptor(mesh);
//***************************************
// Virtually cut mesh
//***************************************
// The parameterization methods support only meshes that // The parameterization methods support only meshes that
// are topological disks => we need to compute a "cutting" of the mesh // are topological disks => we need to compute a "cutting" of the mesh
// that makes it it homeomorphic to a disk // that makes it it homeomorphic to a disk
Seam seam = cut_mesh(mesh_adaptor); Seam seam = cut_mesh(mesh_adaptor);
if (seam.empty()) 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; 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()); Mesh_patch_polyhedron mesh_patch(mesh_adaptor, seam.begin(), seam.end());
//*************************************** //***************************************
@ -259,10 +268,10 @@ int main(int argc,char * argv[])
// Output // Output
//*************************************** //***************************************
// Write Wavefront OBJ file // Write Postscript file
if (err == Parameterizer::OK) 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; std::cerr << "FATAL ERROR: cannot write file " << output_filename << std::endl;
return EXIT_FAILURE; 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 <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <fstream> #include <fstream>
#include <cassert>
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -23,11 +22,9 @@
typedef CGAL::Cartesian<double> Kernel; typedef CGAL::Cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron; typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
// Mesh adaptors // Polyhedron adaptor
typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron> typedef CGAL::Parameterization_polyhedron_adaptor_3<Polyhedron>
Parameterization_polyhedron_adaptor; 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 // 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>
@ -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. // else compute a very simple cut to make it homeomorphic to a disk.
// Return the border of this region (empty on error) // Return the border of this region (empty on error)
// //
// CAUTION: // CAUTION: this cutting algorithm is very naive. Write your own!
// 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!
static Seam cut_mesh(Parameterization_polyhedron_adaptor& mesh_adaptor) static Seam cut_mesh(Parameterization_polyhedron_adaptor& mesh_adaptor)
{ {
// Helper class to compute genus or extract borders // 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 Seam seam; // returned list
// Get refererence to Polyhedron_3 mesh // Get reference to Polyhedron_3 mesh
Polyhedron& mesh = mesh_adaptor.get_adapted_mesh(); Polyhedron& mesh = mesh_adaptor.get_adapted_mesh();
// Extract mesh borders and compute genus // Extract mesh borders and compute genus
@ -135,23 +130,28 @@ int main(int argc,char * argv[])
stream >> mesh; 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); Parameterization_polyhedron_adaptor mesh_adaptor(mesh);
//***************************************
// Virtually cut mesh
//***************************************
// The parameterization methods support only meshes that // The parameterization methods support only meshes that
// are topological disks => we need to compute a "cutting" of the mesh // are topological disks => we need to compute a "cutting" of the mesh
// that makes it it homeomorphic to a disk // that makes it it homeomorphic to a disk
Seam seam = cut_mesh(mesh_adaptor); Seam seam = cut_mesh(mesh_adaptor);
if (seam.empty()) 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; 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()); Mesh_patch_polyhedron mesh_patch(mesh_adaptor, seam.begin(), seam.end());
//*************************************** //***************************************

View File

@ -12,7 +12,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <fstream> #include <fstream>
#include <cassert>
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -62,18 +61,18 @@ int main(int argc,char * argv[])
stream >> mesh; stream >> mesh;
//*************************************** //***************************************
// Create mesh adaptor // Create Polyhedron adaptor
// Note: parameterization methods support only // Note: no cutting => we support only
// meshes that are topological disks // 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;
Parameterization_polyhedron_adaptor mesh_adaptor(mesh); Parameterization_polyhedron_adaptor mesh_adaptor(mesh);
//*************************************** //***************************************
// Floater Mean Value Coordinates parameterization // Floater Mean Value Coordinates parameterization
// (defaults are circular border and OpenNL solver)
//*************************************** //***************************************
// Type that defines the error codes // Type that defines the error codes

View File

@ -13,7 +13,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <fstream> #include <fstream>
#include <cassert>
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -24,7 +23,6 @@ typedef CGAL::Cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron; typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// main() // main()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -64,17 +62,15 @@ int main(int argc,char * argv[])
stream >> mesh; stream >> mesh;
//*************************************** //***************************************
// Create mesh adaptor // Create Polyhedron adaptor
// Note: parameterization methods support only // Note: no cutting => we support only
// meshes that are topological disks // 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;
Parameterization_polyhedron_adaptor mesh_adaptor(mesh); Parameterization_polyhedron_adaptor mesh_adaptor(mesh);
//*************************************** //***************************************
// Floater Mean Value Coordinates parameterization // Floater Mean Value Coordinates parameterization
// with square border // with square border

View File

@ -17,7 +17,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <fstream> #include <fstream>
#include <cassert>
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -27,96 +26,6 @@
typedef CGAL::Cartesian<double> Kernel; typedef CGAL::Cartesian<double> Kernel;
typedef CGAL::Polyhedron_3<Kernel> Polyhedron; 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;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// main() // main()
@ -128,21 +37,19 @@ int main(int argc,char * argv[])
std::cerr << " Floater parameterization" << std::endl; std::cerr << " Floater parameterization" << std::endl;
std::cerr << " Circle border" << std::endl; std::cerr << " Circle border" << std::endl;
std::cerr << " TAUCS solver" << std::endl; std::cerr << " TAUCS solver" << std::endl;
std::cerr << " Output: EPS" << std::endl;
//*************************************** //***************************************
// decode parameters // 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); return(EXIT_FAILURE);
} }
// File names are: // File name is:
const char* input_filename = argv[1]; const char* input_filename = argv[1];
const char* output_filename = argv[2];
//*************************************** //***************************************
// Read the mesh // Read the mesh
@ -159,17 +66,18 @@ int main(int argc,char * argv[])
stream >> mesh; stream >> mesh;
//*************************************** //***************************************
// Create mesh adaptor // Create Polyhedron adaptor
// Note: parameterization methods support only // Note: no cutting => we support only
// meshes that are topological disks // 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); Parameterization_polyhedron_adaptor mesh_adaptor(mesh);
//*************************************** //***************************************
// Floater Mean Value Coordinates parameterizer (circular border) // Floater Mean Value Coordinates parameterization
// with TAUCS solver // (circular border) with TAUCS solver
//*************************************** //***************************************
// Circular border parameterizer (the default) // Circular border parameterizer (the default)
@ -178,8 +86,8 @@ int main(int argc,char * argv[])
// TAUCS solver // TAUCS solver
typedef CGAL::Taucs_solver_traits<double> Solver; typedef CGAL::Taucs_solver_traits<double> Solver;
// Floater Mean Value Coordinates parameterizer (circular border) // Floater Mean Value Coordinates parameterization
// with TAUCS solver // (circular border) with TAUCS solver
typedef CGAL::Mean_value_coordinates_parameterizer_3<Parameterization_polyhedron_adaptor, typedef CGAL::Mean_value_coordinates_parameterizer_3<Parameterization_polyhedron_adaptor,
Border_parameterizer, Border_parameterizer,
Solver> Solver>
@ -193,13 +101,18 @@ int main(int argc,char * argv[])
// Output // Output
//*************************************** //***************************************
// Write Postscript file
if (err == Parameterizer::OK) 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; // (u,v) pair is stored in any halfedge
return EXIT_FAILURE; 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