[vtkusers] using vtkImageConstantPad to ensure a closed surface after vtkContourFilter
Mark Gooding
mark.gooding at gmail.com
Tue Jan 9 05:30:01 EST 2007
Hi all,
I was having a problem that the surfaces generated by my
vtkContourFilter were not closed surfaces where the surface touched
the edge of the volume. After searching in the archives I found an
example where vtkImageConstantPad was used prior to vtkContourFilter
to ensure a closed surface. However, I can't get this to work.
The code below runs with vtkImageConstantPad commented out. However
when I include the padding I get an access violation in
vtkImageThreshold when running in debug mode. (For clarity, the code
shown is somewhat reduced in terms of setting parameters after the
vtkContourFilter, as I don't believe that part of the pipeline is a
problem.)
Am I approaching this problem in the right way? Can anyone see what I
am doing wrong?
I had thought of padding prior to thresholding, but thought that may
be a problem as the image data is coming from a pointer to a c++
array. Would that be a problem?
Any help appreciated as always!
Cheers,
mark
ObjectUnsignedCharArray = vtkUnsignedCharArray::New();
ObjectUnsignedCharArray->SetNumberOfComponents(1);
ObjectUnsignedCharArray->SetArray(PointerToData,PointerToDiscreteSize[0]*PointerToDiscreteSize[1]*PointerToDiscreteSize[2],1);
ObjectStructuredPoints = vtkStructuredPoints::New();
ObjectStructuredPoints->SetNumberOfScalarComponents(1);
ObjectStructuredPoints->SetScalarTypeToUnsignedChar();
ObjectStructuredPoints->SetDimensions(PointerToDiscreteSize[0],PointerToDiscreteSize[1],PointerToDiscreteSize[2]);
ObjectStructuredPoints->SetSpacing(PointerToVoxelResolution[0],PointerToVoxelResolution[1],PointerToVoxelResolution[2]);
ObjectStructuredPoints->SetOrigin(0,0,0);
ObjectStructuredPoints->GetPointData()->SetScalars(ObjectUnsignedCharArray);
ObjectImageThreshold = vtkImageThreshold::New();
ObjectImageThreshold->SetInput(ObjectStructuredPoints);
ObjectImageThreshold->ThresholdByUpper((float)ObjectID);
ObjectImageThreshold->SetInValue((float)ObjectID);
ObjectImageThreshold->SetOutValue(0);
ObjectImageThreshold->SetOutputScalarTypeToUnsignedChar();
ObjectImageThreshold->Update();
//ObjectImageConstantPad = vtkImageConstantPad::New();
//ObjectImageConstantPad->SetInput(ObjectImageThreshold->GetOutput());
//ObjectImageConstantPad->SetConstant(0);
//int* volextent = ObjectImageThreshold->GetOutput()->GetWholeExtent();
//volextent[0]--;
//volextent[1]++;
//volextent[2]--;
//volextent[3]++;
//volextent[4]--;
//volextent[5]++;
//ObjectImageConstantPad->SetOutputWholeExtent(volextent);
//ObjectImageConstantPad->Update();
ObjectContourFilter = vtkContourFilter::New();
ObjectContourFilter->SetInput(ObjectImageThreshold->GetOutput());
//ObjectContourFilter->SetInput(ObjectImageConstantPad->GetOutput());
ObjectContourFilter->UseScalarTreeOn();
ObjectContourFilter->SetValue(0,(float)ObjectID-0.25f);
ObjectTriangleFilter = vtkTriangleFilter::New();
ObjectTriangleFilter->SetInput(ObjectContourFilter->GetOutput());
ObjectDecimate = vtkDecimatePro::New();
ObjectDecimate->SetInput(ObjectTriangleFilter->GetOutput());
ObjectPolyDataNormals = vtkPolyDataNormals::New();
ObjectPolyDataNormals->SetInput(ObjectDecimate->GetOutput());
ObjectStripper = vtkStripper::New();
ObjectStripper->SetInputConnection(ObjectPolyDataNormals->GetOutputPort());
ObjectPolyDataMapper = vtkPolyDataMapper::New();
ObjectPolyDataMapper->SetInput(ObjectStripper->GetOutput());
ObjectActor = vtkActor::New();
ObjectActor->SetMapper(ObjectPolyDataMapper);
More information about the vtkusers
mailing list