[vtkusers] vtkNormals bug???

Jonathan Bailleul Jonathan.Bailleul at greyc.ismra.fr
Tue Apr 29 14:18:35 EDT 2003

Dear all,

I think I've found some inconsistent behaviour in using the vtkNormals
filter with the simple program provided below.
I just read a vtk file and wnat in output a file with the same polygons
plus computed normals. What I get in output is apparently the same, but
when I read the files, I can see that a *random* number of points is
added to the file! 

All my input files have exactly 66 vertices, but the resullting output
files have between 99 and 123 vertices! Please notice that additional
vertices occupy the same coordinates as original vertices, so "there is
no obvious difference visually". 

I might have done something wrong in my program, but in that case, can
you tell me what? 

PS: my vtk version is a nighlty release 4.0x.

#include "vtkSphereSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkPolyDataNormals.h"
#include "vtkPolyDataReader.h"
#include "vtkPolyDataWriter.h"
#include "vtkProperty.h"
#include "vtkCamera.h"

#include <assert.h>
#include <stdlib.h>

/* GLOS (Graphic Library in Open Source), an ANSI Common Lisp OpenGL
   Copyright (C) 2000 the GLOS development team
(http://glos.sourceforge.net) */

static void
usage(int argc, char **argv) 
  if (argc != 3)
      printf("(re)compute normals for .vtk object files\n");
      printf("Usage: %s <vtk input object filename> <vtk output file>
\n", argv[0]);

main(int argc, char* argv[])
  usage(argc, argv);

  // create object geometry
  vtkPolyDataReader *reader = vtkPolyDataReader::New();
  reader -> SetFileName(argv[1]);
  reader -> Update();

  vtkPolyDataNormals *normals = vtkPolyDataNormals::New();
  normals -> SetInput(reader -> GetOutput());
  normals -> Update();
  vtkPolyDataWriter *writer = vtkPolyDataWriter::New();
  writer -> SetInput(normals -> GetOutput());
  writer -> SetFileName(argv[2]);
  writer -> SetFileTypeToASCII();
  writer -> Update();

  return EXIT_SUCCESS;

Jonathan BAILLEUL, Doctorant
GREYC Image - Université de Caen 

More information about the vtkusers mailing list