Esempio n. 1
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkTexturedSphereSource(), 'Processing.',
         (), ('vtkPolyData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
Esempio n. 2
0
    def __init__(self, level=0, textureFile=TEXTURE, shift=0.5):

        self.transf = vtk.vtkTransform()
        self.globe = vtk.vtkTexturedSphereSource()
        self.texture = vtk.vtkTexture()

        #self.transf.Scale(0.25, 1., 1.)
        # may need to shift the picture to match the start longitude
        self.transf.Translate(shift, 0., 0.)
        self.texture.SetTransform(self.transf)
        self.texture.SetInterpolate(1)

        if re.search(r'jpe?g', textureFile.split('.')[-1]):
            self.reader = vtk.vtkJPEGReader()
        elif textureFile.split('.')[-1] == 'png':
            self.reader = vtk.vtkPNGReader()

        self.mapper = vtk.vtkPolyDataMapper()
        self.actor = vtk.vtkActor()

        # connect
        self.actor.SetMapper(self.mapper)
        self.actor.SetTexture(self.texture)

        self.mapper.SetInputConnection(self.globe.GetOutputPort())
        self.texture.SetInputConnection(self.reader.GetOutputPort())
        self.reader.SetFileName(textureFile)

        self.globe.SetThetaResolution(256)
        self.globe.SetPhiResolution(128)
        self.globe.SetRadius(1. + 0.01 * level)
Esempio n. 3
0
    def __init_renderer(self, list_of_planets):

        for planet in list_of_planets:
            actor = vtk.vtkActor()
            #sphere = vtk.vtkSphereSource()
            sphere = vtk.vtkTexturedSphereSource()
            mapper = vtk.vtkPolyDataMapper()
            sphere.SetPhiResolution(20)
            sphere.SetThetaResolution(20)
            scaled_radius = planet.get_radius() * self.__scale_planet_radius 
            if(planet.id == 0):
                scaled_radius = planet.get_radius() * self.__scale_sun_radius
            
            sphere.SetRadius(scaled_radius)
            mapper.SetInput(sphere.GetOutput())
            graphic_name = "../textures/"+planet.get_name()+".jpg"
            graphic_reader = vtk.vtkJPEGReader()
            graphic_reader.SetFileName(graphic_name)
            graphic_texture = vtk.vtkTexture()
            graphic_texture.SetInputConnection(graphic_reader.GetOutputPort())
            graphic_texture.InterpolateOn()
            actor.SetTexture(graphic_texture)
            actor.SetMapper(mapper)
            actor.SetScale(1,1,1)
            actor.SetPosition(int(self.__scale_planet_orbit_inner*planet.get_posVector_x()), 
                              int(self.__scale_planet_orbit_inner*planet.get_posVector_y()), 
                              int(self.__scale_planet_orbit_inner*planet.get_posVector_z()))
            self.__renderer.AddActor(actor)
            self.__list_of_actors.append(actor)
Esempio n. 4
0
 def setup(self):
     self.res = 32
     self.height = 0.0005
     self.sphere = self.addPart(ObjectBase(vtk.vtkTexturedSphereSource()))
     self.sphere._source.SetThetaResolution(self.res)
     self.sphere._source.SetPhiResolution(self.res)
     self.sphere._actor.GetProperty().SetColor(0.0, 0.0, 0.4)
     self.earth = self.addPart(ObjectBase(vtk.vtkEarthSource()))
     self.earth._source.SetRadius(0.5 + self.height)
     self.earth._source.SetOnRatio(0)
Esempio n. 5
0
def main(argv):
    colors = vtk.vtkNamedColors()

    if (len(argv) < 2):
        print("Usage: " + argv[0] + " texture(.png/.ppm) e.g. earth.ppm" +
              " [translate]")
        sys.exit(-1)
    translate = [0.0, 0.0, 0.0]
    if len(argv) > 2:
        translate[0] = float(argv[2])
    else:
        translate[0] = 0.0
    translate[1] = 0.0
    translate[2] = 0.0
    print("%f, %f, %f" % (translate[0], translate[1], translate[2]))

    # Create a sphere with texture coordinates
    source = vtk.vtkTexturedSphereSource()
    source.SetThetaResolution(100)
    source.SetPhiResolution(100)

    # Read texture file
    readerFactory = vtk.vtkImageReader2Factory()
    # imageReader = vtk.vtkImageReader2()
    imageReader = readerFactory.CreateImageReader2(argv[1])
    imageReader.SetFileName(argv[1])

    # Create texture
    texture = vtk.vtkTexture()
    texture.SetInputConnection(imageReader.GetOutputPort())

    transformTexture = vtk.vtkTransformTextureCoords()
    transformTexture.SetInputConnection(source.GetOutputPort())
    transformTexture.SetPosition(translate)

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(transformTexture.GetOutputPort())

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.SetTexture(texture)

    renderer = vtk.vtkRenderer()
    renderer.AddActor(actor)
    renderer.SetBackground(colors.GetColor3d("Black"))

    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    renderWindow.SetWindowName("TexturedSphere")

    renWinInteractor = vtk.vtkRenderWindowInteractor()
    renWinInteractor.SetRenderWindow(renderWindow)

    renderWindow.Render()
    renWinInteractor.Start()
Esempio n. 6
0
def GetSphere():
    thetaResolution = 32
    phiResolution = 32
    surface = vtk.vtkTexturedSphereSource()
    surface.SetThetaResolution(thetaResolution)
    surface.SetPhiResolution(phiResolution)

    # Now the tangents
    tangents = vtk.vtkPolyDataTangents()
    tangents.SetInputConnection(surface.GetOutputPort())
    tangents.Update()
    return tangents.GetOutput()
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self,
         module_manager,
         vtk.vtkTexturedSphereSource(),
         "Processing.",
         (),
         ("vtkPolyData",),
         replaceDoc=True,
         inputFunctions=None,
         outputFunctions=None,
     )
Esempio n. 8
0
def Earth(pos=(0, 0, 0), r=1, lw=1):
    """Build a textured actor representing the Earth.

    .. hint:: |geodesic| |geodesic.py|_
    """
    import os

    tss = vtk.vtkTexturedSphereSource()
    tss.SetRadius(r)
    tss.SetThetaResolution(72)
    tss.SetPhiResolution(36)
    earthMapper = vtk.vtkPolyDataMapper()
    earthMapper.SetInputConnection(tss.GetOutputPort())
    earthActor = Actor(c="w")
    earthActor.SetMapper(earthMapper)
    atext = vtk.vtkTexture()
    pnmReader = vtk.vtkPNMReader()
    cdir = os.path.dirname(__file__)
    if cdir == "":
        cdir = "."
    fn = settings.textures_path + "earth.ppm"
    pnmReader.SetFileName(fn)
    atext.SetInputConnection(pnmReader.GetOutputPort())
    atext.InterpolateOn()
    earthActor.SetTexture(atext)
    if not lw:
        earthActor.SetPosition(pos)
        return earthActor
    es = vtk.vtkEarthSource()
    es.SetRadius(r / 0.995)
    earth2Mapper = vtk.vtkPolyDataMapper()
    earth2Mapper.SetInputConnection(es.GetOutputPort())
    earth2Actor = Actor()  # vtk.vtkActor()
    earth2Actor.SetMapper(earth2Mapper)
    earth2Mapper.ScalarVisibilityOff()
    earth2Actor.GetProperty().SetLineWidth(lw)
    ass = Assembly([earthActor, earth2Actor])
    ass.SetPosition(pos)
    settings.collectable_actors.append(ass)
    return ass
Esempio n. 9
0
def earth(pos=[0, 0, 0], r=1, lw=1):
    '''Build a textured actor representing the Earth.

    .. hint:: Example: `earth.py <https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/earth.py>`_
    
        .. image:: https://user-images.githubusercontent.com/32848391/51031592-5a448700-159d-11e9-9b66-bee6abb18679.png
    '''
    import os
    tss = vtk.vtkTexturedSphereSource()
    tss.SetRadius(r)
    tss.SetThetaResolution(72)
    tss.SetPhiResolution(36)
    earthMapper = vtk.vtkPolyDataMapper()
    earthMapper.SetInputConnection(tss.GetOutputPort())
    earthActor = Actor()  #vtk.vtkActor()
    earthActor.SetMapper(earthMapper)
    atext = vtk.vtkTexture()
    pnmReader = vtk.vtkPNMReader()
    cdir = os.path.dirname(__file__)
    if cdir == '':
        cdir = '.'
    fn = cdir + '/textures/earth.ppm'
    pnmReader.SetFileName(fn)
    atext.SetInputConnection(pnmReader.GetOutputPort())
    atext.InterpolateOn()
    earthActor.SetTexture(atext)
    if not lw:
        earthActor.SetPosition(pos)
        return earthActor
    es = vtk.vtkEarthSource()
    es.SetRadius(r / .995)
    earth2Mapper = vtk.vtkPolyDataMapper()
    earth2Mapper.SetInputConnection(es.GetOutputPort())
    earth2Actor = Actor()  # vtk.vtkActor()
    earth2Actor.SetMapper(earth2Mapper)
    earth2Actor.GetProperty().SetLineWidth(lw)
    ass = Assembly([earthActor, earth2Actor])
    ass.SetPosition(pos)
    return ass
Esempio n. 10
0
def earth(pos=[0, 0, 0], r=1, lw=1):
    '''Build a textured actor representing the Earth.        

    [**Example**](https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/earth.py)    
    '''
    import os
    tss = vtk.vtkTexturedSphereSource()
    tss.SetRadius(r)
    tss.SetThetaResolution(72)
    tss.SetPhiResolution(36)
    earthMapper = vtk.vtkPolyDataMapper()
    earthMapper.SetInputConnection(tss.GetOutputPort())
    earthActor = Actor()  #vtk.vtkActor()
    earthActor.SetMapper(earthMapper)
    atext = vtk.vtkTexture()
    pnmReader = vtk.vtkPNMReader()
    cdir = os.path.dirname(__file__)
    if cdir == '':
        cdir = '.'
    fn = cdir + '/textures/earth.ppm'
    pnmReader.SetFileName(fn)
    atext.SetInputConnection(pnmReader.GetOutputPort())
    atext.InterpolateOn()
    earthActor.SetTexture(atext)
    if not lw:
        earthActor.SetPosition(pos)
        return earthActor
    es = vtk.vtkEarthSource()
    es.SetRadius(r / .995)
    earth2Mapper = vtk.vtkPolyDataMapper()
    earth2Mapper.SetInputConnection(es.GetOutputPort())
    earth2Actor = Actor()  # vtk.vtkActor()
    earth2Actor.SetMapper(earth2Mapper)
    earth2Actor.GetProperty().SetLineWidth(lw)
    ass = Assembly([earthActor, earth2Actor])
    ass.SetPosition(pos)
    return ass
Esempio n. 11
0
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# Create the RenderWindow, Renderer and both Actors
#
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
tss = vtk.vtkTexturedSphereSource()
tss.SetThetaResolution(18)
tss.SetPhiResolution(9)
earthMapper = vtk.vtkPolyDataMapper()
earthMapper.SetInputConnection(tss.GetOutputPort())
earthActor = vtk.vtkActor()
earthActor.SetMapper(earthMapper)
# load in the texture map
#
atext = vtk.vtkTexture()
pnmReader = vtk.vtkPNMReader()
pnmReader.SetFileName("" + str(VTK_DATA_ROOT) + "/Data/earth.ppm")
atext.SetInputConnection(pnmReader.GetOutputPort())
atext.InterpolateOn()
earthActor.SetTexture(atext)
# create a earth source and actor
#
es = vtk.vtkEarthSource()
coneMapper2.SetLookupTable(lut)
coneMapper2.SetScalarModeToUsePointData()
coneMapper2.SetScalarVisibility(1)
coneMapper2.InterpolateScalarsBeforeMappingOn()

coneActorLUT = vtk.vtkActor()
coneActorLUT.SetMapper(coneMapper2)
coneActorLUT.SetPosition(0.1, 1.0, 0)
coneActorLUT.GetProperty().SetOpacity(0.99)

# Actor for opacity through texture.
reader = vtk.vtkPNGReader()
reader.SetFileName(VTK_DATA_ROOT + "/Data/alphachannel.png")
reader.Update()

sphere = vtk.vtkTexturedSphereSource()

texture = vtk.vtkTexture()
texture.SetInputConnection(reader.GetOutputPort())

coneMapper3 = vtk.vtkPolyDataMapper()
coneMapper3.SetInputConnection(sphere.GetOutputPort())

coneActorTexture = vtk.vtkActor()
coneActorTexture.SetTexture(texture)
coneActorTexture.SetMapper(coneMapper3)
coneActorTexture.SetPosition(0, -1.0, 0)
coneActorTexture.GetProperty().SetColor(0.5, 0.5, 1)
coneActorTexture.GetProperty().SetOpacity(0.99)

ren1 = vtk.vtkRenderer()