[vtkusers] A problem with ConstrainedDelaunay2D
zhq
15891495523 at 126.com
Tue Sep 22 10:43:01 EDT 2015
Dear allI want to construct a delaunay triangulation like:
<http://vtk.1045678.n5.nabble.com/file/n5734051/1.jpg> And I refer to the
example:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/Filtering/ConstrainedDelaunay2DBut
the result I get is: <http://vtk.1045678.n5.nabble.com/file/n5734051/2.png>
How to deal with the triangulation in the inner circle ? Maybe I should set
a good boundary. But I don't know how to set the boundary. It's still not
correct if I set the inner circle as the boundary.My code is :#include
#include #include #include #include #include #include #include #include
#include #include #include #include #include #define PI 3.1415926int
main(int, char *[]){ // Generate a 10 x 10 grid of points vtkSmartPointer
points = vtkSmartPointer::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++) { 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++) { double x = cos(theta*PI/180); double y =
sin(theta*PI/180); points->InsertNextPoint(x,y,0); } vtkSmartPointer
aPolyData = vtkSmartPointer::New(); aPolyData->SetPoints(points); // Create
a cell array to store the polygon in vtkSmartPointer aCellArray =
vtkSmartPointer::New(); // Define a polygonal hole with a clockwise polygon
vtkSmartPointer aPolygon = vtkSmartPointer::New(); /*for (int
i=0;i<360;i++) { aPolygon->GetPointIds()->InsertNextId(i+360); }*/ double
x[3]; /*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 boundary = vtkSmartPointer::New();
boundary->SetPoints(aPolyData->GetPoints()); boundary->SetPolys(aCellArray);
boundary->GetPoint(1,x); int n = boundary->GetPoints()->GetNumberOfPoints();
for (int i=0;i<n;i++) { boundary->GetPoint(i,x); } // Triangulate the grid
points vtkSmartPointer delaunay = vtkSmartPointer::New();#if
VTK_MAJOR_VERSION <= 5 delaunay->SetInput(aPolyData);
delaunay->SetSource(boundary);#else delaunay->SetInputData(aPolyData);
delaunay->SetSourceData(boundary);#endif delaunay->Update(); // Visualize
vtkSmartPointer meshMapper = vtkSmartPointer::New();
meshMapper->SetInputConnection(delaunay->GetOutputPort()); vtkSmartPointer
meshActor = vtkSmartPointer::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
boundaryMapper = vtkSmartPointer::New();#if VTK_MAJOR_VERSION <= 5
boundaryMapper->SetInputConnection(boundary->GetProducerPort());#else
boundaryMapper->SetInputData(boundary);#endif vtkSmartPointer boundaryActor
= vtkSmartPointer::New(); boundaryActor->SetMapper(boundaryMapper);
boundaryActor->GetProperty()->SetColor(1,0,0); // Create a renderer, render
window, and interactor vtkSmartPointer renderer = vtkSmartPointer::New();
vtkSmartPointer renderWindow = vtkSmartPointer::New();
renderWindow->AddRenderer(renderer); vtkSmartPointer renderWindowInteractor
= vtkSmartPointer::New();
renderWindowInteractor->SetRenderWindow(renderWindow); // Add the actor to
the scene renderer->AddActor(meshActor); renderer->AddActor(boundaryActor);
renderer->SetBackground(.3, .6, .3); // Background color green // Render and
interact renderWindow->Render(); renderWindowInteractor->Start(); return
EXIT_SUCCESS;} Thanks in advance !ZhangQiang
--
View this message in context: http://vtk.1045678.n5.nabble.com/A-problem-with-ConstrainedDelaunay2D-tp5734051.html
Sent from the VTK - Users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150922/e1dc0e29/attachment.html>
More information about the vtkusers
mailing list