# [vtkusers] How to set the boundary of vtkDelaunay2D ?

zhq 15891495523 at 126.com
Sat Sep 26 10:25:32 EDT 2015

Dear all:

I want to triangulate some points with a boundary. And I find a
example:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Filtering/ConstrainedDelaunay2D

In fact, when I want to test the method in circle (input the data at
30~42 in the code), I actually get:
<http://vtk.1045678.n5.nabble.com/file/n5734142/1.png>

And I want to remove those line inside the inner circle. And when I set
the inner circle points as the boundary ( line 55~58 in the code ), I can't
get what I want.

Could somebody give me some tips ? Thank you very much in advance !

My code is :

#include <vtkVersion.h>
#include <vtkCellArray.h>
#include <vtkProperty.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPolygon.h>
#include <vtkSmartPointer.h>
#include <vtkDelaunay2D.h>
#include <vtkMath.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#define PI 3.1415926
int main(int, char *[])
{
// Generate a 10 x 10 grid of points
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
/*for(unsigned int x = 0; x < 10; x++)
{
for(unsigned int y = 0; y < 10; y++)
{
points->InsertNextPoint(x + vtkMath::Random(-.25, .25),
y + vtkMath::Random(-.25,.25),
0);
}
}*/
for (int theta = 0;theta<360;theta+=10)
{
double x = 2*cos(theta*PI/180);
double y = 2*sin(theta*PI/180);
points->InsertNextPoint(x,y,0);
}

for (int theta = 0;theta<360;theta+=10)
{
double x = cos(theta*PI/180);
double y = sin(theta*PI/180);
points->InsertNextPoint(x,y,0);
}
vtkSmartPointer<vtkPolyData> aPolyData =
vtkSmartPointer<vtkPolyData>::New();
aPolyData->SetPoints(points);

// Create a cell array to store the polygon in
vtkSmartPointer<vtkCellArray> aCellArray =
vtkSmartPointer<vtkCellArray>::New();

// Define a polygonal hole with a clockwise polygon
vtkSmartPointer<vtkPolygon> aPolygon =
vtkSmartPointer<vtkPolygon>::New();

/*for (int i=36;i<72;i++)
{
aPolygon->GetPointIds()->InsertNextId(i);
}*/
/*aPolygon->GetPointIds()->InsertNextId(22);
aPolygon->GetPointIds()->InsertNextId(23);
aPolygon->GetPointIds()->InsertNextId(24);
aPolygon->GetPointIds()->InsertNextId(25);
aPolygon->GetPointIds()->InsertNextId(35);
aPolygon->GetPointIds()->InsertNextId(45);
aPolygon->GetPointIds()->InsertNextId(44);
aPolygon->GetPointIds()->InsertNextId(43);
aPolygon->GetPointIds()->InsertNextId(42);
aPolygon->GetPointIds()->InsertNextId(32);*/

aCellArray->InsertNextCell(aPolygon);

// Create a polydata to store the boundary. The points must be the
// same as the points we will triangulate.
vtkSmartPointer<vtkPolyData> boundary =
vtkSmartPointer<vtkPolyData>::New();
boundary->SetPoints(aPolyData->GetPoints());
boundary->SetPolys(aCellArray);

// Triangulate the grid points
vtkSmartPointer<vtkDelaunay2D> delaunay =
vtkSmartPointer<vtkDelaunay2D>::New();
#if VTK_MAJOR_VERSION <= 5
delaunay->SetInput(aPolyData);
delaunay->SetSource(boundary);
#else
delaunay->SetInputData(aPolyData);
delaunay->SetSourceData(boundary);
#endif
delaunay->Update();

// Visualize
vtkSmartPointer<vtkPolyDataMapper> meshMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
meshMapper->SetInputConnection(delaunay->GetOutputPort());

vtkSmartPointer<vtkActor> meshActor =
vtkSmartPointer<vtkActor>::New();
meshActor->SetMapper(meshMapper);
//meshActor->GetProperty()->SetEdgeColor(0,0,1); // Why aren't the edges
aren't visible unless we set the representation to wireframe?
//meshActor->GetProperty()->SetInterpolationToFlat();
meshActor->GetProperty()->SetRepresentationToWireframe();

vtkSmartPointer<vtkPolyDataMapper> boundaryMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5
boundaryMapper->SetInputConnection(boundary->GetProducerPort());
#else
boundaryMapper->SetInputData(boundary);
#endif

vtkSmartPointer<vtkActor> boundaryActor =
vtkSmartPointer<vtkActor>::New();
boundaryActor->SetMapper(boundaryMapper);
boundaryActor->GetProperty()->SetColor(1,0,0);

// Create a renderer, render window, and interactor
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);

// Add the actor to the scene
renderer->SetBackground(.3, .6, .3); // Background color green

// Render and interact
renderWindow->Render();
renderWindowInteractor->Start();

return EXIT_SUCCESS;
}

ZhangQiang

--
View this message in context: http://vtk.1045678.n5.nabble.com/How-to-set-the-boundary-of-vtkDelaunay2D-tp5734142.html
Sent from the VTK - Users mailing list archive at Nabble.com.