Esempio n. 1
0
def test_face_adjacency_halfedge():
    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.face_adjacency_halfedge(0, 1) == (1, 7)
Esempio n. 2
0
# ==============================================================================
# Main
# ==============================================================================

if __name__ == '__main__':

    import compas
    from compas_pattern.datastructures.mesh_quad_coarse.mesh_quad_coarse import CoarseQuadMesh
    from compas_pattern.algorithms.exploration.walk import Walker
    from compas_pattern.datastructures.mesh_quad.grammar.add_strip import add_strip
    from compas.datastructures import mesh_smooth_centroid
    from compas_plotters.meshplotter import MeshPlotter
    from compas.numerical import ga

    mesh = CoarseQuadMesh.from_obj(compas.get('faces.obj'))
    mesh.collect_strips()

    fit_type = 'max'
    num_var = 5
    boundaries = [(0.0, 1.0)] * num_var
    num_bin_dig = [2] * num_var
    output_path = '/Users/Robin/Desktop/ga/'
    fkwargs = {'mesh': mesh}

    def fit_function(X, **fkwargs):
        print('X', X)
        mesh = fkwargs['mesh']
        orders = [2] + [int(x) for x in X]
        mesh_2 = mesh.copy()
        walker = Walker(mesh_2)
Esempio n. 3
0
from random import choice
from numpy import array

import compas

from compas.datastructures import Mesh
from compas.datastructures import mesh_laplacian_matrix
from compas.geometry import add_vectors
from compas_plotters import MeshPlotter

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

key = choice(list(set(mesh.vertices()) - set(mesh.vertices_on_boundary())))

mesh.vertex[key]['x'] += 0.3
mesh.vertex[key]['y'] += 0.3

V = array(mesh.get_vertices_attributes('xyz'))
L = mesh_laplacian_matrix(mesh)
d = L.dot(V)

plotter = MeshPlotter(mesh, tight=True)

plotter.draw_vertices()
plotter.draw_edges()
plotter.draw_faces()

arrows = []
for start, vector in zip(V, d):
    arrows.append({
        'start': start,
Esempio n. 4
0
    def keypress(self, key, x, y):
        """Assign network functionality to keys.
        """
        if key == 'c':
            self.screenshot(
                os.path.join(compas.TEMP,
                             'screenshots/network-viewer_screenshot.jpg'))

    def special(self, key, x, y):
        """Define the meaning of pressing function keys.
        """
        pass


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

if __name__ == '__main__':

    import compas
    from compas.datastructures import Network

    network = Network.from_obj(compas.get('saddle.obj'))

    viewer = NetworkViewer(network, 600, 600)

    viewer.setup()
    viewer.show()
Esempio n. 5
0
    nodes = breadth_first_traverse(mesh.adjacency, mesh.get_any_vertex())

    return len(nodes) == mesh.number_of_vertices()


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

if __name__ == "__main__":

    import compas
    from compas.datastructures import Network
    from compas.plotters import NetworkPlotter

    network = Network.from_obj(compas.get('grid_irregular.obj'))

    components = connected_components(network.adjacency)

    print(network_is_connected(network))
    print(components)

    key_color = vertex_coloring(network.adjacency)

    colors = ['#ff0000', '#00ff00', '#0000ff']

    plotter = NetworkPlotter(network, figsize=(10, 7))

    plotter.draw_vertices(
        facecolor={key: colors[key_color[key]]
                   for key in network.vertices()})
Esempio n. 6
0
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
    ]
# ==============================================================================

if __name__ == '__main__':

    import compas
    from compas_singular.datastructures.mesh_quad.mesh_quad import QuadMesh
    from compas.datastructures.mesh import mesh_smooth_centroid
    from compas_plotters.meshplotter import MeshPlotter

    #mesh = QuadMesh.from_obj(compas.get('faces.obj'))
    # mesh = QuadMesh.from_json('/Users/Robin/Desktop/json/debug.json')
    # mesh.collect_strips()
    # mesh.collect_polyedges()

    mesh_0 = CoarseQuadMesh.from_quad_mesh(
        QuadMesh.from_obj(compas.get('faces.obj')))
    mesh_0.collect_strips()
    # mesh_0.collect_polyedges()
    # print(mesh_0.is_quadmesh())
    # print(mesh_0.number_of_strips())

    # vertices = [[12.97441577911377, 24.33094596862793, 0.0], [18.310085296630859, 8.467333793640137, 0.0], [30.052173614501953, 18.846050262451172, 0.0], [17.135400772094727, 16.750551223754883, 0.0], [16.661802291870117, 22.973459243774414, 0.0], [14.180665969848633, 26.949295043945313, 0.0], [36.052761077880859, 26.372636795043945, 0.0], [26.180931091308594, 21.778648376464844, 0.0], [19.647378921508789, 12.288106918334961, 0.0], [9.355668067932129, 16.475896835327148, 0.0], [18.929227828979492, 16.271940231323242, 0.0], [7.34525203704834, 12.111981391906738, 0.0], [13.31309986114502, 14.699410438537598, 0.0], [18.699434280395508, 19.613750457763672, 0.0], [11.913931846618652, 10.593378067016602, 0.0], [17.163223266601563, 26.870658874511719, 0.0], [26.110898971557617, 26.634754180908203, 0.0], [22.851469039916992, 9.81414794921875, 0.0], [21.051292419433594, 7.556171894073486, 0.0], [22.1370792388916, 19.089054107666016, 0.0]]
    # faces = [[15, 5, 0, 4], [0, 9, 12, 4], [9, 11, 14, 12], [14, 1, 8, 12], [1, 18, 17, 8], [17, 2, 7, 8], [2, 6, 16, 7], [16, 15, 4, 7], [13, 19, 7, 4], [19, 10, 8, 7], [10, 3, 12, 8], [3, 13, 4, 12]]
    # mesh = QuadMesh.from_vertices_and_faces(vertices, faces)
    # mesh.collect_strips()
    # mesh.collect_polyedges()

    # mesh_0 = CoarseQuadMesh.from_quad_mesh(mesh)
    # mesh_0.collect_strips()
    # mesh_0.collect_polyedges()
Esempio n. 8
0
def test_vertex_neighborhood_centroid():
    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.vertex_neighborhood_centroid(0) == [1.0, 1.0, 0.0]
    assert mesh.vertex_neighborhood_centroid(1) == [
        2.0, 0.6666666666666666, 0.0
    ]
Esempio n. 9
0
def test_vertex_curvature():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.vertex_curvature(0) == 0.0029617825994936453
    assert mesh.vertex_curvature(5) == 0.036193074384009094
Esempio n. 10
0
def test_vertex_area():
    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.vertex_area(0) == 1
    assert mesh.vertex_area(15) == 4
Esempio n. 11
0
def test_vertex_laplacian():

    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.vertex_laplacian(0) == [1.0, 1.0, 0.0]
    assert mesh.vertex_laplacian(1) == [0.0, 0.6666666666666666, 0.0]
Esempio n. 12
0
def test_vertex_coordinates():
    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.vertex_coordinates(15) == [6.0, 4.0, 0.0]
    assert mesh.vertex_coordinates(15, 'yx') == [4.0, 6.0]
Esempio n. 13
0
def test_is_face_on_boundary():
    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.is_face_on_boundary(0)
    assert not mesh.is_face_on_boundary(8)
Esempio n. 14
0
def test_face_adjacency_vertices():
    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.face_adjacency_vertices(0, 1) == [1, 7]
Esempio n. 15
0
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
Esempio n. 16
0
def test_face_normal():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_normal(0) == (0.5435358481001584, -0.16248515023849733,
                                   0.8235091728584537)
Esempio n. 17
0
def test_from_off():
    mesh = Mesh.from_off(compas.get('cube.off'))
    assert mesh.number_of_faces() == 6
    assert mesh.number_of_vertices() == 8
    assert mesh.number_of_edges() == 12
Esempio n. 18
0
def test_face_centroid():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_centroid(0) == [
        3.94185334444046, 2.024157851934433, 1.3333333134651184
    ]
Esempio n. 19
0
def test_edges_on_boundary():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert len(mesh.edges_on_boundary()) == 36
Esempio n. 20
0
def test_face_center():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_center(0) == [
        3.944329439044577, 2.0258867968680776, 1.332040166602369
    ]
Esempio n. 21
0
    def clear(self):
        self.clear_vertices()
        self.clear_faces()
        self.clear_edges()


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

if __name__ == "__main__":

    import compas

    from compas.datastructures import VolMesh

    volmesh = VolMesh.from_obj(compas.get('boxes.obj'))

    artist = VolMeshArtist(volmesh, layer='VolMeshArtist')

    # artist.clear_layer()

    artist.draw_vertices()
    artist.draw_vertexlabels()
    # artist.clear_vertexlabels()

    artist.draw_edges()
    artist.draw_edgelabels()
    # artist.clear_edgelabels()
Esempio n. 22
0
def test_face_area():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_area(0) == 0.3374168482414756
Esempio n. 23
0
import random
import compas
from compas.datastructures import Mesh
from compas_plotters import MeshPlotter

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

start = random.choice(list(mesh.edges()))
edges = mesh.edge_strip(start)

edgecolor = {}
for edge in edges:
    edgecolor[edge] = (0, 255, 0)

edgecolor[start] = (255, 0, 0)

plotter = MeshPlotter(mesh, figsize=(12, 7.5))
plotter.draw_vertices(radius=0.03)
plotter.draw_faces()
plotter.draw_edges(keys=edges, color=edgecolor, width=2.0)
plotter.show()
Esempio n. 24
0
def test_face_flatness():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_flatness(0) == 0.23896112582475654

    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.face_flatness(0) == 0
Esempio n. 25
0
            callback(k, callback_args)


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

if __name__ == "__main__":

    import compas

    from compas.datastructures import Mesh
    from compas.plotters import MeshPlotter
    from compas.utilities import i_to_rgb

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

    for key, attr in mesh.vertices(True):
        attr['is_fixed'] = mesh.vertex_degree(key) == 2

    fixed = [key for key in mesh.vertices_where({'is_fixed': True})]
    radius = {key: (0.05 if key in fixed else 0.01) for key in mesh.vertices()}

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

    plotter.draw_vertices(radius=radius)
    plotter.draw_faces()
    plotter.draw_edges()

    def callback(k, args):
        print(k)
Esempio n. 26
0
def test_face_aspect_ratio():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_aspect_ratio(0) == 1.2813792520925738

    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.face_aspect_ratio(0) == 1
Esempio n. 27
0
from math import radians
import compas
from compas.geometry import Point, Line, Translation, Rotation, Scale
from compas.datastructures import Mesh
from compas_gmsh.models import MeshModel
from compas_view2.app import App

# ==============================================================================
# Input
# ==============================================================================

mesh = Mesh.from_json(compas.get('tubemesh.json'))

centroid = Point(*mesh.centroid())
vector = Point(0, 0, 0) - centroid
vector.z = 0

T = Translation.from_vector(vector)
R = Rotation.from_axis_and_angle([0, 0, 1], radians(105))
S = Scale.from_factors([0.3, 0.3, 0.3])

mesh.transform(S * R * T)

# ==============================================================================
# GMSH model
# ==============================================================================

model = MeshModel.from_mesh(mesh, name='tubemesh', targetlength=0.3)

model.heal()
Esempio n. 28
0
def test_face_skewness():
    mesh = Mesh.from_obj(compas.get('quadmesh.obj'))
    assert mesh.face_skewness(0) == 0.2432393485343291

    mesh = Mesh.from_obj(compas.get('faces.obj'))
    assert mesh.face_skewness(0) == 0
Esempio n. 29
0
    # return the key of the split vertex
    return w


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

if __name__ == "__main__":

    import compas
    from compas.datastructures import Network
    from compas_plotters import NetworkPlotter

    network = Network.from_obj(compas.get('lines.obj'))

    a = network.split_edge(0, 22)
    b = network.split_edge(2, 30)
    c = network.split_edge(17, 21)
    d = network.split_edge(28, 16)

    lines = []
    for u, v in network.edges():
        lines.append({
            'start': network.vertex_coordinates(u, 'xy'),
            'end': network.vertex_coordinates(v, 'xy'),
            'arrow': 'end',
            'width': 4.0,
            'color': '#00ff00'
        })
Esempio n. 30
0
def test_from_ply():
    mesh = Mesh.from_ply(compas.get('bunny.ply'))
    assert mesh.number_of_faces() == 69451
    assert mesh.number_of_vertices() == 35947
    assert mesh.number_of_edges() == 104288