[vtkusers] Is vtkDelaunay2D filter always producing counter-clockwise cells?
pof
jd379252 at gmail.com
Thu May 8 08:20:14 EDT 2008
Hi all,
I'm using vtkDelaunay2D filter to triangulate data points.
As a result, it usually (or at least it's what I thought) produces
triangular cells
that are counter-clockwise.
However, in some cases, it also produces clockwise cells (see topology
of the cell
with Id=4 in the output file "MeshData.vtk" given below, obtained with
the file
"Test.cpp" also given below).
As a hint, in this small test, a constrained Delaunay triangulation is
performed by
specifying the outer boundary (counter-clockwise).
So my questions :
- Is it normal that in some cases vtkDelaunay2D filter produces
clockwise cells ?
- Is there a way to force the filter to obtain only counter-clockwise
cells ?
Thanks,
File "MeshData.vtk"
# vtk DataFile Version 3.0
vtk output
ASCII
DATASET POLYDATA
POINTS 11 float
200 700 0 800 700 0 200 600 0
800 600 0 200 500 0 800 500 0
500 520 0 500 550 0 500 600 0
500 650 0 500 700 0
POLYGONS 13 52
3 7 5 3
3 7 6 5
3 9 8 3
3 8 7 3
3 4 6 5
3 9 0 2
3 7 2 4
3 9 3 1
3 7 4 6
3 10 9 1
3 8 2 7
3 9 2 8
3 10 0 9
CELL_DATA 13
POINT_DATA 11
File "Test.cpp"
/////////////////////////////////////////////////////////////////////////
// Test of constrained Delaunay2D with outer boundary
// vtk5.0.4
//
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkCamera.h"
#include "vtkPoints.h"
#include "vtkCellArray.h"
#include "vtkDelaunay2D.h"
#include "vtkExtractEdges.h"
#include "vtkTubeFilter.h"
#include "vtkProperty.h"
#include "vtkIdFilter.h"
#include "vtkCellCenters.h"
#include "vtkSelectVisiblePoints.h"
#include "vtkLabeledDataMapper.h"
#include "vtkTextProperty.h"
#include "vtkActor2D.h"
#include "vtkPolyDataWriter.h"
int main()
{
// Generate the input points
vtkPoints *points = vtkPoints::New();
points->InsertPoint(0, 200., 700., 0.);
points->InsertPoint(1, 800., 700., 0.);
points->InsertPoint(2, 200., 600., 0.);
points->InsertPoint(3, 800., 600., 0.);
points->InsertPoint(4, 200., 500., 0.);
points->InsertPoint(5, 800., 500., 0.);
points->InsertPoint(6, 500., 520., 0.);
points->InsertPoint(7, 500., 550., 0.);
points->InsertPoint(8, 500., 600., 0.);
points->InsertPoint(9, 500., 650., 0.);
points->InsertPoint(10, 500., 700., 0.);
// Generate the constrained outer boundary
vtkCellArray *polys = vtkCellArray::New();
polys->InsertNextCell(8);
polys->InsertCellPoint(3);
polys->InsertCellPoint(1);
polys->InsertCellPoint(10);
polys->InsertCellPoint(0);
polys->InsertCellPoint(2);
polys->InsertCellPoint(4);
polys->InsertCellPoint(5);
polys->InsertCellPoint(3);
// Build the polydata
vtkPolyData *polyData = vtkPolyData::New();
polyData->SetPoints(points);
polyData->SetPolys(polys);
// Triangulate them
vtkDelaunay2D *del1 = vtkDelaunay2D::New();
del1->SetInput(polyData);
del1->SetSource(polyData);
vtkPolyDataMapper *mapMesh = vtkPolyDataMapper::New();
mapMesh->SetInputConnection(del1->GetOutputPort());
vtkActor *meshActor = vtkActor::New();
meshActor->SetMapper(mapMesh);
// Write the output polydata to a file
vtkPolyDataWriter *writerPD = vtkPolyDataWriter::New();
writerPD->SetFileName("MeshData.vtk");
writerPD->SetInput(del1->GetOutput());
writerPD->Write();
// Tubes around mesh
vtkExtractEdges *extract = vtkExtractEdges::New();
extract->SetInputConnection(del1->GetOutputPort());
vtkTubeFilter *tubes = vtkTubeFilter::New();
tubes->SetInputConnection(extract->GetOutputPort());
tubes->SetRadius(1.0);
tubes->SetNumberOfSides(6);
vtkPolyDataMapper *mapEdges = vtkPolyDataMapper::New();
mapEdges->SetInputConnection(tubes->GetOutputPort());
vtkActor *edgeActor = vtkActor::New();
edgeActor->SetMapper(mapEdges);
(edgeActor->GetProperty())->SetColor(1,0,0);
(edgeActor->GetProperty())->SetSpecularColor(1,1,1);
(edgeActor->GetProperty())->SetSpecular(0.3);
(edgeActor->GetProperty())->SetSpecularPower(20);
(edgeActor->GetProperty())->SetAmbient(0.2);
(edgeActor->GetProperty())->SetDiffuse(0.8);
// Create the graphics structure
vtkRenderer *ren1 = vtkRenderer::New();
/////////////////////////////////////////////////////////////////////
// Stuff to display point and celll Ids
/////////////////////////////////////////////////////////////////////
vtkIdFilter *ids = vtkIdFilter::New();
ids->SetInput(del1->GetOutput());
ids->CellIdsOn();
ids->PointIdsOn();
////////////////////////////////////////////////////////////////////
// Create labels for cells
vtkCellCenters *cc = vtkCellCenters::New();
cc->SetInputConnection(ids->GetOutputPort());
vtkSelectVisiblePoints *visCells = vtkSelectVisiblePoints::New();
visCells->SetInputConnection(cc->GetOutputPort());
visCells->SetRenderer(ren1);
// Create the mapper to display the cell ids. Specify the
// format to use for the labels. Also create the associated actor.
vtkLabeledDataMapper *cellMapper = vtkLabeledDataMapper::New();
cellMapper->SetInputConnection(visCells->GetOutputPort());
cellMapper->SetLabelFormat("%g");
cellMapper->SetLabelModeToLabelFieldData();
(cellMapper->GetLabelTextProperty())->SetColor(0.,0.,1.);
vtkActor2D *cellLabels = vtkActor2D::New();
cellLabels->SetMapper(cellMapper);
////////////////////////////////////////////////////////////////////
// Create labels for points
vtkSelectVisiblePoints *visPts = vtkSelectVisiblePoints::New();
visPts->SetInputConnection(ids->GetOutputPort());
visPts->SetRenderer(ren1);
// Create the mapper to display the point ids. Specify the
// format to use for the labels. Also create the associated actor.
vtkLabeledDataMapper *ldm = vtkLabeledDataMapper::New();
ldm->SetInputConnection(visPts->GetOutputPort());
ldm->SetLabelFormat("%g");
ldm->SetLabelModeToLabelFieldData();
(ldm->GetLabelTextProperty())->SetColor(1.,0.,0.);
vtkActor2D *pointLabels = vtkActor2D::New();
pointLabels->SetMapper(ldm);
// Finishes the graphics structure
// Add the actors to the renderer, set the background and size
ren1->AddActor(meshActor);
ren1->AddActor(edgeActor);
ren1->AddActor(cellLabels);
ren1->AddActor(pointLabels);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren1);
renWin->SetSize(400, 400);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
// Add the actors to the renderer, set the background and size
ren1->SetBackground(0.1, 0.2, 0.4);
renWin->SetSize(400, 400);
ren1->ResetCamera();
renWin->Render();
// This starts the event loop
iren->Start();
// Delete all the instances that have been created
ren1->Delete();
renWin->Delete();
iren->Delete();
meshActor->Delete();
mapMesh->Delete();
writerPD->Delete();
extract->Delete();
tubes->Delete();
edgeActor->Delete();
mapEdges->Delete();
ids->Delete();
cc->Delete();
visCells->Delete();
cellMapper->Delete();
cellLabels->Delete();
ldm->Delete();
pointLabels->Delete();
visPts->Delete();
del1->Delete();
polyData->Delete();
points->Delete();
polys->Delete();
return 0;
}
More information about the vtkusers
mailing list