예제 #1
0
    def from_obj(cls, filepath, precision=None):
        """Construct a network from the data contained in an OBJ file.

        Parameters
        ----------
        filepath : path string, file-like object or URL string
            A path, a file-like object or a URL pointing to a file.
        precision: str, optional
            The precision of the geometric map that is used to connect the lines.

        Returns
        -------
        Network
            A network object.

        Examples
        --------
        >>>
        """
        network = cls()
        obj = OBJ(filepath, precision)
        obj.read()
        nodes = obj.vertices
        edges = obj.lines
        for i, (x, y, z) in enumerate(nodes):
            network.add_node(i, x=x, y=y, z=z)
        for u, v in edges:
            network.add_edge(u, v)
        return network
예제 #2
0
    def to_obj(self, filepath, precision=None, **kwargs):
        """Write the volmesh to an OBJ file.

        Parameters
        ----------
        filepath : path string | file-like object
            A path or a file-like object pointing to a file.
        precision: str, optional
            The precision of the geometric map that is used to connect the lines.
        unweld : bool, optional
            If True, all faces have their own unique vertices.
            If False, vertices are shared between faces if this is also the case in the mesh.
            Default is False.

        Returns
        -------
        None

        Warnings
        --------
        This function only writes geometric data about the vertices and
        the faces to the file.

        """
        obj = OBJ(filepath, precision=precision)
        obj.write(self, **kwargs)
예제 #3
0
    def from_obj(cls, filepath, precision=None):
        """Construct a volmesh object from the data described in an OBJ file.

        Parameters
        ----------
        filepath : path string | file-like object | URL string
            A path, a file-like object or a URL pointing to a file.
        precision: str, optional
            The precision of the geometric map that is used to connect the lines.

        Returns
        -------
        :class:`compas.datastructures.VolMesh`
            A volmesh object.

        """
        obj = OBJ(filepath, precision)
        vertices = obj.parser.vertices
        faces = obj.parser.faces
        groups = obj.parser.groups
        cells = []
        for name in groups:
            group = groups[name]
            cell = []
            for item in group:
                if item[0] != 'f':
                    continue
                face = faces[item[1]]
                cell.append(face)
            cells.append(cell)
        return cls.from_vertices_and_cells(vertices, cells)
예제 #4
0
    def from_obj(cls, filepath, precision=None):
        """Construct a volmesh object from the data described in an OBJ file.

        Parameters
        ----------
        filepath : str
            The path to the file.
        precision: str, optional
            The precision of the geometric map that is used to connect the lines.

        Returns
        -------
        Volesh
            A volmesh object.
        """
        obj = OBJ(filepath, precision)
        vertices = obj.parser.vertices
        faces = obj.parser.faces
        groups = obj.parser.groups
        cells = []
        for name in groups:
            group = groups[name]
            cell = []
            for item in group:
                if item[0] != 'f':
                    continue
                face = faces[item[1]]
                cell.append(face)
            cells.append(cell)
        return cls.from_vertices_and_cells(vertices, cells)
예제 #5
0
    def from_obj(cls, filepath, **kwargs):
        """Initialise a network from the data described in an obj file.

        Parameters:
            filepath (str): The path to the obj file.
            kwargs (dict) : Remaining named parameters. Default is an empty :obj:`dict`.

        Returns:
            Network: A ``Network`` of class ``cls``.

        >>> network = Network.from_obj('path/to/file.obj')

        """
        network = cls()
        network.attributes.update(kwargs)
        obj = OBJ(filepath)
        vertices = obj.parser.vertices
        edges    = obj.parser.lines
        faces = obj.parser.faces
        for i, (x, y, z) in enumerate(vertices):
            network.add_vertex(i, x=x, y=y, z=z)
        for u, v in edges:
            network.add_edge(u, v)
        for face in faces:
            network.add_face(face)
        return network
예제 #6
0
 def from_obj(cls, filepath, precision='3f'):
     network = cls()
     obj = OBJ(filepath, precision=precision)
     vertices = obj.parser.vertices
     edges = obj.parser.lines
     for i, (x, y, z) in enumerate(vertices):
         network.add_vertex(i, x=x, y=y, z=z)
     for u, v in edges:
         network.add_edge(u, v)
     return network
예제 #7
0
    def from_obj(cls, filepath, precision=None):
        """Construct a network from the data contained in an OBJ file.

        Parameters
        ----------
        filepath : str
            Path to the OBJ file.
        precision: str, optional
            The precision of the geometric map that is used to connect the lines.

        Returns
        -------
        Network
            A network object.

        Note
        ----
        There are a few sample files available for testing and debugging:

        * lines.obj

        Examples
        --------
        .. code-block:: python

            import compas
            from compas.datastructures import Network

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

        """
        network = cls()
        obj = OBJ(filepath, precision)
        obj.read()
        vertices = obj.vertices
        edges = obj.lines
        for i, (x, y, z) in enumerate(vertices):
            network.add_vertex(i, x=x, y=y, z=z)
        for u, v in edges:
            network.add_edge(u, v)
        return network
예제 #8
0
    def to_obj(self, filepath, precision=None, unweld=False, **kwargs):
        """Write the mesh to an OBJ file.

        Parameters
        ----------
        filepath : str
            Full path of the file.
        precision: str, optional
            The precision of the geometric map that is used to connect the lines.
        unweld : bool, optional
            If true, all faces have their own unique vertices.
            If false, vertices are shared between faces if this is also the case in the mesh.
            Default is ``False``.

        Warnings
        --------
        This function only writes geometric data about the vertices and
        the faces to the file.
        """
        obj = OBJ(filepath, precision=precision)
        obj.write(self, unweld=unweld, **kwargs)
예제 #9
0
파일: mesh.py 프로젝트: yishizu/compas
    def to_obj(self, filepath, precision=None, **kwargs):
        """Write the mesh to an OBJ file.

        Parameters
        ----------
        filepath : str
            Full path of the file.
        precision: str, optional
            The precision of the geometric map that is used to connect the lines.

        Warning
        -------
        Currently this function only writes geometric data about the vertices and
        the faces to the file.

        Examples
        --------
        >>>
        """
        obj = OBJ(filepath, precision=precision)
        obj.write(self, **kwargs)
예제 #10
0
    def from_obj(cls, filepath, precision=None):
        """Construct a mesh object from the data described in an OBJ file.

        Parameters
        ----------
        filepath : str
            The path to the file.
        precision: str, optional
            The precision of the geometric map that is used to connect the lines.

        Returns
        -------
        Mesh
            A mesh object.

        Note
        ----
        There are a few sample files available for testing and debugging:

        * faces.obj
        * faces_big.obj
        * faces_reversed.obj
        * hypar.obj
        * mesh.obj
        * quadmesh.obj

        Examples
        --------
        >>>
        """
        obj = OBJ(filepath, precision)
        obj.read()
        vertices = obj.vertices
        faces = obj.faces
        edges = obj.lines
        if faces:
            return cls.from_vertices_and_faces(vertices, faces)
        if edges:
            lines = [(vertices[u], vertices[v], 0) for u, v in edges]
            return cls.from_lines(lines)
예제 #11
0
from compas_fofin.datastructures import Cablenet

from compas_plotters import MeshPlotter

# ==============================================================================
# Make a cablenet
# ==============================================================================

# FILE = compas.get('quadmesh.obj')
# cablenet = Cablenet.from_obj(FILE)

HERE = os.path.dirname(__file__)
FILE_I = os.path.join(HERE, 'lines.obj')
FILE_O = os.path.join(HERE, 'lines.json')

obj = OBJ(FILE_I)
lines = [[obj.vertices[u], obj.vertices[v]] for u, v in obj.lines]

cablenet = Cablenet.from_lines(lines, delete_boundary_face=True)

cablenet.edges_attribute('is_edge',
                         False,
                         keys=list(cablenet.edges_on_boundary()))

# ==============================================================================
# Select a starting edge
# ==============================================================================

start = random.choice(
    list(set(cablenet.edges()) - set(cablenet.edges_on_boundary())))
예제 #12
0
from compas_tna.viewers import FormViewer

__author__ = [
    'Tom Van Mele',
]
__copyright__ = 'Copyright 2016 - Block Research Group, ETH Zurich'
__license__ = 'MIT License'
__email__ = '*****@*****.**'

# ==============================================================================
# make a form diagram from a set of lines

filepath = compas.get('lines.obj')

obj = OBJ(filepath)
vertices = obj.parser.vertices
edges = obj.parser.lines
lines = [(vertices[u], vertices[v], 0) for u, v in edges]

form = FormDiagram.from_lines(lines)

# ==============================================================================
# update boundary conditions

boundaries = form.vertices_on_boundaries()

exterior = boundaries[0]
interior = boundaries[1:]

form.set_vertices_attribute('is_anchor', True, keys=exterior)