1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
'''
=========================================================================
Program: Visualization Toolkit
Module: TestNamedColorsIntegration.py
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================
'''
import vtk
import vtk.test.Testing
from vtk.util.misc import vtkGetDataRoot
VTK_DATA_ROOT = vtkGetDataRoot()
class TestICPTransform(vtk.test.Testing.vtkTest):
def testICPTransform(self):
renWin = vtk.vtkRenderWindow()
#iren = vtk.vtkRenderWindowInteractor()
#iren.SetRenderWindow(renWin)
# Create objects
sscale = {2:[0.7, 0.7, 0.7],
3:[0.5, 0.5, 0.5]}
scenter = {2:[-0.25, 0.25, 0.0],
3:[ 0.4, -0.3, 0.0]}
scolors = {2:[0.2, 0.6, 0.1],
3:[0.1, 0.2, 0.6]}
s = dict() # The super quadric sources
for sidx in range(1, 4):
s.update({sidx:vtk.vtkSuperquadricSource()})
s[sidx].ToroidalOff()
s[sidx].SetThetaResolution(20)
s[sidx].SetPhiResolution(20)
s[sidx].SetPhiRoundness(0.7 + (sidx - 2) * 0.4)
s[sidx].SetThetaRoundness(0.85 + (sidx - 1) * 0.4)
if sidx in sscale:
s[sidx].SetScale(sscale[sidx])
if sidx in scenter:
s[sidx].SetCenter(scenter[sidx])
s[sidx].Update()
ren = dict() # Renderers
sm = dict() # Mappers for the super quadric source
sa = dict() # Actors for the super quadric source
fe = dict() # Feature edges
fem = dict() # Feature edges mappers
fea = dict() # Feature edges actors
icp = dict() # Iterated closest point transforms
# Create the renderers
for ridx in range(1, 4):
ren.update({ridx: vtk.vtkRenderer()})
ren[ridx].SetViewport((ridx - 1) / 3.0, 0.0, ridx / 3.0, 1.0)
ren[ridx].SetBackground(0.7, 0.8, 1.0)
cam = ren[ridx].GetActiveCamera()
cam.SetPosition(1.7, 1.4, 1.7)
renWin.AddRenderer(ren[ridx])
# renderer 1 has all 3 objects, render i has object 1 and i (i=2, 3)
# add actors (corresponding to the objects) to each renderer
# and ICP transforms from objects i or to 1.
# object 1 has feature edges too.
for sidx in range(1, 4):
if ridx == 1 or sidx == 1 or ridx == sidx:
sm.update({ridx:{sidx:vtk.vtkPolyDataMapper()}})
sm[ridx][sidx].SetInputConnection(s[sidx].GetOutputPort())
sa.update({ridx:{sidx:vtk.vtkActor()}})
sa[ridx][sidx].SetMapper(sm[ridx][sidx])
prop = sa[ridx][sidx].GetProperty()
if sidx in scolors:
prop.SetColor(scolors[sidx])
if sidx == 1:
prop.SetOpacity(0.2)
fe.update({ridx:{sidx:vtk.vtkFeatureEdges()}})
src = s[sidx]
fe[ridx][sidx].SetInputConnection(src.GetOutputPort())
fe[ridx][sidx].BoundaryEdgesOn()
fe[ridx][sidx].ColoringOff()
fe[ridx][sidx].ManifoldEdgesOff()
fem.update({ridx:{sidx:vtk.vtkPolyDataMapper()}})
fem[ridx][sidx].SetInputConnection(fe[ridx][sidx].GetOutputPort())
fem[ridx][sidx].SetResolveCoincidentTopologyToPolygonOffset()
fea.update({ridx:{sidx:vtk.vtkActor()}})
fea[ridx][sidx].SetMapper(fem[ridx][sidx])
ren[ridx].AddActor(fea[ridx][sidx])
ren[ridx].AddActor(sa[ridx][sidx])
if ridx > 1 and ridx == sidx:
icp.update({ridx:{sidx:vtk.vtkIterativeClosestPointTransform()}})
icp[ridx][sidx].SetSource(s[sidx].GetOutput())
icp[ridx][sidx].SetTarget(s[1].GetOutput())
icp[ridx][sidx].SetCheckMeanDistance(1)
icp[ridx][sidx].SetMaximumMeanDistance(0.001)
icp[ridx][sidx].SetMaximumNumberOfIterations(30)
icp[ridx][sidx].SetMaximumNumberOfLandmarks(50)
sa[ridx][sidx].SetUserTransform(icp[ridx][sidx])
icp[3][3].StartByMatchingCentroidsOn()
renWin.SetSize(400, 100)
# render and interact with data
iRen = vtk.vtkRenderWindowInteractor()
iRen.SetRenderWindow(renWin);
renWin.Render()
img_file = "TestICPTransform.png"
vtk.test.Testing.compareImage(iRen.GetRenderWindow(), vtk.test.Testing.getAbsImagePath(img_file), threshold=25)
vtk.test.Testing.interact()
if __name__ == "__main__":
vtk.test.Testing.main([(TestICPTransform, 'test')])
|