mirror of https://github.com/CGAL/cgal
add a writing function for meshes
This commit is contained in:
parent
ef17e71efa
commit
5c6f20e1ec
|
|
@ -1004,8 +1004,6 @@ void MainWindow::reloadItem() {
|
|||
if(!ok)
|
||||
return;
|
||||
QVariant varian = item->property("load_mates");
|
||||
if (!varian.canConvert<QVariantList>())
|
||||
qDebug()<<"Well, that's gonna be a problem !";
|
||||
QSequentialIterable iterable = varian.value<QSequentialIterable>();
|
||||
// Can use foreach:
|
||||
int mate_id = 0;
|
||||
|
|
@ -1013,8 +1011,6 @@ void MainWindow::reloadItem() {
|
|||
{
|
||||
Scene_item* mate = v.value<Scene_item*>();
|
||||
Scene_item* new_item = new_items[mate_id];
|
||||
if(!new_item)
|
||||
qDebug()<<"That too, is gonna be a problem...";
|
||||
new_item->setName(mate->name());
|
||||
new_item->setColor(mate->color());
|
||||
new_item->setRenderingMode(mate->renderingMode());
|
||||
|
|
|
|||
|
|
@ -169,7 +169,6 @@ class Io_3mf_plugin:
|
|||
}
|
||||
if(need_pmap)
|
||||
{
|
||||
//todo: check if possibility to store pid as property or not
|
||||
SMesh::Property_map<face_descriptor,CGAL::Color> fcolor =
|
||||
mesh.add_property_map<face_descriptor,CGAL::Color>("f:color",first).first;
|
||||
for(std::size_t pid = 0; pid < colors.size(); ++pid)
|
||||
|
|
|
|||
|
|
@ -23,7 +23,11 @@
|
|||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <CGAL/IO/Color.h>
|
||||
|
||||
#include "Model/COM/NMR_DLLInterfaces.h"
|
||||
|
||||
namespace CGAL{
|
||||
namespace tmf_internal{
|
||||
// Utility functions to create vertices and triangles
|
||||
|
|
@ -347,8 +351,8 @@ bool write_polyline_to_model(const PointRange& points,
|
|||
}
|
||||
|
||||
/*!
|
||||
* \brief write_soups_to_3mf will write the polygon soups contained in all_points and
|
||||
* all_polygons into the file named `file_name`, in the 3mf format.
|
||||
* \brief writes the triangle soups contained in `all_points` and
|
||||
* `all_polygons` into the 3mf file `file_name`.
|
||||
* \tparam PointRanges a model of the concepts `RandomAccessContainer` and
|
||||
* `BackInsertionSequence` whose `value type` is
|
||||
* a model of the concepts `RandomAccessContainer` and `BackInsertionSequence`
|
||||
|
|
@ -366,7 +370,7 @@ bool write_polyline_to_model(const PointRange& points,
|
|||
* \return `true` if the writing is successful, `false` otherwise.
|
||||
*/
|
||||
template<typename PointRanges, typename PolygonRanges>
|
||||
bool write_soups_to_3mf(const std::string& file_name,
|
||||
bool write_triangle_soups_to_3mf(const std::string& file_name,
|
||||
const PointRanges& all_points,
|
||||
const PolygonRanges& all_polygons,
|
||||
const std::vector<std::string>& names)
|
||||
|
|
@ -393,11 +397,72 @@ bool write_soups_to_3mf(const std::string& file_name,
|
|||
}
|
||||
else
|
||||
name = std::string("");
|
||||
write_mesh_to_model(all_points[id], all_polygons[id], name, &pMeshObject, pModel);
|
||||
add_build_item(pModel, pMeshObject);
|
||||
//write_mesh_object_to_model(pModel, pMeshObject);
|
||||
std::vector<CGAL::Color> colors(all_polygons[id].size());
|
||||
write_mesh_to_model(all_points[id], all_polygons[id], colors, name, &pMeshObject, pModel);
|
||||
}
|
||||
return export_model_to_file(file_name, pModel);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief writes the triangle meshes contained in `tms`
|
||||
* into the 3mf file `file_name`.
|
||||
* \tparam TriangleMeshRange a model of the concepts `RandomAccessContainer`
|
||||
* and `BackInsertionSequence` whose `value type` is
|
||||
* a model of the concepts `FaceListGraph` and `HalfedgeListGraph`
|
||||
* that has only triangle faces.
|
||||
* \param file_name the name of the 3mf file to write.
|
||||
* \param tms a `TriangleMeshRange` that contains the meshes
|
||||
* to write. An internal property map for `CGAL::vertex_point_t`
|
||||
* must be available for each mesh.
|
||||
* \param names will contains the name of each mesh in `file_name`.
|
||||
* \return `true` if the writing is successful, `false` otherwise.
|
||||
*/
|
||||
template<typename TriangleMeshRange>
|
||||
bool write_triangle_meshes_to_3mf(const std::string& file_name,
|
||||
const TriangleMeshRange& tms,
|
||||
const std::vector<std::string>& names)
|
||||
{
|
||||
typedef typename TriangleMeshRange::value_type Mesh;
|
||||
typedef typename boost::property_map<Mesh, boost::vertex_point_t>::type VPMap;
|
||||
typedef typename boost::property_traits<VPMap>::value_type Point_3;
|
||||
|
||||
typedef std::vector<std::size_t> Polygon;
|
||||
typedef std::vector<Polygon> PolygonRange;
|
||||
|
||||
typedef std::vector<Point_3> PointRange;
|
||||
|
||||
std::vector<PointRange> all_points;
|
||||
std::vector<PolygonRange> all_polygons;
|
||||
|
||||
|
||||
for(auto tm : tms)
|
||||
{
|
||||
PointRange points;
|
||||
PolygonRange triangles;
|
||||
VPMap vpm = get(boost::vertex_point, tm);
|
||||
std::unordered_map<typename boost::graph_traits<Mesh>::vertex_descriptor,
|
||||
std::size_t> vertex_id_map;
|
||||
std::size_t i = 0;
|
||||
for(auto v : vertices(tm))
|
||||
{
|
||||
points.push_back(get(vpm, v));
|
||||
vertex_id_map[v] = i++;
|
||||
}
|
||||
all_points.push_back(points);
|
||||
for(auto f : faces(tm))
|
||||
{
|
||||
Polygon triangle;
|
||||
for(auto vert : CGAL::vertices_around_face(halfedge(f, tm), tm))
|
||||
{
|
||||
triangle.push_back(vertex_id_map[vert]);
|
||||
}
|
||||
triangles.push_back(triangle);
|
||||
}
|
||||
all_polygons.push_back(triangles);
|
||||
}
|
||||
|
||||
return write_triangle_soups_to_3mf(file_name, all_points, all_polygons, names);
|
||||
}
|
||||
}//end CGAL
|
||||
#endif // WRITE_3MF_H
|
||||
|
|
|
|||
|
|
@ -159,6 +159,11 @@ int main(int argc, char** argv)
|
|||
names.push_back(std::string("sphere"));
|
||||
names.push_back(std::string("tube"));
|
||||
|
||||
std::vector<Mesh> meshes(2);
|
||||
meshes[0] = sphere;
|
||||
meshes[1] = tube;
|
||||
CGAL::write_triangle_meshes_to_3mf("meshes.3mf", meshes, names);
|
||||
|
||||
|
||||
//testing of point clouds
|
||||
DWORD nErrorMessage;
|
||||
|
|
|
|||
Loading…
Reference in New Issue