class SparseVoxels(Drawable): """ 3D volumetric data. By default, the voxels are a grid inscribed in the -0.5 < x, y, z < 0.5 cube regardless of the passed voxel array shape (aspect ratio etc.). Different grid size, shape and rotation can be obtained using the model_matrix. Attributes: sparse_voxels: `array_like`. 2D array of `coords` in format [[x,y,z,v],[x,y,z,v]]. v = 0 means empty voxel, 1 and above refer to consecutive color_map entries. space_size: `array_like`. Width, Height, Length of space color_map: `array_like`. Flat array of `int` packed RGB colors (0xff0000 is red, 0xff is blue). model_matrix: `array_like`. 4x4 model transform matrix. wireframe: `bool`. Whether mesh should display as wireframe. opacity: `float`. Opacity of voxels. outlines: `bool`. Whether mesh should display with outlines. outlines_color: `int`. Packed RGB color of the resulting outlines (0xff0000 is red, 0xff is blue) """ type = Unicode(read_only=True).tag(sync=True) sparse_voxels = Array(dtype=np.uint16).tag(sync=True, **array_serialization) space_size = Array(dtype=np.uint32).tag(sync=True, **array_serialization) color_map = Array(dtype=np.uint32).tag(sync=True, **array_serialization) wireframe = Bool().tag(sync=True) outlines = Bool().tag(sync=True) outlines_color = Int(min=0, max=0xffffff).tag(sync=True) opacity = Float(min=EPSILON, max=1.0, default_value=1.0).tag(sync=True) model_matrix = Array(dtype=np.float32).tag(sync=True, **array_serialization) click_callback = None def __init__(self, **kwargs): super(SparseVoxels, self).__init__(**kwargs) self.set_trait('type', 'SparseVoxels') self.on_msg(self._handle_custom_msg) def _handle_custom_msg(self, content, buffers): if content.get('msg_type', '') == 'click_callback': if self.click_callback is not None: self.click_callback(content['coord']['x'], content['coord']['y'], content['coord']['z'])
class VoxelsIpyDW(Drawable): """ 3D volumetric data. By default, the voxels are a grid inscribed in the -0.5 < x, y, z < 0.5 cube regardless of the passed voxel array shape (aspect ratio etc.). Different grid size, shape and rotation can be obtained using the model_matrix. Attributes: voxels: `array_like`. 3D array of `int` in range (0, 255). 0 means empty voxel, 1 and above refer to consecutive color_map entries. color_map: `array_like`. Flat array of `int` packed RGB colors (0xff0000 is red, 0xff is blue). The color defined at index i is for voxel value (i+1), e.g.: color_map = [0xff, 0x00ff] voxels = [[[ 0, # empty voxel 1, # blue voxel 2 # red voxel ]]] model_matrix: `array_like`. 4x4 model transform matrix. wireframe: `bool`. Whether mesh should display as wireframe. outlines: `bool`. Whether mesh should display with outlines. outlines_color: `int`. Packed RGB color of the resulting outlines (0xff0000 is red, 0xff is blue) """ type = Unicode(read_only=True).tag(sync=True) voxels = DataUnion(default_value=[], dtype=np.uint8).tag(sync=True, **data_union_serialization) color_map = Array(dtype=np.float32).tag(sync=True, **array_serialization) wireframe = Bool().tag(sync=True) outlines = Bool().tag(sync=True) outlines_color = Int(min=0, max=0xffffff).tag(sync=True) click_callback = None model_matrix = Array(dtype=np.float32).tag(sync=True, **array_serialization) def __init__(self, **kwargs): super(VoxelsIpyDW, self).__init__(**kwargs) self.set_trait('type', 'Voxels') self.on_msg(self._handle_custom_msg) def _handle_custom_msg(self, content, buffers): if content.get('msg_type', '') == 'click_callback': if self.click_callback is not None: self.click_callback(content['coord']['x'], content['coord']['y'], content['coord']['z'])
class SparseVoxels(DrawableWithVoxelCallback): """ 3D volumetric data. By default, the voxels are a grid inscribed in the -0.5 < x, y, z < 0.5 cube regardless of the passed voxel array shape (aspect ratio etc.). Different grid size, shape and rotation can be obtained using the model_matrix. Attributes: sparse_voxels: `array_like`. 2D array of `coords` in format [[x,y,z,v],[x,y,z,v]]. v = 0 means empty voxel, 1 and above refer to consecutive color_map entries. space_size: `array_like`. Width, Height, Length of space color_map: `array_like`. Flat array of `int` packed RGB colors (0xff0000 is red, 0xff is blue). model_matrix: `array_like`. 4x4 model transform matrix. wireframe: `bool`. Whether mesh should display as wireframe. opacity: `float`. Opacity of voxels. outlines: `bool`. Whether mesh should display with outlines. outlines_color: `int`. Packed RGB color of the resulting outlines (0xff0000 is red, 0xff is blue) """ type = Unicode(read_only=True).tag(sync=True) sparse_voxels = Array(dtype=np.uint16).tag( sync=True, **array_serialization_wrap('sparse_voxels')).valid( validate_sparse_voxels) space_size = Array(dtype=np.uint32).tag( sync=True, **array_serialization_wrap('space_size')).valid(shape_validation(3)) color_map = Array(dtype=np.uint32).tag( sync=True, **array_serialization_wrap('color_map')) wireframe = Bool().tag(sync=True) outlines = Bool().tag(sync=True) outlines_color = Int(min=0, max=0xffffff).tag(sync=True) opacity = TimeSeries(Float(min=0.0, max=1.0, default_value=1.0)).tag(sync=True) model_matrix = TimeSeries(Array(dtype=np.float32)).tag( sync=True, **array_serialization_wrap('model_matrix')) def __init__(self, **kwargs): super(SparseVoxels, self).__init__(**kwargs) self.set_trait('type', 'SparseVoxels')
class Mesh(Widget): """A 3-D Mesh widget.""" _model_name = Unicode('MeshModel').tag(sync=True) _view_module = Unicode('odysis').tag(sync=True) _model_module = Unicode('odysis').tag(sync=True) _view_module_version = Unicode(odysis_version).tag(sync=True) _model_module_version = Unicode(odysis_version).tag(sync=True) # TODO: validate vertices/faces/tetras as being 1-D array, and validate dtype vertices = Array(default_value=array(FLOAT32)).tag(sync=True, **array_serialization) faces = Array(default_value=array(UINT32)).tag(sync=True, **array_serialization) tetras = Array(default_value=array(UINT32)).tag(sync=True, **array_serialization) data = List(Instance(Data), default_value=[]).tag(sync=True, **widget_serialization) bounding_box = List().tag(sync=True) @staticmethod def from_vtk(path): grid = load_vtk(path) grid.ComputeBounds() bounding_box = grid.GetBounds() return Mesh(vertices=get_ugrid_vertices(grid), faces=get_ugrid_faces(grid), tetras=get_ugrid_tetras(grid), data=_grid_data_to_data_widget(get_ugrid_data(grid)), bounding_box=bounding_box) def reload(self, path, reload_vertices=False, reload_faces=False, reload_data=True, reload_tetras=False): grid = load_vtk(path) with self.hold_sync(): if reload_vertices: self.vertices = get_ugrid_vertices(grid) if reload_faces: self.faces = get_ugrid_faces(grid) if reload_tetras: self.tetras = get_ugrid_tetras(grid) if reload_data: self.data = _grid_data_to_data_widget(get_ugrid_data(grid))
class Texture(DrawableWithCallback): """ A 2D image displayed as a texture. By default, the texture image is mapped into the square: -0.5 < x, y < 0.5, z = 1. If the size (scale, aspect ratio) or position should be different then the texture should be transformed using the model_matrix. Attributes: binary: `bytes`. Image data in a specific format. file_format: `str`. Format of the data, it should be the second part of MIME format of type 'image/', for example 'jpeg', 'png', 'gif', 'tiff'. attribute: `array_like`. Array of float attribute for the color mapping, coresponding to each pixels. color_map: `list`. A list of float quadruplets (attribute value, R, G, B), sorted by attribute value. The first quadruplet should have value 0.0, the last 1.0; R, G, B are RGB color components in the range 0.0 to 1.0. color_range: `list`. A pair [min_value, max_value], which determines the levels of color attribute mapped to 0 and 1 in the color map respectively. puv: `list`. A list of float triplets (x,y,z). The first triplet mean a position of left-bottom corner of texture. Second and third triplets means a base of coordinate system for texture. model_matrix: `array_like`. 4x4 model transform matrix. """ type = Unicode(read_only=True).tag(sync=True) binary = Bytes(allow_none=True).tag(sync=True) file_format = Unicode(allow_none=True).tag(sync=True) attribute = Array().tag(sync=True, **array_serialization_wrap('attribute')) puv = Array(dtype=np.float32).tag(sync=True, **array_serialization_wrap('puv')) color_map = Array(dtype=np.float32).tag( sync=True, **array_serialization_wrap('color_map')) color_range = ListOrArray(minlen=2, maxlen=2, empty_ok=True).tag(sync=True) model_matrix = TimeSeries(Array(dtype=np.float32)).tag( sync=True, **array_serialization_wrap('model_matrix')) def __init__(self, **kwargs): super(Texture, self).__init__(**kwargs) self.set_trait('type', 'Texture') def get_bounding_box(self): return get_bounding_box(self.model_matrix)
class CurveData(SceneData): name = "curve_data" data = Array() n_vertices = traitlets.CInt() @traitlets.default("vertex_array") def _default_vertex_array(self): va = VertexArray(name="vertices") return va def add_data(self, curve): # curve is a collection of ndarray of points assert curve.shape[0] > 1 # a curve needs at least 2 points assert curve.shape[1] == 3 # a curve needs at least 3 dimensions # add the singleton 4th dim data = np.ones((curve.shape[0], 4)) data[:, 0:3] = curve self.n_vertices = curve.shape[0] self.data = data self.vertex_array.attributes.append( VertexAttribute(name="model_vertex", data=data.astype("f4"))) self.vertex_array.indices = np.arange(0, self.n_vertices).astype("uint32") self.size = self.n_vertices
class CurveCollection(CurveData): name = "curve_collection" data = Array() n_vertices = traitlets.CInt() def add_curve(self, curve): # curve is a collection of ndarray of points assert curve.shape[0] > 1 # a curve needs at least 2 points assert curve.shape[1] == 3 # a curve needs at least 3 dimensions # double up the indices to use GL_LINES index_range = np.arange(0, curve.shape[0]) line_indices = np.column_stack([index_range, index_range]).ravel()[1:-1] data = curve[line_indices] data = np.column_stack([data, np.ones((data.shape[0], ))]) if self.data.shape: self.data = np.concatenate([self.data, data]) else: self.data = data def add_data(self): self.n_vertices = self.data.shape[0] self.vertex_array.attributes.append( VertexAttribute(name="model_vertex", data=self.data.astype("f4"))) self.vertex_array.indices = np.arange(0, self.n_vertices).astype("uint32") self.size = self.n_vertices
class Contour(bqplot.Mark): _view_name = Unicode('ContourView').tag(sync=True) _model_name = Unicode('ContourModel').tag(sync=True) _view_module = Unicode('bqplot-image-gl').tag(sync=True) _model_module = Unicode('bqplot-image-gl').tag(sync=True) _view_module_version = Unicode('^' + __version__).tag(sync=True) _model_module_version = Unicode('^' + __version__).tag(sync=True) image = Instance(ImageGL, allow_none=True).tag(sync=True, **widgets.widget_serialization) label_steps = Int(40).tag(sync=True) contour_lines = (List(List(Array(None, allow_none=True))).tag( sync=True, **double_list_array_serialization)) level = (Float() | List(Float())).tag(sync=True) color = widgets.Color(None, allow_none=True).tag(sync=True) scales_metadata = Dict({ 'x': { 'orientation': 'horizontal', 'dimension': 'x' }, 'y': { 'orientation': 'vertical', 'dimension': 'y' }, }).tag(sync=True)
class STL(Drawable): """ A STereoLitograpy 3D geometry. STL is a popular format introduced for 3D printing. There are two sub-formats - ASCII and binary. Attributes: text: `str`. STL data in text format (ASCII STL). binary: `bytes`. STL data in binary format (Binary STL). The `text` attribute should be set to None when using Binary STL. color: `int`. Packed RGB color of the resulting mesh (0xff0000 is red, 0xff is blue). model_matrix: `array_like`. 4x4 model transform matrix. wireframe: `bool`. Whether mesh should display as wireframe. flat_shading: `bool`. Whether mesh should display with flat shading. """ type = Unicode(read_only=True).tag(sync=True) text = AsciiStlData(allow_none=True, default_value=None).tag(sync=True) binary = BinaryStlData(allow_none=True, default_value=None).tag(sync=True) color = Int(min=0, max=0xffffff).tag(sync=True) wireframe = Bool().tag(sync=True) flat_shading = Bool().tag(sync=True) model_matrix = TimeSeries(Array(dtype=np.float32)).tag( sync=True, **array_serialization_wrap('model_matrix')) def __init__(self, **kwargs): super(STL, self).__init__(**kwargs) self.set_trait('type', 'STL')
class GaussianFilterSlider(widgets.FloatSlider): image_in = Array() image_out = Array() def __init__(self, description='Gaussian filter', min=0., max=5, **kwargs): super().__init__(description=description, min=min, max=max, **kwargs) def update_image(self, *args): self.image_out = self(self.image_in) @observe('image_in') def _observe_image_in(self, *args): self.update_image() def __call__(self, image): return gaussian_filter(image, sigma=float(self.value))
class Line(Drawable): """ A path (polyline) made up of line segments. Attributes: vertices: `array_like`. An array with (x, y, z) coordinates of segment endpoints. color: `int`. Packed RGB color of the lines (0xff0000 is red, 0xff is blue). width: `float`. The thickness of the lines. model_matrix: `array_like`. 4x4 model transform matrix. """ type = Unicode(default_value='Line', read_only=True).tag(sync=True) vertices = Array().tag(sync=True, **array_serialization) color = Int().tag(sync=True) width = Float().tag(sync=True) model_matrix = Array().tag(sync=True, **array_serialization)
class TransferFunction(widgets.DOMWidget): _view_name = Unicode('TransferFunctionView').tag(sync=True) _view_module = Unicode('ipyvolume').tag(sync=True) style = Unicode("height: 32px; width: 100%;").tag(sync=True) rgba = Array(default_value=None, allow_none=True).tag(sync=True, **array_serialization) _view_module_version = Unicode(semver_range_frontend).tag(sync=True) _model_module_version = Unicode(semver_range_frontend).tag(sync=True)
class PlainBufferGeometry(Geometry): _view_name = Unicode('PlainBufferGeometryView').tag(sync=True) _model_name = Unicode('PlainBufferGeometryModel').tag(sync=True) vertices = Array(dtype='float32').tag(sync=True, **array_serialization).valid( shape_constraints(None, 3)) faces = Array(dtype='uint32', default_value=np.empty(shape=(0, 3), dtype='uint32')).tag( sync=True, **array_serialization).valid(shape_constraints(None, 3)) colors = Array(dtype='float32', default_value=np.empty(shape=(0, 3), dtype='float32'), help="Vertex colors").tag(sync=True, **array_serialization).valid( shape_constraints(None, 3))
class IndexSelector(OneDSelector): """Index selector interaction. This 1-D selector interaction uses the mouse x-cooridnate to select the corresponding point in terms of the selector scale. Index Selector has two modes: 1. default mode: The mouse controls the x-position of the selector. 2. frozen mode: In this mode, the selector is frozen at a point and does not respond to mouse events. A single click switches between the two modes. Attributes ---------- selected: numpy.ndarray A single element array containing the point corresponding the x-position of the mouse. This attribute is updated as you move the mouse along the x-direction on the figure. color: Color or None (default: None) Color of the line representing the index selector. line_width: nonnegative integer (default: 0) Width of the line represetning the index selector. """ selected = Array(None, allow_none=True).tag(sync=True, **array_serialization) line_width = Int(2).tag(sync=True) color = Color(None, allow_none=True).tag(sync=True) _view_name = Unicode('IndexSelector').tag(sync=True) _model_name = Unicode('IndexSelectorModel').tag(sync=True)
class Component(_GanyWidgetBase): """A data component widget.""" _model_name = Unicode('ComponentModel').tag(sync=True) name = Unicode().tag(sync=True) array = Union((Instance(Widget), Array())).tag(sync=True, **data_array_serialization) min = CFloat(allow_none=True, default_value=None) max = CFloat(allow_none=True, default_value=None) def __init__(self, name, array, **kwargs): """Create a new Component instance given its name and array.""" super(Component, self).__init__(name=name, array=array, **kwargs) if self.min is None: self.min = np.min( self.array) if not isinstance(self.array, Widget) else np.min( self.array.array) if self.max is None: self.max = np.max( self.array) if not isinstance(self.array, Widget) else np.max( self.array.array)
class Surface(DrawableWithCallback): """ Surface plot of a 2D function z = f(x, y). The default domain of the scalar field is -0.5 < x, y < 0.5. If the domain should be different, the bounding box needs to be transformed using the model_matrix. Attributes: heights: `array_like`. 2D scalar field of Z values. color: `int`. Packed RGB color of the resulting mesh (0xff0000 is red, 0xff is blue). wireframe: `bool`. Whether mesh should display as wireframe. flat_shading: `bool`. Whether mesh should display with flat shading. attribute: `array_like`. Array of float attribute for the color mapping, coresponding to each vertex. color_map: `list`. A list of float quadruplets (attribute value, R, G, B), sorted by attribute value. The first quadruplet should have value 0.0, the last 1.0; R, G, B are RGB color components in the range 0.0 to 1.0. color_range: `list`. A pair [min_value, max_value], which determines the levels of color attribute mapped to 0 and 1 in the color map respectively. model_matrix: `array_like`. 4x4 model transform matrix. """ type = Unicode(read_only=True).tag(sync=True) heights = Array(dtype=np.float32).tag( sync=True, **array_serialization_wrap('heights')) color = Int(min=0, max=0xffffff).tag(sync=True) wireframe = Bool().tag(sync=True) flat_shading = Bool().tag(sync=True) attribute = TimeSeries(Array(dtype=np.float32)).tag( sync=True, **array_serialization_wrap('attribute')) color_map = TimeSeries(Array(dtype=np.float32)).tag( sync=True, **array_serialization_wrap('color_map')) color_range = TimeSeries(ListOrArray(minlen=2, maxlen=2, empty_ok=True)).tag(sync=True) model_matrix = TimeSeries(Array(dtype=np.float32)).tag( sync=True, **array_serialization_wrap('model_matrix')) def __init__(self, **kwargs): super(Surface, self).__init__(**kwargs) self.set_trait('type', 'Surface')
class Surface(Drawable): """ Surface plot of a 2D function z = f(x, y). The default domain of the scalar field is -0.5 < x, y < 0.5. If the domain should be different, the bounding box needs to be transformed using the model_matrix. Attributes: heights: `array_like`. 2D scalar field of Z values. color: `int`. Packed RGB color of the resulting mesh (0xff0000 is red, 0xff is blue). model_matrix: `array_like`. 4x4 model transform matrix. """ type = Unicode(default_value='Surface', read_only=True).tag(sync=True) heights = Array().tag(sync=True, **array_serialization) color = Int().tag(sync=True) model_matrix = Array().tag(sync=True, **array_serialization)
class Mesh(Drawable): """ A 3D triangles mesh. Attributes: vertices: `array_like`. Array of triangle vertices: float (x, y, z) coordinate triplets. indices: `array_like`. Array of vertex indices: int triplets of indices from vertices array. color: `int`. Packed RGB color of the mesh (0xff0000 is red, 0xff is blue) when not using color maps. attribute: `array_like`. Array of float attribute for the color mapping, coresponding to each vertex. color_map: `list`. A list of float quadruplets (attribute value, R, G, B), sorted by attribute value. The first quadruplet should have value 0.0, the last 1.0; R, G, B are RGB color components in the range 0.0 to 1.0. color_range: `list`. A pair [min_value, max_value], which determines the levels of color attribute mapped to 0 and 1 in the color map respectively. wireframe: `bool`. Whether mesh should display as wireframe. flat_shading: `bool`. Whether mesh should display with flat shading. opacity: `float`. Opacity of mesh. model_matrix: `array_like`. 4x4 model transform matrix. """ type = Unicode(read_only=True).tag(sync=True) vertices = TimeSeries(Array(dtype=np.float32)).tag(sync=True, **array_serialization_wrap('vertices')) indices = TimeSeries(Array(dtype=np.uint32)).tag(sync=True, **array_serialization_wrap('indices')) color = TimeSeries(Int(min=0, max=0xffffff)).tag(sync=True) attribute = TimeSeries(Array(dtype=np.float32)).tag(sync=True, **array_serialization_wrap('attribute')) color_map = TimeSeries(Array(dtype=np.float32)).tag(sync=True, **array_serialization_wrap('color_map')) color_range = TimeSeries(ListOrArray(minlen=2, maxlen=2, empty_ok=True)).tag(sync=True) wireframe = TimeSeries(Bool()).tag(sync=True) flat_shading = TimeSeries(Bool()).tag(sync=True) opacity = Float(min=0.0, max=1.0, default_value=1.0).tag(sync=True) model_matrix = TimeSeries(Array(dtype=np.float32)).tag(sync=True, **array_serialization_wrap('model_matrix')) def __init__(self, **kwargs): super(Mesh, self).__init__(**kwargs) self.set_trait('type', 'Mesh')
class VectorField(Drawable): """ A dense 3D or 2D vector field. By default, the origins of the vectors are assumed to be a grid inscribed in the -0.5 < x, y, z < 0.5 cube or -0.5 < x, y < 0.5 square, regardless of the passed vector field shape (aspect ratio etc.). Different grid size, shape and rotation can be obtained using the model_matrix. The color of the vectors is a gradient from origin_color to head_color. Heads, when used, have uniform head_color. For sparse (i.e. not forming a grid) 3D vectors, use the `Vectors` drawable. Attributes: vectors: `array_like`. Vector field of shape (L, H, W, 3) for 3D fields or (H, W, 2) for 2D fields. colors: `array_like`. Twice the length of vectors array of int: packed RGB colors (0xff0000 is red, 0xff is blue). The array has consecutive pairs (origin_color, head_color) for vectors in row-major order. origin_color: `int`. Packed RGB color of the origins (0xff0000 is red, 0xff is blue) when `colors` is empty. head_color: `int`. Packed RGB color of the vector heads (0xff0000 is red, 0xff is blue) when `colors` is empty. use_head: `bool`. Whether vectors should display an arrow head. head_size: `float`. The size of the arrow heads. scale: `float`. Scale factor for the vector lengths, for artificially scaling the vectors in place. model_matrix: `array_like`. 4x4 model transform matrix. """ type = Unicode(default_value='VectorField', read_only=True).tag(sync=True) vectors = Array().tag(sync=True, **array_serialization) colors = Array().tag(sync=True, **array_serialization) origin_color = Int().tag(sync=True) head_color = Int().tag(sync=True) use_head = Bool().tag(sync=True) head_size = Float().tag(sync=True) scale = Float().tag(sync=True) model_matrix = Array().tag(sync=True, **array_serialization) @validate('vectors') def _validate_vectors(self, proposal): shape = proposal['value'].shape if len(shape) not in (3, 4) or len(shape) != shape[-1] + 1: raise TraitError( 'Vector field has invalid shape: {}, ' 'expected (L, H, W, 3) for a 3D or (H, W, 2) for a 2D field'. format(shape)) return np.array(proposal['value'], np.float32)
class RawCanvas(widgets.DOMWidget): """An example widget.""" _view_name = Unicode('RawCanvasView').tag(sync=True) _model_name = Unicode('RawCanvasModel').tag(sync=True) _view_module = Unicode('fastcanvas').tag(sync=True) _model_module = Unicode('fastcanvas').tag(sync=True) _view_module_version = Unicode('^0.1.0').tag(sync=True) _model_module_version = Unicode('^0.1.0').tag(sync=True) data = Array(default_value=None, allow_none=True).tag(sync=True, **ndarray_serialization)
class Line(Drawable): """ A path (polyline) made up of line segments. Attributes: vertices: `array_like`. An array with (x, y, z) coordinates of segment endpoints. colors: `array_like`. Same-length array of (`int`) packed RGB color of the points (0xff0000 is red, 0xff is blue). color: `int`. Packed RGB color of the lines (0xff0000 is red, 0xff is blue) when `colors` is empty. attribute: `array_like`. Array of float attribute for the color mapping, coresponding to each vertex. color_map: `list`. A list of float quadruplets (attribute value, R, G, B), sorted by attribute value. The first quadruplet should have value 0.0, the last 1.0; R, G, B are RGB color components in the range 0.0 to 1.0. color_range: `list`. A pair [min_value, max_value], which determines the levels of color attribute mapped to 0 and 1 in the color map respectively. width: `float`. The thickness of the lines. shader: `str`. Display style (name of the shader used) of the lines. Legal values are: `simple`: simple lines, `mesh`: high precision triangle mesh of segments (high quality and GPU load). radial_segments: 'int': Number of segmented faces around the circumference of the tube model_matrix: `array_like`. 4x4 model transform matrix. """ type = Unicode(default_value='Line', read_only=True).tag(sync=True) vertices = Array().tag(sync=True, **array_serialization) colors = Array().tag(sync=True, **array_serialization) color = Int().tag(sync=True) width = Float().tag(sync=True) attribute = Array().tag(sync=True, **array_serialization) color_map = Array().tag(sync=True, **array_serialization) color_range = ListOrArray(minlen=2, maxlen=2, empty_ok=True).tag(sync=True) shader = Unicode().tag(sync=True) radial_segments = Int().tag(sync=True) model_matrix = Array().tag(sync=True, **array_serialization) @validate('colors') def _validate_colors(self, proposal): required = self.vertices.size // 3 # (x, y, z) triplet per 1 color actual = proposal['value'].size if actual != 0 and required != actual: raise TraitError('colors has wrong size: %s (%s required)' % (actual, required)) return proposal['value']
class MarchingCubes(DrawableWithCallback): """ An isosurface in a scalar field obtained through Marching Cubes algorithm. The default domain of the scalar field is -0.5 < x, y, z < 0.5. If the domain should be different, the bounding box needs to be transformed using the model_matrix. Attributes: scalar_field: `array_like`. A 3D scalar field of values. level: `float`. Value at the computed isosurface. color: `int`. Packed RGB color of the isosurface (0xff0000 is red, 0xff is blue). wireframe: `bool`. Whether mesh should display as wireframe. flat_shading: `bool`. Whether mesh should display with flat shading. opacity: `float`. Opacity of mesh. model_matrix: `array_like`. 4x4 model transform matrix. """ type = Unicode(read_only=True).tag(sync=True) scalar_field = Array(dtype=np.float32).tag( sync=True, **array_serialization_wrap('scalar_field')) level = Float().tag(sync=True) color = Int(min=0, max=0xffffff).tag(sync=True) wireframe = Bool().tag(sync=True) flat_shading = Bool().tag(sync=True) opacity = TimeSeries(Float(min=0.0, max=1.0, default_value=1.0)).tag(sync=True) model_matrix = TimeSeries(Array(dtype=np.float32)).tag( sync=True, **array_serialization_wrap('model_matrix')) def get_bounding_box(self): return get_bounding_box(self.model_matrix) def __init__(self, **kwargs): super(MarchingCubes, self).__init__(**kwargs) self.set_trait('type', 'MarchingCubes')
class ThreeCircle(AgentType, States, BodyType, TranslationalMotion, RotationalMotion): r"""Three-circle agent type .. tikz:: Three circle agent :include: ../tikz/three_circle_agent.tex **Three-circle** agents are modelled as three disks representing the torso and two shoulders of an average human. Torso is a disk with radius :math:`r_t > 0` from the center of mass :math:`\mathbf{x}`. Two shoulders are disks with radius :math:`r_s` located at along the tangents at distance :math:`r_{ts}` from the center of mass :math:`\mathbf{x} \pm r_{ts} \mathbf{\hat{e}_t}`, where :math:`\mathbf{\hat{e}_t} = [\sin(\varphi), -\cos(\varphi)]`. Three circle type has orientation of :math:`\varphi`. Model was proposed *Crowd dynamics discrete element multi-circle model* [Langston2006]_ and has been used for example in FDS+EVAC [Korhonen2008b]_. %(table_of_traits)s """ position_ls = Array(default_value=(0, 0), dtype=np.float64).valid(shape_validator(2)) position_rs = Array(default_value=(0, 0), dtype=np.float64).valid(shape_validator(2)) @default('position_ls') def _default_position_ls(self): return self.position - self.r_ts * rotate270( unit_vector(self.orientation)) @default('position_rs') def _default_position_rs(self): return self.position + self.r_ts * rotate270( unit_vector(self.orientation)) def overlapping(self, others): return overlapping_three_circles( others, (self.position, self.position_ls, self.position_rs), (self.r_t, self.r_s, self.r_s)) def overlapping_obstacles(self, obstacles) -> bool: return overlapping_three_circle_line(np.array(self), obstacles)
class STL(Drawable): """ A STereoLitograpy 3D geometry. STL is a popular format introduced for 3D printing. There are two sub-formats - ASCII and binary. Attributes: text: `str`. STL data in text format (ASCII STL). binary: `bytes`. STL data in binary format (Binary STL). The `text` attribute should be set to None when using Binary STL. color: `int`. Packed RGB color of the resulting mesh (0xff0000 is red, 0xff is blue). model_matrix: `array_like`. 4x4 model transform matrix. """ type = Unicode(default_value='STL', read_only=True).tag(sync=True) text = Unicode(allow_none=True).tag(sync=True) binary = Array().tag(sync=True, **array_serialization) color = Int().tag(sync=True) model_matrix = Array().tag(sync=True, **array_serialization)
class MarchingCubes(Drawable): """ An isosurface in a scalar field obtained through Marching Cubes algorithm. The default domain of the scalar field is -0.5 < x, y, z < 0.5. If the domain should be different, the bounding box needs to be transformed using the model_matrix. Attributes: scalar_field: `array_like`. A 3D scalar field of values. level: `float`. Value at the computed isosurface. color: `int`. Packed RGB color of the isosurface (0xff0000 is red, 0xff is blue). model_matrix: `array_like`. 4x4 model transform matrix. """ type = Unicode(default_value='MarchingCubes', read_only=True).tag(sync=True) scalar_field = Array().tag(sync=True, **array_serialization) level = Float().tag(sync=True) color = Int().tag(sync=True) model_matrix = Array().tag(sync=True, **array_serialization)
class Volume(Drawable): """ 3D volumetric data. By default, the volume are a grid inscribed in the -0.5 < x, y, z < 0.5 cube regardless of the passed voxel array shape (aspect ratio etc.). Attributes: volume: `array_like`. 3D array of `float`. color_map: `array_like`. Flat array of `int` packed RGB colors (0xff0000 is red, 0xff is blue). The color defined at index i is for voxel value (i+1), e.g.: color_map = [0xff, 0x00ff] voxels = [[[ 0, # empty voxel 1, # blue voxel 2 # red voxel ]]] color_range: `list`. A pair [min_value, max_value], which determines the levels of color attribute mapped to 0 and 1 in the color map respectively. samples: `float` number of iteration per 1 unit of space model_matrix: `array_like`. 4x4 model transform matrix. """ type = Unicode(read_only=True).tag(sync=True) volume = Array(dtype=np.float32).tag(sync=True, **array_serialization) color_map = Array(dtype=np.float32).tag(sync=True, **array_serialization) color_range = ListOrArray(minlen=2, maxlen=2, empty_ok=True).tag(sync=True) samples = Float().tag(sync=True) model_matrix = Array(dtype=np.float32).tag(sync=True, **array_serialization) def __init__(self, **kwargs): super(Volume, self).__init__(**kwargs) self.set_trait('type', 'Volume') def _handle_custom_msg(self, content, buffers): if content.get('msg_type', '') == 'click_callback': if self.click_callback is not None: self.click_callback(content['coord']['x'], content['coord']['y'], content['coord']['z'])
class Mesh(widgets.DOMWidget): _view_name = Unicode('MeshView').tag(sync=True) _view_module = Unicode('ipyvolume').tag(sync=True) _model_name = Unicode('MeshModel').tag(sync=True) _model_module = Unicode('ipyvolume').tag(sync=True) _view_module_version = Unicode(semver_range_frontend).tag(sync=True) _model_module_version = Unicode(semver_range_frontend).tag(sync=True) x = Array(default_value=None).tag(sync=True, **array_sequence_serialization) y = Array(default_value=None).tag(sync=True, **array_sequence_serialization) z = Array(default_value=None).tag(sync=True, **array_sequence_serialization) u = Array(default_value=None, allow_none=True).tag(sync=True, **array_sequence_serialization) v = Array(default_value=None, allow_none=True).tag(sync=True, **array_sequence_serialization) triangles = Array(default_value=None, allow_none=True).tag(sync=True, **array_serialization) lines = Array(default_value=None, allow_none=True).tag(sync=True, **array_serialization) texture = traitlets.Union([ traitlets.Instance(ipywebrtc.MediaStream), Unicode(), traitlets.List(Unicode, [], allow_none=True), Image(default_value=None, allow_none=True), traitlets.List(Image(default_value=None, allow_none=True)) ]).tag(sync=True, **texture_serialization) # selected = Array(default_value=None, allow_none=True).tag(sync=True, **array_sequence_serialization) sequence_index = Integer(default_value=0).tag(sync=True) color = Array(default_value="red", allow_none=True).tag(sync=True, **color_serialization) # color_selected = traitlets.Union([Array(default_value=None, allow_none=True).tag(sync=True, **color_serialization), # Unicode().tag(sync=True)], # default_value="green").tag(sync=True) # geo = traitlets.Unicode('diamond').tag(sync=True) visible = traitlets.CBool(default_value=True).tag(sync=True) material = traitlets.Instance(pythreejs.ShaderMaterial).tag( sync=True, **ipywidgets.widget_serialization) @traitlets.default('material') def _default_material(self): return pythreejs.ShaderMaterial(side=pythreejs.Side.DoubleSide) line_material = traitlets.Instance(pythreejs.ShaderMaterial).tag( sync=True, **ipywidgets.widget_serialization) @traitlets.default('line_material') def _default_line_material(self): return pythreejs.ShaderMaterial()
class Vectors(Drawable): """ 3D vectors. The color of the vectors is a gradient from origin_color to head_color. Heads, when used, have uniform head_color. For dense (i.e. forming a grid) 3D or 2D vectors, use the `VectorField` drawable. Attributes: vectors: `array_like`. The vectors as (dx, dy, dz) float triples. origins: `array_like`. Same-size array of (x, y, z) coordinates of vector origins. colors: `array_like`. Twice the length of vectors array of int: packed RGB colors (0xff0000 is red, 0xff is blue). The array has consecutive pairs (origin_color, head_color) for vectors in row-major order. origin_color: `int`. Packed RGB color of the origins (0xff0000 is red, 0xff is blue), default: same as color. head_color: `int`. Packed RGB color of the vector heads (0xff0000 is red, 0xff is blue), default: same as color. use_head: `bool`. Whether vectors should display an arrow head. head_size: `float`. The size of the arrow heads. labels: `list` of `str`. Captions to display next to the vectors. label_size: `float`. Label font size in 'em' HTML units. line_width: `float`. Width of the vector segments. model_matrix: `array_like`. 4x4 model transform matrix. """ type = Unicode(read_only=True).tag(sync=True) origins = Array(dtype=np.float32).tag(sync=True, **array_serialization) vectors = Array(dtype=np.float32).tag(sync=True, **array_serialization) colors = Array(dtype=np.uint32).tag(sync=True, **array_serialization) origin_color = Int(min=0, max=0xffffff).tag(sync=True) head_color = Int(min=0, max=0xffffff).tag(sync=True) use_head = Bool().tag(sync=True) head_size = Float(min=EPSILON, default_value=1.0).tag(sync=True) labels = List().tag(sync=True) label_size = Float(min=EPSILON, default_value=1.0).tag(sync=True) line_width = Float(min=EPSILON, default_value=0.01).tag(sync=True) model_matrix = Array(dtype=np.float32).tag(sync=True, **array_serialization) def __init__(self, **kwargs): super(Vectors, self).__init__(**kwargs) self.set_trait('type', 'Vectors')
class Mesh(widgets.Widget): _view_name = Unicode('MeshView').tag(sync=True) _view_module = Unicode('ipyvolume').tag(sync=True) _model_name = Unicode('MeshModel').tag(sync=True) _model_module = Unicode('ipyvolume').tag(sync=True) _view_module_version = Unicode(semver_range_frontend).tag(sync=True) _model_module_version = Unicode(semver_range_frontend).tag(sync=True) x = Array(default_value=None).tag(sync=True, **array_sequence_serialization) y = Array(default_value=None).tag(sync=True, **array_sequence_serialization) z = Array(default_value=None).tag(sync=True, **array_sequence_serialization) u = Array(default_value=None, allow_none=True).tag(sync=True, **array_sequence_serialization) v = Array(default_value=None, allow_none=True).tag(sync=True, **array_sequence_serialization) triangles = Array(default_value=None, allow_none=True).tag(sync=True, **array_serialization) lines = Array(default_value=None, allow_none=True).tag(sync=True, **array_serialization) texture = traitlets.Union([ traitlets.Instance(ipywebrtc.MediaStream), Unicode(), traitlets.List(Unicode, [], allow_none=True), Image(default_value=None, allow_none=True), traitlets.List(Image(default_value=None, allow_none=True)), ]).tag(sync=True, **texture_serialization) sequence_index = Integer(default_value=0).tag(sync=True) color = Array(default_value="red", allow_none=True).tag(sync=True, **color_serialization) visible = traitlets.CBool(default_value=True).tag(sync=True) material = traitlets.Instance( pythreejs.ShaderMaterial, help='A :any:`pythreejs.ShaderMaterial` that is used for the mesh' ).tag(sync=True, **widgets.widget_serialization) @traitlets.default('material') def _default_material(self): return pythreejs.ShaderMaterial(side=pythreejs.enums.Side.DoubleSide) line_material = traitlets.Instance( pythreejs.ShaderMaterial, help= 'A :any:`pythreejs.ShaderMaterial` that is used for the lines/wireframe' ).tag(sync=True, **widgets.widget_serialization) @traitlets.default('line_material') def _default_line_material(self): return pythreejs.ShaderMaterial()
class PlainGeometry(Geometry): _view_name = Unicode('PlainGeometryView').tag(sync=True) _model_name = Unicode('PlainGeometryModel').tag(sync=True) vertices = Array(dtype='float32').tag(sync=True, **array_serialization).valid( shape_constraints(None, 3)) faces = Array(dtype='uint32', default_value=np.empty(shape=(0, 3), dtype='uint32')).tag( sync=True, **array_serialization).valid(shape_constraints(None, 3)) # list of [[v1_r,v1_g,v1_b], [v2_r,v2_g,v2_b], [v3_r,v3_g,v3_b]] for each face faceColors = Array( dtype='float32', default_value=np.empty(shape=(0, 3, 3), dtype='float32')).tag( sync=True, **array_serialization).valid(shape_constraints(None, 3, 3)) colors = List(Color).tag(sync=True) faceNormals = Tuple().tag(sync=True)