def main(): colors = vtk.vtkNamedColors() renWin = vtk.vtkRenderWindow() iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) aren = vtk.vtkRenderer() # define two elliptical cylinders quadric1 = vtk.vtkQuadric() quadric1.SetCoefficients(1, 2, 0, 0, 0, 0, 0, 0, 0, -.07) quadric2 = vtk.vtkQuadric() quadric2.SetCoefficients(2, 1, 0, 0, 0, 0, 0, 0, 0, -.07) # Create a sphere for all to use. aSphere = vtk.vtkSphereSource() aSphere.SetPhiResolution(21) aSphere.SetThetaResolution(21) # Create texture coordinates for all. tcoords = vtk.vtkImplicitTextureCoords() tcoords.SetInputConnection(aSphere.GetOutputPort()) tcoords.SetRFunction(quadric1) tcoords.SetSFunction(quadric2) aMapper = vtk.vtkDataSetMapper() aMapper.SetInputConnection(tcoords.GetOutputPort()) # Create a mapper, sphere and texture map for each case. for i in range(0, 16): aBoolean = MakeBooleanTexture(i, 64, 0) aTexture2 = vtk.vtkTexture() aTexture2.SetInputConnection(aBoolean.GetOutputPort()) aTexture2.InterpolateOff() aTexture2.RepeatOff() anActor2 = vtk.vtkActor() anActor2.SetMapper(aMapper) anActor2.SetTexture(aTexture2) anActor2.SetPosition(positions[i]) anActor2.SetScale(2.0, 2.0, 2.0) anActor2.GetProperty().SetColor(colors.GetColor3d('MistyRose')) aren.AddActor(anActor2) aren.SetBackground(colors.GetColor3d('SlateGray')) renWin.SetSize(500, 500) renWin.AddRenderer(aren) renWin.SetWindowName('TextureCutQuadric') # Interact with the data. renWin.Render() iren.Start()
def CreateIsoSurface(flat): """ :param flat: The interpolation to use (flat or Gouraud). :return: the renderer """ quadric = vtk.vtkQuadric() quadric.SetCoefficients(1, 2, 3, 0, 1, 0, 0, 0, 0, 0) sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(25, 25, 25) sample.SetImplicitFunction(quadric) # Generate the implicit surface. contour = vtk.vtkContourFilter() contour.SetInputConnection(sample.GetOutputPort()) range = [1.0, 6.0] contour.GenerateValues(5, range) # Map the contour. contourMapper = vtk.vtkPolyDataMapper() contourMapper.SetInputConnection(contour.GetOutputPort()) contourMapper.SetScalarRange(0, 7) actor = vtk.vtkActor() actor.SetMapper(contourMapper) if flat: actor.GetProperty().SetInterpolationToFlat() else: actor.GetProperty().SetInterpolationToGouraud() renderer = vtk.vtkRenderer() renderer.AddActor(actor) return renderer
def Ellipsoid_deprecated(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, bounds, sample_dims): #create an ellipsoid using a implicit quadric quadric = vtk.vtkQuadric() quadric.SetCoefficients(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9) # The sample function generates a distance function from the implicit # function. This is then contoured to get a polygonal surface. sample = vtk.vtkSampleFunction() sample.SetImplicitFunction(quadric) sample.SetModelBounds(-bounds, bounds, -bounds, bounds, -bounds, bounds) sample.SetSampleDimensions(sample_dims, sample_dims, sample_dims) sample.ComputeNormalsOff() # contour surface = vtk.vtkContourFilter() surface.SetInputConnection(sample.GetOutputPort()) surface.GenerateValues(1.0, 1.0, 1.0) # mapper mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(surface.GetOutputPort()) mapper.ScalarVisibilityOff() actor = vtk.vtkActor() actor.SetMapper(mapper) return actor
def main(): colors = vtk.vtkNamedColors() aren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(aren) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) # # Create surfaces F(x,y,z) = constant # # Sample quadric function quadric = vtk.vtkQuadric() quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0) sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(50, 50, 50) sample.SetImplicitFunction(quadric) contour = vtk.vtkContourFilter() contour.SetInputConnection(sample.GetOutputPort()) contour.GenerateValues(5, 0, 1.2) contourMapper = vtk.vtkPolyDataMapper() contourMapper.SetInputConnection(contour.GetOutputPort()) contourMapper.SetScalarRange(0, 1.2) contourActor = vtk.vtkActor() contourActor.SetMapper(contourMapper) # Create outline outline = vtk.vtkOutlineFilter() outline.SetInputConnection(sample.GetOutputPort()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(colors.GetColor3d("Brown")) outlineActor.GetProperty().SetLineWidth(3.0) # # Rendering stuff # aren.SetBackground(colors.GetColor3d("SlateGray")) aren.AddActor(contourActor) aren.AddActor(outlineActor) aren.ResetCamera() aren.GetActiveCamera().Azimuth(30) aren.GetActiveCamera().Elevation(30) renWin.SetSize(640, 512) renWin.Render() # interact with data iren.Start()
def Cone(): # create the quadric function definition quadric = vtk.vtkQuadric() quadric.SetCoefficients(1, 1, -1, 0, 0, 0, 0, 0, 0, 0) # F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9 # F(x,y,z) = 1*x^2 + 1*y^2 - 1*z^2 PlotFunction(quadric, 0.0)
def Other(): # create the quadric function definition quadric = vtk.vtkQuadric() quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0) # F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9 # F(x,y,z) = 0.5*x^2 + 1*y^2 + 0.2*z^2 + 0*x*y + 0.1*y*z + 0*x*z + 0*x + 0.2*y + 0*z + 0 PlotFunction(quadric, 1.0)
def visQuadFunc(): """ vtk sample scene with iso contours """ # VTK supports implicit functions of the form f(x,y,z)=constant. These # functions can represent things spheres, cones, etc. Here we use a # general form for a quadric to create an elliptical data field. quadric = vtk.vtkQuadric() quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0) # vtkSampleFunction samples an implicit function over the x-y-z range # specified (here it defaults to -1,1 in the x,y,z directions). sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(30, 30, 30) sample.SetImplicitFunction(quadric) # Create five surfaces F(x,y,z) = constant between range specified. The # GenerateValues() method creates n isocontour values between the range # specified. contours = vtk.vtkContourFilter() contours.SetInputConnection(sample.GetOutputPort()) contours.GenerateValues(8, 0.0, 1.2) contMapper = vtk.vtkPolyDataMapper() contMapper.SetInputConnection(contours.GetOutputPort()) contMapper.SetScalarRange(0.0, 1.2) contActor = vtk.vtkActor() contActor.SetMapper(contMapper) # We'll put a simple outline around the data. outline = vtk.vtkOutlineFilter() outline.SetInputConnection(sample.GetOutputPort()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(1, 0.5, 0) # extract data from the volume extract = vtk.vtkExtractVOI() extract.SetInputConnection(sample.GetOutputPort()) extract.SetVOI(0, 29, 0, 29, 15, 15) extract.SetSampleRate(1, 2, 3) contours2 = vtk.vtkContourFilter() contours2.SetInputConnection(extract.GetOutputPort()) contours2.GenerateValues(8, 0.0, 1.2) contMapper2 = vtk.vtkPolyDataMapper() contMapper2.SetInputConnection(contours2.GetOutputPort()) contMapper2.SetScalarRange(0.0, 1.2) contActor2 = vtk.vtkActor() contActor2.SetMapper(contMapper2) return contActor, contActor2, outlineActor, contours, contours2
def hyperboloid(pos=[0, 0, 0], a2=1, value=0.5, height=1, axis=[0, 0, 1], c='magenta', alpha=1, legend=None, texture=None, res=100): ''' Build a hyperboloid of specified aperture `a2` and `height`, centered at `pos`. Full volumetric expression is: :math:`F(x,y,z)=a_0x^2+a_1y^2+a_2z^2+a_3xy+a_4yz+a_5xz+ a_6x+a_7y+a_8z+a_9` .. hint:: Example: `mesh_bands.py <https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/mesh_bands.py>`_ .. image:: https://user-images.githubusercontent.com/32848391/51211548-26a78b00-1916-11e9-9306-67b677d1be3a.png ''' q = vtk.vtkQuadric() q.SetCoefficients(2, 2, -1 / a2, 0, 0, 0, 0, 0, 0, 0) # F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 # + a3*x*y + a4*y*z + a5*x*z # + a6*x + a7*y + a8*z +a9 sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(res, res, res) sample.SetImplicitFunction(q) contours = vtk.vtkContourFilter() contours.SetInputConnection(sample.GetOutputPort()) contours.GenerateValues(1, value, value) contours.Update() axis = np.array(axis) / np.linalg.norm(axis) theta = np.arccos(axis[2]) phi = np.arctan2(axis[1], axis[0]) t = vtk.vtkTransform() t.PostMultiply() t.RotateY(theta * 57.3) t.RotateZ(phi * 57.3) t.Scale(1, 1, height) tf = vtk.vtkTransformPolyDataFilter() tf.SetInputData(contours.GetOutput()) tf.SetTransform(t) tf.Update() pd = tf.GetOutput() actor = Actor(pd, c=c, alpha=alpha, legend=legend, texture=texture) actor.GetProperty().SetInterpolationToPhong() actor.GetMapper().ScalarVisibilityOff() actor.SetPosition(pos) return actor
def paraboloid(pos=[0, 0, 0], r=1, height=1, axis=[0, 0, 1], c='cyan', alpha=1, legend=None, texture=None, res=100): ''' Build a paraboloid of specified height and radius `r`, centered at `pos`. .. note:: Full volumetric expression is: :math:`F(x,y,z)=a_0x^2+a_1y^2+a_2z^2+a_3xy+a_4yz+a_5xz+ a_6x+a_7y+a_8z+a_9` .. image:: https://user-images.githubusercontent.com/32848391/51211547-260ef480-1916-11e9-95f6-4a677e37e355.png ''' quadric = vtk.vtkQuadric() quadric.SetCoefficients(1, 1, 0, 0, 0, 0, 0, 0, height / 4, 0) # F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 # + a3*x*y + a4*y*z + a5*x*z # + a6*x + a7*y + a8*z +a9 sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(res, res, res) sample.SetImplicitFunction(quadric) contours = vtk.vtkContourFilter() contours.SetInputConnection(sample.GetOutputPort()) contours.GenerateValues(1, .01, .01) contours.Update() axis = np.array(axis) / np.linalg.norm(axis) theta = np.arccos(axis[2]) phi = np.arctan2(axis[1], axis[0]) t = vtk.vtkTransform() t.PostMultiply() t.RotateY(theta * 57.3) t.RotateZ(phi * 57.3) t.Scale(r, r, r) tf = vtk.vtkTransformPolyDataFilter() tf.SetInputData(contours.GetOutput()) tf.SetTransform(t) tf.Update() pd = tf.GetOutput() actor = Actor(pd, c=c, alpha=alpha, legend=legend, texture=texture) actor.GetProperty().SetInterpolationToPhong() actor.GetMapper().ScalarVisibilityOff() actor.SetPosition(pos) return actor
def main(): colors = vtk.vtkNamedColors() # create an ellipsoid using a implicit quadric quadric = vtk.vtkQuadric() quadric.SetCoefficients(0.5, 1, 0.2, 0, 0.1, 0, 0, 0.2, 0, 0) # The sample function generates a distance function from the implicit # function. This is then contoured to get a polygonal surface. sample = vtk.vtkSampleFunction() sample.SetImplicitFunction(quadric) sample.SetModelBounds(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5) sample.SetSampleDimensions(40, 40, 40) sample.ComputeNormalsOff() # contour surface = vtk.vtkContourFilter() surface.SetInputConnection(sample.GetOutputPort()) surface.SetValue(0, 0.0) # mapper mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(surface.GetOutputPort()) mapper.ScalarVisibilityOff() actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().EdgeVisibilityOn() actor.GetProperty().SetColor(colors.GetColor3d('AliceBlue')) actor.GetProperty().SetEdgeColor(colors.GetColor3d('SteelBlue')) # A renderer and render window renderer = vtk.vtkRenderer() renderer.SetBackground(colors.GetColor3d('Silver')) # add the actor renderer.AddActor(actor) # render window renwin = vtk.vtkRenderWindow() renwin.AddRenderer(renderer) renwin.SetWindowName('ImplicitQuadric') # An interactor interactor = vtk.vtkRenderWindowInteractor() interactor.SetRenderWindow(renwin) # Start interactor.Initialize() renwin.Render() interactor.Start()
def Hyperboloid(pos=(0, 0, 0), a2=1, value=0.5, height=1, axis=(0, 0, 1), c="magenta", alpha=1, res=100): """ Build a hyperboloid of specified aperture `a2` and `height`, centered at `pos`. Full volumetric expression is: :math:`F(x,y,z)=a_0x^2+a_1y^2+a_2z^2+a_3xy+a_4yz+a_5xz+ a_6x+a_7y+a_8z+a_9` .. hint:: |mesh_bands| |mesh_bands.py|_ """ q = vtk.vtkQuadric() q.SetCoefficients(2, 2, -1 / a2, 0, 0, 0, 0, 0, 0, 0) # F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 # + a3*x*y + a4*y*z + a5*x*z # + a6*x + a7*y + a8*z +a9 sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(res, res, res) sample.SetImplicitFunction(q) contours = vtk.vtkContourFilter() contours.SetInputConnection(sample.GetOutputPort()) contours.GenerateValues(1, value, value) contours.Update() axis = np.array(axis) / np.linalg.norm(axis) theta = np.arccos(axis[2]) phi = np.arctan2(axis[1], axis[0]) t = vtk.vtkTransform() t.PostMultiply() t.RotateY(np.rad2deg(theta)) t.RotateZ(np.rad2deg(phi)) t.Scale(1, 1, height) tf = vtk.vtkTransformPolyDataFilter() tf.SetInputData(contours.GetOutput()) tf.SetTransform(t) tf.Update() pd = tf.GetOutput() actor = Actor(pd, c, alpha).flipNormals() actor.GetProperty().SetInterpolationToPhong() actor.mapper.ScalarVisibilityOff() actor.SetPosition(pos) settings.collectable_actors.append(actor) return actor
def Paraboloid( pos=(0, 0, 0), r=1, height=1, axis=(0, 0, 1), c="cyan", alpha=1, res=50): """ Build a paraboloid of specified height and radius `r`, centered at `pos`. .. note:: Full volumetric expression is: :math:`F(x,y,z)=a_0x^2+a_1y^2+a_2z^2+a_3xy+a_4yz+a_5xz+ a_6x+a_7y+a_8z+a_9` |paraboloid| """ quadric = vtk.vtkQuadric() quadric.SetCoefficients(1, 1, 0, 0, 0, 0, 0, 0, height / 4, 0) # F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 # + a3*x*y + a4*y*z + a5*x*z # + a6*x + a7*y + a8*z +a9 sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(res, res, res) sample.SetImplicitFunction(quadric) contours = vtk.vtkContourFilter() contours.SetInputConnection(sample.GetOutputPort()) contours.GenerateValues(1, 0.01, 0.01) contours.Update() axis = np.array(axis) / np.linalg.norm(axis) theta = np.arccos(axis[2]) phi = np.arctan2(axis[1], axis[0]) t = vtk.vtkTransform() t.PostMultiply() t.RotateY(np.rad2deg(theta)) t.RotateZ(np.rad2deg(phi)) t.Scale(r, r, r) tf = vtk.vtkTransformPolyDataFilter() tf.SetInputData(contours.GetOutput()) tf.SetTransform(t) tf.Update() pd = tf.GetOutput() actor = Actor(pd, c, alpha).flipNormals() actor.GetProperty().SetInterpolationToPhong() actor.mapper.ScalarVisibilityOff() actor.SetPosition(pos) settings.collectable_actors.append(actor) return actor
def hyperboloid(pos=[0, 0, 0], a2=1, value=0.5, height=1, axis=[0, 0, 1], c='magenta', alpha=1, legend=None, texture=None, res=50): ''' Build a hyperboloid of specified aperture a2 and height, centered at pos. ''' q = vtk.vtkQuadric() q.SetCoefficients(2, 2, -1 / a2, 0, 0, 0, 0, 0, 0, 0) #F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 # + a3*x*y + a4*y*z + a5*x*z # + a6*x + a7*y + a8*z +a9 sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(res, res, res) sample.SetImplicitFunction(q) contours = vtk.vtkContourFilter() contours.SetInputConnection(sample.GetOutputPort()) contours.GenerateValues(1, value, value) contours.Update() axis = np.array(axis) / np.linalg.norm(axis) theta = np.arccos(axis[2]) phi = np.arctan2(axis[1], axis[0]) t = vtk.vtkTransform() t.PostMultiply() t.RotateY(theta * 57.3) t.RotateZ(phi * 57.3) t.Scale(1, 1, height) tf = vtk.vtkTransformPolyDataFilter() vu.setInput(tf, contours.GetOutput()) tf.SetTransform(t) tf.Update() pd = tf.GetOutput() actor = vu.makeActor(pd, c=c, alpha=alpha, legend=legend, texture=texture) actor.GetProperty().SetInterpolationToPhong() actor.GetMapper().ScalarVisibilityOff() actor.SetPosition(pos) return actor
def add_ellipsoid(self, center=[0, 0, 0], orientation=[0, 0, 0], radius=5.2, color='blue', opacity=1.0, contours='latitude'): # create an ellipsoid using an implicit quadric quadric = vtk.vtkQuadric() quadric.SetCoefficients(0.5, 1, 0.2, 0, 0.1, 0, 0, 0.2, 0, 0) # The sample function generates a distance function from the implicit # function. This is then contoured to get a polygonal surface. sample = vtk.vtkSampleFunction() sample.SetImplicitFunction(quadric) sample.SetModelBounds(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5) sample.SetSampleDimensions(40, 40, 40) sample.ComputeNormalsOff() # contour surface = vtk.vtkContourFilter() surface.SetInputConnection(sample.GetOutputPort()) surface.SetValue(0, 0.0) # mapper mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(surface.GetOutputPort()) mapper.ScalarVisibilityOff() actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().EdgeVisibilityOn() actor.GetProperty().SetColor(self.colors.GetColor3d('AliceBlue')) actor.GetProperty().SetEdgeColor(self.colors.GetColor3d('SteelBlue')) # Append elements self.sources.append(quadric) self.mappers.append(mapper) self.actors.append(actor) # add the actor self.renderer.AddActor(actor) # Initialize must be called prior to creating timer events. self.interactor.Initialize()
def __init__(self, size=4, color=(0.9, 0.9, 0.9), **kwargs): kwargs["color"] = color kwargs["size"] = size self.poly_data = vtk.vtkPolyData() self.extractor = vtk.vtkExtractPolyDataGeometry() self.extractor.SetInput(self.poly_data) self.constant_function = vtk.vtkQuadric() self.constant_function.SetCoefficients(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0) # Filter disabled by default self.extractor.SetImplicitFunction(self.constant_function) self.frustum = None self.mapper = vtk.vtkPolyDataMapper() self.mapper.SetInputConnection(self.extractor.GetOutputPort()) self.actor = vtk.vtkActor() self.actor.SetMapper(self.mapper) self._process_kwargs(**kwargs)
def __init__(self, parent = None): super(VTKFrame, self).__init__(parent) self.vtkWidget = QVTKRenderWindowInteractor(self) vl = QtGui.QVBoxLayout(self) vl.addWidget(self.vtkWidget) vl.setContentsMargins(0, 0, 0, 0) self.ren = vtk.vtkRenderer() self.ren.SetBackground(0.1, 0.2, 0.4) self.vtkWidget.GetRenderWindow().AddRenderer(self.ren) self.iren = self.vtkWidget.GetRenderWindow().GetInteractor() # Create the quadric function definition quadric = vtk.vtkQuadric() quadric.SetCoefficients(0.5, 1, 0.2, 0, 0.1, 0, 0, 0.2, 0, 0) #quadric.SetCoefficients(0.5, 0, 0.2, 0, 0, 0, 0, 0, 0, -0.1) # Sample the quadric function sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(50, 50, 50) sample.SetImplicitFunction(quadric) sample.SetModelBounds(-1, 1, -1, 1, -1, 1) contourFilter = vtk.vtkContourFilter() contourFilter.SetInputConnection(sample.GetOutputPort()) #contourFilter.GenerateValues(1, 1, 1) contourFilter.Update() # Create a mapper mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(contourFilter.GetOutputPort()) # Create an actor actor = vtk.vtkActor() actor.SetMapper(mapper) self.ren.AddActor(actor) self.ren.ResetCamera() self._initialized = False
def __init__(self, parent=None): super(VTKFrame, self).__init__(parent) self.vtkWidget = QVTKRenderWindowInteractor(self) vl = QtGui.QVBoxLayout(self) vl.addWidget(self.vtkWidget) vl.setContentsMargins(0, 0, 0, 0) self.ren = vtk.vtkRenderer() self.ren.SetBackground(0.1, 0.2, 0.4) self.vtkWidget.GetRenderWindow().AddRenderer(self.ren) self.iren = self.vtkWidget.GetRenderWindow().GetInteractor() # Create the quadric function definition quadric = vtk.vtkQuadric() quadric.SetCoefficients(0.5, 1, 0.2, 0, 0.1, 0, 0, 0.2, 0, 0) #quadric.SetCoefficients(0.5, 0, 0.2, 0, 0, 0, 0, 0, 0, -0.1) # Sample the quadric function sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(50, 50, 50) sample.SetImplicitFunction(quadric) sample.SetModelBounds(-1, 1, -1, 1, -1, 1) contourFilter = vtk.vtkContourFilter() contourFilter.SetInputConnection(sample.GetOutputPort()) #contourFilter.GenerateValues(1, 1, 1) contourFilter.Update() # Create a mapper mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(contourFilter.GetOutputPort()) # Create an actor actor = vtk.vtkActor() actor.SetMapper(mapper) self.ren.AddActor(actor) self.ren.ResetCamera() self._initialized = False
def create_renderer(): """ vtk renderer with a sample scene """ quadric = vtk.vtkQuadric() quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0) sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(50, 50, 50) sample.SetImplicitFunction(quadric) contours = vtk.vtkContourFilter() contours.SetInputConnection(sample.GetOutputPort()) contours.GenerateValues(5, 0.0, 1.2) contour_mapper = vtk.vtkPolyDataMapper() contour_mapper.SetInputConnection(contours.GetOutputPort()) contour_mapper.SetScalarRange(0.0, 1.2) contour_actor = vtk.vtkActor() contour_actor.SetMapper(contour_mapper) outline = vtk.vtkOutlineFilter() outline.SetInputConnection(sample.GetOutputPort()) outline_mapper = vtk.vtkPolyDataMapper() outline_mapper.SetInputConnection(outline.GetOutputPort()) outline_actor = vtk.vtkActor() outline_actor.SetMapper(outline_mapper) outline_actor.GetProperty().SetColor(0, 0, 0) renderer = vtk.vtkRenderer() renderer.AddActor(contour_actor) renderer.AddActor(outline_actor) renderer.SetBackground(.75, .75, .75) return renderer
def Ellipsoid(center, color, U): # create the quadric function definition a0 = U[0][0] a1 = U[1][1] a2 = U[2][2] a3 = 2*U[0][1] a4 = 2*U[1][2] a5 = 2*U[0][2] quadric = vtk.vtkQuadric() quadric.SetCoefficients(a0,a1,a2,a3,a4,a5,0,0,0,-1.5282) # F(x,y,z) = a0*x^2 + a1*y^2 + a2*z^2 + a3*x*y + a4*y*z + a5*x*z + a6*x + a7*y + a8*z + a9 # sample the quadric function sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(36,36,36) sample.SetImplicitFunction(quadric) sample.SetModelBounds(-2, 2, -2, 2, -2, 2) #create the 0 isosurface contours = vtk.vtkContourFilter() contours.SetInput(sample.GetOutput()) contours.GenerateValues(1,1,1) transform = vtk.vtkTransform() transform.Translate(center) # map the contours to graphical primitives contourMapper = vtk.vtkPolyDataMapper() contourMapper.SetInput(contours.GetOutput()) contourMapper.ScalarVisibilityOff() # create an actor for the contours contourActor = vtk.vtkActor() contourActor.SetMapper(contourMapper) contourActor.GetProperty().SetColor(color) # (R,G,B) contourActor.SetUserTransform(transform) return contourActor
def PlotEllipsoide(lnume, A, S, pz): # lnume : liste des ellipsoides # A : coefficients des equations pour les ellipsoides # S : coefficients des eéquations pour la sphère anglobante # pz : pourcentage entre -& et 1 pour positionner le plan de coupe a une altitude pz*Rayon use_function_callback = True colors = vtk.vtkNamedColors() colorsCell = ['AliceBlue', 'Green', 'Blue', 'Yellow', 'Magenta'] # A renderer and render window renderer = vtk.vtkRenderer() renderer.SetBackground(colors.GetColor3d('Silver')) # render window renwin = vtk.vtkRenderWindow() renwin.SetWindowName("CallBack") renwin.AddRenderer(renderer) # An interactor interactor = vtk.vtkRenderWindowInteractor() interactor.SetRenderWindow(renwin) # Start if use_function_callback: CloseWin.int = interactor interactor.AddObserver('EndInteractionEvent', CloseWin) # Create actors # create container Sphere sphere = vtk.vtkQuadric() sphere.SetCoefficients(S) sampleS = vtk.vtkSampleFunction() sampleS.SetImplicitFunction(sphere) # mapper mapperSphere = vtk.vtkPolyDataMapper() mapperSphere.SetInputConnection(sampleS.GetOutputPort()) mapperSphere.ScalarVisibilityOff() # actorSphere = vtk.vtkActor() # actorSphere.SetMapper(mapperSphere) # actorSphere.GetProperty().EdgeVisibilityOn() # actorSphere.GetProperty().SetColor(colors.GetColor3d('AliceBlue')) # actorSphere.GetProperty().SetEdgeColor(colors.GetColor3d('SteelBlue')) bounds = np.array(sampleS.GetModelBounds()) for k in range(3): bounds[2 * k] = -1.1 * np.sqrt(-S[9]) bounds[2 * k + 1] = 1.1 * np.sqrt(-S[9]) print(S[9]) print(bounds) sampleS.SetModelBounds(bounds) # # contour # surface = vtk.vtkContourFilter() # surface.SetInputConnection(sample.GetOutputPort()) ## surface.SetInputConnection(extract.GetOutputPort()) # surface.SetValue(0, 0.0) # contoursS = vtk.vtkContourFilter() contoursS.SetInputConnection(sampleS.GetOutputPort()) contoursS.GenerateValues(1, 0.0, 1.2) contMapper = vtk.vtkPolyDataMapper() contMapper.SetInputConnection(contoursS.GetOutputPort()) contMapper.SetScalarRange(0.0, 1.2) contActor = vtk.vtkActor() contActor.GetProperty().SetOpacity(0.1) contActor.SetMapper(contMapper) # create an ellipsoid using a implicit quadric quadric = [None] * len(lnume) mapper = [None] * len(lnume) actor = [None] * len(lnume) sample = [None] * len(lnume) contours = [None] * len(lnume) for k in lnume: quadric[k] = vtk.vtkQuadric() quadric[k].SetCoefficients(A[lnume[k]]) sample[k] = vtk.vtkSampleFunction() sample[k].SetImplicitFunction(quadric[k]) for l in range(3): bounds[2 * l] = -1.2 * np.sqrt(-S[9]) bounds[2 * l + 1] = 1.2 * np.sqrt(-S[9]) sample[k].SetModelBounds(bounds) contours[k] = vtk.vtkContourFilter() contours[k].SetInputConnection(sample[k].GetOutputPort()) # generation d'une valeur dans l'intervalle spécifié (le min et le max sont inclus) contours[k].GenerateValues(1, 0.0, 0.1) # mapper mapper[k] = vtk.vtkPolyDataMapper() mapper[k].SetInputConnection(contours[k].GetOutputPort()) mapper[k].ScalarVisibilityOff() actor[k] = vtk.vtkActor() actor[k].SetMapper(mapper[k]) #actor[k].GetProperty().EdgeVisibilityOn() actor[k].GetProperty().SetColor( colors.GetColor3d(colorsCell[k % len(colorsCell)])) actor[k].GetProperty().SetEdgeColor(colors.GetColor3d('SteelBlue')) #Add the actors to the scene renderer.AddActor(contActor) for k in lnume: renderer.AddActor(actor[k]) ## Add cut of sphere # # cutterS = vtk.vtkCutter() # cutterS.SetInputConnection(sampleS.GetOutputPort()) # plane = vtk.vtkPlane() # # #Plan de coupe xy # altitude=pz*np.sqrt(-S[9]) # plane.SetOrigin([0,0,altitude]) # plane.SetNormal([0,0,1]) # # cutterS.SetCutFunction(plane) ## cutterS.SetInputConnection(sampleS.GetOutputPort()) ## cutterS.GenerateCutScalarsOn() ## cutterS.SetValue(0,0.5) ## cutterS.Update() # # cutStrips = vtk.vtkStripper() # cutStrips.SetInputConnection(cutterS.GetOutputPort()) # cutStrips.Update() # # circle= cutStrips.GetOutput() # # # write circle out # polyDataWriter = vtk.vtkXMLPolyDataWriter() # if vtk.VTK_MAJOR_VERSION <= 5: # polyDataWriter.SetInput(circle) # else: # polyDataWriter.SetInputData(circle) # # polyDataWriter.SetFileName("circle.vtp") # polyDataWriter.SetCompressorTypeToNone() # polyDataWriter.SetDataModeToAscii() # polyDataWriter.Write() # ## prepare the binary image's voxel grid # whiteImage = vtk.vtkImageData() # boundsI = [0]*6 # circle.GetBounds(boundsI) # spacing = [0]*3 # desired volume spacing # spacing[0] = 0.5 # spacing[1] = 0.5 # spacing[2] = 0.5 # whiteImage.SetSpacing(spacing) # ## compute dimensions # dim = [0]*3 # for i in range(3): # dim[i] = int(math.ceil((bounds[i * 2 + 1] - bounds[i * 2]) / spacing[i])) + 1 # if (dim[i] < 1): # dim[i] = 1 # whiteImage.SetDimensions(dim) # whiteImage.SetExtent(0, dim[0] - 1, 0, dim[1] - 1, 0, dim[2] - 1) # origin = [0]*3 ## NOTE: I am not sure whether or not we had to add some offset! # origin[0] = bounds[0]# + spacing[0] / 2 # origin[1] = bounds[2]# + spacing[1] / 2 # origin[2] = bounds[4]# + spacing[2] / 2 # whiteImage.SetOrigin(origin) # if vtk.VTK_MAJOR_VERSION <= 5: # whiteImage.SetScalarTypeToUnsignedChar() # whiteImage.AllocateScalars() # else: # whiteImage.AllocateScalars(vtk.VTK_UNSIGNED_CHAR, 1) # ## fill the image with foreground voxels: # inval = 255 # outval = 0 # count = whiteImage.GetNumberOfPoints() ##for (vtkIdType i = 0 i < count ++i) # for i in range(count): # whiteImage.GetPointData().GetScalars().SetTuple1(i, inval) # ## sweep polygonal data (this is the important thing with contours!) # extruder = vtk.vtkLinearExtrusionFilter() # if vtk.VTK_MAJOR_VERSION <= 5: # extruder.SetInput(circle) # else: # extruder.SetInputData(circle) # # extruder.SetScaleFactor(1.) # extruder.SetExtrusionTypeToNormalExtrusion() # extruder.SetVector(0, 0, 1) # extruder.Update() # # # polygonal data -. image stencil: # pol2stenc = vtk.vtkPolyDataToImageStencil() # pol2stenc.SetTolerance(0) # important if extruder.SetVector(0, 0, 1) !!! # pol2stenc.SetInputConnection(extruder.GetOutputPort()) # pol2stenc.SetOutputOrigin(origin) # pol2stenc.SetOutputSpacing(spacing) # pol2stenc.SetOutputWholeExtent(whiteImage.GetExtent()) # pol2stenc.Update() # ## cut the corresponding white image and set the background: # imgstenc = vtk.vtkImageStencil() # if vtk.VTK_MAJOR_VERSION <= 5: # imgstenc.SetInput(whiteImage) # imgstenc.SetStencil(pol2stenc.GetOutput()) # else: # imgstenc.SetInputData(whiteImage) # imgstenc.SetStencilConnection(pol2stenc.GetOutputPort()) # # imgstenc.ReverseStencilOff() # imgstenc.SetBackgroundValue(outval) # imgstenc.Update() # # imageWriter = vtk.vtkMetaImageWriter() # imageWriter.SetFileName("labelImage.mhd") # imageWriter.SetInputConnection(imgstenc.GetOutputPort()) # imageWriter.Write() # # imageWriter = vtk.vtkPNGWriter() # imageWriter.SetFileName("labelImage.png") # imageWriter.SetInputConnection(imgstenc.GetOutputPort()) # imageWriter.Write() # # # cutPoly = vtk.vtkPolyData() # # cutPoly.SetPoints(cutStrips.GetOutput().GetPoints()) # cutPoly.SetPolys(cutStrips.GetOutput().GetLines()) # # # Get the edges from the mesh # edges = vtk.vtkExtractEdges() # edges.SetInput(cutPoly) # edge_mapper = vtk.vtkPolyDataMapper() # edge_mapper.SetInput(edges.GetOutput()) # ## Make an actor for those edges # edge_actor = vtk.vtkActor() # edge_actor.SetMapper(edge_mapper) ## Make the actor red (there are other ways of doing this also) # edge_actor.GetProperty().SetColor(1,0,0) # # renderer.AddActor(edge_actor) # ## # Avoid z-buffer fighting # vtk.vtkPolyDataMapper().SetResolveCoincidentTopologyToPolygonOffset() ## ## # Extract boundary from cutPoly ## cutBoundary = vtk.vtkFeatureEdges() ## cutBoundary.SetInputConnection(cutPoly) ## ## cutBoundary.Update() # cutterSMapper = vtk.vtkPolyDataMapper() # cutterSMapper.SetInputConnection(cutterS.GetOutputPort()) # cutterSMapper.ScalarVisibilityOff() ## cutterSMapper.SetScalarRange(0.,0.1) ### cutterMapper.SetLookupTable(clut) ### # cut= vtk.vtkActor() # cut.SetMapper(cutterSMapper) # cut.GetProperty().SetOpacity(1) # cut.GetProperty().EdgeVisibilityOn() # cut.GetProperty().SetColor( 1,0,0 ) # cut.GetProperty().SetEdgeColor( 1,1,1 ) # # renderer.AddActor(cut) # ## ren1.AddViewProp( triActor ) ## ren1.SetViewport( 0,0,0.5,1.0) # # cutters=[None]*len(lnume) # cuttersMapper=[None]*len(lnume) # cut=[None]*len(lnume) # for k in lnume: # cutters[k] = vtk.vtkCutter() # cutters[k].SetCutFunction(plane) # cutters[k].SetInputConnection(sample[k].GetOutputPort()) # cutters[k].Update() # cuttersMapper[k] = vtk.vtkPolyDataMapper() # cuttersMapper[k].SetInputConnection(cutters[k].GetOutputPort()) # cuttersMapper[k].SetScalarRange(0.,0.1) # # cutterMapper.SetLookupTable(clut) # # # cut[k]= vtk.vtkActor() # cut[k].SetMapper(cuttersMapper[k]) # cut[k].GetProperty().SetOpacity(1) ## renderer.AddActor(cut[k]) # # # The sample function generates a distance function from the implicit # # function. This is then contoured to get a polygonal surface. ## sample = vtk.vtkSampleFunction() ## sample.SetImplicitFunction(quadric) ## ## booleanUnion = vtk.vtkImplicitBoolean() ## booleanUnion.AddFunction(sphere) ## booleanUnion.SetOperationType(0) ## extract = vtk.vtkExtractGeometry() ## extract.SetInputConnection(sample.GetOutputPort()) ## extract.SetImplicitFunction(booleanUnion) ## #sample.SetImplicitFunction(sphere) ## #print(sample.GetModelBounds()) ## #sample.SetModelBounds(-0.5, 0.5, -0.5, 0.5, -0.5, 0.5) ## bounds=np.array(sample.GetModelBounds()) ## for k in range(3): ## bounds[2*k]=10*np.sqrt(1/A[nume][k])*bounds[2*k] ## bounds[2*k+1]=10*np.sqrt(1/A[nume][k])*bounds[2*k+1] ## ## #for k in range(3): ## # bounds[2*k]=np.sqrt(-S[9]/S[k])*bounds[2*k] ## # bounds[2*k+1]=np.sqrt(-S[9]/S[k])*bounds[2*k+1] ## ## sample.SetModelBounds(bounds) ## print(sample.GetModelBounds()) ## ## ## sample.SetSampleDimensions(40, 40, 40) ## sample.ComputeNormalsOff() ## ## # contour ## surface = vtk.vtkContourFilter() ## #surface.SetInputConnection(sample.GetOutputPort()) ## surface.SetInputConnection(extract.GetOutputPort()) ## surface.SetValue(0, 0.0) ## ## ## ## ## ## # add the actor ## renderer.AddActor(actor) # # # interactor.Initialize() renwin.Render() interactor.Start() return (renwin)
def main(): """ The entry-point to the program. Adapted from https://lorensen.github.io/VTKExamples/site/Python/Visualization/QuadricVisualization/ """ table_size = 7 lut = create_color_table(table_size) render_window = vtk.vtkRenderWindow() interactor = vtk.vtkRenderWindowInteractor() interactor.SetRenderWindow(render_window) render_window.SetSize(1700, 900) # Text in the first viewport text = '''Edwin Sarver Assignment #3 Visualization The following visualizations were created using VTK for Python. A quadric is generated with multiple layers. This is then sampled in a 50x50x50-cell cube. Then, the following visualizations are created: 1) Isosurfaces 2) Cutting Planes 3) Contour Lines A custom color-table was used to get the coloring at each isosurface value. An interactor was added because it is fun to watch the objects (and text) spin. ''' text_color = vtk.vtkNamedColors().GetColor3d('White') text_actor = create_text(text, text_color) background_color = vtk.vtkNamedColors().GetColor3d('SlateGray') create_viewport(0.0, 0.5, 0.5, 1.0, background_color, [text_actor], render_window, True) # Generate the function quadric = vtk.vtkQuadric() quadric.SetCoefficients(1, 2, 3, 0, 1, 0, 0, 0, 0, 0) sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(50, 50, 50) sample.SetImplicitFunction(quadric) color_data = vtk.vtkUnsignedCharArray() color_data.SetName('colors') color_data.SetNumberOfComponents(3) make_cell_data(table_size, lut, color_data) sample.GetOutput().GetCellData().SetScalars(color_data) # Get the isosurface actors iso_actor = create_isosurface(sample, lut) iso_outline = create_outline(sample) create_viewport(0.5, 1.0, 0.5, 1.0, background_color, [iso_actor, iso_outline], render_window) # Get the cutting plane actors planes_actor = create_planes(sample, 5) planes_outline = create_outline(sample) create_viewport(0.0, 0.5, 0.0, 0.5, background_color, [planes_actor, planes_outline], render_window) # Get the contour actors contours_actor = create_contours(sample, 5, 15) contours_outline = create_outline(sample) create_viewport(0.5, 1.0, 0.0, 0.5, background_color, [contours_actor, contours_outline], render_window) # Render everything render_window.Render() render_window.SetWindowName("Visualization Project #3") interactor.Start()
#!/usr/bin/env python import vtk # Test vtkContour3DLinearGrid with vtkScalarTree. # Control test size res = 50 #res = 300 serialProcessing = 0 mergePoints = 1 interpolateAttr = 0 computeNormals = 0 # # Quadric definition quadric = vtk.vtkQuadric() quadric.SetCoefficients([.5, 1, .2, 0, .1, 0, 0, .2, 0, 0]) sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(res, res, res) sample.SetImplicitFunction(quadric) sample.ComputeNormalsOn() sample.Update() # # Extract voxel cells extract = vtk.vtkExtractCells() extract.SetInputConnection(sample.GetOutputPort()) extract.AddCellRange(0, sample.GetOutput().GetNumberOfCells()) extract.Update() # Now contour the cells, using scalar tree or not
def PlotEllipsoideSimple(lnume, A, S, pz): # lnume : liste des ellipsoides # A : coefficients des equations pour les ellipsoides # S : coefficients des eéquations pour la sphère anglobante # pz : pourcentage entre -& et 1 pour positionner le plan de coupe a une altitude pz*Rayon use_function_callback = False colors = vtk.vtkNamedColors() colorsCell = ['AliceBlue', 'Green', 'Blue', 'Yellow', 'Magenta'] # A renderer and render window renderer = vtk.vtkRenderer() renderer.SetBackground(colors.GetColor3d('Silver')) # render window renwin = vtk.vtkRenderWindow() renwin.SetWindowName("CallBack") renwin.AddRenderer(renderer) # An interactor interactor = vtk.vtkRenderWindowInteractor() interactor.SetRenderWindow(renwin) # Start if use_function_callback: CloseWin.int = interactor interactor.AddObserver('EndInteractionEvent', CloseWin) # Create actors # create container Sphere sphere = vtk.vtkQuadric() sphere.SetCoefficients(S) sampleS = vtk.vtkSampleFunction() sampleS.SetImplicitFunction(sphere) # mapper mapperSphere = vtk.vtkPolyDataMapper() mapperSphere.SetInputConnection(sampleS.GetOutputPort()) mapperSphere.ScalarVisibilityOff() # actorSphere = vtk.vtkActor() # actorSphere.SetMapper(mapperSphere) # actorSphere.GetProperty().EdgeVisibilityOn() # actorSphere.GetProperty().SetColor(colors.GetColor3d('AliceBlue')) # actorSphere.GetProperty().SetEdgeColor(colors.GetColor3d('SteelBlue')) bounds = np.array(sampleS.GetModelBounds()) for k in range(3): bounds[2 * k] = -1.1 * np.sqrt(-S[9]) bounds[2 * k + 1] = 1.1 * np.sqrt(-S[9]) print(S[9]) print(bounds) sampleS.SetModelBounds(bounds) # # contour # surface = vtk.vtkContourFilter() # surface.SetInputConnection(sample.GetOutputPort()) ## surface.SetInputConnection(extract.GetOutputPort()) # surface.SetValue(0, 0.0) # contoursS = vtk.vtkContourFilter() contoursS.SetInputConnection(sampleS.GetOutputPort()) contoursS.GenerateValues(1, 0.0, 1.2) contMapper = vtk.vtkPolyDataMapper() contMapper.SetInputConnection(contoursS.GetOutputPort()) contMapper.SetScalarRange(0.0, 1.2) contActor = vtk.vtkActor() contActor.GetProperty().SetOpacity(0.1) contActor.SetMapper(contMapper) # create an ellipsoid using a implicit quadric quadric = [None] * len(lnume) mapper = [None] * len(lnume) actor = [None] * len(lnume) sample = [None] * len(lnume) contours = [None] * len(lnume) for k in lnume: quadric[k] = vtk.vtkQuadric() quadric[k].SetCoefficients(A[lnume[k]]) sample[k] = vtk.vtkSampleFunction() sample[k].SetImplicitFunction(quadric[k]) for l in range(3): bounds[2 * l] = -1.2 * np.sqrt(-S[9]) bounds[2 * l + 1] = 1.2 * np.sqrt(-S[9]) sample[k].SetModelBounds(bounds) contours[k] = vtk.vtkContourFilter() contours[k].SetInputConnection(sample[k].GetOutputPort()) # generation d'une valeur dans l'intervalle spécifié (le min et le max sont inclus) contours[k].GenerateValues(1, 0.0, 0.1) # mapper mapper[k] = vtk.vtkPolyDataMapper() mapper[k].SetInputConnection(contours[k].GetOutputPort()) mapper[k].ScalarVisibilityOff() actor[k] = vtk.vtkActor() actor[k].SetMapper(mapper[k]) #actor[k].GetProperty().EdgeVisibilityOn() actor[k].GetProperty().SetColor( colors.GetColor3d(colorsCell[k % len(colorsCell)])) actor[k].GetProperty().SetEdgeColor(colors.GetColor3d('SteelBlue')) #Add the actors to the scene renderer.AddActor(contActor) for k in lnume: renderer.AddActor(actor[k]) interactor.Initialize() renwin.Render() interactor.Start() return (renwin) colors = vtk.vtkNamedColors() #Set the background color. colors.SetColor("BkgColor", [26, 51, 77, 255]) # Create a plane planeSource = vtk.vtkPlaneSource() planeSource.SetCenter(1.0, 0.0, 0.0) planeSource.SetNormal(1.0, 0.0, 1.0) planeSource.Update() plane = planeSource.GetOutput() # Create a mapper and actor mapper = vtk.vtkPolyDataMapper() mapper.SetInputData(plane) actor = vtk.vtkActor() actor.SetMapper(mapper) actor.GetProperty().SetColor(colors.GetColor3d("Cyan")) # Create a renderer, render window and interactor renderer = vtk.vtkRenderer() renderWindow = vtk.vtkRenderWindow() renderWindow.SetWindowName("Plane") renderWindow.AddRenderer(renderer) renderWindowInteractor = vtk.vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renderWindow) # Add the actors to the scene renderer.AddActor(actor) renderer.SetBackground(colors.GetColor3d("BkgColor")) # Render and interact renderWindow.Render() renderWindowInteractor.Start()
def main(): colors = vtk.vtkNamedColors() renderer = vtk.vtkRenderer() renderWindow = vtk.vtkRenderWindow() renderWindow.AddRenderer(renderer) interactor = vtk.vtkRenderWindowInteractor() interactor.SetRenderWindow(renderWindow) renderWindow.SetSize(640, 480) # # Create surface of implicit function. # # Sample quadric function. quadric = vtk.vtkQuadric() quadric.SetCoefficients(1, 2, 3, 0, 1, 0, 0, 0, 0, 0) sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(25, 25, 25) sample.SetImplicitFunction(quadric) isoActor = vtk.vtkActor() CreateIsosurface(sample, isoActor) outlineIsoActor = vtk.vtkActor() CreateOutline(sample, outlineIsoActor) planesActor = vtk.vtkActor() CreatePlanes(sample, planesActor, 3) outlinePlanesActor = vtk.vtkActor() CreateOutline(sample, outlinePlanesActor) planesActor.AddPosition(isoActor.GetBounds()[0] * 2.0, 0, 0) outlinePlanesActor.AddPosition(isoActor.GetBounds()[0] * 2.0, 0, 0) contourActor = vtk.vtkActor() CreateContours(sample, contourActor, 3, 15) outlineContourActor = vtk.vtkActor() CreateOutline(sample, outlineContourActor) contourActor.AddPosition(isoActor.GetBounds()[0] * 4.0, 0, 0) outlineContourActor.AddPosition(isoActor.GetBounds()[0] * 4.0, 0, 0) renderer.AddActor(planesActor) renderer.AddActor(outlinePlanesActor) renderer.AddActor(contourActor) renderer.AddActor(outlineContourActor) renderer.AddActor(isoActor) renderer.AddActor(outlineIsoActor) renderer.TwoSidedLightingOn() renderer.SetBackground(colors.GetColor3d("SlateGray")) # Try to set camera to match figure on book renderer.GetActiveCamera().SetPosition(0, -1, 0) renderer.GetActiveCamera().SetFocalPoint(0, 0, 0) renderer.GetActiveCamera().SetViewUp(0, 0, -1) renderer.ResetCamera() renderer.GetActiveCamera().Elevation(20) renderer.GetActiveCamera().Azimuth(10) renderer.GetActiveCamera().Dolly(1.2) renderer.ResetCameraClippingRange() renderWindow.SetSize(640, 480) renderWindow.SetWindowName('QuadricVisualization'); renderWindow.Render() # interact with data interactor.Start()
#!/usr/bin/env python import vtk # Test vtkExtractCells # Control test size #res = 200 res = 50 # Test cell extraction # # Quadric definition quadric = vtk.vtkQuadric() quadric.SetCoefficients([.5,1,.2,0,.1,0,0,.2,0,0]) sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(res,res,res) sample.SetImplicitFunction(quadric) sample.ComputeNormalsOff() sample.Update() # Now extract the cells: use badly formed range extract = vtk.vtkExtractCells() extract.SetInputConnection(sample.GetOutputPort()) extract.AddCellRange(0,sample.GetOutput().GetNumberOfCells()) extrMapper = vtk.vtkDataSetMapper() extrMapper.SetInputConnection(extract.GetOutputPort()) extrMapper.ScalarVisibilityOff() extrActor = vtk.vtkActor() extrActor.SetMapper(extrMapper) extrActor.GetProperty().SetColor(.8,.4,.4)
# Test vtkContour3DLinearGrid with vtkScalarTree and an input # vtkCompositeDataSet # Control test size res = 50 #res = 250 serialProcessing = 0 mergePoints = 1 interpolateAttr = 0 computeNormals = 0 computeScalarRange = 0 # # Quadric definition quadricL = vtk.vtkQuadric() quadricL.SetCoefficients([.5,1,.2,0,.1,0,0,.2,0,0]) sampleL = vtk.vtkSampleFunction() sampleL.SetModelBounds(-1,0, -1,1, -1,1) sampleL.SetSampleDimensions(int(res/2),res,res) sampleL.SetImplicitFunction(quadricL) sampleL.ComputeNormalsOn() sampleL.Update() # # Quadric definition quadricR = vtk.vtkQuadric() quadricR.SetCoefficients([.5,1,.2,0,.1,0,0,.2,0,0]) sampleR = vtk.vtkSampleFunction() sampleR.SetModelBounds(0,1, -1,1, -1,1) sampleR.SetSampleDimensions(int(res/2),res,res)
# Add a x-y-z coordinate to the original point axes_coor = vtk.vtkAxes() axes_coor.SetOrigin(0, 0, 0) mapper_axes_coor = vtk.vtkPolyDataMapper() mapper_axes_coor.SetInputConnection(axes_coor.GetOutputPort()) actor_axes_coor = vtk.vtkActor() actor_axes_coor.SetMapper(mapper_axes_coor) renderer_1.AddActor(actor_axes_coor) renderer_2.AddActor(actor_axes_coor) iren.Initialize() iren.Start() # =========================================================================== # Left view: Quadric defined with vtkQuadric quadric_1 = vtk.vtkQuadric() quadric_1.SetCoefficients(coef) sample_1 = vtk.vtkSampleFunction() sample_1.SetImplicitFunction(quadric_1) sample_1.ComputeNormalsOff() contour_1 = vtk.vtkContourFilter() contour_1.SetInputConnection(sample_1.GetOutputPort()) contour_1.SetValue(0, contour_value) # =========================================================================== # Right view: Quadric defined with meshgrid range_x = [-1, 1] range_y = [-1, 1] range_z = [-1, 1]
def ComputeEdgeOfUnion(lnume, A, S, pz): use_function_callback = True colors = vtk.vtkNamedColors() colorsCell = ['AliceBlue', 'Green', 'Blue', 'Yellow', 'Magenta'] # A renderer and render window renderer = vtk.vtkRenderer() renderer.SetBackground(colors.GetColor3d('Silver')) # render window renwin = vtk.vtkRenderWindow() renwin.SetWindowName("CallBack") renwin.AddRenderer(renderer) # An interactor interactor = vtk.vtkRenderWindowInteractor() interactor.SetRenderWindow(renwin) # Start if use_function_callback: CloseWin.int = interactor interactor.AddObserver('EndInteractionEvent', CloseWin) # Create actors # create container Sphere sphere = vtk.vtkQuadric() sphere.SetCoefficients(S) sampleS = vtk.vtkSampleFunction() sampleS.SetImplicitFunction(sphere) # mapper mapperSphere = vtk.vtkPolyDataMapper() mapperSphere.SetInputConnection(sampleS.GetOutputPort()) mapperSphere.ScalarVisibilityOff() # actorSphere = vtk.vtkActor() # actorSphere.SetMapper(mapperSphere) # actorSphere.GetProperty().EdgeVisibilityOn() # actorSphere.GetProperty().SetColor(colors.GetColor3d('AliceBlue')) # actorSphere.GetProperty().SetEdgeColor(colors.GetColor3d('SteelBlue')) boundsC = np.array(sampleS.GetModelBounds()) for k in range(3): boundsC[2 * k] = -1.1 * np.sqrt(-S[9]) boundsC[2 * k + 1] = 1.1 * np.sqrt(-S[9]) print(S[9]) print(boundsC) sampleS.SetModelBounds(boundsC) # surface.SetValue(0, 0.0) # contoursS = vtk.vtkContourFilter() contoursS.SetInputConnection(sampleS.GetOutputPort()) contoursS.GenerateValues(1, 0.0, 1.2) contMapper = vtk.vtkPolyDataMapper() contMapper.SetInputConnection(contoursS.GetOutputPort()) contMapper.SetScalarRange(0.0, 1.2) contActor = vtk.vtkActor() contActor.GetProperty().SetOpacity(0.1) contActor.SetMapper(contMapper) # create an ellipsoid using a implicit quadric quadric = [None] * len(lnume) mapper = [None] * len(lnume) actor = [None] * len(lnume) sample = [None] * len(lnume) contours = [None] * len(lnume) bounds = np.array(sampleS.GetModelBounds()) booleanOperation = vtk.vtkBooleanOperationPolyDataFilter() booleanOperation.SetOperationToUnion() booleanOperationMapper = vtk.vtkPolyDataMapper() booleanOperationActor = vtk.vtkActor() for k in lnume: quadric[k] = vtk.vtkQuadric() quadric[k].SetCoefficients(A[lnume[k]]) sample[k] = vtk.vtkSampleFunction() sample[k].SetImplicitFunction(quadric[k]) for l in range(3): bounds[2 * l] = -1.2 * np.sqrt(-S[9]) bounds[2 * l + 1] = 1.2 * np.sqrt(-S[9]) sample[k].SetModelBounds(bounds) contours[k] = vtk.vtkContourFilter() contours[k].SetInputConnection(sample[k].GetOutputPort()) # generation d'une valeur dans l'intervalle spécifié (le min et le max sont inclus) contours[k].GenerateValues(1, 0.0, 0.1) # mapper mapper[k] = vtk.vtkPolyDataMapper() mapper[k].SetInputConnection(contours[k].GetOutputPort()) mapper[k].ScalarVisibilityOff() actor[k] = vtk.vtkActor() actor[k].SetMapper(mapper[k]) #actor[k].GetProperty().EdgeVisibilityOn() actor[k].GetProperty().SetColor( colors.GetColor3d(colorsCell[k % len(colorsCell)])) actor[k].GetProperty().SetEdgeColor(colors.GetColor3d('SteelBlue')) Ellipsoid2Tri = vtk.vtkTriangleFilter() input2 = contours[k].GetOutput() Ellipsoid2Tri.SetInputData(input2) if k == lnume[0]: booleanOperationActor.SetMapper(mapper[lnume[0]]) EllipsoidsTri = vtk.vtkTriangleFilter() input1 = booleanOperation.GetOutputPort().GetOutput() # A revoir EllipsoidsTri.SetInputData(input1) else: booleanOperation.SetInputConnection(0, EllipsoidsTri.GetOutputPort()) booleanOperation.SetInputConnection(1, Ellipsoid2Tri.GetOutputPort()) booleanOperation.Update() booleanOperationMapper.SetInputConnection( booleanOperation.GetOutputPort()) booleanOperationMapper.ScalarVisibilityOff() booleanOperationActor.GetProperty().SetDiffuseColor( colors.GetColor3d("Banana"))
def makeModels(self): """ make vtk model """ # Here we create two ellipsoidal implicit functions and boolean them # together to form a "cross" shaped implicit function. quadric = vtk.vtkQuadric() quadric.SetCoefficients(.5, 1, .2, 0, .1, 0, 0, .2, 0, 0) sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(50, 50, 50) sample.SetImplicitFunction(quadric) sample.ComputeNormalsOff() trans = vtk.vtkTransform() trans.Scale(1, .5, .333) sphere = vtk.vtkSphere() sphere.SetRadius(self.radius) sphere.SetTransform(trans) trans2 = vtk.vtkTransform() trans2.Scale(.25, .5, 1.0) sphere2 = vtk.vtkSphere() sphere2.SetRadius(self.radius) sphere2.SetTransform(trans2) self.sphere_geom_1 = sphere self.sphere_geom_2 = sphere2 union = vtk.vtkImplicitBoolean() union.AddFunction(sphere) union.AddFunction(sphere2) union.SetOperationType(0) # Here is where it gets interesting. The implicit function is used to # extract those cells completely inside the function. They are then # shrunk to helpr show what was extracted. extract = vtk.vtkExtractGeometry() extract.SetInputConnection(sample.GetOutputPort()) extract.SetImplicitFunction(union) shrink = vtk.vtkShrinkFilter() shrink.SetInputConnection(extract.GetOutputPort()) shrink.SetShrinkFactor(self.shrink_factor) dataMapper = vtk.vtkDataSetMapper() dataMapper.SetInputConnection(shrink.GetOutputPort()) self.shrink_geom = shrink # data actor self.data_actor = vtk.vtkActor() self.data_actor.SetMapper(dataMapper) # The outline gives context to the original data. outline = vtk.vtkOutlineFilter() outline.SetInputConnection(sample.GetOutputPort()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) # outline actor self.outline_actor = vtk.vtkActor() self.outline_actor.SetMapper(outlineMapper) outlineProp = self.outline_actor.GetProperty() outlineProp.SetColor(0, 0, 0)
# Test vtkContour3DLinearGrid with vtkScalarTree and an input # vtkCompositeDataSet # Control test size res = 50 #res = 250 serialProcessing = 0 mergePoints = 1 interpolateAttr = 0 computeNormals = 0 computeScalarRange = 0 # # Quadric definition quadricL = vtk.vtkQuadric() quadricL.SetCoefficients([.5, 1, .2, 0, .1, 0, 0, .2, 0, 0]) sampleL = vtk.vtkSampleFunction() sampleL.SetModelBounds(-1, 0, -1, 1, -1, 1) sampleL.SetSampleDimensions(int(res / 2), res, res) sampleL.SetImplicitFunction(quadricL) sampleL.ComputeNormalsOn() sampleL.Update() # # Quadric definition quadricR = vtk.vtkQuadric() quadricR.SetCoefficients([.5, 1, .2, 0, .1, 0, 0, .2, 0, 0]) sampleR = vtk.vtkSampleFunction() sampleR.SetModelBounds(0, 1, -1, 1, -1, 1) sampleR.SetSampleDimensions(int(res / 2), res, res)
def main(): colors = vtk.vtkNamedColors() ren1 = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren1) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) quadric = vtk.vtkQuadric() quadric.SetCoefficients(0.5, 1, 0.2, 0, 0.1, 0, 0, 0.2, 0, 0) sample = vtk.vtkSampleFunction() sample.SetSampleDimensions(50, 50, 50) sample.SetImplicitFunction(quadric) sample.ComputeNormalsOff() trans = vtk.vtkTransform() trans.Scale(1, 0.5, 0.333) sphere = vtk.vtkSphere() sphere.SetRadius(0.25) sphere.SetTransform(trans) trans2 = vtk.vtkTransform() trans2.Scale(0.25, 0.5, 1.0) sphere2 = vtk.vtkSphere() sphere2.SetRadius(0.25) sphere2.SetTransform(trans2) booleanUnion = vtk.vtkImplicitBoolean() booleanUnion.AddFunction(sphere) booleanUnion.AddFunction(sphere2) booleanUnion.SetOperationType(0) # boolean Union extract = vtk.vtkExtractGeometry() extract.SetInputConnection(sample.GetOutputPort()) extract.SetImplicitFunction(booleanUnion) shrink = vtk.vtkShrinkFilter() shrink.SetInputConnection(extract.GetOutputPort()) shrink.SetShrinkFactor(0.5) dataMapper = vtk.vtkDataSetMapper() dataMapper.SetInputConnection(shrink.GetOutputPort()) dataActor = vtk.vtkActor() dataActor.SetMapper(dataMapper) # outline outline = vtk.vtkOutlineFilter() outline.SetInputConnection(sample.GetOutputPort()) outlineMapper = vtk.vtkPolyDataMapper() outlineMapper.SetInputConnection(outline.GetOutputPort()) outlineActor = vtk.vtkActor() outlineActor.SetMapper(outlineMapper) outlineActor.GetProperty().SetColor(0, 0, 0) # Add the actors to the renderer, set the background and size # ren1.AddActor(outlineActor) ren1.AddActor(dataActor) ren1.SetBackground(colors.GetColor3d("SlateGray")) renWin.SetSize(640, 480) renWin.SetWindowName('ExtractData') renWin.Render() ren1.GetActiveCamera().Azimuth(30) ren1.GetActiveCamera().Elevation(30) renWin.Render() iren.Start()
def testQuadricCut(self): solidTexture = (255, 255) clearTexture = (255, 0) edgeTexture = (0, 255) def makeBooleanTexture(caseNumber, resolution, thickness): #global solidTexture, clearTexture, edgeTexture booleanTexturecaseNumber = vtk.vtkBooleanTexture() booleanTexturecaseNumber.SetXSize(resolution) booleanTexturecaseNumber.SetYSize(resolution) booleanTexturecaseNumber.SetThickness(thickness) if caseNumber == 0: booleanTexturecaseNumber.SetInIn(solidTexture) booleanTexturecaseNumber.SetOutIn(solidTexture) booleanTexturecaseNumber.SetInOut(solidTexture) booleanTexturecaseNumber.SetOutOut(solidTexture) booleanTexturecaseNumber.SetOnOn(solidTexture) booleanTexturecaseNumber.SetOnIn(solidTexture) booleanTexturecaseNumber.SetOnOut(solidTexture) booleanTexturecaseNumber.SetInOn(solidTexture) booleanTexturecaseNumber.SetOutOn(solidTexture) elif caseNumber == 1: booleanTexturecaseNumber.SetInIn(clearTexture) booleanTexturecaseNumber.SetOutIn(solidTexture) booleanTexturecaseNumber.SetInOut(solidTexture) booleanTexturecaseNumber.SetOutOut(solidTexture) booleanTexturecaseNumber.SetOnOn(edgeTexture) booleanTexturecaseNumber.SetOnIn(edgeTexture) booleanTexturecaseNumber.SetOnOut(solidTexture) booleanTexturecaseNumber.SetInOn(edgeTexture) elif caseNumber == 2: booleanTexturecaseNumber.SetInIn(solidTexture) booleanTexturecaseNumber.SetOutIn(clearTexture) booleanTexturecaseNumber.SetInOut(solidTexture) booleanTexturecaseNumber.SetOutOut(solidTexture) booleanTexturecaseNumber.SetOnOn(edgeTexture) booleanTexturecaseNumber.SetOnIn(edgeTexture) booleanTexturecaseNumber.SetOnOut(solidTexture) booleanTexturecaseNumber.SetInOn(solidTexture) booleanTexturecaseNumber.SetOutOn(edgeTexture) elif caseNumber == 3: booleanTexturecaseNumber.SetInIn(clearTexture) booleanTexturecaseNumber.SetOutIn(clearTexture) booleanTexturecaseNumber.SetInOut(solidTexture) booleanTexturecaseNumber.SetOutOut(solidTexture) booleanTexturecaseNumber.SetOnOn(edgeTexture) booleanTexturecaseNumber.SetOnIn(clearTexture) booleanTexturecaseNumber.SetOnOut(solidTexture) booleanTexturecaseNumber.SetInOn(edgeTexture) booleanTexturecaseNumber.SetOutOn(edgeTexture) elif caseNumber == 4: booleanTexturecaseNumber.SetInIn(solidTexture) booleanTexturecaseNumber.SetOutIn(solidTexture) booleanTexturecaseNumber.SetInOut(clearTexture) booleanTexturecaseNumber.SetOutOut(solidTexture) booleanTexturecaseNumber.SetOnOn(edgeTexture) booleanTexturecaseNumber.SetOnIn(solidTexture) booleanTexturecaseNumber.SetOnOut(edgeTexture) booleanTexturecaseNumber.SetInOn(edgeTexture) booleanTexturecaseNumber.SetOutOn(solidTexture) elif caseNumber == 5: booleanTexturecaseNumber.SetInIn(clearTexture) booleanTexturecaseNumber.SetOutIn(solidTexture) booleanTexturecaseNumber.SetInOut(clearTexture) booleanTexturecaseNumber.SetOutOut(solidTexture) booleanTexturecaseNumber.SetOnOn(edgeTexture) booleanTexturecaseNumber.SetOnIn(edgeTexture) booleanTexturecaseNumber.SetOnOut(edgeTexture) booleanTexturecaseNumber.SetInOn(clearTexture) booleanTexturecaseNumber.SetOutOn(solidTexture) elif caseNumber == 6: booleanTexturecaseNumber.SetInIn(solidTexture) booleanTexturecaseNumber.SetOutIn(clearTexture) booleanTexturecaseNumber.SetInOut(clearTexture) booleanTexturecaseNumber.SetOutOut(solidTexture) booleanTexturecaseNumber.SetOnOn(edgeTexture) booleanTexturecaseNumber.SetOnIn(edgeTexture) booleanTexturecaseNumber.SetOnOut(edgeTexture) booleanTexturecaseNumber.SetInOn(edgeTexture) booleanTexturecaseNumber.SetOutOn(edgeTexture) elif caseNumber == 7: booleanTexturecaseNumber.SetInIn(clearTexture) booleanTexturecaseNumber.SetOutIn(clearTexture) booleanTexturecaseNumber.SetInOut(clearTexture) booleanTexturecaseNumber.SetOutOut(solidTexture) booleanTexturecaseNumber.SetOnOn(edgeTexture) booleanTexturecaseNumber.SetOnIn(clearTexture) booleanTexturecaseNumber.SetOnOut(edgeTexture) booleanTexturecaseNumber.SetInOn(clearTexture) booleanTexturecaseNumber.SetOutOn(edgeTexture) elif caseNumber == 8: booleanTexturecaseNumber.SetInIn(solidTexture) booleanTexturecaseNumber.SetOutIn(solidTexture) booleanTexturecaseNumber.SetInOut(solidTexture) booleanTexturecaseNumber.SetOutOut(clearTexture) booleanTexturecaseNumber.SetOnOn(edgeTexture) booleanTexturecaseNumber.SetOnIn(solidTexture) booleanTexturecaseNumber.SetOnOut(edgeTexture) booleanTexturecaseNumber.SetInOn(solidTexture) booleanTexturecaseNumber.SetOutOn(edgeTexture) elif caseNumber == 9: booleanTexturecaseNumber.SetInIn(clearTexture) booleanTexturecaseNumber.SetInOut(solidTexture) booleanTexturecaseNumber.SetOutIn(solidTexture) booleanTexturecaseNumber.SetOutOut(clearTexture) booleanTexturecaseNumber.SetOnOn(edgeTexture) booleanTexturecaseNumber.SetOnIn(edgeTexture) booleanTexturecaseNumber.SetOnOut(edgeTexture) booleanTexturecaseNumber.SetInOn(edgeTexture) booleanTexturecaseNumber.SetOutOn(edgeTexture) elif caseNumber == 10: booleanTexturecaseNumber.SetInIn(solidTexture) booleanTexturecaseNumber.SetInOut(solidTexture) booleanTexturecaseNumber.SetOutIn(clearTexture) booleanTexturecaseNumber.SetOutOut(clearTexture) booleanTexturecaseNumber.SetOnOn(edgeTexture) booleanTexturecaseNumber.SetOnIn(edgeTexture) booleanTexturecaseNumber.SetOnOut(edgeTexture) booleanTexturecaseNumber.SetInOn(solidTexture) booleanTexturecaseNumber.SetOutOn(clearTexture) elif caseNumber == 11: booleanTexturecaseNumber.SetInIn(clearTexture) booleanTexturecaseNumber.SetInOut(solidTexture) booleanTexturecaseNumber.SetOutIn(clearTexture) booleanTexturecaseNumber.SetOutOut(clearTexture) booleanTexturecaseNumber.SetOnOn(edgeTexture) booleanTexturecaseNumber.SetOnIn(clearTexture) booleanTexturecaseNumber.SetOnOut(edgeTexture) booleanTexturecaseNumber.SetInOn(edgeTexture) booleanTexturecaseNumber.SetOutOn(clearTexture) elif caseNumber == 12: booleanTexturecaseNumber.SetInIn(solidTexture) booleanTexturecaseNumber.SetInOut(clearTexture) booleanTexturecaseNumber.SetOutIn(solidTexture) booleanTexturecaseNumber.SetOutOut(clearTexture) booleanTexturecaseNumber.SetOnOn(edgeTexture) booleanTexturecaseNumber.SetOnIn(solidTexture) booleanTexturecaseNumber.SetOnOut(clearTexture) booleanTexturecaseNumber.SetInOn(edgeTexture) booleanTexturecaseNumber.SetOutOn(edgeTexture) elif caseNumber == 13: booleanTexturecaseNumber.SetInIn(clearTexture) booleanTexturecaseNumber.SetInOut(clearTexture) booleanTexturecaseNumber.SetOutIn(solidTexture) booleanTexturecaseNumber.SetOutOut(clearTexture) booleanTexturecaseNumber.SetOnOn(edgeTexture) booleanTexturecaseNumber.SetOnIn(edgeTexture) booleanTexturecaseNumber.SetOnOut(clearTexture) booleanTexturecaseNumber.SetInOn(clearTexture) booleanTexturecaseNumber.SetOutOn(edgeTexture) elif caseNumber == 14: booleanTexturecaseNumber.SetInIn(solidTexture) booleanTexturecaseNumber.SetInOut(clearTexture) booleanTexturecaseNumber.SetOutIn(clearTexture) booleanTexturecaseNumber.SetOutOut(clearTexture) booleanTexturecaseNumber.SetOnOn(edgeTexture) booleanTexturecaseNumber.SetOnIn(edgeTexture) booleanTexturecaseNumber.SetOnOut(clearTexture) booleanTexturecaseNumber.SetInOn(edgeTexture) booleanTexturecaseNumber.SetOutOn(clearTexture) elif caseNumber == 15: booleanTexturecaseNumber.SetInIn(clearTexture) booleanTexturecaseNumber.SetInOut(clearTexture) booleanTexturecaseNumber.SetOutIn(clearTexture) booleanTexturecaseNumber.SetOutOut(clearTexture) booleanTexturecaseNumber.SetOnOn(clearTexture) booleanTexturecaseNumber.SetOnIn(clearTexture) booleanTexturecaseNumber.SetOnOut(clearTexture) booleanTexturecaseNumber.SetInOn(clearTexture) booleanTexturecaseNumber.SetOutOn(clearTexture) booleanTexturecaseNumber.Update() return booleanTexturecaseNumber # A list of positions positions = [] positions.append((-4, 4, 0)) positions.append((-2, 4, 0)) positions.append((0, 4, 0)) positions.append((2, 4, 0)) positions.append((-4, 2, 0)) positions.append((-2, 2, 0)) positions.append((0, 2, 0)) positions.append((2, 2, 0)) positions.append((-4, 0, 0)) positions.append((-2, 0, 0)) positions.append((0, 0, 0)) positions.append((2, 0, 0)) positions.append((-4, -2, 0)) positions.append((-2, -2, 0)) positions.append((0, -2, 0)) positions.append((2, -2, 0)) ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) # define two elliptical cylinders quadric1 = vtk.vtkQuadric() quadric1.SetCoefficients(1, 2, 0, 0, 0, 0, 0, 0, 0, -.07) quadric2 = vtk.vtkQuadric() quadric2.SetCoefficients(2, 1, 0, 0, 0, 0, 0, 0, 0, -.07) # create a sphere for all to use aSphere = vtk.vtkSphereSource() aSphere.SetPhiResolution(50) aSphere.SetThetaResolution(50) # create texture coordinates for all tcoords = vtk.vtkImplicitTextureCoords() tcoords.SetInputConnection(aSphere.GetOutputPort()) tcoords.SetRFunction(quadric1) tcoords.SetSFunction(quadric2) aMapper = vtk.vtkDataSetMapper() aMapper.SetInputConnection(tcoords.GetOutputPort()) # create a mapper, sphere and texture map for each case aTexture = [] anActor = [] for i in range(0, 16): aTexture.append(vtk.vtkTexture()) aTexture[i].SetInputData(makeBooleanTexture(i, 256, 1).GetOutput()) aTexture[i].InterpolateOff() aTexture[i].RepeatOff() anActor.append(vtk.vtkActor()) anActor[i].SetMapper(aMapper) anActor[i].SetTexture(aTexture[i]) anActor[i].SetPosition(positions[i]) anActor[i].SetScale(2.0, 2.0, 2.0) ren.AddActor(anActor[i]) ren.SetBackground(0.4392, 0.5020, 0.5647) ren.ResetCamera() ren.GetActiveCamera().Zoom(1.4) renWin.SetSize(500, 500) # render and interact with data iRen = vtk.vtkRenderWindowInteractor() iRen.SetRenderWindow(renWin); renWin.Render() img_file = "quadricCut.png" vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) vtk.test.Testing.interact()