<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 04/05/10 17:40, Henrik Westerberg wrote:<br>
<br>
Hi,<br>
<br>
thanks for the answers. I achieved successful picking with
vtkPointPicker doing the following:<br>
<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double *vector = new double[3];<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; double *pos = new double[3];<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //vectors<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; vector =
glyph-&gt;GetOutput()-&gt;GetPointData()-&gt;GetVectors()-&gt;GetTuple(picker-&gt;GetPointId());<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //points<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; pos =
glyph-&gt;GetOutput()-&gt;GetPoint(picker-&gt;GetPointId());<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //pos&nbsp; =
glyph-&gt;GetOutput()-&gt;GetPoints()-&gt;GetPoint(picker-&gt;GetPointId());//This
gives the same result<br>
<br>
However, this picks any point in the polydata, which is not what I
want. I will explain through an example:<br>
&nbsp;&nbsp;&nbsp; Lets say I have two vectors. They are displayed through the
pipeline vtkPolyData-&gt;vtkGlyph3D-&gt;vtkPolyDataMapper-&gt;vtkActor,
where my polydata contains two points and two vector tuples. The picker
selects any point, i.e. any vertex of the vectors, so I can pick like
10 different points for each vector. What I want is to pick each vector
itself, i.e. If I click anywhere in the vector, to get the position
where the vector is placed, this is, the position of one point of the
original polydata. Would this be possible?<br>
<br>
Thanks for your help,<br>
<br>
Alberto<br>
<br>
<blockquote
 cite="mid:3CBF6C8EE0D24348BBD0F8E1AD998D186CA9BB157F@KLUG.crg.es"
 type="cite">
  <pre wrap="">Hi,

Be sure to have GeneratePointIdsOn() as this make like a lot easier on your vtkGlyph3D (which you do, just writing it for the general situation)

glyphs = vtkGlyph3D()
glyphs.GeneratePointIdsOn()


In my case I have a scalar associated with each point.

Then you should be able to do something like the following:

picker = vtkPointPicker()
def handlePick(object, event):
     pid = picker.GetPointId()
     inputIds = glyphs.GetOutput().GetPointData().GetArray("InputPointIds")
     app = int(inputIds.GetTuple1(pid))
     
     if (app &lt; tf_scale.GetOutput().GetPoints().GetNumberOfPoints()):
          print tf_scale.GetOutput().GetPoints().GetPoint(app)
          print scalars.GetValue(app)

where iren is a vtkRenderWindowInteractor

iren.SetPicker(picker)

And you can pick with 'p' key without having to write your own observer.

bye,
Henrik


________________________________________
From: <a class="moz-txt-link-abbreviated" href="mailto:vtkusers-bounces@vtk.org">vtkusers-bounces@vtk.org</a> [<a class="moz-txt-link-abbreviated" href="mailto:vtkusers-bounces@vtk.org">vtkusers-bounces@vtk.org</a>] On Behalf Of Allan James [<a class="moz-txt-link-abbreviated" href="mailto:ar.james@qut.edu.au">ar.james@qut.edu.au</a>]
Sent: 04 May 2010 04:34
To: Gomez, Alberto
Cc: <a class="moz-txt-link-abbreviated" href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a>
Subject: Re: [vtkusers] vtkPointPicker / vtkGlyph3D problem

Hi Alberto,

I could not fix the problem with point picker not producing correct results. After much banging of head against wall I tried cellpicker instead which is now working correctly. I would love to know what I was doing wrong with point picker!

Below is some code snippets for using cellpicker to select a glyph generated using vtkGlyph3D. This code has been hacked a bit from a larger project so it's a bit messy and I havent tested it as is. However it should work by left-clicking on a glyph.

If anyone has suggestions on making this code better, please let me know.


////////////////////////////////////////////////////////
// Make sure GeneratePointIdsOn() called on vtkGlyph3D
// This generates an array on the output dataset called
// "InputPointIds" which generates pointIDs in the glyphs
// that match the original input pointIDs.
////////////////////////////////////////////////////////
_glyphs-&gt;GeneratePointIdsOn();

///////////////////////////////////////////
// Setup pick callback (ScenePickCallback)
///////////////////////////////////////////
_scenePickCallback = ScenePickCallback::New();
_scenePickCallback-&gt;actorToPick = _glyphActor;
_scenePickCallback-&gt;glyphsToPick = _glyphs;
_scenePickCallback-&gt;sceneRenderWindowInteractor = _sceneRenderWindowInteractor;
_sceneRenderWindowInteractor-&gt;GetInteractorStyle()-&gt;AddObserver(vtkCommand::LeftButtonReleaseEvent, _scenePickCallback);


class ScenePickCallback : public vtkCommand
{
public:
        static ScenePickCallback *New();
        virtual void Execute(vtkObject *caller, unsigned long eventId, void* data);

        vtkSmartPointer&lt;vtkActor&gt; actorToPick;
        vtkSmartPointer&lt;vtkGlyph3D&gt; glyphsToPick;
        vtkSmartPointer&lt;vtkRenderWindowInteractor&gt; sceneRenderWindowInteractor;

private:
        ScenePickCallback();
};

void ScenePickCallback::Execute(vtkObject *caller, unsigned long eventId, void* data)
{
        if(eventId == vtkCommand::LeftButtonReleaseEvent)
        {
                int pickPosition[2];
                sceneRenderWindowInteractor-&gt;GetEventPosition(pickPosition);

                sceneRenderWindowInteractor-&gt;GetPicker()-&gt;Pick(pickPosition[0], pickPosition[1], 0, sceneRenderer);

                vtkCellPicker *cellPicker = reinterpret_cast&lt;vtkCellPicker*&gt;(picker.GetPointer());
                if(cellPicker)
                {
                        // Check if correct actor was picked
                        if(cellPicker-&gt;GetActor() == actorToPick.GetPointer())
                        {
                                vtkDataArray *inputIds = glyphsToPick-&gt;GetOutput()-&gt;GetPointData()-&gt;GetArray("InputPointIds");

                                if(inputIds)
                                {
                                        vtkCell *cell = glyphsToPick-&gt;GetOutput()-&gt;GetCell(cellPicker-&gt;GetCellId());

                                        if(cell &amp;&amp; cell-&gt;GetNumberOfPoints() &gt; 0)
                                        {
                                                // get first PointId from picked cell
                                                vtkIdType inputId = cell-&gt;GetPointId(0);

                                                // get matching Id from "InputPointIds" array
                                                vtkIdType selectedPointId = inputIds-&gt;GetTuple1(inputId);

                                                if(selectedPointId &gt;= 0)
                                                {
                                                        // POINT PICKED!
                                                        // selectedPointId = Picked PointID (original input points)
                                                }
                                        }
                                }

                        }
                        else
                        {
                                // NONE PICKED
                        }
                }
        }
}



Allan James
High Performance Computing &amp; Research Support
Queensland University of Technology
(07) 3138 9264
<a class="moz-txt-link-abbreviated" href="mailto:ar.james@qut.edu.au">ar.james@qut.edu.au</a>
<a class="moz-txt-link-freetext" href="http://www.qut.edu.au/its/hpc">http://www.qut.edu.au/its/hpc</a>

  </pre>
  <blockquote type="cite">
    <pre wrap="">&lt;(((&ordm;&gt;  ._.&middot;&acute;&macr;`&middot;..  &gt;++(((&ordm;&gt;  ._.&middot;&acute;&macr;`&middot;..  &gt;++(((&ordm;&gt;
    </pre>
  </blockquote>
  <pre wrap="">

  </pre>
  <blockquote type="cite">
    <pre wrap="">-----Original Message-----
From: Gomez, Alberto [<a class="moz-txt-link-freetext" href="mailto:alberto.gomez@kcl.ac.uk">mailto:alberto.gomez@kcl.ac.uk</a>]
Sent: Friday, 30 April 2010 8:53 PM
To: Allan James
Cc: <a class="moz-txt-link-abbreviated" href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a>
Subject: Re: [vtkusers] vtkPointPicker / vtkGlyph3D problem

Hi all,

I am trying to select a vector from a vector field with the
mouse. The
vector field is a glyph of vectors and it is generated in the
following
way (1). Then I use a custom interaction (subclassing
vtkInteractionStyleTrackballCamera) so that I pick points
when I press
the mouse button (2). When I click the left button, a
callback (3) does
some processing. The problem is that the position I get does
not match
the real vector position (i.e. I plot a vector at the 3D point I get
with the picker through the method picker-&gt;GetPickPosition()
and it does
not match). Anyone has a clue on why? I have played around with the
tolerance with no success.

Another question, how can I get the point information (vector and
position) from the point id??

Thanks,

Alberto


(1) Vector field generation :

//positions
    vtkSmartPointer&lt;vtkPoints&gt; pts =
vtkSmartPointer&lt;vtkPoints&gt;::New();
    pts-&gt;SetNumberOfPoints(num_pts);
//directions
    vtkSmartPointer&lt;vtkDoubleArray&gt; vecArr =
vtkSmartPointer&lt;vtkDoubleArray&gt;::New();
    vecArr-&gt;SetNumberOfComponents(3);
    vecArr-&gt;SetNumberOfTuples(num_pts);
    for (int i = 0; i &lt; num_pts; i++) {
            pts-&gt;InsertNextPoint(positions[i][0], positions[i][1],
positions[i][2]);
            float tuple[3] = {(float) directions[i][0] , (float)
directions[i][1], (float) directions[i][2]};
            vecArr-&gt;InsertNextTuple(tuple);
      }

// put vectors and positions into a grid which will be the
glyph's input
    vtkSmartPointer&lt;vtkUnstructuredGrid&gt; uGrid = vtkSmartPointer&lt;
vtkUnstructuredGrid&gt;::New();
    uGrid-&gt;SetPoints(pts);
    uGrid-&gt;GetPointData()-&gt;SetVectors(vecArr);

 // glyph construction
    vtkSmartPointer&lt;vtkArrowSource&gt; arrow =
vtkSmartPointer&lt;vtkArrowSource&gt;::New();
    vtkSmartPointer&lt;vtkGlyph3D&gt; glyph =
vtkSmartPointer&lt;vtkGlyph3D&gt;::New();
    glyph-&gt;SetInput(uGrid);
    glyph-&gt;SetSource(arrow-&gt;GetOutput());
    glyph-&gt;SetScaleModeToScaleByVector();
    glyph-&gt;GeneratePointIdsOn();
//Mapper and actor
    vtkSmartPointer&lt;vtkPolyDataMapper&gt; gMapper =
vtkSmartPointer&lt;vtkPolyDataMapper&gt;::New();
    gMapper-&gt;SetInput(glyph-&gt;GetOutput());
    gMapper-&gt;ScalarVisibilityOff();
    gMapper-&gt;SetScalarRange(uGrid-&gt;GetScalarRange());

vtkSmartPointer&lt;vtkActor&gt; gactor = vtkSmartPointer&lt;vtkActor&gt;::New();
    gactor-&gt;SetMapper(gMapper);
    gactor-&gt;GetProperty()-&gt;SetColor(color);
    ren-&gt;AddActor(gactor);

(2) Detail of my subclass for custom interactor style:
virtual void OnLeftButtonDown()
    {
         if (this-&gt;Interactor-&gt;GetControlKey() ){
                 int* pos = this-&gt;GetInteractor()-&gt;GetEventPosition();
                pointPicker-&gt;Pick(pos[0], pos[1], 0,
this-&gt;GetDefaultRenderer());
        } else{

            vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
        }
    }

(3)  Callback class (detail)

// Callback thats get called for a picking event.
class PickCallback : public vtkCommand
{
  public:
    static PickCallback* New()
    {
     return new PickCallback();
    }

    void Execute(vtkObject* caller, unsigned long eventId,
void* callData)
    {
      vtkPointPicker *picker = static_cast&lt; vtkPointPicker* &gt;(caller);
      if(picker-&gt;GetPointId() &lt; 1)
      {
      // Nothing is picked.
      }
      else
      {
        double* pos = picker-&gt;GetPickPosition();
     std::cout &lt;&lt; pos[0]&lt;&lt; ","&lt;&lt; pos[1]&lt;&lt; ","&lt;&lt; pos[2]&lt;&lt; std::endl;

        actor = generateVectorActor(picker);


        ren-&gt;AddViewProp(actor);


      }



    }

Allan James wrote:
    </pre>
    <blockquote type="cite">
      <pre wrap="">Hi all,

I have an issue with code that is using vtkPointPicker to
      </pre>
    </blockquote>
    <pre wrap="">pick points displayed using vtkGlyph3D.
    </pre>
    <blockquote type="cite">
      <pre wrap="">
Now I have the picking working great for most of the glyphs
      </pre>
    </blockquote>
    <pre wrap="">- using vtkGlyph3D-&gt;GeneratePointIdsOn(); and I am able to
select glyphs and display a sphere at the selected glyph location.
    </pre>
    <blockquote type="cite">
      <pre wrap="">
My problem is that while this works perfectly 99% of the
      </pre>
    </blockquote>
    <pre wrap="">time - there are certain glyphs that are either very
difficult to pick (sometimes impossible it seems) or I have
to click about 20 pixels or so above or next to the glyph for
the pick to work. Has anyone seen this issue and/or can suggest a fix?
    </pre>
    <blockquote type="cite">
      <pre wrap="">
Why would picking work perfectly for most glyphs but not
      </pre>
    </blockquote>
    <pre wrap="">for some others - when all of the glyphs are generated from
the same simple pointset using the same vtkGlyph3D filter?
    </pre>
    <blockquote type="cite">
      <pre wrap="">
Any help would be muchly appreciated - thanks

Allan James
High Performance Computing &amp; Research Support
Queensland University of Technology
(07) 3138 9264
<a class="moz-txt-link-abbreviated" href="mailto:ar.james@qut.edu.au">ar.james@qut.edu.au</a><a class="moz-txt-link-rfc2396E" href="mailto:ar.james@qut.edu.au">&lt;mailto:ar.james@qut.edu.au&gt;</a>
<a class="moz-txt-link-freetext" href="http://www.qut.edu.au/its/hpc">http://www.qut.edu.au/its/hpc</a>


      </pre>
      <blockquote type="cite">
        <pre wrap="">&lt;(((&ordm;&gt;  ._.&middot;&acute;&macr;`&middot;..  &gt;++(((&ordm;&gt;  ._.&middot;&acute;&macr;`&middot;..  &gt;++(((&ordm;&gt;

        </pre>
      </blockquote>
      <pre wrap="">


      </pre>
    </blockquote>
    <pre wrap="">

--

Alberto G&oacute;mez

/Division of Imaging Sciences
The Rayne Institute
4th Floor, Lambeth Wing
St Thomas' Hospital
London SE1 7EH /

phone: +44 (0) 20 718 88364
email: <a class="moz-txt-link-abbreviated" href="mailto:alberto.gomez@kcl.ac.uk">alberto.gomez@kcl.ac.uk</a> <a class="moz-txt-link-rfc2396E" href="mailto:alberto.gomez@kcl.ac.uk">&lt;mailto:alberto.gomez@kcl.ac.uk&gt;</a>


    </pre>
  </blockquote>
  <pre wrap="">_______________________________________________
Powered by <a class="moz-txt-link-abbreviated" href="http://www.kitware.com">www.kitware.com</a>

Visit other Kitware open-source projects at <a class="moz-txt-link-freetext" href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a>

Please keep messages on-topic and check the VTK FAQ at: <a class="moz-txt-link-freetext" href="http://www.vtk.org/Wiki/VTK_FAQ">http://www.vtk.org/Wiki/VTK_FAQ</a>

Follow this link to subscribe/unsubscribe:
<a class="moz-txt-link-freetext" href="http://www.vtk.org/mailman/listinfo/vtkusers">http://www.vtk.org/mailman/listinfo/vtkusers</a>
  </pre>
</blockquote>
<br>
<br>
<div class="moz-signature">-- <br>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<p>Alberto G&oacute;mez</p>
<p>
<i>Division of Imaging Sciences <br>
The Rayne Institute<br>
4th Floor, Lambeth Wing<br>
St Thomas' Hospital<br>
London SE1 7EH
</i></p>
<p>phone: +44 (0) 20 718 88364<br>
email: <a href="mailto:alberto.gomez@kcl.ac.uk">alberto.gomez@kcl.ac.uk</a>
</p>
</div>
</body>
</html>