Hi Gib,<div><br></div><div>Even though a programmable source like that wiki example is probably the "cleanest" way to do things, there is a simpler way to build a dataset for vtkGlyph3D.</div><div><br></div><div>
The vtkGlyph3D filter needs two inputs: one input for the positions of each glyph (i.e. one point per glyph) and another input for the glyph shape (i.e. the square that you already made).</div><div><br></div><div>The first input is just a list of points, you can build it as a polydata just like you did with the squares, except that you want to use "verts" as your cells:</div>
<div><br></div><div><meta charset="utf-8"><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">vtkSmartPointer<vtkPoints> positions = vtkSmartPointer<vtkPoints>::New();<br>
vtkSmartPointer<vtkCellArray> dummycells = vtkSmartPointer<vtkCellArray>::New();</span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">positions->SetNumberOfPoints(npos); // number of squares</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">dummycells->InsertNextCell(npos); // size of dummy "verts" array</span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">for (int ipos = 0; ipos < npos; ipos++)</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "> {</span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "> positions->SetPoint(ipos, x, y, z); // square positions set here</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "> dummycells->InsertCellPoint(ipos);</span></div><div> }</div><div><br><meta charset="utf-8"><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">vtkSmartPointer<vtkPolyData> input = vtkSmartPointer<vtkPolyData>::New();</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">input->SetPoints(positions);</span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">input->SetVerts(dummycells);</span></div>
<div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br></span></div><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><meta charset="utf-8">vtkSmartPointer<vtkGlyph3D> glypher = vtkSmartPointer<vtkGlyph3D>::New();</span></div>
<div>glypher->SetInput(input);</div><div>glypher->SetSource(polygonPolyData);</div><div><br></div><div>Then feed the output of the glypher into the mapper, and it will automatically draw a square at each position. To change the positions, you would do this:</div>
<div><br></div><div>positions->SetPoint(idx, x, y, z); // set point idx to (x,y,z)</div><div>glypher->Modified(); // tell glypher that the data has changed</div><div><br></div><div>Then re-render, and the squares will be at their new positions. I have not tested the code above, but I've done similar things in the past.</div>
<div><br></div><div> David</div><div><br><div class="gmail_quote">On Wed, Nov 24, 2010 at 12:52 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;">
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.<div><div></div><div class="h5"><br>
<br>
Gib<br>
<br>
Quoting Sebastien Jourdain <<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a>>:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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 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>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Seb,<br>
<br>
Although I referred to a simplified case in which the squares don't change,<br>
in general I need to allow for their movement. Therefore I don't 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>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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 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 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 <<a href="mailto:g.bogle@auckland.ac.nz" target="_blank">g.bogle@auckland.ac.nz</a>><br>
wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
I asked about this before, but didn't attract any responses. I have a<br>
better understanding of the issue now, so perhaps my questions will make<br>
more sense.<br>
<br>
At regular intervals as my simulation program executes, I am rendering a<br>
scene that contains mainly about 1000 small spheres (which move) and<br>
about<br>
10000 flat squares (which do not move). I have discovered that the<br>
surprising slowness of the the rendering is caused by the squares, even<br>
though the spheres have ThetaResolution and PhiResolution both equal to<br>
12,<br>
which I guess means 144 faces per sphere, i.e. a total of 144,000 faces.<br>
By<br>
my calculations rendering the scene 288 times with spheres alone takes<br>
about<br>
4 sec, with the squares alone takes about 20 sec, and with both spheres<br>
and<br>
squares about 24 sec. That is, 10,000 squares take 5 times 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 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 = 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 = 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 what I'm doing<br>
wrong to make the rendering so slow.<br>
<br>
Thanks<br>
Gib<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>
<br>
</blockquote>
<br>
</blockquote>
<br>
<br>
<br>
----------------------------------------------------------------<br>
This message was sent using IMP, the Internet Messaging Program.<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>
<br>
</blockquote>
<br>
</blockquote>
<br>
<br>
<br>
----------------------------------------------------------------<br>
This message was sent using IMP, the Internet Messaging Program.<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 <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>