Thanks for fixing the example. The "import hybrid" isn't needed for anything, I've removed it.<div><br></div><div> - David</div><div><br><div><div class="gmail_quote">On Thu, Feb 3, 2011 at 10:01 AM, Lucas <span dir="ltr"><<a href="mailto:wsacul@gmail.com">wsacul@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Yes that and SetScalars make it work.<br><br>I changed the example code on <a href="http://www.vtk.org/Wiki/VTK/Examples/Python/SolidColoredTriangle" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Python/SolidColoredTriangle</a> to use SetScalars (not sure what the 'import hybrid' is there for, I didn't get it with my python-vtk install so had to delete it to run the example)-<br>
<br>Thanks!<br><font color="#888888"><br>Lucas</font><div><div></div><div class="h5"><br><br><div class="gmail_quote">On Wed, Feb 2, 2011 at 4:18 PM, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com" target="_blank">david.gobbi@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">
Hi Lucas,<div><br></div><div>Changing to SetScalars() was correct. The SetVectors() method is not for colors.</div><div><br></div><div>The bug in your code appears to be how you are filling in the array. You need to instantiate the vtkUnsignedCharArray before the loop, not inside of the loop:</div>
<div>
<div><span style="font-family:'courier new',monospace"><br></span></div><div><span style="font-family:'courier new',monospace"><span style="font-family:arial"><span style="font-family:'courier new',monospace">#setup colors</span><br style="font-family:'courier new',monospace">
<span style="font-family:'courier new',monospace">Colors = vtk.vtkUnsignedCharArray()</span><br style="font-family:'courier new',monospace"><span style="font-family:'courier new',monospace">Colors.SetNumberOfComponents(3)</span><br style="font-family:'courier new',monospace">
<span style="font-family:'courier new',monospace">Colors.SetName("Colors")</span></span></span></div><div><span style="font-family:'courier new',monospace"><span style="font-family:arial"><span style="font-family:'courier new',monospace"><br>
</span></span></span></div><div><span style="font-family:'courier new',monospace">for i in range(255):</span><br style="font-family:'courier new',monospace"><span style="font-family:'courier new',monospace"> for j in range(255):</span><br style="font-family:'courier new',monospace">
<span style="font-family:'courier new',monospace"> id = Points.InsertNextPoint(i, j, 1)</span><br style="font-family:'courier new',monospace"><span style="font-family:'courier new',monospace"> Vertices.InsertNextCell(1)</span><br style="font-family:'courier new',monospace">
<span style="font-family:'courier new',monospace"> Vertices.InsertCellPoint(id)</span><font face="'courier new', monospace"><br></font><span style="font-family:'courier new',monospace"> Colors.InsertNextTuple3(255,i,j)</span><br>
<br></div></div><div>They way you had written the code, you were creating 255 different arrays and setting only the first tuple of each one.</div><div><br></div><div> - David</div><div><br></div><div><br><div class="gmail_quote">
<div><div></div><div>
On Wed, Feb 2, 2011 at 2:27 PM, Lucas <span dir="ltr"><<a href="mailto:wsacul@gmail.com" target="_blank">wsacul@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">
<div><div></div><div>
I'd like to render a point cloud with points individually colored, so I combined the example <a href="http://www.vtk.org/Wiki/VTK/Examples/Python/TriangleColoredPoints" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Python/TriangleColoredPoints</a> with others that sets up the interactive render window. But the points are all white, unless I call SetColor which gives them all the same color. What am I missing?<br>
<br><span style="font-family:courier new,monospace">import vtk</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"># create a rendering window and renderer</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">ren = vtk.vtkRenderer()</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">renWin = vtk.vtkRenderWindow()</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">renWin.AddRenderer(ren)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">renWin.SetSize(400,400)</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"># create a renderwindowinteractor</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">iren = vtk.vtkRenderWindowInteractor()</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">iren.SetRenderWindow(renWin)</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">#setup points and vertices</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">Points = vtk.vtkPoints()</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">Vertices = vtk.vtkCellArray()</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">for i in range(255):</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> for j in range(255):</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> id = Points.InsertNextPoint(i, j, 1)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> Vertices.InsertNextCell(1)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> Vertices.InsertCellPoint(id)</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> #setup colors</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> Colors = vtk.vtkUnsignedCharArray()</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> Colors.SetNumberOfComponents(3)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace"> Colors.SetName("Colors")</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"> Colors.InsertNextTuple3(255,i,j)</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">polydata = vtk.vtkPolyData()</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">polydata.SetPoints(Points)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">polydata.SetVerts(Vertices)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">polydata.GetPointData().SetVectors(Colors)</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">polydata.Modified()</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">polydata.Update()</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">######</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">mapper = vtk.vtkPolyDataMapper()</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">mapper.SetInput(polydata)</span><br style="font-family:courier new,monospace"><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">actor = vtk.vtkActor()</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">actor.SetMapper(mapper)</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">ren.AddActor(actor)</span><br style="font-family:courier new,monospace">
<br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace"># enable user interface interactor</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">renWin.Render()</span><br style="font-family:courier new,monospace">
<span style="font-family:courier new,monospace">iren.Initialize()</span><br style="font-family:courier new,monospace"><span style="font-family:courier new,monospace">iren.Start()</span><br> <br><br>Replacing SetVectors() with SetScalars produces some point coloring, but the colors seem random.<br>
<br>I'm using vtk 5.4.2 and Python 2.6.6 on Ubuntu.<br><br>Thanks,<br><br><font class="Apple-style-span" color="#888888">Lucas</font><br></div></div></blockquote></div></div></blockquote></div></div></div></blockquote>
</div></div></div>