|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# Copyright (c) 2019 - 2022 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 | +import os, sys, platform |
| 23 | +if sys.version_info >= (3,8,0) and platform.system() == "Windows": |
| 24 | + for path in [x.strip() for x in os.environ['PATH'].split(';') if x]: |
| 25 | + os.add_dll_directory(path) |
| 26 | + |
| 27 | +import opengeode |
| 28 | +import opengeode_inspector_py_inspector as inspector |
| 29 | + |
| 30 | +def check_components_linking( section_inspector ): |
| 31 | + nb_unlinked_corners = section_inspector.nb_corners_not_linked_to_a_unique_vertex() |
| 32 | + print( "There are ", nb_unlinked_corners, " corners not linked to a unique vertex." ) |
| 33 | + nb_unlinked_lines = section_inspector.nb_lines_meshed_but_not_linked_to_a_unique_vertex() |
| 34 | + print( "There are ", nb_unlinked_lines, " lines meshed but not linked to a unique vertex." ) |
| 35 | + nb_unlinked_surfaces = section_inspector.nb_surfaces_meshed_but_not_linked_to_a_unique_vertex() |
| 36 | + print( "There are ", nb_unlinked_surfaces, " surfaces meshed but not linked to a unique vertex." ) |
| 37 | + |
| 38 | +def check_invalid_components_topology_unique_vertices( section_inspector ): |
| 39 | + invalid_components_unique_vertices = section_inspector.invalid_components_topology_unique_vertices() |
| 40 | + print( "There are ", len( invalid_components_unique_vertices ), " vertices with invalid components." ) |
| 41 | + for vertex_index in invalid_components_unique_vertices: |
| 42 | + print( "[Test] Model unique vertex with index ", vertex_index, " has invalid components." ) |
| 43 | + |
| 44 | +def check_multiple_corners_unique_vertices( section_inspector ): |
| 45 | + multiple_corners_unique_vertices = section_inspector.multiple_corners_unique_vertices() |
| 46 | + print( "There are ", len( multiple_corners_unique_vertices ), " vertices with multiple corners." ) |
| 47 | + for vertex_index in multiple_corners_unique_vertices: |
| 48 | + print( "[Test] Model unique vertex with index ", vertex_index, " is associated to multiple corners." ) |
| 49 | + |
| 50 | +def check_multiple_internals_corner_vertices( section_inspector ): |
| 51 | + multiple_internals_corner_vertices = section_inspector.multiple_internals_corner_vertices() |
| 52 | + print( "There are ", len( multiple_internals_corner_vertices ), " vertices with multiple internals." ) |
| 53 | + for vertex_index in multiple_internals_corner_vertices: |
| 54 | + print( "[Test] Model unique vertex with index ", vertex_index, " is a corner associated with multiple embeddings." ) |
| 55 | + |
| 56 | +def check_not_internal_nor_boundary_corner_vertices( section_inspector ): |
| 57 | + not_internal_nor_boundary_corner_vertices = section_inspector.not_internal_nor_boundary_corner_vertices() |
| 58 | + print( "There are ", len( not_internal_nor_boundary_corner_vertices ), " corner vertices with no boundary nor internal property." ) |
| 59 | + for vertex_index in not_internal_nor_boundary_corner_vertices: |
| 60 | + print( "[Test] Model unique vertex with index ", vertex_index, " is neither internal nor a boundary." ) |
| 61 | + |
| 62 | +def check_internal_with_multiple_incidences_corner_vertices( section_inspector ): |
| 63 | + internal_with_multiple_incidences_corner_vertices = section_inspector.internal_with_multiple_incidences_corner_vertices() |
| 64 | + print( "There are ", len( internal_with_multiple_incidences_corner_vertices ), " embedded corner vertices with multiple incidences." ) |
| 65 | + for vertex_index in internal_with_multiple_incidences_corner_vertices: |
| 66 | + print( "[Test] Model unique vertex with index ", vertex_index, " is internal but has multiple incidences." ) |
| 67 | + |
| 68 | +def check_line_corners_without_boundary_status( section_inspector ): |
| 69 | + line_corners_without_boundary_status = section_inspector.line_corners_without_boundary_status() |
| 70 | + print( "There are ", len( line_corners_without_boundary_status ), " corner vertices part of a line but not its boundary." ) |
| 71 | + for vertex_index in line_corners_without_boundary_status: |
| 72 | + print( "[Test] Model unique vertex with index ", vertex_index, " is a corner but has a line for which it is not a boundary." ) |
| 73 | + |
| 74 | +def check_part_of_not_boundary_nor_internal_line_unique_vertices( section_inspector ): |
| 75 | + part_of_not_boundary_nor_internal_line_unique_vertices = section_inspector.part_of_not_boundary_nor_internal_line_unique_vertices() |
| 76 | + print( "There are ", len( part_of_not_boundary_nor_internal_line_unique_vertices ), " vertices part of a line which is not boundary not internal." ) |
| 77 | + for vertex_index in part_of_not_boundary_nor_internal_line_unique_vertices: |
| 78 | + print( "[Test] Model unique vertex with index ", vertex_index, " is part of a line which is neither boundary nor internal." ) |
| 79 | + |
| 80 | +def check_part_of_line_with_invalid_internal_topology_unique_vertices( section_inspector ): |
| 81 | + part_of_line_with_invalid_internal_topology_unique_vertices = section_inspector.part_of_line_with_invalid_internal_topology_unique_vertices() |
| 82 | + print( "There are ", len( part_of_line_with_invalid_internal_topology_unique_vertices ), " vertices part of lines with invalid internal property." ) |
| 83 | + for vertex_index in part_of_line_with_invalid_internal_topology_unique_vertices: |
| 84 | + print( "[Test] Model unique vertex with index ", vertex_index, " is part of a line with invalid internal properties." ) |
| 85 | + |
| 86 | +def check_part_of_invalid_unique_line_unique_vertices( section_inspector ): |
| 87 | + part_of_invalid_unique_line_unique_vertices = section_inspector.part_of_invalid_unique_line_unique_vertices() |
| 88 | + print( "There are ", len( part_of_invalid_unique_line_unique_vertices ), " vertices part of a unique line with invalid toplogy." ) |
| 89 | + for vertex_index in part_of_invalid_unique_line_unique_vertices: |
| 90 | + print( "[Test] Model unique vertex with index ", vertex_index, " is part of a unique line with invalid topological properties." ) |
| 91 | + |
| 92 | +def check_part_of_lines_but_not_corner_unique_vertices( section_inspector ): |
| 93 | + part_of_lines_but_not_corner_unique_vertices = section_inspector.part_of_lines_but_not_corner_unique_vertices() |
| 94 | + print( "There are ", len( part_of_lines_but_not_corner_unique_vertices ), " vertices part of multiple lines but not corner." ) |
| 95 | + for vertex_index in part_of_lines_but_not_corner_unique_vertices: |
| 96 | + print( "[Test] Model unique vertex with index ", vertex_index, " is part of multiple lines but is not a corner." ) |
| 97 | + |
| 98 | +def check_part_of_invalid_surfaces_unique_vertices( section_inspector ): |
| 99 | + part_of_invalid_surfaces_unique_vertices = section_inspector.part_of_invalid_surfaces_unique_vertices() |
| 100 | + print( "There are ", len( part_of_invalid_surfaces_unique_vertices ), " vertices with invalid surface topology." ) |
| 101 | + for vertex_index in part_of_invalid_surfaces_unique_vertices: |
| 102 | + print( "[Test] Model unique vertex with index ", vertex_index, " has invalid surfaces topology." ) |
| 103 | + |
| 104 | +def launch_topological_validity_checks( section_inspector ): |
| 105 | + check_components_linking( section_inspector ) |
| 106 | + check_invalid_components_topology_unique_vertices( section_inspector ) |
| 107 | + check_multiple_corners_unique_vertices( section_inspector ) |
| 108 | + check_multiple_internals_corner_vertices( section_inspector ) |
| 109 | + check_not_internal_nor_boundary_corner_vertices( section_inspector ) |
| 110 | + check_internal_with_multiple_incidences_corner_vertices( section_inspector ) |
| 111 | + check_line_corners_without_boundary_status( section_inspector ) |
| 112 | + check_part_of_not_boundary_nor_internal_line_unique_vertices( section_inspector ) |
| 113 | + check_part_of_invalid_unique_line_unique_vertices( section_inspector ) |
| 114 | + check_part_of_invalid_unique_line_unique_vertices( section_inspector ) |
| 115 | + check_part_of_lines_but_not_corner_unique_vertices( section_inspector ) |
| 116 | + check_part_of_invalid_surfaces_unique_vertices( section_inspector ) |
| 117 | + |
| 118 | +def check_a1_vertices_topology(): |
| 119 | + test_dir = os.path.dirname(__file__) |
| 120 | + data_dir = os.path.abspath(os.path.join(test_dir, "../../../tests/data")) |
| 121 | + model_section = opengeode.load_section( data_dir + "/model_A1.og_section" ) |
| 122 | + section_inspector = inspector.BRepTopologyInspector( model_section ) |
| 123 | + if section_inspector.section_topology_is_valid(): |
| 124 | + print( "model_A1 topology is valid." ) |
| 125 | + else: |
| 126 | + print( "model_A1 topology is invalid." ) |
| 127 | + launch_topological_validity_checks( section_inspector ) |
| 128 | + |
| 129 | +def check_a1_valid_vertices_topology(): |
| 130 | + test_dir = os.path.dirname(__file__) |
| 131 | + data_dir = os.path.abspath(os.path.join(test_dir, "../../../tests/data")) |
| 132 | + model_section = opengeode.load_section( data_dir + "/model_A1_valid.og_section" ) |
| 133 | + section_inspector = inspector.BRepTopologyInspector( model_section ) |
| 134 | + if section_inspector.section_topology_is_valid(): |
| 135 | + print( "model_A1_valid topology is valid." ) |
| 136 | + else: |
| 137 | + print( "model_A1_valid topology is invalid." ) |
| 138 | + launch_topological_validity_checks( section_inspector ) |
| 139 | + |
| 140 | +if __name__ == '__main__': |
| 141 | + check_a1_vertices_topology() |
| 142 | + check_a1_valid_vertices_topology() |
0 commit comments