Hi Gib,<div><br></div><div>Glad to hear the good news. I'm sure that you've also figured out that you can use glyphs for your spheres.</div><div><br></div><div>Changing the number of glyphs is possible, but a bit tricky. You have to re-initialize the input polydata when changing the number of points or cells. So going back to my example code, you would do something like this:</div>
<div><br></div><div>input->Initialize();</div><div>input->SetPoints(new_points);</div><div>input->SetVerts(new_verts);</div><div><br></div><div>Generally you will have to re-build the points and the verts arrays from scratch if you want to remove elements. You can call Initialize() on the arrays to clear them before rebuilding them. The VTK arrays don't have an erase() method like C++ vectors do.</div>
<div><br></div><div> David</div><div><br></div><div><br><div class="gmail_quote">On Wed, Nov 24, 2010 at 4:34 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;">Great success!! The glyphs render so fast that the extra time is negligible. Thanks again. It isn't needed for this application, but for future reference: is it possible to change the glypher input on the fly, i.e. the number of cells?<br>
<br>
Hi Fred, are you still interested in seeing the code that runs slowly?<div class="im"><br>
<br>
Gib<br>
<br>
On 25/11/2010 9:20 a.m., David Gobbi wrote:<br>
</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div></div><div class="h5">
Hi Gib,<br>
<br>
Even though a programmable source like that wiki example is probably the<br>
"cleanest" way to do things, there is a simpler way to build a dataset for<br>
vtkGlyph3D.<br>
<br>
The vtkGlyph3D filter needs two inputs: one input for the positions of each<br>
glyph (i.e. one point per glyph) and another input for the glyph shape (i.e. the<br>
square that you already made).<br>
<br>
The first input is just a list of points, you can build it as a polydata just<br>
like you did with the squares, except that you want to use "verts" as your cells:<br>
<br>
vtkSmartPointer<vtkPoints> positions = vtkSmartPointer<vtkPoints>::New();<br>
vtkSmartPointer<vtkCellArray> dummycells = vtkSmartPointer<vtkCellArray>::New();<br>
positions->SetNumberOfPoints(npos); // number of squares<br>
dummycells->InsertNextCell(npos); // size of dummy "verts" array<br>
for (int ipos = 0; ipos < npos; ipos++)<br>
{<br>
positions->SetPoint(ipos, x, y, z); // square positions set here<br>
dummycells->InsertCellPoint(ipos);<br>
}<br>
<br>
vtkSmartPointer<vtkPolyData> input = vtkSmartPointer<vtkPolyData>::New();<br>
input->SetPoints(positions);<br>
input->SetVerts(dummycells);<br>
<br>
vtkSmartPointer<vtkGlyph3D> glypher = vtkSmartPointer<vtkGlyph3D>::New();<br>
glypher->SetInput(input);<br>
glypher->SetSource(polygonPolyData);<br>
<br>
Then feed the output of the glypher into the mapper, and it will automatically<br>
draw a square at each position. To change the positions, you would do this:<br>
<br>
positions->SetPoint(idx, x, y, z); // set point idx to (x,y,z)<br>
glypher->Modified(); // tell glypher that the data has changed<br>
<br>
Then re-render, and the squares will be at their new positions. I have not<br>
tested the code above, but I've done similar things in the past.<br>
<br>
David<br>
<br>
On Wed, Nov 24, 2010 at 12:52 PM, Gib Bogle <<a href="mailto:g.bogle@auckland.ac.nz" target="_blank">g.bogle@auckland.ac.nz</a><br></div></div><div class="im">
<mailto:<a href="mailto:g.bogle@auckland.ac.nz" target="_blank">g.bogle@auckland.ac.nz</a>>> wrote:<br>
<br>
Seb, if this is what you are referring to:<br>
<a href="http://www.itk.org/Wiki/VTK/Java_Code_Samples" target="_blank">http://www.itk.org/Wiki/VTK/Java_Code_Samples</a><br>
it might require skills a bit beyond my rather primitive level of C++ expertise.<br>
<br>
<br>
Gib<br>
<br>
Quoting Sebastien Jourdain <<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a><br></div>
<mailto:<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a>>>:<div class="im"><br>
<br>
You can use a single actor, you will need to have a programable source<br>
that update the output dataset that has the location of each center of<br>
the square.<br>
<br>
Pipeline: Actor(Mapper(Glyph(CustomSource, Square)))<br>
<br>
To change the position of a square, you can have something like that...<br>
<br>
customSource.SetSquarePosition( suquareId, xyz )<br>
<br>
Seb<br>
<br>
PS: I think I wrote a sample code in Java for programmable source on the<br>
wiki...<br>
<br>
<br>
On Wed, Nov 24, 2010 at 1:41 PM, Gib Bogle <<a href="mailto:g.bogle@auckland.ac.nz" target="_blank">g.bogle@auckland.ac.nz</a><br></div><div class="im">
<mailto:<a href="mailto:g.bogle@auckland.ac.nz" target="_blank">g.bogle@auckland.ac.nz</a>>> wrote:<br>
<br>
Hi Seb,<br>
<br>
Although I referred to a simplified case in which the squares don't<br>
change,<br>
in general I need to allow for their movement. Therefore I don't<br>
think it<br>
will be possible for me to use a single actor. If I'm wrong, could you<br>
please provide a bit more detail?<br>
<br>
Thanks<br>
Gib<br>
<br>
Quoting Sebastien Jourdain <<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a><br></div>
<mailto:<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a>>>:<div class="im"><br>
<br>
Hi Gib,<br>
<br>
My first question will be. Are you using one actor for each of your<br>
10000 flat squares ?<br>
If so, the performance limitation may come from the number of actors<br>
involved. One solution to that is to create only one dataset<br>
with all<br>
the squares that has only one mapper and actor. To do so, you can<br>
build it by hand or simply use the Glyph filter with your square<br>
as a<br>
glyph and another dataset that has the location of those squares.<br>
<br>
Seb<br>
<br>
<br>
On Wed, Nov 24, 2010 at 12:44 AM, Gib Bogle<br></div>
<<a href="mailto:g.bogle@auckland.ac.nz" target="_blank">g.bogle@auckland.ac.nz</a> <mailto:<a href="mailto:g.bogle@auckland.ac.nz" target="_blank">g.bogle@auckland.ac.nz</a>>><div><div></div>
<div class="h5"><br>
wrote:<br>
<br>
<br>
I asked about this before, but didn't attract any responses.<br>
I have a<br>
better understanding of the issue now, so perhaps my<br>
questions will make<br>
more sense.<br>
<br>
At regular intervals as my simulation program executes, I am<br>
rendering a<br>
scene that contains mainly about 1000 small spheres (which<br>
move) and<br>
about<br>
10000 flat squares (which do not move). I have discovered<br>
that the<br>
surprising slowness of the the rendering is caused by the<br>
squares, even<br>
though the spheres have ThetaResolution and PhiResolution<br>
both equal to<br>
12,<br>
which I guess means 144 faces per sphere, i.e. a total of<br>
144,000 faces.<br>
By<br>
my calculations rendering the scene 288 times with spheres<br>
alone takes<br>
about<br>
4 sec, with the squares alone takes about 20 sec, and with<br>
both spheres<br>
and<br>
squares about 24 sec. That is, 10,000 squares take 5 times<br>
as long as<br>
1000<br>
spheres with 144,000 faces.<br>
<br>
Apparently there's something very inefficient about the way I am<br>
rendering<br>
the squares. Here is the code for tileMapper (which makes<br>
squares):<br>
<br>
// Create the square<br>
// Setup points to draw a unit square in the XY plane, at y=0<br>
vtkSmartPointer<vtkPoints> points =<br>
vtkSmartPointer<vtkPoints>::New();<br>
vtkSmartPointer<vtkCellArray> vertices =<br>
vtkSmartPointer<vtkCellArray>::New();<br>
points->InsertNextPoint(-0.5, 0.0, -0.5);<br>
points->InsertNextPoint( 0.5, 0.0, -0.5);<br>
points->InsertNextPoint( 0.5, 0.0, 0.5);<br>
points->InsertNextPoint(-0.5, 0.0, 0.5);<br>
<br>
vtkSmartPointer<vtkPolygon> polygon =<br>
vtkSmartPointer<vtkPolygon>::New();<br>
polygon->GetPointIds()->SetNumberOfIds(4); //make a quad<br>
polygon->GetPointIds()->SetId(0, 0);<br>
polygon->GetPointIds()->SetId(1, 1);<br>
polygon->GetPointIds()->SetId(2, 2);<br>
polygon->GetPointIds()->SetId(3, 3);<br>
<br>
//Add the polygon to a list of polygons<br>
vtkSmartPointer<vtkCellArray> polygons =<br>
vtkSmartPointer<vtkCellArray>::New();<br>
polygons->InsertNextCell(polygon);<br>
<br>
//Create a PolyData<br>
vtkSmartPointer<vtkPolyData> polygonPolyData =<br>
vtkSmartPointer<vtkPolyData>::New();<br>
polygonPolyData->SetPoints(points);<br>
polygonPolyData->SetPolys(polygons);<br>
<br>
//Create a mapper and actor<br>
tileMapper = vtkPolyDataMapper::New();<br>
tileMapper->SetInput(polygonPolyData);<br>
tileMapper->ScalarVisibilityOff();<br>
<br>
The square actors are made like this:<br>
<br>
actor = vtkActor::New();<br>
actor->SetMapper(tileMapper);<br>
actor->GetProperty()->SetColor(boneColor);<br>
actor->GetProperty()->SetAmbient(0.5);<br>
actor->GetProperty()->SetDiffuse(0.2);<br>
actor->GetProperty()->SetSpecular(0.5);<br>
actor->SetPosition(pos);<br>
ren->AddActor(actor);<br>
<br>
then not touched again (in the simulations I report times for.)<br>
<br>
I'd be very grateful if someone could give me a clue as to<br>
what I'm doing<br>
wrong to make the rendering so slow.<br>
<br>
Thanks<br>
Gib<br>
_______________________________________________<br></div></div>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a> <<a href="http://www.kitware.com" target="_blank">http://www.kitware.com</a>><div class="im"><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>
<br>
<br>
<br>
<br>
<br>
----------------------------------------------------------------<br>
This message was sent using IMP, the Internet Messaging Program.<br>
_______________________________________________<br></div>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a> <<a href="http://www.kitware.com" target="_blank">http://www.kitware.com</a>><div class="im"><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>
<br>
<br>
<br>
<br>
<br>
----------------------------------------------------------------<br>
This message was sent using IMP, the Internet Messaging Program.<br>
_______________________________________________<br></div>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a> <<a href="http://www.kitware.com" target="_blank">http://www.kitware.com</a>><div class="im"><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>
<br>
<br>
</div></blockquote><div><div></div><div class="h5">
_______________________________________________<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>