[vtkusers] Displaying a simple non convex polygon
Ulrich Kemloh
kemlohulrich at gmail.com
Wed Feb 19 13:45:32 EST 2014
Dear VTK users,
I am having some troubles displaying a simple non convex polygon.
There are at least two triangles strips out of nowhere which seem to be connected to the first vertex.
Attached is the code and the output.
It is quite simple, so I guess I might be doing something terribly wrong,
or I am missing some fundamental knowledge about vtk.
As far as I know vtkPolygon handles non convex polygons as well.
the Vertex should just be counter-clockwise.
Any hints will be so highly appreciated.
Viele Grüße
Ulrich
Minimal working sample Code:
#include <vtkVersion.h>
#include <vtkSmartPointer.h>
#include <vtkPolygon.h>
#include <vtkCellArray.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
int main(int, char *[])
{
// Setup four points
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(-5, 3, 0.0 );
points->InsertNextPoint( 0, 3, 0.0 );
points->InsertNextPoint( 0, 1, 0.0 );
points->InsertNextPoint( -5, 1, 0.0 );
points->InsertNextPoint( -5, -3, 0.0 );
points->InsertNextPoint( 0, -3, 0.0 );
points->InsertNextPoint( 2, -3, 0.0 );
points->InsertNextPoint( 18, -3, 0.0 );
points->InsertNextPoint( 20, -3, 0.0 );
points->InsertNextPoint( 25, -3, 0.0 );
points->InsertNextPoint( 25, 1, 0.0 );
points->InsertNextPoint( 20, 1, 0.0 );
points->InsertNextPoint( 20, 3, 0.0 );
points->InsertNextPoint( 25, 3, 0.0 );
points->InsertNextPoint( 25, 7, 0.0 );
points->InsertNextPoint( -5, 7, 0.0 );
// Create the polygon
vtkSmartPointer<vtkPolygon> polygon =
vtkSmartPointer<vtkPolygon>::New();
polygon->GetPointIds()->SetNumberOfIds(15);
polygon->GetPointIds()->SetId(0, 0);
polygon->GetPointIds()->SetId(1, 1);
polygon->GetPointIds()->SetId(2, 2);
polygon->GetPointIds()->SetId(3, 3);
polygon->GetPointIds()->SetId(4, 4);
polygon->GetPointIds()->SetId(5, 5);
polygon->GetPointIds()->SetId(6, 6);
polygon->GetPointIds()->SetId(7, 7);
polygon->GetPointIds()->SetId(8, 8);
polygon->GetPointIds()->SetId(9, 9);
polygon->GetPointIds()->SetId(10, 10);
polygon->GetPointIds()->SetId(11, 11);
polygon->GetPointIds()->SetId(12, 13);
polygon->GetPointIds()->SetId(13, 13);
polygon->GetPointIds()->SetId(14, 14);
polygon->GetPointIds()->SetId(15, 15);
//polygon->GetPointIds()->SetId(16, 16);
// Add the polygon to a list of polygons
vtkSmartPointer<vtkCellArray> polygons =
vtkSmartPointer<vtkCellArray>::New();
polygons->InsertNextCell(polygon);
// Create a PolyData
vtkSmartPointer<vtkPolyData> polygonPolyData =
vtkSmartPointer<vtkPolyData>::New();
polygonPolyData->SetPoints(points);
polygonPolyData->SetPolys(polygons);
// Create a mapper and actor
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
#if VTK_MAJOR_VERSION <= 5
mapper->SetInput(polygonPolyData);
#else
mapper->SetInputData(polygonPolyData);
#endif
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
// Visualize
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
renderer->AddActor(actor);
renderer->SetBackground(.5,.3,.31); // Background color salmon
renderWindow->Render();
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
--
Ulrich Kemloh
Division Civil Security and Traffic
Jülich Supercomputing Centre
Institute for Advanced Simulation
tel +49 2461 61 4193
fax +49 2461 61 6656
www.fz-juelich.de/ias/jsc/cst
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140219/d5c7fd57/attachment.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: CMakeLists.txt
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140219/d5c7fd57/attachment.txt>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140219/d5c7fd57/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Polygon.cxx
Type: application/octet-stream
Size: 3387 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140219/d5c7fd57/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140219/d5c7fd57/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vtk-Polygon-question.png
Type: image/png
Size: 19871 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140219/d5c7fd57/attachment.png>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140219/d5c7fd57/attachment-0003.html>
More information about the vtkusers
mailing list