1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4''' 5========================================================================= 6 7 Program: Visualization Toolkit 8 Module: TestNamedColorsIntegration.py 9 10 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 11 All rights reserved. 12 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 13 14 This software is distributed WITHOUT ANY WARRANTY; without even 15 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 16 PURPOSE. See the above copyright notice for more information. 17 18========================================================================= 19''' 20 21import vtk 22import vtk.test.Testing 23from vtk.util.misc import vtkGetDataRoot 24VTK_DATA_ROOT = vtkGetDataRoot() 25 26class TestAllLogic(vtk.test.Testing.vtkTest): 27 28 def testAllLogic(self): 29 30 # append multiple displaced spheres into an RGB image. 31 32 33 # Image pipeline 34 35 renWin = vtk.vtkRenderWindow() 36 37 logics = ["And", "Or", "Xor", "Nand", "Nor", "Not"] 38 types = ["Float", "Double", "UnsignedInt", "UnsignedLong", "UnsignedShort", "UnsignedChar"] 39 40 sphere1 = list() 41 sphere2 = list() 42 logic = list() 43 mapper = list() 44 actor = list() 45 imager = list() 46 47 for idx, operator in enumerate(logics): 48 ScalarType = types[idx] 49 50 sphere1.append(vtk.vtkImageEllipsoidSource()) 51 sphere1[idx].SetCenter(95, 100, 0) 52 sphere1[idx].SetRadius(70, 70, 70) 53 eval('sphere1[idx].SetOutputScalarTypeTo' + ScalarType + '()') 54 sphere1[idx].Update() 55 56 sphere2.append(vtk.vtkImageEllipsoidSource()) 57 sphere2[idx].SetCenter(161, 100, 0) 58 sphere2[idx].SetRadius(70, 70, 70) 59 eval('sphere2[idx].SetOutputScalarTypeTo' + ScalarType + '()') 60 sphere2[idx].Update() 61 62 logic.append(vtk.vtkImageLogic()) 63 logic[idx].SetInput1Data(sphere1[idx].GetOutput()) 64 if operator != "Not": 65 logic[idx].SetInput2Data(sphere2[idx].GetOutput()) 66 67 logic[idx].SetOutputTrueValue(150) 68 eval('logic[idx].SetOperationTo' + operator + '()') 69 70 mapper.append(vtk.vtkImageMapper()) 71 mapper[idx].SetInputConnection(logic[idx].GetOutputPort()) 72 mapper[idx].SetColorWindow(255) 73 mapper[idx].SetColorLevel(127.5) 74 75 actor.append(vtk.vtkActor2D()) 76 actor[idx].SetMapper(mapper[idx]) 77 78 imager.append(vtk.vtkRenderer()) 79 imager[idx].AddActor2D(actor[idx]) 80 81 renWin.AddRenderer(imager[idx]) 82 83 84 85 imager[0].SetViewport(0, .5, .33, 1) 86 imager[1].SetViewport(.33, .5, .66, 1) 87 imager[2].SetViewport(.66, .5, 1, 1) 88 imager[3].SetViewport(0, 0, .33, .5) 89 imager[4].SetViewport(.33, 0, .66, .5) 90 imager[5].SetViewport(.66, 0, 1, .5) 91 92 renWin.SetSize(768, 512) 93 94 # render and interact with data 95 96 iRen = vtk.vtkRenderWindowInteractor() 97 iRen.SetRenderWindow(renWin); 98 renWin.Render() 99 100 img_file = "TestAllLogic.png" 101 vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25) 102 vtk.test.Testing.interact() 103 104if __name__ == "__main__": 105 vtk.test.Testing.main([(TestAllLogic, 'test')]) 106