<div dir="ltr">THANKS,<div>this helped me a lot</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jan 29, 2016 at 11:55 AM, Cory Quammen <span dir="ltr"><<a href="mailto:cory.quammen@kitware.com" target="_blank">cory.quammen@kitware.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">Hi Rishi,<div><br></div><div>Answers inlined below:<br><div class="gmail_extra"><br><div class="gmail_quote"><span>On Fri, Jan 29, 2016 at 1:04 PM, Rishi Rawat <span dir="ltr"><<a href="mailto:rishiraw@usc.edu" target="_blank">rishiraw@usc.edu</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"><span style="font-size:12.8px">How to color a sphere source in an appendpolydata object?</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">Eventually, I want to plot hundreds+ spheres in 3D, each with a different color. I'd like to use an appendpolydata object to improve efficiency. Below is the code I have so far using 1 sphere. </span><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">I think I've tracked the problem down to the appendData object. doing appendData.AddInputData(</span><span style="font-size:12.8px">polydata sp ) causes nothing to show up in my renderwindow, whereas if I do appendData.AddInputConnection(</span><span style="font-size:12.8px">Sphere.GetOutputPort() ), I get an object to show up, but it is gray (no color).</span><br style="font-size:12.8px"><br style="font-size:12.8px"><span style="font-size:12.8px">How can I color objects before placing them in the appendpolydata object?</span></div></div></blockquote><div><br></div></span><div>VTK doesn't quite work that way, but you are close. See my notes below.</div><span><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div style="font-size:12.8px">My Code:<div><br></div><div><br>import vtk<br>from vtk import *<br># create a rendering window and renderer<br>ren = vtk.vtkRenderer()<br>renWin = vtk.vtkRenderWindow()<br>renWin.AddRenderer(ren)<br><br># create a renderwindowinteractor<br>iren = vtk.vtkRenderWindowInteractor()<br>iren.SetRenderWindow(renWin)<br><br>#setup colors (setting the name to "Colors" is nice but not necessary)<br>Colors = vtk.vtkUnsignedCharArray();<br>Colors.SetNumberOfComponents(3);<br>Colors.SetName("Colors");<br>Colors.InsertNextTuple3(255,0,0);<br></div></div></div></div></blockquote><div><br></div></span><div>You'll need a color for *each* cell in in each sphere that you are appending together. You'll need a call to</div><div><br></div><div>Colors.SetNumberOfTuples()</div><div><br></div><div>after Colors.SetNumberOfComponents(3) and pass it the number of cells in the sphere source. Then, you'll need to duplicate the color by calling</div><div><br></div><div>Colors.InsertNextTuple3()</div><div><br></div><div>once for each cell. You can actually use</div><div><br></div><div>color = [255, 0, 0]</div><div>Colors.SetTupleValue(i, color)</div><div><br></div><div>where i is the cell index because you have already allocated the array when you called Colors.SetNumberOfTuples().</div><span><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div style="font-size:12.8px"><div>sphere = vtk.vtkSphereSource()<br>sphere.SetThetaResolution(5)<br>sphere.SetPhiResolution(5)<br>sphere.SetRadius(10)<br>sphere.SetCenter( 0,0,0)<br>sp = sphere.GetOutput()<br></div></div></div></div></blockquote><div><br></div></span><div>You'll need a call to 'sphere.Update()' here so that the output is generated, otherwise 'sp' will be empty and you'll be appending a lot of empty data sets.</div><span><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div style="font-size:12.8px"><div>sp.GetCellData().SetScalars(Colors);<br>appendData.AddInputData(sp )<br><br><br># If I enable this next line, i get a sphere, but it is not colored, it is gray<br>#appendData.AddInputConnection(sphere.GetOutputPort() )<br><br>print "done"<br>#cd.SetScalars(Colors)<br>#cd.Update()<br>#sphere.Update()<br><br>mapper = vtk.vtkPolyDataMapper()<br>if vtk.VTK_MAJOR_VERSION <= 5:<br> mapper.SetInput(trianglePolyData)<br>else:<br> #mapper.SetInputData(trianglePolyData)<br> mapper.SetInputConnection(appendData.GetOutputPort() )<br># actor<br>actor = vtk.vtkActor()<br>actor.SetMapper(mapper)<br></div></div></div></div></blockquote><div><br></div></span><div>You'll also need to call</div><div><br></div><div>mapper.SetColorModeToDirectScalars()</div><div><br></div><div>to ensure that your spheres are colored by the colors you set in the cell data array rather than being mapped through a color map.</div><div><br></div><div>HTH,</div><div>Cory</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><div dir="ltr"><div><div style="font-size:12.8px"><div><br># assign actor to the renderer<br>ren.AddActor(actor)<br><br># enable user interface interactor<br>iren.Initialize()<br>renWin.Render()<br>iren.Start()</div></div><div><br></div>
</div></div>
<br></span>_______________________________________________<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" rel="noreferrer" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Search the list archives at: <a href="http://markmail.org/search/?q=vtkusers" rel="noreferrer" target="_blank">http://markmail.org/search/?q=vtkusers</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/vtkusers" rel="noreferrer" target="_blank">http://public.kitware.com/mailman/listinfo/vtkusers</a><br>
<br></blockquote></div><span><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div>Cory Quammen<br>R&D Engineer<br>Kitware, Inc.</div>
</font></span></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div><div dir="ltr"><div><div dir="ltr"><div style="color:rgb(136,136,136)"><font face="garamond, serif">Rishi Rawat</font></div><div style="color:rgb(136,136,136)"><font face="garamond, serif">MD/PHD Candidate</font></div><div style="color:rgb(136,136,136)"><font face="garamond, serif">HTE (Health Technology Engineering) Fellow</font></div><div style="color:rgb(136,136,136)"><font face="garamond, serif">Keck School of Medicine</font></div><div style="color:rgb(136,136,136)"><span style="font-family:garamond,serif">University of Southern California</span></div><div style="color:rgb(136,136,136)"><a href="mailto:rishiraw@usc.edu" style="font-family:garamond,serif" target="_blank">rishiraw@usc.edu</a><span style="font-family:garamond,serif"> | </span><a value="+17147217918" style="font-family:garamond,serif;color:rgb(34,34,34)">720-352-6218</a><br></div></div></div></div></div>
</div></div>