How to use the compas.datastructures.Mesh.from_obj function in COMPAS

To help you get started, we’ve selected a few COMPAS examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github compas-dev / compas / tests / compas / datastructures / test_mesh.py View on Github external
def test_faces_on_boundary():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert list(mesh.faces_on_boundary()) == [45, 46, 47, 48, 49, 50, 51, 52, 60, 70, 40, 6, 8, 2, 75, 62, 55, 59, 20, 14, 71, 13, 78, 27, 21, 15, 9, 76, 61, 3, 79, 80]
github compas-dev / compas / tests / compas / datastructures / test_mesh.py View on Github external
def test_vertex_normal():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.vertex_normal(0) == [-0.7875436283909406, 0.07148692938164082, 0.6120985642103861]
    assert mesh.vertex_normal(5) == [-0.482011312317331, -0.32250183520381565, 0.814651864963369]
github compas-dev / compas / tests / compas / datastructures / test_mesh.py View on Github external
def test_face_curvature():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_curvature(0) == 0.0035753184898039566

    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.face_curvature(0) == 0
github compas-dev / compas / docs / examples / plotter / mesh-equilibrium.py View on Github external
from compas.viewers import MeshViewer

from compas.numerical import fd_numpy


__author__    = 'Tom Van Mele'
__copyright__ = 'Copyright 2016, Block Research Group - ETH Zurich'
__license__   = 'MIT license'
__email__     = 'vanmelet@ethz.ch'


# make a mesh from an orthogonal grid of faces
# with two high corners and two low corners
# and define the default attributes of vertices and edges

mesh = Mesh.from_obj(compas.get('hypar.obj'))

dva = {'is_anchor': False, 'px': 0.0, 'py': 0.0, 'pz': 0.0}
dea = {'q': 1.0}

mesh.update_default_vertex_attributes(dva)
mesh.update_default_edge_attributes(dea)


# mark the corners of the mesh as anchors
# i.e. they can take reaction forces
# increase the force density along the boundaries
# to prevent the mesh from collapsing too much

mesh.set_vertices_attribute('is_anchor', True, keys=mesh.vertices_where({'vertex_degree': 2}))
mesh.set_edges_attribute('q', 10.0, keys=mesh.edges_on_boundary())
github compas-dev / compas / src / compas / datastructures / mesh / bbox_numpy.py View on Github external
"""
    xyz = mesh.get_vertices_attributes('xyz')
    return oriented_bounding_box_xy_numpy(xyz)


# ==============================================================================
# Main
# ==============================================================================

if __name__ == '__main__':

    import doctest
    import compas
    from compas.datastructures import Mesh

    hypar = Mesh.from_obj(compas.get('hypar.obj'))
    mesh = Mesh.from_obj(compas.get('faces.obj'))

    doctest.testmod()
github compas-dev / compas / src / compas_viewers / vtkviewer.py View on Github external
# data = {'voxels': x + y + z}

    # viewer = VtkViewer(data=data)
    # viewer.setup()
    # viewer.start()


    # ==============================================================================
    # Datastructure
    # ==============================================================================

    from compas.datastructures import Mesh

    import compas

    datastructure = Mesh.from_obj(compas.get('quadmesh.obj'))

    viewer = VtkViewer(datastructure=datastructure)
    viewer.setup()
    viewer.start()
github compas-dev / compas / docs / reference / generated / compas-visualization-MeshPlotter-1.py View on Github external
import compas
from compas.datastructures import Mesh
from compas.visualization import MeshPlotter

mesh = Mesh.from_obj(compas.get('faces.obj'))

plotter = MeshPlotter(mesh)

plotter.draw_vertices(text='key')
plotter.draw_edges()
plotter.draw_faces()

plotter.show()
github compas-dev / compas / src / compas_plotters / meshplotter.py View on Github external
polygons.append(Polygon(points))
            facecolors.append(color_to_rgb(facecolor[fkey], normalize=True))
        self.facecollection.set_paths(polygons)
        self.facecollection.set_facecolor(facecolors)


# ==============================================================================
# Main
# ==============================================================================

if __name__ == "__main__":

    import compas
    from compas.datastructures import Mesh

    mesh = Mesh.from_obj(compas.get('faces.obj'))

    plotter = MeshPlotter(mesh, figsize=(10, 6))

    plotter.draw_vertices(text='key', radius=0.2, picker=10)

    for text in plotter.axes.texts:
        text.set_visible(False)

    plotter.draw_edges()
    plotter.draw_faces()

    def onpick(event):
        index = event.ind[0]
        for i, text in enumerate(plotter.axes.texts):
            if i == index:
                text.set_visible(True)
github compas-dev / compas / docs / workshops / acadia2017 / day1 / datastructures-5.py View on Github external
import compas
from compas.datastructures import Mesh
from compas.visualization import MeshPlotter

mesh = Mesh.from_obj(compas.get('faces.obj'))

plotter = MeshPlotter(mesh)

plotter.draw_vertices(text={key: '%.1f' % mesh.vertex_area(key) for key in mesh.vertices()})
plotter.draw_faces()
plotter.draw_edges()

plotter.show()
github compas-dev / compas / docs / .source / _examples / mesh-equilibrium.py View on Github external
from compas.visualization.viewers.meshviewer import MeshViewer

from compas.numerical import fd


__author__    = 'Tom Van Mele'
__copyright__ = 'Copyright 2016, Block Research Group - ETH Zurich'
__license__   = 'MIT license'
__email__     = 'vanmelet@ethz.ch'


# make a mesh from an orthogonal grid of faces
# with two high corners
# and two low corners

mesh = Mesh.from_obj(compas.get_data('hypar.obj'))

# define the default attributes of vertices and edges

dva = {'is_anchor': False, 'px': 0.0, 'py': 0.0, 'pz': -0.0}
dea = {'q': 1.0}

# update the default attributes of vertices and edges

mesh.update_default_vertex_attributes(dva)
mesh.update_default_edge_attributes(dea)

# mark the corners of the mesh as anchors
# i.e. they can take reaction forces

for key in mesh.vertices():
    mesh.vertex[key]['is_anchor'] = mesh.vertex_degree(key) == 2