[vtkusers] using vtkImageConstantPad to ensure a closed surface after vtkContourFilte

Dean Inglis dean.inglis at sympatico.ca
Tue Jan 9 07:35:33 EST 2007


Hi Mark,

why are you using vtkStructuredPoints and not vtkImageData?
I think your general approach is correct, and you may be
running into a problem with setting the unsigned char
array with an external c++ array (PointerToData).  One thing
to try is to DeepCopy the "made up" vtkStructuredPoints
with a new one to separate the pipeline from the c++ array pointer:

ObjectUnsignedCharArray = vtkUnsignedCharArray::New();
ObjectUnsignedCharArray->SetNumberOfComponents(1);
ObjectUnsignedCharArray->SetArray(PointerToData,PointerToDiscreteSize[0]*Poi
nterToDiscreteSize[1]*PointerToDiscreteSize[2],1);

ObjectStructuredPoints = vtkStructuredPoints::New();
ObjectStructuredPoints->SetNumberOfScalarComponents(1);
ObjectStructuredPoints->SetScalarTypeToUnsignedChar();
ObjectStructuredPoints->SetDimensions(PointerToDiscreteSize[0],PointerToDisc
reteSize[1],PointerToDiscreteSize[2]);
ObjectStructuredPoints->SetSpacing(PointerToVoxelResolution[0],PointerToVoxe
lResolution[1],PointerToVoxelResolution[2]);
ObjectStructuredPoints->SetOrigin(0,0,0);
ObjectStructuredPoints->GetPointData()->SetScalars(ObjectUnsignedCharArray);

/****************************************** try this
ObjectStructuredPoints->Update();
ObjectStructuredPointsSEPARATE = vtkStructuredPoints::New();
ObjectStructuredPointsSEPARATE->DeepCopy(ObjectStructuredPoints);

ObjectImageThreshold = vtkImageThreshold::New();
ObjectImageThreshold->SetInput(ObjectStructuredPointsSEPARATE);

/******************************************

ObjectImageThreshold->ThresholdByUpper((float)ObjectID);
ObjectImageThreshold->SetInValue((float)ObjectID);
ObjectImageThreshold->SetOutValue(0);
ObjectImageThreshold->SetOutputScalarTypeToUnsignedChar();
ObjectImageThreshold->Update();

regards,
Dean


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!




More information about the vtkusers mailing list