def __init__(self, parent=None):
        super(GLWidget, self).__init__(parent)

        self.setupInteraction()
        self.setupVis()
        self.cyls = list()

        #        self.skelModel = SkelGL.SkelGL()
        #        self.skelModel.timer.timeout.connect(self.timeOut)
        self.timer = QtCore.QTimer()
        self.timer.setSingleShot(False)
        self.timer.timeout.connect(self.timeOut)
        self.timer.start(10)

        self.metaGL = MetaGraphGL(self)
        self.metaGL.connectionOptions.sigConnectionAccepted.connect(
            self.acceptConnection)
        self.metaGL.breakOptions.sigBreakAccepted.connect(self.acceptBreak)
        self.metaGL.splitOptions.sigSplitAccepted.connect(self.acceptSplit)
        self.metaGL.centerChanged.connect(self.viewCenterChanged)
        #self.metaThread = MetaGraphThread()
        #self.metaGL.connectionOptions.sigConnectionAccepted.connect(self.metaThread.acceptConnection)
        #self.metaGL.breakOptions.sigBreakAccepted.connect(self.metaThread.acceptBreak)
        #self.metaGL.splitOptions.sigSplitAccepted.connect(self.metaThread.acceptSplit)
        #self.metaThread.sigUpdateMetaGraph.connect(self.metaGL.updateGraphSlot)
        #self.metaThread.start()

        self.modes = {
            -1: 'NoMode',
            0: 'Connection Mode',
            1: 'Separation Mode',
            2: 'Spltting Mode'
        }

        self.currentMode = -1
Пример #2
0
 def run(self):
     self.graph.breakOperation(self.edge)
     graphGL = MetaGraphGL()
     graphGL.setMetaGraph(self.graph)
     self.sigUpdateMetaGraph.emit(graphGL)
Пример #3
0
 def run(self):
     self.graph.joinOperation(self.v0id, self.v1id)
     graphGL = MetaGraphGL()
     graphGL.setMetaGraph(self.graph)
     self.sigUpdateMetaGraph.emit(graphGL)
Пример #4
0
 def run(self):
     graph = MetaGraph(self.filename)
     graphGL = MetaGraphGL()
     graphGL.setMetaGraph(graph)
     self.sigUpdateMetaGraph.emit(graphGL)
Пример #5
0
    def run(self):
        while True:
            if not self.fileIsLoaded:
                if self.loadFile:
                    self.graph = MetaGraph(self.fileToLoad)
                    self.fileIsLoaded = True
                    self.loadFile = False
                    graphGL = MetaGraphGL()
                    graphGL.setMetaGraph(self.graph)
                    self.sigUpdateMetaGraph.emit(graphGL)

            if self.joinOptions != None:
                self.graph.joinOperation(self.joinOptions.v0id,
                                         self.joinOptions.v1id)
                graphGL = MetaGraphGL()
                graphGL.setMetaGraph(self.graph)
                self.sigUpdateMetaGraph.emit(graphGL)
                self.joinOptions = None

            if self.breakOptions != None:
                self.graph.breakOperation(self.breakOptions.edge)
                graphGL = MetaGraphGL()
                graphGL.setMetaGraph(self.graph)
                self.sigUpdateMetaGraph.emit(graphGL)
                self.breakOptions = None

            if self.splitOptions != None:
                self.graph.splitOperation(self.splitOptions.splitEdge,
                                          self.splitOptions.secondaries)
                graphGL = MetaGraphGL()
                graphGL.setMetaGraph(self.graph)
                self.sigUpdateMetaGraph.emit(graphGL)
                self.splitOptions = None

            if self.isNotified:
                self.isNotified = False
                self.wasNotified.emit()

            if self.isTerminated:
                self.wasTerminated.emit()
                return
            self.sleep(1000)
Пример #6
0
 def run(self):
     self.graph.splitOperation(self.splitEdge, self.secondaries)
     graphGL = MetaGraphGL()
     graphGL.setMetaGraph(self.graph)
     self.sigUpdateMetaGraph.emit(graphGL)
class GLWidget(QtOpenGL.QGLWidget):
    xRotationChanged = pyqtSignal(int)
    yRotationChanged = pyqtSignal(int)
    zRotationChanged = pyqtSignal(int)

    @pyqtSlot(str)
    def loadFileEvent(self, filename: str):
        self.loadThread = LoadOperationThread(filename)
        self.loadThread.finished.connect(self.loadThread.deleteLater)
        self.loadThread.sigUpdateMetaGraph.connect(self.metaGL.loadGraphSlot)
        self.loadThread.run()

    @pyqtSlot(int, int)
    def acceptConnection(self, v0id, v1id):
        self.connectionThread = JoinOperationThread(self.metaGL.graph, v0id,
                                                    v1id)
        self.connectionThread.finished.connect(
            self.connectionThread.deleteLater)
        self.connectionThread.sigUpdateMetaGraph.connect(
            self.metaGL.updateGraphSlot)
        self.connectionThread.run()

    @pyqtSlot(object)
    def acceptBreak(self, edge: MetaEdge3d):
        self.breakThread = BreakOperationThread(self.metaGL.graph, edge)
        self.breakThread.finished.connect(self.breakThread.deleteLater)
        self.breakThread.sigUpdateMetaGraph.connect(
            self.metaGL.updateGraphSlot)
        self.breakThread.run()

    @pyqtSlot(object, object)
    def acceptSplit(self, splitEdge: MetaEdge3d, secondaries):
        self.splitThread = SplitOperationThread(self.metaGL.graph, splitEdge,
                                                secondaries)
        self.splitThread.finished.connect(self.splitThread.deleteLater)
        self.splitThread.sigUpdateMetaGraph.connect(
            self.metaGL.updateGraphSlot)
        #self.splitThread.start()
        self.splitThread.run()

    @pyqtSlot(object)
    def viewCenterChanged(self, center):
        self.camera.look_at(center)
        self.camera.viewCenter = center
        self.camera.standoff = np.linalg.norm(self.camera.viewCenter -
                                              self.camera.get_position())
        self.camera.resolveAngularPosition()

    @pyqtSlot()
    def recenter(self):
        self.camera.viewCenter = p3d2arr(self.metaGL.graph.skeleton.center)
        self.camera.standoff = self.metaGL.graph.skeleton.radius * 2
        self.camera.resolveAngularPosition()

    def __init__(self, parent=None):
        super(GLWidget, self).__init__(parent)

        self.setupInteraction()
        self.setupVis()
        self.cyls = list()

        #        self.skelModel = SkelGL.SkelGL()
        #        self.skelModel.timer.timeout.connect(self.timeOut)
        self.timer = QtCore.QTimer()
        self.timer.setSingleShot(False)
        self.timer.timeout.connect(self.timeOut)
        self.timer.start(10)

        self.metaGL = MetaGraphGL(self)
        self.metaGL.connectionOptions.sigConnectionAccepted.connect(
            self.acceptConnection)
        self.metaGL.breakOptions.sigBreakAccepted.connect(self.acceptBreak)
        self.metaGL.splitOptions.sigSplitAccepted.connect(self.acceptSplit)
        self.metaGL.centerChanged.connect(self.viewCenterChanged)
        #self.metaThread = MetaGraphThread()
        #self.metaGL.connectionOptions.sigConnectionAccepted.connect(self.metaThread.acceptConnection)
        #self.metaGL.breakOptions.sigBreakAccepted.connect(self.metaThread.acceptBreak)
        #self.metaGL.splitOptions.sigSplitAccepted.connect(self.metaThread.acceptSplit)
        #self.metaThread.sigUpdateMetaGraph.connect(self.metaGL.updateGraphSlot)
        #self.metaThread.start()

        self.modes = {
            -1: 'NoMode',
            0: 'Connection Mode',
            1: 'Separation Mode',
            2: 'Spltting Mode'
        }

        self.currentMode = -1

    @pyqtSlot()
    def timeOut(self):
        if self.isWDown:
            self.camera.goForward(self.speed)
        elif self.isSDown:
            self.camera.goForward(-self.speed)

        if self.isADown:
            self.camera.goRight(-self.speed)
        elif self.isDDown:
            self.camera.goRight(self.speed)

        if self.isQDown:
            self.camera.roll(-0.01 * 5)
        elif self.isEDown:
            self.camera.roll(0.01 * 5)
        self.update()

    @pyqtSlot()
    def updateCurrentGL(self, modelGL: object):
        self.modelGL = modelGL
        self.hasModelGL = True

    def setupInteraction(self):
        self.isMouseLeftDown = False
        self.isMouseRightDown = False
        self.isMouseMiddleDown = False
        self.zoom = 1.0
        self.zoomDegrees = 0.0
        self.lastMouseX = 0.0
        self.lastMouseY = 0.0

        self.isWDown = False
        self.isADown = False
        self.isSDown = False
        self.isDDown = False
        self.isQDown = False
        self.isEDown = False

        self.baseSpeed = 0.15 * 5
        self.speed = self.baseSpeed

        self.installEventFilter(self)
        self.setFocusPolicy(Qt.StrongFocus)

    def setupVis(self):
        self.camera = Camera()
        initialPosition = v3(0, 0, 40)

        self.camera.set_position(initialPosition)
        self.viewCenter = v3()
        self.camera.look_at(self.viewCenter)
        self.camera.set_near(1.0)
        self.camera.set_far(1000.0)
        self.baseFov = (60.0 / 180.0) * np.pi
        self.camera.set_fov(self.baseFov)
        w = float(self.width())
        h = float(self.height())
        self.camera.set_aspect(w / h)
        p = self.camera.get_model_matrix()

        self.imageCenterX = w / 2.0
        self.imageCenterY = h / 2.0

    def __del__(self):
        self.makeCurrent()
        for cyl in self.cyls:
            glDeleteLists(cyl)

    def setXRotation(self, angle: float):
        self.normalizeAngle(angle)
        oAngle = angle * 2 * np.pi / 5760.0
        pitch = self.camera.get_world_pitch()
        angleDif = oAngle - pitch
        self.camera.pitch(angleDif)
        if angle != self.xRot:
            self.xRot = angle
            self.xRotationChanged.emit(angle)
            self.updateGL()

    def setYRotation(self, angle: float):
        self.normalizeAngle(angle)
        oAngle = angle * 2 * np.pi / 5760.0
        yaw = self.camera.get_world_yaw()
        angleDif = oAngle - yaw
        self.camera.yaw(angleDif)
        if angle != self.yRot:
            self.yRot = angle
            self.yRotationChanged.emit(angle)
            self.updateGL()

    def setZRotation(self, angle: float):
        self.normalizeAngle(angle)
        oAngle = angle * 2 * np.pi / 5760.0
        roll = self.camera.get_world_roll()
        angleDif = oAngle - roll
        self.camera.roll(angleDif)
        if angle != self.zRot:
            self.zRot = angle
            self.zRotationChanged.emit(angle)
            self.updateGL()

    def initializeGL(self):
        lightPos = (1000.0, 1000.0, 1000.0, 1.0)
        lightPos2 = (-1000.0, -1000.0, 0, 1.0)
        ambientLight = (1.0, 1.0, 1.0, 1.0)
        ref = (0.5, 0.0, 0.0, 1.0)
        ref2 = (1.0, 0.0, 0.0, 1.0)
        reflectance1 = (0.8, 0.1, 0.0, 0.7)
        reflectance2 = (0.0, 0.8, 0.2, 1.0)
        reflectance3 = (0.2, 0.2, 1.0, 1.0)

        #glLightfv(GL_LIGHT0, GL_POSITION, lightPos)
        #        glLightfv(GL_LIGHT1, GL_POSITION, lightPos)
        #        glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight)
        #glEnable(GL_LIGHTING)
        glDisable(GL_LIGHTING)
        glEnable(GL_LIGHT0)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        self.cx = 0
        self.cy = 0
        self.cz = 0
        self.rad = 10
        rad = self.rad

        self.rotX = 0.0
        self.rotY = 0.0

        glEnable(GL_NORMALIZE)
        glClearColor(1.0, 1.0, 1.0, 1.0)

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(self.camera.get_fov_deg(), self.camera.get_aspect(),
                       self.camera.get_near(), self.camera.get_far())
        glMatrixMode(GL_MODELVIEW)
        self.issuesGL = IssuesGL()
        self.sphere = VBOSphere()

        random.seed(0)
        self.randvals = []
        for row in range(0, 201):
            self.randvals.append([])
            for col in range(0, 201):
                self.randvals[row].append(random.uniform(0.25, 1.0))

    def paintGL(self):
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(self.camera.get_fov_deg(), self.camera.get_aspect(),
                       self.camera.get_near(), self.camera.get_far())

        glMatrixMode(GL_MODELVIEW)
        glPushMatrix()
        glLoadIdentity()

        self.camera.look_at(self.camera.viewCenter)
        lpos = self.camera.viewCenter
        up = self.camera.get_world_up()

        pos = self.camera.get_position()
        lightpos = (pos[0], pos[1], pos[2], 1.0)
        color = (1.0, 0.0, 1.0, 1.0)

        ldir = lpos - pos

        gluLookAt(pos[0], pos[1], pos[2], lpos[0], lpos[1], lpos[2], up[0],
                  up[1], up[2])

        glEnable(GL_LIGHTING)
        glEnable(GL_LIGHT0)
        glLightfv(GL_LIGHT0, GL_POSITION, lightpos)
        glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, ldir)
        ldir /= np.linalg.norm(ldir)

        #self.metaGL.display(self.zoom)
        glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, color)
        #self.issuesGL.issuegl()
        x = -100.0
        y = -100.0
        z = 0.0
        row = 0
        while x <= 100:
            y = -10.0
            col = 0
            while y <= 10:
                self.sphere.fancyDraw(1.0, 0.5, 1.0, x, y, z,
                                      self.randvals[row][col])
                y = y + 1.0
                col = col + 1
            x = x + 1.0
            row = row + 1

        #glTranslated(-100.0, 0.0, 0.0)
        #for x in range(, 200):
        #    glTranslated(0.0, -100.0, 0.0)
        #    for y in range(0, 100):
        #        #glScalef(2.0, 2.0, 2.0)
        #        self.sphere.draw()
        #        #glScalef(0.5, 0.5, 0.5)
        #        glTranslated(0.0, 1.0, 0.0)
        #    glTranslated(1.0, 0.0, 0.0)

        glDisable(GL_LIGHTING)
        glPopMatrix()

    def resizeGL(self, width: int, height: int):
        side = min(width, height)

        #fov = (60.0 / 180.0) * np.pi
        #self.camera.set_fov(fov)
        w = float(self.width())
        h = float(self.height())
        self.camera.set_aspect(w / h)

        glViewport(0, 0, width, height)

        #glMatrixMode(GL_PROJECTION)
        #glLoadIdentity()
        #glFrustum(-1.0, +1.0, -1.0, 1.0, 5.0, 60.0)
        #glMatrixMode(GL_MODELVIEW)
        #glLoadIdentity()
        #glTranslated(0.0, 0.0, -40.0)
        self.imageCenterX = float(width) / 2.0
        self.imageCenterY = float(height) / 2.0

    def xRotation(self):
        return self.xRot

    def yRotation(self):
        return self.yRot

    def zRotation(self):
        return self.zRot

    #def drawCallList(self, gear, dx : float = 0, dy : float = 0, dz : float = 0, angle : float = 0):
    #    glPushMatrix()
    #    glTranslated(dx, dy, dz)
    #    glRotated(angle, 0.0, 0.0, 1.0)
    #    glCallList(gear)
    #    glPopMatrix()

    def normalizeAngle(self, angle: float):
        while (angle < 0):
            angle += 360 * 16

        while (angle > 360 * 16):
            angle -= 360 * 16

    def keyPressEvent(self, event: QtGui.QKeyEvent):
        key = event.key()
        modifiers = event.modifiers()

        if self.underMouse() and modifiers == Qt.NoModifier:
            if key == Qt.Key_W:
                self.isWDown = True
#                self.camera.goUp(0.1)
            elif key == Qt.Key_S:
                self.isSDown = True
#                self.camera.goUp(-0.1)

            elif key == Qt.Key_A:
                self.isADown = True
#                self.camera.goRight(-0.1)
            elif key == Qt.Key_D:
                self.isDDown = True
#                self.camera.goRight(0.1)

            elif key == Qt.Key_Q:
                self.isQDown = True
#                self.camera.roll(0.05)
            elif key == Qt.Key_E:
                self.isEDown = True
#                self.camera.roll(-0.05)

        QtOpenGL.QGLWidget.keyPressEvent(self, event)

    def keyReleaseEvent(self, event: QtGui.QKeyEvent):
        key = event.key()
        modifiers = event.modifiers()
        if key == Qt.Key_W:
            self.isWDown = False
        elif key == Qt.Key_S:
            self.isSDown = False

        elif key == Qt.Key_A:
            self.isADown = False
        elif key == Qt.Key_D:
            self.isDDown = False

        elif key == Qt.Key_Q:
            self.isQDown = False
        elif key == Qt.Key_E:
            self.isEDown = False

        elif key == Qt.Key_Return:
            if self.currentMode == 0:
                t = 1
#                    self.skelModel.AcceptConnection()
            elif self.currentMode == 1:
                g = 3
#                    self.skelModel.AcceptBreak()

        QtOpenGL.QGLWidget.keyReleaseEvent(self, event)

    def wheelEvent(self, QWheelEvent: QtGui.QWheelEvent):
        numDegrees = (QWheelEvent.angleDelta() / 8.0).y()

        self.zoomDegrees += numDegrees

        halfRotations = self.zoomDegrees / 180

        self.zoom = pow(2.0, halfRotations)

        self.camera.set_fov(self.baseFov / self.zoom)

        self.speed = self.baseSpeed / self.zoom

        return super().wheelEvent(QWheelEvent)

    def mousePressEvent(self, event: QtGui.QMouseEvent):

        if event.button() == Qt.RightButton and not self.isMouseLeftDown:
            self.isMouseRightDown = True
            self.lastMouseX = event.x()
            self.lastMouseY = event.y()
            ray = self.getRay(event.x(), event.y())
            origin = self.camera.getNpPosition()
            self.metaGL.doPicking(origin, ray)
            #self.metaThread.RayPickedEvent(origin, ray)
            '''
            if self.currentMode == 0:
                (hitFound, nodeHit, nodeHitId) = self.skelModel.getFirstNodeHit(origin, ray)
                if hitFound:
                    self.skelModel.PickConnectionNode(nodeHit)
            if self.currentMode == 1:
                (hitFound, edgeHit, edgeHitId) = self.skelModel.getFirstEdgeHit(origin, ray)
                if hitFound:
                    self.skelModel.PickBreakEdge(edgeHit)
            '''
        elif event.button() == Qt.LeftButton and not self.isMouseRightDown:
            self.isMouseLeftDown = True
            self.lastMouseX = event.x()
            self.lastMouseY = event.y()
            ray = self.getRay(event.x(), event.y())
            origin = self.camera.getNpPosition()
            self.metaGL.doPicking(origin, ray)
            #            (hitFound, edgeHit, edgeHitId) = self.skelModel.getFirstEdgeHit(origin, ray)
            #            self.skelModel.highlightEdge(edgeHitId)
            '''
            if self.currentMode == -1:
                (hitFound, nodeHit, nodeHitId) = self.skelModel.getFirstNodeHit(origin, ray)
                self.skelModel.highlightNode(nodeHitId)
            '''

        elif event.button() == Qt.MiddleButton:
            self.isMouseMiddleDown = True
            self.lastMouseX = event.x()
            self.lastMouseY = event.y()

    def mouseMoveEvent(self, event: QtGui.QMouseEvent):

        if self.isMouseMiddleDown:
            difX = event.x() - self.lastMouseX
            difY = event.y() - self.lastMouseY

            self.camera.goUp(self.speed * difY * 0.3)
            self.camera.goRight(-self.speed * difX * 0.3)

            self.lastMouseX = event.x()
            self.lastMouseY = event.y()

        if self.isMouseLeftDown:
            difX = event.x() - self.lastMouseX
            difY = event.y() - self.lastMouseY

            self.camera.increment_phi(0.01 * difX)
            self.camera.increment_theta(0.01 * difY)
            self.camera.resolveAngularPosition()

            self.lastMouseX = event.x()
            self.lastMouseY = event.y()

        elif self.isMouseRightDown:
            difX = event.x() - self.lastMouseX
            difY = event.y() - self.lastMouseY

            self.camera.yaw(0.01 * difX)
            self.camera.pitch(0.01 * difY)
            self.camera.resolveAngularPosition()

            self.lastMouseX = event.x()
            self.lastMouseY = event.y()

        if self.isMouseLeftDown or self.isMouseRightDown or self.isMouseMiddleDown:
            if event.x() > self.width():
                self.lastMouseX = 0
                newPoint = self.mapToGlobal(QtCore.QPoint(0, event.y()))
                QtGui.QCursor.setPos(newPoint.x(), newPoint.y())
            elif event.x() < 0:
                self.lastMouseX = self.width()
                newPoint = self.mapToGlobal(
                    QtCore.QPoint(self.width(), event.y()))
                QtGui.QCursor.setPos(newPoint.x(), newPoint.y())

            if event.y() > self.height():
                self.lastMouseY = 0
                newPoint = self.mapToGlobal(QtCore.QPoint(event.x(), 0))
                QtGui.QCursor.setPos(newPoint.x(), newPoint.y())
            if event.y() < 0:
                self.lastMouseY = self.height()
                newPoint = self.mapToGlobal(
                    QtCore.QPoint(event.x(), self.height()))
                QtGui.QCursor.setPos(newPoint.x(), newPoint.y())

    def mouseReleaseEvent(self, event: QtGui.QMouseEvent):
        if event.button() == Qt.RightButton:
            self.isMouseRightDown = False
        elif event.button() == Qt.LeftButton:
            self.isMouseLeftDown = False
        elif event.button() == Qt.MiddleButton:
            self.isMouseMiddleDown = False

    def getRay(self, windowX: float, windowY: float):
        projectedX = (windowX - self.imageCenterX) / self.imageCenterX
        projectedY = (self.imageCenterY - windowY) / self.imageCenterY

        view = self.camera.get_world_forward()
        view = view / np.linalg.norm(view)

        h = np.cross(view, self.camera.get_world_up())
        h = h / np.linalg.norm(h)

        v = np.cross(h, view)
        v = v / np.linalg.norm(v)

        vLength = np.tan(self.camera.get_fov() / 2) * self.camera.get_near()
        hLength = vLength * self.camera.get_aspect()

        v = v * vLength
        h = h * hLength

        pos = self.camera.getNpPosition(
        ) + view * self.camera.get_near() + h * projectedX + v * projectedY

        dirVec = pos - self.camera.getNpPosition()

        dirVec = dirVec / np.linalg.norm(dirVec)

        return dirVec

    def enterConnectionMode(self, ConnectionWidget: Ui_ConnectionTabWidget):
        self.currentMode = 0
        self.connectionWidget = ConnectionWidget
        self.metaGL.enterConnectionMode(ConnectionWidget)

    def enterBreakMode(self, BreakWidget: Ui_BreakTabWidget):
        self.currentMode = 1
        self.metaGL.enterBreakMode(BreakWidget)

    def enterSplitMode(self, SplitWidget: Ui_SplitTabWidget):
        self.currentMode = 2
        self.metaGL.enterSplitMode(SplitWidget)