remved some useless internal code

This commit is contained in:
Dmitry Anisimov 2021-04-13 09:24:45 +02:00
parent f9bdb150a6
commit fa5d4b251a
4 changed files with 0 additions and 344 deletions

View File

@ -1,209 +0,0 @@
// Copyright (c) 2020 GeometryFactory SARL (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL$
// $Id$
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
//
// Author(s) : Dmitry Anisimov
//
#ifndef CGAL_SHAPE_DETECTION_REGION_GROWING_POLYGON_MESH_POLYLINE_GRAPH_POINTS_H
#define CGAL_SHAPE_DETECTION_REGION_GROWING_POLYGON_MESH_POLYLINE_GRAPH_POINTS_H
#include <CGAL/license/Shape_detection.h>
// Boost includes.
#include <CGAL/boost/graph/named_params_helper.h>
#include <CGAL/boost/graph/Named_function_parameters.h>
// Internal includes.
#include <CGAL/Shape_detection/Region_growing/internal/property_map.h>
namespace CGAL {
namespace Shape_detection {
namespace internal {
template<
typename PolygonMesh,
typename FaceRange = typename PolygonMesh::Face_range,
typename VertexRange = typename PolygonMesh::Vertex_range,
typename VertexToPointMap = typename boost::property_map<PolygonMesh, CGAL::vertex_point_t>::type>
class Polyline_graph_points {
private:
struct PVertex {
std::size_t index = std::size_t(-1);
std::set<std::size_t> neighbors;
std::set<std::size_t> regions;
};
public:
using Face_graph = PolygonMesh;
using Face_range = FaceRange;
using Vertex_range = VertexRange;
using Vertex_to_point_map = VertexToPointMap;
using Point_range = std::vector<PVertex>;
using Point_map = internal::Polyline_graph_point_map<PVertex, Vertex_range, Vertex_to_point_map>;
private:
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 Vertex_to_index_map = internal::Item_to_index_property_map<Vertex_range>;
public:
template<typename NamedParameters>
Polyline_graph_points(
const PolygonMesh& pmesh,
const std::vector< std::vector<std::size_t> >& regions,
const NamedParameters& np) :
m_face_graph(pmesh),
m_regions(regions),
m_face_range(faces(m_face_graph)),
m_vertex_range(vertices(m_face_graph)),
m_vertex_to_point_map(parameters::choose_parameter(parameters::get_parameter(
np, internal_np::vertex_point), get_const_property_map(CGAL::vertex_point, pmesh))),
m_face_to_region_map(m_face_range, regions),
m_face_to_index_map(m_face_range),
m_vertex_to_index_map(m_vertex_range),
m_point_map(m_vertex_range, m_vertex_to_point_map) {
CGAL_precondition(m_face_range.size() > 0);
CGAL_precondition(m_vertex_range.size() > 0);
CGAL_precondition(regions.size() > 0);
build_graph();
}
void build_graph() {
clear();
int r1 = -1, r2 = -1;
std::vector<std::size_t> pvertex_map(
m_vertex_range.size(), std::size_t(-1));
for (const auto& edge : edges(m_face_graph)) {
std::tie(r1, r2) = get_regions(edge);
if (r1 == r2) continue;
add_graph_edge(edge, r1, r2, pvertex_map);
}
}
void operator()(
const std::size_t query_index,
std::vector<std::size_t>& neighbors) const {
neighbors.clear();
CGAL_precondition(query_index < m_pvertices.size());
const auto& pvertex = m_pvertices[query_index];
for (const std::size_t neighbor : pvertex.neighbors)
neighbors.push_back(neighbor);
}
const Point_range& point_range() const {
return m_pvertices;
}
const Point_map& point_map() const {
return m_point_map;
}
void clear() {
m_pvertices.clear();
}
void release_memory() {
m_pvertices.shrink_to_fit();
}
private:
const Face_graph& m_face_graph;
const std::vector< std::vector<std::size_t> >& m_regions;
const Face_range m_face_range;
const Vertex_range m_vertex_range;
const Vertex_to_point_map m_vertex_to_point_map;
const Face_to_region_map m_face_to_region_map;
const Face_to_index_map m_face_to_index_map;
const Vertex_to_index_map m_vertex_to_index_map;
const Point_map m_point_map;
Point_range m_pvertices;
template<typename EdgeType>
std::pair<int, int> get_regions(const EdgeType& edge) const {
const auto hedge1 = halfedge(edge, m_face_graph);
const auto hedge2 = opposite(hedge1, m_face_graph);
const auto face1 = face(hedge1, m_face_graph);
const auto face2 = face(hedge2, m_face_graph);
const std::size_t fi1 = get(m_face_to_index_map, face1);
const std::size_t fi2 = get(m_face_to_index_map, face2);
CGAL_precondition(fi1 != fi2);
int r1 = -1, r2 = -1;
if (fi1 != std::size_t(-1))
r1 = get(m_face_to_region_map, fi1);
if (fi2 != std::size_t(-1))
r2 = get(m_face_to_region_map, fi2);
return std::make_pair(r1, r2);
}
template<typename EdgeType>
void add_graph_edge(
const EdgeType& edge, const int region1, const int region2,
std::vector<std::size_t>& pvertex_map) {
const auto s = source(edge, m_face_graph);
const auto t = target(edge, m_face_graph);
const std::size_t vsource = get(m_vertex_to_index_map, s);
const std::size_t vtarget = get(m_vertex_to_index_map, t);
CGAL_precondition(vsource != std::size_t(-1));
CGAL_precondition(vtarget != std::size_t(-1));
CGAL_precondition(vsource != vtarget);
CGAL_precondition(region1 != region2);
CGAL_precondition(
pvertex_map.size() == m_vertex_range.size());
CGAL_precondition(vsource < pvertex_map.size());
if (pvertex_map[vsource] == std::size_t(-1)) { // add new pvertex
pvertex_map[vsource] = m_pvertices.size();
m_pvertices.push_back(PVertex());
m_pvertices.back().index = vsource;
}
CGAL_precondition(vtarget < pvertex_map.size());
if (pvertex_map[vtarget] == std::size_t(-1)) { // add new pvertex
pvertex_map[vtarget] = m_pvertices.size();
m_pvertices.push_back(PVertex());
m_pvertices.back().index = vtarget;
}
// Update pvertex info.
const std::size_t pv1 = pvertex_map[vsource];
const std::size_t pv2 = pvertex_map[vtarget];
CGAL_precondition(pv1 != std::size_t(-1) && pv1 < m_pvertices.size());
CGAL_precondition(pv2 != std::size_t(-1) && pv2 < m_pvertices.size());
auto& pvertex1 = m_pvertices[pv1];
auto& pvertex2 = m_pvertices[pv2];
pvertex1.neighbors.insert(pv2);
pvertex1.regions.insert(region1);
pvertex1.regions.insert(region2);
pvertex2.neighbors.insert(pv1);
pvertex2.regions.insert(region1);
pvertex2.regions.insert(region2);
}
};
} // namespace internal
} // namespace Shape_detection
} // namespace CGAL
#endif // CGAL_SHAPE_DETECTION_REGION_GROWING_POLYGON_MESH_POLYLINE_GRAPH_POINTS_H

View File

@ -174,50 +174,6 @@ namespace internal {
std::vector<int> m_indices;
};
template<
typename KeyType,
typename VertexRange,
typename VertexToPointMap>
class Polyline_graph_point_map {
public:
using Key_type = KeyType;
using Vertex_range = VertexRange;
using Vertex_to_point_map = VertexToPointMap;
using value_type = typename Vertex_to_point_map::value_type;
using reference = const value_type&;
using key_type = Key_type;
using category = boost::lvalue_property_map_tag;
Polyline_graph_point_map() :
m_vertex_range(nullptr),
m_vertex_to_point_map(nullptr)
{ }
Polyline_graph_point_map(
const Vertex_range& vertex_range,
const Vertex_to_point_map& vertex_to_point_map) :
m_vertex_range(std::make_shared<Vertex_range>(vertex_range)),
m_vertex_to_point_map(std::make_shared<Vertex_to_point_map>(vertex_to_point_map))
{ }
reference operator[](const key_type& vertex) const {
CGAL_precondition(vertex.index < m_vertex_range->size());
const auto& key = *(m_vertex_range->begin() + vertex.index);
return get(*m_vertex_to_point_map, key);
}
friend inline reference get(
const Polyline_graph_point_map& pgraph_map, const key_type& key) {
return pgraph_map[key];
}
private:
const std::shared_ptr<Vertex_range> m_vertex_range;
const std::shared_ptr<Vertex_to_point_map> m_vertex_to_point_map;
};
template<
typename KeyType,
typename FaceGraph,

View File

@ -21,7 +21,6 @@ if(EIGEN3_FOUND)
# create_single_source_cgal_program("test_region_growing_on_segment_set.cpp")
create_single_source_cgal_program("test_region_growing_on_polygon_mesh.cpp")
# create_single_source_cgal_program("test_region_growing_on_polyline.cpp")
create_single_source_cgal_program("test_region_growing_on_polyline_graph.cpp")
create_single_source_cgal_program("test_region_growing_on_point_set_2_with_sorting.cpp")
create_single_source_cgal_program("test_region_growing_on_point_set_3_with_sorting.cpp")
# create_single_source_cgal_program("test_region_growing_on_segment_set_with_sorting.cpp")
@ -38,7 +37,6 @@ if(EIGEN3_FOUND)
# test_region_growing_on_segment_set
test_region_growing_on_polygon_mesh
# test_region_growing_on_polyline
test_region_growing_on_polyline_graph
test_region_growing_on_point_set_2_with_sorting
test_region_growing_on_point_set_3_with_sorting
# test_region_growing_on_segment_set_with_sorting

View File

@ -1,89 +0,0 @@
// STL includes.
#include <vector>
#include <string>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <iterator>
#include <cassert>
// CGAL includes.
#include <CGAL/assertions.h>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/Shape_detection/Region_growing/Region_growing.h>
#include <CGAL/Shape_detection/Region_growing/Region_growing_on_polygon_mesh.h>
#include <CGAL/Shape_detection/Region_growing/Region_growing_on_polyline.h>
#include <CGAL/Shape_detection/Region_growing/internal/Polyline_graph.h>
#include "../../examples/Shape_detection/include/utils.h"
namespace SD = CGAL::Shape_detection;
using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
using Point_3 = typename Kernel::Point_3;
using Surface_mesh = CGAL::Surface_mesh<Point_3>;
using Polyline_graph = CGAL::Shape_detection::internal::Polyline_graph_points<Surface_mesh>;
using Vertex_to_point_map = typename Polyline_graph::Vertex_to_point_map;
using Point_range = typename Polyline_graph::Point_range;
using Point_map = typename Polyline_graph::Point_map;
using Region_type = CGAL::Shape_detection::Polyline::Least_squares_line_fit_region<Kernel, Point_range, Point_map>;
using Sorting = CGAL::Shape_detection::Polyline::Least_squares_line_fit_sorting<Kernel, Point_range, Polyline_graph, Point_map>;
using Region_growing = CGAL::Shape_detection::Region_growing<Point_range, Polyline_graph, Region_type, typename Sorting::Seed_map>;
int main(int argc, char *argv[]) {
// Load data.
std::ifstream in(argc > 1 ? argv[1] : "data/am.off");
CGAL::set_ascii_mode(in);
assert(in);
Surface_mesh surface_mesh;
in >> surface_mesh;
in.close();
// std::cout << "- num faces: " << faces(surface_mesh).size() << std::endl;
// std::cout << "- num vertices: " << vertices(surface_mesh).size() << std::endl;
assert(faces(surface_mesh).size() == 7320);
assert(vertices(surface_mesh).size() == 3662);
std::vector< std::vector<std::size_t> > regions;
CGAL::Shape_detection::internal::region_growing_planes(
surface_mesh, std::back_inserter(regions));
// std::cout << "- num regions: " << regions.size() << std::endl;
assert(regions.size() == 9);
// std::string fullpath = (argc > 2 ? argv[2] : "regions_sm.ply");
// utils::save_polygon_mesh_regions(surface_mesh, regions, fullpath);
const Vertex_to_point_map vertex_to_point_map(
get(CGAL::vertex_point, surface_mesh));
Polyline_graph pgraph(surface_mesh, regions,
CGAL::parameters::vertex_point_map(vertex_to_point_map));
const auto& point_range = pgraph.point_range();
// std::cout << "- num extracted points: " << point_range.size() << std::endl;
Region_type region_type(
point_range, CGAL::parameters::point_map(pgraph.point_map()));
Sorting sorting(point_range, pgraph, CGAL::parameters::point_map(pgraph.point_map()));
sorting.sort();
Region_growing region_growing(
point_range, pgraph, region_type, sorting.seed_map());
std::vector< std::vector<std::size_t> > subregions;
region_growing.detect(std::back_inserter(subregions));
// std::cout << "- num subregions: " << subregions.size() << std::endl;
assert(subregions.size() == 21);
// fullpath = (argc > 2 ? argv[2] : "subregions_sm.ply");
// utils::save_point_regions_3<Kernel, Point_range, Point_map>(
// point_range, subregions, fullpath, pgraph.point_map());
std::cout << "rg_pgraph, epick_test_success: " << true << std::endl;
return EXIT_SUCCESS;
}