Get normal vector of the closest polydata cell to a given test point

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Get normal vector of the closest polydata cell to a given test point

Tom08

Hello,

i have a test point p[x,y,z] and a polydata.
I use vtkCellLocator to get the closest cell of the polydata to this point.

I get:
- the closest point
- the squared distance to the closest point
- cell ID

Now I want to get the normal vector of the cell. I know the cell ID but I don't know how to get the
normal vector from it.

Thank you!


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Get normal vector of the closest polydata cell to a given test point

Tom08

Thank you very much!

The problem is that most of the points are on the surface. Therefore test point = closest point.
I only use the cellLocator to get the corresponding cell.

Now I try to get the normale vector of the whole cell (orientation of the cell).

Is there a way to get that vector?


Von: Girish Lande <[hidden email]>
Gesendet: Mittwoch, 11. Jänner 2017 12:43
An: M. Jordan
Betreff: Re: [vtkusers] Get normal vector of the closest polydata cell to a given test point
 
Hi Jordan,

You can use vector between your test point and closest point as NORMAL vector.
Please see code snippet below.
normalizedX is output 

double* pos = picker->GetPickPosition();

        double testPoint[3] = {pos[0],pos[1],pos[2]};

        //Find the closest points to TestPoint
        double closestPoint[3];//the coordinates of the closest point will be returned here
        double closestPointDist2; //the squared distance to the closest point will be returned here
        vtkIdType cellId; //the cell id of the cell containing the closest point will be returned here
        int subId; //this is rarely used (in triangle strips only, I believe)
        cellLocator->FindClosestPoint(testPoint, closestPoint, cellId, subId, closestPointDist2);

        std::cout << "Coordinates of closest point: " << closestPoint[0] << " " << closestPoint[1] << " " << closestPoint[2] << std::endl;
        std::cout << "Squared distance to closest point: " << closestPointDist2 << std::endl;
        std::cout << "CellId: " << cellId << std::endl;

        endPoint[0]=pos[0];
        endPoint[1]=pos[1];
        endPoint[2]=pos[2];
        startPoint[0]=closestPoint[0];
        startPoint[1]=closestPoint[1];
        startPoint[2]=closestPoint[2];

// Compute a basis
         double normalizedX[3];
         double normalizedY[3];
         double normalizedZ[3];

         // The X axis is a vector from start to end
         vtkMath::Subtract(endPoint, startPoint, normalizedX);
         double length = vtkMath::Norm(normalizedX);
         length=1;
         vtkMath::Normalize(normalizedX);

On 11 January 2017 at 16:32, M. Jordan <[hidden email]> wrote:

Hello,

i have a test point p[x,y,z] and a polydata.
I use vtkCellLocator to get the closest cell of the polydata to this point.

I get:
- the closest point
- the squared distance to the closest point
- cell ID

Now I want to get the normal vector of the cell. I know the cell ID but I don't know how to get the
normal vector from it.

Thank you!


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers




--
thanks & regards,
Girish


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Get normal vector of the closest polydata cell to a given test point

David Doria-2-3
In reply to this post by Tom08

Hello,

i have a test point p[x,y,z] and a polydata.
I use vtkCellLocator to get the closest cell of the polydata to this point.

I get:
- the closest point
- the squared distance to the closest point
- cell ID

Now I want to get the normal vector of the cell. I know the cell ID but I don't know how to get the
normal vector from it.

Thank you!


This example shows how to retrieve cell normals:


David 

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers