コード例 #1
0
 def to_omf(self):
     self.validate()
     omf_grid_surface = omf.SurfaceElement(
         name=self.name or '',
         description=self.description or '',
         geometry=omf.SurfaceGridGeometry(
             origin=self.origin,
             tensor_u=self.tensor_u,
             tensor_v=self.tensor_v,
             axis_u=self.axis_u,
             axis_v=self.axis_v,
         ),
         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,
     )
     if self.offset_w is not None:
         omf_grid_surface.offset_w = self.offset_w.array
     return omf_grid_surface
コード例 #2
0
def test_texture():
    try:
        dirname, _ = os.path.split(os.path.abspath(__file__))
        png_file = os.path.sep.join(dirname.split(os.path.sep) + ['temp.png'])
        s = ['110010010011', '101011010100', '110010110101', '100010010011']
        s = [[int(v) for v in val] for val in s]
        f = open(png_file, 'wb')
        w = png.Writer(len(s[0]), len(s), greyscale=True, bitdepth=16)
        w.write(f, s)
        f.close()

        proj = omf.Project()

        surf = omf.SurfaceElement(
            geometry=omf.SurfaceGridGeometry(
                tensor_u=[1., 1., 1., 1., 1.],
                tensor_v=[1., 1., 1., 1., 1.],
            ),
            textures=[
                omf.ImageTexture(
                    origin=[0., 0, 0],
                    axis_u=[5., 0, 0],
                    axis_v=[0., 5, 0],
                    image=png_file,
                )
            ],
        )
        proj.elements = [surf]
        proj.validate()
        view = get_view_from_proj(proj)
        view.validate()
        assert len(view.contents) == 3

    finally:
        os.remove(png_file)
コード例 #3
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
コード例 #4
0
def test_data():
    arr = [float(val) for val in range(25)]
    arr_int = [int(val % 4) for val in range(25)]

    proj = omf.Project()

    surf = omf.SurfaceElement(
        geometry=omf.SurfaceGridGeometry(
            tensor_u=[1., 1., 1., 1., 1.],
            tensor_v=[1., 1., 1., 1., 1.],
        ),
        data=[
            omf.ScalarData(name='my data',
                           description='my desc',
                           location='faces',
                           array=arr,
                           colormap=omf.ScalarColormap(
                               gradient=[
                                   'red',
                                   'blue',
                                   'black',
                                   'orange',
                               ] * 32,
                               limits=[min(arr), max(arr)],
                           )),
            omf.MappedData(
                name='my data',
                description='my desc',
                location='faces',
                array=arr_int,
                legends=[
                    omf.Legend(values=[
                        'yellow',
                        'black',
                        'brown',
                        'green',
                    ], ),
                    omf.Legend(values=[
                        'yellow!',
                        'black!!',
                        'brown!!!',
                        'green!!!!',
                    ], ),
                ],
            )
        ],
    )
    proj.elements = [surf]
    proj.validate()
    view = get_view_from_proj(proj)
    view.validate()
    assert len(view.contents) == 9
コード例 #5
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]
コード例 #6
0
 def _to_omf(self):
     import omf
     element = omf.SurfaceElement(
         name=self.title or '',
         description=self.description or '',
         geometry=self.mesh._to_omf(),
         color=self.opts.color or 'random',
         data=[],
         textures=[tex._to_omf() for tex in self.textures])
     for data in self.data:
         if data.location == 'CC':
             location = 'faces'
         else:
             location = 'vertices'
         omf_data = data.data._to_omf()
         omf_data.location = location
         element.data.append(omf_data)
     return element
コード例 #7
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
コード例 #8
0
ファイル: element_test.py プロジェクト: kthnyt/omfvista
                                 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.],
                                     axis_u=[1., 0, 0],
                                     axis_v=[0, 0, 1.],
                                     offset_w=np.random.rand(11,
                                                             16).flatten()),
コード例 #9
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)