[vtkusers] Questions for picking.

安 继业 an_jiye at hotmail.com
Tue Feb 17 07:00:12 EST 2004


Hi.

I have done some picking work. It didn't seem to be what I had thought of.

In my test application, I create a vtkImageData object to simulate the 
source. It contains 64*64*93 points, the scalar type is unsigned char. I 
manually assign each slices the "same" value, where there are two rectangle 
areas with B inside A. Rectangle A locates at (5,1) to (49, 49), while 
rectangle B at (20, 20) to (39, 39). I assign value 0 to all the pixels 
outside A, value 2 inside B, and value 1 between A and B.

At next step, I use vtkContourFilter::SetValue(0, 1) and 
vtkContourFilter::SetValue(0, 2) to render this data set. My pipeline is 
vtkImageData->vtkContourFilter->vtkPolyDataNormals->vtkStripper->vtkPolyDataMapper->vtkActor. 
There are totally two pipelines. As a result, there are two cuboid surfaces 
in the rendering window, with B inside A. The four lower vertices of A is 
(5, 1, 0), (49, 1, 0), (49, 49, 0), (5, 49, 0), you will get the 
coordinates of the upper four vertices when replace z axis 0 with 92. 
Similarly, the lower four vertices of B is (20, 20, 0), (39, 20, 0), (39, 
39, 0) and (39, 20, 0). Getting the upper four vertices is the same as A.

The class for my observer is as below:

class vtkMyCallback : public vtkCommand
{
public:
    vtkMyCallback::vtkMyCallback() { };
    static vtkMyCallback *New() { return new vtkMyCallback; }

    virtual void Execute(vtkObject *caller, unsigned long, void*)
    {
        vtkRenderWindowInteractor *iren = 
reinterpret_cast<vtkRenderWindowInteractor*>(caller);
        vtkPointPicker *picker = (vtkPointPicker *)iren->GetPicker();

        if (picker->GetPointId() != -1){
            vtkPoints *points = picker->GetPickedPositions();
            int n = points->GetNumberOfPoints();

            cout<< n << " points are picked: \n";
            for(int i = 0; i < n; ++ i){
                double pos[3];
                points->GetPoint(i, pos);
                cout<<"\tPoisition: ("<<pos[0]<<", "<<pos[1]<<", "<<pos[2] 
<< ")"<< endl;
            }
        }
    }
};

I add my observer like this:

... ...
vtkPointPicker *picker = vtkPointPicker::New();
iren->SetPicker(picker);

vtkMyCallback *callback = vtkMyCallback::New();
iren->AddObserver(vtkCommand::EndPickEvent, callback);
... ...

I also create a carema to make the actor locates at a traditional 
coordinate system, with the origin at lower left, x axies from left to 
right, y axis points inside and z axis from down to up.

...
camera->SetViewUp (0, 0, 1);
camera->SetPosition (0, 0, 0);
camera->SetFocalPoint (0, 1, 0);
...

During the visualization procedure, I use the default vtk interactor style. 
That is, use keypress "p" for points picking.

To my surprise, I got the following results and some question occur: 

1. Why I got negative coordinates sometimes? like (1.34204, -0.79771, 
-5.08054). If the picking poinst is "on" the A surface, the minimum y axis 
should be 1, and the minimum z axis should be zero. I didn't get a negative 
x axis, but I think maybe it is possible to do so. Why? Can I only pick the 
points right ON the surface?

2. When I picking points by key press "p" while mouse cursor moves on the A 
surface (5, 1, 0), (49, 1, 0), (49, 1, 92) and (5, 1, 92), the following 
results occur:

1 points are picked:
    Poisition: (8.24702, 0.980525, 2.79693) <--------- I can understand.

1 points are picked:
    Poisition: (6.62972, 49.0116, 5.25943) <--------- Why the y axis is 49?

2 points are picked:
    Poisition: (15.9431, 48.9816, 14.8662) <--------- It is on the back 
surface of A?
    Poisition: (17.191, 19.5678, 18.3799)  <--------- It is on the front 
surface of B?

    Why these two points are picked? Where is the front surface of A?

2 points are picked:
    Poisition: (20.592, 0.938955, 3.75471) <--------- I can understand.
    Poisition: (20.0176, 19.9942, -0.032108) <--------- It is on the front 
surface of B?

    The z axis is negative.

1 points are picked:
    Poisition: (5.16348, 24.0098, 37.8442) <--------- Why the y axis is 24?

2 points are picked:
    Poisition: (36.259, 1.00855, 15.1336) <--------- I can understand.
    Poisition: (37.9111, 38.9501, 9.62979) <--------- It is on the back 
surface of B?

2 points are picked:
    Poisition: (24.0894, 49.0852, 2.34159) <--------- It is on the back 
surface of A?
    Poisition: (24.2017, 39.0064, 4.02494) <--------- It is on the back 
surface of B?

I never do some rotate to the carema by hold down the left mouse button 
when achieveing the above results. If do some, some other "strange" results 
will occur.

In conclusion, I can not understant how does vtkPointPicker pick points 
from the two surfaces. It seems I can get points from each of the four 
parallel surfaces from A and B. But acturally, I can only see the front 
surface of A.

Another question, why the point coordinates are not so accurate? I mean the 
y axis should be only one of the values 1, 20, 39 and 49, at least it 
should be much similar to these values. It seems there are some little 
errors in most of the time. The errors can range from 0.00x to 1. And also 
there is one 24 value.

I am using vtk4.4.0 under MS Visual C++ 6.0, windows 2000 professional 
edition.

Any suggestion will be appreciated. Thank you in advance.

Best Regards,
Jiye An

_________________________________________________________________
免费下载 MSN Explorer:   http://explorer.msn.com/lccn/  




More information about the vtkusers mailing list