def test_lines(subtype, options_class): proj = omf.Project(origin=[5., 5, 5]) lines = omf.LineSetElement( name='my elem', description='my desc', geometry=omf.LineSetGeometry( vertices=[[i / 3, i / 4, i / 5] for i in range(10)], segments=[[i, i + 1] for i in range(9)], origin=[5., 5, 5], ), subtype=subtype, color='red', ) proj.elements = [lines] proj.validate() view = get_view_from_proj(proj) view.validate() assert len(view.contents) == 3 lineset = find(view, spatial.ElementLineSet) defaults = lineset.defaults.serialize() assert defaults['__class__'] == options_class assert defaults['color']['value'] == '#FF0000' assert list(lineset.vertices.array[0]) == [10., 10, 10] assert lineset.name == 'my elem' assert lineset.description == 'my desc'
def _to_omf(self): import omf from omf.data import Int2Array geometry = omf.LineSetGeometry( vertices=omf.Vector3Array(self.vertices, ), segments=Int2Array(self.segments, ), ) return geometry
def build_geometry(self): """ build an omf.LineSetElement geometry of the borehole Returns -------- geometry : omf.lineset.LineSetGeometry Contains spatial information of a line set """ vertices, segments = [], [] for i in self.intervals: if i.top not in vertices: if hasattr(i.top, 'x') and hasattr(i.top, 'y'): x = i.top.x y = i.top.y else: x = self.x_collar y = self.y_collar vertices.append([x, y, -i.top.z]) top = len(vertices) - 1 else: top = vertices.index(i.top) if i.base not in vertices: if hasattr(i.base, 'x') and hasattr(i.base, 'y'): x = i.base.x y = i.base.y else: x = self.x_collar y = self.y_collar vertices.append([x, y, -i.base.z]) base = len(vertices) - 1 else: base = vertices.index(i.base) segments.append([top, base]) vertices = np.array(vertices) self.geometry = omf.LineSetElement( name=self.name, geometry=omf.LineSetGeometry(vertices=vertices, segments=segments), data=[ omf.MappedData(name='component', description='test', array=omf.ScalarArray( self.get_components_indices()), legends=[self.omf_legend], location='segments') ]) print("Borehole geometry created successfully !") return self.geometry
def to_omf(self): self.validate() omf_line_set = omf.LineSetElement( name=self.name or '', description=self.description or '', geometry=omf.LineSetGeometry( vertices=self.vertices.array, segments=self.segments.array, ), data=[attr.to_omf(cell_location='segments') for attr in self.data], color=self.defaults.color.value, ) return omf_line_set
def polygon_to_omf(polygon, topo_points, description='Line set polygon', name='polygon'): """Converts a polygon shape to an OMF.LineSetElement object. This assumes the points are ordered. """ pts = np.array(polygon.points) pts = np.c_[pts, np.zeros(pts.shape[0])] pts = _fix_to_topography(topo_points, pts) partial = np.arange(0, pts.shape[0], dtype=int) segments = np.c_[partial, np.roll(partial, -1)] element = omf.LineSetElement( name=name, description=description, subtype='line', geometry=omf.LineSetGeometry( vertices=pts, segments=segments, ) ) return element
# origin=[0, 0, 0], # axis_u=[1, 0, 0], # axis_v=[0, 1, 0] # ), # omf.ImageTexture( # name='test image', # image='test_image.png', # origin=[0, 0, 0], # axis_u=[1, 0, 0], # axis_v=[0, 0, 1] # ) # ], color='green') LINESET = 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') SURFACE = omf.SurfaceElement(name='trisurf', geometry=omf.SurfaceGeometry( vertices=np.random.rand(100, 3), triangles=np.floor(
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)