Esempio n. 1
0
 def PerlinNoise(self, currentElement):
     pNoise = vtk.vtkPerlinNoise()
     try:
         pNoise.SetFrequency( coordsFromString(currentElement.get('SetFrequency')) )
     except:
         self.logger.error('  .. <PelinNoise> failed to SetFrequency')
     if 'SetThetaResolution' in currentElement.keys():
         try:
             pNoise.SetThetaResolution( coordsFromString(currentElement.get('SetPhase')) )
         except:
             self.logger.error('  .. <PelinNoise> failed to SetPhase')
     return pNoise
Esempio n. 2
0
def main():
    colors = vtk.vtkNamedColors()
    perlinNoise = vtk.vtkPerlinNoise()
    perlinNoise.SetFrequency(2, 1.25, 1.5)
    perlinNoise.SetPhase(0, 0, 0)

    sample = vtk.vtkSampleFunction()
    sample.SetImplicitFunction(perlinNoise)
    sample.SetSampleDimensions(65, 65, 20)
    sample.ComputeNormalsOff()

    surface = vtk.vtkContourFilter()
    surface.SetInputConnection(sample.GetOutputPort())
    surface.SetValue(0, 0.0)

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(surface.GetOutputPort())
    mapper.ScalarVisibilityOff()

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetColor(colors.GetColor3d('SteelBlue'))

    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(renderWindow)

    # Add the actors to the renderer, set the background and size
    renderer.AddActor(actor)
    renderer.SetBackground(colors.GetColor3d('SlateGray'))

    renderWindow.SetWindowName('PerlinNoise')
    renderWindow.SetSize(300, 300)
    renderer.ResetCamera()
    renderWindow.Render()
    interactor.Start()
Esempio n. 3
0
#!/usr/bin/env python
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()

# A simple example of a three-dimensional noise pattern.
# first we load in the standard vtk packages into tcl
perlin = vtk.vtkPerlinNoise()
perlin.SetFrequency(2,1.25,1.5)
perlin.SetPhase(0,0,0)
sample = vtk.vtkSampleFunction()
sample.SetImplicitFunction(perlin)
sample.SetSampleDimensions(65,65,20)
sample.ComputeNormalsOff()
surface = vtk.vtkContourFilter()
surface.SetInputConnection(sample.GetOutputPort())
surface.SetValue(0,0.0)
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(surface.GetOutputPort())
mapper.ScalarVisibilityOff()
actor = vtk.vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetColor(0.2,0.4,0.6)
ren1 = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren1)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# Add the actors to the renderer, set the background and size
#
Esempio n. 4
0
#!/usr/bin/env python

# This example demonstrates how to combine a "geometric" implicit
# function with noise at different frequencies to produce the
# appearance of a landscape.

import vtk

plane = vtk.vtkPlane()

p1 = vtk.vtkPerlinNoise()
p1.SetFrequency(1, 1, 0)

p2 = vtk.vtkPerlinNoise()
p2.SetFrequency(3, 5, 0)
p2.SetPhase(0.5, 0.5, 0)

p3 = vtk.vtkPerlinNoise()
p3.SetFrequency(16, 16, 0)

sum = vtk.vtkImplicitSum()
sum.SetNormalizeByWeight(1)
sum.AddFunction(plane)
sum.AddFunction(p1, 0.2)
sum.AddFunction(p2, 0.1)
sum.AddFunction(p3, 0.02)

sample = vtk.vtkSampleFunction()
sample.SetImplicitFunction(sum)
sample.SetSampleDimensions(65, 65, 20)
sample.SetModelBounds(-1, 1, -1, 1, -0.5, 0.5)
Esempio n. 5
0
def main():
    bounds = [4.0, 4.0, 8.0]
    colors = vtk.vtkNamedColors()

    coordData = np.random.random_sample((4, 3))

    # x = array of 8 3-tuples of float representing the vertices of a cube:
    x = (np.array([(0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (1.0, 1.0, 0.0),
                   (0.0, 1.0, 0.0), (0.0, 0.0, 1.0), (1.0, 0.0, 1.0),
                   (1.0, 1.0, 1.0), (0.0, 1.0, 1.0)]) - 0.5) * bounds

    # pts = array of 6 4-tuples of vtkIdType (int) representing the faces
    #     of the cube in terms of the above vertices
    pts = [(3, 2, 1, 0), (4, 5, 6, 7), (0, 1, 5, 4), (1, 2, 6, 5),
           (2, 3, 7, 6), (3, 0, 4, 7)]

    # We'll create the building blocks of polydata including data attributes.
    cube = vtk.vtkPolyData()
    points = vtk.vtkPoints()
    polys = vtk.vtkCellArray()
    scalars = vtk.vtkFloatArray()

    # Load the point, cell, and data attributes.
    for i, xi in enumerate(x):
        points.InsertPoint(i, xi)
    for pt in pts:
        polys.InsertNextCell(mkVtkIdList(pt))
    for i, _ in enumerate(x):
        scalars.InsertTuple1(i, i)

    # We now assign the pieces to the vtkPolyData.
    cube.SetPoints(points)
    cube.SetPolys(polys)
    cube.GetPointData().SetScalars(scalars)

    # cubeNormals = vtk.vtkPolyDataNormals()
    # cubeNormals.SetInputData(cube)

    # cubeNormals.Update()

    dist = vtk.vtkImplicitPolyDataDistance()
    dist.SetInput(cube)

    # sphere = vtk.vtkQuadratic()
    # # sphere.SetRadius(0.2)

    # # implicitFunction = vtk.vtkSuperquadric()
    # # implicitFunction.SetPhiRoundness(2.5)
    # # implicitFunction.SetThetaRoundness(.5)
    noiseFunction = vtk.vtkPerlinNoise()
    noiseFunction.SetAmplitude(2)
    # noiseFunction2 = vtk.vtkPerlinNoise()
    # noiseFunction2.SetAmplitude(3)
    # noiseFunction2.SetFrequency(2,2,2)

    # window = vtk.vtkImplicitWindowFunction()
    # window.SetImplicitFunction(noiseFunction2)
    # window.SetWindowRange(0, 10)

    noiseSum = vtk.vtkImplicitSum()
    noiseSum.AddFunction(noiseFunction)
    # # noiseSum.AddFunction(window)
    # noiseSum.AddFunction(sphere)
    noiseSum.AddFunction(dist)

    # # noiseFunction.SetFrequency([5, 5, 5])
    # # window = vtk.vtkImplicitWindowFunction()
    # # window.SetImplicitFunction(halo)
    # # window.SetWindowRange(-0, 10)

    # Sample the function.
    sample = vtk.vtkSampleFunction()
    sample.SetSampleDimensions(30, 30, 30)
    sample.SetImplicitFunction(noiseSum)

    xmin, xmax, ymin, ymax, zmin, zmax = -bounds[0], bounds[
        0], -bounds[1], bounds[1], -bounds[2], bounds[2]
    sample.SetModelBounds(xmin, xmax, ymin, ymax, zmin, zmax)

    # Create the 0 isosurface.
    contours = vtk.vtkContourFilter()
    contours.SetInputConnection(sample.GetOutputPort())
    contours.GenerateValues(1, 2.0, 2.0)

    # Map the contours to graphical primitives.
    contourMapper = vtk.vtkPolyDataMapper()
    contourMapper.SetInputConnection(contours.GetOutputPort())
    contourMapper.SetScalarRange(0.0, 1.2)
    contourMapper.ScalarVisibilityOff()

    # Create an actor for the contours.
    contourActor = vtk.vtkActor()
    contourActor.SetMapper(contourMapper)
    contourActor.GetProperty().SetColor(colors.GetColor3d("salmon"))

    # Create a box around the function to indicate the sampling volume.

    #Create outline.
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(sample.GetOutputPort())

    # Map it to graphics primitives.
    outlineMapper = vtk.vtkPolyDataMapper()
    outlineMapper.SetInputConnection(outline.GetOutputPort())

    # Create an actor.
    outlineActor = vtk.vtkActor()
    outlineActor.SetMapper(outlineMapper)
    outlineActor.GetProperty().SetColor(0, 0, 0)

    # Visualize.
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(renderWindow)

    renderer.AddActor(contourActor)
    renderer.AddActor(outlineActor)
    renderer.SetBackground(colors.GetColor3d("powder_blue"))

    # Enable user interface interactor
    renderWindow.Render()

    # Sign up to receive TimerEvent
    cb = vtkTimerCallback()
    cb.noise = noiseFunction
    interactor.AddObserver('TimerEvent', cb.execute)
    timerId = interactor.CreateRepeatingTimer(1)

    interactor.Start()
Esempio n. 6
0
def main():
    value = 2.0
    colors = vtk.vtkNamedColors()

    sphere = vtk.vtkSphere()
    sphere.SetRadius(0.2)

    # implicitFunction = vtk.vtkSuperquadric()
    # implicitFunction.SetPhiRoundness(2.5)
    # implicitFunction.SetThetaRoundness(.5)
    noiseFunction = vtk.vtkPerlinNoise()
    noiseFunction.SetAmplitude(2)
    noiseFunction2 = vtk.vtkPerlinNoise()
    noiseFunction2.SetAmplitude(3)
    noiseFunction2.SetFrequency(2,2,2)

    window = vtk.vtkImplicitWindowFunction()
    window.SetImplicitFunction(noiseFunction2)
    window.SetWindowRange(0, 10)

    noiseSum = vtk.vtkImplicitSum()
    noiseSum.AddFunction(noiseFunction)
    # noiseSum.AddFunction(window)
    noiseSum.AddFunction(sphere)

    # noiseFunction.SetFrequency([5, 5, 5])
    # window = vtk.vtkImplicitWindowFunction()
    # window.SetImplicitFunction(halo)
    # window.SetWindowRange(-0, 10)

    # Sample the function.
    sample = vtk.vtkSampleFunction()
    sample.SetSampleDimensions(30,30,30)
    sample.SetImplicitFunction(noiseSum)

    xmin, xmax, ymin, ymax, zmin, zmax = -value, value, -value, value, -value, value
    sample.SetModelBounds(xmin, xmax, ymin, ymax, zmin, zmax)

    # Create the 0 isosurface.
    contours = vtk.vtkContourFilter()
    contours.SetInputConnection(sample.GetOutputPort())
    contours.GenerateValues(1, 2.0, 2.0)

    # Map the contours to graphical primitives.
    contourMapper = vtk.vtkPolyDataMapper()
    contourMapper.SetInputConnection(contours.GetOutputPort())
    contourMapper.SetScalarRange(0.0, 1.2)
    contourMapper.ScalarVisibilityOff()

    # Create an actor for the contours.
    contourActor = vtk.vtkActor()
    contourActor.SetMapper(contourMapper)
    contourActor.GetProperty().SetColor(colors.GetColor3d("salmon"))

    # Create a box around the function to indicate the sampling volume. 

    #Create outline.
    outline = vtk.vtkOutlineFilter()
    outline.SetInputConnection(sample.GetOutputPort())

    # Map it to graphics primitives.
    outlineMapper = vtk.vtkPolyDataMapper()
    outlineMapper.SetInputConnection(outline.GetOutputPort())

    # Create an actor.
    outlineActor = vtk.vtkActor()
    outlineActor.SetMapper(outlineMapper)
    outlineActor.GetProperty().SetColor(0,0,0)

    # Visualize.
    renderer = vtk.vtkRenderer()
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)
    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(renderWindow)

    renderer.AddActor(contourActor)
    renderer.AddActor(outlineActor)
    renderer.SetBackground(colors.GetColor3d("powder_blue"))

    # Enable user interface interactor
    renderWindow.Render()

    # Sign up to receive TimerEvent
    cb = vtkTimerCallback()
    cb.noise = noiseFunction
    interactor.AddObserver('TimerEvent', cb.execute)
    timerId = interactor.CreateRepeatingTimer(1);

    interactor.Start()
Esempio n. 7
0
#!/usr/bin/env python

# This example demonstrates how to combine a "geometric" implicit
# function with noise at different frequencies to produce the
# appearance of a landscape.

import vtk

plane = vtk.vtkPlane()

p1 = vtk.vtkPerlinNoise()
p1.SetFrequency(1, 1, 0)

p2 = vtk.vtkPerlinNoise()
p2.SetFrequency(3, 5, 0)
p2.SetPhase(0.5, 0.5, 0)

p3 = vtk.vtkPerlinNoise()
p3.SetFrequency(16, 16, 0)

sum = vtk.vtkImplicitSum()
sum.SetNormalizeByWeight(1)
sum.AddFunction(plane)
sum.AddFunction(p1, 0.2)
sum.AddFunction(p2, 0.1)
sum.AddFunction(p3, 0.02)

sample = vtk.vtkSampleFunction()
sample.SetImplicitFunction(sum)
sample.SetSampleDimensions(65, 65, 20)
sample.SetModelBounds(-1, 1, -1, 1, -0.5, 0.5)