<div dir="ltr">Hi,<div><br></div><div>I am trying to generate triangles from sets of points. I am using vtkDelaunay2D for this. For some pointsets, vtkDelaunay2D is not generating any triangles. Following is the code I am using. I am basically creating a vtkPolyData using the points, and then applying vtkDelaunay2D on that polydata. Lastly, I am visualizing the output.</div>
<div><br></div><div><br></div><div><br></div><div><br></div><div> #include <stdio.h></div><div> #include <iostream></div><div> #include <fstream></div><div><br></div><div> #include <vtkSmartPointer.h></div>
<div> #include <vtkIdList.h></div><div> #include <vtkCellArray.h></div><div> #include <vtkPoints.h></div><div> #include <vtkPolyData.h></div><div> #include <vtkActor.h></div>
<div> #include <vtkPolyDataMapper.h></div><div> #include <vtkRenderer.h></div><div> #include <vtkRenderWindow.h></div><div> #include <vtkRenderWindowInteractor.h></div><div>
#include <vtkDelaunay2D.h></div><div> #include <vtkPolyDataWriter.h></div><div><br></div><div> using namespace std;</div><div><br></div><div> int main() {</div><div><div> int pointIndex[] = {0, 1, 2, 3};</div>
<div> </div><div> // Points</div><div> double **pts = new double*[3];</div><div> pts[0] = new double[3] {8.53125, 7.53125, 1.53125};</div><div> pts[1] = new double[3] {8.53125, 7.53125, 2.53125};</div>
<div> pts[2] = new double[3] {8.26562, 8.26562, 2.53125};</div><div> pts[3] = new double[3] {8.26562, 8.26562, 1.53125};</div><div><br></div><div> vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();</div>
<div> vtkSmartPointer<vtkIdList> pointList = vtkSmartPointer<vtkIdList>::New();</div><div><br></div><div> for (int i = 0; i < 4; i++) {</div><div> points->InsertPoint(i, pts[i][0], pts[i][1], pts[i][2]);</div>
<div> pointList->InsertNextId(i);</div><div> }</div><div><br></div><div> vtkSmartPointer<vtkCellArray> vertexArray = vtkSmartPointer<vtkCellArray>::New();</div><div> vertexArray->InsertNextCell(pointList);</div>
<div><br></div><div> vtkSmartPointer<vtkPolyData> pdata = vtkSmartPointer<vtkPolyData>::New();</div><div> pdata->SetPoints(points);</div><div> pdata->SetVerts(vertexArray);</div>
<div><br></div><div> vtkSmartPointer<vtkDelaunay2D> del = vtkSmartPointer<vtkDelaunay2D>::New();</div><div> del->SetProjectionPlaneMode(VTK_BEST_FITTING_PLANE);</div><div> del->SetInput(pdata);</div>
<div> del->Update();</div><div><br></div><div> vtkSmartPointer<vtkPolyData> output = del->GetOutput();</div><div> cout << "Number of cells: " << output->GetNumberOfCells() << endl;</div>
<div> cout << "Number of points: " << output->GetNumberOfPoints() << endl;</div><div><br></div><div> vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();</div>
<div> mapper->SetInput(output);</div><div><br></div><div> vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();</div><div> actor->SetMapper(mapper);</div><div>
<br></div><div> vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New();</div><div> vtkSmartPointer<vtkRenderWindow> renwin = vtkSmartPointer<vtkRenderWindow>::New();</div>
<div> vtkSmartPointer<vtkRenderWindowInteractor> iren = vtkSmartPointer<vtkRenderWindowInteractor>::New();</div><div><br></div><div> renwin->AddRenderer(ren); </div><div> iren->SetRenderWindow(renwin);</div>
<div> ren->AddActor(actor);</div><div><br></div><div> renwin->Render();</div><div> iren->Start();</div></div><div> </div><div> return 0;</div><div> }</div>
<div><br></div><div><br></div><div><br></div><div>For the 4 points in the code, I am not getting any triangulations. Can someone tell me why? I was wondering if this is because of some kind of limitation with vtkDelaunay2D or perhaps because my code is incorrect. Any help is appreciated. </div>
<div><div><br></div>-- <br>Tanweer Rashid<br>MSVE Dept.<br><div>Old Dominion University</div>
</div></div>