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