Esempio n. 1
0
    def __init__(self, viewer, parent=None, order=0):

        self._viewer = viewer
        self._interaction_box = viewer.overlays.interaction_box
        self.node = Compound([Line(), Markers(), Markers()], parent=parent)
        self.node.order = order
        self._on_interaction_box_change()
        self._interaction_box.events.points.connect(
            self._on_interaction_box_change)
        self._interaction_box.events.show.connect(
            self._on_interaction_box_change)
        self._interaction_box.events.show_handle.connect(
            self._on_interaction_box_change)
        self._interaction_box.events.show_vertices.connect(
            self._on_interaction_box_change)
        self._interaction_box.events.selected_vertex.connect(
            self._on_interaction_box_change)
        self._interaction_box.events.transform.connect(
            self._on_interaction_box_change)
        self._highlight_width = 1.5

        self._vertex_size = 10
        self._rotation_handle_length = 20
        self._highlight_color = (0, 0.6, 1)
        self.square_marker_node.symbol = 'square'
        self.square_marker_node.scaling = False
        self.round_marker_node.symbol = 'disc'
        self.round_marker_node.scaling = False
    def _on_display_change(self):
        parent = self.node.parent
        self.node.transforms = ChainTransform()
        self.node.parent = None

        if self.layer.dims.ndisplay == 2:
            self.node = Compound([Line(), Markers(), Markers()])
        else:
            self.node = Markers()

        self.node.parent = parent
        self.layer._update_dims()
        self.layer._set_view_slice()
        self.reset()
Esempio n. 3
0
    def create_marker(self, id, pos, name):
        marker = Markers(parent=self.view.scene)
        marker.transform = STTransform(translate=(0, 0, -10))
        marker.interactive = True

        # add id
        marker.unfreeze()
        marker.id = id
        marker.freeze()

        marker.set_data(pos=pos[np.newaxis],
                        symbol="disc",
                        edge_color="blue",
                        face_color='red',
                        size=10)

        # initialize Markertext
        text = Text(text=name,
                    pos=pos,
                    font_size=15,
                    anchor_x='right',
                    anchor_y='top',
                    parent=self.view.scene)

        return marker, text
Esempio n. 4
0
    def add_chan(self, chan, color=None, values=None, limits_c=None, colormap=CHAN_COLORMAP, alpha=None):
        """Add channels to visualization

        Parameters
        ----------
        chan : instance of Channels
            channels to plot
        color : tuple
            3-, 4-element tuple, representing RGB and alpha, between 0 and 1
        values : ndarray
            array with values for each channel
        limits_c : tuple of 2 floats, optional
            min and max values to normalize the color
        colormap : str
            one of the colormaps in vispy
        alpha : float
            transparency (0 = transparent, 1 = opaque)
        """
        # reuse previous limits
        if limits_c is None and self._chan_limits is not None:
            limits_c = self._chan_limits

        chan_colors, limits = _prepare_colors(color=color, values=values,
                                              limits_c=limits_c,
                                              colormap=colormap, alpha=alpha,
                                              chan=chan)

        self._chan_limits = limits

        xyz = chan.return_xyz()
        marker = Markers()
        marker.set_data(pos=xyz, size=CHAN_SIZE, face_color=chan_colors)
        self._add_mesh(marker)
Esempio n. 5
0
    def create_cities(self):
        # initialize city markers
        self.markers = Markers(parent=self.view.scene)
        # move z-direction a bit negative (means nearer to the viewer)
        self.markers.transform = STTransform(translate=(0, 0, -10))

        cities = utils.get_cities_coords()
        cnameList = []
        ccoordList = []
        for k, v in cities.items():
            cnameList.append(k)
            ccoordList.append(v)
        ccoord = np.vstack(ccoordList)
        ccoord = utils.wgs84_to_radolan(ccoord)
        pos_scene = np.zeros((ccoord.shape[0], 2), dtype=np.float32)
        pos_scene[:] = ccoord - self.r0

        # initialize Markers
        self.markers.set_data(pos=pos_scene,
                              symbol="disc",
                              edge_color="blue",
                              face_color='red',
                              size=10)

        # initialize Markertext
        self.text = Text(text=cnameList,
                         pos=pos_scene,
                         font_size=15,
                         anchor_x='right',
                         anchor_y='top',
                         parent=self.view.scene)
Esempio n. 6
0
def add_mesh_data_to_view(mdata,
                          view,
                          want_faces=True,
                          want_points=True,
                          want_lines=True,
                          transform=transforms.MatrixTransform()):
  color = mdata.get('color', 'g')
  if isinstance(color, str) and color == 'random': color = np.random.random(3).tolist()
  else: color = Color(color).rgb.tolist()

  res = Attributize()
  res.lines = []
  res.objs = []
  if want_lines and 'lines' in mdata:
    for polyline in mdata.lines:
      if isinstance(polyline, Attributize):
        width = polyline.get('width', 1)
        method = 'gl'
        if width > 1: method = 'gl'
        l = Line(
            pos=np.array(np.array(polyline.polyline)),
            antialias=True,
            method=method,
            color=np.array(polyline.colors),
            width=width,)
      else:
        l = Line(pos=np.array(np.array(polyline)), antialias=False, method='gl', color=color)
      l.transform = transform
      view.add(l)
      res.lines.append(l)
      res.objs.append(l)

  if want_points and mdata.get('points', None) is not None:
    scatter = Markers()
    #mdata.points = np.array((
    #    (10.928140, -51.417831, -213.253723),
    #    (0.000000, -46.719570, -205.607208),
    #    (0.000000, -53.499737, -215.031876),
    #    (0.000000, -69.314308, -223.780746),
    #    (0.000000, -89.549263, -170.910568),))
    #mdata.points = np.array(((-12.138942,-55.812309,-217.007050),(10.928140,-51.417831,-213.253723),(-7.289741,-43.585541,-200.506531)))
    points_color = mdata.get('points_color', color)
    points_size = mdata.get('points_size', 10)
    points = np.array(mdata.points)

    #print('PLOTTING ', points, points_size)
    if len(points) == 0: return
    scatter.set_data(points, edge_color=None, face_color=points_color, size=points_size)
    scatter.transform = transform
    view.add(scatter)
    res.objs.append(scatter)
    res.points = scatter

  if want_faces and 'mesh' in mdata:
    mesh = Mesh(meshdata=mdata.mesh, color=color + [0.7])
    mesh.transform = transform
    view.add(mesh)
    res.mesh = mesh
    res.objs.append(mesh)
  return res
Esempio n. 7
0
 def __init__(self):
     app.Canvas.__init__(self, keys='interactive', size=(512, 512 + 2*32),
                         title="Marker demo [press space to change marker]")
     self.index = 0
     self.scale = 1.
     self.markers = Markers()
     self.markers.set_data(pos)
     self.markers.set_style(marker_types[self.index])
Esempio n. 8
0
def test_markers():
    """Test basic marker / point-sprite support"""
    # this is probably too basic, but it at least ensures that point sprites
    # work for people
    np.random.seed(57983)
    data = np.random.normal(size=(30, 2), loc=50, scale=10)
    
    with TestingCanvas() as c:
        marker = Markers(parent=c.scene)
        marker.set_data(data)
        assert_image_approved(c.render(), "visuals/markers.png")

    # Test good correlation at high-dpi
    with TestingCanvas(px_scale=2) as c:
        marker = Markers(parent=c.scene)
        marker.set_data(data)
        assert_image_approved(c.render(), "visuals/markers.png")
Esempio n. 9
0
def test_markers():
    """Test basic marker / point-sprite support"""
    # this is probably too basic, but it at least ensures that point sprites
    # work for people
    with TestingCanvas() as c:
        marker = Markers()
        marker.set_data(np.array([[50, 50]], np.float32))
        c.draw_visual(marker)
        marker = _screenshot(alpha=False)
        assert 10 < (marker == 255).sum() < 100
    def __init__(self, layer):
        # Create a compound visual with the following four subvisuals:
        # Lines: The lines of the interaction box used for highlights.
        # Markers: The the outlines for each point used for highlights.
        # Markers: The actual markers of each point.
        node = Compound([Line(), Markers(), Markers()])

        super().__init__(layer, node)

        self.layer.events.symbol.connect(lambda e: self._on_data_change())
        self.layer.events.edge_width.connect(lambda e: self._on_data_change())
        self.layer.events.edge_color.connect(lambda e: self._on_data_change())
        self.layer.events.face_color.connect(lambda e: self._on_data_change())
        self.layer.events.highlight.connect(
            lambda e: self._on_highlight_change())

        self.layer.dims.events.ndisplay.connect(
            lambda e: self._on_display_change())

        self._on_display_change()
Esempio n. 11
0
    def attach(self, viewer, view, canvas, parent=None, order=0):
        super().attach(viewer, view, canvas, parent, order)

        self.node = Markers(pos=self._markers_data, parent=parent)
        self.node.transform = STTransform()
        self.node.order = order

        self._nodes = [self.node]

        self._viewer.dims.events.ndisplay.connect(self._on_data_change)

        self._on_data_change(None)
Esempio n. 12
0
    def __init__(self, layer):
        # Create a compound visual with the following four subvisuals:
        # Markers: corresponding to the vertices of the interaction box or the
        # shapes that are used for highlights.
        # Lines: The lines of the interaction box used for highlights.
        # Mesh: The mesh of the outlines for each shape used for highlights.
        # Mesh: The actual meshes of the shape faces and edges
        node = Compound([Mesh(), Mesh(), Line(), Markers()])

        super().__init__(layer, node)

        self.layer.events.edge_width.connect(self._on_data_change)
        self.layer.events.edge_color.connect(self._on_data_change)
        self.layer.events.face_color.connect(self._on_data_change)
        self.layer.events.highlight.connect(self._on_highlight_change)

        self._reset_base()
        self._on_data_change()
        self._on_highlight_change()
Esempio n. 13
0
 def __init__(self):
     self.clamp_filter = ClampSizeFilter()
     super().__init__([Markers(), Markers(), Line(), Text()])
     self.attach(self.clamp_filter)
     self.scaling = True
Esempio n. 14
0
import mercantile
import numpy as np
from vismap import Canvas, MercatorTransform
from vispy import app
from vispy.scene.visuals import Text, Markers

c = Canvas(show=True)
c.title = 'Issue 5'
c.view.camera.rect = (-1.08475e+07, 4.18788e+06), (2886.92, 2886.92)
c.view.add_tiles_for_current_zoom()

# add reference marker, using calculated x, y
long, lat = -97.441296, 35.18048
x, y = mercantile.xy(long, lat)

m_expected = Markers(parent=c.view.scene)
m_expected.set_data(np.array([(x, y, 0)]), face_color=(0, 1, 1))

t_ok = Text(
    'Expected position',
    pos=(x + 100, y),
    anchor_x='left',
    parent=c.view.scene,
    color=(0, 1, 1),
)
t_ok.order = 10

m_bad = c.view.marker_at((long - 0.0005, lat), face_color=(1, 0, 0))
t_bad = Text(
    'Actual position',
    pos=(long, lat),
Esempio n. 15
0
    def __init__(
        self,
        coords,
        *,
        symbol='o',
        size=10,
        edge_width=1,
        edge_color='black',
        face_color='white',
        n_dimensional=False,
        name=None,
    ):

        # Create a compound visual with the following four subvisuals:
        # Lines: The lines of the interaction box used for highlights.
        # Markers: The the outlines for each point used for highlights.
        # Markers: The actual markers of each point.
        visual = Compound([Line(), Markers(), Markers()])

        super().__init__(visual, name)

        self.events.add(
            mode=Event,
            size=Event,
            face_color=Event,
            edge_color=Event,
            symbol=Event,
            n_dimensional=Event,
        )
        self._colors = get_color_names()

        # Freeze refreshes
        with self.freeze_refresh():
            # Save the point coordinates
            self._data = coords

            # Save the point style params
            self.symbol = symbol
            self.n_dimensional = n_dimensional
            self.edge_width = edge_width

            self.sizes = size
            self.edge_colors = list(
                itertools.islice(ensure_iterable(edge_color, color=True), 0,
                                 len(self.data)))
            self.face_colors = list(
                itertools.islice(ensure_iterable(face_color, color=True), 0,
                                 len(self.data)))

            # The following point properties are for the new points that will
            # be added. For any given property, if a list is passed to the
            # constructor so each point gets its own value then the default
            # value is used when adding new points
            if np.isscalar(size):
                self._size = size
            else:
                self._size = 10

            if type(edge_color) is str:
                self._edge_color = edge_color
            else:
                self._edge_color = 'black'

            if type(face_color) is str:
                self._face_color = face_color
            else:
                self._face_color = 'white'

            # Indices of selected points
            self._selected_data = []
            self._selected_data_stored = []
            self._selected_data_history = []
            # Indices of selected points within the currently viewed slice
            self._selected_view = []
            # Index of hovered point
            self._hover_point = None
            self._hover_point_stored = None
            self._selected_box = None
            self._mode = Mode.PAN_ZOOM
            self._mode_history = self._mode
            self._status = self.mode

            self._drag_start = None

            # Nx2 array of points in the currently viewed slice
            self._data_view = np.empty((0, 2))
            # Sizes of points in the currently viewed slice
            self._sizes_view = 0
            # Full data indices of points located in the currently viewed slice
            self._indices_view = []

            self._drag_box = None
            self._drag_box_stored = None
            self._is_selecting = False
            self._clipboard = {}

            # update flags
            self._need_display_update = False
            self._need_visual_update = False

            # Re intitialize indices depending on image dims
            self._indices = (0, ) * (self.ndim - 2) + (
                slice(None, None, None),
                slice(None, None, None),
            )

            # Trigger generation of view slice and thumbnail
            self._set_view_slice()
Esempio n. 16
0
 def __init__(self):
     super().__init__([Mesh(), Mesh(), Line(), Markers(), Text()])
Esempio n. 17
0
    def debug(self, measurements, file_path, add_geodesic):

        # Model object
        model = mesh_lib.Model(file_path)
        model_point_coordinates = model.get_coords()

        canvas = scene.SceneCanvas(keys='interactive')
        view = canvas.central_widget.add_view()

        # all model - GREEN
        points = Markers(parent=view.scene)
        points.set_data(
            pos=model_point_coordinates,
            edge_color=None,
            face_color=(0, 1, 0, .3),
            size=5
        )
        data_list = []
        for m in measurements:  # measurements in config file
            # parsing key vertexes and description text
            point_1 = int(m[1]) + 1
            point_2 = int(m[2]) + 1
            point_3 = int(m[3]) + 1
            text = " ".join(m[4:])

            # coordinates of key vertexes
            key_coords = model.get_coords((point_1, point_2, point_3))
            # plane that goes through all three key vertexes
            plane = mesh_lib.get_plane(key_coords)

            # key vertexes WHITE
            points = Markers()
            points.set_data(
                pos=key_coords,
                edge_color=None,
                face_color=(1, 1, 1, 1),
                size=5
            )

            # "C" - circumference
            if m[0] == "C":
                # 3 segments of path (indexes)
                p_1 = model.get_path(point_1, point_2)
                p_2 = model.get_path(point_2, point_3)
                p_3 = model.get_path(point_3, point_1)
                # full path
                path = p_1 + p_2[1:] + p_3[1:]
            # "L" - Length
            if m[0] == "L":
                # 2 segments of path (indexes)
                p_1 = model.get_path(point_1, point_2)
                p_2 = model.get_path(point_2, point_3)
                # full path
                path = p_1 + p_2[1:]

            # geodesic
            geodesic_coordinates = model.get_coords(path)
            geodesic_length = mesh_lib.get_length(geodesic_coordinates)
            print("{0}:".format(text))
            print(
                "  Geodesic distance: {0} cm".format(
                    round(100 * geodesic_length, 3)
                )
            )

            if add_geodesic:  # if debug_full
                # geodesic line - RED
                line = Line(parent=view.scene)
                line.set_data(
                    pos=geodesic_coordinates,
                    color=(1, 0, 0, 1)
                )

            # approximated
            flattened_coordinates = mesh_lib.get_projections(plane, geodesic_coordinates)
            flattened_length = mesh_lib.get_length(flattened_coordinates)
            print(
                "  Approximated distance: {0} cm".format(
                    round(100 * flattened_length, 3)
                )
            )
            
            data_list.append(geodesic_length)
            data_list.append(flattened_length)
            # flattened line - BLUE
            line = Line(parent=view.scene)
            line.set_data(
                pos=flattened_coordinates,
                color=(0, 0, 1, 1)
            )

        view.camera = 'turntable'
        view.camera.fov = 45
        view.camera.distance = 3

        axis = XYZAxis(parent=view.scene)
        final_result = {"canvas":canvas,"data":data_list}
        return final_result
Esempio n. 18
0
  n_log_samples = 500
  # Get X coordinates by Random walking.
  well_x = 200 * np.ones(n_log_samples)
  delta_x = 0.3 * np.random.randn(n_log_samples)
  well_x += np.cumsum(delta_x)
  # Get Y and Z coordinates.
  well_y = 100 * np.ones(n_log_samples)
  well_z = np.linspace(0, 80, n_log_samples)
  # Concate X, Y, and Z coordinates.
  well_log_coords = np.stack((well_x, well_y, well_z), axis=1)
  # Get well log colors.
  cmap = get_colormap('hsl')
  values = np.random.uniform(-1.5, 2.5, n_log_samples)
  values = np.convolve(values, np.ones((20,))/20, mode='same')
  well_log_colors = np.array([cmap.map(x) for x in values]).squeeze()
  well_log = Markers(pos=well_log_coords, symbol='hbar', size=15,
    face_color=well_log_colors, edge_width=0)
  well_log.set_gl_state(depth_test=False)
  visual_nodes.append(well_log)

  canvas4 = SeismicCanvas(title='Voting Scores',
                          visual_nodes=visual_nodes,
                          xyz_axis=xyz_axis,
                          colorbar=colorbar,
                          **canvas_params)


  # Image 5: seismic with fault skin surfaces (meshes).
  fault_surfaces = []
  fault_cmap = 'hsl'
  fault_range = (0, 180)
Esempio n. 19
0
 def __init__(self):
     super().__init__([Markers(), Markers(), Line(), Text()])
     self.scaling = True