mirror of https://github.com/CGAL/cgal
new function add_bbox(face_graph) that adds bbox to face graph
the bbox can be : * triangulated or not * tight or not
This commit is contained in:
parent
a484bfa35a
commit
62b8e8fb6f
|
|
@ -15,14 +15,18 @@
|
|||
|
||||
#include <CGAL/license/Polygon_mesh_processing/miscellaneous.h>
|
||||
|
||||
|
||||
#include <CGAL/Bbox_3.h>
|
||||
|
||||
#include <boost/graph/graph_traits.hpp>
|
||||
#include <CGAL/Polygon_mesh_processing/polygon_soup_to_polygon_mesh.h>
|
||||
#include <CGAL/Polygon_mesh_processing/orient_polygon_soup.h>
|
||||
#include <CGAL/boost/graph/copy_face_graph.h>
|
||||
|
||||
#include <boost/graph/graph_traits.hpp>
|
||||
#include <CGAL/Named_function_parameters.h>
|
||||
#include <CGAL/boost/graph/named_params_helper.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace CGAL {
|
||||
|
||||
namespace Polygon_mesh_processing {
|
||||
|
|
@ -255,6 +259,83 @@ namespace CGAL {
|
|||
}
|
||||
return bb;
|
||||
}
|
||||
|
||||
/*!
|
||||
* adds a triangulated bounding box to a polygon mesh
|
||||
* @todo add extended bbox factor
|
||||
* @todo add triangulate or not as NP
|
||||
*/
|
||||
template<typename PolygonMesh,
|
||||
typename NamedParameters = parameters::Default_named_parameters>
|
||||
void add_bbox(PolygonMesh& pmesh,
|
||||
const NamedParameters& np = parameters::default_values())
|
||||
{
|
||||
using parameters::choose_parameter;
|
||||
using parameters::get_parameter;
|
||||
|
||||
typedef typename GetGeomTraits<PolygonMesh, NamedParameters>::type GT;
|
||||
GT gt = choose_parameter<GT>(get_parameter(np, internal_np::geom_traits));
|
||||
typedef typename GT::Point_3 Point_3;
|
||||
|
||||
const double factor = 1.1; //todo : add as NP
|
||||
CGAL::Bbox_3 bb = bbox(pmesh);
|
||||
if (factor != 1.0)
|
||||
{
|
||||
const double dx = bb.xmax() - bb.xmin();
|
||||
const double dy = bb.ymax() - bb.ymin();
|
||||
const double dz = bb.zmax() - bb.zmin();
|
||||
const Point_3 center( bb.xmin() + 0.5 * dx,
|
||||
bb.ymin() + 0.5 * dy,
|
||||
bb.zmin() + 0.5 * dz );
|
||||
bb = Bbox_3( center.x() - factor * 0.5 * dx,
|
||||
center.y() - factor * 0.5 * dy,
|
||||
center.z() - factor * 0.5 * dz,
|
||||
center.x() + factor * 0.5 * dx,
|
||||
center.y() + factor * 0.5 * dy,
|
||||
center.z() + factor * 0.5 * dz );
|
||||
}
|
||||
|
||||
const bool triangulate = true; //todo : add as NP
|
||||
|
||||
const typename GT::Iso_cuboid_3 bbox(bb);
|
||||
std::vector<Point_3> bb_points;
|
||||
for (int i = 0; i < 8; ++i)
|
||||
bb_points.push_back(bbox[i]);
|
||||
|
||||
std::vector<std::vector<std::size_t>> faces;
|
||||
if (!triangulate)
|
||||
{
|
||||
faces.push_back({0, 1, 2, 3});//bottom
|
||||
faces.push_back({4, 5, 6, 7});//top
|
||||
faces.push_back({0, 1, 6, 5});//front
|
||||
faces.push_back({2, 3, 4, 7});//back
|
||||
faces.push_back({1, 2, 7, 6});//right
|
||||
faces.push_back({0, 3, 4, 5});//left
|
||||
}
|
||||
else
|
||||
{
|
||||
faces.push_back({0, 1, 2});//bottom
|
||||
faces.push_back({0, 2, 3});
|
||||
faces.push_back({4, 5, 6});//top
|
||||
faces.push_back({4, 6, 7});
|
||||
faces.push_back({0, 1, 5});//front
|
||||
faces.push_back({1, 5, 6});
|
||||
faces.push_back({2, 3, 4});//back
|
||||
faces.push_back({2, 4, 7});
|
||||
faces.push_back({1, 2, 6});//right
|
||||
faces.push_back({2, 6, 7});
|
||||
faces.push_back({0, 3, 4});//left
|
||||
faces.push_back({0, 4, 5});
|
||||
}
|
||||
|
||||
PolygonMesh bbox_pmesh;
|
||||
orient_polygon_soup(bb_points, faces);
|
||||
polygon_soup_to_polygon_mesh(bb_points, faces, bbox_pmesh);
|
||||
|
||||
CGAL::copy_face_graph(bbox_pmesh, pmesh,
|
||||
parameters::default_values(),
|
||||
np);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue