Exports a mesh in the (.off) format.
496831
def export_off(vertices, triangles, filename):
    
    
    with open(filename, 'w') as fh:
        fh.write('OFF\n')
        fh.write('{} {} 0\n'.format(len(vertices), len(triangles)))

        for v in vertices:
            fh.write("{} {} {}\n".format(*v))
            
        for f in triangles:
            fh.write("3 {} {} {}\n".format(*f))
1327473
def export_data(filename_or_fobj, data, mode="w"):
    """"""

    if filename_or_fobj is None:
        return data

    _, fobj = get_filename_and_fobj(filename_or_fobj, mode=mode)
    source = Source.from_file(filename_or_fobj, mode=mode, plugin_name=None)
    source.fobj.write(data)
    source.fobj.flush()
    return source.fobj
910485
def export_collada(mesh, **kwargs):
    
    meshes = mesh
    if not isinstance(mesh, (list, tuple, set, np.ndarray)):
        meshes = [mesh]

    c = collada.Collada()
    nodes = []
    for i, m in enumerate(meshes):

        # Load uv, colors, materials
        uv = None
        colors = None
        mat = _unparse_material(None)
        if m.visual.defined:
            if m.visual.kind == 'texture':
                mat = _unparse_material(m.visual.material)
                uv = m.visual.uv
            elif m.visual.kind == 'vertex':
                colors = (m.visual.vertex_colors / 255.0)[:, :3]
        c.effects.append(mat.effect)
        c.materials.append(mat)

        # Create geometry object
        vertices = collada.source.FloatSource(
            'verts-array', m.vertices.flatten(), ('X', 'Y', 'Z'))
        normals = collada.source.FloatSource(
            'normals-array', m.vertex_normals.flatten(), ('X', 'Y', 'Z'))
        input_list = collada.source.InputList()
        input_list.addInput(0, 'VERTEX', '#verts-array')
        input_list.addInput(1, 'NORMAL', '#normals-array')
        arrays = [vertices, normals]
        if uv is not None:
            texcoords = collada.source.FloatSource(
                'texcoords-array', uv.flatten(), ('U', 'V'))
            input_list.addInput(2, 'TEXCOORD', '#texcoords-array')
            arrays.append(texcoords)
        if colors is not None:
            idx = 2
            if uv:
                idx = 3
            colors = collada.source.FloatSource('colors-array',
                                                colors.flatten(), ('R', 'G', 'B'))
            input_list.addInput(idx, 'COLOR', '#colors-array')
            arrays.append(colors)
        geom = collada.geometry.Geometry(
            c, uuid.uuid4().hex, uuid.uuid4().hex, arrays
        )
        indices = np.repeat(m.faces.flatten(), len(arrays))

        matref = 'material{}'.format(i)
        triset = geom.createTriangleSet(indices, input_list, matref)
        geom.primitives.append(triset)
        c.geometries.append(geom)

        matnode = collada.scene.MaterialNode(matref, mat, inputs=[])
        geomnode = collada.scene.GeometryNode(geom, [matnode])
        node = collada.scene.Node('node{}'.format(i), children=[geomnode])
        nodes.append(node)
    scene = collada.scene.Scene('scene', nodes)
    c.scenes.append(scene)
    c.scene = scene

    b = io.BytesIO()
    c.write(b)
    b.seek(0)
    return b.read()
247945
def export(self, node):
        """"""
        attriter = self.attriter or (lambda attr_values: attr_values)
        return self.__export(node, self.dictcls, attriter, self.childiter)
1254522
def out_format(data, out, opts=None, **kwargs):
    '''
    
    '''
    return try_printout(data, out, opts, **kwargs)
407435
public void writeGridInPmeshFormat(String outPutFileName) throws IOException {
        BufferedWriter writer = new BufferedWriter(new FileWriter(outPutFileName + ".pmesh"));
        int numberOfGridPoints = grid.length * grid[0].length * grid[0][0].length;
        writer.write(numberOfGridPoints + "\n");
        for (int z = 0; z < grid[0][0].length; z++) {
            for (int y = 0; y < grid[0].length; y++) {
                for (int x = 0; x < grid.length; x++) {
                    Point3d coords = getCoordinatesFromGridPoint(new Point3d(x, y, z));
                    writer.write(coords.x + "\t" + coords.y + "\t" + coords.z + "\n");
                }
            }
        }
        writer.close();
    }
1269539
def export(self, filename, offset=0, length=None):
        
        self.__validate_offset(filename=filename, offset=offset, length=length)

        with open(filename, 'w') as f:
            if length is None:
                length = len(self.data) - offset

            if offset > 0:
                output = self.data[offset:length]
            else:
                output = self.data[:length]

            f.write(output)
396549
def normalize_mesh(mesh):
  ''''''
  mesh = dict(mesh)
  pos = mesh['position'][:,:3].copy()
  pos -= (pos.max(0)+pos.min(0)) / 2.0
  pos /= np.abs(pos).max()
  mesh['position'] = pos
  return mesh
2608
def export(defn):
    """"""
    globals()[defn.__name__] = defn
    __all__.append(defn.__name__)
    return defn
204892
def format_geometry_in
      output = ""
      if self.lattice_vectors
        output << self.lattice_vectors.collect{|v| "lattice_vector #{v[0]} #{v[1]} #{v[2]}"}.join("\n")
        output << "\n"
      end
      output << self.atoms.collect{|a| a.format_geometry_in}.join("\n")

      output
    end
887837
def export_to_tf_tensor(self, x, laid_out_x):
    
    tensor_layout = self.tensor_layout(x.shape)
    if not tensor_layout.is_fully_replicated:
      raise NotImplementedError(
          "SimdMeshImpl only supports export_to_tf_tensor of fully-replicated "
          "Tensors.  Try reshaping to new dimension names. "
          " x.shape = %s tensor_layout=%s"
          % (x.shape, tensor_layout))
    return laid_out_x.one_slice
900097
def export(self, nidm_version, export_dir):
        
        attributes = [(PROV['type'], NIDM_STATISTIC_MAP),
                      (DCT['format'], self.fmt)]

        if not self.isderfrommap:
            attributes.insert(0, (
                NIDM_IN_COORDINATE_SPACE,  self.coord_space.id))
            attributes.insert(0, (PROV['label'], self.label))

        if not self.stat_type == 'Z':
            attributes.insert(0, (NIDM_ERROR_DEGREES_OF_FREEDOM, self.dof))
            attributes.insert(0, (NIDM_EFFECT_DEGREES_OF_FREEDOM, self.effdof))
        else:
            # For Z-Statistic error dof is infinity and effect dof is 1
            attributes.insert(0, (NIDM_ERROR_DEGREES_OF_FREEDOM, float("inf")))
            attributes.insert(0, (NIDM_EFFECT_DEGREES_OF_FREEDOM, self.effdof))

        if self.stat is not None:
            attributes.insert(0, (NIDM_STATISTIC_TYPE, self.stat))

        if self.contrast_name is not None:
            attributes.insert(0, (NIDM_CONTRAST_NAME, self.contrast_name))

        # Create "Statistic Map" entity
        # FIXME: Deal with other than t-contrast maps: dof + statisticType
        self.add_attributes(attributes)
915781
def write(filename, mesh, write_binary=True):
    
    if mesh.points.shape[1] == 2:
        logging.warning(
            "msh2 requires 3D points, but 2D points given. "
            "Appending 0 third component."
        )
        mesh.points = numpy.column_stack(
            [mesh.points[:, 0], mesh.points[:, 1], numpy.zeros(mesh.points.shape[0])]
        )

    if write_binary:
        for key, value in mesh.cells.items():
            if value.dtype != c_int:
                logging.warning(
                    "Binary Gmsh needs 32-bit integers (got %s). Converting.",
                    value.dtype,
                )
                mesh.cells[key] = numpy.array(value, dtype=c_int)

    # Gmsh cells are mostly ordered like VTK, with a few exceptions:
    cells = mesh.cells.copy()
    if "tetra10" in cells:
        cells["tetra10"] = cells["tetra10"][:, [0, 1, 2, 3, 4, 5, 6, 7, 9, 8]]
    if "hexahedron20" in cells:
        cells["hexahedron20"] = cells["hexahedron20"][
            :, [0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 13, 9, 16, 18, 19, 17, 10, 12, 14, 15]
        ]

    with open(filename, "wb") as fh:
        mode_idx = 1 if write_binary else 0
        size_of_double = 8
        fh.write(
            ("$MeshFormat\n2.2 {} {}\n".format(mode_idx, size_of_double)).encode(
                "utf-8"
            )
        )
        if write_binary:
            fh.write(struct.pack("i", 1))
            fh.write("\n".encode("utf-8"))
        fh.write("$EndMeshFormat\n".encode("utf-8"))

        if mesh.field_data:
            _write_physical_names(fh, mesh.field_data)

        # Split the cell data: gmsh:physical and gmsh:geometrical are tags, the
        # rest is actual cell data.
        tag_data = {}
        other_data = {}
        for cell_type, a in mesh.cell_data.items():
            tag_data[cell_type] = {}
            other_data[cell_type] = {}
            for key, data in a.items():
                if key in ["gmsh:physical", "gmsh:geometrical"]:
                    tag_data[cell_type][key] = data.astype(c_int)
                else:
                    other_data[cell_type][key] = data

        _write_nodes(fh, mesh.points, write_binary)
        _write_elements(fh, cells, tag_data, write_binary)
        if mesh.gmsh_periodic is not None:
            _write_periodic(fh, mesh.gmsh_periodic)
        for name, dat in mesh.point_data.items():
            _write_data(fh, "NodeData", name, dat, write_binary)
        cell_data_raw = raw_from_cell_data(other_data)
        for name, dat in cell_data_raw.items():
            _write_data(fh, "ElementData", name, dat, write_binary)

    return
1095563
def to_(self, off_pts):
        """"""
        off_pts = np.asarray(off_pts, dtype=np.float)
        has_z = (off_pts.shape[-1] > 2)

        # scale according to current settings
        scale_pt = [self.viewer._org_scale_x, self.viewer._org_scale_y]
        if has_z:
            scale_pt.append(self.viewer._org_scale_z)

        off_pts = np.multiply(off_pts, scale_pt)
        return off_pts
521770
def to_mesh(self):
        
        result = Trimesh(vertices=self.vertices.copy(),
                         faces=self.faces.copy(),
                         face_normals=self.face_normals.copy(),
                         process=False)
        return result
193173
def export(self, filename, fmt="DER"):
        
        f = open(filename, "wb")
        if fmt == "DER":
            f.write(self.der)
        elif fmt == "PEM":
            f.write(self.pem)
        f.close()
16895
def export_dict(mesh, encoding=None):
    

    def encode(item, dtype=None):
        if encoding is None:
            return item.tolist()
        else:
            if dtype is None:
                dtype = item.dtype
            return util.array_to_encoded(item, dtype=dtype, encoding=encoding)

    # metadata keys we explicitly want to preserve
    # sometimes there are giant datastructures we don't
    # care about in metadata which causes exports to be
    # extremely slow, so skip all but known good keys
    meta_keys = ['units', 'file_name', 'file_path']
    metadata = {k: v for k, v in mesh.metadata.items() if k in meta_keys}

    export = {
        'metadata': metadata,
        'faces': encode(mesh.faces),
        'face_normals': encode(mesh.face_normals),
        'vertices': encode(mesh.vertices)
    }
    if mesh.visual.kind == 'face':
        export['face_colors'] = encode(mesh.visual.face_colors)
    elif mesh.visual.kind == 'vertex':
        export['vertex_colors'] = encode(mesh.visual.vertex_colors)

    return export