[vtkusers] vtkDelaunay3D - Integer division by zero

Bill Lorensen bill.lorensen at gmail.com
Wed Feb 19 15:56:21 EST 2014


Also, you are better off using TriangleFilter rather than depending on
the graphics hardware to render non-convex polygons...

Try this:
#include <vtkVersion.h>
#include <vtkSmartPointer.h>
#include <vtkPolygon.h>
#include <vtkCellArray.h>
#include <vtkTriangleFilter.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(16);
  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);

  vtkSmartPointer<vtkTriangleFilter> triangles =
    vtkSmartPointer<vtkTriangleFilter>::New();
#if VTK_MAJOR_VERSION <= 5
  triangles->SetInput(polygonPolyData);
#else
  triangles->SetInputData(polygonPolyData);
#endif

  // Create a mapper and actor
  vtkSmartPointer<vtkPolyDataMapper> mapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(triangles->GetOutputPort());

  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;
}

On Wed, Feb 19, 2014 at 3:50 PM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
> There is a bug on your program:
>  polygon->GetPointIds()->SetNumberOfIds(15);
> should be
>  polygon->GetPointIds()->SetNumberOfIds(16);
>
> On Wed, Feb 19, 2014 at 3:41 PM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
>> Please post your code.
>>
>>
>> On Tue, Feb 18, 2014 at 8:11 AM, Susanne Schmalkalt
>> <Susanne.Schmalkalt at gmx.de> wrote:
>>> Dear vtkusers,
>>>
>>> I encounter a problem using the vtkDelaunay3d Algorithm.
>>> What I am doing is quite simple. I want to obtain the convex Hull of several
>>> 3D points. I followed this example:
>>> http://www.itk.org/Wiki/VTK/Examples/Boneyard/Cxx/PolyData/ConvexHullDelaunay3D
>>>
>>> I add the points to a vtkPolyData object, and then use vtkDelaunay3d to
>>> compute the convex Hull.
>>> But when I do so, it returns the error:
>>> Unhandled exception at 0x05c6a084 in GUIWindowApplication.exe: 0xC0000094:
>>> Integer division by zero.
>>>
>>>   vtkSmartPointer<vtkPolyData> delaunayPolyData =  vtkSmartPointer<
>>> vtkPolyData>::New();
>>>
>>>  delaunayPolyData->SetPoints(somePoints);   // somePoints is a
>>> vtkSmartPointer<vtkPoints>
>>>
>>>   vtkSmartPointer<vtkDelaunay3D> delaunay = vtkSmartPointer< vtkDelaunay3D
>>>>::New();
>>>   delaunay->SetInput(delaunayPolyData);
>>>   delaunay->Update();
>>>
>>>
>>> Do i have to change some settings in the beginning? Does anybody know where
>>> this error comes from?
>>> I mean, integer division by zero should be handeld by the vtkDelaunay3D
>>> algorithm, right?
>>>
>>> Thank you a lot!
>>> Susi
>>>
>>> _______________________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Please keep messages on-topic and check the VTK FAQ at:
>>> http://www.vtk.org/Wiki/VTK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.vtk.org/mailman/listinfo/vtkusers
>>>
>>
>>
>>
>> --
>> Unpaid intern in BillsBasement at noware dot com
>
>
>
> --
> Unpaid intern in BillsBasement at noware dot com



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the vtkusers mailing list