mirror of https://github.com/CGAL/cgal
remove the UV parts of the BGL write_PLY and add NPs for the vpm and vimap. Missing doc. Also fix the STL_ASCII reader.
This commit is contained in:
parent
c33e8b60d7
commit
f3dfd786e5
|
|
@ -42,14 +42,14 @@ public:
|
|||
const NamedParameters& np)
|
||||
{
|
||||
typedef typename CGAL::GetVertexPointMap<FaceGraph, NamedParameters>::const_type VPM;
|
||||
typedef typename boost::property_traits<VPM>::reference Point_ref;
|
||||
typedef typename boost::property_traits<VPM>::reference Point_ref;
|
||||
|
||||
typedef typename Polygon_mesh_processing::GetK<FaceGraph, NamedParameters>::Kernel Kernel;
|
||||
typedef typename Kernel::Vector_3 Vector;
|
||||
typedef typename Kernel::Point_2 Texture;
|
||||
typedef CGAL::Color Color;
|
||||
|
||||
typedef typename CGAL::GetVertexPointMap<FaceGraph, NamedParameters>::type VPM;
|
||||
//typedef typename CGAL::GetVertexPointMap<FaceGraph, NamedParameters>::type VPM;
|
||||
|
||||
typedef typename internal_np::Lookup_named_param_def<
|
||||
internal_np::vertex_normal_map_t, NamedParameters,
|
||||
|
|
|
|||
|
|
@ -20,23 +20,25 @@
|
|||
#include <fstream>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
template <class FaceGraph>
|
||||
/*!
|
||||
*TODO
|
||||
*/
|
||||
template <class FaceGraph, class NamedParameters>
|
||||
bool write_PLY(std::ostream& out,
|
||||
const FaceGraph& mesh)
|
||||
const FaceGraph& mesh,
|
||||
const NamedParameters& np,
|
||||
const std::string& comments = std::string())
|
||||
{
|
||||
typedef typename boost::graph_traits<FaceGraph>::vertex_descriptor vertex_descriptor;
|
||||
typedef typename boost::graph_traits<FaceGraph>::halfedge_descriptor halfedge_descriptor;
|
||||
typedef typename boost::graph_traits<FaceGraph>::face_descriptor face_descriptor;
|
||||
typedef typename CGAL::GetInitializedVertexIndexMap<FaceGraph, NamedParameters>::const_type VIMap;
|
||||
typedef typename GetVertexPointMap<FaceGraph, NamedParameters>::const_type Vpm;
|
||||
typedef typename Vpm::value_type Point_3;
|
||||
|
||||
typedef typename boost::property_map<FaceGraph, boost::vertex_point_t>::type::value_type Point_3;
|
||||
|
||||
// @fixme
|
||||
typedef typename FaceGraph::template Property_map<halfedge_descriptor,std::pair<float, float> > UV_map;
|
||||
|
||||
UV_map h_uv;
|
||||
bool has_texture;
|
||||
boost::tie(h_uv, has_texture) = mesh.template property_map<halfedge_descriptor,std::pair<float, float> >("h:uv");
|
||||
VIMap vim = CGAL::get_initialized_vertex_index_map(mesh, np);
|
||||
Vpm vpm = parameters::choose_parameter(parameters::get_parameter(np, internal_np::vertex_point),
|
||||
get_const_property_map(boost::vertex_point, mesh));
|
||||
|
||||
if(!out.good())
|
||||
{
|
||||
|
|
@ -47,33 +49,32 @@ bool write_PLY(std::ostream& out,
|
|||
// Write header
|
||||
out << "ply" << std::endl
|
||||
<< ((get_mode(out) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl
|
||||
<< "comment Generated by the CGAL library" << std::endl
|
||||
<< "element vertex " << num_vertices(mesh) << std::endl;
|
||||
<< "comment Generated by the CGAL library" << std::endl;
|
||||
|
||||
if(comments != std::string())
|
||||
{
|
||||
std::istringstream iss(comments);
|
||||
std::string line;
|
||||
while(getline(iss, line))
|
||||
{
|
||||
if(line != "Generated by the CGAL library") // Avoid repeating the line if multiple savings
|
||||
out << "comment " << line << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
out << "element vertex " << num_vertices(mesh) << std::endl;
|
||||
IO::internal::output_property_header(out, make_ply_point_writer (CGAL::Identity_property_map<Point_3>()));
|
||||
|
||||
out << "element face " << num_faces(mesh) << std::endl;
|
||||
IO::internal::output_property_header(
|
||||
out, std::make_pair(CGAL::Identity_property_map<std::vector<std::size_t> >(),
|
||||
PLY_property<std::vector<int> >("vertex_indices")));
|
||||
|
||||
IO::internal::output_property_header(out, std::make_pair(CGAL::Identity_property_map<std::vector<std::size_t> >(),
|
||||
PLY_property<std::vector<int> >("vertex_indices")));
|
||||
|
||||
if(has_texture)
|
||||
{
|
||||
out << "element halfedge " << num_halfedges(mesh) << std::endl;
|
||||
|
||||
IO::internal::output_property_header(out, std::make_pair(CGAL::Identity_property_map<std::size_t >(),
|
||||
PLY_property<unsigned int >("source")));
|
||||
IO::internal::output_property_header(out, std::make_pair(CGAL::Identity_property_map<std::size_t >(),
|
||||
PLY_property<unsigned int >("target")));
|
||||
IO::internal::output_property_header(out, std::make_tuple(h_uv,
|
||||
PLY_property<float>("u"),
|
||||
PLY_property<float>("v")));
|
||||
}
|
||||
out << "end_header" << std::endl;
|
||||
|
||||
for(vertex_descriptor vd : vertices(mesh))
|
||||
{
|
||||
Point_3 p = get(get(CGAL::vertex_point, mesh), vd);
|
||||
Point_3 p = get(vpm, vd);
|
||||
IO::internal::output_properties(out, &p, make_ply_point_writer (CGAL::Identity_property_map<Point_3>()));
|
||||
}
|
||||
|
||||
|
|
@ -82,38 +83,29 @@ bool write_PLY(std::ostream& out,
|
|||
{
|
||||
polygon.clear();
|
||||
for(halfedge_descriptor hd : halfedges_around_face(halfedge(fd, mesh), mesh))
|
||||
polygon.push_back(get(get(boost::vertex_index, mesh), target(hd,mesh)));
|
||||
|
||||
polygon.push_back(get(vim, target(hd,mesh)));
|
||||
IO::internal::output_properties(out, &polygon,
|
||||
std::make_pair(CGAL::Identity_property_map<std::vector<std::size_t> >(),
|
||||
PLY_property<std::vector<int> >("vertex_indices")));
|
||||
}
|
||||
|
||||
if(has_texture)
|
||||
{
|
||||
for(halfedge_descriptor hd : halfedges(mesh))
|
||||
{
|
||||
typedef std::tuple<unsigned int, unsigned int, float, float> Super_tuple;
|
||||
Super_tuple t = std::make_tuple(source(hd, mesh),target(hd, mesh),
|
||||
h_uv[hd].first,
|
||||
h_uv[hd].second);
|
||||
|
||||
IO::internal::output_properties(out, &t,
|
||||
std::make_pair(Nth_of_tuple_property_map<0,Super_tuple>(),
|
||||
PLY_property<unsigned int >("source")),
|
||||
std::make_pair(Nth_of_tuple_property_map<1,Super_tuple>(),
|
||||
PLY_property<unsigned int >("target")),
|
||||
std::make_pair(Nth_of_tuple_property_map<2,Super_tuple>(),
|
||||
PLY_property<float>("u")),
|
||||
std::make_pair(Nth_of_tuple_property_map<3,Super_tuple>(),
|
||||
PLY_property<float>("v")));
|
||||
}
|
||||
std::make_pair(CGAL::Identity_property_map<std::vector<std::size_t> >(),
|
||||
PLY_property<std::vector<int> >("vertex_indices")));
|
||||
}
|
||||
|
||||
return out.good();
|
||||
}
|
||||
|
||||
// @fixme add overloads
|
||||
template <class FaceGraph, class NamedParameters>
|
||||
bool write_PLY(std::ostream& out,
|
||||
const FaceGraph& mesh,
|
||||
const NamedParameters& np)
|
||||
{
|
||||
return write_PLY(out, mesh, np, "");
|
||||
}
|
||||
|
||||
template <class FaceGraph>
|
||||
bool write_PLY(std::ostream& out,
|
||||
const FaceGraph& mesh)
|
||||
{
|
||||
return write_PLY(out, mesh, parameters::all_default(), "");
|
||||
}
|
||||
|
||||
} // namespace CGAL
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
#include <CGAL/boost/graph/graph_traits_Linear_cell_complex_for_combinatorial_map.h>
|
||||
#include <CGAL/boost/graph/helpers.h>
|
||||
|
||||
#include <CGAL/boost/graph/IO/PLY.h>
|
||||
|
||||
#if defined(CGAL_USE_OPENMESH)
|
||||
|
||||
#include <OpenMesh/Core/IO/MeshIO.hh>
|
||||
|
|
@ -195,10 +197,31 @@ bool test_STL()
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<class FaceGraph>
|
||||
bool test_PLY()
|
||||
{
|
||||
FaceGraph fg;
|
||||
CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0),
|
||||
Point(2, 0, 1), Point(3, 0, 0), fg);
|
||||
std::ostringstream out;
|
||||
CGAL::write_PLY(out, fg);
|
||||
if(out.fail())
|
||||
{
|
||||
std::cerr<<"Tetrahedron writing failed."<<std::endl;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
const char* filename=(argc>1) ? argv[1] : "data/prim.off";
|
||||
|
||||
/*
|
||||
//PLY
|
||||
test_PLY<Polyhedron>();
|
||||
test_PLY<SM>();
|
||||
// OFF
|
||||
test_bgl_read_write<Polyhedron>(filename);
|
||||
test_bgl_read_write<SM>(filename);
|
||||
|
|
@ -214,7 +237,7 @@ int main(int argc, char** argv)
|
|||
return 1;
|
||||
if(!test_gocad<LCC>())
|
||||
return 1;
|
||||
|
||||
*/
|
||||
// STL
|
||||
if(!test_STL<Polyhedron>())
|
||||
return 1;
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ bool parse_ASCII_STL(std::istream& is,
|
|||
return false;
|
||||
}
|
||||
|
||||
return !is.fail();
|
||||
return !in_solid;
|
||||
}
|
||||
|
||||
template <class PointRange, class TriangleRange>
|
||||
|
|
|
|||
Loading…
Reference in New Issue