[vtkusers] need help: how to let different isosurfaces and cutting planes(slices) have different colors?

boyeggplant110 boyeggplant110 at gmail.com
Wed Oct 3 01:08:45 EDT 2012


Hi all,

I am a beginner of VTK and I want to show several isosurfaces and slices at
the same time. The number of isosurfaces and slices depends on the input
from users . I want to inquiry

how to let different isosurfaces and slices have different colors according
to their inputted values which are used to the function of SetValue() in
vtkContourFilter and vtkCutter.

I attach my code in the following:

 

isosurfacenum=int(input("please enter how many isosurfaces you want: "))

cuttingsliceindex=list()

isosurfacevalue=list()

count=0

while isosurfacenum>0:

    count+=1

    input_isosurfacevalue=int(input("please enter the isosurface
value"+str(count)+": "))

    isosurfacevalue.append(input_isosurfacevalue)

    if count>=isosurfacenum:

        break

count=0

 

cuttingplanenum=int(input("please enter how many cutting plane you want(up
to 4)"))

while cuttingplanenum>0:

    count+=1

    input_cuttingsliceindex=int(input("please enter the cuttingslice
value(up to 90)"+str(count)+": "))

    if input_cuttingsliceindex>=90:

        count-=1

        print("your enter exceed the max value,please enter again")

        continue

    cuttingsliceindex.append(input_cuttingsliceindex)

    if count>=cuttingplanenum:

        break

reader=vtk.vtkStructuredPointsReader()

 

reader.SetFileName(input_data_name)

 

print("1")

# vtk isosurface

iso = vtk.vtkContourFilter()

iso.SetInputConnection(reader.GetOutputPort())

lenght_isosurfacevalue=len(isosurfacevalue)

while 1:

    iso.SetValue(lenght_isosurfacevalue,
float(isosurfacevalue[lenght_isosurfacevalue-1]))

    lenght_isosurfacevalue-=1

    if lenght_isosurfacevalue==0:

        break

normals = vtk.vtkPolyDataNormals()

normals.SetInputConnection(iso.GetOutputPort())

normals.SetFeatureAngle(45)

isoMapper = vtk.vtkPolyDataMapper()

isoMapper.SetInputConnection(normals.GetOutputPort())

 

isoActor = vtk.vtkLODActor()

isoActor.SetMapper(isoMapper)

 

outline = vtk.vtkStructuredGridOutlineFilter()

outline.SetInputConnection(reader.GetOutputPort())

outlineMapper = vtk.vtkPolyDataMapper()

outlineMapper.SetInputConnection(outline.GetOutputPort())

outlineActor = vtk.vtkActor()

outlineActor.SetMapper(outlineMapper)

print("2")

print("3")

print("4")

#cutting plane

print("5")

plane = vtk.vtkPlane()

plane.SetNormal(-0.287, 0, 0.9579)

plane = vtk.vtkPlane()

plane.SetNormal(-0.287, 0, 0.9579)

planeCut = vtk.vtkCutter()

planeCut.SetInputConnection(reader.GetOutputPort())

planeCut.SetCutFunction(plane)

lenght_cuttingsliceindex=len(cuttingsliceindex)

while 1:

    planeCut.SetValue(lenght_cuttingsliceindex,
float(cuttingsliceindex[lenght_cuttingsliceindex-1]))

    lenght_cuttingsliceindex-=1

    if lenght_cuttingsliceindex==0:

        break

cutMapper = vtk.vtkPolyDataMapper()

cutMapper.SetInputConnection(planeCut.GetOutputPort())

cutActor = vtk.vtkActor()

cutActor.SetMapper(cutMapper)

 

 

thanks!

 

 

JIE

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20121003/39e39548/attachment.htm>


More information about the vtkusers mailing list