COMPAS 2.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- compas/__init__.py +274 -0
- compas/__main__.py +31 -0
- compas/_iotools.py +80 -0
- compas/_os.py +746 -0
- compas/colors/__init__.py +14 -0
- compas/colors/cmcrameri/acton.txt +256 -0
- compas/colors/cmcrameri/actonS.txt +100 -0
- compas/colors/cmcrameri/bam.txt +256 -0
- compas/colors/cmcrameri/bamO.txt +256 -0
- compas/colors/cmcrameri/bamako.txt +256 -0
- compas/colors/cmcrameri/bamakoS.txt +100 -0
- compas/colors/cmcrameri/batlow.txt +256 -0
- compas/colors/cmcrameri/batlowK.txt +256 -0
- compas/colors/cmcrameri/batlowS.txt +100 -0
- compas/colors/cmcrameri/batlowW.txt +256 -0
- compas/colors/cmcrameri/berlin.txt +256 -0
- compas/colors/cmcrameri/bilbao.txt +256 -0
- compas/colors/cmcrameri/bilbaoS.txt +100 -0
- compas/colors/cmcrameri/broc.txt +256 -0
- compas/colors/cmcrameri/brocO.txt +256 -0
- compas/colors/cmcrameri/buda.txt +256 -0
- compas/colors/cmcrameri/budaS.txt +100 -0
- compas/colors/cmcrameri/bukavu.txt +256 -0
- compas/colors/cmcrameri/cork.txt +256 -0
- compas/colors/cmcrameri/corkO.txt +256 -0
- compas/colors/cmcrameri/davos.txt +256 -0
- compas/colors/cmcrameri/davosS.txt +100 -0
- compas/colors/cmcrameri/devon.txt +256 -0
- compas/colors/cmcrameri/devonS.txt +100 -0
- compas/colors/cmcrameri/fes.txt +256 -0
- compas/colors/cmcrameri/grayC.txt +256 -0
- compas/colors/cmcrameri/grayCS.txt +100 -0
- compas/colors/cmcrameri/hawaii.txt +256 -0
- compas/colors/cmcrameri/hawaiiS.txt +100 -0
- compas/colors/cmcrameri/imola.txt +256 -0
- compas/colors/cmcrameri/imolaS.txt +100 -0
- compas/colors/cmcrameri/lajolla.txt +256 -0
- compas/colors/cmcrameri/lajollaS.txt +100 -0
- compas/colors/cmcrameri/lapaz.txt +256 -0
- compas/colors/cmcrameri/lapazS.txt +100 -0
- compas/colors/cmcrameri/lisbon.txt +256 -0
- compas/colors/cmcrameri/nuuk.txt +256 -0
- compas/colors/cmcrameri/nuukS.txt +100 -0
- compas/colors/cmcrameri/oleron.txt +256 -0
- compas/colors/cmcrameri/oslo.txt +256 -0
- compas/colors/cmcrameri/osloS.txt +100 -0
- compas/colors/cmcrameri/roma.txt +256 -0
- compas/colors/cmcrameri/romaO.txt +256 -0
- compas/colors/cmcrameri/tofino.txt +256 -0
- compas/colors/cmcrameri/tokyo.txt +256 -0
- compas/colors/cmcrameri/tokyoS.txt +100 -0
- compas/colors/cmcrameri/turku.txt +256 -0
- compas/colors/cmcrameri/turkuS.txt +100 -0
- compas/colors/cmcrameri/vanimo.txt +256 -0
- compas/colors/cmcrameri/vik.txt +256 -0
- compas/colors/cmcrameri/vikO.txt +256 -0
- compas/colors/color.py +1118 -0
- compas/colors/colordict.py +103 -0
- compas/colors/colormap.py +306 -0
- compas/colors/html_colors.py +149 -0
- compas/colors/mpl_colormap.py +1064 -0
- compas/data/__init__.py +31 -0
- compas/data/coercion.py +71 -0
- compas/data/conftest.py +10 -0
- compas/data/data.py +342 -0
- compas/data/encoders.py +240 -0
- compas/data/exceptions.py +2 -0
- compas/data/json.py +240 -0
- compas/data/samples/boxes.obj +250 -0
- compas/data/samples/butt_model.obj +2829 -0
- compas/data/samples/cone.stl +0 -0
- compas/data/samples/cube.off +16 -0
- compas/data/samples/cube_ascii.stl +56114 -0
- compas/data/samples/cube_binary.stl +0 -0
- compas/data/samples/cube_binary_2.stl +0 -0
- compas/data/samples/doosabin.json +1 -0
- compas/data/samples/faces.obj +63 -0
- compas/data/samples/faces_big.obj +9663 -0
- compas/data/samples/faces_reversed.obj +63 -0
- compas/data/samples/fink.obj +135 -0
- compas/data/samples/grid_irregular.obj +303 -0
- compas/data/samples/hypar.obj +148 -0
- compas/data/samples/lines.json +1 -0
- compas/data/samples/lines.obj +282 -0
- compas/data/samples/lines_big.obj +40322 -0
- compas/data/samples/lines_bigger.obj +161282 -0
- compas/data/samples/lines_noleaves.obj +422 -0
- compas/data/samples/mesh.obj +874 -0
- compas/data/samples/mesh_100_faces.json +1893 -0
- compas/data/samples/mesh_110_faces.json +2081 -0
- compas/data/samples/open_edges.obj +424 -0
- compas/data/samples/point.json +1 -0
- compas/data/samples/quadmesh.obj +183 -0
- compas/data/samples/quadmesh_planar.obj +181 -0
- compas/data/samples/saddle.obj +314 -0
- compas/data/samples/spline.obj +72 -0
- compas/data/samples/tubemesh.json +1 -0
- compas/data/samples/tubemesh.obj +378 -0
- compas/data/samples/tubemesh.off +374 -0
- compas/data/samples/tubemesh.ply +551 -0
- compas/data/schema.py +137 -0
- compas/data/validators.py +243 -0
- compas/datastructures/__init__.py +75 -0
- compas/datastructures/_mutablemapping.py +148 -0
- compas/datastructures/assembly/__init__.py +0 -0
- compas/datastructures/assembly/assembly.py +234 -0
- compas/datastructures/assembly/exceptions.py +6 -0
- compas/datastructures/assembly/part.py +228 -0
- compas/datastructures/attributes.py +85 -0
- compas/datastructures/cell_network/__init__.py +0 -0
- compas/datastructures/cell_network/cell_network.py +4190 -0
- compas/datastructures/datastructure.py +309 -0
- compas/datastructures/graph/__init__.py +0 -0
- compas/datastructures/graph/duality.py +197 -0
- compas/datastructures/graph/graph.py +2478 -0
- compas/datastructures/graph/operations/__init__.py +0 -0
- compas/datastructures/graph/operations/join.py +124 -0
- compas/datastructures/graph/operations/split.py +63 -0
- compas/datastructures/graph/planarity.py +292 -0
- compas/datastructures/graph/smoothing.py +59 -0
- compas/datastructures/mesh/__init__.py +0 -0
- compas/datastructures/mesh/conway.py +553 -0
- compas/datastructures/mesh/duality.py +104 -0
- compas/datastructures/mesh/mesh.py +5103 -0
- compas/datastructures/mesh/operations/__init__.py +0 -0
- compas/datastructures/mesh/operations/collapse.py +350 -0
- compas/datastructures/mesh/operations/extrude.py +0 -0
- compas/datastructures/mesh/operations/insert.py +120 -0
- compas/datastructures/mesh/operations/merge.py +83 -0
- compas/datastructures/mesh/operations/split.py +263 -0
- compas/datastructures/mesh/operations/substitute.py +37 -0
- compas/datastructures/mesh/operations/swap.py +62 -0
- compas/datastructures/mesh/operations/weld.py +107 -0
- compas/datastructures/mesh/remesh.py +234 -0
- compas/datastructures/mesh/slice.py +170 -0
- compas/datastructures/mesh/smoothing.py +187 -0
- compas/datastructures/mesh/subdivision.py +754 -0
- compas/datastructures/tree/__init__.py +0 -0
- compas/datastructures/tree/tree.py +504 -0
- compas/datastructures/volmesh/__init__.py +0 -0
- compas/datastructures/volmesh/volmesh.py +4203 -0
- compas/files/__init__.py +27 -0
- compas/files/_xml/__init__.py +0 -0
- compas/files/_xml/xml_cli.py +213 -0
- compas/files/_xml/xml_cpython.py +32 -0
- compas/files/_xml/xml_pre_38.py +58 -0
- compas/files/_xml/xml_shared.py +40 -0
- compas/files/gltf/__init__.py +0 -0
- compas/files/gltf/constants.py +59 -0
- compas/files/gltf/data_classes.py +657 -0
- compas/files/gltf/extensions.py +317 -0
- compas/files/gltf/gltf.py +92 -0
- compas/files/gltf/gltf_children.py +64 -0
- compas/files/gltf/gltf_content.py +615 -0
- compas/files/gltf/gltf_exporter.py +465 -0
- compas/files/gltf/gltf_mesh.py +273 -0
- compas/files/gltf/gltf_node.py +348 -0
- compas/files/gltf/gltf_parser.py +115 -0
- compas/files/gltf/gltf_reader.py +310 -0
- compas/files/gltf/gltf_scene.py +125 -0
- compas/files/gltf/helpers.py +59 -0
- compas/files/obj.py +680 -0
- compas/files/off.py +296 -0
- compas/files/ply.py +697 -0
- compas/files/stl.py +436 -0
- compas/files/xml.py +328 -0
- compas/geometry/__init__.py +772 -0
- compas/geometry/_core/__init__.py +0 -0
- compas/geometry/_core/_algebra.py +2826 -0
- compas/geometry/_core/angles.py +408 -0
- compas/geometry/_core/centroids.py +573 -0
- compas/geometry/_core/distance.py +895 -0
- compas/geometry/_core/normals.py +149 -0
- compas/geometry/_core/nurbs.py +367 -0
- compas/geometry/_core/predicates_2.py +582 -0
- compas/geometry/_core/predicates_3.py +1111 -0
- compas/geometry/_core/quaternions.py +196 -0
- compas/geometry/_core/size.py +204 -0
- compas/geometry/_core/tangent.py +56 -0
- compas/geometry/_core/transformations.py +1121 -0
- compas/geometry/_core/transformations_numpy.py +279 -0
- compas/geometry/bbox.py +145 -0
- compas/geometry/bbox_numpy.py +306 -0
- compas/geometry/bestfit.py +77 -0
- compas/geometry/bestfit_numpy.py +259 -0
- compas/geometry/booleans.py +297 -0
- compas/geometry/booleans_shapely.py +147 -0
- compas/geometry/brep/__init__.py +112 -0
- compas/geometry/brep/brep.py +1131 -0
- compas/geometry/brep/edge.py +302 -0
- compas/geometry/brep/errors.py +22 -0
- compas/geometry/brep/face.py +329 -0
- compas/geometry/brep/loop.py +87 -0
- compas/geometry/brep/trim.py +46 -0
- compas/geometry/brep/vertex.py +46 -0
- compas/geometry/contours.py +32 -0
- compas/geometry/curves/__init__.py +0 -0
- compas/geometry/curves/arc.py +429 -0
- compas/geometry/curves/bezier.py +345 -0
- compas/geometry/curves/circle.py +500 -0
- compas/geometry/curves/conic.py +16 -0
- compas/geometry/curves/curve.py +614 -0
- compas/geometry/curves/ellipse.py +408 -0
- compas/geometry/curves/hyperbola.py +336 -0
- compas/geometry/curves/line.py +431 -0
- compas/geometry/curves/nurbs.py +412 -0
- compas/geometry/curves/parabola.py +256 -0
- compas/geometry/curves/polyline.py +724 -0
- compas/geometry/frame.py +769 -0
- compas/geometry/geometry.py +296 -0
- compas/geometry/hull.py +146 -0
- compas/geometry/hull_numpy.py +82 -0
- compas/geometry/icp_numpy.py +104 -0
- compas/geometry/interpolation_barycentric.py +38 -0
- compas/geometry/interpolation_coons.py +102 -0
- compas/geometry/interpolation_tweening.py +87 -0
- compas/geometry/intersection.py +121 -0
- compas/geometry/intersections.py +1105 -0
- compas/geometry/kdtree.py +153 -0
- compas/geometry/offset.py +208 -0
- compas/geometry/pca_numpy.py +87 -0
- compas/geometry/plane.py +657 -0
- compas/geometry/point.py +664 -0
- compas/geometry/pointcloud.py +409 -0
- compas/geometry/polygon.py +473 -0
- compas/geometry/polyhedron.py +650 -0
- compas/geometry/projection.py +155 -0
- compas/geometry/quadmesh_planarize.py +30 -0
- compas/geometry/quadmesh_planarize_none.py +114 -0
- compas/geometry/quaternion.py +544 -0
- compas/geometry/reflection.py +102 -0
- compas/geometry/rotation.py +354 -0
- compas/geometry/scale.py +100 -0
- compas/geometry/shapes/__init__.py +0 -0
- compas/geometry/shapes/box.py +747 -0
- compas/geometry/shapes/capsule.py +472 -0
- compas/geometry/shapes/cone.py +309 -0
- compas/geometry/shapes/cylinder.py +355 -0
- compas/geometry/shapes/shape.py +300 -0
- compas/geometry/shapes/sphere.py +362 -0
- compas/geometry/shapes/torus.py +294 -0
- compas/geometry/shear.py +115 -0
- compas/geometry/surfaces/__init__.py +0 -0
- compas/geometry/surfaces/conical.py +166 -0
- compas/geometry/surfaces/cylindrical.py +251 -0
- compas/geometry/surfaces/extrusion.py +0 -0
- compas/geometry/surfaces/nurbs.py +380 -0
- compas/geometry/surfaces/planar.py +223 -0
- compas/geometry/surfaces/revolution.py +0 -0
- compas/geometry/surfaces/spherical.py +259 -0
- compas/geometry/surfaces/surface.py +689 -0
- compas/geometry/surfaces/toroidal.py +198 -0
- compas/geometry/transformation.py +554 -0
- compas/geometry/translation.py +104 -0
- compas/geometry/triangulation_delaunay.py +102 -0
- compas/geometry/triangulation_earclip.py +300 -0
- compas/geometry/trimesh_curvature.py +113 -0
- compas/geometry/trimesh_descent_numpy.py +26 -0
- compas/geometry/trimesh_geodistance.py +35 -0
- compas/geometry/trimesh_gradient_numpy.py +74 -0
- compas/geometry/trimesh_isolines.py +41 -0
- compas/geometry/trimesh_matrices.py +31 -0
- compas/geometry/trimesh_matrices_numpy.py +191 -0
- compas/geometry/trimesh_parametrisation.py +55 -0
- compas/geometry/trimesh_pull_points_numpy.py +216 -0
- compas/geometry/trimesh_remeshing.py +97 -0
- compas/geometry/trimesh_samplepoints_numpy.py +108 -0
- compas/geometry/trimesh_slicing.py +28 -0
- compas/geometry/trimesh_smoothing_numpy.py +34 -0
- compas/geometry/vector.py +889 -0
- compas/itertools.py +441 -0
- compas/linalg.py +634 -0
- compas/matrices.py +314 -0
- compas/plugins.py +488 -0
- compas/rpc/__init__.py +20 -0
- compas/rpc/__main__.py +77 -0
- compas/rpc/dispatcher.py +181 -0
- compas/rpc/errors.py +11 -0
- compas/rpc/proxy.py +437 -0
- compas/rpc/server.py +79 -0
- compas/rpc/services/__init__.py +0 -0
- compas/rpc/services/default.py +87 -0
- compas/rpc/services/watcher.py +43 -0
- compas/scene/__init__.py +56 -0
- compas/scene/assemblyobject.py +3 -0
- compas/scene/context.py +154 -0
- compas/scene/descriptors/__init__.py +0 -0
- compas/scene/descriptors/attribute.py +30 -0
- compas/scene/descriptors/color.py +91 -0
- compas/scene/descriptors/colordict.py +101 -0
- compas/scene/descriptors/protocol.py +12 -0
- compas/scene/exceptions.py +7 -0
- compas/scene/geometryobject.py +58 -0
- compas/scene/graphobject.py +173 -0
- compas/scene/meshobject.py +238 -0
- compas/scene/scene.py +144 -0
- compas/scene/sceneobject.py +253 -0
- compas/scene/volmeshobject.py +252 -0
- compas/tolerance.py +879 -0
- compas/topology/__init__.py +45 -0
- compas/topology/combinatorics.py +108 -0
- compas/topology/connectivity.py +129 -0
- compas/topology/orientation.py +204 -0
- compas/topology/traversal.py +567 -0
- compas/utilities/__init__.py +25 -0
- compas/utilities/azync.py +155 -0
- compas/utilities/datetime.py +40 -0
- compas/utilities/decorators.py +136 -0
- compas/utilities/remote.py +54 -0
- compas/utilities/ssh.py +169 -0
- compas-2.1.1.dist-info/AUTHORS.md +42 -0
- compas-2.1.1.dist-info/LICENSE +21 -0
- compas-2.1.1.dist-info/METADATA +132 -0
- compas-2.1.1.dist-info/RECORD +468 -0
- compas-2.1.1.dist-info/WHEEL +5 -0
- compas-2.1.1.dist-info/entry_points.txt +2 -0
- compas-2.1.1.dist-info/top_level.txt +4 -0
- compas_blender/__init__.py +250 -0
- compas_blender/collections.py +130 -0
- compas_blender/conversions/__init__.py +48 -0
- compas_blender/conversions/breps.py +0 -0
- compas_blender/conversions/colors.py +23 -0
- compas_blender/conversions/curves.py +125 -0
- compas_blender/conversions/geometry.py +161 -0
- compas_blender/conversions/meshes.py +148 -0
- compas_blender/conversions/surfaces.py +48 -0
- compas_blender/conversions/transformations.py +46 -0
- compas_blender/data.py +30 -0
- compas_blender/geometry/__init__.py +14 -0
- compas_blender/geometry/booleans.py +100 -0
- compas_blender/install.py +338 -0
- compas_blender/objects.py +326 -0
- compas_blender/print_python_path.py +18 -0
- compas_blender/scene/__init__.py +116 -0
- compas_blender/scene/boxobject.py +64 -0
- compas_blender/scene/capsuleobject.py +73 -0
- compas_blender/scene/circleobject.py +53 -0
- compas_blender/scene/coneobject.py +70 -0
- compas_blender/scene/curveobject.py +58 -0
- compas_blender/scene/cylinderobject.py +70 -0
- compas_blender/scene/frameobject.py +105 -0
- compas_blender/scene/graphobject.py +257 -0
- compas_blender/scene/lineobject.py +60 -0
- compas_blender/scene/meshobject.py +508 -0
- compas_blender/scene/planeobject.py +81 -0
- compas_blender/scene/pointcloudobject.py +67 -0
- compas_blender/scene/pointobject.py +71 -0
- compas_blender/scene/polygonobject.py +57 -0
- compas_blender/scene/polyhedronobject.py +57 -0
- compas_blender/scene/polylineobject.py +54 -0
- compas_blender/scene/sceneobject.py +249 -0
- compas_blender/scene/sphereobject.py +72 -0
- compas_blender/scene/surfaceobject.py +54 -0
- compas_blender/scene/torusobject.py +73 -0
- compas_blender/scene/vectorobject.py +69 -0
- compas_blender/scene/volmeshobject.py +475 -0
- compas_blender/utilities/__init__.py +38 -0
- compas_blender/utilities/drawing.py +768 -0
- compas_ghpython/__init__.py +124 -0
- compas_ghpython/components/Compas_FromJson/code.py +18 -0
- compas_ghpython/components/Compas_Info/code.py +15 -0
- compas_ghpython/components/Compas_RpcCall/code.py +31 -0
- compas_ghpython/components/Compas_ToJson/code.py +19 -0
- compas_ghpython/components/Compas_ToRhinoGeometry/code.py +15 -0
- compas_ghpython/components/__init__.py +99 -0
- compas_ghpython/install.py +29 -0
- compas_ghpython/scene/__init__.py +115 -0
- compas_ghpython/scene/boxobject.py +40 -0
- compas_ghpython/scene/brepobject.py +40 -0
- compas_ghpython/scene/capsuleobject.py +41 -0
- compas_ghpython/scene/circleobject.py +40 -0
- compas_ghpython/scene/coneobject.py +40 -0
- compas_ghpython/scene/curveobject.py +42 -0
- compas_ghpython/scene/cylinderobject.py +38 -0
- compas_ghpython/scene/ellipseobject.py +40 -0
- compas_ghpython/scene/frameobject.py +67 -0
- compas_ghpython/scene/graphobject.py +77 -0
- compas_ghpython/scene/lineobject.py +39 -0
- compas_ghpython/scene/meshobject.py +137 -0
- compas_ghpython/scene/planeobject.py +61 -0
- compas_ghpython/scene/pointobject.py +38 -0
- compas_ghpython/scene/polygonobject.py +48 -0
- compas_ghpython/scene/polyhedronobject.py +48 -0
- compas_ghpython/scene/polylineobject.py +39 -0
- compas_ghpython/scene/sceneobject.py +12 -0
- compas_ghpython/scene/sphereobject.py +39 -0
- compas_ghpython/scene/surfaceobject.py +42 -0
- compas_ghpython/scene/torusobject.py +39 -0
- compas_ghpython/scene/vectorobject.py +51 -0
- compas_ghpython/scene/volmeshobject.py +154 -0
- compas_ghpython/sets.py +83 -0
- compas_ghpython/timer.py +36 -0
- compas_ghpython/uninstall.py +31 -0
- compas_ghpython/utilities/__init__.py +33 -0
- compas_ghpython/utilities/drawing.py +457 -0
- compas_rhino/__init__.py +607 -0
- compas_rhino/conduits/__init__.py +16 -0
- compas_rhino/conduits/base.py +121 -0
- compas_rhino/conduits/faces.py +91 -0
- compas_rhino/conduits/labels.py +102 -0
- compas_rhino/conduits/lines.py +109 -0
- compas_rhino/conduits/points.py +111 -0
- compas_rhino/conversions/__init__.py +168 -0
- compas_rhino/conversions/breps.py +122 -0
- compas_rhino/conversions/curves.py +453 -0
- compas_rhino/conversions/docobjects.py +0 -0
- compas_rhino/conversions/exceptions.py +7 -0
- compas_rhino/conversions/extrusions.py +80 -0
- compas_rhino/conversions/geometry.py +187 -0
- compas_rhino/conversions/meshes.py +281 -0
- compas_rhino/conversions/shapes.py +291 -0
- compas_rhino/conversions/surfaces.py +355 -0
- compas_rhino/conversions/transformations.py +45 -0
- compas_rhino/geometry/__init__.py +44 -0
- compas_rhino/geometry/booleans.py +118 -0
- compas_rhino/geometry/brep/__init__.py +40 -0
- compas_rhino/geometry/brep/brep.py +554 -0
- compas_rhino/geometry/brep/builder.py +184 -0
- compas_rhino/geometry/brep/edge.py +202 -0
- compas_rhino/geometry/brep/face.py +285 -0
- compas_rhino/geometry/brep/loop.py +129 -0
- compas_rhino/geometry/brep/trim.py +99 -0
- compas_rhino/geometry/brep/vertex.py +76 -0
- compas_rhino/geometry/curves/__init__.py +43 -0
- compas_rhino/geometry/curves/curve.py +382 -0
- compas_rhino/geometry/curves/nurbs.py +298 -0
- compas_rhino/geometry/surfaces/__init__.py +50 -0
- compas_rhino/geometry/surfaces/nurbs.py +370 -0
- compas_rhino/geometry/surfaces/surface.py +407 -0
- compas_rhino/geometry/trimesh_curvature.py +344 -0
- compas_rhino/geometry/trimesh_slicing.py +65 -0
- compas_rhino/install.py +382 -0
- compas_rhino/install_plugin.py +169 -0
- compas_rhino/install_with_pip.py +20 -0
- compas_rhino/layers.py +347 -0
- compas_rhino/objects.py +1141 -0
- compas_rhino/print_python_path.py +18 -0
- compas_rhino/scene/__init__.py +123 -0
- compas_rhino/scene/boxobject.py +44 -0
- compas_rhino/scene/brepobject.py +41 -0
- compas_rhino/scene/capsuleobject.py +45 -0
- compas_rhino/scene/circleobject.py +43 -0
- compas_rhino/scene/coneobject.py +43 -0
- compas_rhino/scene/curveobject.py +43 -0
- compas_rhino/scene/cylinderobject.py +43 -0
- compas_rhino/scene/ellipseobject.py +44 -0
- compas_rhino/scene/frameobject.py +99 -0
- compas_rhino/scene/graphobject.py +364 -0
- compas_rhino/scene/helpers.py +33 -0
- compas_rhino/scene/lineobject.py +43 -0
- compas_rhino/scene/meshobject.py +673 -0
- compas_rhino/scene/planeobject.py +71 -0
- compas_rhino/scene/pointobject.py +43 -0
- compas_rhino/scene/polygonobject.py +45 -0
- compas_rhino/scene/polyhedronobject.py +45 -0
- compas_rhino/scene/polylineobject.py +43 -0
- compas_rhino/scene/sceneobject.py +123 -0
- compas_rhino/scene/sphereobject.py +43 -0
- compas_rhino/scene/surfaceobject.py +42 -0
- compas_rhino/scene/torusobject.py +43 -0
- compas_rhino/scene/vectorobject.py +49 -0
- compas_rhino/scene/volmeshobject.py +518 -0
- compas_rhino/ui.py +114 -0
- compas_rhino/uninstall.py +243 -0
- compas_rhino/uninstall_plugin.py +91 -0
- compas_rhino/utilities/__init__.py +37 -0
- compas_rhino/utilities/constructors.py +71 -0
- compas_rhino/utilities/drawing.py +1081 -0
|
@@ -0,0 +1,4203 @@
|
|
|
1
|
+
from __future__ import absolute_import
|
|
2
|
+
from __future__ import division
|
|
3
|
+
from __future__ import print_function
|
|
4
|
+
|
|
5
|
+
from itertools import product
|
|
6
|
+
from random import sample
|
|
7
|
+
|
|
8
|
+
from compas.datastructures import Mesh
|
|
9
|
+
from compas.datastructures.attributes import CellAttributeView
|
|
10
|
+
from compas.datastructures.attributes import EdgeAttributeView
|
|
11
|
+
from compas.datastructures.attributes import FaceAttributeView
|
|
12
|
+
from compas.datastructures.attributes import VertexAttributeView
|
|
13
|
+
from compas.datastructures.datastructure import Datastructure
|
|
14
|
+
from compas.files import OBJ
|
|
15
|
+
from compas.geometry import Box
|
|
16
|
+
from compas.geometry import Line
|
|
17
|
+
from compas.geometry import Point
|
|
18
|
+
from compas.geometry import Polygon
|
|
19
|
+
from compas.geometry import Polyhedron
|
|
20
|
+
from compas.geometry import Vector
|
|
21
|
+
from compas.geometry import add_vectors
|
|
22
|
+
from compas.geometry import bestfit_plane
|
|
23
|
+
from compas.geometry import bounding_box
|
|
24
|
+
from compas.geometry import centroid_points
|
|
25
|
+
from compas.geometry import centroid_polygon
|
|
26
|
+
from compas.geometry import centroid_polyhedron
|
|
27
|
+
from compas.geometry import distance_point_point
|
|
28
|
+
from compas.geometry import length_vector
|
|
29
|
+
from compas.geometry import normal_polygon
|
|
30
|
+
from compas.geometry import normalize_vector
|
|
31
|
+
from compas.geometry import oriented_bounding_box
|
|
32
|
+
from compas.geometry import project_point_plane
|
|
33
|
+
from compas.geometry import scale_vector
|
|
34
|
+
from compas.geometry import subtract_vectors
|
|
35
|
+
from compas.geometry import transform_points
|
|
36
|
+
from compas.itertools import linspace
|
|
37
|
+
from compas.itertools import pairwise
|
|
38
|
+
from compas.tolerance import TOL
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def iter_edges_from_vertices(vertices):
|
|
42
|
+
for i, u in enumerate(vertices):
|
|
43
|
+
j = (i + 1) % len(vertices)
|
|
44
|
+
yield u, vertices[j]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class VolMesh(Datastructure):
|
|
48
|
+
"""Geometric implementation of a face data structure for volumetric meshes.
|
|
49
|
+
|
|
50
|
+
Parameters
|
|
51
|
+
----------
|
|
52
|
+
default_vertex_attributes : dict, optional
|
|
53
|
+
Default values for vertex attributes.
|
|
54
|
+
default_edge_attributes : dict, optional
|
|
55
|
+
Default values for edge attributes.
|
|
56
|
+
default_face_attributes : dict, optional
|
|
57
|
+
Default values for face attributes.
|
|
58
|
+
default_cell_attributes : dict, optional
|
|
59
|
+
Default values for cell attributes.
|
|
60
|
+
name : str, optional
|
|
61
|
+
The name of the volmesh.
|
|
62
|
+
**kwargs : dict, optional
|
|
63
|
+
Additional keyword arguments, which are stored in the attributes dict.
|
|
64
|
+
|
|
65
|
+
Attributes
|
|
66
|
+
----------
|
|
67
|
+
default_vertex_attributes : dict[str, Any]
|
|
68
|
+
Default attributes of the vertices.
|
|
69
|
+
default_edge_attributes : dict[str, Any]
|
|
70
|
+
Default values for edge attributes.
|
|
71
|
+
default_face_attributes : dict[str, Any]
|
|
72
|
+
Default values for face attributes.
|
|
73
|
+
default_cell_attributes : dict[str, Any]
|
|
74
|
+
Default values for cell attributes.
|
|
75
|
+
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
DATASCHEMA = {
|
|
79
|
+
"type": "object",
|
|
80
|
+
"properties": {
|
|
81
|
+
"attributes": {"type": "object"},
|
|
82
|
+
"default_vertex_attributes": {"type": "object"},
|
|
83
|
+
"default_edge_attributes": {"type": "object"},
|
|
84
|
+
"default_face_attributes": {"type": "object"},
|
|
85
|
+
"default_cell_attributes": {"type": "object"},
|
|
86
|
+
"vertex": {
|
|
87
|
+
"type": "object",
|
|
88
|
+
"patternProperties": {"^[0-9]+$": {"type": "object"}},
|
|
89
|
+
"additionalProperties": False,
|
|
90
|
+
},
|
|
91
|
+
"cell": {
|
|
92
|
+
"type": "object",
|
|
93
|
+
"patternProperties": {
|
|
94
|
+
"^[0-9]+$": {
|
|
95
|
+
"type": "array",
|
|
96
|
+
"minItems": 4,
|
|
97
|
+
"items": {
|
|
98
|
+
"type": "array",
|
|
99
|
+
"minItems": 3,
|
|
100
|
+
"items": {"type": "integer", "minimum": 0},
|
|
101
|
+
},
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"additionalProperties": False,
|
|
105
|
+
},
|
|
106
|
+
"edge_data": {
|
|
107
|
+
"type": "object",
|
|
108
|
+
"patternProperties": {"^\\([0-9]+, [0-9]+\\)$": {"type": "object"}},
|
|
109
|
+
"additionalProperties": False,
|
|
110
|
+
},
|
|
111
|
+
"face_data": {
|
|
112
|
+
"type": "object",
|
|
113
|
+
"patternProperties": {"^\\([0-9]+(, [0-9]+){3, }\\)$": {"type": "object"}},
|
|
114
|
+
"additionalProperties": False,
|
|
115
|
+
},
|
|
116
|
+
"cell_data": {
|
|
117
|
+
"type": "object",
|
|
118
|
+
"patternProperties": {"^[0-9]+$": {"type": "object"}},
|
|
119
|
+
"additionalProperties": False,
|
|
120
|
+
},
|
|
121
|
+
"max_vertex": {"type": "number", "minimum": -1},
|
|
122
|
+
"max_face": {"type": "number", "minimum": -1},
|
|
123
|
+
"max_cell": {"type": "number", "minimum": -1},
|
|
124
|
+
},
|
|
125
|
+
"required": [
|
|
126
|
+
"attributes",
|
|
127
|
+
"default_vertex_attributes",
|
|
128
|
+
"default_edge_attributes",
|
|
129
|
+
"default_face_attributes",
|
|
130
|
+
"vertex",
|
|
131
|
+
"cell",
|
|
132
|
+
"edge_data",
|
|
133
|
+
"face_data",
|
|
134
|
+
"cell_data",
|
|
135
|
+
"max_vertex",
|
|
136
|
+
"max_face",
|
|
137
|
+
"max_cell",
|
|
138
|
+
],
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
@property
|
|
142
|
+
def __data__(self):
|
|
143
|
+
_cell = {}
|
|
144
|
+
for c in self._cell:
|
|
145
|
+
faces = []
|
|
146
|
+
for u in sorted(self._cell[c]):
|
|
147
|
+
for v in sorted(self._cell[c][u]):
|
|
148
|
+
faces.append(self._halfface[self._cell[c][u][v]])
|
|
149
|
+
_cell[c] = faces
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
"attributes": self.attributes,
|
|
153
|
+
"default_vertex_attributes": self.default_vertex_attributes,
|
|
154
|
+
"default_edge_attributes": self.default_edge_attributes,
|
|
155
|
+
"default_face_attributes": self.default_face_attributes,
|
|
156
|
+
"default_cell_attributes": self.default_cell_attributes,
|
|
157
|
+
"vertex": {str(vertex): attr for vertex, attr in self._vertex.items()},
|
|
158
|
+
"cell": {str(cell): faces for cell, faces in _cell.items()},
|
|
159
|
+
"edge_data": self._edge_data,
|
|
160
|
+
"face_data": self._face_data,
|
|
161
|
+
"cell_data": {str(cell): attr for cell, attr in self._cell_data},
|
|
162
|
+
"max_vertex": self._max_vertex,
|
|
163
|
+
"max_face": self._max_face,
|
|
164
|
+
"max_cell": self._max_cell,
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
@classmethod
|
|
168
|
+
def __from_data__(cls, data):
|
|
169
|
+
volmesh = cls(
|
|
170
|
+
default_vertex_attributes=data.get("default_vertex_attributes"),
|
|
171
|
+
default_edge_attributes=data.get("default_edge_attributes"),
|
|
172
|
+
default_face_attributes=data.get("default_face_attributes"),
|
|
173
|
+
default_cell_attributes=data.get("default_cell_attributes"),
|
|
174
|
+
)
|
|
175
|
+
volmesh.attributes.update(data["attributes"] or {})
|
|
176
|
+
|
|
177
|
+
vertex = data["vertex"] or {}
|
|
178
|
+
cell = data["cell"] or {}
|
|
179
|
+
edge_data = data.get("edge_data") or {}
|
|
180
|
+
face_data = data.get("face_data") or {}
|
|
181
|
+
cell_data = data.get("cell_data") or {}
|
|
182
|
+
|
|
183
|
+
for key, attr in iter(vertex.items()):
|
|
184
|
+
volmesh.add_vertex(key=key, attr_dict=attr)
|
|
185
|
+
|
|
186
|
+
for ckey, faces in iter(cell.items()):
|
|
187
|
+
volmesh.add_cell(faces, ckey=ckey, attr_dict=cell_data.get(ckey))
|
|
188
|
+
|
|
189
|
+
for edge in edge_data:
|
|
190
|
+
volmesh._edge_data[edge] = edge_data[edge] or {}
|
|
191
|
+
|
|
192
|
+
for face in face_data:
|
|
193
|
+
volmesh._face_data[face] = face_data[face] or {}
|
|
194
|
+
|
|
195
|
+
volmesh._max_vertex = data.get("max_vertex", volmesh._max_vertex)
|
|
196
|
+
volmesh._max_face = data.get("max_face", volmesh._max_face)
|
|
197
|
+
volmesh._max_cell = data.get("max_cell", volmesh._max_cell)
|
|
198
|
+
|
|
199
|
+
return volmesh
|
|
200
|
+
|
|
201
|
+
def __init__(self, default_vertex_attributes=None, default_edge_attributes=None, default_face_attributes=None, default_cell_attributes=None, name=None, **kwargs): # fmt: skip
|
|
202
|
+
super(VolMesh, self).__init__(kwargs, name=name)
|
|
203
|
+
self._max_vertex = -1
|
|
204
|
+
self._max_face = -1
|
|
205
|
+
self._max_cell = -1
|
|
206
|
+
self._vertex = {}
|
|
207
|
+
self._halfface = {}
|
|
208
|
+
self._cell = {}
|
|
209
|
+
self._plane = {}
|
|
210
|
+
self._edge_data = {}
|
|
211
|
+
self._face_data = {}
|
|
212
|
+
self._cell_data = {}
|
|
213
|
+
self.default_vertex_attributes = {"x": 0.0, "y": 0.0, "z": 0.0}
|
|
214
|
+
self.default_edge_attributes = {}
|
|
215
|
+
self.default_face_attributes = {}
|
|
216
|
+
self.default_cell_attributes = {}
|
|
217
|
+
if default_vertex_attributes:
|
|
218
|
+
self.default_vertex_attributes.update(default_vertex_attributes)
|
|
219
|
+
if default_edge_attributes:
|
|
220
|
+
self.default_edge_attributes.update(default_edge_attributes)
|
|
221
|
+
if default_face_attributes:
|
|
222
|
+
self.default_face_attributes.update(default_face_attributes)
|
|
223
|
+
if default_cell_attributes:
|
|
224
|
+
self.default_cell_attributes.update(default_cell_attributes)
|
|
225
|
+
|
|
226
|
+
def __str__(self):
|
|
227
|
+
tpl = "<VolMesh with {} vertices, {} faces, {} cells, {} edges>"
|
|
228
|
+
return tpl.format(
|
|
229
|
+
self.number_of_vertices(),
|
|
230
|
+
self.number_of_faces(),
|
|
231
|
+
self.number_of_cells(),
|
|
232
|
+
self.number_of_edges(),
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
# --------------------------------------------------------------------------
|
|
236
|
+
# Customisation
|
|
237
|
+
# --------------------------------------------------------------------------
|
|
238
|
+
|
|
239
|
+
# --------------------------------------------------------------------------
|
|
240
|
+
# Special properties
|
|
241
|
+
# --------------------------------------------------------------------------
|
|
242
|
+
|
|
243
|
+
# --------------------------------------------------------------------------
|
|
244
|
+
# Constructors
|
|
245
|
+
# --------------------------------------------------------------------------
|
|
246
|
+
|
|
247
|
+
@classmethod
|
|
248
|
+
def from_meshgrid(cls, dx=10, dy=None, dz=None, nx=10, ny=None, nz=None):
|
|
249
|
+
"""Construct a volmesh from a 3D meshgrid.
|
|
250
|
+
|
|
251
|
+
Parameters
|
|
252
|
+
----------
|
|
253
|
+
dx : float, optional
|
|
254
|
+
The size of the grid in the x direction.
|
|
255
|
+
dy : float, optional
|
|
256
|
+
The size of the grid in the y direction.
|
|
257
|
+
Defaults to the value of `dx`.
|
|
258
|
+
dz : float, optional
|
|
259
|
+
The size of the grid in the z direction.
|
|
260
|
+
Defaults to the value of `dx`.
|
|
261
|
+
nx : int, optional
|
|
262
|
+
The number of elements in the x direction.
|
|
263
|
+
ny : int, optional
|
|
264
|
+
The number of elements in the y direction.
|
|
265
|
+
Defaults to the value of `nx`.
|
|
266
|
+
nz : int, optional
|
|
267
|
+
The number of elements in the z direction.
|
|
268
|
+
Defaults to the value of `nx`.
|
|
269
|
+
|
|
270
|
+
Returns
|
|
271
|
+
-------
|
|
272
|
+
:class:`compas.datastructures.VolMesh`
|
|
273
|
+
|
|
274
|
+
See Also
|
|
275
|
+
--------
|
|
276
|
+
:meth:`from_obj`, :meth:`from_vertices_and_cells`
|
|
277
|
+
|
|
278
|
+
"""
|
|
279
|
+
dy = dy or dx
|
|
280
|
+
dz = dz or dx
|
|
281
|
+
ny = ny or nx
|
|
282
|
+
nz = nz or nx
|
|
283
|
+
|
|
284
|
+
vertices = [
|
|
285
|
+
[x, y, z]
|
|
286
|
+
for z, x, y in product(
|
|
287
|
+
linspace(0, dz, nz + 1),
|
|
288
|
+
linspace(0, dx, nx + 1),
|
|
289
|
+
linspace(0, dy, ny + 1),
|
|
290
|
+
)
|
|
291
|
+
]
|
|
292
|
+
cells = []
|
|
293
|
+
for k, i, j in product(range(nz), range(nx), range(ny)):
|
|
294
|
+
a = k * ((nx + 1) * (ny + 1)) + i * (ny + 1) + j
|
|
295
|
+
b = k * ((nx + 1) * (ny + 1)) + (i + 1) * (ny + 1) + j
|
|
296
|
+
c = k * ((nx + 1) * (ny + 1)) + (i + 1) * (ny + 1) + j + 1
|
|
297
|
+
d = k * ((nx + 1) * (ny + 1)) + i * (ny + 1) + j + 1
|
|
298
|
+
aa = (k + 1) * ((nx + 1) * (ny + 1)) + i * (ny + 1) + j
|
|
299
|
+
bb = (k + 1) * ((nx + 1) * (ny + 1)) + (i + 1) * (ny + 1) + j
|
|
300
|
+
cc = (k + 1) * ((nx + 1) * (ny + 1)) + (i + 1) * (ny + 1) + j + 1
|
|
301
|
+
dd = (k + 1) * ((nx + 1) * (ny + 1)) + i * (ny + 1) + j + 1
|
|
302
|
+
bottom = [d, c, b, a]
|
|
303
|
+
front = [a, b, bb, aa]
|
|
304
|
+
right = [b, c, cc, bb]
|
|
305
|
+
left = [a, aa, dd, d]
|
|
306
|
+
back = [c, d, dd, cc]
|
|
307
|
+
top = [aa, bb, cc, dd]
|
|
308
|
+
cells.append([bottom, front, left, back, right, top])
|
|
309
|
+
|
|
310
|
+
return cls.from_vertices_and_cells(vertices, cells)
|
|
311
|
+
|
|
312
|
+
@classmethod
|
|
313
|
+
def from_obj(cls, filepath, precision=None):
|
|
314
|
+
"""Construct a volmesh object from the data described in an OBJ file.
|
|
315
|
+
|
|
316
|
+
Parameters
|
|
317
|
+
----------
|
|
318
|
+
filepath : path string | file-like object | URL string
|
|
319
|
+
A path, a file-like object or a URL pointing to a file.
|
|
320
|
+
precision: str, optional
|
|
321
|
+
The precision of the geometric map that is used to connect the lines.
|
|
322
|
+
|
|
323
|
+
Returns
|
|
324
|
+
-------
|
|
325
|
+
:class:`compas.datastructures.VolMesh`
|
|
326
|
+
A volmesh object.
|
|
327
|
+
|
|
328
|
+
See Also
|
|
329
|
+
--------
|
|
330
|
+
:meth:`to_obj`
|
|
331
|
+
:meth:`from_meshgrid`, :meth:`from_vertices_and_cells`
|
|
332
|
+
:class:`compas.files.OBJ`
|
|
333
|
+
|
|
334
|
+
"""
|
|
335
|
+
obj = OBJ(filepath, precision)
|
|
336
|
+
vertices = obj.parser.vertices or [] # type: ignore
|
|
337
|
+
faces = obj.parser.faces or [] # type: ignore
|
|
338
|
+
groups = obj.parser.groups or [] # type: ignore
|
|
339
|
+
cells = []
|
|
340
|
+
for name in groups:
|
|
341
|
+
group = groups[name]
|
|
342
|
+
cell = []
|
|
343
|
+
for item in group:
|
|
344
|
+
if item[0] != "f":
|
|
345
|
+
continue
|
|
346
|
+
face = faces[item[1]]
|
|
347
|
+
cell.append(face)
|
|
348
|
+
cells.append(cell)
|
|
349
|
+
return cls.from_vertices_and_cells(vertices, cells)
|
|
350
|
+
|
|
351
|
+
@classmethod
|
|
352
|
+
def from_vertices_and_cells(cls, vertices, cells):
|
|
353
|
+
"""Construct a volmesh object from vertices and cells.
|
|
354
|
+
|
|
355
|
+
Parameters
|
|
356
|
+
----------
|
|
357
|
+
vertices : list[list[float]]
|
|
358
|
+
Ordered list of vertices, represented by their XYZ coordinates.
|
|
359
|
+
cells : list[list[list[int]]]
|
|
360
|
+
List of cells defined by their faces.
|
|
361
|
+
|
|
362
|
+
Returns
|
|
363
|
+
-------
|
|
364
|
+
:class:`compas.datastructures.VolMesh`
|
|
365
|
+
A volmesh object.
|
|
366
|
+
|
|
367
|
+
See Also
|
|
368
|
+
--------
|
|
369
|
+
:meth:`to_vertices_and_cells`
|
|
370
|
+
:meth:`from_obj`, :meth:`from_meshgrid`
|
|
371
|
+
|
|
372
|
+
"""
|
|
373
|
+
volmesh = cls()
|
|
374
|
+
for x, y, z in vertices:
|
|
375
|
+
volmesh.add_vertex(x=x, y=y, z=z)
|
|
376
|
+
for cell in cells:
|
|
377
|
+
volmesh.add_cell(cell)
|
|
378
|
+
return volmesh
|
|
379
|
+
|
|
380
|
+
# --------------------------------------------------------------------------
|
|
381
|
+
# Conversions
|
|
382
|
+
# --------------------------------------------------------------------------
|
|
383
|
+
|
|
384
|
+
def to_obj(self, filepath, precision=None, **kwargs):
|
|
385
|
+
"""Write the volmesh to an OBJ file.
|
|
386
|
+
|
|
387
|
+
Parameters
|
|
388
|
+
----------
|
|
389
|
+
filepath : path string | file-like object
|
|
390
|
+
A path or a file-like object pointing to a file.
|
|
391
|
+
precision: str, optional
|
|
392
|
+
The precision of the geometric map that is used to connect the lines.
|
|
393
|
+
unweld : bool, optional
|
|
394
|
+
If True, all faces have their own unique vertices.
|
|
395
|
+
If False, vertices are shared between faces if this is also the case in the mesh.
|
|
396
|
+
Default is False.
|
|
397
|
+
|
|
398
|
+
Returns
|
|
399
|
+
-------
|
|
400
|
+
None
|
|
401
|
+
|
|
402
|
+
See Also
|
|
403
|
+
--------
|
|
404
|
+
:meth:`from_obj`
|
|
405
|
+
|
|
406
|
+
Warnings
|
|
407
|
+
--------
|
|
408
|
+
This function only writes geometric data about the vertices and
|
|
409
|
+
the faces to the file.
|
|
410
|
+
|
|
411
|
+
"""
|
|
412
|
+
obj = OBJ(filepath, precision=precision)
|
|
413
|
+
obj.write(self, **kwargs)
|
|
414
|
+
|
|
415
|
+
def to_vertices_and_cells(self):
|
|
416
|
+
"""Return the vertices and cells of a volmesh.
|
|
417
|
+
|
|
418
|
+
Returns
|
|
419
|
+
-------
|
|
420
|
+
list[list[float]]
|
|
421
|
+
A list of vertices, represented by their XYZ coordinates.
|
|
422
|
+
list[list[list[int]]]
|
|
423
|
+
A list of cells, with each cell a list of faces, and each face a list of vertex indices.
|
|
424
|
+
|
|
425
|
+
See Also
|
|
426
|
+
--------
|
|
427
|
+
:meth:`from_vertices_and_cells`
|
|
428
|
+
|
|
429
|
+
"""
|
|
430
|
+
vertex_index = self.vertex_index()
|
|
431
|
+
vertices = [self.vertex_coordinates(vertex) for vertex in self.vertices()]
|
|
432
|
+
cells = []
|
|
433
|
+
for cell in self.cells():
|
|
434
|
+
faces = [[vertex_index[vertex] for vertex in self.halfface_vertices(face)] for face in self.cell_faces(cell)]
|
|
435
|
+
cells.append(faces)
|
|
436
|
+
return vertices, cells
|
|
437
|
+
|
|
438
|
+
def cell_to_mesh(self, cell):
|
|
439
|
+
"""Construct a mesh object from from a cell of a volmesh.
|
|
440
|
+
|
|
441
|
+
Parameters
|
|
442
|
+
----------
|
|
443
|
+
cell : int
|
|
444
|
+
Identifier of the cell.
|
|
445
|
+
|
|
446
|
+
Returns
|
|
447
|
+
-------
|
|
448
|
+
:class:`compas.datastructures.Mesh`
|
|
449
|
+
A mesh object.
|
|
450
|
+
|
|
451
|
+
See Also
|
|
452
|
+
--------
|
|
453
|
+
:meth:`cell_to_vertices_and_faces`
|
|
454
|
+
|
|
455
|
+
"""
|
|
456
|
+
vertices, faces = self.cell_to_vertices_and_faces(cell)
|
|
457
|
+
return Mesh.from_vertices_and_faces(vertices, faces)
|
|
458
|
+
|
|
459
|
+
def cell_to_vertices_and_faces(self, cell):
|
|
460
|
+
"""Return the vertices and faces of a cell.
|
|
461
|
+
|
|
462
|
+
Parameters
|
|
463
|
+
----------
|
|
464
|
+
cell : int
|
|
465
|
+
Identifier of the cell.
|
|
466
|
+
|
|
467
|
+
Returns
|
|
468
|
+
-------
|
|
469
|
+
list[list[float]]
|
|
470
|
+
A list of vertices, represented by their XYZ coordinates,
|
|
471
|
+
list[list[int]]
|
|
472
|
+
A list of faces, with each face a list of vertex indices.
|
|
473
|
+
|
|
474
|
+
See Also
|
|
475
|
+
--------
|
|
476
|
+
:meth:`cell_to_mesh`
|
|
477
|
+
|
|
478
|
+
"""
|
|
479
|
+
vertices = self.cell_vertices(cell)
|
|
480
|
+
faces = self.cell_faces(cell)
|
|
481
|
+
vertex_index = dict((vertex, index) for index, vertex in enumerate(vertices))
|
|
482
|
+
vertices = [self.vertex_coordinates(vertex) for vertex in vertices]
|
|
483
|
+
faces = [[vertex_index[vertex] for vertex in self.halfface_vertices(face)] for face in faces]
|
|
484
|
+
return vertices, faces
|
|
485
|
+
|
|
486
|
+
# --------------------------------------------------------------------------
|
|
487
|
+
# Helpers
|
|
488
|
+
# --------------------------------------------------------------------------
|
|
489
|
+
|
|
490
|
+
def clear(self):
|
|
491
|
+
"""Clear all the volmesh data.
|
|
492
|
+
|
|
493
|
+
Returns
|
|
494
|
+
-------
|
|
495
|
+
None
|
|
496
|
+
|
|
497
|
+
"""
|
|
498
|
+
del self._vertex
|
|
499
|
+
del self._halfface
|
|
500
|
+
del self._cell
|
|
501
|
+
del self._plane
|
|
502
|
+
del self._edge_data
|
|
503
|
+
del self._face_data
|
|
504
|
+
del self._cell_data
|
|
505
|
+
self._vertex = {}
|
|
506
|
+
self._halfface = {}
|
|
507
|
+
self._cell = {}
|
|
508
|
+
self._plane = {}
|
|
509
|
+
self._edge_data = {}
|
|
510
|
+
self._face_data = {}
|
|
511
|
+
self._cell_data = {}
|
|
512
|
+
self._max_vertex = -1
|
|
513
|
+
self._max_face = -1
|
|
514
|
+
self._max_cell = -1
|
|
515
|
+
|
|
516
|
+
def vertex_sample(self, size=1):
|
|
517
|
+
"""Get the identifiers of a set of random vertices.
|
|
518
|
+
|
|
519
|
+
Parameters
|
|
520
|
+
----------
|
|
521
|
+
size : int, optional
|
|
522
|
+
The size of the sample.
|
|
523
|
+
|
|
524
|
+
Returns
|
|
525
|
+
-------
|
|
526
|
+
list[int]
|
|
527
|
+
The identifiers of the vertices.
|
|
528
|
+
|
|
529
|
+
See Also
|
|
530
|
+
--------
|
|
531
|
+
:meth:`edge_sample`, :meth:`face_sample`, :meth:`cell_sample`
|
|
532
|
+
|
|
533
|
+
"""
|
|
534
|
+
return sample(list(self.vertices()), size)
|
|
535
|
+
|
|
536
|
+
def edge_sample(self, size=1):
|
|
537
|
+
"""Get the identifiers of a set of random edges.
|
|
538
|
+
|
|
539
|
+
Parameters
|
|
540
|
+
----------
|
|
541
|
+
size : int, optional
|
|
542
|
+
The size of the sample.
|
|
543
|
+
|
|
544
|
+
Returns
|
|
545
|
+
-------
|
|
546
|
+
list[tuple[int, int]]
|
|
547
|
+
The identifiers of the edges.
|
|
548
|
+
|
|
549
|
+
See Also
|
|
550
|
+
--------
|
|
551
|
+
:meth:`vertex_sample`, :meth:`face_sample`, :meth:`cell_sample`
|
|
552
|
+
|
|
553
|
+
"""
|
|
554
|
+
return sample(list(self.edges()), size)
|
|
555
|
+
|
|
556
|
+
def face_sample(self, size=1):
|
|
557
|
+
"""Get the identifiers of a set of random faces.
|
|
558
|
+
|
|
559
|
+
Parameters
|
|
560
|
+
----------
|
|
561
|
+
size : int, optional
|
|
562
|
+
The size of the sample.
|
|
563
|
+
|
|
564
|
+
Returns
|
|
565
|
+
-------
|
|
566
|
+
list[int]
|
|
567
|
+
The identifiers of the faces.
|
|
568
|
+
|
|
569
|
+
See Also
|
|
570
|
+
--------
|
|
571
|
+
:meth:`vertex_sample`, :meth:`edge_sample`, :meth:`cell_sample`
|
|
572
|
+
|
|
573
|
+
"""
|
|
574
|
+
return sample(list(self.faces()), size)
|
|
575
|
+
|
|
576
|
+
def cell_sample(self, size=1):
|
|
577
|
+
"""Get the identifiers of a set of random cells.
|
|
578
|
+
|
|
579
|
+
Parameters
|
|
580
|
+
----------
|
|
581
|
+
size : int, optional
|
|
582
|
+
The size of the sample.
|
|
583
|
+
|
|
584
|
+
Returns
|
|
585
|
+
-------
|
|
586
|
+
list[int]
|
|
587
|
+
The identifiers of the cells.
|
|
588
|
+
|
|
589
|
+
See Also
|
|
590
|
+
--------
|
|
591
|
+
:meth:`vertex_sample`, :meth:`edge_sample`, :meth:`face_sample`
|
|
592
|
+
|
|
593
|
+
"""
|
|
594
|
+
return sample(list(self.cells()), size)
|
|
595
|
+
|
|
596
|
+
def vertex_index(self):
|
|
597
|
+
"""Returns a dictionary that maps vertex dictionary keys to the
|
|
598
|
+
corresponding index in a vertex list or array.
|
|
599
|
+
|
|
600
|
+
Returns
|
|
601
|
+
-------
|
|
602
|
+
dict[int, int]
|
|
603
|
+
A dictionary of vertex-index pairs.
|
|
604
|
+
|
|
605
|
+
See Also
|
|
606
|
+
--------
|
|
607
|
+
:meth:`index_vertex`
|
|
608
|
+
|
|
609
|
+
"""
|
|
610
|
+
return {key: index for index, key in enumerate(self.vertices())}
|
|
611
|
+
|
|
612
|
+
def index_vertex(self):
|
|
613
|
+
"""Returns a dictionary that maps the indices of a vertex list to
|
|
614
|
+
keys in the vertex dictionary.
|
|
615
|
+
|
|
616
|
+
Returns
|
|
617
|
+
-------
|
|
618
|
+
dict[int, int]
|
|
619
|
+
A dictionary of index-vertex pairs.
|
|
620
|
+
|
|
621
|
+
See Also
|
|
622
|
+
--------
|
|
623
|
+
:meth:`vertex_index`
|
|
624
|
+
|
|
625
|
+
"""
|
|
626
|
+
return dict(enumerate(self.vertices()))
|
|
627
|
+
|
|
628
|
+
def vertex_gkey(self, precision=None):
|
|
629
|
+
"""Returns a dictionary that maps vertex dictionary keys to the corresponding
|
|
630
|
+
*geometric key* up to a certain precision.
|
|
631
|
+
|
|
632
|
+
Parameters
|
|
633
|
+
----------
|
|
634
|
+
precision : int, optional
|
|
635
|
+
Precision for converting numbers to strings.
|
|
636
|
+
Default is :attr:`TOL.precision`.
|
|
637
|
+
|
|
638
|
+
Returns
|
|
639
|
+
-------
|
|
640
|
+
dict[int, str]
|
|
641
|
+
A dictionary of vertex-geometric key pairs.
|
|
642
|
+
|
|
643
|
+
See Also
|
|
644
|
+
--------
|
|
645
|
+
:meth:`gkey_vertex`
|
|
646
|
+
|
|
647
|
+
"""
|
|
648
|
+
gkey = TOL.geometric_key
|
|
649
|
+
xyz = self.vertex_coordinates
|
|
650
|
+
return {vertex: gkey(xyz(vertex), precision) for vertex in self.vertices()}
|
|
651
|
+
|
|
652
|
+
def gkey_vertex(self, precision=None):
|
|
653
|
+
"""Returns a dictionary that maps *geometric keys* of a certain precision
|
|
654
|
+
to the keys of the corresponding vertices.
|
|
655
|
+
|
|
656
|
+
Parameters
|
|
657
|
+
----------
|
|
658
|
+
precision : int, optional
|
|
659
|
+
Precision for converting numbers to strings.
|
|
660
|
+
Default is :attr:`TOL.precision`.
|
|
661
|
+
|
|
662
|
+
Returns
|
|
663
|
+
-------
|
|
664
|
+
dict[str, int]
|
|
665
|
+
A dictionary of geometric key-vertex pairs.
|
|
666
|
+
|
|
667
|
+
See Also
|
|
668
|
+
--------
|
|
669
|
+
:meth:`vertex_gkey`
|
|
670
|
+
|
|
671
|
+
"""
|
|
672
|
+
gkey = TOL.geometric_key
|
|
673
|
+
xyz = self.vertex_coordinates
|
|
674
|
+
return {gkey(xyz(vertex), precision): vertex for vertex in self.vertices()}
|
|
675
|
+
|
|
676
|
+
# --------------------------------------------------------------------------
|
|
677
|
+
# Builders & Modifiers
|
|
678
|
+
# --------------------------------------------------------------------------
|
|
679
|
+
|
|
680
|
+
def add_vertex(self, key=None, attr_dict=None, **kwattr):
|
|
681
|
+
"""Add a vertex to the volmesh object.
|
|
682
|
+
|
|
683
|
+
Parameters
|
|
684
|
+
----------
|
|
685
|
+
key : int, optional
|
|
686
|
+
The vertex identifier.
|
|
687
|
+
attr_dict : dict[str, Any], optional
|
|
688
|
+
dictionary of vertex attributes.
|
|
689
|
+
**kwattr : dict[str, Any], optional
|
|
690
|
+
A dictionary of additional attributes compiled of remaining named arguments.
|
|
691
|
+
|
|
692
|
+
Returns
|
|
693
|
+
-------
|
|
694
|
+
int
|
|
695
|
+
The identifier of the vertex.
|
|
696
|
+
|
|
697
|
+
See Also
|
|
698
|
+
--------
|
|
699
|
+
:meth:`add_halfface`, :meth:`add_cell`
|
|
700
|
+
|
|
701
|
+
Notes
|
|
702
|
+
-----
|
|
703
|
+
If no key is provided for the vertex, one is generated
|
|
704
|
+
automatically. An automatically generated key is an integer that increments
|
|
705
|
+
the highest integer value of any key used so far by 1.
|
|
706
|
+
|
|
707
|
+
If a key with an integer value is provided that is higher than the current
|
|
708
|
+
highest integer key value, then the highest integer value is updated accordingly.
|
|
709
|
+
|
|
710
|
+
"""
|
|
711
|
+
if key is None:
|
|
712
|
+
key = self._max_vertex = self._max_vertex + 1
|
|
713
|
+
key = int(key)
|
|
714
|
+
if key > self._max_vertex:
|
|
715
|
+
self._max_vertex = key
|
|
716
|
+
if key not in self._vertex:
|
|
717
|
+
self._vertex[key] = {}
|
|
718
|
+
self._plane[key] = {}
|
|
719
|
+
attr = attr_dict or {}
|
|
720
|
+
attr.update(kwattr)
|
|
721
|
+
self._vertex[key].update(attr)
|
|
722
|
+
return key
|
|
723
|
+
|
|
724
|
+
def add_halfface(self, vertices, fkey=None, attr_dict=None, **kwattr):
|
|
725
|
+
"""Add a face to the volmesh object.
|
|
726
|
+
|
|
727
|
+
Parameters
|
|
728
|
+
----------
|
|
729
|
+
vertices : list[int]
|
|
730
|
+
A list of ordered vertex keys representing the face.
|
|
731
|
+
For every vertex that does not yet exist, a new vertex is created.
|
|
732
|
+
fkey : int, optional
|
|
733
|
+
The face identifier.
|
|
734
|
+
attr_dict : dict[str, Any], optional
|
|
735
|
+
dictionary of halfface attributes.
|
|
736
|
+
**kwattr : dict[str, Any], optional
|
|
737
|
+
A dictionary of additional attributes compiled of remaining named arguments.
|
|
738
|
+
|
|
739
|
+
Returns
|
|
740
|
+
-------
|
|
741
|
+
int
|
|
742
|
+
The key of the face.
|
|
743
|
+
|
|
744
|
+
See Also
|
|
745
|
+
--------
|
|
746
|
+
:meth:`add_vertex`, :meth:`add_cell`
|
|
747
|
+
|
|
748
|
+
Notes
|
|
749
|
+
-----
|
|
750
|
+
If no key is provided for the face, one is generated
|
|
751
|
+
automatically. An automatically generated key is an integer that increments
|
|
752
|
+
the highest integer value of any key used so far by 1.
|
|
753
|
+
|
|
754
|
+
If a key with an integer value is provided that is higher than the current
|
|
755
|
+
highest integer key value, then the highest integer value is updated accordingly.
|
|
756
|
+
|
|
757
|
+
"""
|
|
758
|
+
if len(vertices) < 3:
|
|
759
|
+
return
|
|
760
|
+
if vertices[-1] == vertices[0]:
|
|
761
|
+
vertices = vertices[:-1]
|
|
762
|
+
vertices = [int(key) for key in vertices]
|
|
763
|
+
if fkey is None:
|
|
764
|
+
fkey = self._max_face = self._max_face + 1
|
|
765
|
+
fkey = int(fkey)
|
|
766
|
+
if fkey > self._max_face:
|
|
767
|
+
self._max_face = fkey
|
|
768
|
+
attr = attr_dict or {}
|
|
769
|
+
attr.update(kwattr)
|
|
770
|
+
self._halfface[fkey] = vertices
|
|
771
|
+
for name, value in attr.items():
|
|
772
|
+
self.face_attribute(fkey, name, value)
|
|
773
|
+
for u, v in iter_edges_from_vertices(vertices):
|
|
774
|
+
if v not in self._plane[u]:
|
|
775
|
+
self._plane[u][v] = {}
|
|
776
|
+
self._plane[u][v][fkey] = None
|
|
777
|
+
if u not in self._plane[v]:
|
|
778
|
+
self._plane[v][u] = {}
|
|
779
|
+
self._plane[v][u][fkey] = None
|
|
780
|
+
|
|
781
|
+
return fkey
|
|
782
|
+
|
|
783
|
+
def add_cell(self, faces, ckey=None, attr_dict=None, **kwattr):
|
|
784
|
+
"""Add a cell to the volmesh object.
|
|
785
|
+
|
|
786
|
+
Parameters
|
|
787
|
+
----------
|
|
788
|
+
faces : list[list[int]]
|
|
789
|
+
The faces of the cell defined as lists of vertices.
|
|
790
|
+
ckey : int, optional
|
|
791
|
+
The cell identifier.
|
|
792
|
+
attr_dict : dict[str, Any], optional
|
|
793
|
+
A dictionary of cell attributes.
|
|
794
|
+
**kwattr : dict[str, Any], optional
|
|
795
|
+
A dictionary of additional attributes compiled of remaining named arguments.
|
|
796
|
+
|
|
797
|
+
Returns
|
|
798
|
+
-------
|
|
799
|
+
int
|
|
800
|
+
The key of the cell.
|
|
801
|
+
|
|
802
|
+
Raises
|
|
803
|
+
------
|
|
804
|
+
TypeError
|
|
805
|
+
If the provided cell key is of an unhashable type.
|
|
806
|
+
|
|
807
|
+
See also
|
|
808
|
+
--------
|
|
809
|
+
:meth:`add_vertex`, :meth:`add_halfface`
|
|
810
|
+
|
|
811
|
+
Notes
|
|
812
|
+
-----
|
|
813
|
+
If no key is provided for the cell, one is generated
|
|
814
|
+
automatically. An automatically generated key is an integer that increments
|
|
815
|
+
the highest integer value of any key used so far by 1.
|
|
816
|
+
|
|
817
|
+
If a key with an integer value is provided that is higher than the current
|
|
818
|
+
highest integer key value, then the highest integer value is updated accordingly.
|
|
819
|
+
|
|
820
|
+
"""
|
|
821
|
+
if ckey is None:
|
|
822
|
+
ckey = self._max_cell = self._max_cell + 1
|
|
823
|
+
ckey = int(ckey)
|
|
824
|
+
if ckey > self._max_cell:
|
|
825
|
+
self._max_cell = ckey
|
|
826
|
+
attr = attr_dict or {}
|
|
827
|
+
attr.update(kwattr)
|
|
828
|
+
self._cell[ckey] = {}
|
|
829
|
+
for name, value in attr.items():
|
|
830
|
+
self.cell_attribute(ckey, name, value)
|
|
831
|
+
for vertices in faces:
|
|
832
|
+
fkey = self.add_halfface(vertices)
|
|
833
|
+
vertices = self.halfface_vertices(fkey)
|
|
834
|
+
for u, v in iter_edges_from_vertices(vertices):
|
|
835
|
+
if u not in self._cell[ckey]:
|
|
836
|
+
self._cell[ckey][u] = {}
|
|
837
|
+
self._plane[u][v][fkey] = ckey
|
|
838
|
+
self._cell[ckey][u][v] = fkey
|
|
839
|
+
|
|
840
|
+
return ckey
|
|
841
|
+
|
|
842
|
+
def delete_vertex(self, vertex):
|
|
843
|
+
"""Delete a vertex from the volmesh and everything that is attached to it.
|
|
844
|
+
|
|
845
|
+
Parameters
|
|
846
|
+
----------
|
|
847
|
+
vertex : int
|
|
848
|
+
The identifier of the vertex.
|
|
849
|
+
|
|
850
|
+
Returns
|
|
851
|
+
-------
|
|
852
|
+
None
|
|
853
|
+
|
|
854
|
+
See Also
|
|
855
|
+
--------
|
|
856
|
+
:meth:`delete_halfface`, :meth:`delete_cell`
|
|
857
|
+
|
|
858
|
+
"""
|
|
859
|
+
for cell in self.vertex_cells(vertex):
|
|
860
|
+
self.delete_cell(cell)
|
|
861
|
+
|
|
862
|
+
def delete_cell(self, cell):
|
|
863
|
+
"""Delete a cell from the volmesh.
|
|
864
|
+
|
|
865
|
+
Parameters
|
|
866
|
+
----------
|
|
867
|
+
cell : int
|
|
868
|
+
The identifier of the cell.
|
|
869
|
+
|
|
870
|
+
Returns
|
|
871
|
+
-------
|
|
872
|
+
None
|
|
873
|
+
|
|
874
|
+
See Also
|
|
875
|
+
--------
|
|
876
|
+
:meth:`delete_vertex`, :meth:`delete_halfface`
|
|
877
|
+
|
|
878
|
+
"""
|
|
879
|
+
cell_vertices = self.cell_vertices(cell)
|
|
880
|
+
cell_faces = self.cell_faces(cell)
|
|
881
|
+
for face in cell_faces:
|
|
882
|
+
for edge in self.halfface_halfedges(face):
|
|
883
|
+
u, v = edge
|
|
884
|
+
if (u, v) in self._edge_data:
|
|
885
|
+
del self._edge_data[u, v]
|
|
886
|
+
if (v, u) in self._edge_data:
|
|
887
|
+
del self._edge_data[v, u]
|
|
888
|
+
for vertex in cell_vertices:
|
|
889
|
+
if len(self.vertex_cells(vertex)) == 1:
|
|
890
|
+
del self._vertex[vertex]
|
|
891
|
+
for face in cell_faces:
|
|
892
|
+
vertices = self.halfface_vertices(face)
|
|
893
|
+
for u, v in iter_edges_from_vertices(vertices):
|
|
894
|
+
self._plane[u][v][face] = None
|
|
895
|
+
if self._plane[v][u][face] is None:
|
|
896
|
+
del self._plane[u][v][face]
|
|
897
|
+
del self._plane[v][u][face]
|
|
898
|
+
del self._halfface[face]
|
|
899
|
+
key = "-".join(map(str, sorted(vertices)))
|
|
900
|
+
if key in self._face_data:
|
|
901
|
+
del self._face_data[key]
|
|
902
|
+
del self._cell[cell]
|
|
903
|
+
if cell in self._cell_data:
|
|
904
|
+
del self._cell_data[cell]
|
|
905
|
+
|
|
906
|
+
def remove_unused_vertices(self):
|
|
907
|
+
"""Remove all unused vertices from the volmesh object.
|
|
908
|
+
|
|
909
|
+
Returns
|
|
910
|
+
-------
|
|
911
|
+
None
|
|
912
|
+
|
|
913
|
+
"""
|
|
914
|
+
for vertex in list(self.vertices()):
|
|
915
|
+
if vertex not in self._plane:
|
|
916
|
+
del self._vertex[vertex]
|
|
917
|
+
else:
|
|
918
|
+
if not self._plane[vertex]:
|
|
919
|
+
del self._vertex[vertex]
|
|
920
|
+
del self._plane[vertex]
|
|
921
|
+
|
|
922
|
+
# --------------------------------------------------------------------------
|
|
923
|
+
# Volmesh Geometry
|
|
924
|
+
# --------------------------------------------------------------------------
|
|
925
|
+
|
|
926
|
+
def centroid(self):
|
|
927
|
+
"""Compute the centroid of the volmesh.
|
|
928
|
+
|
|
929
|
+
Returns
|
|
930
|
+
-------
|
|
931
|
+
:class:`compas.geometry.Point`
|
|
932
|
+
The point at the centroid.
|
|
933
|
+
|
|
934
|
+
"""
|
|
935
|
+
return Point(*centroid_points([self.vertex_coordinates(vertex) for vertex in self.vertices()]))
|
|
936
|
+
|
|
937
|
+
def aabb(self):
|
|
938
|
+
"""Calculate the axis aligned bounding box of the mesh.
|
|
939
|
+
|
|
940
|
+
Returns
|
|
941
|
+
-------
|
|
942
|
+
:class:`compas.geometry.Box`
|
|
943
|
+
|
|
944
|
+
"""
|
|
945
|
+
xyz = self.vertices_attributes("xyz")
|
|
946
|
+
return Box.from_bounding_box(bounding_box(xyz))
|
|
947
|
+
|
|
948
|
+
def obb(self):
|
|
949
|
+
"""Calculate the oriented bounding box of the datastructure.
|
|
950
|
+
|
|
951
|
+
Returns
|
|
952
|
+
-------
|
|
953
|
+
:class:`compas.geometry.Box`
|
|
954
|
+
|
|
955
|
+
"""
|
|
956
|
+
xyz = self.vertices_attributes("xyz")
|
|
957
|
+
return Box.from_bounding_box(oriented_bounding_box(xyz))
|
|
958
|
+
|
|
959
|
+
# --------------------------------------------------------------------------
|
|
960
|
+
# VolMesh Topology
|
|
961
|
+
# --------------------------------------------------------------------------
|
|
962
|
+
|
|
963
|
+
def number_of_vertices(self):
|
|
964
|
+
"""Count the number of vertices in the volmesh.
|
|
965
|
+
|
|
966
|
+
Returns
|
|
967
|
+
-------
|
|
968
|
+
int
|
|
969
|
+
The number of vertices.
|
|
970
|
+
|
|
971
|
+
See Also
|
|
972
|
+
--------
|
|
973
|
+
:meth:`number_of_edges`, :meth:`number_of_faces`, :meth:`number_of_cells`
|
|
974
|
+
|
|
975
|
+
"""
|
|
976
|
+
return len(list(self.vertices()))
|
|
977
|
+
|
|
978
|
+
def number_of_edges(self):
|
|
979
|
+
"""Count the number of edges in the volmesh.
|
|
980
|
+
|
|
981
|
+
Returns
|
|
982
|
+
-------
|
|
983
|
+
int
|
|
984
|
+
The number of edges.
|
|
985
|
+
|
|
986
|
+
See Also
|
|
987
|
+
--------
|
|
988
|
+
:meth:`number_of_vertices`, :meth:`number_of_faces`, :meth:`number_of_cells`
|
|
989
|
+
|
|
990
|
+
"""
|
|
991
|
+
return len(list(self.edges()))
|
|
992
|
+
|
|
993
|
+
def number_of_faces(self):
|
|
994
|
+
"""Count the number of faces in the volmesh.
|
|
995
|
+
|
|
996
|
+
Returns
|
|
997
|
+
-------
|
|
998
|
+
int
|
|
999
|
+
The number of faces.
|
|
1000
|
+
|
|
1001
|
+
See Also
|
|
1002
|
+
--------
|
|
1003
|
+
:meth:`number_of_vertices`, :meth:`number_of_edges`, :meth:`number_of_cells`
|
|
1004
|
+
|
|
1005
|
+
"""
|
|
1006
|
+
return len(list(self.faces()))
|
|
1007
|
+
|
|
1008
|
+
def number_of_cells(self):
|
|
1009
|
+
"""Count the number of faces in the volmesh.
|
|
1010
|
+
|
|
1011
|
+
Returns
|
|
1012
|
+
-------
|
|
1013
|
+
int
|
|
1014
|
+
The number of cells.
|
|
1015
|
+
|
|
1016
|
+
See Also
|
|
1017
|
+
--------
|
|
1018
|
+
:meth:`number_of_vertices`, :meth:`number_of_edges`, :meth:`number_of_faces`
|
|
1019
|
+
|
|
1020
|
+
"""
|
|
1021
|
+
return len(list(self.cells()))
|
|
1022
|
+
|
|
1023
|
+
def is_valid(self):
|
|
1024
|
+
"""Verify that the volmesh is valid.
|
|
1025
|
+
|
|
1026
|
+
Returns
|
|
1027
|
+
-------
|
|
1028
|
+
bool
|
|
1029
|
+
True if the volmesh is valid.
|
|
1030
|
+
False otherwise.
|
|
1031
|
+
|
|
1032
|
+
"""
|
|
1033
|
+
raise NotImplementedError
|
|
1034
|
+
|
|
1035
|
+
# --------------------------------------------------------------------------
|
|
1036
|
+
# Vertex Accessors
|
|
1037
|
+
# --------------------------------------------------------------------------
|
|
1038
|
+
|
|
1039
|
+
def vertices(self, data=False):
|
|
1040
|
+
"""Iterate over the vertices of the volmesh.
|
|
1041
|
+
|
|
1042
|
+
Parameters
|
|
1043
|
+
----------
|
|
1044
|
+
data : bool, optional
|
|
1045
|
+
If True, yield the vertex attributes in addition to the vertex identifiers.
|
|
1046
|
+
|
|
1047
|
+
Yields
|
|
1048
|
+
------
|
|
1049
|
+
int | tuple[int, dict[str, Any]]
|
|
1050
|
+
If `data` is False, the next vertex identifier.
|
|
1051
|
+
If `data` is True, the next vertex as a (vertex, attr) a tuple.
|
|
1052
|
+
|
|
1053
|
+
See Also
|
|
1054
|
+
--------
|
|
1055
|
+
:meth:`edges`, :meth:`faces`, :meth:`cells`
|
|
1056
|
+
|
|
1057
|
+
"""
|
|
1058
|
+
for vertex in self._vertex:
|
|
1059
|
+
if not data:
|
|
1060
|
+
yield vertex
|
|
1061
|
+
else:
|
|
1062
|
+
yield vertex, self.vertex_attributes(vertex)
|
|
1063
|
+
|
|
1064
|
+
def vertices_where(self, conditions=None, data=False, **kwargs):
|
|
1065
|
+
"""Get vertices for which a certain condition or set of conditions is true.
|
|
1066
|
+
|
|
1067
|
+
Parameters
|
|
1068
|
+
----------
|
|
1069
|
+
conditions : dict, optional
|
|
1070
|
+
A set of conditions in the form of key-value pairs.
|
|
1071
|
+
The keys should be attribute names. The values can be attribute
|
|
1072
|
+
values or ranges of attribute values in the form of min/max pairs.
|
|
1073
|
+
data : bool, optional
|
|
1074
|
+
If True, yield the vertex attributes in addition to the identifiers.
|
|
1075
|
+
**kwargs : dict[str, Any], optional
|
|
1076
|
+
Additional conditions provided as named function arguments.
|
|
1077
|
+
|
|
1078
|
+
Yields
|
|
1079
|
+
------
|
|
1080
|
+
int | tuple[int, dict[str, Any]]
|
|
1081
|
+
If `data` is False, the next vertex that matches the condition.
|
|
1082
|
+
If `data` is True, the next vertex and its attributes.
|
|
1083
|
+
|
|
1084
|
+
See Also
|
|
1085
|
+
--------
|
|
1086
|
+
:meth:`vertices_where_predicate`
|
|
1087
|
+
:meth:`edges_where`, :meth:`faces_where`, :meth:`cells_where`
|
|
1088
|
+
|
|
1089
|
+
"""
|
|
1090
|
+
conditions = conditions or {}
|
|
1091
|
+
conditions.update(kwargs)
|
|
1092
|
+
|
|
1093
|
+
for key, attr in self.vertices(True):
|
|
1094
|
+
is_match = True
|
|
1095
|
+
|
|
1096
|
+
attr = attr or {}
|
|
1097
|
+
|
|
1098
|
+
for name, value in conditions.items():
|
|
1099
|
+
method = getattr(self, name, None)
|
|
1100
|
+
|
|
1101
|
+
if callable(method):
|
|
1102
|
+
val = method(key)
|
|
1103
|
+
|
|
1104
|
+
if isinstance(val, list):
|
|
1105
|
+
if value not in val:
|
|
1106
|
+
is_match = False
|
|
1107
|
+
break
|
|
1108
|
+
break
|
|
1109
|
+
|
|
1110
|
+
if isinstance(value, (tuple, list)):
|
|
1111
|
+
minval, maxval = value
|
|
1112
|
+
if val < minval or val > maxval:
|
|
1113
|
+
is_match = False
|
|
1114
|
+
break
|
|
1115
|
+
else:
|
|
1116
|
+
if value != val:
|
|
1117
|
+
is_match = False
|
|
1118
|
+
break
|
|
1119
|
+
|
|
1120
|
+
else:
|
|
1121
|
+
if name not in attr:
|
|
1122
|
+
is_match = False
|
|
1123
|
+
break
|
|
1124
|
+
|
|
1125
|
+
if isinstance(attr[name], list):
|
|
1126
|
+
if value not in attr[name]:
|
|
1127
|
+
is_match = False
|
|
1128
|
+
break
|
|
1129
|
+
break
|
|
1130
|
+
|
|
1131
|
+
if isinstance(value, (tuple, list)):
|
|
1132
|
+
minval, maxval = value
|
|
1133
|
+
if attr[name] < minval or attr[name] > maxval:
|
|
1134
|
+
is_match = False
|
|
1135
|
+
break
|
|
1136
|
+
else:
|
|
1137
|
+
if value != attr[name]:
|
|
1138
|
+
is_match = False
|
|
1139
|
+
break
|
|
1140
|
+
|
|
1141
|
+
if is_match:
|
|
1142
|
+
if data:
|
|
1143
|
+
yield key, attr
|
|
1144
|
+
else:
|
|
1145
|
+
yield key
|
|
1146
|
+
|
|
1147
|
+
def vertices_where_predicate(self, predicate, data=False):
|
|
1148
|
+
"""Get vertices for which a certain condition or set of conditions is true using a lambda function.
|
|
1149
|
+
|
|
1150
|
+
Parameters
|
|
1151
|
+
----------
|
|
1152
|
+
predicate : callable
|
|
1153
|
+
The condition you want to evaluate.
|
|
1154
|
+
The callable takes 2 parameters: the vertex identifier and the vertex attributes, and should return True or False.
|
|
1155
|
+
data : bool, optional
|
|
1156
|
+
If True, yield the vertex attributes in addition to the identifiers.
|
|
1157
|
+
|
|
1158
|
+
Yields
|
|
1159
|
+
------
|
|
1160
|
+
int | tuple[int, dict[str, Any]]
|
|
1161
|
+
If `data` is False, the next vertex that matches the condition.
|
|
1162
|
+
If `data` is True, the next vertex and its attributes.
|
|
1163
|
+
|
|
1164
|
+
See Also
|
|
1165
|
+
--------
|
|
1166
|
+
:meth:`vertices_where`
|
|
1167
|
+
:meth:`edges_where_predicate`, :meth:`faces_where_predicate`, :meth:`cells_where_predicate`
|
|
1168
|
+
|
|
1169
|
+
"""
|
|
1170
|
+
for key, attr in self.vertices(True):
|
|
1171
|
+
if predicate(key, attr):
|
|
1172
|
+
if data:
|
|
1173
|
+
yield key, attr
|
|
1174
|
+
else:
|
|
1175
|
+
yield key
|
|
1176
|
+
|
|
1177
|
+
# --------------------------------------------------------------------------
|
|
1178
|
+
# Vertex Attributes
|
|
1179
|
+
# --------------------------------------------------------------------------
|
|
1180
|
+
|
|
1181
|
+
def update_default_vertex_attributes(self, attr_dict=None, **kwattr):
|
|
1182
|
+
"""Update the default vertex attributes.
|
|
1183
|
+
|
|
1184
|
+
Parameters
|
|
1185
|
+
----------
|
|
1186
|
+
attr_dict : dict[str, Any], optional
|
|
1187
|
+
A dictionary of attributes with their default values.
|
|
1188
|
+
**kwattr : dict[str, Any], optional
|
|
1189
|
+
A dictionary of additional attributes compiled of remaining named arguments.
|
|
1190
|
+
|
|
1191
|
+
Returns
|
|
1192
|
+
-------
|
|
1193
|
+
None
|
|
1194
|
+
|
|
1195
|
+
See Also
|
|
1196
|
+
--------
|
|
1197
|
+
:meth:`update_default_edge_attributes`, :meth:`update_default_face_attributes`, :meth:`update_default_cell_attributes`
|
|
1198
|
+
|
|
1199
|
+
Notes
|
|
1200
|
+
-----
|
|
1201
|
+
Named arguments overwrite correpsonding name-value pairs in the attribute dictionary.
|
|
1202
|
+
|
|
1203
|
+
"""
|
|
1204
|
+
if not attr_dict:
|
|
1205
|
+
attr_dict = {}
|
|
1206
|
+
attr_dict.update(kwattr)
|
|
1207
|
+
self.default_vertex_attributes.update(attr_dict)
|
|
1208
|
+
|
|
1209
|
+
def vertex_attribute(self, vertex, name, value=None):
|
|
1210
|
+
"""Get or set an attribute of a vertex.
|
|
1211
|
+
|
|
1212
|
+
Parameters
|
|
1213
|
+
----------
|
|
1214
|
+
vertex : int
|
|
1215
|
+
The vertex identifier.
|
|
1216
|
+
name : str
|
|
1217
|
+
The name of the attribute
|
|
1218
|
+
value : object, optional
|
|
1219
|
+
The value of the attribute.
|
|
1220
|
+
|
|
1221
|
+
Returns
|
|
1222
|
+
-------
|
|
1223
|
+
object | None
|
|
1224
|
+
The value of the attribute,
|
|
1225
|
+
or None when the function is used as a "setter".
|
|
1226
|
+
|
|
1227
|
+
Raises
|
|
1228
|
+
------
|
|
1229
|
+
KeyError
|
|
1230
|
+
If the vertex does not exist.
|
|
1231
|
+
|
|
1232
|
+
See Also
|
|
1233
|
+
--------
|
|
1234
|
+
:meth:`unset_vertex_attribute`
|
|
1235
|
+
:meth:`vertex_attributes`, :meth:`vertices_attribute`, :meth:`vertices_attributes`
|
|
1236
|
+
:meth:`edge_attribute`, :meth:`face_attribute`, :meth:`cell_attribute`
|
|
1237
|
+
|
|
1238
|
+
"""
|
|
1239
|
+
if vertex not in self._vertex:
|
|
1240
|
+
raise KeyError(vertex)
|
|
1241
|
+
if value is not None:
|
|
1242
|
+
self._vertex[vertex][name] = value
|
|
1243
|
+
return None
|
|
1244
|
+
if name in self._vertex[vertex]:
|
|
1245
|
+
return self._vertex[vertex][name]
|
|
1246
|
+
else:
|
|
1247
|
+
if name in self.default_vertex_attributes:
|
|
1248
|
+
return self.default_vertex_attributes[name]
|
|
1249
|
+
|
|
1250
|
+
def unset_vertex_attribute(self, vertex, name):
|
|
1251
|
+
"""Unset the attribute of a vertex.
|
|
1252
|
+
|
|
1253
|
+
Parameters
|
|
1254
|
+
----------
|
|
1255
|
+
vertex : int
|
|
1256
|
+
The vertex identifier.
|
|
1257
|
+
name : str
|
|
1258
|
+
The name of the attribute.
|
|
1259
|
+
|
|
1260
|
+
Returns
|
|
1261
|
+
-------
|
|
1262
|
+
None
|
|
1263
|
+
|
|
1264
|
+
Raises
|
|
1265
|
+
------
|
|
1266
|
+
KeyError
|
|
1267
|
+
If the vertex does not exist.
|
|
1268
|
+
|
|
1269
|
+
See Also
|
|
1270
|
+
--------
|
|
1271
|
+
:meth:`vertex_attribute`
|
|
1272
|
+
|
|
1273
|
+
Notes
|
|
1274
|
+
-----
|
|
1275
|
+
Unsetting the value of a vertex attribute implicitly sets it back to the value
|
|
1276
|
+
stored in the default vertex attribute dict.
|
|
1277
|
+
|
|
1278
|
+
"""
|
|
1279
|
+
if name in self._vertex[vertex]:
|
|
1280
|
+
del self._vertex[vertex][name]
|
|
1281
|
+
|
|
1282
|
+
def vertex_attributes(self, vertex, names=None, values=None):
|
|
1283
|
+
"""Get or set multiple attributes of a vertex.
|
|
1284
|
+
|
|
1285
|
+
Parameters
|
|
1286
|
+
----------
|
|
1287
|
+
vertex : int
|
|
1288
|
+
The identifier of the vertex.
|
|
1289
|
+
names : list[str], optional
|
|
1290
|
+
A list of attribute names.
|
|
1291
|
+
values : list[Any], optional
|
|
1292
|
+
A list of attribute values.
|
|
1293
|
+
|
|
1294
|
+
Returns
|
|
1295
|
+
-------
|
|
1296
|
+
dict[str, Any] | list[Any] | None
|
|
1297
|
+
If the parameter `names` is empty,
|
|
1298
|
+
the function returns a dictionary of all attribute name-value pairs of the vertex.
|
|
1299
|
+
If the parameter `names` is not empty,
|
|
1300
|
+
the function returns a list of the values corresponding to the requested attribute names.
|
|
1301
|
+
The function returns None if it is used as a "setter".
|
|
1302
|
+
|
|
1303
|
+
Raises
|
|
1304
|
+
------
|
|
1305
|
+
KeyError
|
|
1306
|
+
If the vertex does not exist.
|
|
1307
|
+
|
|
1308
|
+
See Also
|
|
1309
|
+
--------
|
|
1310
|
+
:meth:`vertex_attribute`, :meth:`vertices_attribute`, :meth:`vertices_attributes`
|
|
1311
|
+
:meth:`edge_attributes`, :meth:`face_attributes`, :meth:`cell_attributes`
|
|
1312
|
+
|
|
1313
|
+
"""
|
|
1314
|
+
if vertex not in self._vertex:
|
|
1315
|
+
raise KeyError(vertex)
|
|
1316
|
+
if names and values is not None:
|
|
1317
|
+
# use it as a setter
|
|
1318
|
+
for name, value in zip(names, values):
|
|
1319
|
+
self._vertex[vertex][name] = value
|
|
1320
|
+
return
|
|
1321
|
+
# use it as a getter
|
|
1322
|
+
if not names:
|
|
1323
|
+
# return all vertex attributes as a dict
|
|
1324
|
+
return VertexAttributeView(self.default_vertex_attributes, self._vertex[vertex])
|
|
1325
|
+
values = []
|
|
1326
|
+
for name in names:
|
|
1327
|
+
if name in self._vertex[vertex]:
|
|
1328
|
+
values.append(self._vertex[vertex][name])
|
|
1329
|
+
elif name in self.default_vertex_attributes:
|
|
1330
|
+
values.append(self.default_vertex_attributes[name])
|
|
1331
|
+
else:
|
|
1332
|
+
values.append(None)
|
|
1333
|
+
return values
|
|
1334
|
+
|
|
1335
|
+
def vertices_attribute(self, name, value=None, keys=None):
|
|
1336
|
+
"""Get or set an attribute of multiple vertices.
|
|
1337
|
+
|
|
1338
|
+
Parameters
|
|
1339
|
+
----------
|
|
1340
|
+
name : str
|
|
1341
|
+
The name of the attribute.
|
|
1342
|
+
value : object, optional
|
|
1343
|
+
The value of the attribute.
|
|
1344
|
+
Default is None.
|
|
1345
|
+
keys : list[int], optional
|
|
1346
|
+
A list of vertex identifiers.
|
|
1347
|
+
|
|
1348
|
+
Returns
|
|
1349
|
+
-------
|
|
1350
|
+
list[Any] | None
|
|
1351
|
+
The value of the attribute for each vertex,
|
|
1352
|
+
or None if the function is used as a "setter".
|
|
1353
|
+
|
|
1354
|
+
Raises
|
|
1355
|
+
------
|
|
1356
|
+
KeyError
|
|
1357
|
+
If any of the vertices does not exist.
|
|
1358
|
+
|
|
1359
|
+
See Also
|
|
1360
|
+
--------
|
|
1361
|
+
:meth:`vertex_attribute`, :meth:`vertex_attributes`, :meth:`vertices_attributes`
|
|
1362
|
+
:meth:`edges_attribute`, :meth:`faces_attribute`, :meth:`cells_attribute`
|
|
1363
|
+
|
|
1364
|
+
"""
|
|
1365
|
+
vertices = keys or self.vertices()
|
|
1366
|
+
if value is not None:
|
|
1367
|
+
for vertex in vertices:
|
|
1368
|
+
self.vertex_attribute(vertex, name, value)
|
|
1369
|
+
return
|
|
1370
|
+
return [self.vertex_attribute(vertex, name) for vertex in vertices]
|
|
1371
|
+
|
|
1372
|
+
def vertices_attributes(self, names=None, values=None, keys=None):
|
|
1373
|
+
"""Get or set multiple attributes of multiple vertices.
|
|
1374
|
+
|
|
1375
|
+
Parameters
|
|
1376
|
+
----------
|
|
1377
|
+
names : list[str], optional
|
|
1378
|
+
The names of the attribute.
|
|
1379
|
+
Default is None.
|
|
1380
|
+
values : list[Any], optional
|
|
1381
|
+
The values of the attributes.
|
|
1382
|
+
Default is None.
|
|
1383
|
+
key : list[Any], optional
|
|
1384
|
+
A list of vertex identifiers.
|
|
1385
|
+
|
|
1386
|
+
Returns
|
|
1387
|
+
-------
|
|
1388
|
+
list[dict[str, Any]] | list[list[Any]] | None
|
|
1389
|
+
If the parameter `names` is empty,
|
|
1390
|
+
the function returns a list containing an attribute dict per vertex.
|
|
1391
|
+
If the parameter `names` is not empty,
|
|
1392
|
+
the function returns a list containing a list of attribute values per vertex corresponding to the provided attribute names.
|
|
1393
|
+
The function returns None if it is used as a "setter".
|
|
1394
|
+
|
|
1395
|
+
Raises
|
|
1396
|
+
------
|
|
1397
|
+
KeyError
|
|
1398
|
+
If any of the vertices does not exist.
|
|
1399
|
+
|
|
1400
|
+
See Also
|
|
1401
|
+
--------
|
|
1402
|
+
:meth:`vertex_attribute`, :meth:`vertex_attributes`, :meth:`vertices_attribute`
|
|
1403
|
+
:meth:`edges_attributes`, :meth:`faces_attributes`, :meth:`cells_attributes`
|
|
1404
|
+
|
|
1405
|
+
"""
|
|
1406
|
+
vertices = keys or self.vertices()
|
|
1407
|
+
if values:
|
|
1408
|
+
for vertex in vertices:
|
|
1409
|
+
self.vertex_attributes(vertex, names, values)
|
|
1410
|
+
return
|
|
1411
|
+
return [self.vertex_attributes(vertex, names) for vertex in vertices]
|
|
1412
|
+
|
|
1413
|
+
# --------------------------------------------------------------------------
|
|
1414
|
+
# Vertex Topology
|
|
1415
|
+
# --------------------------------------------------------------------------
|
|
1416
|
+
|
|
1417
|
+
def has_vertex(self, vertex):
|
|
1418
|
+
"""Verify that a vertex is in the volmesh.
|
|
1419
|
+
|
|
1420
|
+
Parameters
|
|
1421
|
+
----------
|
|
1422
|
+
vertex : int
|
|
1423
|
+
The identifier of the vertex.
|
|
1424
|
+
|
|
1425
|
+
Returns
|
|
1426
|
+
-------
|
|
1427
|
+
bool
|
|
1428
|
+
True if the vertex is in the volmesh.
|
|
1429
|
+
False otherwise.
|
|
1430
|
+
|
|
1431
|
+
See Also
|
|
1432
|
+
--------
|
|
1433
|
+
:meth:`has_edge`, :meth:`has_face`, :meth:`has_cell`
|
|
1434
|
+
|
|
1435
|
+
"""
|
|
1436
|
+
return vertex in self._vertex
|
|
1437
|
+
|
|
1438
|
+
def vertex_neighbors(self, vertex):
|
|
1439
|
+
"""Return the vertex neighbors of a vertex.
|
|
1440
|
+
|
|
1441
|
+
Parameters
|
|
1442
|
+
----------
|
|
1443
|
+
vertex : int
|
|
1444
|
+
The identifier of the vertex.
|
|
1445
|
+
|
|
1446
|
+
Returns
|
|
1447
|
+
-------
|
|
1448
|
+
list[int]
|
|
1449
|
+
The list of neighboring vertices.
|
|
1450
|
+
|
|
1451
|
+
See Also
|
|
1452
|
+
--------
|
|
1453
|
+
:meth:`vertex_degree`, :meth:`vertex_min_degree`, :meth:`vertex_max_degree`
|
|
1454
|
+
:meth:`vertex_faces`, :meth:`vertex_halffaces`, :meth:`vertex_cells`
|
|
1455
|
+
:meth:`vertex_neighborhood`
|
|
1456
|
+
|
|
1457
|
+
"""
|
|
1458
|
+
return self._plane[vertex].keys()
|
|
1459
|
+
|
|
1460
|
+
def vertex_neighborhood(self, vertex, ring=1):
|
|
1461
|
+
"""Return the vertices in the neighborhood of a vertex.
|
|
1462
|
+
|
|
1463
|
+
Parameters
|
|
1464
|
+
----------
|
|
1465
|
+
vertex : int
|
|
1466
|
+
The identifier of the vertex.
|
|
1467
|
+
ring : int, optional
|
|
1468
|
+
The number of neighborhood rings to include.
|
|
1469
|
+
|
|
1470
|
+
Returns
|
|
1471
|
+
-------
|
|
1472
|
+
list[int]
|
|
1473
|
+
The vertices in the neighborhood.
|
|
1474
|
+
|
|
1475
|
+
See Also
|
|
1476
|
+
--------
|
|
1477
|
+
:meth:`vertex_neighbors`
|
|
1478
|
+
|
|
1479
|
+
Notes
|
|
1480
|
+
-----
|
|
1481
|
+
The vertices in the neighborhood are unordered.
|
|
1482
|
+
|
|
1483
|
+
"""
|
|
1484
|
+
nbrs = set(self.vertex_neighbors(vertex))
|
|
1485
|
+
i = 1
|
|
1486
|
+
while True:
|
|
1487
|
+
if i == ring:
|
|
1488
|
+
break
|
|
1489
|
+
temp = []
|
|
1490
|
+
for nbr in nbrs:
|
|
1491
|
+
temp += self.vertex_neighbors(nbr)
|
|
1492
|
+
nbrs.update(temp)
|
|
1493
|
+
i += 1
|
|
1494
|
+
return list(nbrs - set([vertex]))
|
|
1495
|
+
|
|
1496
|
+
def vertex_degree(self, vertex):
|
|
1497
|
+
"""Count the neighbors of a vertex.
|
|
1498
|
+
|
|
1499
|
+
Parameters
|
|
1500
|
+
----------
|
|
1501
|
+
vertex : int
|
|
1502
|
+
The identifier of the vertex.
|
|
1503
|
+
|
|
1504
|
+
Returns
|
|
1505
|
+
-------
|
|
1506
|
+
int
|
|
1507
|
+
The degree of the vertex.
|
|
1508
|
+
|
|
1509
|
+
See Also
|
|
1510
|
+
--------
|
|
1511
|
+
:meth:`vertex_neighbors`, :meth:`vertex_min_degree`, :meth:`vertex_max_degree`
|
|
1512
|
+
|
|
1513
|
+
"""
|
|
1514
|
+
return len(self.vertex_neighbors(vertex))
|
|
1515
|
+
|
|
1516
|
+
def vertex_min_degree(self):
|
|
1517
|
+
"""Compute the minimum degree of all vertices.
|
|
1518
|
+
|
|
1519
|
+
Returns
|
|
1520
|
+
-------
|
|
1521
|
+
int
|
|
1522
|
+
The lowest degree of all vertices.
|
|
1523
|
+
|
|
1524
|
+
See Also
|
|
1525
|
+
--------
|
|
1526
|
+
:meth:`vertex_degree`, :meth:`vertex_max_degree`
|
|
1527
|
+
|
|
1528
|
+
"""
|
|
1529
|
+
if not self._vertex:
|
|
1530
|
+
return 0
|
|
1531
|
+
return min(self.vertex_degree(vertex) for vertex in self.vertices())
|
|
1532
|
+
|
|
1533
|
+
def vertex_max_degree(self):
|
|
1534
|
+
"""Compute the maximum degree of all vertices.
|
|
1535
|
+
|
|
1536
|
+
Returns
|
|
1537
|
+
-------
|
|
1538
|
+
int
|
|
1539
|
+
The highest degree of all vertices.
|
|
1540
|
+
|
|
1541
|
+
See Also
|
|
1542
|
+
--------
|
|
1543
|
+
:meth:`vertex_degree`, :meth:`vertex_min_degree`
|
|
1544
|
+
|
|
1545
|
+
"""
|
|
1546
|
+
if not self._vertex:
|
|
1547
|
+
return 0
|
|
1548
|
+
return max(self.vertex_degree(vertex) for vertex in self.vertices())
|
|
1549
|
+
|
|
1550
|
+
def vertex_halffaces(self, vertex):
|
|
1551
|
+
"""Return all halffaces connected to a vertex.
|
|
1552
|
+
|
|
1553
|
+
Parameters
|
|
1554
|
+
----------
|
|
1555
|
+
vertex : int
|
|
1556
|
+
The identifier of the vertex.
|
|
1557
|
+
|
|
1558
|
+
Returns
|
|
1559
|
+
-------
|
|
1560
|
+
list[int]
|
|
1561
|
+
The list of halffaces connected to a vertex.
|
|
1562
|
+
|
|
1563
|
+
See Also
|
|
1564
|
+
--------
|
|
1565
|
+
:meth:`vertex_neighbors`, :meth:`vertex_faces`, :meth:`vertex_cells`
|
|
1566
|
+
|
|
1567
|
+
"""
|
|
1568
|
+
cells = self.vertex_cells(vertex)
|
|
1569
|
+
nbrs = self.vertex_neighbors(vertex)
|
|
1570
|
+
halffaces = set()
|
|
1571
|
+
for cell in cells:
|
|
1572
|
+
for nbr in nbrs:
|
|
1573
|
+
if nbr in self._cell[cell][vertex]:
|
|
1574
|
+
halffaces.add(self._cell[cell][vertex][nbr])
|
|
1575
|
+
halffaces.add(self._cell[cell][nbr][vertex])
|
|
1576
|
+
return list(halffaces)
|
|
1577
|
+
|
|
1578
|
+
def vertex_cells(self, vertex):
|
|
1579
|
+
"""Return all cells connected to a vertex.
|
|
1580
|
+
|
|
1581
|
+
Parameters
|
|
1582
|
+
----------
|
|
1583
|
+
vertex : int
|
|
1584
|
+
The identifier of the vertex.
|
|
1585
|
+
|
|
1586
|
+
Returns
|
|
1587
|
+
-------
|
|
1588
|
+
list[int]
|
|
1589
|
+
The list of cells connected to a vertex.
|
|
1590
|
+
|
|
1591
|
+
See Also
|
|
1592
|
+
--------
|
|
1593
|
+
:meth:`vertex_neighbors`, :meth:`vertex_faces`, :meth:`vertex_halffaces`
|
|
1594
|
+
|
|
1595
|
+
"""
|
|
1596
|
+
cells = set()
|
|
1597
|
+
for nbr in self._plane[vertex]:
|
|
1598
|
+
for cell in self._plane[vertex][nbr].values():
|
|
1599
|
+
if cell is not None:
|
|
1600
|
+
cells.add(cell)
|
|
1601
|
+
return list(cells)
|
|
1602
|
+
|
|
1603
|
+
def is_vertex_on_boundary(self, vertex):
|
|
1604
|
+
"""Verify that a vertex is on a boundary.
|
|
1605
|
+
|
|
1606
|
+
Parameters
|
|
1607
|
+
----------
|
|
1608
|
+
vertex : int
|
|
1609
|
+
The identifier of the vertex.
|
|
1610
|
+
|
|
1611
|
+
Returns
|
|
1612
|
+
-------
|
|
1613
|
+
bool
|
|
1614
|
+
True if the vertex is on the boundary.
|
|
1615
|
+
False otherwise.
|
|
1616
|
+
|
|
1617
|
+
See Also
|
|
1618
|
+
--------
|
|
1619
|
+
:meth:`is_edge_on_boundary`, :meth:`is_face_on_boundary`, :meth:`is_cell_on_boundary`
|
|
1620
|
+
|
|
1621
|
+
"""
|
|
1622
|
+
halffaces = self.vertex_halffaces(vertex)
|
|
1623
|
+
for halfface in halffaces:
|
|
1624
|
+
if self.is_halfface_on_boundary(halfface):
|
|
1625
|
+
return True
|
|
1626
|
+
return False
|
|
1627
|
+
|
|
1628
|
+
# --------------------------------------------------------------------------
|
|
1629
|
+
# Vertex Geometry
|
|
1630
|
+
# --------------------------------------------------------------------------
|
|
1631
|
+
|
|
1632
|
+
def vertex_coordinates(self, vertex, axes="xyz"):
|
|
1633
|
+
"""Return the coordinates of a vertex.
|
|
1634
|
+
|
|
1635
|
+
Parameters
|
|
1636
|
+
----------
|
|
1637
|
+
vertex : int
|
|
1638
|
+
The identifier of the vertex.
|
|
1639
|
+
axes : str, optional
|
|
1640
|
+
The axes alon which to take the coordinates.
|
|
1641
|
+
Should be a combination of x, y, and z.
|
|
1642
|
+
|
|
1643
|
+
Returns
|
|
1644
|
+
-------
|
|
1645
|
+
list[float]
|
|
1646
|
+
Coordinates of the vertex.
|
|
1647
|
+
|
|
1648
|
+
See Also
|
|
1649
|
+
--------
|
|
1650
|
+
:meth:`vertex_point`, :meth:`vertex_laplacian`, :meth:`vertex_neighborhood_centroid`
|
|
1651
|
+
|
|
1652
|
+
"""
|
|
1653
|
+
return [self._vertex[vertex][axis] for axis in axes]
|
|
1654
|
+
|
|
1655
|
+
def vertex_point(self, vertex):
|
|
1656
|
+
"""Return the point representation of a vertex.
|
|
1657
|
+
|
|
1658
|
+
Parameters
|
|
1659
|
+
----------
|
|
1660
|
+
vertex : int
|
|
1661
|
+
The identifier of the vertex.
|
|
1662
|
+
|
|
1663
|
+
Returns
|
|
1664
|
+
-------
|
|
1665
|
+
:class:`compas.geometry.Point`
|
|
1666
|
+
The point.
|
|
1667
|
+
|
|
1668
|
+
See Also
|
|
1669
|
+
--------
|
|
1670
|
+
:meth:`vertex_laplacian`, :meth:`vertex_neighborhood_centroid`
|
|
1671
|
+
|
|
1672
|
+
"""
|
|
1673
|
+
return Point(*self.vertex_coordinates(vertex))
|
|
1674
|
+
|
|
1675
|
+
def vertex_laplacian(self, vertex):
|
|
1676
|
+
"""Compute the vector from a vertex to the centroid of its neighbors.
|
|
1677
|
+
|
|
1678
|
+
Parameters
|
|
1679
|
+
----------
|
|
1680
|
+
vertex : int
|
|
1681
|
+
The identifier of the vertex.
|
|
1682
|
+
|
|
1683
|
+
Returns
|
|
1684
|
+
-------
|
|
1685
|
+
:class:`compas.geometry.Vector`
|
|
1686
|
+
The laplacian vector.
|
|
1687
|
+
|
|
1688
|
+
See Also
|
|
1689
|
+
--------
|
|
1690
|
+
:meth:`vertex_point`, :meth:`vertex_neighborhood_centroid`
|
|
1691
|
+
|
|
1692
|
+
"""
|
|
1693
|
+
c = self.vertex_neighborhood_centroid(vertex)
|
|
1694
|
+
p = self.vertex_coordinates(vertex)
|
|
1695
|
+
return Vector(*subtract_vectors(c, p))
|
|
1696
|
+
|
|
1697
|
+
def vertex_neighborhood_centroid(self, vertex):
|
|
1698
|
+
"""Compute the point at the centroid of the neighbors of a vertex.
|
|
1699
|
+
|
|
1700
|
+
Parameters
|
|
1701
|
+
----------
|
|
1702
|
+
vertex : int
|
|
1703
|
+
The identifier of the vertex.
|
|
1704
|
+
|
|
1705
|
+
Returns
|
|
1706
|
+
-------
|
|
1707
|
+
:class:`compas.geometry.Point`
|
|
1708
|
+
The coordinates of the centroid.
|
|
1709
|
+
|
|
1710
|
+
See Also
|
|
1711
|
+
--------
|
|
1712
|
+
:meth:`vertex_point`, :meth:`vertex_laplacian`
|
|
1713
|
+
|
|
1714
|
+
"""
|
|
1715
|
+
return Point(*centroid_points([self.vertex_coordinates(nbr) for nbr in self.vertex_neighbors(vertex)]))
|
|
1716
|
+
|
|
1717
|
+
# --------------------------------------------------------------------------
|
|
1718
|
+
# Edge Accessors
|
|
1719
|
+
# --------------------------------------------------------------------------
|
|
1720
|
+
|
|
1721
|
+
def edges(self, data=False):
|
|
1722
|
+
"""Iterate over the edges of the volmesh.
|
|
1723
|
+
|
|
1724
|
+
Parameters
|
|
1725
|
+
----------
|
|
1726
|
+
data : bool, optional
|
|
1727
|
+
If True, yield the edge attributes as well as the edge identifiers.
|
|
1728
|
+
|
|
1729
|
+
Yields
|
|
1730
|
+
------
|
|
1731
|
+
tuple[int, int] | tuple[tuple[int, int], dict[str, Any]]
|
|
1732
|
+
If `data` is False, the next edge as a (u, v) tuple.
|
|
1733
|
+
If `data` is True, the next edge as a ((u, v), attr) tuple.
|
|
1734
|
+
|
|
1735
|
+
See Also
|
|
1736
|
+
--------
|
|
1737
|
+
:meth:`vertices`, :meth:`faces`, :meth:`cells`
|
|
1738
|
+
|
|
1739
|
+
"""
|
|
1740
|
+
seen = set()
|
|
1741
|
+
for face in self._halfface:
|
|
1742
|
+
vertices = self._halfface[face]
|
|
1743
|
+
for u, v in pairwise(vertices + vertices[:1]):
|
|
1744
|
+
if (u, v) in seen or (v, u) in seen:
|
|
1745
|
+
continue
|
|
1746
|
+
seen.add((u, v))
|
|
1747
|
+
seen.add((v, u))
|
|
1748
|
+
if not data:
|
|
1749
|
+
yield u, v
|
|
1750
|
+
else:
|
|
1751
|
+
yield (u, v), self.edge_attributes((u, v))
|
|
1752
|
+
|
|
1753
|
+
def edges_where(self, conditions=None, data=False, **kwargs):
|
|
1754
|
+
"""Get edges for which a certain condition or set of conditions is true.
|
|
1755
|
+
|
|
1756
|
+
Parameters
|
|
1757
|
+
----------
|
|
1758
|
+
conditions : dict, optional
|
|
1759
|
+
A set of conditions in the form of key-value pairs.
|
|
1760
|
+
The keys should be attribute names. The values can be attribute
|
|
1761
|
+
values or ranges of attribute values in the form of min/max pairs.
|
|
1762
|
+
data : bool, optional
|
|
1763
|
+
If True, yield the edge attributes in addition to the identifiers.
|
|
1764
|
+
**kwargs : dict[str, Any], optional
|
|
1765
|
+
Additional conditions provided as named function arguments.
|
|
1766
|
+
|
|
1767
|
+
Yields
|
|
1768
|
+
------
|
|
1769
|
+
tuple[int, int] | tuple[tuple[int, int], dict[str, Any]]
|
|
1770
|
+
If `data` is False, the next edge as a (u, v) tuple.
|
|
1771
|
+
If `data` is True, the next edge as a (u, v, data) tuple.
|
|
1772
|
+
|
|
1773
|
+
See Also
|
|
1774
|
+
--------
|
|
1775
|
+
:meth:`edges_where_predicate`
|
|
1776
|
+
:meth:`vertices_where`, :meth:`faces_where`, :meth:`cells_where`
|
|
1777
|
+
|
|
1778
|
+
"""
|
|
1779
|
+
conditions = conditions or {}
|
|
1780
|
+
conditions.update(kwargs)
|
|
1781
|
+
|
|
1782
|
+
for key in self.edges():
|
|
1783
|
+
is_match = True
|
|
1784
|
+
|
|
1785
|
+
attr = self.edge_attributes(key) or {}
|
|
1786
|
+
|
|
1787
|
+
for name, value in conditions.items():
|
|
1788
|
+
method = getattr(self, name, None)
|
|
1789
|
+
|
|
1790
|
+
if method and callable(method):
|
|
1791
|
+
val = method(key)
|
|
1792
|
+
elif name in attr:
|
|
1793
|
+
val = attr[name]
|
|
1794
|
+
else:
|
|
1795
|
+
is_match = False
|
|
1796
|
+
break
|
|
1797
|
+
|
|
1798
|
+
if isinstance(val, list):
|
|
1799
|
+
if value not in val:
|
|
1800
|
+
is_match = False
|
|
1801
|
+
break
|
|
1802
|
+
elif isinstance(value, (tuple, list)):
|
|
1803
|
+
minval, maxval = value
|
|
1804
|
+
if val < minval or val > maxval:
|
|
1805
|
+
is_match = False
|
|
1806
|
+
break
|
|
1807
|
+
else:
|
|
1808
|
+
if value != val:
|
|
1809
|
+
is_match = False
|
|
1810
|
+
break
|
|
1811
|
+
|
|
1812
|
+
if is_match:
|
|
1813
|
+
if data:
|
|
1814
|
+
yield key, attr
|
|
1815
|
+
else:
|
|
1816
|
+
yield key
|
|
1817
|
+
|
|
1818
|
+
def edges_where_predicate(self, predicate, data=False):
|
|
1819
|
+
"""Get edges for which a certain condition or set of conditions is true using a lambda function.
|
|
1820
|
+
|
|
1821
|
+
Parameters
|
|
1822
|
+
----------
|
|
1823
|
+
predicate : callable
|
|
1824
|
+
The condition you want to evaluate.
|
|
1825
|
+
The callable takes 2 parameters: the edge identifier and the edge attributes, and should return True or False.
|
|
1826
|
+
data : bool, optional
|
|
1827
|
+
If True, yield the edge attributes in addition to the identifiers.
|
|
1828
|
+
|
|
1829
|
+
Yields
|
|
1830
|
+
------
|
|
1831
|
+
tuple[int, int] | tuple[tuple[int, int], dict[str, Any]]
|
|
1832
|
+
If `data` is False, the next edge as a (u, v) tuple.
|
|
1833
|
+
If `data` is True, the next edge as a (u, v, data) tuple.
|
|
1834
|
+
|
|
1835
|
+
See Also
|
|
1836
|
+
--------
|
|
1837
|
+
:meth:`edges_where`
|
|
1838
|
+
:meth:`vertices_where_predicate`, :meth:`faces_where_predicate`, :meth:`cells_where_predicate`
|
|
1839
|
+
|
|
1840
|
+
"""
|
|
1841
|
+
for key, attr in self.edges(True):
|
|
1842
|
+
if predicate(key, attr):
|
|
1843
|
+
if data:
|
|
1844
|
+
yield key, attr
|
|
1845
|
+
else:
|
|
1846
|
+
yield key
|
|
1847
|
+
|
|
1848
|
+
# --------------------------------------------------------------------------
|
|
1849
|
+
# Edge Attributes
|
|
1850
|
+
# --------------------------------------------------------------------------
|
|
1851
|
+
|
|
1852
|
+
def update_default_edge_attributes(self, attr_dict=None, **kwattr):
|
|
1853
|
+
"""Update the default edge attributes.
|
|
1854
|
+
|
|
1855
|
+
Parameters
|
|
1856
|
+
----------
|
|
1857
|
+
attr_dict : dict[str, Any], optional
|
|
1858
|
+
A dictionary of attributes with their default values.
|
|
1859
|
+
**kwattr : dict[str, Any], optional
|
|
1860
|
+
A dictionary of additional attributes compiled of remaining named arguments.
|
|
1861
|
+
|
|
1862
|
+
Returns
|
|
1863
|
+
-------
|
|
1864
|
+
None
|
|
1865
|
+
|
|
1866
|
+
See Also
|
|
1867
|
+
--------
|
|
1868
|
+
:meth:`update_default_vertex_attributes`, :meth:`update_default_face_attributes`, :meth:`update_default_cell_attributes`
|
|
1869
|
+
|
|
1870
|
+
Notes
|
|
1871
|
+
-----
|
|
1872
|
+
Named arguments overwrite correpsonding key-value pairs in the attribute dictionary.
|
|
1873
|
+
|
|
1874
|
+
"""
|
|
1875
|
+
if not attr_dict:
|
|
1876
|
+
attr_dict = {}
|
|
1877
|
+
attr_dict.update(kwattr)
|
|
1878
|
+
self.default_edge_attributes.update(attr_dict)
|
|
1879
|
+
|
|
1880
|
+
def edge_attribute(self, edge, name, value=None):
|
|
1881
|
+
"""Get or set an attribute of an edge.
|
|
1882
|
+
|
|
1883
|
+
Parameters
|
|
1884
|
+
----------
|
|
1885
|
+
edge : tuple[int, int]
|
|
1886
|
+
The edge identifier.
|
|
1887
|
+
name : str
|
|
1888
|
+
The name of the attribute.
|
|
1889
|
+
value : object, optional
|
|
1890
|
+
The value of the attribute.
|
|
1891
|
+
|
|
1892
|
+
Returns
|
|
1893
|
+
-------
|
|
1894
|
+
object | None
|
|
1895
|
+
The value of the attribute, or None when the function is used as a "setter".
|
|
1896
|
+
|
|
1897
|
+
Raises
|
|
1898
|
+
------
|
|
1899
|
+
KeyError
|
|
1900
|
+
If the edge does not exist.
|
|
1901
|
+
|
|
1902
|
+
See Also
|
|
1903
|
+
--------
|
|
1904
|
+
:meth:`unset_edge_attribute`
|
|
1905
|
+
:meth:`edge_attributes`, :meth:`edges_attribute`, :meth:`edges_attributes`
|
|
1906
|
+
:meth:`vertex_attribute`, :meth:`face_attribute`, :meth:`cell_attribute`
|
|
1907
|
+
|
|
1908
|
+
"""
|
|
1909
|
+
u, v = edge
|
|
1910
|
+
if u not in self._plane or v not in self._plane[u]:
|
|
1911
|
+
raise KeyError(edge)
|
|
1912
|
+
key = str(tuple(sorted(edge)))
|
|
1913
|
+
if value is not None:
|
|
1914
|
+
if key not in self._edge_data:
|
|
1915
|
+
self._edge_data[key] = {}
|
|
1916
|
+
self._edge_data[key][name] = value
|
|
1917
|
+
return
|
|
1918
|
+
if key in self._edge_data and name in self._edge_data[key]:
|
|
1919
|
+
return self._edge_data[key][name]
|
|
1920
|
+
if name in self.default_edge_attributes:
|
|
1921
|
+
return self.default_edge_attributes[name]
|
|
1922
|
+
|
|
1923
|
+
def unset_edge_attribute(self, edge, name):
|
|
1924
|
+
"""Unset the attribute of an edge.
|
|
1925
|
+
|
|
1926
|
+
Parameters
|
|
1927
|
+
----------
|
|
1928
|
+
edge : tuple[int, int]
|
|
1929
|
+
The edge identifier.
|
|
1930
|
+
name : str
|
|
1931
|
+
The name of the attribute.
|
|
1932
|
+
|
|
1933
|
+
Raises
|
|
1934
|
+
------
|
|
1935
|
+
KeyError
|
|
1936
|
+
If the edge does not exist.
|
|
1937
|
+
|
|
1938
|
+
Returns
|
|
1939
|
+
-------
|
|
1940
|
+
None
|
|
1941
|
+
|
|
1942
|
+
See Also
|
|
1943
|
+
--------
|
|
1944
|
+
:meth:`edge_attribute`
|
|
1945
|
+
|
|
1946
|
+
Notes
|
|
1947
|
+
-----
|
|
1948
|
+
Unsetting the value of an edge attribute implicitly sets it back to the value
|
|
1949
|
+
stored in the default edge attribute dict.
|
|
1950
|
+
|
|
1951
|
+
"""
|
|
1952
|
+
u, v = edge
|
|
1953
|
+
if u not in self._plane or v not in self._plane[u]:
|
|
1954
|
+
raise KeyError(edge)
|
|
1955
|
+
key = str(tuple(sorted(edge)))
|
|
1956
|
+
if key in self._edge_data and name in self._edge_data[key]:
|
|
1957
|
+
del self._edge_data[key][name]
|
|
1958
|
+
|
|
1959
|
+
def edge_attributes(self, edge, names=None, values=None):
|
|
1960
|
+
"""Get or set multiple attributes of an edge.
|
|
1961
|
+
|
|
1962
|
+
Parameters
|
|
1963
|
+
----------
|
|
1964
|
+
edge : tuple[int, int]
|
|
1965
|
+
The identifier of the edge.
|
|
1966
|
+
names : list[str], optional
|
|
1967
|
+
A list of attribute names.
|
|
1968
|
+
values : list[Any], optional
|
|
1969
|
+
A list of attribute values.
|
|
1970
|
+
|
|
1971
|
+
Returns
|
|
1972
|
+
-------
|
|
1973
|
+
dict[str, Any] | list[Any] | None
|
|
1974
|
+
If the parameter `names` is empty, a dictionary of all attribute name-value pairs of the edge.
|
|
1975
|
+
If the parameter `names` is not empty, a list of the values corresponding to the provided names.
|
|
1976
|
+
None if the function is used as a "setter".
|
|
1977
|
+
|
|
1978
|
+
Raises
|
|
1979
|
+
------
|
|
1980
|
+
KeyError
|
|
1981
|
+
If the edge does not exist.
|
|
1982
|
+
|
|
1983
|
+
See Also
|
|
1984
|
+
--------
|
|
1985
|
+
:meth:`edge_attribute`, :meth:`edges_attribute`, :meth:`edges_attributes`
|
|
1986
|
+
:meth:`vertex_attributes`, :meth:`face_attributes`, :meth:`cell_attributes`
|
|
1987
|
+
|
|
1988
|
+
"""
|
|
1989
|
+
u, v = edge
|
|
1990
|
+
if u not in self._plane or v not in self._plane[u]:
|
|
1991
|
+
raise KeyError(edge)
|
|
1992
|
+
key = str(tuple(sorted(edge)))
|
|
1993
|
+
if names and values:
|
|
1994
|
+
for name, value in zip(names, values):
|
|
1995
|
+
if key not in self._edge_data:
|
|
1996
|
+
self._edge_data[key] = {}
|
|
1997
|
+
self._edge_data[key][name] = value
|
|
1998
|
+
return
|
|
1999
|
+
if not names:
|
|
2000
|
+
key = str(tuple(sorted(edge)))
|
|
2001
|
+
return EdgeAttributeView(self.default_edge_attributes, self._edge_data.setdefault(key, {}))
|
|
2002
|
+
values = []
|
|
2003
|
+
for name in names:
|
|
2004
|
+
value = self.edge_attribute(edge, name)
|
|
2005
|
+
values.append(value)
|
|
2006
|
+
return values
|
|
2007
|
+
|
|
2008
|
+
def edges_attribute(self, name, value=None, edges=None):
|
|
2009
|
+
"""Get or set an attribute of multiple edges.
|
|
2010
|
+
|
|
2011
|
+
Parameters
|
|
2012
|
+
----------
|
|
2013
|
+
name : str
|
|
2014
|
+
The name of the attribute.
|
|
2015
|
+
value : object, optional
|
|
2016
|
+
The value of the attribute.
|
|
2017
|
+
Default is None.
|
|
2018
|
+
edges : list[tuple[int, int]], optional
|
|
2019
|
+
A list of edge identifiers.
|
|
2020
|
+
|
|
2021
|
+
Returns
|
|
2022
|
+
-------
|
|
2023
|
+
list[Any] | None
|
|
2024
|
+
A list containing the value per edge of the requested attribute,
|
|
2025
|
+
or None if the function is used as a "setter".
|
|
2026
|
+
|
|
2027
|
+
Raises
|
|
2028
|
+
------
|
|
2029
|
+
KeyError
|
|
2030
|
+
If any of the edges does not exist.
|
|
2031
|
+
|
|
2032
|
+
See Also
|
|
2033
|
+
--------
|
|
2034
|
+
:meth:`edge_attribute`, :meth:`edge_attributes`, :meth:`edges_attributes`
|
|
2035
|
+
:meth:`vertex_attribute`, :meth:`face_attribute`, :meth:`cell_attribute`
|
|
2036
|
+
|
|
2037
|
+
"""
|
|
2038
|
+
edges = edges or self.edges()
|
|
2039
|
+
if value is not None:
|
|
2040
|
+
for edge in edges:
|
|
2041
|
+
self.edge_attribute(edge, name, value)
|
|
2042
|
+
return
|
|
2043
|
+
return [self.edge_attribute(edge, name) for edge in edges]
|
|
2044
|
+
|
|
2045
|
+
def edges_attributes(self, names=None, values=None, edges=None):
|
|
2046
|
+
"""Get or set multiple attributes of multiple edges.
|
|
2047
|
+
|
|
2048
|
+
Parameters
|
|
2049
|
+
----------
|
|
2050
|
+
names : list[str], optional
|
|
2051
|
+
The names of the attribute.
|
|
2052
|
+
values : list[Any], optional
|
|
2053
|
+
The values of the attributes.
|
|
2054
|
+
edges : list[tuple[int, int]], optional
|
|
2055
|
+
A list of edge identifiers.
|
|
2056
|
+
|
|
2057
|
+
Returns
|
|
2058
|
+
-------
|
|
2059
|
+
list[dict[str, Any]] | list[list[Any]] | None
|
|
2060
|
+
If the parameter `names` is empty,
|
|
2061
|
+
a list containing per edge an attribute dict with all attributes (default + custom) of the edge.
|
|
2062
|
+
If the parameter `names` is not empty,
|
|
2063
|
+
a list containing per edge a list of attribute values corresponding to the requested names.
|
|
2064
|
+
None if the function is used as a "setter".
|
|
2065
|
+
|
|
2066
|
+
Raises
|
|
2067
|
+
------
|
|
2068
|
+
KeyError
|
|
2069
|
+
If any of the edges does not exist.
|
|
2070
|
+
|
|
2071
|
+
See Also
|
|
2072
|
+
--------
|
|
2073
|
+
:meth:`edge_attribute`, :meth:`edge_attributes`, :meth:`edges_attribute`
|
|
2074
|
+
:meth:`vertex_attributes`, :meth:`face_attributes`, :meth:`cell_attributes`
|
|
2075
|
+
|
|
2076
|
+
"""
|
|
2077
|
+
edges = edges or self.edges()
|
|
2078
|
+
if values:
|
|
2079
|
+
for edge in edges:
|
|
2080
|
+
self.edge_attributes(edge, names, values)
|
|
2081
|
+
return
|
|
2082
|
+
return [self.edge_attributes(edge, names) for edge in edges]
|
|
2083
|
+
|
|
2084
|
+
# --------------------------------------------------------------------------
|
|
2085
|
+
# Edge Topology
|
|
2086
|
+
# --------------------------------------------------------------------------
|
|
2087
|
+
|
|
2088
|
+
def has_edge(self, edge):
|
|
2089
|
+
"""Verify that the volmesh contains a directed edge (u, v).
|
|
2090
|
+
|
|
2091
|
+
Parameters
|
|
2092
|
+
----------
|
|
2093
|
+
edge : tuple[int, int]
|
|
2094
|
+
The identifier of the edge.
|
|
2095
|
+
|
|
2096
|
+
Returns
|
|
2097
|
+
-------
|
|
2098
|
+
bool
|
|
2099
|
+
True if the edge exists.
|
|
2100
|
+
False otherwise.
|
|
2101
|
+
|
|
2102
|
+
See Also
|
|
2103
|
+
--------
|
|
2104
|
+
:meth:`has_vertex`, :meth:`has_face`, :meth:`has_cell`
|
|
2105
|
+
|
|
2106
|
+
"""
|
|
2107
|
+
return edge in set(self.edges())
|
|
2108
|
+
|
|
2109
|
+
def edge_halffaces(self, edge):
|
|
2110
|
+
"""Ordered halffaces around edge (u, v).
|
|
2111
|
+
|
|
2112
|
+
Parameters
|
|
2113
|
+
----------
|
|
2114
|
+
edge : tuple[int, int]
|
|
2115
|
+
The identifier of the edge.
|
|
2116
|
+
|
|
2117
|
+
Returns
|
|
2118
|
+
-------
|
|
2119
|
+
list[int]
|
|
2120
|
+
Ordered list of halfface identifiers.
|
|
2121
|
+
|
|
2122
|
+
See Also
|
|
2123
|
+
--------
|
|
2124
|
+
:meth:`edge_cells`
|
|
2125
|
+
|
|
2126
|
+
"""
|
|
2127
|
+
u, v = edge
|
|
2128
|
+
cells = [cell for cell in self._plane[u][v].values() if cell is not None]
|
|
2129
|
+
cell = cells[0]
|
|
2130
|
+
halffaces = []
|
|
2131
|
+
if self.is_edge_on_boundary(edge):
|
|
2132
|
+
for cell in cells:
|
|
2133
|
+
halfface = self._cell[cell][v][u]
|
|
2134
|
+
if self.is_halfface_on_boundary(halfface):
|
|
2135
|
+
break
|
|
2136
|
+
for _ in cells:
|
|
2137
|
+
halfface = self._cell[cell][u][v]
|
|
2138
|
+
cell = self._plane[v][u][halfface]
|
|
2139
|
+
halffaces.append(halfface)
|
|
2140
|
+
return halffaces
|
|
2141
|
+
|
|
2142
|
+
def edge_cells(self, edge):
|
|
2143
|
+
"""Ordered cells around edge (u, v).
|
|
2144
|
+
|
|
2145
|
+
Parameters
|
|
2146
|
+
----------
|
|
2147
|
+
edge : tuple[int, int]
|
|
2148
|
+
The identifier of the edge.
|
|
2149
|
+
|
|
2150
|
+
Returns
|
|
2151
|
+
-------
|
|
2152
|
+
list[int]
|
|
2153
|
+
Ordered list of keys identifying the ordered cells.
|
|
2154
|
+
|
|
2155
|
+
See Also
|
|
2156
|
+
--------
|
|
2157
|
+
:meth:`edge_halffaces`
|
|
2158
|
+
|
|
2159
|
+
"""
|
|
2160
|
+
halffaces = self.edge_halffaces(edge)
|
|
2161
|
+
return [self.halfface_cell(halfface) for halfface in halffaces]
|
|
2162
|
+
|
|
2163
|
+
def is_edge_on_boundary(self, edge):
|
|
2164
|
+
"""Verify that an edge is on the boundary.
|
|
2165
|
+
|
|
2166
|
+
Parameters
|
|
2167
|
+
----------
|
|
2168
|
+
edge : tuple[int, int]
|
|
2169
|
+
The identifier of the edge.
|
|
2170
|
+
|
|
2171
|
+
Returns
|
|
2172
|
+
-------
|
|
2173
|
+
bool
|
|
2174
|
+
True if the edge is on the boundary.
|
|
2175
|
+
False otherwise.
|
|
2176
|
+
|
|
2177
|
+
See Also
|
|
2178
|
+
--------
|
|
2179
|
+
:meth:`is_vertex_on_boundary`, :meth:`is_face_on_boundary`, :meth:`is_cell_on_boundary`
|
|
2180
|
+
|
|
2181
|
+
Notes
|
|
2182
|
+
-----
|
|
2183
|
+
This method simply checks if u-v or v-u is on the edge of the volmesh.
|
|
2184
|
+
The direction u-v does not matter.
|
|
2185
|
+
|
|
2186
|
+
"""
|
|
2187
|
+
u, v = edge
|
|
2188
|
+
return None in self._plane[u][v].values()
|
|
2189
|
+
|
|
2190
|
+
# --------------------------------------------------------------------------
|
|
2191
|
+
# Edge Geometry
|
|
2192
|
+
# --------------------------------------------------------------------------
|
|
2193
|
+
|
|
2194
|
+
def edge_coordinates(self, edge, axes="xyz"):
|
|
2195
|
+
"""Return the coordinates of the start and end point of an edge.
|
|
2196
|
+
|
|
2197
|
+
Parameters
|
|
2198
|
+
----------
|
|
2199
|
+
edge : tuple[int, int]
|
|
2200
|
+
The edge identifier.
|
|
2201
|
+
axes : str, optional
|
|
2202
|
+
The axes along which the coordinates should be included.
|
|
2203
|
+
|
|
2204
|
+
Returns
|
|
2205
|
+
-------
|
|
2206
|
+
tuple[list[float], list[float]]
|
|
2207
|
+
The coordinates of the start point.
|
|
2208
|
+
The coordinates of the end point.
|
|
2209
|
+
|
|
2210
|
+
See Also
|
|
2211
|
+
--------
|
|
2212
|
+
:meth:`edge_start`, :meth:`edge_end`, :meth:`edge_midpoint`, :meth:`edge_point`
|
|
2213
|
+
:meth:`edge_vector`, :meth:`edge_direction`, :meth:`edge_line`
|
|
2214
|
+
:meth:`edge_length`
|
|
2215
|
+
|
|
2216
|
+
"""
|
|
2217
|
+
u, v = edge
|
|
2218
|
+
return self.vertex_coordinates(u, axes=axes), self.vertex_coordinates(v, axes=axes)
|
|
2219
|
+
|
|
2220
|
+
def edge_start(self, edge):
|
|
2221
|
+
"""Return the start point of an edge.
|
|
2222
|
+
|
|
2223
|
+
Parameters
|
|
2224
|
+
----------
|
|
2225
|
+
edge : tuple[int, int]
|
|
2226
|
+
The edge identifier.
|
|
2227
|
+
|
|
2228
|
+
Returns
|
|
2229
|
+
-------
|
|
2230
|
+
:class:`compas.geometry.Point`
|
|
2231
|
+
The start point.
|
|
2232
|
+
|
|
2233
|
+
See Also
|
|
2234
|
+
--------
|
|
2235
|
+
:meth:`edge_end`, :meth:`edge_midpoint`, :meth:`edge_point`
|
|
2236
|
+
|
|
2237
|
+
"""
|
|
2238
|
+
return self.vertex_point(edge[0])
|
|
2239
|
+
|
|
2240
|
+
def edge_end(self, edge):
|
|
2241
|
+
"""Return the end point of an edge.
|
|
2242
|
+
|
|
2243
|
+
Parameters
|
|
2244
|
+
----------
|
|
2245
|
+
edge : tuple[int, int]
|
|
2246
|
+
The edge identifier.
|
|
2247
|
+
|
|
2248
|
+
Returns
|
|
2249
|
+
-------
|
|
2250
|
+
:class:`compas.geometry.Point`
|
|
2251
|
+
The end point.
|
|
2252
|
+
|
|
2253
|
+
See Also
|
|
2254
|
+
--------
|
|
2255
|
+
:meth:`edge_start`, :meth:`edge_midpoint`, :meth:`edge_point`
|
|
2256
|
+
|
|
2257
|
+
"""
|
|
2258
|
+
return self.vertex_point(edge[1])
|
|
2259
|
+
|
|
2260
|
+
def edge_midpoint(self, edge):
|
|
2261
|
+
"""Return the midpoint of an edge.
|
|
2262
|
+
|
|
2263
|
+
Parameters
|
|
2264
|
+
----------
|
|
2265
|
+
edge : tuple[int, int]
|
|
2266
|
+
The edge identifier.
|
|
2267
|
+
|
|
2268
|
+
Returns
|
|
2269
|
+
-------
|
|
2270
|
+
:class:`compas.geometry.Point`
|
|
2271
|
+
The midpoint.
|
|
2272
|
+
|
|
2273
|
+
See Also
|
|
2274
|
+
--------
|
|
2275
|
+
:meth:`edge_start`, :meth:`edge_end`, :meth:`edge_point`
|
|
2276
|
+
|
|
2277
|
+
"""
|
|
2278
|
+
a, b = self.edge_coordinates(edge)
|
|
2279
|
+
return Point(0.5 * (a[0] + b[0]), 0.5 * (a[1] + b[1]), 0.5 * (a[2] + b[2]))
|
|
2280
|
+
|
|
2281
|
+
def edge_point(self, edge, t=0.5):
|
|
2282
|
+
"""Return the point at a parametric location along an edge.
|
|
2283
|
+
|
|
2284
|
+
Parameters
|
|
2285
|
+
----------
|
|
2286
|
+
edge : tuple[int, int]
|
|
2287
|
+
The edge identifier.
|
|
2288
|
+
t : float, optional
|
|
2289
|
+
The location of the point on the edge.
|
|
2290
|
+
If the value of `t` is outside the range 0-1, the point will
|
|
2291
|
+
lie in the direction of the edge, but not on the edge vector.
|
|
2292
|
+
|
|
2293
|
+
Returns
|
|
2294
|
+
-------
|
|
2295
|
+
:class:`compas.geometry.Point`
|
|
2296
|
+
The XYZ coordinates of the point.
|
|
2297
|
+
|
|
2298
|
+
See Also
|
|
2299
|
+
--------
|
|
2300
|
+
:meth:`edge_start`, :meth:`edge_end`, :meth:`edge_midpoint`
|
|
2301
|
+
|
|
2302
|
+
"""
|
|
2303
|
+
if t == 0:
|
|
2304
|
+
return self.edge_start(edge)
|
|
2305
|
+
if t == 1:
|
|
2306
|
+
return self.edge_end(edge)
|
|
2307
|
+
if t == 0.5:
|
|
2308
|
+
return self.edge_midpoint(edge)
|
|
2309
|
+
|
|
2310
|
+
a, b = self.edge_coordinates(edge)
|
|
2311
|
+
ab = subtract_vectors(b, a)
|
|
2312
|
+
return Point(*add_vectors(a, scale_vector(ab, t)))
|
|
2313
|
+
|
|
2314
|
+
def edge_vector(self, edge):
|
|
2315
|
+
"""Return the vector of an edge.
|
|
2316
|
+
|
|
2317
|
+
Parameters
|
|
2318
|
+
----------
|
|
2319
|
+
edge : tuple[int, int]
|
|
2320
|
+
The edge identifier.
|
|
2321
|
+
|
|
2322
|
+
Returns
|
|
2323
|
+
-------
|
|
2324
|
+
:class:`compas.geometry.Vector`
|
|
2325
|
+
The vector from start to end.
|
|
2326
|
+
|
|
2327
|
+
See Also
|
|
2328
|
+
--------
|
|
2329
|
+
:meth:`edge_direction`, :meth:`edge_line`
|
|
2330
|
+
|
|
2331
|
+
"""
|
|
2332
|
+
a, b = self.edge_coordinates(edge)
|
|
2333
|
+
return Vector.from_start_end(a, b)
|
|
2334
|
+
|
|
2335
|
+
def edge_direction(self, edge):
|
|
2336
|
+
"""Return the direction vector of an edge.
|
|
2337
|
+
|
|
2338
|
+
Parameters
|
|
2339
|
+
----------
|
|
2340
|
+
edge : tuple[int, int]
|
|
2341
|
+
The edge identifier.
|
|
2342
|
+
|
|
2343
|
+
Returns
|
|
2344
|
+
-------
|
|
2345
|
+
:class:`compas.geometry.Vector`
|
|
2346
|
+
The direction vector of the edge.
|
|
2347
|
+
|
|
2348
|
+
See Also
|
|
2349
|
+
--------
|
|
2350
|
+
:meth:`edge_vector`, :meth:`edge_line`
|
|
2351
|
+
|
|
2352
|
+
"""
|
|
2353
|
+
return Vector(*normalize_vector(self.edge_vector(edge)))
|
|
2354
|
+
|
|
2355
|
+
def edge_line(self, edge):
|
|
2356
|
+
"""Return the line representation of an edge.
|
|
2357
|
+
|
|
2358
|
+
Parameters
|
|
2359
|
+
----------
|
|
2360
|
+
edge : tuple[int, int]
|
|
2361
|
+
The edge identifier.
|
|
2362
|
+
|
|
2363
|
+
Returns
|
|
2364
|
+
-------
|
|
2365
|
+
:class:`compas.geometry.Line`
|
|
2366
|
+
The line.
|
|
2367
|
+
|
|
2368
|
+
See Also
|
|
2369
|
+
--------
|
|
2370
|
+
:meth:`edge_vector`, :meth:`edge_direction`
|
|
2371
|
+
|
|
2372
|
+
"""
|
|
2373
|
+
return Line(self.edge_start(edge), self.edge_end(edge))
|
|
2374
|
+
|
|
2375
|
+
def edge_length(self, edge):
|
|
2376
|
+
"""Return the length of an edge.
|
|
2377
|
+
|
|
2378
|
+
Parameters
|
|
2379
|
+
----------
|
|
2380
|
+
edge : tuple[int, int]
|
|
2381
|
+
The edge identifier.
|
|
2382
|
+
|
|
2383
|
+
Returns
|
|
2384
|
+
-------
|
|
2385
|
+
float
|
|
2386
|
+
The length of the edge.
|
|
2387
|
+
|
|
2388
|
+
"""
|
|
2389
|
+
a, b = self.edge_coordinates(edge)
|
|
2390
|
+
return distance_point_point(a, b)
|
|
2391
|
+
|
|
2392
|
+
# --------------------------------------------------------------------------
|
|
2393
|
+
# (Half)Face Accessors
|
|
2394
|
+
# --------------------------------------------------------------------------
|
|
2395
|
+
|
|
2396
|
+
def halffaces(self, data=False):
|
|
2397
|
+
"""Iterate over the halffaces of the volmesh.
|
|
2398
|
+
|
|
2399
|
+
Parameters
|
|
2400
|
+
----------
|
|
2401
|
+
data : bool, optional
|
|
2402
|
+
If True, yield the half-face attributes in addition to half-face identifiers.
|
|
2403
|
+
|
|
2404
|
+
Yields
|
|
2405
|
+
------
|
|
2406
|
+
int | tuple[int, dict[str, Any]]
|
|
2407
|
+
If `data` is False, the next halfface identifier.
|
|
2408
|
+
If `data` is True, the next halfface as a (halfface, attr) tuple.
|
|
2409
|
+
|
|
2410
|
+
See Also
|
|
2411
|
+
--------
|
|
2412
|
+
:meth:`vertices`, :meth:`edges`, :meth:`cells`
|
|
2413
|
+
|
|
2414
|
+
"""
|
|
2415
|
+
for hface in self._halfface:
|
|
2416
|
+
if not data:
|
|
2417
|
+
yield hface
|
|
2418
|
+
else:
|
|
2419
|
+
yield hface, self.face_attributes(hface)
|
|
2420
|
+
|
|
2421
|
+
def faces(self, data=False):
|
|
2422
|
+
""" "Iterate over the halffaces of the volmesh and yield faces.
|
|
2423
|
+
|
|
2424
|
+
Parameters
|
|
2425
|
+
----------
|
|
2426
|
+
data : bool, optional
|
|
2427
|
+
If True, yield the face attributes in addition to the face identifiers.
|
|
2428
|
+
|
|
2429
|
+
Yields
|
|
2430
|
+
------
|
|
2431
|
+
int | tuple[int, dict[str, Any]]
|
|
2432
|
+
If `data` is False, the next face identifier.
|
|
2433
|
+
If `data` is True, the next face as a (face, attr) tuple.
|
|
2434
|
+
|
|
2435
|
+
See Also
|
|
2436
|
+
--------
|
|
2437
|
+
:meth:`vertices`, :meth:`edges`, :meth:`cells`
|
|
2438
|
+
|
|
2439
|
+
Notes
|
|
2440
|
+
-----
|
|
2441
|
+
Volmesh faces have no topological meaning (analogous to an edge of a mesh).
|
|
2442
|
+
They are typically used for geometric operations (i.e. planarisation).
|
|
2443
|
+
Between the interface of two cells, there are two interior faces (one from each cell).
|
|
2444
|
+
Only one of these two interior faces are returned as a "face".
|
|
2445
|
+
The unique faces are found by comparing string versions of sorted vertex lists.
|
|
2446
|
+
|
|
2447
|
+
"""
|
|
2448
|
+
seen = set()
|
|
2449
|
+
faces = []
|
|
2450
|
+
for face in self._halfface:
|
|
2451
|
+
key = "-".join(map(str, sorted(self.halfface_vertices(face))))
|
|
2452
|
+
if key not in seen:
|
|
2453
|
+
seen.add(key)
|
|
2454
|
+
faces.append(face)
|
|
2455
|
+
for face in faces:
|
|
2456
|
+
if not data:
|
|
2457
|
+
yield face
|
|
2458
|
+
else:
|
|
2459
|
+
yield face, self.face_attributes(face)
|
|
2460
|
+
|
|
2461
|
+
def faces_where(self, conditions=None, data=False, **kwargs):
|
|
2462
|
+
"""Get faces for which a certain condition or set of conditions is true.
|
|
2463
|
+
|
|
2464
|
+
Parameters
|
|
2465
|
+
----------
|
|
2466
|
+
conditions : dict, optional
|
|
2467
|
+
A set of conditions in the form of key-value pairs.
|
|
2468
|
+
The keys should be attribute names. The values can be attribute
|
|
2469
|
+
values or ranges of attribute values in the form of min/max pairs.
|
|
2470
|
+
data : bool, optional
|
|
2471
|
+
If True, yield the face attributes in addition to the identifiers.
|
|
2472
|
+
**kwargs : dict[str, Any], optional
|
|
2473
|
+
Additional conditions provided as named function arguments.
|
|
2474
|
+
|
|
2475
|
+
Yields
|
|
2476
|
+
------
|
|
2477
|
+
int | tuple[int, dict[str, Any]]
|
|
2478
|
+
If `data` is False, the next face that matches the condition.
|
|
2479
|
+
If `data` is True, the next face and its attributes.
|
|
2480
|
+
|
|
2481
|
+
See Also
|
|
2482
|
+
--------
|
|
2483
|
+
:meth:`faces_where_predicate`
|
|
2484
|
+
:meth:`vertices_where`, :meth:`edges_where`, :meth:`cells_where`
|
|
2485
|
+
|
|
2486
|
+
"""
|
|
2487
|
+
conditions = conditions or {}
|
|
2488
|
+
conditions.update(kwargs)
|
|
2489
|
+
|
|
2490
|
+
for fkey in self.faces():
|
|
2491
|
+
is_match = True
|
|
2492
|
+
|
|
2493
|
+
attr = self.face_attributes(fkey) or {}
|
|
2494
|
+
|
|
2495
|
+
for name, value in conditions.items():
|
|
2496
|
+
method = getattr(self, name, None)
|
|
2497
|
+
|
|
2498
|
+
if method and callable(method):
|
|
2499
|
+
val = method(fkey)
|
|
2500
|
+
elif name in attr:
|
|
2501
|
+
val = attr[name]
|
|
2502
|
+
else:
|
|
2503
|
+
is_match = False
|
|
2504
|
+
break
|
|
2505
|
+
|
|
2506
|
+
if isinstance(val, list):
|
|
2507
|
+
if value not in val:
|
|
2508
|
+
is_match = False
|
|
2509
|
+
break
|
|
2510
|
+
elif isinstance(value, (tuple, list)):
|
|
2511
|
+
minval, maxval = value
|
|
2512
|
+
if val < minval or val > maxval:
|
|
2513
|
+
is_match = False
|
|
2514
|
+
break
|
|
2515
|
+
else:
|
|
2516
|
+
if value != val:
|
|
2517
|
+
is_match = False
|
|
2518
|
+
break
|
|
2519
|
+
|
|
2520
|
+
if is_match:
|
|
2521
|
+
if data:
|
|
2522
|
+
yield fkey, attr
|
|
2523
|
+
else:
|
|
2524
|
+
yield fkey
|
|
2525
|
+
|
|
2526
|
+
def faces_where_predicate(self, predicate, data=False):
|
|
2527
|
+
"""Get faces for which a certain condition or set of conditions is true using a lambda function.
|
|
2528
|
+
|
|
2529
|
+
Parameters
|
|
2530
|
+
----------
|
|
2531
|
+
predicate : callable
|
|
2532
|
+
The condition you want to evaluate.
|
|
2533
|
+
The callable takes 2 parameters: the face identifier and the the face attributes, and should return True or False.
|
|
2534
|
+
data : bool, optional
|
|
2535
|
+
If True, yield the face attributes in addition to the identifiers.
|
|
2536
|
+
|
|
2537
|
+
Yields
|
|
2538
|
+
------
|
|
2539
|
+
int | tuple[int, dict[str, Any]]
|
|
2540
|
+
If `data` is False, the next face that matches the condition.
|
|
2541
|
+
If `data` is True, the next face and its attributes.
|
|
2542
|
+
|
|
2543
|
+
See Also
|
|
2544
|
+
--------
|
|
2545
|
+
:meth:`faces_where`
|
|
2546
|
+
:meth:`vertices_where_predicate`, :meth:`edges_where_predicate`, :meth:`cells_where_predicate`
|
|
2547
|
+
|
|
2548
|
+
"""
|
|
2549
|
+
for fkey, attr in self.faces(True):
|
|
2550
|
+
if predicate(fkey, attr):
|
|
2551
|
+
if data:
|
|
2552
|
+
yield fkey, attr
|
|
2553
|
+
else:
|
|
2554
|
+
yield fkey
|
|
2555
|
+
|
|
2556
|
+
# --------------------------------------------------------------------------
|
|
2557
|
+
# Face Attributes
|
|
2558
|
+
# --------------------------------------------------------------------------
|
|
2559
|
+
|
|
2560
|
+
def update_default_face_attributes(self, attr_dict=None, **kwattr):
|
|
2561
|
+
"""Update the default face attributes.
|
|
2562
|
+
|
|
2563
|
+
Parameters
|
|
2564
|
+
----------
|
|
2565
|
+
attr_dict : dict[str, Any], optional
|
|
2566
|
+
A dictionary of attributes with their default values.
|
|
2567
|
+
**kwattr : dict[str, Any], optional
|
|
2568
|
+
A dictionary of additional attributes compiled of remaining named arguments.
|
|
2569
|
+
|
|
2570
|
+
Returns
|
|
2571
|
+
-------
|
|
2572
|
+
None
|
|
2573
|
+
|
|
2574
|
+
See Also
|
|
2575
|
+
--------
|
|
2576
|
+
:meth:`update_default_vertex_attributes`, :meth:`update_default_edge_attributes`, :meth:`update_default_cell_attributes`
|
|
2577
|
+
|
|
2578
|
+
Notes
|
|
2579
|
+
-----
|
|
2580
|
+
Named arguments overwrite correpsonding key-value pairs in the attribute dictionary.
|
|
2581
|
+
|
|
2582
|
+
"""
|
|
2583
|
+
if not attr_dict:
|
|
2584
|
+
attr_dict = {}
|
|
2585
|
+
attr_dict.update(kwattr)
|
|
2586
|
+
self.default_face_attributes.update(attr_dict)
|
|
2587
|
+
|
|
2588
|
+
def face_attribute(self, face, name, value=None):
|
|
2589
|
+
"""Get or set an attribute of a face.
|
|
2590
|
+
|
|
2591
|
+
Parameters
|
|
2592
|
+
----------
|
|
2593
|
+
face : int
|
|
2594
|
+
The face identifier.
|
|
2595
|
+
name : str
|
|
2596
|
+
The name of the attribute.
|
|
2597
|
+
value : object, optional
|
|
2598
|
+
The value of the attribute.
|
|
2599
|
+
|
|
2600
|
+
Returns
|
|
2601
|
+
-------
|
|
2602
|
+
object | None
|
|
2603
|
+
The value of the attribute, or None when the function is used as a "setter".
|
|
2604
|
+
|
|
2605
|
+
Raises
|
|
2606
|
+
------
|
|
2607
|
+
KeyError
|
|
2608
|
+
If the face does not exist.
|
|
2609
|
+
|
|
2610
|
+
See Also
|
|
2611
|
+
--------
|
|
2612
|
+
:meth:`unset_face_attribute`
|
|
2613
|
+
:meth:`face_attributes`, :meth:`faces_attribute`, :meth:`faces_attributes`
|
|
2614
|
+
:meth:`vertex_attribute`, :meth:`edge_attribute`, :meth:`cell_attribute`
|
|
2615
|
+
|
|
2616
|
+
"""
|
|
2617
|
+
if face not in self._halfface:
|
|
2618
|
+
raise KeyError(face)
|
|
2619
|
+
key = str(tuple(sorted(self.halfface_vertices(face))))
|
|
2620
|
+
if value is not None:
|
|
2621
|
+
if key not in self._face_data:
|
|
2622
|
+
self._face_data[key] = {}
|
|
2623
|
+
self._face_data[key][name] = value
|
|
2624
|
+
return
|
|
2625
|
+
if key in self._face_data and name in self._face_data[key]:
|
|
2626
|
+
return self._face_data[key][name]
|
|
2627
|
+
if name in self.default_face_attributes:
|
|
2628
|
+
return self.default_face_attributes[name]
|
|
2629
|
+
|
|
2630
|
+
def unset_face_attribute(self, face, name):
|
|
2631
|
+
"""Unset the attribute of a face.
|
|
2632
|
+
|
|
2633
|
+
Parameters
|
|
2634
|
+
----------
|
|
2635
|
+
face : int
|
|
2636
|
+
The face identifier.
|
|
2637
|
+
name : str
|
|
2638
|
+
The name of the attribute.
|
|
2639
|
+
|
|
2640
|
+
Raises
|
|
2641
|
+
------
|
|
2642
|
+
KeyError
|
|
2643
|
+
If the face does not exist.
|
|
2644
|
+
|
|
2645
|
+
Returns
|
|
2646
|
+
-------
|
|
2647
|
+
None
|
|
2648
|
+
|
|
2649
|
+
See Also
|
|
2650
|
+
--------
|
|
2651
|
+
:meth:`face_attribute`
|
|
2652
|
+
|
|
2653
|
+
Notes
|
|
2654
|
+
-----
|
|
2655
|
+
Unsetting the value of a face attribute implicitly sets it back to the value
|
|
2656
|
+
stored in the default face attribute dict.
|
|
2657
|
+
|
|
2658
|
+
"""
|
|
2659
|
+
if face not in self._halfface:
|
|
2660
|
+
raise KeyError(face)
|
|
2661
|
+
key = str(tuple(sorted(self.halfface_vertices(face))))
|
|
2662
|
+
if key in self._face_data and name in self._face_data[key]:
|
|
2663
|
+
del self._face_data[key][name]
|
|
2664
|
+
|
|
2665
|
+
def face_attributes(self, face, names=None, values=None):
|
|
2666
|
+
"""Get or set multiple attributes of a face.
|
|
2667
|
+
|
|
2668
|
+
Parameters
|
|
2669
|
+
----------
|
|
2670
|
+
face : int
|
|
2671
|
+
The identifier of the face.
|
|
2672
|
+
names : list[str], optional
|
|
2673
|
+
A list of attribute names.
|
|
2674
|
+
values : list[Any], optional
|
|
2675
|
+
A list of attribute values.
|
|
2676
|
+
|
|
2677
|
+
Returns
|
|
2678
|
+
-------
|
|
2679
|
+
dict[str, Any] | list[Any] | None
|
|
2680
|
+
If the parameter `names` is empty, a dictionary of all attribute name-value pairs of the face.
|
|
2681
|
+
If the parameter `names` is not empty, a list of the values corresponding to the provided names.
|
|
2682
|
+
None if the function is used as a "setter".
|
|
2683
|
+
|
|
2684
|
+
Raises
|
|
2685
|
+
------
|
|
2686
|
+
KeyError
|
|
2687
|
+
If the face does not exist.
|
|
2688
|
+
|
|
2689
|
+
See Also
|
|
2690
|
+
--------
|
|
2691
|
+
:meth:`face_attribute`, :meth:`faces_attribute`, :meth:`faces_attributes`
|
|
2692
|
+
:meth:`vertex_attributes`, :meth:`edge_attributes`, :meth:`cell_attributes`
|
|
2693
|
+
|
|
2694
|
+
"""
|
|
2695
|
+
if face not in self._halfface:
|
|
2696
|
+
raise KeyError(face)
|
|
2697
|
+
key = str(tuple(sorted(self.halfface_vertices(face))))
|
|
2698
|
+
if names and values:
|
|
2699
|
+
for name, value in zip(names, values):
|
|
2700
|
+
if key not in self._face_data:
|
|
2701
|
+
self._face_data[key] = {}
|
|
2702
|
+
self._face_data[key][name] = value
|
|
2703
|
+
return
|
|
2704
|
+
if not names:
|
|
2705
|
+
return FaceAttributeView(self.default_face_attributes, self._face_data.setdefault(key, {}))
|
|
2706
|
+
values = []
|
|
2707
|
+
for name in names:
|
|
2708
|
+
value = self.face_attribute(face, name)
|
|
2709
|
+
values.append(value)
|
|
2710
|
+
return values
|
|
2711
|
+
|
|
2712
|
+
def faces_attribute(self, name, value=None, faces=None):
|
|
2713
|
+
"""Get or set an attribute of multiple faces.
|
|
2714
|
+
|
|
2715
|
+
Parameters
|
|
2716
|
+
----------
|
|
2717
|
+
name : str
|
|
2718
|
+
The name of the attribute.
|
|
2719
|
+
value : object, optional
|
|
2720
|
+
The value of the attribute.
|
|
2721
|
+
Default is None.
|
|
2722
|
+
faces : list[int], optional
|
|
2723
|
+
A list of face identifiers.
|
|
2724
|
+
|
|
2725
|
+
Returns
|
|
2726
|
+
-------
|
|
2727
|
+
list[Any] | None
|
|
2728
|
+
A list containing the value per face of the requested attribute,
|
|
2729
|
+
or None if the function is used as a "setter".
|
|
2730
|
+
|
|
2731
|
+
Raises
|
|
2732
|
+
------
|
|
2733
|
+
KeyError
|
|
2734
|
+
If any of the faces does not exist.
|
|
2735
|
+
|
|
2736
|
+
See Also
|
|
2737
|
+
--------
|
|
2738
|
+
:meth:`face_attribute`, :meth:`face_attributes`, :meth:`faces_attributes`
|
|
2739
|
+
:meth:`vertex_attribute`, :meth:`edge_attribute`, :meth:`cell_attribute`
|
|
2740
|
+
|
|
2741
|
+
"""
|
|
2742
|
+
faces = faces or self.faces()
|
|
2743
|
+
if value is not None:
|
|
2744
|
+
for face in faces:
|
|
2745
|
+
self.face_attribute(face, name, value)
|
|
2746
|
+
return
|
|
2747
|
+
return [self.face_attribute(face, name) for face in faces]
|
|
2748
|
+
|
|
2749
|
+
def faces_attributes(self, names=None, values=None, faces=None):
|
|
2750
|
+
"""Get or set multiple attributes of multiple faces.
|
|
2751
|
+
|
|
2752
|
+
Parameters
|
|
2753
|
+
----------
|
|
2754
|
+
names : list[str], optional
|
|
2755
|
+
The names of the attribute.
|
|
2756
|
+
Default is None.
|
|
2757
|
+
values : list[Any], optional
|
|
2758
|
+
The values of the attributes.
|
|
2759
|
+
Default is None.
|
|
2760
|
+
faces : list[int], optional
|
|
2761
|
+
A list of face identifiers.
|
|
2762
|
+
|
|
2763
|
+
Returns
|
|
2764
|
+
-------
|
|
2765
|
+
list[dict[str, Any]] | list[list[Any]] | None
|
|
2766
|
+
If the parameter `names` is empty,
|
|
2767
|
+
a list containing per face an attribute dict with all attributes (default + custom) of the face.
|
|
2768
|
+
If the parameter `names` is not empty,
|
|
2769
|
+
a list containing per face a list of attribute values corresponding to the requested names.
|
|
2770
|
+
None if the function is used as a "setter".
|
|
2771
|
+
|
|
2772
|
+
Raises
|
|
2773
|
+
------
|
|
2774
|
+
KeyError
|
|
2775
|
+
If any of the faces does not exist.
|
|
2776
|
+
|
|
2777
|
+
See Also
|
|
2778
|
+
--------
|
|
2779
|
+
:meth:`face_attribute`, :meth:`face_attributes`, :meth:`faces_attribute`
|
|
2780
|
+
:meth:`vertex_attributes`, :meth:`edge_attributes`, :meth:`cell_attributes`
|
|
2781
|
+
|
|
2782
|
+
"""
|
|
2783
|
+
faces = faces or self.faces()
|
|
2784
|
+
if values:
|
|
2785
|
+
for face in faces:
|
|
2786
|
+
self.face_attributes(face, names, values)
|
|
2787
|
+
return
|
|
2788
|
+
return [self.face_attributes(face, names) for face in faces]
|
|
2789
|
+
|
|
2790
|
+
# --------------------------------------------------------------------------
|
|
2791
|
+
# Face Topology
|
|
2792
|
+
# --------------------------------------------------------------------------
|
|
2793
|
+
|
|
2794
|
+
def has_halfface(self, halfface):
|
|
2795
|
+
"""Verify that a face is part of the volmesh.
|
|
2796
|
+
|
|
2797
|
+
Parameters
|
|
2798
|
+
----------
|
|
2799
|
+
halfface : int
|
|
2800
|
+
The identifier of the halfface.
|
|
2801
|
+
|
|
2802
|
+
Returns
|
|
2803
|
+
-------
|
|
2804
|
+
bool
|
|
2805
|
+
True if the face exists.
|
|
2806
|
+
False otherwise.
|
|
2807
|
+
|
|
2808
|
+
See Also
|
|
2809
|
+
--------
|
|
2810
|
+
:meth:`has_vertex`, :meth:`has_edge`, :meth:`has_cell`
|
|
2811
|
+
|
|
2812
|
+
"""
|
|
2813
|
+
return halfface in self._halfface
|
|
2814
|
+
|
|
2815
|
+
def halfface_vertices(self, halfface):
|
|
2816
|
+
"""The vertices of a halfface.
|
|
2817
|
+
|
|
2818
|
+
Parameters
|
|
2819
|
+
----------
|
|
2820
|
+
halfface : int
|
|
2821
|
+
The identifier of the halfface.
|
|
2822
|
+
|
|
2823
|
+
Returns
|
|
2824
|
+
-------
|
|
2825
|
+
list[int]
|
|
2826
|
+
Ordered vertex identifiers.
|
|
2827
|
+
|
|
2828
|
+
See Also
|
|
2829
|
+
--------
|
|
2830
|
+
:meth:`halfface_edges`, :meth:`halfface_halfedges`
|
|
2831
|
+
|
|
2832
|
+
"""
|
|
2833
|
+
return self._halfface[halfface]
|
|
2834
|
+
|
|
2835
|
+
def halfface_halfedges(self, halfface):
|
|
2836
|
+
"""The halfedges of a halfface.
|
|
2837
|
+
|
|
2838
|
+
Parameters
|
|
2839
|
+
----------
|
|
2840
|
+
halfface : int
|
|
2841
|
+
The identifier of the halfface.
|
|
2842
|
+
|
|
2843
|
+
Returns
|
|
2844
|
+
-------
|
|
2845
|
+
list[tuple[int, int]]
|
|
2846
|
+
The halfedges of a halfface.
|
|
2847
|
+
|
|
2848
|
+
See Also
|
|
2849
|
+
--------
|
|
2850
|
+
:meth:`halfface_edges`, :meth:`halfface_vertices`
|
|
2851
|
+
|
|
2852
|
+
"""
|
|
2853
|
+
vertices = self.halfface_vertices(halfface)
|
|
2854
|
+
return list(pairwise(vertices + vertices[0:1]))
|
|
2855
|
+
|
|
2856
|
+
def halfface_cell(self, halfface):
|
|
2857
|
+
"""The cell to which the halfface belongs to.
|
|
2858
|
+
|
|
2859
|
+
Parameters
|
|
2860
|
+
----------
|
|
2861
|
+
halfface : int
|
|
2862
|
+
The identifier of the halfface.
|
|
2863
|
+
|
|
2864
|
+
Returns
|
|
2865
|
+
-------
|
|
2866
|
+
int
|
|
2867
|
+
Identifier of the cell.
|
|
2868
|
+
|
|
2869
|
+
See Also
|
|
2870
|
+
--------
|
|
2871
|
+
:meth:`halfface_opposite_cell`
|
|
2872
|
+
|
|
2873
|
+
"""
|
|
2874
|
+
u, v = self._halfface[halfface][:2]
|
|
2875
|
+
return self._plane[u][v][halfface]
|
|
2876
|
+
|
|
2877
|
+
def halfface_opposite_cell(self, halfface):
|
|
2878
|
+
"""The cell to which the opposite halfface belongs to.
|
|
2879
|
+
|
|
2880
|
+
Parameters
|
|
2881
|
+
----------
|
|
2882
|
+
halfface : int
|
|
2883
|
+
The identifier of the halfface.
|
|
2884
|
+
|
|
2885
|
+
Returns
|
|
2886
|
+
-------
|
|
2887
|
+
int
|
|
2888
|
+
Identifier of the cell.
|
|
2889
|
+
|
|
2890
|
+
See Also
|
|
2891
|
+
--------
|
|
2892
|
+
:meth:`halfface_cell`
|
|
2893
|
+
|
|
2894
|
+
"""
|
|
2895
|
+
u, v = self._halfface[halfface][:2]
|
|
2896
|
+
return self._plane[v][u][halfface]
|
|
2897
|
+
|
|
2898
|
+
def halfface_opposite_halfface(self, halfface):
|
|
2899
|
+
"""The opposite face of a face.
|
|
2900
|
+
|
|
2901
|
+
Parameters
|
|
2902
|
+
----------
|
|
2903
|
+
halfface : int
|
|
2904
|
+
The identifier of the halfface.
|
|
2905
|
+
|
|
2906
|
+
Returns
|
|
2907
|
+
-------
|
|
2908
|
+
int
|
|
2909
|
+
Identifier of the opposite face.
|
|
2910
|
+
|
|
2911
|
+
See Also
|
|
2912
|
+
--------
|
|
2913
|
+
:meth:`halfface_adjacent_halfface`
|
|
2914
|
+
|
|
2915
|
+
Notes
|
|
2916
|
+
-----
|
|
2917
|
+
A face and its opposite face share the same vertices, but in reverse order.
|
|
2918
|
+
For a boundary face, the opposite face is None.
|
|
2919
|
+
|
|
2920
|
+
"""
|
|
2921
|
+
u, v = self._halfface[halfface][:2]
|
|
2922
|
+
nbr = self._plane[v][u][halfface]
|
|
2923
|
+
return None if nbr is None else self._cell[nbr][v][u]
|
|
2924
|
+
|
|
2925
|
+
def halfface_adjacent_halfface(self, halfface, halfedge):
|
|
2926
|
+
"""Return the halfface adjacent to the halfface across the halfedge.
|
|
2927
|
+
|
|
2928
|
+
Parameters
|
|
2929
|
+
----------
|
|
2930
|
+
halfface : int
|
|
2931
|
+
The identifier of the halfface.
|
|
2932
|
+
halfedge : tuple[int, int]
|
|
2933
|
+
The identifier of the halfedge.
|
|
2934
|
+
|
|
2935
|
+
Returns
|
|
2936
|
+
-------
|
|
2937
|
+
int | None
|
|
2938
|
+
The identifier of the adjacent half-face, or None if `halfedge` is on the boundary.
|
|
2939
|
+
|
|
2940
|
+
See Also
|
|
2941
|
+
--------
|
|
2942
|
+
:meth:`halfface_opposite_halfface`
|
|
2943
|
+
|
|
2944
|
+
Notes
|
|
2945
|
+
-----
|
|
2946
|
+
The adjacent face belongs a to one of the cell neighbors over faces of the initial cell.
|
|
2947
|
+
A face and its adjacent face share two common vertices.
|
|
2948
|
+
|
|
2949
|
+
"""
|
|
2950
|
+
u, v = halfedge
|
|
2951
|
+
cell = self.halfface_cell(halfface)
|
|
2952
|
+
nbr_halfface = self._cell[cell][v][u]
|
|
2953
|
+
nbr_cell = self._plane[u][v][nbr_halfface]
|
|
2954
|
+
return None if nbr_cell is None else self._cell[nbr_cell][v][u]
|
|
2955
|
+
|
|
2956
|
+
def halfface_vertex_ancestor(self, halfface, vertex):
|
|
2957
|
+
"""Return the vertex before the specified vertex in a specific face.
|
|
2958
|
+
|
|
2959
|
+
Parameters
|
|
2960
|
+
----------
|
|
2961
|
+
halfface : int
|
|
2962
|
+
The identifier of the halfface.
|
|
2963
|
+
vertex : int
|
|
2964
|
+
The identifier of the vertex.
|
|
2965
|
+
|
|
2966
|
+
Returns
|
|
2967
|
+
-------
|
|
2968
|
+
int
|
|
2969
|
+
The identifier of the vertex before the given vertex in the face cycle.
|
|
2970
|
+
|
|
2971
|
+
Raises
|
|
2972
|
+
------
|
|
2973
|
+
ValueError
|
|
2974
|
+
If the vertex is not part of the face.
|
|
2975
|
+
|
|
2976
|
+
See Also
|
|
2977
|
+
--------
|
|
2978
|
+
:meth:`halfface_vertex_descendent`
|
|
2979
|
+
|
|
2980
|
+
"""
|
|
2981
|
+
i = self._halfface[halfface].index(vertex)
|
|
2982
|
+
return self._halfface[halfface][i - 1]
|
|
2983
|
+
|
|
2984
|
+
def halfface_vertex_descendent(self, halfface, vertex):
|
|
2985
|
+
"""Return the vertex after the specified vertex in a specific face.
|
|
2986
|
+
|
|
2987
|
+
Parameters
|
|
2988
|
+
----------
|
|
2989
|
+
halfface : int
|
|
2990
|
+
The identifier of the halfface.
|
|
2991
|
+
vertex : int
|
|
2992
|
+
The identifier of the vertex.
|
|
2993
|
+
|
|
2994
|
+
Returns
|
|
2995
|
+
-------
|
|
2996
|
+
int
|
|
2997
|
+
The identifier of the vertex after the given vertex in the face cycle.
|
|
2998
|
+
|
|
2999
|
+
Raises
|
|
3000
|
+
------
|
|
3001
|
+
ValueError
|
|
3002
|
+
If the vertex is not part of the face.
|
|
3003
|
+
|
|
3004
|
+
See Also
|
|
3005
|
+
--------
|
|
3006
|
+
:meth:`halfface_vertex_ancestor`
|
|
3007
|
+
|
|
3008
|
+
"""
|
|
3009
|
+
if self._halfface[halfface][-1] == vertex:
|
|
3010
|
+
return self._halfface[halfface][0]
|
|
3011
|
+
i = self._halfface[halfface].index(vertex)
|
|
3012
|
+
return self._halfface[halfface][i + 1]
|
|
3013
|
+
|
|
3014
|
+
def halfface_manifold_neighbors(self, halfface):
|
|
3015
|
+
"""Return the halfface neighbors of a halfface that are on the same manifold.
|
|
3016
|
+
|
|
3017
|
+
Parameters
|
|
3018
|
+
----------
|
|
3019
|
+
halfface : int
|
|
3020
|
+
The identifier of the halfface.
|
|
3021
|
+
|
|
3022
|
+
Returns
|
|
3023
|
+
-------
|
|
3024
|
+
list[int]
|
|
3025
|
+
The list of neighboring halffaces.
|
|
3026
|
+
|
|
3027
|
+
See Also
|
|
3028
|
+
--------
|
|
3029
|
+
:meth:`halfface_manifold_neighborhood`
|
|
3030
|
+
|
|
3031
|
+
Notes
|
|
3032
|
+
-----
|
|
3033
|
+
Neighboring halffaces on the same cell are not included.
|
|
3034
|
+
|
|
3035
|
+
"""
|
|
3036
|
+
nbrs = []
|
|
3037
|
+
cell = self.halfface_cell(halfface)
|
|
3038
|
+
for u, v in self.halfface_halfedges(halfface):
|
|
3039
|
+
nbr_halfface = self._cell[cell][v][u]
|
|
3040
|
+
nbr_cell = self._plane[u][v][nbr_halfface]
|
|
3041
|
+
if nbr_cell is not None:
|
|
3042
|
+
nbr = self._cell[nbr_cell][v][u]
|
|
3043
|
+
nbrs.append(nbr)
|
|
3044
|
+
return nbrs
|
|
3045
|
+
|
|
3046
|
+
def halfface_manifold_neighborhood(self, halfface, ring=1):
|
|
3047
|
+
"""Return the halfface neighborhood of a halfface across their edges.
|
|
3048
|
+
|
|
3049
|
+
Parameters
|
|
3050
|
+
----------
|
|
3051
|
+
halfface : int
|
|
3052
|
+
The identifier of the halfface.
|
|
3053
|
+
|
|
3054
|
+
Returns
|
|
3055
|
+
-------
|
|
3056
|
+
list[int]
|
|
3057
|
+
The list of neighboring halffaces.
|
|
3058
|
+
|
|
3059
|
+
See Also
|
|
3060
|
+
--------
|
|
3061
|
+
:meth:`halfface_manifold_neighbors`
|
|
3062
|
+
|
|
3063
|
+
Notes
|
|
3064
|
+
-----
|
|
3065
|
+
Neighboring halffaces on the same cell are not included.
|
|
3066
|
+
|
|
3067
|
+
"""
|
|
3068
|
+
nbrs = set(self.halfface_manifold_neighbors(halfface))
|
|
3069
|
+
i = 1
|
|
3070
|
+
while True:
|
|
3071
|
+
if i == ring:
|
|
3072
|
+
break
|
|
3073
|
+
temp = []
|
|
3074
|
+
for nbr in nbrs:
|
|
3075
|
+
temp += self.halfface_manifold_neighbors(nbr)
|
|
3076
|
+
nbrs.update(temp)
|
|
3077
|
+
i += 1
|
|
3078
|
+
return list(nbrs - set([halfface]))
|
|
3079
|
+
|
|
3080
|
+
def is_halfface_on_boundary(self, halfface):
|
|
3081
|
+
"""Verify that a face is on the boundary.
|
|
3082
|
+
|
|
3083
|
+
Parameters
|
|
3084
|
+
----------
|
|
3085
|
+
halfface : int
|
|
3086
|
+
The identifier of the halfface.
|
|
3087
|
+
|
|
3088
|
+
Returns
|
|
3089
|
+
-------
|
|
3090
|
+
bool
|
|
3091
|
+
True if the face is on the boundary.
|
|
3092
|
+
False otherwise.
|
|
3093
|
+
|
|
3094
|
+
See Also
|
|
3095
|
+
--------
|
|
3096
|
+
:meth:`is_vertex_on_boundary`, :meth:`is_edge_on_boundary`, :meth:`is_cell_on_boundary`
|
|
3097
|
+
|
|
3098
|
+
"""
|
|
3099
|
+
u, v = self._halfface[halfface][:2]
|
|
3100
|
+
return self._plane[v][u][halfface] is None
|
|
3101
|
+
|
|
3102
|
+
# --------------------------------------------------------------------------
|
|
3103
|
+
# Face Geometry
|
|
3104
|
+
# --------------------------------------------------------------------------
|
|
3105
|
+
|
|
3106
|
+
def face_vertices(self, face):
|
|
3107
|
+
"""The vertices of a face.
|
|
3108
|
+
|
|
3109
|
+
Parameters
|
|
3110
|
+
----------
|
|
3111
|
+
halfface : int
|
|
3112
|
+
The identifier of the face.
|
|
3113
|
+
|
|
3114
|
+
Returns
|
|
3115
|
+
-------
|
|
3116
|
+
list[int]
|
|
3117
|
+
Ordered vertex identifiers.
|
|
3118
|
+
|
|
3119
|
+
"""
|
|
3120
|
+
return self.halfface_vertices(face)
|
|
3121
|
+
|
|
3122
|
+
def face_coordinates(self, face, axes="xyz"):
|
|
3123
|
+
"""Compute the coordinates of the vertices of a face.
|
|
3124
|
+
|
|
3125
|
+
Parameters
|
|
3126
|
+
----------
|
|
3127
|
+
face : int
|
|
3128
|
+
The identifier of the face.
|
|
3129
|
+
axes : str, optional
|
|
3130
|
+
The axes alon which to take the coordinates.
|
|
3131
|
+
Should be a combination of x, y, and z.
|
|
3132
|
+
|
|
3133
|
+
Returns
|
|
3134
|
+
-------
|
|
3135
|
+
list[list[float]]
|
|
3136
|
+
The coordinates of the vertices of the face.
|
|
3137
|
+
|
|
3138
|
+
See Also
|
|
3139
|
+
--------
|
|
3140
|
+
:meth:`face_points`, :meth:`face_polygon`, :meth:`face_normal`, :meth:`face_centroid`, :meth:`face_center`
|
|
3141
|
+
:meth:`face_area`, :meth:`face_flatness`, :meth:`face_aspect_ratio`
|
|
3142
|
+
|
|
3143
|
+
"""
|
|
3144
|
+
return [self.vertex_coordinates(vertex, axes=axes) for vertex in self.face_vertices(face)]
|
|
3145
|
+
|
|
3146
|
+
def face_points(self, face):
|
|
3147
|
+
"""Compute the points of the vertices of a face.
|
|
3148
|
+
|
|
3149
|
+
Parameters
|
|
3150
|
+
----------
|
|
3151
|
+
face : int
|
|
3152
|
+
The identifier of the face.
|
|
3153
|
+
|
|
3154
|
+
Returns
|
|
3155
|
+
-------
|
|
3156
|
+
list[:class:`compas.geometry.Point`]
|
|
3157
|
+
The points of the vertices of the face.
|
|
3158
|
+
|
|
3159
|
+
See Also
|
|
3160
|
+
--------
|
|
3161
|
+
:meth:`face_polygon`, :meth:`face_normal`, :meth:`face_centroid`, :meth:`face_center`
|
|
3162
|
+
|
|
3163
|
+
"""
|
|
3164
|
+
return [self.vertex_point(vertex) for vertex in self.face_vertices(face)]
|
|
3165
|
+
|
|
3166
|
+
def face_polygon(self, face):
|
|
3167
|
+
"""Compute the polygon of a face.
|
|
3168
|
+
|
|
3169
|
+
Parameters
|
|
3170
|
+
----------
|
|
3171
|
+
face : int
|
|
3172
|
+
The identifier of the face.
|
|
3173
|
+
|
|
3174
|
+
Returns
|
|
3175
|
+
-------
|
|
3176
|
+
:class:`compas.geometry.Polygon`
|
|
3177
|
+
The polygon of the face.
|
|
3178
|
+
|
|
3179
|
+
See Also
|
|
3180
|
+
--------
|
|
3181
|
+
:meth:`face_points`, :meth:`face_normal`, :meth:`face_centroid`, :meth:`face_center`
|
|
3182
|
+
|
|
3183
|
+
"""
|
|
3184
|
+
return Polygon(self.face_points(face))
|
|
3185
|
+
|
|
3186
|
+
def face_normal(self, face, unitized=True):
|
|
3187
|
+
"""Compute the oriented normal of a face.
|
|
3188
|
+
|
|
3189
|
+
Parameters
|
|
3190
|
+
----------
|
|
3191
|
+
face : int
|
|
3192
|
+
The identifier of the face.
|
|
3193
|
+
unitized : bool, optional
|
|
3194
|
+
If True, unitize the normal vector.
|
|
3195
|
+
|
|
3196
|
+
Returns
|
|
3197
|
+
-------
|
|
3198
|
+
:class:`compas.geometry.Vector`
|
|
3199
|
+
The normal vector.
|
|
3200
|
+
|
|
3201
|
+
See Also
|
|
3202
|
+
--------
|
|
3203
|
+
:meth:`face_points`, :meth:`face_polygon`, :meth:`face_centroid`, :meth:`face_center`
|
|
3204
|
+
|
|
3205
|
+
"""
|
|
3206
|
+
return Vector(*normal_polygon(self.face_coordinates(face), unitized=unitized))
|
|
3207
|
+
|
|
3208
|
+
def face_centroid(self, face):
|
|
3209
|
+
"""Compute the point at the centroid of a face.
|
|
3210
|
+
|
|
3211
|
+
Parameters
|
|
3212
|
+
----------
|
|
3213
|
+
face : int
|
|
3214
|
+
The identifier of the face.
|
|
3215
|
+
|
|
3216
|
+
Returns
|
|
3217
|
+
-------
|
|
3218
|
+
:class:`compas.geometry.Point`
|
|
3219
|
+
The coordinates of the centroid.
|
|
3220
|
+
|
|
3221
|
+
See Also
|
|
3222
|
+
--------
|
|
3223
|
+
:meth:`face_points`, :meth:`face_polygon`, :meth:`face_normal`, :meth:`face_center`
|
|
3224
|
+
|
|
3225
|
+
"""
|
|
3226
|
+
return Point(*centroid_points(self.face_coordinates(face)))
|
|
3227
|
+
|
|
3228
|
+
def face_center(self, face):
|
|
3229
|
+
"""Compute the point at the center of mass of a face.
|
|
3230
|
+
|
|
3231
|
+
Parameters
|
|
3232
|
+
----------
|
|
3233
|
+
face : int
|
|
3234
|
+
The identifier of the face.
|
|
3235
|
+
|
|
3236
|
+
Returns
|
|
3237
|
+
-------
|
|
3238
|
+
:class:`compas.geometry.Point`
|
|
3239
|
+
The coordinates of the center of mass.
|
|
3240
|
+
|
|
3241
|
+
See Also
|
|
3242
|
+
--------
|
|
3243
|
+
:meth:`face_points`, :meth:`face_polygon`, :meth:`face_normal`, :meth:`face_centroid`
|
|
3244
|
+
|
|
3245
|
+
"""
|
|
3246
|
+
return Point(*centroid_polygon(self.face_coordinates(face)))
|
|
3247
|
+
|
|
3248
|
+
def face_area(self, face):
|
|
3249
|
+
"""Compute the oriented area of a face.
|
|
3250
|
+
|
|
3251
|
+
Parameters
|
|
3252
|
+
----------
|
|
3253
|
+
face : int
|
|
3254
|
+
The identifier of the face.
|
|
3255
|
+
|
|
3256
|
+
Returns
|
|
3257
|
+
-------
|
|
3258
|
+
float
|
|
3259
|
+
The non-oriented area of the face.
|
|
3260
|
+
|
|
3261
|
+
See Also
|
|
3262
|
+
--------
|
|
3263
|
+
:meth:`face_flatness`, :meth:`face_aspect_ratio`
|
|
3264
|
+
|
|
3265
|
+
"""
|
|
3266
|
+
return length_vector(self.face_normal(face, unitized=False))
|
|
3267
|
+
|
|
3268
|
+
def face_flatness(self, face, maxdev=0.02):
|
|
3269
|
+
"""Compute the flatness of a face.
|
|
3270
|
+
|
|
3271
|
+
Parameters
|
|
3272
|
+
----------
|
|
3273
|
+
face : int
|
|
3274
|
+
The identifier of the face.
|
|
3275
|
+
|
|
3276
|
+
Returns
|
|
3277
|
+
-------
|
|
3278
|
+
float
|
|
3279
|
+
The flatness.
|
|
3280
|
+
|
|
3281
|
+
See Also
|
|
3282
|
+
--------
|
|
3283
|
+
:meth:`face_area`, :meth:`face_aspect_ratio`
|
|
3284
|
+
|
|
3285
|
+
Notes
|
|
3286
|
+
-----
|
|
3287
|
+
compas.geometry.mesh_flatness function currently only works for quadrilateral faces.
|
|
3288
|
+
This function uses the distance between each face vertex and its projected point
|
|
3289
|
+
on the best-fit plane of the face as the flatness metric.
|
|
3290
|
+
|
|
3291
|
+
"""
|
|
3292
|
+
deviation = 0
|
|
3293
|
+
polygon = self.face_coordinates(face)
|
|
3294
|
+
plane = bestfit_plane(polygon)
|
|
3295
|
+
for pt in polygon:
|
|
3296
|
+
pt_proj = project_point_plane(pt, plane)
|
|
3297
|
+
dev = distance_point_point(pt, pt_proj)
|
|
3298
|
+
if dev > deviation:
|
|
3299
|
+
deviation = dev
|
|
3300
|
+
return deviation
|
|
3301
|
+
|
|
3302
|
+
def face_aspect_ratio(self, face):
|
|
3303
|
+
"""Face aspect ratio as the ratio between the lengths of the maximum and minimum face edges.
|
|
3304
|
+
|
|
3305
|
+
Parameters
|
|
3306
|
+
----------
|
|
3307
|
+
face : int
|
|
3308
|
+
The identifier of the face.
|
|
3309
|
+
|
|
3310
|
+
Returns
|
|
3311
|
+
-------
|
|
3312
|
+
float
|
|
3313
|
+
The aspect ratio.
|
|
3314
|
+
|
|
3315
|
+
See Also
|
|
3316
|
+
--------
|
|
3317
|
+
:meth:`face_area`, :meth:`face_flatness`
|
|
3318
|
+
|
|
3319
|
+
References
|
|
3320
|
+
----------
|
|
3321
|
+
.. [1] Wikipedia. *Types of mesh*.
|
|
3322
|
+
Available at: https://en.wikipedia.org/wiki/Types_of_mesh.
|
|
3323
|
+
|
|
3324
|
+
"""
|
|
3325
|
+
face_edge_lengths = [self.edge_length(edge) for edge in self.halfface_halfedges(face)]
|
|
3326
|
+
return max(face_edge_lengths) / min(face_edge_lengths)
|
|
3327
|
+
|
|
3328
|
+
halfface_area = face_area
|
|
3329
|
+
halfface_centroid = face_centroid
|
|
3330
|
+
halfface_center = face_center
|
|
3331
|
+
halfface_coordinates = face_coordinates
|
|
3332
|
+
halfface_flatness = face_flatness
|
|
3333
|
+
halfface_normal = face_normal
|
|
3334
|
+
halfface_aspect_ratio = face_aspect_ratio
|
|
3335
|
+
|
|
3336
|
+
# --------------------------------------------------------------------------
|
|
3337
|
+
# Cell Accessors
|
|
3338
|
+
# --------------------------------------------------------------------------
|
|
3339
|
+
|
|
3340
|
+
def cells(self, data=False):
|
|
3341
|
+
"""Iterate over the cells of the volmesh.
|
|
3342
|
+
|
|
3343
|
+
Parameters
|
|
3344
|
+
----------
|
|
3345
|
+
data : bool, optional
|
|
3346
|
+
If True, yield the cell attributes in addition to the cell identifiers.
|
|
3347
|
+
|
|
3348
|
+
Yields
|
|
3349
|
+
------
|
|
3350
|
+
int | tuple[int, dict[str, Any]]
|
|
3351
|
+
If `data` is False, the next cell identifier.
|
|
3352
|
+
If `data` is True, the next cell as a (cell, attr) tuple.
|
|
3353
|
+
|
|
3354
|
+
See Also
|
|
3355
|
+
--------
|
|
3356
|
+
:meth:`vertices`, :meth:`edges`, :meth:`faces`
|
|
3357
|
+
|
|
3358
|
+
"""
|
|
3359
|
+
for cell in self._cell:
|
|
3360
|
+
if not data:
|
|
3361
|
+
yield cell
|
|
3362
|
+
else:
|
|
3363
|
+
yield cell, self.cell_attributes(cell)
|
|
3364
|
+
|
|
3365
|
+
def cells_where(self, conditions=None, data=False, **kwargs):
|
|
3366
|
+
"""Get cells for which a certain condition or set of conditions is true.
|
|
3367
|
+
|
|
3368
|
+
Parameters
|
|
3369
|
+
----------
|
|
3370
|
+
conditions : dict, optional
|
|
3371
|
+
A set of conditions in the form of key-value pairs.
|
|
3372
|
+
The keys should be attribute names. The values can be attribute
|
|
3373
|
+
values or ranges of attribute values in the form of min/max pairs.
|
|
3374
|
+
data : bool, optional
|
|
3375
|
+
If True, yield the cell attributes in addition to the identifiers.
|
|
3376
|
+
**kwargs : dict[str, Any], optional
|
|
3377
|
+
Additional conditions provided as named function arguments.
|
|
3378
|
+
|
|
3379
|
+
Yields
|
|
3380
|
+
------
|
|
3381
|
+
int | tuple[int, dict[str, Any]]
|
|
3382
|
+
If `data` is False, the next cell that matches the condition.
|
|
3383
|
+
If `data` is True, the next cell and its attributes.
|
|
3384
|
+
|
|
3385
|
+
See Also
|
|
3386
|
+
--------
|
|
3387
|
+
:meth:`cells_where_predicate`
|
|
3388
|
+
:meth:`vertices_where`, :meth:`edges_where`, :meth:`faces_where`
|
|
3389
|
+
|
|
3390
|
+
"""
|
|
3391
|
+
conditions = conditions or {}
|
|
3392
|
+
conditions.update(kwargs)
|
|
3393
|
+
|
|
3394
|
+
for ckey in self.cells():
|
|
3395
|
+
is_match = True
|
|
3396
|
+
|
|
3397
|
+
attr = self.cell_attributes(ckey) or {}
|
|
3398
|
+
|
|
3399
|
+
for name, value in conditions.items():
|
|
3400
|
+
method = getattr(self, name, None)
|
|
3401
|
+
|
|
3402
|
+
if method and callable(method):
|
|
3403
|
+
val = method(ckey)
|
|
3404
|
+
elif name in attr:
|
|
3405
|
+
val = attr[name]
|
|
3406
|
+
else:
|
|
3407
|
+
is_match = False
|
|
3408
|
+
break
|
|
3409
|
+
|
|
3410
|
+
if isinstance(val, list):
|
|
3411
|
+
if value not in val:
|
|
3412
|
+
is_match = False
|
|
3413
|
+
break
|
|
3414
|
+
elif isinstance(value, (tuple, list)):
|
|
3415
|
+
minval, maxval = value
|
|
3416
|
+
if val < minval or val > maxval:
|
|
3417
|
+
is_match = False
|
|
3418
|
+
break
|
|
3419
|
+
else:
|
|
3420
|
+
if value != val:
|
|
3421
|
+
is_match = False
|
|
3422
|
+
break
|
|
3423
|
+
|
|
3424
|
+
if is_match:
|
|
3425
|
+
if data:
|
|
3426
|
+
yield ckey, attr
|
|
3427
|
+
else:
|
|
3428
|
+
yield ckey
|
|
3429
|
+
|
|
3430
|
+
def cells_where_predicate(self, predicate, data=False):
|
|
3431
|
+
"""Get cells for which a certain condition or set of conditions is true using a lambda function.
|
|
3432
|
+
|
|
3433
|
+
Parameters
|
|
3434
|
+
----------
|
|
3435
|
+
predicate : callable
|
|
3436
|
+
The condition you want to evaluate.
|
|
3437
|
+
The callable takes 2 parameters: the cell identifier and the cell attributes, and should return True or False.
|
|
3438
|
+
data : bool, optional
|
|
3439
|
+
If True, yield the cell attributes in addition to the identifiers.
|
|
3440
|
+
|
|
3441
|
+
Yields
|
|
3442
|
+
------
|
|
3443
|
+
int | tuple[int, dict[str, Any]]
|
|
3444
|
+
If `data` is False, the next cell that matches the condition.
|
|
3445
|
+
If `data` is True, the next cell and its attributes.
|
|
3446
|
+
|
|
3447
|
+
See Also
|
|
3448
|
+
--------
|
|
3449
|
+
:meth:`cells_where`
|
|
3450
|
+
:meth:`vertices_where_predicate`, :meth:`edges_where_predicate`, :meth:`faces_where_predicate`
|
|
3451
|
+
|
|
3452
|
+
"""
|
|
3453
|
+
for ckey, attr in self.cells(True):
|
|
3454
|
+
if predicate(ckey, attr):
|
|
3455
|
+
if data:
|
|
3456
|
+
yield ckey, attr
|
|
3457
|
+
else:
|
|
3458
|
+
yield ckey
|
|
3459
|
+
|
|
3460
|
+
# --------------------------------------------------------------------------
|
|
3461
|
+
# Cell Attributes
|
|
3462
|
+
# --------------------------------------------------------------------------
|
|
3463
|
+
|
|
3464
|
+
def update_default_cell_attributes(self, attr_dict=None, **kwattr):
|
|
3465
|
+
"""Update the default cell attributes.
|
|
3466
|
+
|
|
3467
|
+
Parameters
|
|
3468
|
+
----------
|
|
3469
|
+
attr_dict : dict[str, Any], optional
|
|
3470
|
+
A dictionary of attributes with their default values.
|
|
3471
|
+
**kwattr : dict[str, Any], optional
|
|
3472
|
+
A dictionary of additional attributes compiled of remaining named arguments.
|
|
3473
|
+
|
|
3474
|
+
Returns
|
|
3475
|
+
-------
|
|
3476
|
+
None
|
|
3477
|
+
|
|
3478
|
+
See Also
|
|
3479
|
+
--------
|
|
3480
|
+
:meth:`update_default_vertex_attributes`, :meth:`update_default_edge_attributes`, :meth:`update_default_face_attributes`
|
|
3481
|
+
|
|
3482
|
+
Notes
|
|
3483
|
+
-----
|
|
3484
|
+
Named arguments overwrite corresponding cell-value pairs in the attribute dictionary.
|
|
3485
|
+
|
|
3486
|
+
"""
|
|
3487
|
+
if not attr_dict:
|
|
3488
|
+
attr_dict = {}
|
|
3489
|
+
attr_dict.update(kwattr)
|
|
3490
|
+
self.default_cell_attributes.update(attr_dict)
|
|
3491
|
+
|
|
3492
|
+
def cell_attribute(self, cell, name, value=None):
|
|
3493
|
+
"""Get or set an attribute of a cell.
|
|
3494
|
+
|
|
3495
|
+
Parameters
|
|
3496
|
+
----------
|
|
3497
|
+
cell : int
|
|
3498
|
+
The cell identifier.
|
|
3499
|
+
name : str
|
|
3500
|
+
The name of the attribute.
|
|
3501
|
+
value : object, optional
|
|
3502
|
+
The value of the attribute.
|
|
3503
|
+
|
|
3504
|
+
Returns
|
|
3505
|
+
-------
|
|
3506
|
+
object | None
|
|
3507
|
+
The value of the attribute, or None when the function is used as a "setter".
|
|
3508
|
+
|
|
3509
|
+
Raises
|
|
3510
|
+
------
|
|
3511
|
+
KeyError
|
|
3512
|
+
If the cell does not exist.
|
|
3513
|
+
|
|
3514
|
+
See Also
|
|
3515
|
+
--------
|
|
3516
|
+
:meth:`unset_cell_attribute`
|
|
3517
|
+
:meth:`cell_attributes`, :meth:`cells_attribute`, :meth:`cells_attributes`
|
|
3518
|
+
:meth:`vertex_attribute`, :meth:`edge_attribute`, :meth:`face_attribute`
|
|
3519
|
+
|
|
3520
|
+
"""
|
|
3521
|
+
if cell not in self._cell:
|
|
3522
|
+
raise KeyError(cell)
|
|
3523
|
+
if value is not None:
|
|
3524
|
+
if cell not in self._cell_data:
|
|
3525
|
+
self._cell_data[cell] = {}
|
|
3526
|
+
self._cell_data[cell][name] = value
|
|
3527
|
+
return
|
|
3528
|
+
if cell in self._cell_data and name in self._cell_data[cell]:
|
|
3529
|
+
return self._cell_data[cell][name]
|
|
3530
|
+
if name in self.default_cell_attributes:
|
|
3531
|
+
return self.default_cell_attributes[name]
|
|
3532
|
+
|
|
3533
|
+
def unset_cell_attribute(self, cell, name):
|
|
3534
|
+
"""Unset the attribute of a cell.
|
|
3535
|
+
|
|
3536
|
+
Parameters
|
|
3537
|
+
----------
|
|
3538
|
+
cell : int
|
|
3539
|
+
The cell identifier.
|
|
3540
|
+
name : str
|
|
3541
|
+
The name of the attribute.
|
|
3542
|
+
|
|
3543
|
+
Returns
|
|
3544
|
+
-------
|
|
3545
|
+
None
|
|
3546
|
+
|
|
3547
|
+
Raises
|
|
3548
|
+
------
|
|
3549
|
+
KeyError
|
|
3550
|
+
If the cell does not exist.
|
|
3551
|
+
|
|
3552
|
+
See Also
|
|
3553
|
+
--------
|
|
3554
|
+
:meth:`cell_attribute`
|
|
3555
|
+
|
|
3556
|
+
Notes
|
|
3557
|
+
-----
|
|
3558
|
+
Unsetting the value of a cell attribute implicitly sets it back to the value
|
|
3559
|
+
stored in the default cell attribute dict.
|
|
3560
|
+
|
|
3561
|
+
"""
|
|
3562
|
+
if cell not in self._cell:
|
|
3563
|
+
raise KeyError(cell)
|
|
3564
|
+
if cell in self._cell_data:
|
|
3565
|
+
if name in self._cell_data[cell]:
|
|
3566
|
+
del self._cell_data[cell][name]
|
|
3567
|
+
|
|
3568
|
+
def cell_attributes(self, cell, names=None, values=None):
|
|
3569
|
+
"""Get or set multiple attributes of a cell.
|
|
3570
|
+
|
|
3571
|
+
Parameters
|
|
3572
|
+
----------
|
|
3573
|
+
cell : int
|
|
3574
|
+
The identifier of the cell.
|
|
3575
|
+
names : list[str], optional
|
|
3576
|
+
A list of attribute names.
|
|
3577
|
+
values : list[Any], optional
|
|
3578
|
+
A list of attribute values.
|
|
3579
|
+
|
|
3580
|
+
Returns
|
|
3581
|
+
-------
|
|
3582
|
+
dict[str, Any] | list[Any] | None
|
|
3583
|
+
If the parameter `names` is empty, a dictionary of all attribute name-value pairs of the cell.
|
|
3584
|
+
If the parameter `names` is not empty, a list of the values corresponding to the provided names.
|
|
3585
|
+
None if the function is used as a "setter".
|
|
3586
|
+
|
|
3587
|
+
Raises
|
|
3588
|
+
------
|
|
3589
|
+
KeyError
|
|
3590
|
+
If the cell does not exist.
|
|
3591
|
+
|
|
3592
|
+
See Also
|
|
3593
|
+
--------
|
|
3594
|
+
:meth:`cell_attribute`, :meth:`cells_attribute`, :meth:`cells_attributes`
|
|
3595
|
+
:meth:`vertex_attributes`, :meth:`edge_attributes`, :meth:`face_attributes`
|
|
3596
|
+
|
|
3597
|
+
"""
|
|
3598
|
+
if cell not in self._cell:
|
|
3599
|
+
raise KeyError(cell)
|
|
3600
|
+
if names and values is not None:
|
|
3601
|
+
for name, value in zip(names, values):
|
|
3602
|
+
if cell not in self._cell_data:
|
|
3603
|
+
self._cell_data[cell] = {}
|
|
3604
|
+
self._cell_data[cell][name] = value
|
|
3605
|
+
return
|
|
3606
|
+
if not names:
|
|
3607
|
+
return CellAttributeView(self.default_cell_attributes, self._cell_data.setdefault(cell, {}))
|
|
3608
|
+
values = []
|
|
3609
|
+
for name in names:
|
|
3610
|
+
value = self.cell_attribute(cell, name)
|
|
3611
|
+
values.append(value)
|
|
3612
|
+
return values
|
|
3613
|
+
|
|
3614
|
+
def cells_attribute(self, name, value=None, cells=None):
|
|
3615
|
+
"""Get or set an attribute of multiple cells.
|
|
3616
|
+
|
|
3617
|
+
Parameters
|
|
3618
|
+
----------
|
|
3619
|
+
name : str
|
|
3620
|
+
The name of the attribute.
|
|
3621
|
+
value : object, optional
|
|
3622
|
+
The value of the attribute.
|
|
3623
|
+
cells : list[int], optional
|
|
3624
|
+
A list of cell identifiers.
|
|
3625
|
+
|
|
3626
|
+
Returns
|
|
3627
|
+
-------
|
|
3628
|
+
list[Any] | None
|
|
3629
|
+
A list containing the value per face of the requested attribute,
|
|
3630
|
+
or None if the function is used as a "setter".
|
|
3631
|
+
|
|
3632
|
+
Raises
|
|
3633
|
+
------
|
|
3634
|
+
KeyError
|
|
3635
|
+
If any of the cells does not exist.
|
|
3636
|
+
|
|
3637
|
+
See Also
|
|
3638
|
+
--------
|
|
3639
|
+
:meth:`cell_attribute`, :meth:`cell_attributes`, :meth:`cells_attributes`
|
|
3640
|
+
:meth:`vertex_attribute`, :meth:`edge_attribute`, :meth:`face_attribute`
|
|
3641
|
+
|
|
3642
|
+
"""
|
|
3643
|
+
if not cells:
|
|
3644
|
+
cells = self.cells()
|
|
3645
|
+
if value is not None:
|
|
3646
|
+
for cell in cells:
|
|
3647
|
+
self.cell_attribute(cell, name, value)
|
|
3648
|
+
return
|
|
3649
|
+
return [self.cell_attribute(cell, name) for cell in cells]
|
|
3650
|
+
|
|
3651
|
+
def cells_attributes(self, names=None, values=None, cells=None):
|
|
3652
|
+
"""Get or set multiple attributes of multiple cells.
|
|
3653
|
+
|
|
3654
|
+
Parameters
|
|
3655
|
+
----------
|
|
3656
|
+
names : list[str], optional
|
|
3657
|
+
The names of the attribute.
|
|
3658
|
+
Default is None.
|
|
3659
|
+
values : list[Any], optional
|
|
3660
|
+
The values of the attributes.
|
|
3661
|
+
Default is None.
|
|
3662
|
+
cells : list[int], optional
|
|
3663
|
+
A list of cell identifiers.
|
|
3664
|
+
|
|
3665
|
+
Returns
|
|
3666
|
+
-------
|
|
3667
|
+
list[dict[str, Any]] | list[list[Any]] | None
|
|
3668
|
+
If the parameter `names` is empty,
|
|
3669
|
+
a list containing per cell an attribute dict with all attributes (default + custom) of the cell.
|
|
3670
|
+
If the parameter `names` is empty,
|
|
3671
|
+
a list containing per cell a list of attribute values corresponding to the requested names.
|
|
3672
|
+
None if the function is used as a "setter".
|
|
3673
|
+
|
|
3674
|
+
Raises
|
|
3675
|
+
------
|
|
3676
|
+
KeyError
|
|
3677
|
+
If any of the faces does not exist.
|
|
3678
|
+
|
|
3679
|
+
See Also
|
|
3680
|
+
--------
|
|
3681
|
+
:meth:`cell_attribute`, :meth:`cell_attributes`, :meth:`cells_attribute`
|
|
3682
|
+
:meth:`vertex_attributes`, :meth:`edge_attributes`, :meth:`face_attributes`
|
|
3683
|
+
|
|
3684
|
+
"""
|
|
3685
|
+
if not cells:
|
|
3686
|
+
cells = self.cells()
|
|
3687
|
+
if values is not None:
|
|
3688
|
+
for cell in cells:
|
|
3689
|
+
self.cell_attributes(cell, names, values)
|
|
3690
|
+
return
|
|
3691
|
+
return [self.cell_attributes(cell, names) for cell in cells]
|
|
3692
|
+
|
|
3693
|
+
# --------------------------------------------------------------------------
|
|
3694
|
+
# Cell Topology
|
|
3695
|
+
# --------------------------------------------------------------------------
|
|
3696
|
+
|
|
3697
|
+
def cell_vertices(self, cell):
|
|
3698
|
+
"""The vertices of a cell.
|
|
3699
|
+
|
|
3700
|
+
Parameters
|
|
3701
|
+
----------
|
|
3702
|
+
cell : int
|
|
3703
|
+
Identifier of the cell.
|
|
3704
|
+
|
|
3705
|
+
Returns
|
|
3706
|
+
-------
|
|
3707
|
+
list[int]
|
|
3708
|
+
The vertex identifiers of a cell.
|
|
3709
|
+
|
|
3710
|
+
See Also
|
|
3711
|
+
--------
|
|
3712
|
+
:meth:`cell_edges`, :meth:`cell_faces`, :meth:`cell_halfedges`
|
|
3713
|
+
|
|
3714
|
+
Notes
|
|
3715
|
+
-----
|
|
3716
|
+
This method is similar to :meth:`~compas.datastructures.HalfEdge.vertices`,
|
|
3717
|
+
but in the context of a cell of the `VolMesh`.
|
|
3718
|
+
|
|
3719
|
+
"""
|
|
3720
|
+
return list(set([vertex for face in self.cell_faces(cell) for vertex in self.halfface_vertices(face)]))
|
|
3721
|
+
|
|
3722
|
+
def cell_halfedges(self, cell):
|
|
3723
|
+
"""The halfedges of a cell.
|
|
3724
|
+
|
|
3725
|
+
Parameters
|
|
3726
|
+
----------
|
|
3727
|
+
cell : int
|
|
3728
|
+
Identifier of the cell.
|
|
3729
|
+
|
|
3730
|
+
Returns
|
|
3731
|
+
-------
|
|
3732
|
+
list[tuple[int, int]]
|
|
3733
|
+
The halfedges of a cell.
|
|
3734
|
+
|
|
3735
|
+
See Also
|
|
3736
|
+
--------
|
|
3737
|
+
:meth:`cell_edges`, :meth:`cell_faces`, :meth:`cell_vertices`
|
|
3738
|
+
|
|
3739
|
+
Notes
|
|
3740
|
+
-----
|
|
3741
|
+
This method is similar to :meth:`~compas.datastructures.HalfEdge.halfedges`,
|
|
3742
|
+
but in the context of a cell of the `VolMesh`.
|
|
3743
|
+
|
|
3744
|
+
"""
|
|
3745
|
+
halfedges = []
|
|
3746
|
+
for face in self.cell_faces(cell):
|
|
3747
|
+
halfedges += self.halfface_halfedges(face)
|
|
3748
|
+
return halfedges
|
|
3749
|
+
|
|
3750
|
+
def cell_edges(self, cell):
|
|
3751
|
+
"""Return all edges of a cell.
|
|
3752
|
+
|
|
3753
|
+
Parameters
|
|
3754
|
+
----------
|
|
3755
|
+
cell : int
|
|
3756
|
+
The cell identifier.
|
|
3757
|
+
|
|
3758
|
+
Returns
|
|
3759
|
+
-------
|
|
3760
|
+
list[tuple[int, int]]
|
|
3761
|
+
The edges of the cell.
|
|
3762
|
+
|
|
3763
|
+
See Also
|
|
3764
|
+
--------
|
|
3765
|
+
:meth:`cell_halfedges`, :meth:`cell_faces`, :meth:`cell_vertices`
|
|
3766
|
+
|
|
3767
|
+
Notes
|
|
3768
|
+
-----
|
|
3769
|
+
This method is similar to :meth:`~compas.datastructures.HalfEdge.edges`,
|
|
3770
|
+
but in the context of a cell of the `VolMesh`.
|
|
3771
|
+
|
|
3772
|
+
"""
|
|
3773
|
+
raise NotImplementedError
|
|
3774
|
+
|
|
3775
|
+
def cell_faces(self, cell):
|
|
3776
|
+
"""The faces of a cell.
|
|
3777
|
+
|
|
3778
|
+
Parameters
|
|
3779
|
+
----------
|
|
3780
|
+
cell : int
|
|
3781
|
+
Identifier of the cell.
|
|
3782
|
+
|
|
3783
|
+
Returns
|
|
3784
|
+
-------
|
|
3785
|
+
list[int]
|
|
3786
|
+
The faces of a cell.
|
|
3787
|
+
|
|
3788
|
+
See Also
|
|
3789
|
+
--------
|
|
3790
|
+
:meth:`cell_halfedges`, :meth:`cell_edges`, :meth:`cell_vertices`
|
|
3791
|
+
|
|
3792
|
+
Notes
|
|
3793
|
+
-----
|
|
3794
|
+
This method is similar to :meth:`~compas.datastructures.HalfEdge.faces`,
|
|
3795
|
+
but in the context of a cell of the `VolMesh`.
|
|
3796
|
+
|
|
3797
|
+
"""
|
|
3798
|
+
faces = set()
|
|
3799
|
+
for vertex in self._cell[cell]:
|
|
3800
|
+
faces.update(self._cell[cell][vertex].values())
|
|
3801
|
+
return list(faces)
|
|
3802
|
+
|
|
3803
|
+
def cell_vertex_neighbors(self, cell, vertex):
|
|
3804
|
+
"""Ordered vertex neighbors of a vertex of a cell.
|
|
3805
|
+
|
|
3806
|
+
Parameters
|
|
3807
|
+
----------
|
|
3808
|
+
cell : int
|
|
3809
|
+
Identifier of the cell.
|
|
3810
|
+
vertex : int
|
|
3811
|
+
Identifier of the vertex.
|
|
3812
|
+
|
|
3813
|
+
Returns
|
|
3814
|
+
-------
|
|
3815
|
+
list[int]
|
|
3816
|
+
The list of neighboring vertices.
|
|
3817
|
+
|
|
3818
|
+
See Also
|
|
3819
|
+
--------
|
|
3820
|
+
:meth:`cell_vertex_faces`
|
|
3821
|
+
|
|
3822
|
+
Notes
|
|
3823
|
+
-----
|
|
3824
|
+
All of the returned vertices are part of the cell.
|
|
3825
|
+
|
|
3826
|
+
This method is similar to :meth:`~compas.datastructures.HalfEdge.vertex_neighbors`,
|
|
3827
|
+
but in the context of a cell of the `VolMesh`.
|
|
3828
|
+
|
|
3829
|
+
"""
|
|
3830
|
+
if vertex not in self.cell_vertices(cell):
|
|
3831
|
+
raise KeyError(vertex)
|
|
3832
|
+
nbr_vertices = self._cell[cell][vertex].keys()
|
|
3833
|
+
v = nbr_vertices[0]
|
|
3834
|
+
ordered_vkeys = [v]
|
|
3835
|
+
for i in range(len(nbr_vertices) - 1):
|
|
3836
|
+
face = self._cell[cell][vertex][v]
|
|
3837
|
+
v = self.halfface_vertex_ancestor(face, vertex)
|
|
3838
|
+
ordered_vkeys.append(v)
|
|
3839
|
+
return ordered_vkeys
|
|
3840
|
+
|
|
3841
|
+
def cell_vertex_faces(self, cell, vertex):
|
|
3842
|
+
"""Ordered faces connected to a vertex of a cell.
|
|
3843
|
+
|
|
3844
|
+
Parameters
|
|
3845
|
+
----------
|
|
3846
|
+
cell : int
|
|
3847
|
+
Identifier of the cell.
|
|
3848
|
+
vertex : int
|
|
3849
|
+
Identifier of the vertex.
|
|
3850
|
+
|
|
3851
|
+
Returns
|
|
3852
|
+
-------
|
|
3853
|
+
list[int]
|
|
3854
|
+
The ordered list of faces connected to a vertex of a cell.
|
|
3855
|
+
|
|
3856
|
+
See Also
|
|
3857
|
+
--------
|
|
3858
|
+
:meth:`cell_vertex_neighbors`
|
|
3859
|
+
|
|
3860
|
+
Notes
|
|
3861
|
+
-----
|
|
3862
|
+
All of the returned faces should are part of the same cell.
|
|
3863
|
+
|
|
3864
|
+
This method is similar to :meth:`~compas.datastructures.HalfEdge.vertex_faces`,
|
|
3865
|
+
but in the context of a cell of the `VolMesh`.
|
|
3866
|
+
|
|
3867
|
+
"""
|
|
3868
|
+
nbr_vertices = self._cell[cell][vertex].keys()
|
|
3869
|
+
u = vertex
|
|
3870
|
+
v = nbr_vertices[0]
|
|
3871
|
+
ordered_faces = []
|
|
3872
|
+
for i in range(len(nbr_vertices)):
|
|
3873
|
+
face = self._cell[cell][u][v]
|
|
3874
|
+
v = self.halfface_vertex_ancestor(face, u)
|
|
3875
|
+
ordered_faces.append(face)
|
|
3876
|
+
return ordered_faces
|
|
3877
|
+
|
|
3878
|
+
def cell_halfedge_face(self, cell, halfedge):
|
|
3879
|
+
"""Find the face corresponding to a specific halfedge of a cell.
|
|
3880
|
+
|
|
3881
|
+
Parameters
|
|
3882
|
+
----------
|
|
3883
|
+
cell : int
|
|
3884
|
+
The identifier of the cell.
|
|
3885
|
+
halfedge : tuple[int, int]
|
|
3886
|
+
The identifier of the halfedge.
|
|
3887
|
+
|
|
3888
|
+
Returns
|
|
3889
|
+
-------
|
|
3890
|
+
int
|
|
3891
|
+
The identifier of the face.
|
|
3892
|
+
|
|
3893
|
+
See Also
|
|
3894
|
+
--------
|
|
3895
|
+
:meth:`cell_halfedge_opposite_face`
|
|
3896
|
+
|
|
3897
|
+
Notes
|
|
3898
|
+
-----
|
|
3899
|
+
This method is similar to :meth:`~compas.datastructures.HalfEdge.halfedge_face`,
|
|
3900
|
+
but in the context of a cell of the `VolMesh`.
|
|
3901
|
+
|
|
3902
|
+
"""
|
|
3903
|
+
u, v = halfedge
|
|
3904
|
+
return self._cell[cell][u][v]
|
|
3905
|
+
|
|
3906
|
+
def cell_halfedge_opposite_face(self, cell, halfedge):
|
|
3907
|
+
"""Find the opposite face corresponding to a specific halfedge of a cell.
|
|
3908
|
+
|
|
3909
|
+
Parameters
|
|
3910
|
+
----------
|
|
3911
|
+
cell : int
|
|
3912
|
+
The identifier of the cell.
|
|
3913
|
+
halfedge : tuple[int, int]
|
|
3914
|
+
The identifier of the halfedge.
|
|
3915
|
+
|
|
3916
|
+
Returns
|
|
3917
|
+
-------
|
|
3918
|
+
int
|
|
3919
|
+
The identifier of the face.
|
|
3920
|
+
|
|
3921
|
+
See Also
|
|
3922
|
+
--------
|
|
3923
|
+
:meth:`cell_halfedge_face`
|
|
3924
|
+
|
|
3925
|
+
"""
|
|
3926
|
+
u, v = halfedge
|
|
3927
|
+
return self._cell[cell][v][u]
|
|
3928
|
+
|
|
3929
|
+
def cell_face_neighbors(self, cell, face):
|
|
3930
|
+
"""Find the faces adjacent to a given face of a cell.
|
|
3931
|
+
|
|
3932
|
+
Parameters
|
|
3933
|
+
----------
|
|
3934
|
+
cell : int
|
|
3935
|
+
The identifier of the cell.
|
|
3936
|
+
face : int
|
|
3937
|
+
The identifier of the face.
|
|
3938
|
+
|
|
3939
|
+
Returns
|
|
3940
|
+
-------
|
|
3941
|
+
int
|
|
3942
|
+
The identifier of the face.
|
|
3943
|
+
|
|
3944
|
+
See Also
|
|
3945
|
+
--------
|
|
3946
|
+
:meth:`cell_neighbors`
|
|
3947
|
+
|
|
3948
|
+
Notes
|
|
3949
|
+
-----
|
|
3950
|
+
This method is similar to :meth:`~compas.datastructures.HalfEdge.face_neighbors`,
|
|
3951
|
+
but in the context of a cell of the `VolMesh`.
|
|
3952
|
+
|
|
3953
|
+
"""
|
|
3954
|
+
nbrs = []
|
|
3955
|
+
for halfedge in self.halfface_halfedges(face):
|
|
3956
|
+
nbr = self.cell_halfedge_opposite_face(cell, halfedge)
|
|
3957
|
+
if nbr is not None:
|
|
3958
|
+
nbrs.append(nbr)
|
|
3959
|
+
return nbrs
|
|
3960
|
+
|
|
3961
|
+
def cell_neighbors(self, cell):
|
|
3962
|
+
"""Find the neighbors of a given cell.
|
|
3963
|
+
|
|
3964
|
+
Parameters
|
|
3965
|
+
----------
|
|
3966
|
+
cell : int
|
|
3967
|
+
The identifier of the cell.
|
|
3968
|
+
|
|
3969
|
+
Returns
|
|
3970
|
+
-------
|
|
3971
|
+
list[int]
|
|
3972
|
+
The identifiers of the adjacent cells.
|
|
3973
|
+
|
|
3974
|
+
See Also
|
|
3975
|
+
--------
|
|
3976
|
+
:meth:`cell_face_neighbors`
|
|
3977
|
+
|
|
3978
|
+
"""
|
|
3979
|
+
nbrs = []
|
|
3980
|
+
for face in self.cell_faces(cell):
|
|
3981
|
+
nbr = self.halfface_opposite_cell(face)
|
|
3982
|
+
if nbr is not None:
|
|
3983
|
+
nbrs.append(nbr)
|
|
3984
|
+
return nbrs
|
|
3985
|
+
|
|
3986
|
+
def is_cell_on_boundary(self, cell):
|
|
3987
|
+
"""Verify that a cell is on the boundary.
|
|
3988
|
+
|
|
3989
|
+
Parameters
|
|
3990
|
+
----------
|
|
3991
|
+
cell : int
|
|
3992
|
+
Identifier of the cell.
|
|
3993
|
+
|
|
3994
|
+
Returns
|
|
3995
|
+
-------
|
|
3996
|
+
bool
|
|
3997
|
+
True if the face is on the boundary.
|
|
3998
|
+
False otherwise.
|
|
3999
|
+
|
|
4000
|
+
See Also
|
|
4001
|
+
--------
|
|
4002
|
+
:meth:`is_vertex_on_boundary`, :meth:`is_edge_on_boundary`, :meth:`is_face_on_boundary`
|
|
4003
|
+
|
|
4004
|
+
"""
|
|
4005
|
+
faces = self.cell_faces(cell)
|
|
4006
|
+
for face in faces:
|
|
4007
|
+
if self.is_halfface_on_boundary(face):
|
|
4008
|
+
return True
|
|
4009
|
+
return False
|
|
4010
|
+
|
|
4011
|
+
# --------------------------------------------------------------------------
|
|
4012
|
+
# Cell Geometry
|
|
4013
|
+
# --------------------------------------------------------------------------
|
|
4014
|
+
|
|
4015
|
+
def cell_points(self, cell):
|
|
4016
|
+
"""Compute the points of the vertices of a cell.
|
|
4017
|
+
|
|
4018
|
+
Parameters
|
|
4019
|
+
----------
|
|
4020
|
+
cell : int
|
|
4021
|
+
The identifier of the cell.
|
|
4022
|
+
|
|
4023
|
+
Returns
|
|
4024
|
+
-------
|
|
4025
|
+
list[:class:`compas.geometry.Point`]
|
|
4026
|
+
The points of the vertices of the cell.
|
|
4027
|
+
|
|
4028
|
+
See Also
|
|
4029
|
+
--------
|
|
4030
|
+
:meth:`cell_polygon`, :meth:`cell_centroid`, :meth:`cell_center`
|
|
4031
|
+
|
|
4032
|
+
"""
|
|
4033
|
+
return [self.vertex_point(vertex) for vertex in self.cell_vertices(cell)]
|
|
4034
|
+
|
|
4035
|
+
def cell_centroid(self, cell):
|
|
4036
|
+
"""Compute the point at the centroid of a cell.
|
|
4037
|
+
|
|
4038
|
+
Parameters
|
|
4039
|
+
----------
|
|
4040
|
+
cell : int
|
|
4041
|
+
The identifier of the cell.
|
|
4042
|
+
|
|
4043
|
+
Returns
|
|
4044
|
+
-------
|
|
4045
|
+
:class:`compas.geometry.Point`
|
|
4046
|
+
The coordinates of the centroid.
|
|
4047
|
+
|
|
4048
|
+
See Also
|
|
4049
|
+
--------
|
|
4050
|
+
:meth:`cell_center`
|
|
4051
|
+
|
|
4052
|
+
"""
|
|
4053
|
+
vertices = self.cell_vertices(cell)
|
|
4054
|
+
return Point(*centroid_points([self.vertex_coordinates(vertex) for vertex in vertices]))
|
|
4055
|
+
|
|
4056
|
+
def cell_center(self, cell):
|
|
4057
|
+
"""Compute the point at the center of mass of a cell.
|
|
4058
|
+
|
|
4059
|
+
Parameters
|
|
4060
|
+
----------
|
|
4061
|
+
cell : int
|
|
4062
|
+
The identifier of the cell.
|
|
4063
|
+
|
|
4064
|
+
Returns
|
|
4065
|
+
-------
|
|
4066
|
+
:class:`compas.geometry.Point`
|
|
4067
|
+
The coordinates of the center of mass.
|
|
4068
|
+
|
|
4069
|
+
See Also
|
|
4070
|
+
--------
|
|
4071
|
+
:meth:`cell_centroid`
|
|
4072
|
+
|
|
4073
|
+
"""
|
|
4074
|
+
vertices, faces = self.cell_to_vertices_and_faces(cell)
|
|
4075
|
+
return Point(*centroid_polyhedron((vertices, faces)))
|
|
4076
|
+
|
|
4077
|
+
def cell_vertex_normal(self, cell, vertex):
|
|
4078
|
+
"""Return the normal vector at the vertex of a boundary cell as the weighted average of the
|
|
4079
|
+
normals of the neighboring faces.
|
|
4080
|
+
|
|
4081
|
+
Parameters
|
|
4082
|
+
----------
|
|
4083
|
+
cell : int
|
|
4084
|
+
The identifier of the vertex of the cell.
|
|
4085
|
+
vertex : int
|
|
4086
|
+
The identifier of the vertex of the cell.
|
|
4087
|
+
|
|
4088
|
+
Returns
|
|
4089
|
+
-------
|
|
4090
|
+
:class:`compas.geometry.Vector`
|
|
4091
|
+
The components of the normal vector.
|
|
4092
|
+
|
|
4093
|
+
"""
|
|
4094
|
+
cell_faces = self.cell_faces(cell)
|
|
4095
|
+
vectors = [self.face_normal(face) for face in self.vertex_halffaces(vertex) if face in cell_faces]
|
|
4096
|
+
return Vector(*normalize_vector(centroid_points(vectors)))
|
|
4097
|
+
|
|
4098
|
+
def cell_polyhedron(self, cell):
|
|
4099
|
+
"""Construct a polyhedron from the vertices and faces of a cell.
|
|
4100
|
+
|
|
4101
|
+
Parameters
|
|
4102
|
+
----------
|
|
4103
|
+
cell : int
|
|
4104
|
+
The identifier of the cell.
|
|
4105
|
+
|
|
4106
|
+
Returns
|
|
4107
|
+
-------
|
|
4108
|
+
:class:`compas.geometry.Polyhedron`
|
|
4109
|
+
The polyhedron.
|
|
4110
|
+
|
|
4111
|
+
"""
|
|
4112
|
+
vertices, faces = self.cell_to_vertices_and_faces(cell)
|
|
4113
|
+
return Polyhedron(vertices, faces)
|
|
4114
|
+
|
|
4115
|
+
# --------------------------------------------------------------------------
|
|
4116
|
+
# Boundaries
|
|
4117
|
+
# --------------------------------------------------------------------------
|
|
4118
|
+
|
|
4119
|
+
def vertices_on_boundaries(self):
|
|
4120
|
+
"""Find the vertices on the boundary.
|
|
4121
|
+
|
|
4122
|
+
Returns
|
|
4123
|
+
-------
|
|
4124
|
+
list[int]
|
|
4125
|
+
The vertices of the boundary.
|
|
4126
|
+
|
|
4127
|
+
See Also
|
|
4128
|
+
--------
|
|
4129
|
+
:meth:`faces_on_boundaries`, :meth:`cells_on_boundaries`
|
|
4130
|
+
|
|
4131
|
+
"""
|
|
4132
|
+
vertices = set()
|
|
4133
|
+
for face in self._halfface:
|
|
4134
|
+
if self.is_halfface_on_boundary(face):
|
|
4135
|
+
vertices.update(self.halfface_vertices(face))
|
|
4136
|
+
return list(vertices)
|
|
4137
|
+
|
|
4138
|
+
def halffaces_on_boundaries(self):
|
|
4139
|
+
"""Find the faces on the boundary.
|
|
4140
|
+
|
|
4141
|
+
Returns
|
|
4142
|
+
-------
|
|
4143
|
+
list[int]
|
|
4144
|
+
The faces of the boundary.
|
|
4145
|
+
|
|
4146
|
+
See Also
|
|
4147
|
+
--------
|
|
4148
|
+
:meth:`vertices_on_boundaries`, :meth:`cells_on_boundaries`
|
|
4149
|
+
|
|
4150
|
+
"""
|
|
4151
|
+
faces = set()
|
|
4152
|
+
for face in self._halfface:
|
|
4153
|
+
if self.is_halfface_on_boundary(face):
|
|
4154
|
+
faces.add(face)
|
|
4155
|
+
return list(faces)
|
|
4156
|
+
|
|
4157
|
+
def cells_on_boundaries(self):
|
|
4158
|
+
"""Find the cells on the boundary.
|
|
4159
|
+
|
|
4160
|
+
Returns
|
|
4161
|
+
-------
|
|
4162
|
+
list[int]
|
|
4163
|
+
The cells of the boundary.
|
|
4164
|
+
|
|
4165
|
+
See Also
|
|
4166
|
+
--------
|
|
4167
|
+
:meth:`vertices_on_boundaries`, :meth:`faces_on_boundaries`
|
|
4168
|
+
|
|
4169
|
+
"""
|
|
4170
|
+
cells = set()
|
|
4171
|
+
for face in self.halffaces_on_boundaries():
|
|
4172
|
+
cells.add(self.halfface_cell(face))
|
|
4173
|
+
return list(cells)
|
|
4174
|
+
|
|
4175
|
+
# --------------------------------------------------------------------------
|
|
4176
|
+
# Transformations
|
|
4177
|
+
# --------------------------------------------------------------------------
|
|
4178
|
+
|
|
4179
|
+
def transform(self, T):
|
|
4180
|
+
"""Transform the mesh.
|
|
4181
|
+
|
|
4182
|
+
Parameters
|
|
4183
|
+
----------
|
|
4184
|
+
T : :class:`Transformation`
|
|
4185
|
+
The transformation used to transform the mesh.
|
|
4186
|
+
|
|
4187
|
+
Returns
|
|
4188
|
+
-------
|
|
4189
|
+
None
|
|
4190
|
+
The mesh is modified in-place.
|
|
4191
|
+
|
|
4192
|
+
Examples
|
|
4193
|
+
--------
|
|
4194
|
+
>>> from compas.datastructures import Mesh
|
|
4195
|
+
>>> from compas.geometry import matrix_from_axis_and_angle
|
|
4196
|
+
>>> mesh = Mesh.from_polyhedron(6)
|
|
4197
|
+
>>> T = matrix_from_axis_and_angle([0, 0, 1], math.pi / 4)
|
|
4198
|
+
>>> mesh.transform(T)
|
|
4199
|
+
|
|
4200
|
+
"""
|
|
4201
|
+
points = transform_points(self.vertices_attributes("xyz"), T)
|
|
4202
|
+
for vertex, point in zip(self.vertices(), points):
|
|
4203
|
+
self.vertex_attributes(vertex, "xyz", point)
|