[vtkusers] vtkContourFilter issue

David Doria daviddoria+vtk at gmail.com
Wed Dec 9 13:11:58 EST 2009


On Wed, Dec 9, 2009 at 12:38 PM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
> David,
>
> 1) Please do not use drand48. It's not portable. Use
> vtkMath::Random(0.0,1.0) for equivalent.
> 2) drand48 generates numbers between 0,1. You cannot extract an
> isosurface of 0. Try vtkMath::Random(-1.0,1.0)
>
> Bill

Bill,

1) Good point. Will do.

2) You are correct, that was an artifact of simplifying my code into a
demo. In the demo, when this was changed, it worked as expected. In my
real code, the values were indeed on both sides of zero.

I have isolated the problem: I was setting up the ImageData in a
separate class that derives from vtkImageAlgorithm (aside: why is it
not called vtkImageDataAlgorithm?)

When I cut and paste the contents of the RequestData function from
that class into the function we have been discussing, it works fine.

I checked the input pointer in RequestData and it has the correct
number of points, so the input of the pipeline has been setup
correctly. The output of the voxelizeFilter seems to be setup properly
back in the calling function. It seems to me that these two should
behave identically, but one produces valid output while the other
produces empty output.

Here is the VoxelizePolyData class:
http://www.rpi.edu/~doriad/VTK_List/vtkVoxelizePolyData/

Does anyone see why these two things would be any different:

A)
  vtkSmartPointer<vtkVoxelizePolyData> voxelizeFilter =
vtkSmartPointer<vtkVoxelizePolyData>::New();
  voxelizeFilter->SetInput(input);
  voxelizeFilter->Update();
  vtkImageData* grid = voxelizeFilter->GetOutput();

B)

  //get the bounds of the input PolyData
    double bounds[6];
    input->GetBounds(bounds);
  //xmin, xmax, ymin, ymax, zmin, zmax
    double xmin = bounds[0];
    double xmax = bounds[1];
    double ymin = bounds[2];
    double ymax = bounds[3];
    double zmin = bounds[4];
    double zmax = bounds[5];

  //create a grid the size of the point set
    vtkSmartPointer<vtkImageData> grid = vtkSmartPointer<vtkImageData>::New();

  //set the bottom left corner of the grid to the bottom left corner
of the data bounding box
    grid->SetOrigin(xmin, ymin, zmin);

  //create a grid of voxels of size (NumberOfCellsX x NumberOfCellsY x
NumberOfCellsZ)
  //there are (NumberOfCellsX+1 x NumberOfCellsY+1 x NumberOfCellsZ+1)
points to make this size voxel grid
    grid->SetExtent(0, 10, 0, 10, 0, 10);

  //set the size of each element/cell/voxel so that the grid spans the
entire input point set volume
  //grid->SetSpacing((xmax-xmin)/static_cast<double>(this->NumberOfCellsX),
(ymax-ymin)/static_cast<double>(this->NumberOfCellsY),
(zmax-zmin)/static_cast<double>(this->NumberOfCellsZ));
    grid->SetSpacing((xmax-xmin)/static_cast<double>(10),
(ymax-ymin)/static_cast<double>(10),
(zmax-zmin)/static_cast<double>(10));

Have I done something wrong in setting up the pipeline connections of
the voxelizePolyData filter?

Thanks,

David



More information about the vtkusers mailing list