now works with default maps

This commit is contained in:
Dmitry Anisimov 2021-04-13 13:45:09 +02:00
parent fe5e3415e8
commit 1a542135d1
4 changed files with 53 additions and 42 deletions

View File

@ -66,7 +66,16 @@ namespace Polygon_mesh {
using Face_graph = PolygonMesh;
using Face_range = FaceRange;
using Vertex_to_point_map = VertexToPointMap;
using Face_to_region_map = internal::Item_to_region_index_map;
using Face_to_index_map = internal::Item_to_index_property_map<Face_range>;
using Face_to_region_index_map = internal::Item_to_region_index_map<Face_to_index_map>;
struct Face_to_region_map : public Face_to_region_index_map {
template<typename Regions>
Face_to_region_map(const Face_range& face_range, const Regions& regions) :
Face_to_region_index_map(face_range, Face_to_index_map(face_range), regions)
{ }
};
/// \endcond
/// Number type.

View File

@ -69,7 +69,7 @@ namespace Polygon_mesh {
std::size_t index = std::size_t(-1);
std::set<std::size_t> sneighbors;
std::set<std::size_t> tneighbors;
std::pair<int, int> regions;
std::pair<long, long> regions;
};
public:
@ -179,7 +179,7 @@ namespace Polygon_mesh {
void build_graph() {
clear();
int r1 = -1, r2 = -1;
long r1 = -1, r2 = -1;
std::vector<std::size_t> pedge_map(
m_edge_range.size(), std::size_t(-1));
for (const auto& edge : m_edge_range) {
@ -301,7 +301,7 @@ namespace Polygon_mesh {
\pre `query_index < segment_range().size()`
*/
const std::pair<int, int>& edge_regions(
const std::pair<long, long>& edge_regions(
const std::size_t query_index) const {
CGAL_precondition(query_index < segment_range().size());
@ -334,7 +334,7 @@ namespace Polygon_mesh {
std::vector<PEdge> m_pedges;
template<typename EdgeType>
std::pair<int, int> get_regions(const EdgeType& edge) const {
std::pair<long, long> get_regions(const EdgeType& edge) const {
const auto hedge1 = halfedge(edge, m_face_graph);
const auto hedge2 = opposite(hedge1, m_face_graph);
@ -346,17 +346,17 @@ namespace Polygon_mesh {
const std::size_t fi2 = get(m_face_to_index_map, face2);
CGAL_precondition(fi1 != fi2);
int r1 = -1, r2 = -1;
long r1 = -1, r2 = -1;
if (fi1 != std::size_t(-1))
r1 = get(m_face_to_region_map, fi1);
r1 = get(m_face_to_region_map, face1);
if (fi2 != std::size_t(-1))
r2 = get(m_face_to_region_map, fi2);
r2 = get(m_face_to_region_map, face2);
return std::make_pair(r1, r2);
}
template<typename EdgeType>
void add_graph_edge(
const EdgeType& edge, const int region1, const int region2,
const EdgeType& edge, const long region1, const long region2,
std::vector<std::size_t>& pedge_map) {
PEdge pedge;

View File

@ -42,17 +42,14 @@ namespace internal {
class Item_property_map {
public:
using Item_range = ItemRange;
using Property_map = PropertyMap;
using value_type = typename Property_map::value_type;
using reference = const value_type&;
using key_type = std::size_t;
using value_type = typename PropertyMap::value_type;
using reference = const value_type&;
using category = boost::lvalue_property_map_tag;
Item_property_map(
const Item_range& item_range,
const Property_map& property_map) :
const ItemRange& item_range,
const PropertyMap& property_map) :
m_item_range(item_range),
m_property_map(property_map)
{ }
@ -69,26 +66,20 @@ namespace internal {
}
private:
const Item_range& m_item_range;
const Property_map& m_property_map;
const ItemRange& m_item_range;
const PropertyMap& m_property_map;
};
template<typename ItemRange>
class Item_to_index_property_map {
public:
using Item_range = ItemRange;
using Iterator = typename Item_range::const_iterator;
using Item = typename Iterator::value_type;
using key_type = typename ItemRange::const_iterator::value_type;
using value_type = std::size_t;
using key_type = Item;
using reference = value_type;
using category = boost::readable_property_map_tag;
using Item_map = std::map<key_type, value_type>;
Item_to_index_property_map(const Item_range& item_range) :
Item_to_index_property_map(const ItemRange& item_range) :
m_item_range(item_range) {
value_type i = 0;
@ -112,8 +103,8 @@ namespace internal {
}
private:
const Item_range& m_item_range;
Item_map m_item_map;
const ItemRange& m_item_range;
std::map<key_type, value_type> m_item_map;
};
class Seed_property_map {
@ -121,6 +112,7 @@ namespace internal {
public:
using key_type = std::size_t;
using value_type = std::size_t;
using reference = value_type;
using category = boost::readable_property_map_tag;
Seed_property_map(
@ -141,41 +133,52 @@ namespace internal {
const std::vector<std::size_t>& m_seeds;
};
template<typename ItemToIndexMap>
class Item_to_region_index_map {
public:
using key_type = std::size_t;
using value_type = int;
using key_type = typename ItemToIndexMap::key_type;
using value_type = long;
using reference = value_type;
using category = boost::readable_property_map_tag;
Item_to_region_index_map() { }
Item_to_region_index_map() :
m_item_to_index_map(nullptr)
{ }
template<typename ItemRange>
template<typename ItemRange, typename RegionRange>
Item_to_region_index_map(
const ItemRange& items,
const std::vector< std::vector<std::size_t> >& regions) :
const ItemToIndexMap& item_to_index_map,
const RegionRange& regions) :
m_item_to_index_map(std::make_shared<ItemToIndexMap>(item_to_index_map)),
m_indices(items.size(), -1) {
for (std::size_t i = 0; i < regions.size(); ++i) {
for (const std::size_t index : regions[i]) {
long region_index = 0;
for (const auto& region : regions) {
for (const auto index : region) {
CGAL_precondition(index < m_indices.size());
m_indices[index] = static_cast<int>(i);
m_indices[index] = region_index;
}
++region_index;
}
CGAL_precondition(region_index == static_cast<long>(regions.size()));
}
inline friend value_type get(
const Item_to_region_index_map& item_to_region_index_map,
const key_type key) {
const key_type& key) {
const auto& indices = item_to_region_index_map.m_indices;
CGAL_precondition(key < indices.size());
return indices[key];
const auto& item_to_index_map = item_to_region_index_map.m_item_to_index_map;
const std::size_t item_index = get(*item_to_index_map, key);
CGAL_precondition(item_index < indices.size());
return indices[item_index];
}
private:
std::vector<int> m_indices;
const std::shared_ptr<ItemToIndexMap> m_item_to_index_map;
std::vector<long> m_indices;
};
} // namespace internal

View File

@ -1,4 +1,3 @@
- make a better version of the Polyline_graph where I return a filtered set of original edges instead of PEdge
- update the polyhedron demo
- ---- submission ----
- add new tests: polyline (2D, 3D), polyline with sorting (2D, 3D), free functions, randomness, strict tests on the data from PMP, tests similar to the basic_example, check polylines with equal points