More optionals for non-nullable maps

This commit is contained in:
JacksonCampolattaro 2023-09-16 18:38:32 +02:00
parent 48b502e5bb
commit c67bec24cc
2 changed files with 25 additions and 29 deletions

View File

@ -24,10 +24,10 @@ template < class TriangleMesh,
class VertexPointMap = typename boost::property_map<TriangleMesh,vertex_point_t>::type > class VertexPointMap = typename boost::property_map<TriangleMesh,vertex_point_t>::type >
struct Triangle_from_face_descriptor_map{ struct Triangle_from_face_descriptor_map{
typename std::remove_const_t<TriangleMesh>* m_tm; typename std::remove_const_t<TriangleMesh>* m_tm;
VertexPointMap m_vpm; std::optional<VertexPointMap> m_vpm;
Triangle_from_face_descriptor_map() Triangle_from_face_descriptor_map()
: m_tm(nullptr) : m_tm(nullptr), m_vpm()
{} {}
Triangle_from_face_descriptor_map(TriangleMesh const* tm) Triangle_from_face_descriptor_map(TriangleMesh const* tm)
@ -58,9 +58,9 @@ struct Triangle_from_face_descriptor_map{
std::remove_const_t<TriangleMesh>& tm = *(pmap.m_tm); std::remove_const_t<TriangleMesh>& tm = *(pmap.m_tm);
CGAL_precondition(halfedge(f,tm) == next(next(next(halfedge(f,tm),tm),tm),tm)); CGAL_precondition(halfedge(f,tm) == next(next(next(halfedge(f,tm),tm),tm),tm));
return value_type( get(pmap.m_vpm, target(halfedge(f,tm),tm)), return value_type( get(*pmap.m_vpm, target(halfedge(f,tm),tm)),
get(pmap.m_vpm, target(next(halfedge(f,tm),tm),tm)), get(*pmap.m_vpm, target(next(halfedge(f,tm),tm),tm)),
get(pmap.m_vpm, source(halfedge(f,tm),tm)) ); get(*pmap.m_vpm, source(halfedge(f,tm),tm)) );
} }
inline friend inline friend
@ -71,9 +71,9 @@ struct Triangle_from_face_descriptor_map{
std::remove_const_t<TriangleMesh> & tm = *(pmap.m_tm); std::remove_const_t<TriangleMesh> & tm = *(pmap.m_tm);
CGAL_precondition(halfedge(f.first,tm) == next(next(next(halfedge(f.first,tm),tm),tm),tm)); CGAL_precondition(halfedge(f.first,tm) == next(next(next(halfedge(f.first,tm),tm),tm),tm));
return value_type( get(pmap.m_vpm, target(halfedge(f.first,tm),tm)), return value_type( get(*pmap.m_vpm, target(halfedge(f.first,tm),tm)),
get(pmap.m_vpm, target(next(halfedge(f.first,tm),tm),tm)), get(*pmap.m_vpm, target(next(halfedge(f.first,tm),tm),tm)),
get(pmap.m_vpm, source(halfedge(f.first,tm),tm)) ); get(*pmap.m_vpm, source(halfedge(f.first,tm),tm)) );
} }
}; };
@ -132,7 +132,7 @@ template <class PolygonMesh,
class VertexPointMap = typename boost::property_map<PolygonMesh,vertex_point_t>::type > class VertexPointMap = typename boost::property_map<PolygonMesh,vertex_point_t>::type >
struct One_point_from_face_descriptor_map{ struct One_point_from_face_descriptor_map{
One_point_from_face_descriptor_map() One_point_from_face_descriptor_map()
: m_pm(nullptr) : m_pm(nullptr), m_vpm()
{} {}
One_point_from_face_descriptor_map(PolygonMesh const * g) One_point_from_face_descriptor_map(PolygonMesh const * g)
@ -146,7 +146,7 @@ struct One_point_from_face_descriptor_map{
{} {}
std::remove_const_t<PolygonMesh>* m_pm; std::remove_const_t<PolygonMesh>* m_pm;
VertexPointMap m_vpm; std::optional<VertexPointMap> m_vpm;
//classical typedefs //classical typedefs
typedef typename boost::graph_traits<PolygonMesh>::face_descriptor key_type; typedef typename boost::graph_traits<PolygonMesh>::face_descriptor key_type;
@ -160,7 +160,7 @@ struct One_point_from_face_descriptor_map{
get(const One_point_from_face_descriptor_map<PolygonMesh,VertexPointMap>& m, get(const One_point_from_face_descriptor_map<PolygonMesh,VertexPointMap>& m,
key_type f) key_type f)
{ {
return get(m.m_vpm, target(halfedge(f, *m.m_pm), *m.m_pm)); return get(*m.m_vpm, target(halfedge(f, *m.m_pm), *m.m_pm));
} }
inline friend inline friend
@ -168,7 +168,7 @@ struct One_point_from_face_descriptor_map{
get(const One_point_from_face_descriptor_map<PolygonMesh,VertexPointMap>& m, get(const One_point_from_face_descriptor_map<PolygonMesh,VertexPointMap>& m,
const std::pair<key_type, const PolygonMesh*>& f) const std::pair<key_type, const PolygonMesh*>& f)
{ {
return get(m.m_vpm, target(halfedge(f.first, *m.m_pm), *m.m_pm)); return get(*m.m_vpm, target(halfedge(f.first, *m.m_pm), *m.m_pm));
} }
}; };

View File

@ -151,8 +151,8 @@ public :
pen.setWidth(0); pen.setWidth(0);
painter->setPen(pen); painter->setPen(pen);
painter->setBrush(brush); painter->setBrush(brush);
SMesh::Property_map<halfedge_descriptor, float> u; std::optional<SMesh::Property_map<halfedge_descriptor, float>> u;
SMesh::Property_map<halfedge_descriptor, float> v; std::optional<SMesh::Property_map<halfedge_descriptor, float>> v;
u = graph->add_property_map<halfedge_descriptor, float> u = graph->add_property_map<halfedge_descriptor, float>
("h:u", 0.0f).first; ("h:u", 0.0f).first;
@ -167,11 +167,11 @@ public :
boost::graph_traits<SMesh>::face_descriptor f(*fi); boost::graph_traits<SMesh>::face_descriptor f(*fi);
QPointF points[3]; QPointF points[3];
boost::graph_traits<SMesh>::halfedge_descriptor h = halfedge(f, *graph);; boost::graph_traits<SMesh>::halfedge_descriptor h = halfedge(f, *graph);;
points[0] = QPointF(get(u, h), -get(v, h)); points[0] = QPointF(get(*u, h), -get(*v, h));
h = next(halfedge(f, *graph), *graph); h = next(halfedge(f, *graph), *graph);
points[1] = QPointF(get(u, h), -get(v, h)); points[1] = QPointF(get(*u, h), -get(*v, h));
h = next(next(halfedge(f, *graph), *graph), *graph); h = next(next(halfedge(f, *graph), *graph), *graph);
points[2] = QPointF(get(u, h), -get(v, h)); points[2] = QPointF(get(*u, h), -get(*v, h));
painter->drawPolygon(points,3); painter->drawPolygon(points,3);
} }
@ -515,7 +515,7 @@ public Q_SLOTS:
sm->add_property_map<SMesh::Vertex_index, Point_3>("v:uv3").first; sm->add_property_map<SMesh::Vertex_index, Point_3>("v:uv3").first;
for(SMesh::Vertex_index v : sm->vertices()) for(SMesh::Vertex_index v : sm->vertices())
{ {
uv_map_3[v] = Point_3(uv_map[v][0], uv_map[v] uv_map_3.value()[v] = Point_3(uv_map[v][0], uv_map[v]
[1], 0); [1], 0);
if(uv_map[v][0] > xmax) if(uv_map[v][0] > xmax)
xmax = uv_map[v][0]; xmax = uv_map[v][0];
@ -582,7 +582,7 @@ public Q_SLOTS:
} }
// build AABB-tree for face location queries // build AABB-tree for face location queries
Tree aabb_tree(faces(*sm).first, faces(*sm).second, *sm, uv_map_3); Tree aabb_tree(faces(*sm).first, faces(*sm).second, *sm, uv_map_3.value());
visu_item = new Scene_polylines_item; visu_item = new Scene_polylines_item;
connect(visu_item, &Scene_polylines_item::aboutToBeDestroyed, this, connect(visu_item, &Scene_polylines_item::aboutToBeDestroyed, this,
@ -609,7 +609,7 @@ public Q_SLOTS:
Face_location loc = Surface_mesh_shortest_path::locate( Face_location loc = Surface_mesh_shortest_path::locate(
Point_3(p_2.x(), p_2.y(), 0), Point_3(p_2.x(), p_2.y(), 0),
aabb_tree, *sm, uv_map_3); aabb_tree, *sm, uv_map_3.value());
visu_item->polylines.back().push_back( visu_item->polylines.back().push_back(
Surface_mesh_shortest_path::point(loc.first, loc.second, *sm, sm->points())); Surface_mesh_shortest_path::point(loc.first, loc.second, *sm, sm->points()));
} }
@ -630,12 +630,8 @@ public Q_SLOTS:
{ {
component->insert(*bfit); component->insert(*bfit);
} }
SMesh::Property_map<halfedge_descriptor, float> umap; auto umap = sm->add_property_map<halfedge_descriptor, float>("h:u", 0.0f).first;
SMesh::Property_map<halfedge_descriptor, float> vmap; auto vmap = sm->add_property_map<halfedge_descriptor, float>("h:v", 0.0f).first;
umap = sm->add_property_map<halfedge_descriptor, float>
("h:u", 0.0f).first;
vmap = sm->add_property_map<halfedge_descriptor, float>
("h:v", 0.0f).first;
SMesh::Halfedge_iterator it; SMesh::Halfedge_iterator it;
SMesh::Property_map<SMesh::Vertex_index, EPICK::Point_2> uv_map = SMesh::Property_map<SMesh::Vertex_index, EPICK::Point_2> uv_map =
sm->property_map<SMesh::Vertex_index, EPICK::Point_2>("v:uv").first; sm->property_map<SMesh::Vertex_index, EPICK::Point_2>("v:uv").first;
@ -886,7 +882,7 @@ private:
TriangleMesh& tm) TriangleMesh& tm)
{ {
Tree aabb_tree(faces(*sm).first, faces(*sm).second, *sm, uv_map_3); Tree aabb_tree(faces(*sm).first, faces(*sm).second, *sm, uv_map_3.value());
typedef typename boost::graph_traits<TriangleMesh>::vertex_descriptor vertex_descriptor; typedef typename boost::graph_traits<TriangleMesh>::vertex_descriptor vertex_descriptor;
typedef std::map<typename CDT::Vertex_handle, vertex_descriptor> Map; typedef std::map<typename CDT::Vertex_handle, vertex_descriptor> Map;
@ -907,7 +903,7 @@ private:
const EPICK::Point_2& pt=fit->vertex(i)->point(); const EPICK::Point_2& pt=fit->vertex(i)->point();
Face_location loc = Surface_mesh_shortest_path::locate( Face_location loc = Surface_mesh_shortest_path::locate(
Point_3(pt.x(), pt.y(), 0), Point_3(pt.x(), pt.y(), 0),
aabb_tree, *sm, uv_map_3); aabb_tree, *sm, uv_map_3.value());
it->second = add_vertex(Surface_mesh_shortest_path::point(loc.first, loc.second, it->second = add_vertex(Surface_mesh_shortest_path::point(loc.first, loc.second,
*sm, sm->points()), tm); *sm, sm->points()), tm);
} }
@ -955,7 +951,7 @@ private:
EPICK::Vector_2 translation; EPICK::Vector_2 translation;
EPICK::Aff_transformation_2 transfo; EPICK::Aff_transformation_2 transfo;
std::vector<std::vector<EPICK::Point_2> > polylines; std::vector<std::vector<EPICK::Point_2> > polylines;
SMesh::Property_map<SMesh::Vertex_index, Point_3> uv_map_3; std::optional<SMesh::Property_map<SMesh::Vertex_index, Point_3>> uv_map_3;
SMesh* sm; SMesh* sm;
float xmin, xmax, ymin, ymax; float xmin, xmax, ymin, ymax;
int pointsize; int pointsize;