コード例 #1
0
    def updateMouseHitPoint(self, event):

        displayPoint = self.getMousePositionInView(event)
        camera = self.view.camera()

        actors = self.view.renderer().GetActors()
        actors = [
            actors.GetItemAsObject(i) for i in range(actors.GetNumberOfItems())
        ]
        pickableSettings = [actor.GetPickable() for actor in actors]
        for actor in actors:
            if actor != self.cameraCenterObj.actor:
                actor.SetPickable(True)

        #res = vis.pickPoint(displayPoint, self.view, pickType='render')
        #if res.pickedProp:
        #    print('got pick with hardware')
        #if not res.pickedProp:
        res = vis.pickPoint(displayPoint,
                            self.view,
                            pickType='points',
                            tolerance=0.0005)
        if not res.pickedProp:
            res = vis.pickPoint(displayPoint,
                                self.view,
                                pickType='points',
                                tolerance=0.001)
        if not res.pickedProp:
            res = vis.pickPoint(displayPoint, self.view, pickType='cells')

        for actor, pickable in zip(actors, pickableSettings):
            actor.SetPickable(pickable)

        if res.pickedProp is not None:
            worldPoint = res.pickedPoint
        else:
            pt1, pt2 = vis.getRayFromDisplayPoint(self.view, displayPoint)
            if self.lastHitPoint is None:
                worldPoint = projectPointToLine(
                    pt1, pt2, np.array(camera.GetFocalPoint()))
            else:
                projectedWorldPoint, pcoord = projectPointToLineParam(
                    pt1, pt2, self.lastHitPoint)
                if pcoord >= 0.1:
                    worldPoint = projectedWorldPoint
                else:
                    worldPoint = projectPointToLine(
                        pt1, pt2, np.array(camera.GetFocalPoint()))

        # don't use last hit point
        # self.lastHitPoint = np.array(worldPoint)

        t = vtk.vtkTransform()
        t.Translate(worldPoint[:3])
        self.cameraCenterObj.actor.SetUserTransform(t)
        self.showOnMove = True
        self.style.SetCustomCenterOfRotation(worldPoint[:3])
コード例 #2
0
ファイル: pointpicker.py プロジェクト: patmarion/director
    def tick(self):

        if self.obj is None:
            self.hoverPos, prop, _ = vis.pickPoint(self.lastMovePos, self.view, pickType=self.pickType, tolerance=self.tolerance)
            if prop is None:
                self.hoverPos = None
        else:
            self.hoverPos = vis.pickPoint(self.lastMovePos, self.view, obj=self.obj, pickType=self.pickType, tolerance=self.tolerance)

        self.draw()
コード例 #3
0
    def tick(self):

        if self.obj is None:
            pickedPointFields = vis.pickPoint(self.lastMovePos, self.view, pickType=self.pickType,
                                                   tolerance=self.tolerance)
            self.hoverPos = pickedPointFields.pickedPoint
            prop = pickedPointFields.pickedProp
            if prop is None:
                self.hoverPos = None
        else:
            pickedPointFields = vis.pickPoint(self.lastMovePos, self.view, obj=self.obj, pickType=self.pickType, tolerance=self.tolerance)
            self.hoverPos = pickedPointFields.pickedPoint

        self.draw()
コード例 #4
0
 def getPointPick(self, displayPoint):
     pickData = vis.pickPoint(displayPoint,
                              self.view,
                              obj=self.points,
                              pickType='cells',
                              tolerance=0.01)
     return pickData.pickedPoint
コード例 #5
0
 def getHandlePick(self, displayPoint):
     pickData = vis.pickPoint(displayPoint,
                              self.view,
                              obj=self.handle,
                              pickType="cells",
                              tolerance=0.01)
     return pickData.pickedPoint
コード例 #6
0
    def tick(self):

        if self.obj is None:
            self.hoverPos, prop, _ = vis.pickPoint(self.lastMovePos,
                                                   self.view,
                                                   pickType=self.pickType,
                                                   tolerance=self.tolerance)
            if prop is None:
                self.hoverPos = None
        else:
            self.hoverPos = vis.pickPoint(self.lastMovePos,
                                          self.view,
                                          obj=self.obj,
                                          pickType=self.pickType,
                                          tolerance=self.tolerance)

        self.draw()
コード例 #7
0
    def updatePick(self, displayPoint):

        pickType = str(self.ui.pickTypeCombo.currentText)
        if 'render' in pickType:
            pickType = 'render'
        elif 'vertex' in pickType:
            pickType = 'points'
        elif 'surface' in pickType:
            pickType = 'cells'
        else:
            raise Exception('unknown pick type')

        tolerance = self.ui.toleranceSpinBox.value
        pickPointFields = vis.pickPoint(displayPoint,
                                        self.view,
                                        pickType=pickType,
                                        tolerance=tolerance)
        worldPoint = pickPointFields.pickedPoint
        prop = pickPointFields.pickedProp
        dataset = pickPointFields.pickedDataset
        normal = pickPointFields.pickedNormal

        if not prop:
            worldPoint = np.zeros(3)
            normal = np.zeros(3)

        obj = vis.getObjectByProp(prop)

        self.ui.displayPt.text = '%d, %d' % tuple(displayPoint)
        self.ui.worldPt.text = '%.5f, %.5f, %.5f' % tuple(worldPoint)
        self.ui.pickPt.text = '%.5f, %.5f, %.5f' % tuple(worldPoint)

        if normal is not None:
            self.ui.pickNormal.text = '%.5f, %.5f, %.5f' % tuple(normal)
        else:
            self.ui.pickNormal.text = 'not available'

        scale = computeViewScale(self.view, worldPoint)
        scale = scale * 10

        self.annotation.setProperty('Visible', prop is not None)
        t = vtk.vtkTransform()
        t.Translate(worldPoint)
        t.Scale(scale, scale, scale)
        self.annotation.actor.SetUserTransform(t)
        self.annotation._renderAllViews()

        if obj:
            self.ui.objName.text = obj.getProperty('Name')
        else:
            self.ui.objName.text = 'none'

        if dataset:
            self.ui.numPts.text = dataset.GetNumberOfPoints()
            self.ui.numCells.text = dataset.GetNumberOfCells()
        else:
            self.ui.numPts.text = '0'
            self.ui.numCells.text = '0'
コード例 #8
0
    def tick(self):

        if self.obj is None:
            pickedPointFields = vis.pickPoint(self.lastMovePos,
                                              self.view,
                                              pickType=self.pickType,
                                              tolerance=self.tolerance)
            self.hoverPos = pickedPointFields.pickedPoint
            prop = pickedPointFields.pickedProp
            if prop is None:
                self.hoverPos = None
        else:
            pickedPointFields = vis.pickPoint(self.lastMovePos,
                                              self.view,
                                              obj=self.obj,
                                              pickType=self.pickType,
                                              tolerance=self.tolerance)
            self.hoverPos = pickedPointFields.pickedPoint

        self.draw()
コード例 #9
0
    def getSelection(self, displayPoint):

        pickedPoint, pickedProp, pickedDataset, normal = vis.pickPoint(displayPoint, self.view, pickType='cells', tolerance=0.0)

        if not pickedDataset:
            return None

        linkName = self.robotModel.model.getLinkNameForMesh(pickedDataset)
        if not linkName:
            return None

        return pickedPoint, linkName, normal
コード例 #10
0
ファイル: pointpicker.py プロジェクト: patmarion/director
    def tick(self):

        objs = self.getObjectsFunction() if self.getObjectsFunction else None

        self.hoverPos, prop, _ = vis.pickPoint(self.lastMovePos, self.view, pickType='cells', tolerance=self.tolerance, obj=objs)
        prevPickedObj = self.pickedObj
        curPickedObj = vis.getObjectByProp(prop)

        if curPickedObj is not prevPickedObj:
            self.unsetHoverProperties(prevPickedObj)
            self.setHoverProperties(curPickedObj)
            self.pickedObj = curPickedObj
コード例 #11
0
ファイル: measurementpanel.py プロジェクト: rxdu/director
    def updatePick(self, displayPoint):

        pickType = str(self.ui.pickTypeCombo.currentText)
        if 'render' in pickType:
            pickType = 'render'
        elif 'vertex' in pickType:
            pickType = 'points'
        elif 'surface' in pickType:
            pickType = 'cells'
        else:
            raise Exception('unknown pick type')


        tolerance = self.ui.toleranceSpinBox.value
        pickPointFields = vis.pickPoint(
            displayPoint,
            self.view,
            pickType=pickType,
            tolerance=tolerance)
        worldPoint = pickPointFields.pickedPoint
        prop = pickPointFields.pickedProp
        dataset = pickPointFields.pickedDataset
        normal = pickPointFields.pickedNormal


        if not prop:
            worldPoint = np.zeros(3)
            normal = np.zeros(3)

        obj = vis.getObjectByProp(prop)

        self.ui.displayPt.text = '%d, %d' % tuple(displayPoint)
        self.ui.worldPt.text = '%.5f, %.5f, %.5f' % tuple(worldPoint)
        self.ui.pickPt.text = '%.5f, %.5f, %.5f' % tuple(worldPoint)
        self.ui.pickNormal.text = '%.5f, %.5f, %.5f' % tuple(normal)

        self.annotation.setProperty('Visible', prop is not None)
        t = vtk.vtkTransform()
        t.Translate(worldPoint)
        self.annotation.actor.SetUserTransform(t)
        self.annotation._renderAllViews()

        if obj:
            self.ui.objName.text = obj.getProperty('Name')
        else:
            self.ui.objName.text = 'none'

        if dataset:
            self.ui.numPts.text = dataset.GetNumberOfPoints()
            self.ui.numCells.text = dataset.GetNumberOfCells()
        else:
            self.ui.numPts.text = '0'
            self.ui.numCells.text = '0'
コード例 #12
0
def encode_normal_rgb(view, height, width, pickType='cells', tolerance=0.05):
    #picktype is one of ('points', 'cells', 'render')
    image = np.zeros((height, width, 3))
    for i in range(height):
        print i
        for j in range(width):
            pickPointFields = vis.pickPoint([i, j],
                                            view,
                                            pickType=pickType,
                                            tolerance=tolerance)
            normal = np.array(pickPointFields.pickedNormal)
            image[i, j, :] = normal
        # add some rgb conversion step, maybe png writer does that???
    return image
コード例 #13
0
ファイル: measurementpanel.py プロジェクト: ori-drs/director
    def updatePick(self, displayPoint):

        pickType = str(self.ui.pickTypeCombo.currentText)
        if "render" in pickType:
            pickType = "render"
        elif "vertex" in pickType:
            pickType = "points"
        elif "surface" in pickType:
            pickType = "cells"
        else:
            raise Exception("unknown pick type")

        tolerance = self.ui.toleranceSpinBox.value
        pickPointFields = vis.pickPoint(displayPoint,
                                        self.view,
                                        pickType=pickType,
                                        tolerance=tolerance)
        worldPoint = pickPointFields.pickedPoint
        prop = pickPointFields.pickedProp
        dataset = pickPointFields.pickedDataset
        normal = pickPointFields.pickedNormal

        if not prop:
            worldPoint = np.zeros(3)
            normal = np.zeros(3)

        obj = vis.getObjectByProp(prop)

        self.ui.displayPt.text = "%d, %d" % tuple(displayPoint)
        self.ui.worldPt.text = "%.5f, %.5f, %.5f" % tuple(worldPoint)
        self.ui.pickPt.text = "%.5f, %.5f, %.5f" % tuple(worldPoint)
        self.ui.pickNormal.text = "%.5f, %.5f, %.5f" % tuple(normal)

        self.annotation.setProperty("Visible", prop is not None)
        t = vtk.vtkTransform()
        t.Translate(worldPoint)
        self.annotation.actor.SetUserTransform(t)
        self.annotation._renderAllViews()

        if obj:
            self.ui.objName.text = obj.getProperty("Name")
        else:
            self.ui.objName.text = "none"

        if dataset:
            self.ui.numPts.text = dataset.GetNumberOfPoints()
            self.ui.numCells.text = dataset.GetNumberOfCells()
        else:
            self.ui.numPts.text = "0"
            self.ui.numCells.text = "0"
コード例 #14
0
    def getSelection(self, displayPoint):
        pickData = vis.pickPoint(displayPoint, self.view, pickType='cells', tolerance=0.0)
        pickedPoint = pickData.pickedPoint
        pickedDataset = pickData.pickedDataset
        normal = pickData.pickedNormal

        if not pickedDataset:
            return None

        linkName = self.robotModel.model.getLinkNameForMesh(pickedDataset)
        if not linkName:
            return None

        return pickedPoint, linkName, normal
コード例 #15
0
    def tick(self):

        objs = self.getObjectsFunction() if self.getObjectsFunction else None

        self.hoverPos, prop, _ = vis.pickPoint(self.lastMovePos,
                                               self.view,
                                               pickType='cells',
                                               tolerance=self.tolerance,
                                               obj=objs)
        prevPickedObj = self.pickedObj
        curPickedObj = vis.getObjectByProp(prop)

        if curPickedObj is not prevPickedObj:
            self.unsetHoverProperties(prevPickedObj)
            self.setHoverProperties(curPickedObj)
            self.pickedObj = curPickedObj
コード例 #16
0
def placeHandModel(displayPoint, view, side='left'):

    obj, _ = vis.findPickedObject(displayPoint, view)
    if isinstance(obj, vis.FrameItem):
        _, handFrame = handFactory.placeHandModelWithTransform(
            obj.transform, view, side=side, parent=obj.parent())
        handFrame.frameSync = vis.FrameSync()
        handFrame.frameSync.addFrame(obj)
        handFrame.frameSync.addFrame(handFrame, ignoreIncoming=True)
        return

    pickedPointFields = vis.pickPoint(displayPoint,
                                      view,
                                      pickType='cells',
                                      tolerance=0.0)
    pickedPoint = pickedPointFields.pickedPoint
    prop = pickedPointFields.pickedProp

    obj = vis.getObjectByProp(prop)
    if not obj:
        return

    yaxis = -normal
    zaxis = [0, 0, 1]
    xaxis = np.cross(yaxis, zaxis)
    xaxis /= np.linalg.norm(xaxis)
    zaxis = np.cross(xaxis, yaxis)
    zaxis /= np.linalg.norm(zaxis)

    t = transformUtils.getTransformFromAxes(-zaxis, yaxis, xaxis)
    t.PostMultiply()
    t.Translate(pickedPoint)

    if side == 'right':
        t.PreMultiply()
        t.RotateY(180)

    handObj, handFrame = handFactory.placeHandModelWithTransform(t,
                                                                 view,
                                                                 side=side,
                                                                 parent=obj)

    syncFrame = getChildFrame(obj)
    if syncFrame:
        handFrame.frameSync = vis.FrameSync()
        handFrame.frameSync.addFrame(handFrame, ignoreIncoming=True)
        handFrame.frameSync.addFrame(syncFrame)
コード例 #17
0
    def tick(self):

        objs = self.getObjectsFunction() if self.getObjectsFunction else None

        pickedPointFields = vis.pickPoint(
            self.lastMovePos,
            self.view,
            pickType="cells",
            tolerance=self.tolerance,
            obj=objs,
        )
        self.hoverPos = pickedPointFields.pickedPoint
        prop = pickedPointFields.pickedProp

        prevPickedObj = self.pickedObj
        curPickedObj = vis.getObjectByProp(prop)

        if curPickedObj is not prevPickedObj:
            self.unsetHoverProperties(prevPickedObj)
            self.setHoverProperties(curPickedObj)
            self.pickedObj = curPickedObj
コード例 #18
0
def placeHandModel(displayPoint, view, side='left'):

    obj, _ = vis.findPickedObject(displayPoint, view)
    if isinstance(obj, vis.FrameItem):
        _, handFrame = handFactory.placeHandModelWithTransform(obj.transform, view, side=side, parent=obj.parent())
        handFrame.frameSync = vis.FrameSync()
        handFrame.frameSync.addFrame(obj)
        handFrame.frameSync.addFrame(handFrame, ignoreIncoming=True)
        return

    pickedPointFields = vis.pickPoint(displayPoint, view, pickType='cells', tolerance=0.0)
    pickedPoint = pickedPointFields.pickedPoint
    prop = pickedPointFields.pickedProp

    obj = vis.getObjectByProp(prop)
    if not obj:
        return

    yaxis = -normal
    zaxis = [0,0,1]
    xaxis = np.cross(yaxis, zaxis)
    xaxis /= np.linalg.norm(xaxis)
    zaxis = np.cross(xaxis, yaxis)
    zaxis /= np.linalg.norm(zaxis)

    t = transformUtils.getTransformFromAxes(-zaxis, yaxis, xaxis)
    t.PostMultiply()
    t.Translate(pickedPoint)

    if side == 'right':
        t.PreMultiply()
        t.RotateY(180)

    handObj, handFrame = handFactory.placeHandModelWithTransform(t, view, side=side, parent=obj)

    syncFrame = getChildFrame(obj)
    if syncFrame:
        handFrame.frameSync = vis.FrameSync()
        handFrame.frameSync.addFrame(handFrame, ignoreIncoming=True)
        handFrame.frameSync.addFrame(syncFrame)
コード例 #19
0
    def getSelection(self, displayPoint):

        pickData = vis.pickPoint(displayPoint, self.view, pickType='cells', tolerance=0.0)

        pickedPoint = pickData.pickedPoint
        pickedDataset = pickData.pickedDataset
        normal = pickData.pickedNormal
        pickedCellId = pickData.pickedCellId

        if not pickedDataset:
            return None

        linkName = self.robotModel.model.getLinkNameForMesh(pickedDataset)

        for name, data in self.linkDict.iteritems():
            if pickedDataset == data['polyData']:
                linkName = name

        if not linkName:
            return None

        return pickedPoint, linkName, normal, pickedCellId
コード例 #20
0
ファイル: pointpicker.py プロジェクト: tkoolen/director
    def tick(self):

        # get affordances
        affs = self.affordanceManager.getAffordances()
        affs = [a for a in affs if a.getProperty('Visible')]
        if self.filterFunc is not None:
            affs = [a for a in affs if self.filterFunc(a)]

        # get picked affordance
        self.hoverPos, prop, _ = vis.pickPoint(self.lastMovePos, self.view, pickType='cells', tolerance=self.tolerance, obj=affs)
        prevPickedObj = self.pickedObj
        curPickedObj = vis.getObjectByProp(prop)
        if curPickedObj is not prevPickedObj:
            if prevPickedObj is not None:
                prevPickedObj.setProperty('Color', self.storedProps['Color'])
                prevPickedObj.setProperty('Alpha', self.storedProps['Alpha'])
            if curPickedObj is not None:
                self.storedProps['Color'] = curPickedObj.getProperty('Color')
                self.storedProps['Alpha'] = curPickedObj.getProperty('Alpha')
                curPickedObj.setProperty('Color', self.hoverColor)
                curPickedObj.setProperty('Alpha', self.hoverAlpha)
            self.pickedObj = curPickedObj

        self.draw()
コード例 #21
0
ファイル: pointpicker.py プロジェクト: patmarion/director
 def getHandlePick(self, displayPoint):
     return vis.pickPoint(displayPoint, self.view, obj=self.handle, pickType='cells', tolerance=0.01)
コード例 #22
0
ファイル: pointpicker.py プロジェクト: patmarion/director
 def getPointPick(self, displayPoint):
     return vis.pickPoint(displayPoint, self.view, obj=self.points, pickType='cells', tolerance=0.01)
コード例 #23
0
    def updateMouseHitPoint(self, event):

        displayPoint = self.getMousePositionInView(event)
        camera = self.view.camera()

        if self.lastHitPoint is not None:
            newFocalPoint = projectPointToLine(
                                np.array(camera.GetPosition()),
                                np.array(camera.GetFocalPoint()),
                                self.lastHitPoint)
            camera.SetFocalPoint(newFocalPoint)

        actors = self.view.renderer().GetActors()
        actors = [actors.GetItemAsObject(i) for i in range(actors.GetNumberOfItems())]
        pickableSettings = [actor.GetPickable() for actor in actors]
        for actor in actors:
            if actor != self.cameraCenterObj.actor:
                actor.SetPickable(True)

        #res = vis.pickPoint(displayPoint, self.view, pickType='render')
        #if res.pickedProp:
        #    print('got pick with hardware')
        #if not res.pickedProp:

        res = vis.pickPoint(displayPoint, self.view, pickType='points', tolerance=0.0005)
        if not res.pickedProp:
            res = vis.pickPoint(displayPoint, self.view, pickType='points', tolerance=0.001)
        if res.pickedProp is None:
            res = vis.pickPoint(displayPoint, self.view, pickType='cells')

        for actor, pickable in zip(actors, pickableSettings):
            actor.SetPickable(pickable)

        if res.pickedProp is not None:
            worldPoint = res.pickedPoint
        else:
            pt1, pt2 = vis.getRayFromDisplayPoint(self.view, displayPoint)
            rayOrigin = pt1

            ray = pt2 - pt1
            pt1 = np.array(camera.GetPosition())
            pt2 = pt1 + ray

            #print('cam to ray origin:', rayOrigin - pt1)

            if self.lastHitPoint is None:
                worldPoint = projectPointToLine(pt1, pt2, np.array(camera.GetFocalPoint()))
            else:
                #print('no prop was picked, finding a point on the pick ray...')
                projectedWorldPoint, pcoord = projectPointToLineParam(pt1, pt2, self.lastHitPoint)
                #print('pcoord of last hit point:', pcoord)
                if pcoord >= 0.1:
                    #print('using last hit point projected to pick ray')
                    worldPoint = projectedWorldPoint
                else:
                    #print('pcoord was bad so using current focal projected to pick ray')
                    worldPoint = projectPointToLine(pt1, pt2, np.array(camera.GetFocalPoint()))


        self.lastHitPoint = np.array(worldPoint)

        t = vtk.vtkTransform()
        t.Translate(worldPoint[:3])
        self.cameraCenterObj.actor.SetUserTransform(t)
        self.showOnMove = True
        self.style.SetCustomCenterOfRotation(worldPoint[:3])
コード例 #24
0
 def getHandlePick(self, displayPoint):
     return vis.pickPoint(displayPoint,
                          self.view,
                          obj=self.handle,
                          pickType='cells',
                          tolerance=0.01)