From fa5d4b251aeb1ab669098b1771df77de683c5ba0 Mon Sep 17 00:00:00 2001 From: Dmitry Anisimov Date: Tue, 13 Apr 2021 09:24:45 +0200 Subject: [PATCH] remved some useless internal code --- .../Region_growing/internal/Polyline_graph.h | 209 ------------------ .../Region_growing/internal/property_map.h | 44 ---- .../test/Shape_detection/CMakeLists.txt | 2 - .../test_region_growing_on_polyline_graph.cpp | 89 -------- 4 files changed, 344 deletions(-) delete mode 100644 Shape_detection/include/CGAL/Shape_detection/Region_growing/internal/Polyline_graph.h delete mode 100644 Shape_detection/test/Shape_detection/test_region_growing_on_polyline_graph.cpp diff --git a/Shape_detection/include/CGAL/Shape_detection/Region_growing/internal/Polyline_graph.h b/Shape_detection/include/CGAL/Shape_detection/Region_growing/internal/Polyline_graph.h deleted file mode 100644 index 4d0741a36ba..00000000000 --- a/Shape_detection/include/CGAL/Shape_detection/Region_growing/internal/Polyline_graph.h +++ /dev/null @@ -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 - -// Boost includes. -#include -#include - -// Internal includes. -#include - -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::type> - class Polyline_graph_points { - - private: - struct PVertex { - std::size_t index = std::size_t(-1); - std::set neighbors; - std::set 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; - using Point_map = internal::Polyline_graph_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; - using Vertex_to_index_map = internal::Item_to_index_property_map; - - public: - template - Polyline_graph_points( - const PolygonMesh& pmesh, - const std::vector< std::vector >& 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 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& 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 >& 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 - std::pair 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 - void add_graph_edge( - const EdgeType& edge, const int region1, const int region2, - std::vector& 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 diff --git a/Shape_detection/include/CGAL/Shape_detection/Region_growing/internal/property_map.h b/Shape_detection/include/CGAL/Shape_detection/Region_growing/internal/property_map.h index 3a6b2ae0cd6..e827169a3df 100644 --- a/Shape_detection/include/CGAL/Shape_detection/Region_growing/internal/property_map.h +++ b/Shape_detection/include/CGAL/Shape_detection/Region_growing/internal/property_map.h @@ -174,50 +174,6 @@ namespace internal { std::vector 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)), - m_vertex_to_point_map(std::make_shared(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 m_vertex_range; - const std::shared_ptr m_vertex_to_point_map; - }; - template< typename KeyType, typename FaceGraph, diff --git a/Shape_detection/test/Shape_detection/CMakeLists.txt b/Shape_detection/test/Shape_detection/CMakeLists.txt index f6e96c2f338..4f145b6630b 100644 --- a/Shape_detection/test/Shape_detection/CMakeLists.txt +++ b/Shape_detection/test/Shape_detection/CMakeLists.txt @@ -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 diff --git a/Shape_detection/test/Shape_detection/test_region_growing_on_polyline_graph.cpp b/Shape_detection/test/Shape_detection/test_region_growing_on_polyline_graph.cpp deleted file mode 100644 index 1d9323d94a9..00000000000 --- a/Shape_detection/test/Shape_detection/test_region_growing_on_polyline_graph.cpp +++ /dev/null @@ -1,89 +0,0 @@ -// STL includes. -#include -#include -#include -#include -#include -#include -#include - -// CGAL includes. -#include -#include - -#include - -#include -#include -#include - -#include -#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; -using Polyline_graph = CGAL::Shape_detection::internal::Polyline_graph_points; - -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; -using Sorting = CGAL::Shape_detection::Polyline::Least_squares_line_fit_sorting; -using Region_growing = CGAL::Shape_detection::Region_growing; - -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 > 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 > 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( - // point_range, subregions, fullpath, pgraph.point_map()); - - std::cout << "rg_pgraph, epick_test_success: " << true << std::endl; - return EXIT_SUCCESS; -}