def _ReadUpFront(self): # Read all elements reader = omf.OMFReader(self.GetFileName()) self.__project = reader.get_project() self.__names = [e.name for e in self.__project.elements] for n in self.__names: self._dataselection.AddArray(n) self.NeedToRead(flag=False) return 1
def _read_up_front(self): """Internal functiona to read all data at the start""" # Read all elements reader = omf.OMFReader(self.get_file_name()) self.__project = reader.get_project() self.__names = [e.name for e in self.__project.elements] for n in self.__names: self._dataselection.AddArray(n) self.need_to_read(flag=False) return 1
def load_project(filename): """Loads an OMF project file into a :class:`pyvista.MultiBlock` dataset""" reader = omf.OMFReader(filename) project = reader.get_project() return project_to_vtk(project)
import omf ############################################################################### surfaces = omfvista.load_project(gdc19.get_project_path('surfaces.omf')) topo = surfaces['land_surface'] ############################################################################### # Decimate Topography Surface dec = topo.extract_geometry().decimate(0.99, inplace=False) dec.plot(notebook=True, show_edges=True, color=True) ############################################################################### # Re-do the texture mapping reader = omf.OMFReader(gdc19.get_project_path('surfaces.omf')) project = reader.get_project() # Assumes 'land_surface' is at index 0 surf = project.elements[0] tex = surf.textures[0] print(tex.name) og = tex.origin pu = tex.axis_u pv = tex.axis_v dec.texture_map_to_plane(origin=og, point_u=og + pu, point_v=og + pv, inplace=True, name='geo_aer')
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)
def load_topo(): proj = omf.OMFReader(gdc19.get_omf_project_filename()).get_project() for el in proj.elements: if el.name == 'land_surface': return omfvista.wrap(el) raise RuntimeError('Topo is not in project file. Some one messed up.')