Esempio n. 1
0
    def auto_add_peaks(self, tmodel):
        """
        Automagically add peak markers
        
        *tmodel* a :class:`~specimen.models.ThresholdSelector` model
        """
        threshold = tmodel.sel_threshold
        base = 1 if (tmodel.pattern == "exp") else 2
        data_x, data_y = tmodel.get_xy()
        maxtab, mintab = peakdetect(data_y, data_x, 5,
                                    threshold)  # @UnusedVariable

        mpositions = [marker.position for marker in self.markers]

        with self.visuals_changed.hold():
            i = 1
            for x, y in maxtab:  # @UnusedVariable
                if not x in mpositions:
                    nm = self.goniometer.get_nm_from_2t(x) if x != 0 else 0
                    new_marker = Marker(label="%%.%df" %
                                        (3 + min(int(log(nm, 10)), 0)) % nm,
                                        parent=self,
                                        position=x,
                                        base=base)
                    self.markers.append(new_marker)
                i += 1
Esempio n. 2
0
 def load_markers_from(self, fname):
     self.notify('render off')
     for line in file(fname, 'r'):
         marker = Marker.from_string(line)
         self.add_marker(marker)
     self.notify('render on')
     UndoRegistry().flush()
Esempio n. 3
0
    def key_press(self, interactor, event):
        key = interactor.GetKeySym()

        #XXX this is annoying in dwm (and probably elsewhere)
        #if self.pickerName is None:
        #error_msg('You must select the pick segment in the Picker tab')
        #return
        def checkPickerName():
            if self.pickerName is None:
                error_msg('You must select the pick segment in the Picker tab')
                return False
            return True

        if key.lower() == 'q':  #hehehe
            gtk.main_quit()
        if key.lower() == 'i':
            if not checkPickerName():
                return
            print "Inserting Marker"
            x, y = interactor.GetEventPosition()
            picker = vtk.vtkCellPicker()
            picker.PickFromListOn()
            o = self.paramd[self.pickerName]
            picker.AddPickList(o.isoActor)
            picker.SetTolerance(0.005)
            picker.Pick(x, y, 0, self.sr.renderer)
            points = picker.GetPickedPositions()
            numPoints = points.GetNumberOfPoints()
            if numPoints < 1: return
            pnt = points.GetPoint(0)

            marker = Marker(xyz=pnt, rgb=EventHandler().get_default_color())

            EventHandler().add_marker(marker)
        elif key.lower() == 'x':
            if not checkPickerName():
                return
            x, y = interactor.GetEventPosition()
            picker = vtk.vtkCellPicker()
            picker.PickFromListOn()
            for o in self.paramd.values():
                picker.AddPickList(o.isoActor)
            picker.SetTolerance(0.01)
            picker.Pick(x, y, 0, self.sr.renderer)
            cellId = picker.GetCellId()
            if cellId == -1:
                pass
            else:
                o = self.paramd.values()[0]
                o.remove.RemoveCell(cellId)
                interactor.Render()
        elif key.lower() == 'e':
            if not checkPickerName():
                return
            o = self.paramd.values()[0]
            pw = o.planeWidget
            if pw.GetEnabled():
                pw.EnabledOff()
            else:
                pw.EnabledOn()
Esempio n. 4
0
    def load_markers_from(self, fname):

        self.notify('render off')
        for line in file(fname, 'r'):
            marker = Marker.from_string(line)
            self.add_marker(marker)
        self.notify('render on')
        UndoRegistry().flush()
Esempio n. 5
0
    def load_markers_from(self, fname):
	#this runs when you load markers from file. it loads a csv file line by line and adds each marker
        self.notify('render off')
        for line in file(fname, 'r'):
            marker = Marker.from_string(line)
            self.add_marker(marker) #adds the marker to a vtk actor collection
        self.notify('render on')
        UndoRegistry().flush()
Esempio n. 6
0
 def load_markers_from(self, fname):
     #this runs when you load markers from file. it loads a csv file line by line and adds each marker
     self.notify('render off')
     for line in file(fname, 'r'):
         marker = Marker.from_string(line)
         self.add_marker(marker)  #adds the marker to a vtk actor collection
     self.notify('render on')
     UndoRegistry().flush()
Esempio n. 7
0
    def __init__(self):

        self.window = Tk()
        self.markers = Marker()
        self.mercator = PhotoImage(master=self.window, file='mercator.png')
        self.canvas = Canvas(master=self.window)

        self.WIDTH = self.mercator.width()
        self.HEIGHT = self.mercator.height()

        self.window.title('GeoRoute')
        self.window.resizable(False, False)
        self.window.geometry('{}x{}'.format(self.WIDTH, self.HEIGHT))
        self.canvas.configure(width=self.mercator.width(),
                              height=self.mercator.height())
        self.canvas.create_image(0, 0, anchor=NW, image=self.mercator)
        self.canvas.pack()
Esempio n. 8
0
    def __init__(self):
        self.config_provider = ConfigProvider()

        self.irobot = Robot()
        self.webcam = Webcam()

        self.marker = Marker()
        self.markers_cache = None

        self.features = Features(self.config_provider)

        self.texture_background = None
Esempio n. 9
0
    def OnKeyPress(self, wid, event=None):

        if (event.keyval == gdk.keyval_from_name("i")
                or event.keyval == gdk.keyval_from_name("I")):

            xyz = self.get_cursor_position_world()
            if xyz is None: return

            marker = Marker(xyz=xyz, rgb=EventHandler().get_default_color())

            EventHandler().add_marker(marker)
            return True

        elif (event.keyval == gdk.keyval_from_name("r")
              or event.keyval == gdk.keyval_from_name("R")):
            self.set_camera(self.resetCamera)
            return True

        return MarkerWindowInteractor.OnKeyPress(self, wid, event)
Esempio n. 10
0
def loop():

    frame = capture.get_frame()
    if frame is None:
        return

    (cap_height, cap_width, cap_channels) = frame.shape
    # print(width, height, channels)

    global markerDict
    (corners, ids, rejects) = aruco.detectMarkers(frame, markerDict)
    # print(corners)
    frame = aruco.drawDetectedMarkers(frame, corners, ids)

    detected_markers = np.array([]).reshape(0, 3)
    for i in range(len(corners)):
        corner = corners[i][0]
        p1 = corner[0]
        p2 = corner[1]
        p3 = corner[2]
        p4 = corner[3]
        x = p1[0] - ((p1[0] - p3[0]) / 2)
        y = p1[1] - ((p1[1] - p3[1]) / 2)

        x = int(x)
        y = int(y)

        # print(x, y, cap_width, cap_height)
        detected_markers = np.vstack(
            (detected_markers,
             np.array([ids[i][0], x / cap_width, y / cap_height])))
        cv2.circle(frame, (x, y), 10, (255, 255, 255), 2)

    global sock
    if not sock.is_available():
        sock.connect()
    else:
        send_data = Markers()
        for row in detected_markers:
            marker = Marker(int(row[0]), row[1], row[2])
            send_data.append(marker)
        sock.send(str(send_data))
Esempio n. 11
0
 def _add_markers(self):
     for i in range(12):
         self.note_markers.add(Marker())
Esempio n. 12
0
class IRobot(object):

    INVERSE_MATRIX = np.array([
        [1.0,   1.0,  1.0,  1.0],
        [-1.0, -1.0, -1.0, -1.0],
        [-1.0, -1.0, -1.0, -1.0],
        [1.0,   1.0,  1.0,  1.0]
    ])

    def __init__(self):
        self.config_provider = ConfigProvider()

        self.irobot = Robot()
        self.webcam = Webcam()

        self.marker = Marker()
        self.markers_cache = None

        self.features = Features(self.config_provider)

        self.texture_background = None

    def _init_gl(self):
        glClearColor(0.0, 0.0, 0.0, 0.0)
        glClearDepth(1.0)
        glDepthFunc(GL_LESS)
        glEnable(GL_DEPTH_TEST)
        glShadeModel(GL_SMOOTH)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(33.7, 1.3, 0.1, 100.0)
        glMatrixMode(GL_MODELVIEW)

        # load robots frames
        self.irobot.load_frames(self.config_provider.animation)

        # start webcam thread
        self.webcam.start()

        # assign texture
        glEnable(GL_TEXTURE_2D)
        self.texture_background = glGenTextures(1)

    def _draw_scene(self):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()

        # reset robots
        self.irobot.reset()

        # get image from webcam
        image = self.webcam.get_current_frame()

        # handle background
        self._handle_background(image.copy())

        # handle markers
        self._handle_markers(image.copy())

        # handle features
        self.features.handle(self.irobot, self.irobot, image.copy())

        glutSwapBuffers()

    def _handle_background(self, image):
        # let features update background image
        image = self.features.update_background_image(image)

        # convert image to OpenGL texture format
        bg_image = cv2.flip(image, 0)
        bg_image = Image.fromarray(bg_image)
        ix = bg_image.size[0]
        iy = bg_image.size[1]
        bg_image = bg_image.tobytes('raw', 'BGRX', 0, -1)

        # create background texture
        glBindTexture(GL_TEXTURE_2D, self.texture_background)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
        glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE,
                     bg_image)

        # draw background
        glBindTexture(GL_TEXTURE_2D, self.texture_background)
        glPushMatrix()
        glTranslatef(0.0, 0.0, -10.0)
        glBegin(GL_QUADS)
        glTexCoord2f(0.0, 1.0)
        glVertex3f(-4.0, -3.0, 0.0)
        glTexCoord2f(1.0, 1.0)
        glVertex3f(4.0, -3.0, 0.0)
        glTexCoord2f(1.0, 0.0)
        glVertex3f(4.0, 3.0, 0.0)
        glTexCoord2f(0.0, 0.0)
        glVertex3f(-4.0, 3.0, 0.0)
        glEnd()
        glPopMatrix()

    def _handle_markers(self, image):

        # attempt to detect markers
        markers = []

        try:
            markers = self.marker.detect(image)
        except Exception as ex:
            print(ex)

        # manage markers cache
        if markers:
            self.markers_cache = markers
        elif self.markers_cache:
            markers = self.markers_cache
            self.markers_cache = None
        else:
            return

        for marker in markers:

            rvecs, tvecs, marker_rotation, marker_name = marker

            # build view matrix
            rmtx = cv2.Rodrigues(rvecs)[0]

            view_matrix = np.array(
                    [[rmtx[0][0], rmtx[0][1], rmtx[0][2], tvecs[0]],
                     [rmtx[1][0], rmtx[1][1], rmtx[1][2], tvecs[1]],
                     [rmtx[2][0], rmtx[2][1], rmtx[2][2], tvecs[2]],
                     [0.0, 0.0, 0.0, 1.0]])

            view_matrix = view_matrix * self.INVERSE_MATRIX

            view_matrix = np.transpose(view_matrix)

            # load view matrix and draw cube
            glPushMatrix()
            glLoadMatrixd(view_matrix)

            if marker_name == ROCKY_ROBOT:
                self.irobot.next_frame(marker_rotation,
                                            self.features.is_speaking(),
                                            self.features.get_emotion())
            elif marker_name == SPORTY_ROBOT:
                self.irobot.next_frame(marker_rotation,
                                             self.features.is_speaking(),
                                             self.features.get_emotion())

            glColor3f(1.0, 1.0, 1.0)
            glPopMatrix()

    def main(self):
        glutInit()
        glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH)
        glutInitWindowSize(640, 480)
        glutInitWindowPosition(100, 100)
        glutCreateWindow('irobot')
        glutDisplayFunc(self._draw_scene)
        glutIdleFunc(self._draw_scene)
        self._init_gl()
        glutMainLoop()
Esempio n. 13
0
    def delete_project(self, user):
        indexes = user.get_indexes(create_new=False)

        if self.distilled_document is not None and self.distilled_document not in self.documents:
            self.documents.append(self.distilled_document)

        if len(self.documents) > 0:
            documents = ndb.get_multi(self.documents)
            perms = []

            for doc in documents:
                perms.append(doc.permissions)

                q = Marker.query()
                q = q.filter(Marker.document == doc.key)
                for m in q.iter():
                    m.key.delete()

                q = PublishDocument.query()
                q = q.filter(PublishDocument.document == doc.key)
                for m in q.iter():
                    m.key.delete()

                q = PublishSummary.query()
                q = q.filter(PublishSummary.document == doc.key)
                for m in q.iter():
                    m.key.delete()

                q = PublishPresentation.query()
                q = q.filter(PublishPresentation.document == doc.key)
                for m in q.iter():
                    m.key.delete()

                q = PresentationDocument.query()
                q = q.filter(PresentationDocument.document == doc.key)
                for m in q.iter():
                    m.key.delete()

                q = SummaryDocument.query()
                q = q.filter(SummaryDocument.document == doc.key)
                for m in q.iter():
                    m.key.delete()

                doc.index_delete(indexes)

            ndb.delete_multi(perms)
            ndb.delete_multi(self.documents)

        concept = self.get_children()
        indexes = user.get_indexes()

        for con in concept:
            if not con:
                continue

            if con.node_type == 'LinkedConcept':
                con.delete(user, touch_concept=True, force=True)
            else:
                con.rdelete(user, indexes)

        groups = self.get_groups()
        for group in groups:
            if self.key in group.artifacts:
                group.artifacts.remove(self.key)

        ndb.put_multi(groups)

        self.permissions.delete()
        self.index_delete(indexes)
        self.key.delete()
Esempio n. 14
0
class Map:
    def __init__(self):

        self.window = Tk()
        self.markers = Marker()
        self.mercator = PhotoImage(master=self.window, file='mercator.png')
        self.canvas = Canvas(master=self.window)

        self.WIDTH = self.mercator.width()
        self.HEIGHT = self.mercator.height()

        self.window.title('GeoRoute')
        self.window.resizable(False, False)
        self.window.geometry('{}x{}'.format(self.WIDTH, self.HEIGHT))
        self.canvas.configure(width=self.mercator.width(),
                              height=self.mercator.height())
        self.canvas.create_image(0, 0, anchor=NW, image=self.mercator)
        self.canvas.pack()

    def project(self, latitude, longitude):

        coordX = (self.WIDTH / 360) * (longitude + 180)
        coordY = (self.HEIGHT / 2) - (
            self.WIDTH * log(tan((pi / 4) +
                                 (radians(latitude) / 2))) / (2 * pi))

        self.canvas.create_line(coordX,
                                coordY,
                                *self.markers.last(default=((), (coordX,
                                                                 coordY)))[1],
                                width=2,
                                fill=self.markers.FILL)
        self.canvas.create_oval(coordX - self.markers.OFFSET,
                                coordY - self.markers.OFFSET,
                                coordX + self.markers.OFFSET,
                                coordY + self.markers.OFFSET,
                                fill=self.markers.FILL,
                                outline='')
        self.markers.push((latitude, longitude), (coordX, coordY))

    def estimate(self, waypoints=[]):
        # TODO
        return self.markers.last()[0]

    def write(self, payload):

        address = payload.decode('ascii')
        coords = geocoords(address)

        # incognito host; use computed estimate
        if not coords and len(self.markers):
            coords = self.estimate()

        # probably still internal network
        elif not coords:
            return

        self.print(address)
        self.emit(coords)

    def emit(self, payload):
        self.project(*payload)
        self.window.update()

    def print(self, payload):
        print(len(self.markers) + 1, payload)

    def clean(self):
        self.canvas.itemconfig(len(self.markers) * 2 + 1,
                               fill=self.markers.LFILL)

    def gmap(self):
        # TODO
        pass
Esempio n. 15
0
 def _add_markers(self):
     for i in range(25):
         marker = Marker()
         self.note_markers.add(marker)