def add_eye_ball(self, pose, orientation): # Eye ball sphere = vtk.vtkSphereSource() sphere.SetThetaResolution(64) sphere.SetPhiResolution(64) sphere.SetRadius(0.5) reader = vtk.vtkJPEGReader() reader.SetFileName(os.path.join(rospkg.RosPack().get_path('motion_renderer'), 'resource', 'green_eye.jpg')) texture = vtk.vtkTexture() texture.SetInputConnection(reader.GetOutputPort()) map_to_sphere = vtk.vtkTextureMapToSphere() map_to_sphere.SetInputConnection(sphere.GetOutputPort()) map_to_sphere.PreventSeamOn() xform = vtk.vtkTransformTextureCoords() xform.SetInputConnection(map_to_sphere.GetOutputPort()) xform.SetScale(1.5, 1.5, 1) mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(xform.GetOutputPort()) # Left Eye Actor eye_actor = vtk.vtkActor() eye_actor.SetMapper(mapper) eye_actor.SetTexture(texture) eye_actor.SetPosition(pose[0], pose[1], pose[2]) eye_actor.RotateX(orientation[0]) eye_actor.RotateY(orientation[1]) eye_actor.RotateZ(orientation[2]) self.ren.AddActor(eye_actor) return eye_actor
def GridSurface(self): #---------------------------------------------------------------------- # ELECTRODE CONTACT DELAUNAY TRIANGULATION ---------------------------- deln = vtk.vtkDelaunay3D() deln.SetInput(self.electrodePolyData) deln.SetTolerance(0.01) tmapper = vtk.vtkTextureMapToSphere() tmapper.SetInputConnection(deln.GetOutputPort()) #tmapper.PreventSeamOn() mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(tmapper.GetOutputPort()) # TEST TEXTURE PART atext = vtk.vtkOpenGLTexture() self.contactScalarData = vtk.vtkDoubleArray() self.contactScalarData.SetNumberOfComponents(1) for tupleID in range(self.electrodePolyData.GetNumberOfPoints()): self.contactScalarData.InsertNextValue(random.uniform(0, 1)) self.UpdateGridSurface() atext.SetInput(self.electrodePolyData) self.triangulation = vtk.vtkOpenGLActor() self.triangulation.SetMapper(mapper) self.triangulation.SetTexture(atext) self.triangulation.GetProperty().SetOpacity(1)
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__( self, module_manager, vtk.vtkTextureMapToSphere(), 'Processing.', ('vtkDataSet',), ('vtkDataSet',), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def getSphericalMap( self, **args ): thetaResolution = args.get( "thetaRes", 32 ) phiResolution = args.get( "phiRes", 32 ) radius = args.get( "radius", 100 ) if self.sphereActor == None: self.sphere = vtk.vtkSphereSource() self.sphere.SetThetaResolution( thetaResolution ) self.sphere.SetPhiResolution( phiResolution ) self.sphere.SetRadius( radius ) self.sphere.SetEndTheta( 359.999 ) mesh = self.sphere.GetOutput() self.sphereTexmapper = vtk.vtkTextureMapToSphere() if vtk.VTK_MAJOR_VERSION <= 5: self.sphereTexmapper.SetInput(mesh) else: self.sphereTexmapper.SetInputData(mesh) self.sphereTexmapper.PreventSeamOff() self.sphereMapper = vtk.vtkPolyDataMapper() self.sphereMapper.SetInputConnection(self.sphereTexmapper.GetOutputPort()) imageFlipper = vtk.vtkImageFlip() if vtk.VTK_MAJOR_VERSION <= 5: imageFlipper.SetInput(self.sphericalBaseImage) else: imageFlipper.SetInputData(self.sphericalBaseImage) imageFlipper.SetFilteredAxis( 1 ) self.sphereTexture = vtk.vtkTexture() self.sphereTexture.SetInputConnection( imageFlipper.GetOutputPort() ) self.sphereActor = vtk.vtkActor() self.sphereActor.SetMapper(self.sphereMapper) self.sphereActor.SetTexture(self.sphereTexture) # self.sphereActor.GetProperty().SetOpacity( self.map_opacity ) self.sphereActor.SetVisibility( False ) return self.sphereActor
def __init__(self, module_manager): SimpleVTKClassModuleBase.__init__(self, module_manager, vtk.vtkTextureMapToSphere(), 'Processing.', ('vtkDataSet', ), ('vtkDataSet', ), replaceDoc=True, inputFunctions=None, outputFunctions=None)
def sphere(radius, theta, phi): sphere_shape = vtk.vtkSphereSource() sphere_shape.SetRadius(radius) sphere_shape.SetThetaResolution(theta) sphere_shape.SetPhiResolution(phi) map_to_sphere = vtk.vtkTextureMapToSphere() map_to_sphere.SetInputConnection(sphere_shape.GetOutputPort()) map_to_sphere.PreventSeamOn() mapp_object = vtk.vtkPolyDataMapper() mapp_object.SetInputConnection(map_to_sphere.GetOutputPort()) return mapp_object
def main(): colors = vtk.vtkNamedColors() jpegfile = get_program_parameters() # Create a render window ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) renWin.SetSize(480, 480) renWin.SetWindowName('SphereTexture') iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # Generate an sphere polydata sphere = vtk.vtkSphereSource() sphere.SetThetaResolution(12) sphere.SetPhiResolution(12) # Read the image data from a file reader = vtk.vtkJPEGReader() reader.SetFileName(jpegfile) # Create texture object texture = vtk.vtkTexture() texture.SetInputConnection(reader.GetOutputPort()) # Map texture coordinates map_to_sphere = vtk.vtkTextureMapToSphere() map_to_sphere.SetInputConnection(sphere.GetOutputPort()) map_to_sphere.PreventSeamOn() # Create mapper and set the mapped texture as input mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(map_to_sphere.GetOutputPort()) # Create actor and set the mapper and the texture actor = vtk.vtkActor() actor.SetMapper(mapper) actor.SetTexture(texture) ren.AddActor(actor) ren.SetBackground(colors.GetColor3d('RosyBrown')) iren.Initialize() renWin.Render() iren.Start()
def assignTexture(actor, name, scale=1, falsecolors=False, mapTo=1): '''Assign a texture to actor from file or name in /textures directory''' if mapTo == 1: tmapper = vtk.vtkTextureMapToCylinder() elif mapTo == 2: tmapper = vtk.vtkTextureMapToSphere() elif mapTo == 3: tmapper = vtk.vtkTextureMapToPlane() setInput(tmapper, polydata(actor)) if mapTo == 1: tmapper.PreventSeamOn() xform = vtk.vtkTransformTextureCoords() xform.SetInputConnection(tmapper.GetOutputPort()) xform.SetScale(scale, scale, scale) if mapTo == 1: xform.FlipSOn() xform.Update() mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(xform.GetOutputPort()) mapper.ScalarVisibilityOff() cdir = os.path.dirname(__file__) if cdir == '': cdir = '.' fn = cdir + '/textures/' + name + ".jpg" if os.path.exists(name): fn = name elif not os.path.exists(fn): colors.printc(('Texture', name, 'not found in', cdir + '/textures'), 'r') colors.printc('Available textures:', c='m', end=' ') for ff in os.listdir(cdir + '/textures'): colors.printc(ff.split('.')[0], end=' ', c='m') print() return jpgReader = vtk.vtkJPEGReader() jpgReader.SetFileName(fn) atext = vtk.vtkTexture() atext.RepeatOn() atext.EdgeClampOff() atext.InterpolateOn() if falsecolors: atext.MapColorScalarsThroughLookupTableOn() atext.SetInputConnection(jpgReader.GetOutputPort()) actor.GetProperty().SetColor(1, 1, 1) actor.SetMapper(mapper) actor.SetTexture(atext)
def TextureMapToSphere(self, currentElement): tmapper = vtk.vtkTextureMapToSphere() # Datatype(s) I need for input: Algorithm AlgorithmElement = '' for childElement in currentElement.getchildren(): if childElement.tag in vtkTypes['Algorithm']: AlgorithmElement = childElement if AlgorithmElement != '': dataset = self.namesToFunctions[childElement.tag](childElement) try: tmapper.SetInputConnection(dataset.GetOutputPort()) except: self.logger.error(' .. <TextureMapToSphere> failed to SetInputConnection') if 'SetPreventSeam' in currentElement.keys(): try: tmapper.SetPreventSeam( int(currentElement.get('SetPreventSeam')) ) except: self.logger.error(' .. <TextureMapToSphere> failed to SetPreventSeam') else: self.logger.error(' .. <TextureMapToSphere> needs an Algorithm-type childnode') return tmapper
def createActor(self): reader = vtk.vtkJPEGReader() reader.SetFileName("padoru.jpg") texture = vtk.vtkTexture() # Create texture object texture.SetInputConnection(reader.GetOutputPort()) map_to_sphere = vtk.vtkTextureMapToSphere() map_to_sphere.SetInputConnection(self.source1.GetOutputPort()) sphere_mapper = vtk.vtkPolyDataMapper() sphere_mapper.SetInputConnection(map_to_sphere.GetOutputPort()) self.sphere_actor.SetMapper(sphere_mapper) self.sphere_actor.SetTexture(texture) #self.sphere_actor.GetProperty().SetColor(1, 0, 0.0) self.sphere_actor.SetPosition(self.pos[0], self.pos[1], self.pos[2])
def getSphericalMap(self, **args): thetaResolution = args.get("thetaRes", 32) phiResolution = args.get("phiRes", 32) radius = args.get("radius", 100) if self.sphereActor == None: self.sphere = vtk.vtkSphereSource() self.sphere.SetThetaResolution(thetaResolution) self.sphere.SetPhiResolution(phiResolution) self.sphere.SetRadius(radius) self.sphere.SetEndTheta(359.999) self.sphere.Update() mesh = self.sphere.GetOutput() self.sphereTexmapper = vtk.vtkTextureMapToSphere() if vtk.VTK_MAJOR_VERSION <= 5: self.sphereTexmapper.SetInput(mesh) else: self.sphereTexmapper.SetInputData(mesh) self.sphereTexmapper.PreventSeamOff() self.sphereMapper = vtk.vtkPolyDataMapper() self.sphereMapper.SetInputConnection( self.sphereTexmapper.GetOutputPort()) imageFlipper = vtk.vtkImageFlip() if vtk.VTK_MAJOR_VERSION <= 5: imageFlipper.SetInput(self.sphericalBaseImage) else: imageFlipper.SetInputData(self.sphericalBaseImage) imageFlipper.SetFilteredAxis(1) self.sphereTexture = vtk.vtkTexture() self.sphereTexture.SetInputConnection(imageFlipper.GetOutputPort()) self.sphereActor = vtk.vtkActor() self.sphereActor.SetMapper(self.sphereMapper) self.sphereActor.SetTexture(self.sphereTexture) # self.sphereActor.GetProperty().SetOpacity( self.map_opacity ) self.sphereActor.SetVisibility(False) return self.sphereActor
def addEarth(): # 加入球体 sphereSource2 = vtk.vtkSphereSource() sphereSource2.SetCenter(0.0, 0.0, 0.0) # 球体中心点 sphereSource2.SetRadius(0.2) # 球体半径 # Make the surface smooth. sphereSource2.SetPhiResolution(100) sphereSource2.SetThetaResolution(100) map_to_sphere = vtk.vtkTextureMapToSphere() map_to_sphere.SetInputConnection(sphereSource2.GetOutputPort()) map_to_sphere.PreventSeamOff() # Read the image data from a file reader = vtk.vtkJPEGReader() reader.SetFileName('./data/under.jpg') # Create texture object texture = vtk.vtkTexture() texture.SetInputConnection(reader.GetOutputPort()) mapper3 = vtk.vtkPolyDataMapper() mapper3.SetInputConnection(map_to_sphere.GetOutputPort()) sphere_Actor2 = vtk.vtkActor() sphere_Actor2.SetMapper(mapper3) sphere_Actor2.SetTexture(texture) return sphere_Actor2
imageReader = readerFactory.CreateImageReader2(textureName) imageReader.SetFileName(textureName) # Create texture texture = vtk.vtkTexture() #texture = vtk.vtkOpenGLTexture() texture.SetInputConnection(imageReader.GetOutputPort()) texture.SetQuality(32) # Wrap with sphere # Delaynay deln = vtk.vtkDelaunay3D() deln.SetInputConnection(meshReader.GetOutputPort()) deln.SetTolerance(0.01) tmapper = vtk.vtkTextureMapToSphere() #tmapper.SetInputConnection(deln.GetOutputPort()) tmapper.SetInputConnection(meshReader.GetOutputPort()) #tmapper.PreventSeamOn() mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(tmapper.GetOutputPort()) triangulation = vtk.vtkOpenGLActor() triangulation.SetMapper(mapper) triangulation.SetTexture(texture) triangulation.GetProperty().SetOpacity(1) renderer = vtk.vtkRenderer() renderer.AddActor(triangulation) renderer.SetBackground(colors.GetColor3d("Black"))
vertexColors.InsertNextValue(2) vertexColors.InsertNextValue(2) vertexColors.InsertNextValue(2) vertexColors.InsertNextValue(2) vertexColors.InsertNextValue(2) vertexColors.InsertNextValue(2) vertexColors.InsertNextValue(2) vertexColors.InsertNextValue(2) vertexColors.InsertNextValue(2) vertexColors.InsertNextValue(2) model = vtk.vtkPolyData() model.SetPolys(faces) model.SetPoints(points) model.GetCellData().SetScalars(faceColors) model.GetPointData().SetScalars(vertexColors) ballTC = vtk.vtkTextureMapToSphere() ballTC.SetInputData(model) lut = vtk.vtkLookupTable() lut.SetNumberOfColors(3) lut.Build() lut.SetTableValue(0,0,0,0,1) lut.SetTableValue(1,1,.3,.3,1) lut.SetTableValue(2,.8,.8,.9,1) mapper = vtk.vtkDataSetMapper() mapper.SetInputConnection(ballTC.GetOutputPort()) mapper.SetScalarModeToUseCellData() mapper.SetLookupTable(lut) mapper.SetScalarRange(0,2) earth = vtk.vtkPNMReader() earth.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/earth.ppm") texture = vtk.vtkTexture()
renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # read the volume reader = vtk.vtkJPEGReader() reader.SetFileName(VTK_DATA_ROOT + "/Data/beach.jpg") #--------------------------------------------------------- # Do the surface rendering sphereSource = vtk.vtkSphereSource() sphereSource.SetRadius(100) textureSphere = vtk.vtkTextureMapToSphere() textureSphere.SetInputConnection(sphereSource.GetOutputPort()) sphereStripper = vtk.vtkStripper() sphereStripper.SetInputConnection(textureSphere.GetOutputPort()) sphereStripper.SetMaximumLength(5) sphereMapper = vtk.vtkPolyDataMapper() sphereMapper.SetInputConnection(sphereStripper.GetOutputPort()) sphereMapper.ScalarVisibilityOff() sphereTexture = vtk.vtkTexture() sphereTexture.SetInputConnection(reader.GetOutputPort()) sphereProperty = vtk.vtkProperty() sphereProperty.BackfaceCullingOn()
sphere.SetThetaResolution(12) sphere.SetPhiResolution(12) # Read the image data from a file reader = vtk.vtkJPEGReader() reader.SetFileName(jpegfile) # Create texture object texture = vtk.vtkTexture() if vtk.VTK_MAJOR_VERSION <= 5: texture.SetInput(reader.GetOutput()) else: texture.SetInputConnection(reader.GetOutputPort()) # Map texture coordinates map_to_sphere = vtk.vtkTextureMapToSphere() if vtk.VTK_MAJOR_VERSION <= 5: map_to_sphere.SetInput(sphere.GetOutput()) else: map_to_sphere.SetInputConnection(sphere.GetOutputPort()) map_to_sphere.PreventSeamOn() # Create mapper and set the mapped texture as input mapper = vtk.vtkPolyDataMapper() if vtk.VTK_MAJOR_VERSION <= 5: mapper.SetInput(map_to_sphere.GetOutput()) else: mapper.SetInputConnection(map_to_sphere.GetOutputPort()) # Create actor and set the mapper and the texture actor = vtk.vtkActor()
def main(): colors = vtk.vtkNamedColors() jpgfile = "texture_bola.jpg" reader = vtk.vtkJPEGReader() reader.SetFileName(jpgfile) # Create a sphere sphereSource = vtk.vtkSphereSource() sphereSource.SetCenter(0.0, 0.0, 0.0) sphereSource.SetRadius(radio) sphereSource.SetPhiResolution(300) sphereSource.SetThetaResolution(300) # Create a pared1 pared1 = vtk.vtkCubeSource() pared1.SetXLength(3100) pared1.SetYLength(250) pared1.SetZLength(100) pared1.Update() # Create a pared1 pared2 = vtk.vtkCubeSource() pared2.SetXLength(3100) pared2.SetYLength(250) pared2.SetZLength(100) pared2.Update() # Create a pared1 pared3 = vtk.vtkCubeSource() pared3.SetXLength(100) pared3.SetYLength(250) pared3.SetZLength(3100) pared3.Update() # Create a pared1 pared4 = vtk.vtkCubeSource() pared4.SetXLength(100) pared4.SetYLength(250) pared4.SetZLength(3100) pared4.Update() # Create a pared1 pared5 = vtk.vtkCubeSource() pared5.SetXLength(3000) pared5.SetYLength(radio / 2) pared5.SetZLength(3000) pared5.Update() texture = vtk.vtkTexture() texture.SetInputConnection(reader.GetOutputPort()) map_to_sphere = vtk.vtkTextureMapToSphere() map_to_sphere.SetInputConnection(sphereSource.GetOutputPort()) # Create a mapper and actor mapper1 = vtk.vtkPolyDataMapper() mapper1.SetInputConnection(map_to_sphere.GetOutputPort()) # Create mapper mapper2 = vtk.vtkPolyDataMapper() mapper2.SetInputData(pared1.GetOutput()) # Create mapper mapper3 = vtk.vtkPolyDataMapper() mapper3.SetInputData(pared2.GetOutput()) # Create mapper mapper4 = vtk.vtkPolyDataMapper() mapper4.SetInputData(pared3.GetOutput()) # Create mapper mapper5 = vtk.vtkPolyDataMapper() mapper5.SetInputData(pared4.GetOutput()) # Create mapper mapper6 = vtk.vtkPolyDataMapper() mapper6.SetInputData(pared5.GetOutput()) actor1 = vtk.vtkActor() #actor1.GetProperty().SetColor(colors.GetColor3d("Peacock")) actor1.GetProperty().SetSpecular(0.6) actor1.GetProperty().SetSpecularPower(30) actor1.SetPosition(0, radio, 0) actor1.SetMapper(mapper1) actor1.SetTexture(texture) actor2 = vtk.vtkActor() actor2.SetMapper(mapper2) actor2.GetProperty().SetColor(173 / 255, 114 / 255, 4 / 255) actor2.SetPosition(0, 0, -1500) actor3 = vtk.vtkActor() actor3.SetMapper(mapper3) actor3.GetProperty().SetColor(173 / 255, 114 / 255, 4 / 255) actor3.SetPosition(0, 0, 1500) actor4 = vtk.vtkActor() actor4.SetMapper(mapper4) actor4.GetProperty().SetColor(173 / 255, 114 / 255, 4 / 255) actor4.SetPosition(-1500, 0, 0) actor5 = vtk.vtkActor() actor5.SetMapper(mapper5) actor5.GetProperty().SetColor(173 / 255, 114 / 255, 4 / 255) actor5.SetPosition(1500, 0, 0) actor6 = vtk.vtkActor() actor6.SetMapper(mapper6) actor6.GetProperty().SetColor(24 / 255, 173 / 255, 4 / 255) actor6.SetPosition(0, -radio / 2, 0) # Setup a renderer, render window, and interactor renderer = vtk.vtkRenderer() renderer.SetBackground(colors.GetColor3d("Black")) renderWindow = vtk.vtkRenderWindow() renderWindow.SetWindowName("Tarea 2") renderWindow.SetSize(1600, 900) renderWindow.AddRenderer(renderer) renderWindowInteractor = vtk.vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) # Add the actor to the scene renderer.AddActor(actor1) renderer.AddActor(actor2) renderer.AddActor(actor3) renderer.AddActor(actor4) renderer.AddActor(actor5) renderer.AddActor(actor6) # Render and interact renderWindow.Render() renderer.GetActiveCamera().Zoom(1) renderWindow.Render() renderer.GetActiveCamera().SetPosition(2000, 7000, 7000) renderWindow.Render() # Initialize must be called prior to creating timer events. renderWindowInteractor.Initialize() # Sign up to receive TimerEvent #tiempo_simulado, actor, window, posicionX, velocidadX, posicionY, velocidadY, rebote ,rugosidad cb = vtkTimerCallback(3000, actor1, renderWindowInteractor, 0, 1, 0, 3, 0.99, 0.000002) renderWindowInteractor.AddObserver('TimerEvent', cb.execute) cb.timerId = renderWindowInteractor.CreateRepeatingTimer(500) # start the interaction and timer renderWindow.Render() renderWindowInteractor.Start()
ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # read the volume reader = vtk.vtkJPEGReader() reader.SetFileName(VTK_DATA_ROOT + "/Data/beach.jpg") #--------------------------------------------------------- # Do the surface rendering sphereSource = vtk.vtkSphereSource() sphereSource.SetRadius(100) textureSphere = vtk.vtkTextureMapToSphere() textureSphere.SetInputConnection(sphereSource.GetOutputPort()) sphereStripper = vtk.vtkStripper() sphereStripper.SetInputConnection(textureSphere.GetOutputPort()) sphereStripper.SetMaximumLength(5) sphereMapper = vtk.vtkPolyDataMapper() sphereMapper.SetInputConnection(sphereStripper.GetOutputPort()) sphereMapper.ScalarVisibilityOff() sphereTexture = vtk.vtkTexture() sphereTexture.SetInputConnection(reader.GetOutputPort()) sphereProperty = vtk.vtkProperty() # sphereProperty.BackfaceCullingOn()
#Mond textureMond = vtk.vtkTexture() textureMond.SetInputConnection(readerMond.GetOutputPort()) #Mars textureMars = vtk.vtkTexture() textureMars.SetInputConnection(readerMars.GetOutputPort()) #Venus textureVenus = vtk.vtkTexture() textureVenus.SetInputConnection(readerVenus.GetOutputPort()) ################################################################## # Map texture coordinates #Sonne map_to_sphere_Sonne = vtk.vtkTextureMapToSphere() map_to_sphere_Sonne.SetInputConnection(Sonne.Source.GetOutputPort()) #Erde map_to_sphere_Erde = vtk.vtkTextureMapToSphere() map_to_sphere_Erde.SetInputConnection(transformErdeFilter.GetOutputPort()) #Mond map_to_sphere_Mond = vtk.vtkTextureMapToSphere() map_to_sphere_Mond.SetInputConnection(transformMondFilter.GetOutputPort()) #Mars map_to_sphere_Mars = vtk.vtkTextureMapToSphere() map_to_sphere_Mars.SetInputConnection(transformMarsFilter.GetOutputPort()) #Venus