|
| 1 | +/* |
| 2 | + * Copyright (c) 2019 - 2021 Geode-solutions |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + * of this software and associated documentation files (the "Software"), to deal |
| 6 | + * in the Software without restriction, including without limitation the rights |
| 7 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | + * copies of the Software, and to permit persons to whom the Software is |
| 9 | + * furnished to do so, subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in |
| 12 | + * all copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 20 | + * SOFTWARE. |
| 21 | + * |
| 22 | + */ |
| 23 | + |
| 24 | +#include <geode/inspector/criterion/adjacency/surface_adjacency.h> |
| 25 | + |
| 26 | +#include <geode/basic/pimpl_impl.h> |
| 27 | + |
| 28 | +#include <geode/mesh/core/surface_mesh.h> |
| 29 | + |
| 30 | +namespace geode |
| 31 | +{ |
| 32 | + template < index_t dimension > |
| 33 | + class SurfaceMeshAdjacency< dimension >::Impl |
| 34 | + { |
| 35 | + public: |
| 36 | + Impl( const SurfaceMesh< dimension >& mesh ) |
| 37 | + { |
| 38 | + for( const auto polygon_id : Range{ mesh.nb_polygons() } ) |
| 39 | + { |
| 40 | + for( const auto edge_id : |
| 41 | + LRange{ mesh.nb_polygon_edges( polygon_id ) } ) |
| 42 | + { |
| 43 | + const PolygonEdge polygon_edge{ polygon_id, edge_id }; |
| 44 | + if( !mesh.is_edge_on_border( polygon_edge ) |
| 45 | + && !mesh_polygon_edge_has_right_adjacency( |
| 46 | + mesh, polygon_edge ) ) |
| 47 | + { |
| 48 | + polygons_wrong_adjacency_edges_.push_back( |
| 49 | + polygon_edge ); |
| 50 | + } |
| 51 | + } |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + bool mesh_has_wrong_adjacencies() const |
| 56 | + { |
| 57 | + return polygons_wrong_adjacency_edges_.size() > 0; |
| 58 | + } |
| 59 | + |
| 60 | + index_t nb_edges_with_wrong_adjacency() const |
| 61 | + { |
| 62 | + return polygons_wrong_adjacency_edges_.size(); |
| 63 | + } |
| 64 | + |
| 65 | + const std::vector< PolygonEdge >& |
| 66 | + polygon_edges_with_wrong_adjacency() const |
| 67 | + { |
| 68 | + return polygons_wrong_adjacency_edges_; |
| 69 | + } |
| 70 | + |
| 71 | + private: |
| 72 | + bool mesh_polygon_edge_has_right_adjacency( |
| 73 | + const SurfaceMesh< dimension >& mesh, |
| 74 | + const PolygonEdge& polygon_edge ) |
| 75 | + { |
| 76 | + const auto adjacent_polygon = mesh.polygon_adjacent( polygon_edge ); |
| 77 | + const auto polygon_adj_id = adjacent_polygon.value(); |
| 78 | + const auto v0 = mesh.polygon_vertex( polygon_edge ); |
| 79 | + const auto v1 = mesh.polygon_edge_vertex( polygon_edge, 1 ); |
| 80 | + for( const auto e : |
| 81 | + LRange{ mesh.nb_polygon_edges( polygon_adj_id ) } ) |
| 82 | + { |
| 83 | + const PolygonEdge adj_edge{ polygon_adj_id, e }; |
| 84 | + const auto adj_v0 = mesh.polygon_vertex( adj_edge ); |
| 85 | + if( adj_v0 == v1 ) |
| 86 | + { |
| 87 | + const auto adj_v1 = mesh.polygon_edge_vertex( adj_edge, 1 ); |
| 88 | + if( adj_v1 == v0 |
| 89 | + && mesh.polygon_adjacent( adj_edge ) |
| 90 | + == polygon_edge.polygon_id ) |
| 91 | + { |
| 92 | + return true; |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | + return false; |
| 97 | + } |
| 98 | + |
| 99 | + private: |
| 100 | + std::vector< PolygonEdge > polygons_wrong_adjacency_edges_; |
| 101 | + }; |
| 102 | + |
| 103 | + template < index_t dimension > |
| 104 | + SurfaceMeshAdjacency< dimension >::SurfaceMeshAdjacency( |
| 105 | + const SurfaceMesh< dimension >& mesh ) |
| 106 | + : impl_( mesh ) |
| 107 | + { |
| 108 | + } |
| 109 | + |
| 110 | + template < index_t dimension > |
| 111 | + SurfaceMeshAdjacency< dimension >::~SurfaceMeshAdjacency() |
| 112 | + { |
| 113 | + } |
| 114 | + |
| 115 | + template < index_t dimension > |
| 116 | + bool SurfaceMeshAdjacency< dimension >::mesh_has_wrong_adjacencies() const |
| 117 | + { |
| 118 | + return impl_->mesh_has_wrong_adjacencies(); |
| 119 | + } |
| 120 | + |
| 121 | + template < index_t dimension > |
| 122 | + index_t |
| 123 | + SurfaceMeshAdjacency< dimension >::nb_edges_with_wrong_adjacency() const |
| 124 | + { |
| 125 | + return impl_->nb_edges_with_wrong_adjacency(); |
| 126 | + } |
| 127 | + |
| 128 | + template < index_t dimension > |
| 129 | + const std::vector< PolygonEdge >& |
| 130 | + SurfaceMeshAdjacency< dimension >::polygon_edges_with_wrong_adjacency() |
| 131 | + const |
| 132 | + { |
| 133 | + return impl_->polygon_edges_with_wrong_adjacency(); |
| 134 | + } |
| 135 | + |
| 136 | + template class opengeode_inspector_inspector_api SurfaceMeshAdjacency< 2 >; |
| 137 | + template class opengeode_inspector_inspector_api SurfaceMeshAdjacency< 3 >; |
| 138 | +} // namespace geode |
0 commit comments