[vtkusers] triangle - triangle intersection VTK C++
nolvis
fgr at lordsofts.com
Fri Jul 21 06:44:20 EDT 2017
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.
More information about the vtkusers
mailing list