Ejemplo n.º 1
0
 def export_canvas_worker(self, fn, copy2clipboard):
     img = self.canvas.render()
     # If not full directory path, the relative path starts from CWD.
     logger.info("Save picture to {}".format(fn))
     vp.io.write_png(fn, img)
     if copy2clipboard:
         copy_to_clipboard(fn)
Ejemplo n.º 2
0
def display_selection(fig, selected, pos):
    """
    -i- fig : vispy fig
    -i- selected : vispy visual
    -i- pos : list, [x,y] pixel position of event
    """
    logger.info("Mouse pressed at pixel ({}, {})".format(pos[0], pos[1]))
    # Range of pixels to detect selected data
    posMin = [x - 5 for x in pos]  # 5 pixels range
    posMax = [x + 5 for x in pos]
    # map the mouse position to data coordinates
    tr = fig.scene.node_transform(selected)
    pos = tr.map(pos)
    posMin = tr.map(posMin)
    posMax = tr.map(posMax)
    # handle y+ axis pointing downward
    xMin = min(posMin[0], posMax[0])
    xMax = max(posMin[0], posMax[0])
    yMin = min(posMin[1], posMax[1])
    yMax = max(posMin[1], posMax[1])
    logger.info("Clicked at {}".format(pos))  # [x,y,z,mb]
    logger.info("Object name: {}".format(selected.name))
    if not hasattr(selected, 'vertexes'):
        return
    index = np.where((selected.vertexes['xyz'][:, 0] >= xMin)
                     & (selected.vertexes['xyz'][:, 0] <= xMax)
                     & (selected.vertexes['xyz'][:, 1] >= yMin)
                     & (selected.vertexes['xyz'][:, 1] <= yMax))
    if len(index[0]) >= 1:  # index is tuple (array,)
        index = index[0][0]
    logger.info("Data index = {}".format(index))
    for prop_name in sorted(selected.prop):
        prop = selected.prop[prop_name]
        array = prop['array1d']
        logger.info("{} = {}".format(prop_name, array[index]))
Ejemplo n.º 3
0
 def remove_item_agent(self, dob):
     name = dob.name
     key = 'object'
     if name in self.dpState:
         if key in self.dpState[name]:
             if self.dpState[name][key]['self']:
                 logger.info('{} is removing {}'.format(self._name, name))
                 self.save_display_state(name, 'object', 'self', False)
                 self.clear()
Ejemplo n.º 4
0
 def remove_item_agent(self, dob):
     parent = self._name
     name = dob.name
     key = 'object'
     if name in self.dpState:
         if key in self.dpState[name]:
             if self.dpState[name][key]['self']:
                 logger.info('{} is removing {}'.format(parent, name))
                 try:
                     item = dob.vs2d[parent]
                     self.remove_item(item)
                 except ValueError as e:
                     print("Ignore %s" % str(e))
                 self.save_display_state(dob.name, 'object', 'self', False)
Ejemplo n.º 5
0
    def add_item_agent(self, dob):
        parent = self._name
        geom = dob.geometry_type
        if geom not in ['Point', 'Label', 'Line']:
            QMessageBox.critical(
                self, _("Warning"),
                _("{} cannot display {}".format(parent, dob.name)))
            return

        logger.info('{} is adding {}'.format(parent, dob.name))
        if parent not in dob.vs2d:
            dob.make_vs2d(parent=parent)
        item = dob.vs2d[parent]
        self.add_item(item)
        self.save_display_state(dob.name, 'object', 'self', True)
Ejemplo n.º 6
0
        def on_mouse_press(event):
            if not self.canvas.pick_mode:
                return
            if len(self.canvas.visuals) == 0:
                return  # canvas is empty

            #if event.handled or event.button != 1:
            #    return
            if event.button == 2:
                queried = None
                for v in self.canvas.visuals_at(event.pos):
                    if isinstance(v, vp.scene.widgets.viewbox.ViewBox):
                        continue
                    queried = v
                    break
                if queried is not None:
                    logger.info("Object name {}".format(queried.name))
                return

            # emit signal of coordinate of picked point
            vis = self.canvas.visuals[0]
            tr = self.canvas.scene.node_transform(vis)
            pos = tr.map(event.pos)
            x, y, z = pos[:3]
            xy = np.array([x, y])
            survey = self.treebase.survey
            if survey is None:
                ilno, xlno = (0, 0)
            else:
                ilno, xlno = xy2ln(xy, survey=survey)
            self.canvas.sigPickedPoint.emit((ilno, xlno, x, y, z))

            selected = None
            for v in self.canvas.visuals_at(event.pos):
                if isinstance(v, vp.scene.widgets.viewbox.ViewBox):
                    continue
                selected = v
                break
            if selected is not None:
                display_selection(self.canvas, selected, event.pos)
Ejemplo n.º 7
0
def split_array(array, byteLimit):
    size = array.shape[0]
    byte = array.nbytes
    if byte >= byteLimit:
        if byte % byteLimit == 0:
            nsplit = int(byte / byteLimit)
        else:
            nsplit = int(byte / byteLimit) + 1
        nvCellSize = int(size / nsplit)
        splitIndex = np.arange(nvCellSize, size, nvCellSize).tolist()
        splitArray = np.split(array, splitIndex)
    else:
        splitArray = [array]
    cellSize = [a.shape[0] for a in splitArray]
    cellByte = [a.nbytes for a in splitArray]
    assert sum(cellSize) == size, "Lost element in split"
    assert sum(cellByte) == byte, "Lost byte in split"
    if byte >= byteLimit:
        logger.info('input array size = {}'.format(size))
        logger.info('input array bytes = {}'.format(byte))
        logger.info('output arrays size = {}'.format(cellSize))
        logger.info('output arrays bytes = {}'.format(cellByte))
    return splitArray
Ejemplo n.º 8
0
 def print_coord(self, point):
     logger.info("Mouse pressed at image index {}".format(point))
     self.dob.print_section_val(self.section_type, point)
Ejemplo n.º 9
0
 def print_coord(self, point):
     logger.info("Mouse pressed at coordinate {}".format(point))
Ejemplo n.º 10
0
def myprint(*args, **kwargs):
    """My custom print() function."""
    # TODO what about the kwargs?
    strArgs = [str(arg) for arg in args]
    text = ' '.join(strArgs)
    logger.info(text)
Ejemplo n.º 11
0
 def apply(self):
     logger.info("External modules: {}".format(str(self.extmodules)))
     self.sigExtModules.emit(self.extmodules)