예제 #1
0
 def _to_omf(self):
     import omf
     from omf.data import Int3Array
     geometry = omf.SurfaceGeometry(
         vertices=omf.Vector3Array(self.vertices, ),
         triangles=Int3Array(self.triangles, ),
     )
     return geometry
예제 #2
0
def surf_to_omf(filename, name, description, elevation=False):
    surf = delauney(read_surface_verts(gdc19.get_surfaces_path(filename)))
    if elevation:
        surf = surf.elevation()

    tris = surf.faces.reshape(surf.n_cells, 4)[:, 1:4]
    element = omf.SurfaceElement(name=name,
                                 description=description,
                                 geometry=omf.SurfaceGeometry(
                                     vertices=surf.points, triangles=tris))
    element.validate()
    return element
예제 #3
0
 def to_omf(self):
     self.validate()
     omf_surface = omf.SurfaceElement(
         name=self.name or '',
         description=self.description or '',
         geometry=omf.SurfaceGeometry(
             vertices=self.vertices.array,
             triangles=self.triangles.array,
         ),
         data=[
             attr.to_omf(cell_location='faces') for attr in self.data
             if not isinstance(attr, TextureProjection)
         ],
         textures=[
             tex.to_omf() for tex in self.data
             if isinstance(tex, TextureProjection)
         ],
         color=self.defaults.color.value,
     )
     return omf_surface
예제 #4
0
def test_surfaces():
    proj = omf.Project(origin=[5., 5, 5])
    surf_0 = omf.SurfaceElement(
        name='my elem',
        description='my desc',
        geometry=omf.SurfaceGeometry(
            vertices=[[i / 3, i / 4, i / 5] for i in range(10)],
            triangles=[[i, i + 1, i + 2] for i in range(8)],
            origin=[5., 5, 5],
        ),
        color='red',
    )
    surf_1 = omf.SurfaceElement(
        name='my elem',
        description='my desc',
        geometry=omf.SurfaceGridGeometry(
            tensor_u=[1., 1., 1., 1., 1.],
            tensor_v=[1., 1., 1., 1., 1.],
            offset_w=[1.] * 36,
            origin=[5., 5, 5],
        ),
        color='red',
    )
    proj.elements = [surf_0, surf_1]
    proj.validate()
    view = get_view_from_proj(proj)
    view.validate()
    assert len(view.contents) == 5
    for cls in (spatial.ElementSurface, spatial.ElementSurfaceGrid):
        surface = find(view, cls)
        defaults = surface.defaults.serialize()
        assert defaults['__class__'] == 'OptionsSurface'
        assert defaults['color']['value'] == '#FF0000'
        assert surface.name == 'my elem'
        assert surface.description == 'my desc'
    assert list(find(
        view, spatial.ElementSurface).vertices.array[0]) == [10., 10, 10]
    assert list(find(view, spatial.ElementSurfaceGrid).origin) == [10., 10, 10]
예제 #5
0
                                 vertices=np.random.rand(100, 3),
                                 segments=np.floor(
                                     np.random.rand(50, 2) * 100).astype(int)),
                             data=[
                                 omf.ScalarData(name='rand vert data',
                                                array=np.random.rand(100),
                                                location='vertices'),
                                 omf.ScalarData(name='rand segment data',
                                                array=np.random.rand(50),
                                                location='segments')
                             ],
                             color='#0000FF')

SURFACE = omf.SurfaceElement(name='trisurf',
                             geometry=omf.SurfaceGeometry(
                                 vertices=np.random.rand(100, 3),
                                 triangles=np.floor(
                                     np.random.rand(50, 3) * 100).astype(int)),
                             data=[
                                 omf.ScalarData(name='rand vert data',
                                                array=np.random.rand(100),
                                                location='vertices'),
                                 omf.ScalarData(name='rand face data',
                                                array=np.random.rand(50),
                                                location='faces')
                             ],
                             color=[100, 200, 200])
GRID = omf.SurfaceElement(
    name='gridsurf',
    geometry=omf.SurfaceGridGeometry(tensor_u=np.ones(10).astype(float),
                                     tensor_v=np.ones(15).astype(float),
                                     origin=[50., 50., 50.],
예제 #6
0
    def test_doc_ex(self):
        dirname, _ = os.path.split(os.path.abspath(__file__))
        pngfile = os.path.sep.join(dirname.split(os.path.sep)[:-1] +
                                   ['docs', 'images', 'PointSetGeometry.png'])

        proj = omf.Project(
            name='Test project',
            description='Just some assorted elements'
        )

        pts = omf.PointSetElement(
            name='Random Points',
            description='Just random points',
            geometry=omf.PointSetGeometry(
                vertices=np.random.rand(100, 3)
            ),
            data=[
                omf.ScalarData(
                    name='rand data',
                    array=np.random.rand(100),
                    location='vertices'
                ),
                omf.ScalarData(
                    name='More rand data',
                    array=np.random.rand(100),
                    location='vertices'
                )
            ],
            textures=[
                omf.ImageTexture(
                    name='test image',
                    image=pngfile,
                    origin=[0, 0, 0],
                    axis_u=[1, 0, 0],
                    axis_v=[0, 1, 0]
                ),
                omf.ImageTexture(
                    name='test image',
                    image=pngfile,
                    origin=[0, 0, 0],
                    axis_u=[1, 0, 0],
                    axis_v=[0, 0, 1]
                )
            ],
            color='green'
        )

        lin = omf.LineSetElement(
            name='Random Line',
            geometry=omf.LineSetGeometry(
                vertices=np.random.rand(100, 3),
                segments=np.floor(np.random.rand(50, 2)*100).astype(int)
            ),
            data=[
                omf.ScalarData(
                    name='rand vert data',
                    array=np.random.rand(100),
                    location='vertices'
                ),
                omf.ScalarData(
                    name='rand segment data',
                    array=np.random.rand(50),
                    location='segments'
                )
            ],
            color='#0000FF'
        )

        surf = omf.SurfaceElement(
            name='trisurf',
            geometry=omf.SurfaceGeometry(
                vertices=np.random.rand(100, 3),
                triangles=np.floor(np.random.rand(50, 3)*100).astype(int)
            ),
            data=[
                omf.ScalarData(
                    name='rand vert data',
                    array=np.random.rand(100),
                    location='vertices'
                ),
                omf.ScalarData(
                    name='rand face data',
                    array=np.random.rand(50),
                    location='faces'
                )
            ],
            color=[100, 200, 200]
        )

        grid = omf.SurfaceElement(
            name='gridsurf',
            geometry=omf.SurfaceGridGeometry(
                tensor_u=np.ones(10).astype(float),
                tensor_v=np.ones(15).astype(float),
                origin=[50., 50., 50.],
                axis_u=[1., 0, 0],
                axis_v=[0, 0, 1.],
                offset_w=np.random.rand(11, 16).flatten()
            ),
            data=[
                omf.ScalarData(
                    name='rand vert data',
                    array=np.random.rand(11, 16).flatten(),
                    location='vertices'
                ),
                omf.ScalarData(
                    name='rand face data',
                    array=np.random.rand(10, 15).flatten(order='f'),
                    location='faces'
                )
            ],
            textures=[
                omf.ImageTexture(
                    name='test image',
                    image=pngfile,
                    origin=[2., 2., 2.],
                    axis_u=[5., 0, 0],
                    axis_v=[0, 2., 5.]
                )
            ]
        )

        vol = omf.VolumeElement(
            name='vol',
            geometry=omf.VolumeGridGeometry(
                tensor_u=np.ones(10).astype(float),
                tensor_v=np.ones(15).astype(float),
                tensor_w=np.ones(20).astype(float),
                origin=[10., 10., -10]
            ),
            data=[
                omf.ScalarData(
                    name='Random Data',
                    location='cells',
                    array=np.random.rand(10, 15, 20).flatten()
                )
            ]
        )

        proj.elements = [pts, lin, surf, grid, vol]

        assert proj.validate()

        serial_file = os.path.sep.join([dirname, 'out.omf'])
        omf.OMFWriter(proj, serial_file)
        reader = omf.OMFReader(serial_file)
        new_proj = reader.get_project()

        assert new_proj.validate()
        assert str(new_proj.elements[3].textures[0].uid) == \
            str(proj.elements[3].textures[0].uid)
        del reader
        os.remove(serial_file)