def applyCameraTexture(obj, imageManager, imageName='CAMERA_LEFT'): imageUtime = imageManager.getUtime(imageName) if not imageUtime: return cameraToLocal = vtk.vtkTransform() imageManager.queue.getTransform(imageName, 'local', imageUtime, cameraToLocal) pd = filterUtils.transformPolyData(obj.polyData, obj.actor.GetUserTransform()) pd = filterUtils.transformPolyData(pd, cameraToLocal.GetLinearInverse()) imageManager.queue.computeTextureCoords(imageName, pd) tcoordsArrayName = 'tcoords_%s' % imageName tcoords = pd.GetPointData().GetArray(tcoordsArrayName) assert tcoords obj.polyData.GetPointData().SetTCoords(None) obj.polyData.GetPointData().SetTCoords(tcoords) obj._updateColorByProperty() obj.actor.SetTexture(imageManager.getTexture(imageName)) obj.actor.GetProperty().LightingOff() obj.actor.GetProperty().SetColor([1, 1, 1])
def applyCameraTexture(obj, imageManager, imageName='CAMERA_LEFT'): imageUtime = imageManager.getUtime(imageName) if not imageUtime: return cameraToLocal = vtk.vtkTransform() imageManager.queue.getTransform(imageName, 'local', imageUtime, cameraToLocal) pd = filterUtils.transformPolyData(obj.polyData, obj.actor.GetUserTransform()) pd = filterUtils.transformPolyData(pd, cameraToLocal.GetLinearInverse()) imageManager.queue.computeTextureCoords(imageName, pd) tcoordsArrayName = 'tcoords_%s' % imageName tcoords = pd.GetPointData().GetArray(tcoordsArrayName) assert tcoords obj.polyData.GetPointData().SetTCoords(None) obj.polyData.GetPointData().SetTCoords(tcoords) obj._updateColorByProperty() obj.actor.SetTexture(imageManager.getTexture(imageName)) obj.actor.GetProperty().LightingOff() obj.actor.GetProperty().SetColor([1,1,1])
def drawFrameInCamera(t, frameName='new frame',visible=True): v = imageView.view q = cameraview.imageManager.queue localToCameraT = vtk.vtkTransform() q.getTransform('local', 'CAMERA_LEFT', localToCameraT) res = vis.showFrame( vtk.vtkTransform() , 'temp',view=v, visible=True, scale = 0.2) om.removeFromObjectModel(res) pd = res.polyData pd = filterUtils.transformPolyData(pd, t) pd = filterUtils.transformPolyData(pd, localToCameraT) q.projectPoints('CAMERA_LEFT', pd ) vis.showPolyData(pd, ('overlay ' + frameName), view=v, colorByName='Axes',parent='camera overlay',visible=visible)
def updateObjectInCamera(self, obj, cameraObj): imageView = self.imageView objToLocalT = transformUtils.copyFrame(obj.actor.GetUserTransform() or vtk.vtkTransform()) localToCameraT = vtk.vtkTransform() self.imageQueue.getTransform('local', imageView.imageName, localToCameraT) t = vtk.vtkTransform() t.PostMultiply() t.Concatenate(objToLocalT) t.Concatenate(localToCameraT) pd = filterUtils.transformPolyData(obj.polyData, t) ''' normals = pd.GetPointData().GetNormals() cameraToImageT = vtk.vtkTransform() imageQueue.getCameraProjectionTransform(imageView.imageName, cameraToImageT) pd = filterUtils.transformPolyData(pd, cameraToImageT) pts = vnp.getNumpyFromVtk(pd, 'Points') pts[:,0] /= pts[:,2] pts[:,1] /= pts[:,2] pd.GetPointData().SetNormals(normals) ''' self.imageQueue.projectPoints(imageView.imageName, pd) cameraObj.setPolyData(pd) self.addActorToImageOverlay(cameraObj, imageView)
def promotePolyDataItem(cls, obj): parent = obj.parent() view = obj.views[0] name = obj.getProperty('Name') polyData = obj.polyData props = obj.properties._properties childFrame = obj.getChildFrame() if childFrame: t = transformUtils.copyFrame(childFrame.transform) else: t = vtk.vtkTransform() t.PostMultiply() t.Translate(filterUtils.computeCentroid(polyData)) polyData = filterUtils.transformPolyData(polyData, t.GetLinearInverse()) children = [c for c in obj.children() if c is not childFrame] meshId = cls.getMeshManager().add(polyData) om.removeFromObjectModel(obj) obj = MeshAffordanceItem(name, view) obj.setProperty('Filename', meshId) om.addToObjectModel(obj, parentObj=parent) frame = vis.addChildFrame(obj) frame.copyFrame(t) for child in children: om.addToObjectModel(child, parentObj=obj) obj.syncProperties(props) return obj
def transformGeometry(polyDataList, geom): t = transformUtils.transformFromPose(geom.position, geom.quaternion) polyDataList = [ filterUtils.transformPolyData(polyData, t) for polyData in polyDataList ] return polyDataList
def buildRobot(x=0, y=0): #print "building robot" polyData = ioUtils.readPolyData('celica.obj') scale = 0.04 t = vtk.vtkTransform() t.RotateZ(90) t.Scale(scale, scale, scale) polyData = filterUtils.transformPolyData(polyData, t) #d = DebugData() #d.addCone((x,y,0), (1,0,0), height=0.2, radius=0.1) #polyData = d.getPolyData() obj = vis.showPolyData(polyData, 'robot') robotFrame = vis.addChildFrame(obj) # this makes sure we can only rotate it in two dimensions robotFrame.setProperty('Scale', 3) robotFrame.setProperty('Edit', True) robotFrame.widget.HandleRotationEnabledOff() rep = robotFrame.widget.GetRepresentation() rep.SetTranslateAxisEnabled(2, False) rep.SetRotateAxisEnabled(0, False) rep.SetRotateAxisEnabled(1, False) return obj, robotFrame
def newPolyData(self, name, view, parent=None): self.handModel.model.setJointPositions( np.zeros(self.handModel.model.numberOfJoints())) polyData = vtk.vtkPolyData() self.handModel.model.getModelMesh(polyData) polyData = filterUtils.transformPolyData(polyData, self.modelToPalm) if isinstance(parent, str): parent = om.getOrCreateContainer(parent) color = [1.0, 1.0, 0.0] if self.side == 'right': color = [0.33, 1.0, 0.0] obj = vis.showPolyData(polyData, name, view=view, color=color, visible=False, parent=parent) obj.side = self.side frame = vtk.vtkTransform() frame.PostMultiply() obj.actor.SetUserTransform(frame) frameObj = vis.showFrame(frame, '%s frame' % name, view=view, scale=0.2, visible=False, parent=obj) return obj
def drawObjectInCamera(objectName,visible=True): v = imageView.view q = cameraview.imageManager.queue localToCameraT = vtk.vtkTransform() q.getTransform('local', 'CAMERA_LEFT', localToCameraT) obj = om.findObjectByName(objectName) if obj is None: return objToLocalT = transformUtils.copyFrame(obj.actor.GetUserTransform() or vtk.vtkTransform()) objPolyDataOriginal = obj.polyData pd = objPolyDataOriginal pd = filterUtils.transformPolyData(pd, objToLocalT) pd = filterUtils.transformPolyData(pd, localToCameraT) q.projectPoints('CAMERA_LEFT', pd) vis.showPolyData(pd, ('overlay ' + objectName), view=v, color=[0,1,0],parent='camera overlay',visible=visible)
def showFusedMaps(self): om.removeFromObjectModel(om.findObjectByName('stereo')) om.getOrCreateContainer('stereo') q = imageManager.queue cameraToLocalNow = vtk.vtkTransform() utime = q.getCurrentImageTime('CAMERA_TSDF') q.getTransform('CAMERA_LEFT', 'local', utime, cameraToLocalNow) cameraToLocalFusedNow = vtk.vtkTransform() q.getTransform('CAMERA_LEFT_ALT', 'local', utime, cameraToLocalFusedNow) for i in range(len(self.pointClouds)): fusedNowToLocalNow = vtk.vtkTransform() fusedNowToLocalNow.PreMultiply() fusedNowToLocalNow.Concatenate(cameraToLocalNow) fusedNowToLocalNow.Concatenate( cameraToLocalFusedNow.GetLinearInverse()) fusedTransform = vtk.vtkTransform() fusedTransform.PreMultiply() fusedTransform.Concatenate(fusedNowToLocalNow) fusedTransform.Concatenate(self.cameraToLocalFusedTransforms[i]) pd = filterUtils.transformPolyData(self.pointClouds[i], fusedTransform) vis.showFrame(fusedTransform, ('cloud frame ' + str(i)), visible=True, scale=0.2, parent='stereo') vis.showPolyData(pd, ('stereo ' + str(i)), parent='stereo', colorByName='rgb_colors')
def showFusedMaps(self): om.removeFromObjectModel(om.findObjectByName('stereo')) om.getOrCreateContainer('stereo') q = imageManager.queue cameraToLocalNow = vtk.vtkTransform() utime = q.getCurrentImageTime('CAMERA_TSDF') q.getTransform('CAMERA_LEFT','local', utime,cameraToLocalNow) cameraToLocalFusedNow = vtk.vtkTransform() q.getTransform('CAMERA_LEFT_ALT','local', utime,cameraToLocalFusedNow) for i in range(len(self.pointClouds)): fusedNowToLocalNow = vtk.vtkTransform() fusedNowToLocalNow.PreMultiply() fusedNowToLocalNow.Concatenate( cameraToLocalNow) fusedNowToLocalNow.Concatenate( cameraToLocalFusedNow.GetLinearInverse() ) fusedTransform = vtk.vtkTransform() fusedTransform.PreMultiply() fusedTransform.Concatenate( fusedNowToLocalNow) fusedTransform.Concatenate( self.cameraToLocalFusedTransforms[i] ) pd = filterUtils.transformPolyData(self.pointClouds[i], fusedTransform) vis.showFrame(fusedTransform, ('cloud frame ' + str(i)), visible=True, scale=0.2, parent='stereo') vis.showPolyData(pd, ('stereo ' + str(i)), parent='stereo', colorByName='rgb_colors')
def setPolyData(self, polyData): if polyData.GetNumberOfPoints(): originPose = self.getProperty('Origin') pos, quat = originPose[:3], originPose[3:] t = transformUtils.transformFromPose(pos, quat) polyData = filterUtils.transformPolyData(polyData, t.GetLinearInverse()) PolyDataItem.setPolyData(self, polyData)
def scaleGeometry(polyDataList, geom): scale = geom.float_data[0] if scale != 1.0: t = vtk.vtkTransform() t.Scale(scale, scale, scale) polyDataList = [filterUtils.transformPolyData(polyData, t) for polyData in polyDataList] return polyDataList
def loadMap(self, filename, transform=None): print filename pd = io.readPolyData(filename) if transform is not None: pd = filterUtils.transformPolyData(pd, self.cameraToLocalInit) pdi = vis.updatePolyData(pd, 'map') try: pdi.setProperty('Color By', 'rgb_colors') except Exception, e: print "Could not set color to RGB - not an element" #raise e
def onShowMapButton(self): vis.updateFrame(self.cameraToLocalInit, 'initial cam' ) filename = os.path.expanduser('~/Kinect_Logs/Kintinuous.pcd') print filename pd = io.readPolyData(filename) pd = filterUtils.transformPolyData(pd, self.cameraToLocalInit ) #t = transformUtils.frameFromPositionAndRPY([0,0,0],[-90,0,-90]) #pd = filterUtils.transformPolyData(pd , t) pdi = vis.updatePolyData(pd,'map') pdi.setProperty('Color By', 'rgb_colors')
def loadFootMeshes(): meshes = [] for i in range(0,2): d = DebugData() for footMeshFile in _footMeshFiles[i]: d.addPolyData(ioUtils.readPolyData( footMeshFile , computeNormals=True)) t = vtk.vtkTransform() t.Scale(0.98, 0.98, 0.98) pd = filterUtils.transformPolyData(d.getPolyData(), t) meshes.append(pd) return meshes
def _updateSource(self): p = vtk.vtkPolyData() utime = self.PointCloudQueue.getPointCloudFromPointCloud(p) if not p.GetNumberOfPoints(): return sensorToLocalFused = vtk.vtkTransform() self.queue.getTransform('VELODYNE', 'local', utime, sensorToLocalFused) p = filterUtils.transformPolyData(p,sensorToLocalFused) self.polyDataObj.setPolyData(p) if not self.polyDataObj.initialized: self.polyDataObj.initialized = True
def _updateSource(self): p = vtk.vtkPolyData() utime = self.PointCloudQueue.getPointCloudFromPointCloud(p) if not p.GetNumberOfPoints(): return sensorToLocalFused = vtk.vtkTransform() self.queue.getTransform('VELODYNE', 'local', utime, sensorToLocalFused) p = filterUtils.transformPolyData(p, sensorToLocalFused) self.polyDataObj.setPolyData(p) if not self.polyDataObj.initialized: self.polyDataObj.initialized = True
def _updateSource(self): p = vtk.vtkPolyData() utime = self.KinectQueue.getPointCloudFromKinect(p) if not p.GetNumberOfPoints(): return cameraToLocalFused = vtk.vtkTransform() self.queue.getTransform('KINECT_RGB', 'local', utime, cameraToLocalFused) p = filterUtils.transformPolyData(p,cameraToLocalFused) self.polyDataObj.setPolyData(p) if not self.polyDataObj.initialized: self.polyDataObj.setProperty('Color By', 'rgb_colors') self.polyDataObj.initialized = True
def getStereoPointCloud(decimation=4, imagesChannel='CAMERA', cameraName='CAMERA_LEFT', removeSize=0): q = imageManager.queue utime = q.getCurrentImageTime(cameraName) if utime == 0: return None p = vtk.vtkPolyData() cameraToLocal = vtk.vtkTransform() q.getPointCloudFromImages(imagesChannel, p, decimation, removeSize) q.getTransform('CAMERA_LEFT', 'local', utime, cameraToLocal) p = filterUtils.transformPolyData(p, cameraToLocal) return p
def scaleGeometry(polyDataList, geom): if len(geom.float_data) == 1: scale_x = scale_y = scale_z = geom.float_data[0] elif len(geom.float_data) == 3: scale_x = geom.float_data[0] scale_y = geom.float_data[1] scale_z = geom.float_data[2] else: scale_x = scale_y = scale_z = 1.0 if scale_x != 1.0 or scale_y != 1.0 or scale_z != 1.0: t = vtk.vtkTransform() t.Scale(scale_x, scale_y, scale_z) polyDataList = [filterUtils.transformPolyData(polyData, t) for polyData in polyDataList] return polyDataList
def _updateSource(self): p = vtk.vtkPolyData() utime = self.KinectQueue.getPointCloudFromKinect(p) if not p.GetNumberOfPoints(): return cameraToLocalFused = vtk.vtkTransform() self.queue.getTransform('KINECT_RGB', 'local', utime, cameraToLocalFused) p = filterUtils.transformPolyData(p, cameraToLocalFused) self.polyDataObj.setPolyData(p) if not self.polyDataObj.initialized: self.polyDataObj.setProperty('Color By', 'rgb_colors') self.polyDataObj.initialized = True
def buildRobot(x=0,y=0): #print "building robot" polyData = ioUtils.readPolyData('celica.obj') scale = 0.04 t = vtk.vtkTransform() t.RotateZ(90) t.Scale(scale, scale, scale) polyData = filterUtils.transformPolyData(polyData, t) #d = DebugData() #d.addCone((x,y,0), (1,0,0), height=0.2, radius=0.1) #polyData = d.getPolyData() obj = vis.showPolyData(polyData, 'robot') robotFrame = vis.addChildFrame(obj) return obj, robotFrame
def buildRobot(x=0, y=0): #print "building robot" polyData = ioUtils.readPolyData('crazyflie.obj') scale = 0.01 t = vtk.vtkTransform() t.RotateX(90) t.Scale(scale, scale, scale) polyData = filterUtils.transformPolyData(polyData, t) #d = DebugData() #d.addCone((x,y,0), (1,0,0), height=0.2, radius=0.1) #polyData = d.getPolyData() obj = vis.showPolyData(polyData, 'robot') robotFrame = vis.addChildFrame(obj) return obj, robotFrame
def createSkyboxPlane(side): pd = createTexturedPlane() t = vtk.vtkTransform() t.PostMultiply() if side == 'top': t.Translate(0, 0, 0.5) t.RotateZ(180) elif side == 'bottom': t.RotateX(180) t.RotateY(180) t.RotateZ(-270) t.Translate(0, 0, -0.5) elif side == 'front': t.RotateY(90) t.RotateX(90) t.RotateZ(180) t.Translate(0.5, 0.0, 0.0) elif side == 'back': t.RotateY(90) t.RotateX(90) t.RotateZ(0) t.Translate(-0.5, 0.0, 0.0) elif side == 'left': t.RotateY(90) t.RotateX(90) t.RotateZ(-90) t.Translate(0.0, 0.5, 0.0) elif side == 'right': t.RotateY(90) t.RotateX(90) t.RotateZ(90) t.Translate(0.0, -0.5, 0.0) pd = filterUtils.transformPolyData(pd, t) return pd
def createTextureGround(imageFilename, view): pd = createTexturedPlane() texture = createTexture(imageFilename) texture.RepeatOn() tcoords = vnp.getNumpyFromVtk(pd, 'Texture Coordinates') tcoords *= 60 t = vtk.vtkTransform() t.PostMultiply() t.Scale(200,200,200) t.Translate(0,0,-0.005) pd = filterUtils.transformPolyData(pd, t) obj = vis.showPolyData(pd, 'ground', view=view, alpha=1.0, parent='skybox') obj.actor.SetTexture(texture) obj.actor.GetProperty().LightingOff()
def createSkyboxPlane(side): pd = createTexturedPlane() t = vtk.vtkTransform() t.PostMultiply() if side == 'top': t.Translate(0,0,0.5) t.RotateZ(180) elif side == 'bottom': t.RotateX(180) t.RotateY(180) t.RotateZ(-270) t.Translate(0,0,-0.5) elif side == 'front': t.RotateY(90) t.RotateX(90) t.RotateZ(180) t.Translate(0.5,0.0,0.0) elif side == 'back': t.RotateY(90) t.RotateX(90) t.RotateZ(0) t.Translate(-0.5,0.0,0.0) elif side == 'left': t.RotateY(90) t.RotateX(90) t.RotateZ(-90) t.Translate(0.0,0.5,0.0) elif side == 'right': t.RotateY(90) t.RotateX(90) t.RotateZ(90) t.Translate(0.0,-0.5,0.0) pd = filterUtils.transformPolyData(pd, t) return pd
def newPolyData(self, name, view, parent=None): self.handModel.model.setJointPositions(np.zeros(self.handModel.model.numberOfJoints())) polyData = vtk.vtkPolyData() self.handModel.model.getModelMesh(polyData) polyData = filterUtils.transformPolyData(polyData, self.modelToPalm) if isinstance(parent, str): parent = om.getOrCreateContainer(parent) color = [1.0, 1.0, 0.0] if self.side == 'right': color = [0.33, 1.0, 0.0] obj = vis.showPolyData(polyData, name, view=view, color=color, visible=False, parent=parent) obj.side = self.side frame = vtk.vtkTransform() frame.PostMultiply() obj.actor.SetUserTransform(frame) frameObj = vis.showFrame(frame, '%s frame' % name, view=view, scale=0.2, visible=False, parent=obj) return obj
def createTextureGround(imageFilename, view): pd = createTexturedPlane() texture = createTexture(imageFilename) texture.RepeatOn() tcoords = vnp.getNumpyFromVtk(pd, 'Texture Coordinates') tcoords *= 60 t = vtk.vtkTransform() t.PostMultiply() t.Scale(200, 200, 200) t.Translate(0, 0, -0.005) pd = filterUtils.transformPolyData(pd, t) obj = vis.showPolyData(pd, 'ground', view=view, alpha=1.0, parent='skybox') obj.actor.SetTexture(texture) obj.actor.GetProperty().LightingOff()
def getNewHandPolyData(self): self.handModel.model.setJointPositions(np.zeros(self.handModel.model.numberOfJoints())) polyData = vtk.vtkPolyData() self.handModel.model.getModelMesh(polyData) return filterUtils.transformPolyData(polyData, self.modelToPalm)
def transformGeometry(polyDataList, geom): t = transformUtils.transformFromPose(geom.position, geom.quaternion) polyDataList = [filterUtils.transformPolyData(polyData, t) for polyData in polyDataList] return polyDataList
def getNewHandPolyData(self): self.handModel.model.setJointPositions( np.zeros(self.handModel.model.numberOfJoints())) polyData = vtk.vtkPolyData() self.handModel.model.getModelMesh(polyData) return filterUtils.transformPolyData(polyData, self.modelToPalm)