[vtkusers] How to set the boundary of vtkDelaunay2D ?

David Gobbi david.gobbi at gmail.com
Sun Sep 27 10:20:55 EDT 2015


On Sun, Sep 27, 2015 at 5:16 AM, zhq <15891495523 at 126.com> wrote:

> Dear David:
>
>       I have read the example you give. And the input of
> vtkContourTriangulator is all surface, how can I input a set of points ?
>

The input to to vtkContourTriangulator is lines, not a surface.  Join the
points together into line segments.


#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 <vtkContourTriangulator.h>
#include <vtkMath.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#define PI 3.1415926

int main(int, char *[])
{
        // Generate two circular contours with line segments
        vtkSmartPointer<vtkPoints> points =
                vtkSmartPointer<vtkPoints>::New();
        vtkSmartPointer<vtkCellArray> aCellArray =
                vtkSmartPointer<vtkCellArray>::New();

        vtkIdType lastPointId = 35;
        for (int theta = 0;theta<360;theta+=10)
        {
                double x = 2*cos(theta*PI/180);
                double y = 2*sin(theta*PI/180);
                vtkIdType pointId = points->InsertNextPoint(x,y,0);
                aCellArray->InsertNextCell(2);
                aCellArray->InsertCellPoint(lastPointId);
                aCellArray->InsertCellPoint(pointId);
                lastPointId = pointId;
        }

        lastPointId = 71;
        for (int theta = 350;theta>=0;theta-=10)
        {
                double x = cos(theta*PI/180);
                double y = sin(theta*PI/180);
                vtkIdType pointId = points->InsertNextPoint(x,y,0);
                aCellArray->InsertNextCell(2);
                aCellArray->InsertCellPoint(lastPointId);
                aCellArray->InsertCellPoint(pointId);
                lastPointId = pointId;
        }

        // Create a polydata to store the contour.
        vtkSmartPointer<vtkPolyData> contour =
                vtkSmartPointer<vtkPolyData>::New();
        contour->SetPoints(points);
        contour->SetLines(aCellArray);
        contour->BuildCells();
        contour->BuildLinks();

        // Triangulate the grid points
        vtkSmartPointer<vtkContourTriangulator> triangulator =
                vtkSmartPointer<vtkContourTriangulator>::New();
#if VTK_MAJOR_VERSION <= 5
        triangulator->SetInput(contour);
#else
        triangulator->SetInputData(contour);
#endif
        triangulator->Update();

        // Visualize
        vtkSmartPointer<vtkPolyDataMapper> meshMapper =
                vtkSmartPointer<vtkPolyDataMapper>::New();
        meshMapper->SetInputConnection(triangulator->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> contourMapper =
                vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5
        contourMapper->SetInputConnection(contour->GetProducerPort());
#else
        contourMapper->SetInputData(contour);
#endif

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

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

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

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

        return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150927/8ace2f7a/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: triangulator.png
Type: image/png
Size: 18412 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150927/8ace2f7a/attachment.png>


More information about the vtkusers mailing list