[vtkusers] triangle - triangle intersection VTK C++
TJ Corona
tj.corona at kitware.com
Fri Jul 21 07:48:47 EDT 2017
I agree, this is rather confusing. The method vtkIntersectionPolyDataFilter::TriangleTriangleIntersection() sets the isCoplanar flag if the triangles are coplanar, and does not continue with the intersection calculation. In your first example, the triangles are coplanar, whereas in your second example they are not. This is deliberate, as the algorithm employed in vtkIntersectionPolyDataFilter keys off of this isCoplanar flag to traverse a different code path. I will post a MR today to update the documentation to reflect this.
The good news is that there is also a method called vtkTriangle::TrianglesIntersect(). It will not return where the intersection occurs, but should correctly identify both of your triangles as intersecting.
Would anybody be opposed to me changing the method name vtkIntersectionPolyDataFilter::TriangleTriangleIntersection() to better reflect the fact that it is not entirely general?
Thomas J. Corona, Ph.D.
Kitware, Inc.
Senior R&D Engineer
21 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-881-4443
> On Jul 21, 2017, at 6:44 AM, nolvis <fgr at lordsofts.com> wrote:
>
>
>
> I am bit confused how Triangle - triangle intersection works in VTK. When im
> using points commented as Shares an edge z = 0 it shows that intersection
> doesn't exist, but when im using points commented as Shares an edge z = 5 ,
> i am getting intersection. Why is that?
>
> //VTK includes
> #include <vtkSmartPointer.h>
> #include <vtkCellArray.h>
> #include <vtkTriangle.h>
> #include <vtkLine.h>
> //render
> #include <vtkActor.h>
> #include <vtkRenderer.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkProperty.h>
> //polydata
> #include <vtkPolyData.h>
> #include <vtkPolyDataMapper.h>
> #include <vtkIntersectionPolyDataFilter.h>
>
> //default includes
> #include <iostream>
> using namespace std;
>
> void displayPoly(vtkSmartPointer<vtkPolyData> &polyData);
>
> int main(int , char *[])
> {
> // Creates a polydata object
> vtkSmartPointer<vtkPolyData> polyData =
> vtkSmartPointer<vtkPolyData>::New();
>
> // creates a point object
> vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
> //Shares an edge z = 5
> points->InsertNextPoint ( 0.0, 0.0, 0.0 );
> points->InsertNextPoint ( 5.0, 0.0, 0.0 );
> points->InsertNextPoint ( 0.0, 5.0, 0.0 );
> points->InsertNextPoint ( 0.0, 5.0, 0.0 );
> points->InsertNextPoint ( 5.0, 0.0, 0.0 );
> points->InsertNextPoint ( 10.0, 10.0, 5.0 );
>
> //Shares an edge z = 0
> // points->InsertNextPoint ( 0.0, 0.0, 0.0 );
> // points->InsertNextPoint ( 5.0, 0.0, 0.0 );
> // points->InsertNextPoint ( 0.0, 5.0, 0.0 );
> // points->InsertNextPoint ( 0.0, 5.0, 0.0 );
> // points->InsertNextPoint ( 5.0, 0.0, 0.0 );
> // points->InsertNextPoint ( 10.0, 10.0, 0.0 );
>
> vtkSmartPointer<vtkCellArray> triangles =
> vtkSmartPointer<vtkCellArray>::New();
> for(int i = 0; i < 2; i++){
> vtkSmartPointer<vtkTriangle> triangle =
> vtkSmartPointer<vtkTriangle>::New();
> triangle->GetPointIds()->SetId ( 0, i*3 );
> triangle->GetPointIds()->SetId ( 1, i*3+1 );
> triangle->GetPointIds()->SetId ( 2, i*3 + 2 );
>
> //add the triangles to the list of triangles
> triangles->InsertNextCell ( triangle );
> }
>
> polyData->SetPoints ( points );
> polyData->SetPolys ( triangles );
> vtkSmartPointer<vtkCellArray> cells =
> vtkSmartPointer<vtkCellArray>::New();
> cells = polyData->GetPolys();
> cells->InitTraversal();
> vtkSmartPointer<vtkIdList> idList = vtkSmartPointer<vtkIdList>::New();
> vtkSmartPointer<vtkIntersectionPolyDataFilter> filter =
> vtkSmartPointer<vtkIntersectionPolyDataFilter>::New();
>
> while(cells->GetNextCell(idList))
> {
> vtkIdType i = cells->GetTraversalLocation();
> double a[3], b[3], c[3];
> polyData->GetPoint(idList->GetId(0), a);
> polyData->GetPoint(idList->GetId(1), b);
> polyData->GetPoint(idList->GetId(2), c);
>
> while(cells->GetNextCell(idList)){
> double e[3], f[3], g[3], pt1[3], pt2[3], surfaceid[2], tolerance;
> polyData->GetPoint(idList->GetId(0), e);
> polyData->GetPoint(idList->GetId(1), f);
> polyData->GetPoint(idList->GetId(2), g);
>
> int coplanar;
> int intersect = filter->TriangleTriangleIntersection(a, b, c, e, f, g,
> coplanar, pt1, pt2, surfaceid, tolerance);
> if(intersect == 1){
> cout << "triangle to compare with" << endl;
> cout << a[0] << " " << a[1] << " " << a[2] << endl;
> cout << b[0] << " " << b[1] << " " << b[2] << endl;
> cout << c[0] << " " << c[1] << " " << c[2] << endl;
>
> cout << "comperable triangle" << endl;
> cout << e[0] << " " << e[1] << " " << e[2] << endl;
> cout << f[0] << " " << f[1] << " " << f[2] << endl;
> cout << g[0] << " " << g[1] << " " << g[2] << endl;
> cout << "Intersection of triangles" << endl << endl;
> cout << "coplanar: " << coplanar << endl;
> cout << "pt1: " << pt1[0] << " " << pt1[1] << " " << pt1[2] << endl;
> cout << "pt2: " << pt2[0] << " " << pt2[1] << " " << pt2[2] << endl;
> cout << "surfid: " << surfaceid[0] << " " << surfaceid[1] << endl;
> cout << "tolerance: " << tolerance << endl;
> cout << "Intersect: " << intersect << endl;
> }
> }
> cells->SetTraversalLocation(i);
> }
> displayPoly(polyData);
> }
>
> void displayPoly(vtkSmartPointer<vtkPolyData> &polyData){
> //mapper
> vtkSmartPointer<vtkPolyDataMapper> mapper =
> vtkSmartPointer<vtkPolyDataMapper>::New();
> mapper->SetInputDataObject(polyData);
>
> //actor
> vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
> actor->SetMapper(mapper);
> actor->GetProperty()->SetRepresentationToWireframe();
>
> //render
> vtkSmartPointer<vtkRenderer> renderer =
> vtkSmartPointer<vtkRenderer>::New();
> vtkSmartPointer<vtkRenderWindow> renderWindow =
> vtkSmartPointer<vtkRenderWindow>::New();
> renderWindow->AddRenderer(renderer);
>
> //renderWindow
> vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
> vtkSmartPointer<vtkRenderWindowInteractor>::New();
> renderWindowInteractor->SetRenderWindow(renderWindow);
> renderer->AddActor(actor);
> renderWindow->Render();
> renderWindowInteractor->Start();
> }
>
>
>
>
>
> --
> View this message in context: http://vtk.1045678.n5.nabble.com/triangle-triangle-intersection-VTK-C-tp5744096.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20170721/40550030/attachment.html>
More information about the vtkusers
mailing list