Hi Gib,<div><br></div><div>Glad to hear the good news.  I&#39;m sure that you&#39;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-&gt;Initialize();</div><div>input-&gt;SetPoints(new_points);</div><div>input-&gt;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&#39;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">&lt;<a href="mailto:g.bogle@auckland.ac.nz">g.bogle@auckland.ac.nz</a>&gt;</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&#39;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>
&quot;cleanest&quot; 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 &quot;verts&quot; as your cells:<br>
<br>
vtkSmartPointer&lt;vtkPoints&gt; positions = vtkSmartPointer&lt;vtkPoints&gt;::New();<br>
vtkSmartPointer&lt;vtkCellArray&gt; dummycells = vtkSmartPointer&lt;vtkCellArray&gt;::New();<br>
positions-&gt;SetNumberOfPoints(npos); // number of squares<br>
dummycells-&gt;InsertNextCell(npos); // size of dummy &quot;verts&quot; array<br>
for (int ipos = 0; ipos &lt; npos; ipos++)<br>
   {<br>
   positions-&gt;SetPoint(ipos, x, y, z);  // square positions set here<br>
   dummycells-&gt;InsertCellPoint(ipos);<br>
   }<br>
<br>
vtkSmartPointer&lt;vtkPolyData&gt; input = vtkSmartPointer&lt;vtkPolyData&gt;::New();<br>
input-&gt;SetPoints(positions);<br>
input-&gt;SetVerts(dummycells);<br>
<br>
vtkSmartPointer&lt;vtkGlyph3D&gt; glypher = vtkSmartPointer&lt;vtkGlyph3D&gt;::New();<br>
glypher-&gt;SetInput(input);<br>
glypher-&gt;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-&gt;SetPoint(idx, x, y, z); // set point idx to (x,y,z)<br>
glypher-&gt;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&#39;ve done similar things in the past.<br>
<br>
   David<br>
<br>
On Wed, Nov 24, 2010 at 12:52 PM, Gib Bogle &lt;<a href="mailto:g.bogle@auckland.ac.nz" target="_blank">g.bogle@auckland.ac.nz</a><br></div></div><div class="im">
&lt;mailto:<a href="mailto:g.bogle@auckland.ac.nz" target="_blank">g.bogle@auckland.ac.nz</a>&gt;&gt; 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 &lt;<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a><br></div>
    &lt;mailto:<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a>&gt;&gt;:<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 &lt;<a href="mailto:g.bogle@auckland.ac.nz" target="_blank">g.bogle@auckland.ac.nz</a><br></div><div class="im">
        &lt;mailto:<a href="mailto:g.bogle@auckland.ac.nz" target="_blank">g.bogle@auckland.ac.nz</a>&gt;&gt; wrote:<br>
<br>
            Hi Seb,<br>
<br>
            Although I referred to a simplified case in which the squares don&#39;t<br>
            change,<br>
            in general I need to allow for their movement.  Therefore I don&#39;t<br>
            think it<br>
            will be possible for me to use a single actor.  If I&#39;m wrong, could you<br>
            please provide a bit more  detail?<br>
<br>
            Thanks<br>
            Gib<br>
<br>
            Quoting Sebastien Jourdain &lt;<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a><br></div>
            &lt;mailto:<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a>&gt;&gt;:<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>
                &lt;<a href="mailto:g.bogle@auckland.ac.nz" target="_blank">g.bogle@auckland.ac.nz</a> &lt;mailto:<a href="mailto:g.bogle@auckland.ac.nz" target="_blank">g.bogle@auckland.ac.nz</a>&gt;&gt;<div><div></div>

<div class="h5"><br>
                wrote:<br>
<br>
<br>
                    I asked about this before, but didn&#39;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&#39;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&lt;vtkPoints&gt; points =<br>
                    vtkSmartPointer&lt;vtkPoints&gt;::New();<br>
                    vtkSmartPointer&lt;vtkCellArray&gt; vertices =<br>
                    vtkSmartPointer&lt;vtkCellArray&gt;::New();<br>
                    points-&gt;InsertNextPoint(-0.5, 0.0, -0.5);<br>
                    points-&gt;InsertNextPoint( 0.5, 0.0, -0.5);<br>
                    points-&gt;InsertNextPoint( 0.5, 0.0,  0.5);<br>
                    points-&gt;InsertNextPoint(-0.5, 0.0,  0.5);<br>
<br>
                    vtkSmartPointer&lt;vtkPolygon&gt; polygon =<br>
                    vtkSmartPointer&lt;vtkPolygon&gt;::New();<br>
                    polygon-&gt;GetPointIds()-&gt;SetNumberOfIds(4); //make a quad<br>
                    polygon-&gt;GetPointIds()-&gt;SetId(0, 0);<br>
                    polygon-&gt;GetPointIds()-&gt;SetId(1, 1);<br>
                    polygon-&gt;GetPointIds()-&gt;SetId(2, 2);<br>
                    polygon-&gt;GetPointIds()-&gt;SetId(3, 3);<br>
<br>
                    //Add the polygon to a list of polygons<br>
                    vtkSmartPointer&lt;vtkCellArray&gt; polygons =<br>
                    vtkSmartPointer&lt;vtkCellArray&gt;::New();<br>
                    polygons-&gt;InsertNextCell(polygon);<br>
<br>
                    //Create a PolyData<br>
                    vtkSmartPointer&lt;vtkPolyData&gt; polygonPolyData =<br>
                    vtkSmartPointer&lt;vtkPolyData&gt;::New();<br>
                    polygonPolyData-&gt;SetPoints(points);<br>
                    polygonPolyData-&gt;SetPolys(polygons);<br>
<br>
                    //Create a mapper and actor<br>
                    tileMapper = vtkPolyDataMapper::New();<br>
                    tileMapper-&gt;SetInput(polygonPolyData);<br>
                    tileMapper-&gt;ScalarVisibilityOff();<br>
<br>
                    The square actors are made like this:<br>
<br>
                    actor = vtkActor::New();<br>
                    actor-&gt;SetMapper(tileMapper);<br>
                    actor-&gt;GetProperty()-&gt;SetColor(boneColor);<br>
                    actor-&gt;GetProperty()-&gt;SetAmbient(0.5);<br>
                    actor-&gt;GetProperty()-&gt;SetDiffuse(0.2);<br>
                    actor-&gt;GetProperty()-&gt;SetSpecular(0.5);<br>
                    actor-&gt;SetPosition(pos);<br>
                    ren-&gt;AddActor(actor);<br>
<br>
                    then not touched again (in the simulations I report times for.)<br>
<br>
                    I&#39;d be very grateful if someone could give me a clue as to<br>
                    what I&#39;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> &lt;<a href="http://www.kitware.com" target="_blank">http://www.kitware.com</a>&gt;<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> &lt;<a href="http://www.kitware.com" target="_blank">http://www.kitware.com</a>&gt;<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> &lt;<a href="http://www.kitware.com" target="_blank">http://www.kitware.com</a>&gt;<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>