<div dir="ltr">The Code here:<div><br></div><div><div>#!/usr/bin/env python</div><div>import vtk</div><div>from vtk.test import Testing</div><div><br></div><div><br></div><div><br></div><div># This example shows how to visualise the variation in shape in a set of objects using</div><div># vtkPCAAnalysisFilter.</div><div>#</div><div># We make three ellipsoids by distorting and translating a sphere and then align them together</div><div># using vtkProcrustesAlignmentFilter, and then pass the output to vtkPCAAnalysisFilter. We visualise</div><div># the first and second modes - the major sources of variation that were in the training set.</div><div>sphere = vtk.vtkSphereSource()</div><div>sphere.SetPhiResolution(36)</div><div>sphere.SetThetaResolution(36)</div><div>sphere.Update()</div><div># make two copies of the shape and distort them a little</div><div>transform1 = vtk.vtkTransform()</div><div>transform1.Translate(0.2,0.1,0.3)</div><div>transform1.Scale(1.3,1.1,0.8)</div><div>transform2 = vtk.vtkTransform()</div><div>transform2.Translate(0.3,0.7,0.1)</div><div>transform2.Scale(1.0,0.1,1.8)</div><div>transformer1 = vtk.vtkTransformPolyDataFilter()</div><div>transformer1.SetInputConnection(sphere.GetOutputPort())</div><div>transformer1.SetTransform(transform1)</div><div>transformer1.Update()</div><div>transformer2 = vtk.vtkTransformPolyDataFilter()</div><div>transformer2.SetInputConnection(sphere.GetOutputPort())</div><div>transformer2.SetTransform(transform2)</div><div>transformer2.Update()</div><div>#------------------------------------------------------------------</div><div># map these three shapes into the first renderer</div><div>#------------------------------------------------------------------</div><div>map1a = vtk.vtkPolyDataMapper()</div><div>map1a.SetInputConnection(sphere.GetOutputPort())</div><div>Actor1a = vtk.vtkActor()</div><div>Actor1a.SetMapper(map1a)</div><div>Actor1a.GetProperty().SetDiffuseColor(1.0000,0.3882,0.2784)</div><div>map1b = vtk.vtkPolyDataMapper()</div><div>map1b.SetInputConnection(transformer1.GetOutputPort())</div><div>Actor1b = vtk.vtkActor()</div><div>Actor1b.SetMapper(map1b)</div><div>Actor1b.GetProperty().SetDiffuseColor(0.3882,1.0000,0.2784)</div><div>map1c = vtk.vtkPolyDataMapper()</div><div>map1c.SetInputConnection(transformer2.GetOutputPort())</div><div>Actor1c = vtk.vtkActor()</div><div>Actor1c.SetMapper(map1c)</div><div>Actor1c.GetProperty().SetDiffuseColor(0.3882,0.2784,1.0000)</div><div>#------------------------------------------------------------------</div><div># align the shapes using Procrustes (using SetModeToRigidBody)</div><div># and map the aligned shapes into the second renderer</div><div>#------------------------------------------------------------------</div><div>group = vtk.vtkMultiBlockDataGroupFilter()</div><div>group.AddInputConnection(sphere.GetOutputPort())</div><div>group.AddInputConnection(transformer1.GetOutputPort())</div><div>group.AddInputConnection(transformer2.GetOutputPort())</div><div>procrustes = vtk.vtkProcrustesAlignmentFilter()</div><div>procrustes.SetInputConnection(group.GetOutputPort())</div><div>procrustes.GetLandmarkTransform().SetModeToRigidBody()</div><div>procrustes.Update()</div><div>map2a = vtk.vtkPolyDataMapper()</div><div>map2a.SetInputData(procrustes.GetOutput().GetBlock(0))</div><div>Actor2a = vtk.vtkActor()</div><div>Actor2a.SetMapper(map2a)</div><div>Actor2a.GetProperty().SetDiffuseColor(1.0000,0.3882,0.2784)</div><div>map2b = vtk.vtkPolyDataMapper()</div><div>map2b.SetInputData(procrustes.GetOutput().GetBlock(1))</div><div>Actor2b = vtk.vtkActor()</div><div>Actor2b.SetMapper(map2b)</div><div>Actor2b.GetProperty().SetDiffuseColor(0.3882,1.0000,0.2784)</div><div>map2c = vtk.vtkPolyDataMapper()</div><div>map2c.SetInputData(procrustes.GetOutput().GetBlock(2))</div><div>Actor2c = vtk.vtkActor()</div><div>Actor2c.SetMapper(map2c)</div><div>Actor2c.GetProperty().SetDiffuseColor(0.3882,0.2784,1.0000)</div><div>#------------------------------------------------------------------</div><div># pass the output of Procrustes to vtkPCAAnalysisFilter</div><div>#------------------------------------------------------------------</div><div>pca = vtk.vtkPCAAnalysisFilter()</div><div>pca.SetInputConnection(procrustes.GetOutputPort())</div><div>pca.Update()</div><div># we need to call Update because GetParameterisedShape is not</div><div># part of the normal SetInput/GetOutput pipeline</div><div>#------------------------------------------------------------------</div><div># map the first mode into the third renderer:</div><div># -3,0,3 standard deviations on the first mode</div><div># illustrate the extremes around the average shape</div><div>#------------------------------------------------------------------</div><div>params = vtk.vtkFloatArray()</div><div>params.SetNumberOfComponents(1)</div><div>params.SetNumberOfTuples(1)</div><div>params.SetTuple1(0,0.0)</div><div>shapea = vtk.vtkPolyData()</div><div>shapea.DeepCopy(sphere.GetOutput())</div><div>pca.GetParameterisedShape(params,shapea)</div><div>normalsa = vtk.vtkPolyDataNormals()</div><div>normalsa.SetInputData(shapea)</div><div>map3a = vtk.vtkPolyDataMapper()</div><div>map3a.SetInputConnection(normalsa.GetOutputPort())</div><div>Actor3a = vtk.vtkActor()</div><div>Actor3a.SetMapper(map3a)</div><div>Actor3a.GetProperty().SetDiffuseColor(1,1,1)</div><div>params.SetTuple1(0,-3.0)</div><div>shapeb = vtk.vtkPolyData()</div><div>shapeb.DeepCopy(sphere.GetOutput())</div><div>pca.GetParameterisedShape(params,shapeb)</div><div>normalsb = vtk.vtkPolyDataNormals()</div><div>normalsb.SetInputData(shapeb)</div><div>map3b = vtk.vtkPolyDataMapper()</div><div>map3b.SetInputConnection(normalsb.GetOutputPort())</div><div>Actor3b = vtk.vtkActor()</div><div>Actor3b.SetMapper(map3b)</div><div>Actor3b.GetProperty().SetDiffuseColor(1,1,1)</div><div>params.SetTuple1(0,3.0)</div><div>shapec = vtk.vtkPolyData()</div><div>shapec.DeepCopy(sphere.GetOutput())</div><div>pca.GetParameterisedShape(params,shapec)</div><div>normalsc = vtk.vtkPolyDataNormals()</div><div>normalsc.SetInputData(shapec)</div><div>map3c = vtk.vtkPolyDataMapper()</div><div>map3c.SetInputConnection(normalsc.GetOutputPort())</div><div>Actor3c = vtk.vtkActor()</div><div>Actor3c.SetMapper(map3c)</div><div>Actor3c.GetProperty().SetDiffuseColor(1,1,1)</div><div>#------------------------------------------------------------------</div><div># map the second mode into the fourth renderer:</div><div>#------------------------------------------------------------------</div><div>params4 = vtk.vtkFloatArray()</div><div>params4.SetNumberOfComponents(1)</div><div>params4.SetNumberOfTuples(2)</div><div>params4.SetTuple1(0,0.0)</div><div>params4.SetTuple1(1,-3.0)</div><div>shape4a = vtk.vtkPolyData()</div><div>shape4a.DeepCopy(sphere.GetOutput())</div><div>pca.GetParameterisedShape(params4,shape4a)</div><div>normals4a = vtk.vtkPolyDataNormals()</div><div>normals4a.SetInputData(shape4a)</div><div>map4a = vtk.vtkPolyDataMapper()</div><div>map4a.SetInputConnection(normals4a.GetOutputPort())</div><div>Actor4a = vtk.vtkActor()</div><div>Actor4a.SetMapper(map4a)</div><div>Actor4a.GetProperty().SetDiffuseColor(1,1,1)</div><div>params4.SetTuple1(1,0.0)</div><div>shape4b = vtk.vtkPolyData()</div><div>shape4b.DeepCopy(sphere.GetOutput())</div><div>pca.GetParameterisedShape(params4,shape4b)</div><div>normals4b = vtk.vtkPolyDataNormals()</div><div>normals4b.SetInputData(shape4b)</div><div>map4b = vtk.vtkPolyDataMapper()</div><div>map4b.SetInputConnection(normals4b.GetOutputPort())</div><div>Actor4b = vtk.vtkActor()</div><div>Actor4b.SetMapper(map4b)</div><div>Actor4b.GetProperty().SetDiffuseColor(1,1,1)</div><div>params4.SetTuple1(1,3.0)</div><div>shape4c = vtk.vtkPolyData()</div><div>shape4c.DeepCopy(sphere.GetOutput())</div><div>pca.GetParameterisedShape(params4,shape4c)</div><div>normals4c = vtk.vtkPolyDataNormals()</div><div>normals4c.SetInputData(shape4c)</div><div>map4c = vtk.vtkPolyDataMapper()</div><div>map4c.SetInputConnection(normals4c.GetOutputPort())</div><div>Actor4c = vtk.vtkActor()</div><div>Actor4c.SetMapper(map4c)</div><div>Actor4c.GetProperty().SetDiffuseColor(1,1,1)</div><div>#------------------------------------------------------------------</div><div># Create the RenderWindow and its four Renderers</div><div>#------------------------------------------------------------------</div><div>ren1 = vtk.vtkRenderer()</div><div>ren2 = vtk.vtkRenderer()</div><div>ren3 = vtk.vtkRenderer()</div><div>ren4 = vtk.vtkRenderer()</div><div>renWin = vtk.vtkRenderWindow()</div><div>renWin.AddRenderer(ren1)</div><div>renWin.AddRenderer(ren2)</div><div>renWin.AddRenderer(ren3)</div><div>renWin.AddRenderer(ren4)</div><div>renWin.SetSize(600,200)</div><div>iren = vtk.vtkRenderWindowInteractor()</div><div>iren.SetRenderWindow(renWin)</div><div># Add the actors to the renderer</div><div>ren1.AddActor(Actor1a)</div><div>ren1.AddActor(Actor1b)</div><div>ren1.AddActor(Actor1c)</div><div>ren2.AddActor(Actor2a)</div><div>ren2.AddActor(Actor2b)</div><div>ren2.AddActor(Actor2c)</div><div>ren3.AddActor(Actor3a)</div><div>ren3.AddActor(Actor3b)</div><div>ren3.AddActor(Actor3c)</div><div>ren4.AddActor(Actor4a)</div><div>ren4.AddActor(Actor4b)</div><div>ren4.AddActor(Actor4c)</div><div># set the properties of the renderers</div><div>ren1.SetBackground(1,1,1)</div><div>ren1.SetViewport(0.0,0.0,0.25,1.0)</div><div>ren1.ResetCamera()</div><div>ren1.GetActiveCamera().SetPosition(1,-1,0)</div><div>ren1.ResetCamera()</div><div>ren2.SetBackground(1,1,1)</div><div>ren2.SetViewport(0.25,0.0,0.5,1.0)</div><div>ren2.ResetCamera()</div><div>ren2.GetActiveCamera().SetPosition(1,-1,0)</div><div>ren2.ResetCamera()</div><div>ren3.SetBackground(1,1,1)</div><div>ren3.SetViewport(0.5,0.0,0.75,1.0)</div><div>ren3.ResetCamera()</div><div>ren3.GetActiveCamera().SetPosition(1,-1,0)</div><div>ren3.ResetCamera()</div><div>ren4.SetBackground(1,1,1)</div><div>ren4.SetViewport(0.75,0.0,1.0,1.0)</div><div>ren4.ResetCamera()</div><div>ren4.GetActiveCamera().SetPosition(1,-1,0)</div><div>ren4.ResetCamera()</div><div># render the image</div><div>#</div><div>renWin.Render()</div><div># output the image to file (used to generate the initial regression image)</div><div>#vtkWindowToImageFilter to_image</div><div>#to_image SetInput renWin</div><div>#vtkPNGWriter to_png</div><div>#to_png SetFileName "TestPCA.png"</div><div>#to_png SetInputConnection [to_image GetOutputPort]</div><div>#to_png Write</div><div># prevent the tk window from showing up then start the event loop</div><div># --- end of script --</div></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 23, 2014 at 2:22 PM, Lizeth Castellanos <span dir="ltr"><<a href="mailto:castellanoslizan@gmail.com" target="_blank">castellanoslizan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hello vtk-users!<div><br></div><div>I'm usign the TestPCA.py from <a href="http://vtk.org/gitwebp=VTK.git;a=blob;f=Filters/Hybrid/Testing/Python/TestPCA.py" target="_blank">http://vtk.org/gitwebp=VTK.git;a=blob;f=Filters/Hybrid/Testing/Python/TestPCA.py</a></div><div><br></div><div>When I run the test, I get the next error:</div><div><br></div><div><div><font face="monospace, monospace">ERROR: In /media/hdd2/VTK/vtk-5.6.0/Filtering/vtkExecutive.cxx, line 757</font></div><div><font face="monospace, monospace">vtkStreamingDemandDrivenPipeline (0x23a12e0): Algorithm vtkProcrustesAlignmentFilter(0x23a0400) returned failure for request: vtkInformation (0x23a18e0)</font></div><div><font face="monospace, monospace">  Debug: Off</font></div><div><font face="monospace, monospace">  Modified Time: 894</font></div><div><font face="monospace, monospace">  Reference Count: 1</font></div><div><font face="monospace, monospace">  Registered Events: (none)</font></div><div><font face="monospace, monospace">  Request: REQUEST_DATA_OBJECT</font></div><div><font face="monospace, monospace">  ALGORITHM_AFTER_FORWARD: 1</font></div><div><font face="monospace, monospace">  FORWARD_DIRECTION: 0</font></div><div><font face="monospace, monospace">  FROM_OUTPUT_PORT: 0</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">Traceback (most recent call last):<br></font></div><div><font face="monospace, monospace">  File "TestPCA.py", line 63, in <module></font></div><div><font face="monospace, monospace">    map2a.SetInputData(procrustes.GetOutput().GetBlock(0))</font></div><div><font face="monospace, monospace">    AttributeError: SetInputData</font></div></div><div><br></div><div>Someone have any idea about it?</div><div><div><br></div><div><div><br></div><div>Thanks!</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-Lizeth<br clear="all"><div><br></div><br><div><div dir="ltr"><div><br></div><div><br></div></div></div>
</div></font></span></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div>Lizeth  Andrea Castellanos Beltrán.</div><div>MSc Student</div><div>Federal University of Rio Grande do Sul (UFRGS)</div><div><br></div><div><br></div></div></div>
</div>