[vtkusers] Delaunay3d help

Lichun Andrew Li ll1 at ese.wustl.edu
Mon Aug 29 22:27:02 EDT 2005


in VC++, the following code crashes:
(unhandled exception (vtkRendering.dll), access violation).
I was just trying to triangulate points on a hemisphere.

#include "vtkMath.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkPolyData.h"
#include "vtkPoints.h"
#include "vtkCellArray.h"
#include "vtkIntArray.h"
#include "vtkDoubleArray.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkCamera.h"
#include "vtkPointData.h"
#include "vtkDelaunay3D.h"
#include "vtkUnstructuredGridToPolyDataFilter.h"
#include "vtkUnstructuredGrid.h"




void main( int argc, char *argv[] )
{
   int i = 0;
   int delta_deg = 60;  //angle increment
   int azimuth=0;
   int elevation = 0;
   float azimuth_rad, elevation_rad;
   float R = 100;

   static float coor[3];

   vtkPolyData *hemisphere = vtkPolyData::New();
   vtkPoints *points = vtkPoints::New();

   for (elevation = 90; elevation >= 0; elevation = elevation - delta_deg)
 	  for ( azimuth = 0; azimuth < 360; azimuth = azimuth + delta_deg)
 	  {
 		  azimuth_rad = azimuth*vtkMath::DegreesToRadians();
 		  elevation_rad = elevation*vtkMath::DegreesToRadians();
 		  coor[0] = R*cos(elevation_rad)*cos(azimuth_rad);
 		  coor[1] = R*cos(elevation_rad)*sin(azimuth_rad);
 		  coor[2] = R*sin(elevation_rad);
 		  i++;
 		  points->InsertPoint(i, coor);
 	  }

   hemisphere->SetPoints(points);
   points->Delete();

   vtkDelaunay3D * mesh = vtkDelaunay3D::New();
   mesh->SetInput(hemisphere);
   mesh->SetTolerance (0.01);
   mesh->SetAlpha(0.2);

   vtkPolyDataMapper *hemisphereMapper = vtkPolyDataMapper::New();
       hemisphereMapper->SetInput((vtkPolyData*) mesh->GetOutput());

   vtkActor *hemisphereActor = vtkActor::New();
 	hemisphereActor->SetMapper(hemisphereMapper);

   vtkRenderer *renderer = vtkRenderer::New();
   renderer->AddActor(hemisphereActor);


   vtkRenderWindow *renWin = vtkRenderWindow::New();
     renWin->AddRenderer(renderer);
 	renWin->SetSize(300,300);
     renWin->Render();

   vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
     iren->SetRenderWindow(renWin);

   iren->Start();

   renderer->Delete();
   renWin->Delete();
   iren->Delete();
   hemisphere->Delete();
   points->Delete();
   hemisphereMapper->Delete();
   hemisphereActor->Delete();

}




More information about the vtkusers mailing list