The same input polydata that controls the positions of the glyphs can also control the color, size, and orientation of each glyph.  This is done by calling input-&gt;GetPointData()-&gt;AddArray(...) to add scalar arrays that control the parameters.  Look at the documentation for vtkGlyph3D for more info.<br>

<br>  David<br><br><div class="gmail_quote">On Wed, Nov 24, 2010 at 5:37 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: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

There is just one limitation (as far as I can see).  One can&#39;t specify the glyph colours individually.  My spheres change colour as the state evolves.  I&#39;d like to be able to control the square colours individually too, but that&#39;s less important.<br>


<br>
Cheers<br>
Gib<div class="im"><br>
<br>
On 25/11/2010 12:55 p.m., David Gobbi wrote:<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hi Gib,<br>
<br><div class="im">
Glad to hear the good news.  I&#39;m sure that you&#39;ve also figured out that you can<br>
use glyphs for your spheres.<br>
<br>
Changing the number of glyphs is possible, but a bit tricky.  You have to<br>
re-initialize the input polydata when changing the number of points or cells.<br>
  So going back to my example code, you would do something like this:<br>
<br>
input-&gt;Initialize();<br>
input-&gt;SetPoints(new_points);<br>
input-&gt;SetVerts(new_verts);<br>
<br>
Generally you will have to re-build the points and the verts arrays from scratch<br>
if you want to remove elements.   You can call Initialize() on the arrays to<br>
clear them before rebuilding them.  The VTK arrays don&#39;t have an erase() method<br>
like C++ vectors do.<br>
<br>
   David<br>
<br>
<br>
On Wed, Nov 24, 2010 at 4:34 PM, Gib Bogle &lt;<a href="mailto:g.bogle@auckland.ac.nz" target="_blank">g.bogle@auckland.ac.nz</a><br></div><div><div></div><div class="h5">
&lt;mailto:<a href="mailto:g.bogle@auckland.ac.nz" target="_blank">g.bogle@auckland.ac.nz</a>&gt;&gt; wrote:<br>
<br>
    Great success!!  The glyphs render so fast that the extra time is<br>
    negligible. Thanks again.  It isn&#39;t needed for this application, but for<br>
    future reference: is it possible to change the glypher input on the fly,<br>
    i.e. the number of cells?<br>
<br>
    Hi Fred, are you still interested in seeing the code that runs slowly?<br>
<br>
<br>
    Gib<br>
<br>
    On 25/11/2010 9:20 a.m., David Gobbi wrote:<br>
<br>
        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<br>
        (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<br>
        just<br>
        like you did with the squares, except that you want to use &quot;verts&quot; as<br>
        your cells:<br>
<br>
        vtkSmartPointer&lt;vtkPoints&gt; positions = vtkSmartPointer&lt;vtkPoints&gt;::New();<br>
        vtkSmartPointer&lt;vtkCellArray&gt; dummycells =<br>
        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<br>
        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>
        &lt;mailto:<a href="mailto:g.bogle@auckland.ac.nz" target="_blank">g.bogle@auckland.ac.nz</a>&gt;<br></div></div><div><div></div><div class="h5">
        &lt;mailto:<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;&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<br>
        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>
        &lt;mailto:<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a>&gt;<br>
        &lt;mailto:<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a><br>
        &lt;mailto:<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a>&gt;&gt;&gt;:<br>
<br>
<br>
                You can use a single actor, you will need to have a programable<br>
        source<br>
                that update the output dataset that has the location of each<br>
        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<br>
        that...<br>
<br>
                customSource.SetSquarePosition( suquareId, xyz )<br>
<br>
                Seb<br>
<br>
                PS: I think I wrote a sample code in Java for programmable<br>
        source on the<br>
                wiki...<br>
<br>
<br>
                On Wed, Nov 24, 2010 at 1:41 PM, Gib  Bogle<br>
        &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;<br></div></div><div class="im">


        &lt;mailto:<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;&gt; wrote:<br>
<br>
                    Hi Seb,<br>
<br>
                    Although I referred to a simplified case in which the<br>
        squares don&#39;t<br>
                    change,<br>
                    in general I need to allow for their movement.  Therefore I<br>
        don&#39;t<br>
                    think it<br>
                    will be possible for me to use a single actor.  If I&#39;m<br>
        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>
        &lt;mailto:<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a>&gt;<br></div><div class="im">
        &lt;mailto:<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a><br></div><div class="im">
        &lt;mailto:<a href="mailto:sebastien.jourdain@kitware.com" target="_blank">sebastien.jourdain@kitware.com</a>&gt;&gt;&gt;:<br>
<br>
<br>
                        Hi Gib,<br>
<br>
                        My first question will be. Are you using one actor for<br>
        each of your<br>
                        10000 flat squares ?<br>
                        If so, the performance limitation may come from the<br>
        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<br>
        so, you can<br>
                        build it by hand or simply use the Glyph filter with<br>
        your square<br>
                        as a<br>
                        glyph and another dataset that has the location of those<br>
        squares.<br>
<br>
                        Seb<br>
<br>
<br>
                        On Wed, Nov 24, 2010 at 12:44 AM, Gib Bogle<br>
        &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;<br></div>
        &lt;mailto:<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;&gt;<div><div></div>

<div class="h5"><br>
<br>
                        wrote:<br>
<br>
<br>
                            I asked about this before, but didn&#39;t attract any<br>
        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<br>
        executes, I am<br>
                            rendering a<br>
                            scene that contains mainly about 1000 small spheres<br>
        (which<br>
                            move) and<br>
                            about<br>
                            10000 flat squares (which do not move).  I have<br>
        discovered<br>
                            that the<br>
                            surprising slowness of the the rendering is caused<br>
        by the<br>
                            squares, even<br>
                            though the spheres have ThetaResolution and<br>
        PhiResolution<br>
                            both equal to<br>
                            12,<br>
                            which I guess means 144 faces per sphere, i.e. a<br>
        total of<br>
                            144,000 faces.<br>
                              By<br>
                            my calculations rendering the scene 288 times with<br>
        spheres<br>
                            alone takes<br>
                            about<br>
                            4 sec, with the squares alone takes about 20 sec,<br>
        and with<br>
                            both spheres<br>
                            and<br>
                            squares about 24 sec.  That is, 10,000 squares take<br>
        5 times<br>
                            as long as<br>
                            1000<br>
                            spheres with 144,000 faces.<br>
<br>
                            Apparently there&#39;s something very inefficient about<br>
        the way I am<br>
                            rendering<br>
                            the squares.  Here is the code for tileMapper (which<br>
        makes<br>
                            squares):<br>
<br>
                            // Create the square<br>
                            // Setup points to draw a unit square in the XY<br>
        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<br>
        times for.)<br>
<br>
                            I&#39;d be very grateful if someone could give me a clue<br>
        as to<br>
                            what I&#39;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> &lt;<a href="http://www.kitware.com" target="_blank">http://www.kitware.com</a>&gt;<br>
        &lt;<a href="http://www.kitware.com" target="_blank">http://www.kitware.com</a>&gt;<br>
<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>
                    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;<br>
        &lt;<a href="http://www.kitware.com" target="_blank">http://www.kitware.com</a>&gt;<br>
<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>
            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;<br></div></div><div class="im">
        &lt;<a href="http://www.kitware.com" target="_blank">http://www.kitware.com</a>&gt;<br>
<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>
    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;<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>