It should be possible to modify the scalars the same way as the points:<div><br></div><div>points->SetPoint(idx, point);</div><div>colors->SetTupleValue(idx, color);</div><div>glypher->Modified();</div><div><br></div>
<div>The vtkCellArray isn't necessary (but somehow polydata with no cells goes against my sense of aesthetics).</div><div><br></div><div> David<br><br><div class="gmail_quote">On Thu, Nov 25, 2010 at 7:07 PM, Gib Bogle <span dir="ltr"><<a href="mailto:g.bogle@auckland.ac.nz">g.bogle@auckland.ac.nz</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">It turns out there was a difference between what I was doing and the wiki example code, one of those seemingly insignificant details that are actually important.<br>
<br>
I had<br>
glypher->SetScaleFactor(1.0);<br>
and the wiki code has<br>
glypher->ScalingOff();<br>
With that change it works (although I don't know why).<br>
<br>
I have a final (I hope!) question. I now want to selectively change the color of glyphs. I know how to change the position of the point indexed by idx:<br>
points->SetPoint(idx,x,y,z);<br>
glypher->Modified();<br>
<br>
Presumably something very similar is needed to change the color of this glyph, but I don't know how to access the array that holds the colors, which was initialized with:<br>
input->GetPointData()->SetScalars(colors);<br>
<br>
Can someone help me over this last hurdle?<div><div></div><div class="h5"><br>
<br>
<br>
On 26/11/2010 12:42 p.m., Gib Bogle wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I've been trying to follow David Gobbi's suggestion about coloring the glyphs<br>
that I am now using to render my squares with. The hints he provided were not<br>
enough for me to get it working, so I hunted around and found the wiki example<br>
<a href="http://www.itk.org/Wiki/VTK/Examples/Cxx/Visualization/ColorGlyphs" target="_blank">http://www.itk.org/Wiki/VTK/Examples/Cxx/Visualization/ColorGlyphs</a><br>
This works fine, so I thought I could just follow the same path. It doesn't work<br>
for me, and I'm guessing that it's because I'm using a vtkPolyData that contains<br>
both vtkPoints and vtkCellArray. David advised me to use<br>
input->GetPointData()->AddArray(...)<br>
but I couldn't see how to implement this. My code is shown below. What am I<br>
missing? (This code doesn't display the squares at all, unless I comment out<br>
input->GetPointData()->SetScalars(colors).)<br>
I apologize for the ignorance I'm displaying - I don't understand why it's<br>
necessary to use the vtkCellArray, for example.<br>
<br>
points = vtkSmartPointer<vtkPoints>::New();<br>
vtkSmartPointer<vtkCellArray> dummycells = vtkSmartPointer<vtkCellArray>::New();<br>
points->SetNumberOfPoints(npos); // number of squares<br>
dummycells->InsertNextCell(npos);<br>
colors = vtkSmartPointer<vtkUnsignedCharArray>::New();<br>
colors->SetName("colors");<br>
colors->SetNumberOfComponents(3);<br>
unsigned char g[3] = {0,255,0};<br>
for (int ipos=0; ipos<npos; ipos++) {<br>
points->SetPoint(ipos, x, y, z);<br>
dummycells->InsertCellPoint(ipos);<br>
colors->InsertNextTupleValue(g);<br>
}<br>
input = vtkSmartPointer<vtkPolyData>::New();<br>
input->SetPoints(points);<br>
input->SetVerts(dummycells);<br>
input->GetPointData()->SetScalars(colors);<br>
glypher = vtkSmartPointer<vtkGlyph3D>::New();<br>
glypher->SetInput(input);<br>
glypher->SetSource(polygonPolyData);<br>
glypher->SetScaleFactor(1.0);<br>
glypher->SetColorModeToColorByScalar();<br>
// glypher->SetInputArrayToProcess(3, 0, 0, 0, "colors");<br>
glypher->Update();<br>
squareMapper = vtkPolyDataMapper::New();<br>
squareMapper->SetInputConnection(glypher->GetOutputPort());<br>
glactor = vtkActor::New();<br>
glactor->SetMapper(squareMapper);<br>
glactor->GetProperty()->SetAmbient(0.5);<br>
glactor->GetProperty()->SetDiffuse(0.2);<br>
glactor->GetProperty()->SetSpecular(0.5);<br>
ren->AddActor(glactor);<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at:<br>
<a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" 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" target="_blank">http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</div></div></blockquote></div><br></div>