[vtkusers] [Problem] How do I get the Connected Components of a vtkImplicitFunction ?
Jean-Marie Normand
normand at lina.univ-nantes.fr
Mon Feb 7 09:29:55 EST 2005
Hi all,
I'd like to extract the components of a vtkImplicitFunction, but I fail
to obtain them.
I perform some boolean operations on vtkImplicitFunctions which leads to
a vtkImplicitBoolean that has multiple parts, and I'd like to extract
each one.
I didn't find any possibilities but to use a
vtkPolyDataconnectivityFilter whichi requires first to "tessellate" my
implicit functions. My first question would be :
- Is it possible to obtain those components without sampling the
function, then apply a contour filter and finally a
vtkPolyDataConnectivityFilter ?
In fact the method described above succeed on a toy example (a cube cut
in two parts), but when I try to use it in my application, the following
error is always rised :
ERROR: In
/home/jim/Download/VTK/VTK/Graphics/vtkPolyDataConnectivityFilter.cxx,
line 90
vtkPolyDataConnectivityFilter (0x99ec4b0): No points!
and it tells me that there are no connected components which is actually
wrong since when I display the implicit function I can see the
components.
Here is my sample of code, any help would be greatly appreciated since I
don't understand what's wrong.
// Sampling the implicit function
vtkSampleFunction *implicitSampleFunction = vtkSampleFunction::New();
implicitSampleFunction->SetImplicitFunction(impFunc);
implicitSampleFunction->SetModelBounds(-1.5*WORLD_SIZE,1.5*WORLD_SIZE,-1.5*WORLD_SIZE,1.5*WORLD_SIZE,-1.5*WORLD_SIZE,1.5*WORLD_SIZE);
implicitSampleFunction->SetSampleDimensions(100,100,100);
implicitSampleFunction->ComputeNormalsOff();
// Creating a ContourFilter of the above Sample Function
vtkContourFilter *implicitContourFilter = vtkContourFilter::New();
implicitContourFilter->SetInput(implicitSampleFunction->GetOutput());
implicitContourFilter->SetValue(0,0.);
/* cleaning up the result in a vtkCleanPolyData before applying the
vtkPolyDataConnectivityFilter */
vtkCleanPolyData *implicitCleaned = vtkCleanPolyData::New();
implicitCleaned->SetInput( implicitContourFilter->GetOutput() );
implicitCleaned->SetTolerance(0.);
// Applying the vtkPolyDataConnectivityFilter
vtkPolyDataConnectivityFilter *implicitPDCF =
vtkPolyDataConnectivityFilter::New();
implicitPDCF->SetInput(implicitCleaned->GetOutput());
implicitPDCF->ScalarConnectivityOff();
// getting the number of connected components of the implicit function
implicitPDCF->SetExtractionModeToAllRegions();
implicitPDCF->Update();
int nb_connected_components =
implicitPDCF->GetNumberOfExtractedRegions();
cout<<"Nb connected components : "<<nb_connected_components<<endl;
/* returns 0!*/
// declaring temporary variables needed in the loop
vtkPolyData *extractedPolyData = vtkPolyData::New();
vtkImplicitDataSet *implicitFunc;
// Declaring the vtkImplicitFunctionList
vtkImplicitFunctionList *impList = new vtkImplicitFunctionList();
implicitPDCF->SetExtractionModeToSpecifiedRegions();
// extracting all the regions in a loop
for(int i=0; i<nb_connected_components; i++)
{
// retrieving the ith region
implicitPDCF->AddSpecifiedRegion(i);
implicitPDCF->Update();
// copying it into a vtkPolyData*
extractedPolyData = implicitPDCF->GetOutput();
// Converting the vtkPolyData into a vtkImplicitFunction
implicitFunc = vtkImplicitDataSet::New();
implicitFunc->SetDataSet(extractedPolyData);
// Adding an implicit function to a list
impList->addImplicitFunction(implicitFunc);
}
// Freeing memory
implicitCleaned->Delete();
implicitContourFilter->Delete();
implicitSampleFunction->Delete();
extractedPolyData->Delete();
}
Thanks in advance
--
Jim
More information about the vtkusers
mailing list