|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# Copyright (c) 2019 - 2023 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 |
| 23 | +import sys |
| 24 | +import platform |
| 25 | +if sys.version_info >= (3, 8, 0) and platform.system() == "Windows": |
| 26 | + for path in [x.strip() for x in os.environ['PATH'].split(';') if x]: |
| 27 | + os.add_dll_directory(path) |
| 28 | + |
| 29 | +import opengeode as geode |
| 30 | +import opengeode_inspector_py_inspector as inspector |
| 31 | + |
| 32 | +def check_intersections2D(): |
| 33 | + surface = geode.TriangulatedSurface2D.create() |
| 34 | + builder = geode.TriangulatedSurfaceBuilder2D.create( surface ) |
| 35 | + builder.create_vertices( 5 ) |
| 36 | + builder.set_point( 0, geode.Point2D( [ 0., 0. ] ) ) |
| 37 | + builder.set_point( 1, geode.Point2D( [ 3., -1. ] ) ) |
| 38 | + builder.set_point( 2, geode.Point2D( [ 3., 3. ] ) ) |
| 39 | + builder.set_point( 3, geode.Point2D( [ 0., -3. ] ) ) |
| 40 | + builder.set_point( 4, geode.Point2D( [ 3., -3. ] ) ) |
| 41 | + builder.create_triangle( [ 0, 1, 2 ] ) |
| 42 | + builder.create_triangle( [ 0, 1, 3 ] ) |
| 43 | + builder.create_triangle( [ 1, 3, 4 ] ) |
| 44 | + builder.set_polygon_adjacent( geode.PolygonEdge( 0, 0 ), 1 ) |
| 45 | + builder.set_polygon_adjacent( geode.PolygonEdge( 1, 0 ), 0 ) |
| 46 | + builder.set_polygon_adjacent( geode.PolygonEdge( 1, 1 ), 2 ) |
| 47 | + builder.set_polygon_adjacent( geode.PolygonEdge( 2, 0 ), 1 ) |
| 48 | + |
| 49 | + curve = geode.EdgedCurve2D.create() |
| 50 | + builder_curve = geode.EdgedCurveBuilder2D.create( curve ) |
| 51 | + builder_curve.create_vertices( 8 ) |
| 52 | + builder_curve.set_point( 0, geode.Point2D( [ 5., 0. ] ) ) |
| 53 | + builder_curve.set_point( 1, geode.Point2D( [ 3., 0. ] ) ) |
| 54 | + builder_curve.set_point( 2, geode.Point2D( [ 2., 0. ] ) ) |
| 55 | + builder_curve.set_point( 3, geode.Point2D( [ 1., 0. ] ) ) |
| 56 | + builder_curve.set_point( 4, geode.Point2D( [ -1., 0. ] ) ) |
| 57 | + builder_curve.set_point( 5, geode.Point2D( [ 0., -3. ] ) ) |
| 58 | + builder_curve.set_point( 6, geode.Point2D( [ 3., -3. ] ) ) |
| 59 | + builder_curve.set_point( 7, geode.Point2D( [ 1.5, -2. ] ) ) |
| 60 | + builder_curve.create_edge_with_vertices( 0, 1 ) |
| 61 | + builder_curve.create_edge_with_vertices( 1, 2 ) |
| 62 | + builder_curve.create_edge_with_vertices( 2, 3 ) |
| 63 | + builder_curve.create_edge_with_vertices( 3, 4 ) |
| 64 | + builder_curve.create_edge_with_vertices( 4, 5 ) |
| 65 | + builder_curve.create_edge_with_vertices( 5, 6 ) |
| 66 | + builder_curve.create_edge_with_vertices( 6, 7 ) |
| 67 | + |
| 68 | + intersections_inspector = inspector.SurfaceCurveIntersections2D( surface, curve ) |
| 69 | + if not intersections_inspector.meshes_have_intersections(): |
| 70 | + raise ValueError( "[Test] 2D Surface and Curve should have intersections." ) |
| 71 | + if not intersections_inspector.nb_intersecting_elements_pair() == 7: |
| 72 | + raise ValueError( "[Test] 2D Surface and Curve should have 7 intersecting elements pair." ) |
| 73 | + |
| 74 | +def check_intersections3D(): |
| 75 | + surface = geode.TriangulatedSurface3D.create() |
| 76 | + builder = geode.TriangulatedSurfaceBuilder3D.create( surface ) |
| 77 | + builder.create_vertices( 5 ) |
| 78 | + builder.set_point( 0, geode.Point3D( [ 0., 0., 0 ] ) ) |
| 79 | + builder.set_point( 1, geode.Point3D( [ 3., -1., 0 ] ) ) |
| 80 | + builder.set_point( 2, geode.Point3D( [ 3., 3., 0 ] ) ) |
| 81 | + builder.set_point( 3, geode.Point3D( [ 0., -3., 0 ] ) ) |
| 82 | + builder.set_point( 4, geode.Point3D( [ 3., -3., 0 ] ) ) |
| 83 | + builder.create_triangle( [ 0, 1, 2 ] ) |
| 84 | + builder.create_triangle( [ 0, 1, 3 ] ) |
| 85 | + builder.create_triangle( [ 1, 3, 4 ] ) |
| 86 | + builder.set_polygon_adjacent( geode.PolygonEdge( 0, 0 ), 1 ) |
| 87 | + builder.set_polygon_adjacent( geode.PolygonEdge( 1, 0 ), 0 ) |
| 88 | + builder.set_polygon_adjacent( geode.PolygonEdge( 1, 1 ), 2 ) |
| 89 | + builder.set_polygon_adjacent( geode.PolygonEdge( 2, 0 ), 1 ) |
| 90 | + |
| 91 | + curve = geode.EdgedCurve3D.create() |
| 92 | + builder_curve = geode.EdgedCurveBuilder3D.create( curve ) |
| 93 | + builder_curve.create_vertices( 9 ) |
| 94 | + builder_curve.set_point( 0, geode.Point3D( [ 5., 0., 1 ] ) ) |
| 95 | + builder_curve.set_point( 1, geode.Point3D( [ 3., 0., 0 ] ) ) |
| 96 | + builder_curve.set_point( 2, geode.Point3D( [ 2., 0., 0 ] ) ) |
| 97 | + builder_curve.set_point( 3, geode.Point3D( [ 1., 0., 0 ] ) ) |
| 98 | + builder_curve.set_point( 4, geode.Point3D( [ -1., 0., 0 ] ) ) |
| 99 | + builder_curve.set_point( 5, geode.Point3D( [ 0., -3., 0 ] ) ) |
| 100 | + builder_curve.set_point( 6, geode.Point3D( [ 3., -3., 0 ] ) ) |
| 101 | + builder_curve.set_point( 7, geode.Point3D( [ 1.5, -2., 2 ] ) ) |
| 102 | + builder_curve.set_point( 8, geode.Point3D( [ 2, -2., -2 ] ) ) |
| 103 | + builder_curve.create_edge_with_vertices( 0, 1 ) |
| 104 | + builder_curve.create_edge_with_vertices( 1, 2 ) |
| 105 | + builder_curve.create_edge_with_vertices( 2, 3 ) |
| 106 | + builder_curve.create_edge_with_vertices( 3, 4 ) |
| 107 | + builder_curve.create_edge_with_vertices( 4, 5 ) |
| 108 | + builder_curve.create_edge_with_vertices( 5, 6 ) |
| 109 | + builder_curve.create_edge_with_vertices( 6, 7 ) |
| 110 | + builder_curve.create_edge_with_vertices( 7, 8 ) |
| 111 | + |
| 112 | + intersections_inspector = inspector.SurfaceCurveIntersections3D(surface, curve ) |
| 113 | + if not intersections_inspector.meshes_have_intersections(): |
| 114 | + raise ValueError( "[Test] 3D Surface and Curve should have intersections." ) |
| 115 | + if not intersections_inspector.nb_intersecting_elements_pair() == 6: |
| 116 | + raise ValueError( "[Test] 3D Surface and Curve should have 6 intersecting elements pair." ) |
| 117 | + |
| 118 | +if __name__ == '__main__': |
| 119 | + inspector.OpenGeodeInspectorInspector.initialize() |
| 120 | + check_intersections2D() |
| 121 | + check_intersections3D() |
0 commit comments