[vtkusers] [Problem] How do I get the Connected Components of a vtkImplicitFunction ?

Jean-Marie Normand normand at lina.univ-nantes.fr
Tue Feb 8 05:25:12 EST 2005


Hi Dave,
thanks for your reply!
Actually I've created a class to display my implicit functions that
consists in sampling the function via a vtkSampleFunction, then
contouring it (vtkContourFilter) and finally creating the associated
vtkPolyDataMapper and vtkActor.

The problem seems indded to come from the bounds, I found yesterday that
if I change my 

implicitSampleFunction->SetModelsBounds(-100.,100.,-100.,100.,-100.,100.);

to

implicitSampleFunction->SetModelsBounds(-101.,101.,-101.,101.,-101.,101.);

then I get 11 connected components.... I don't really understand why
with +/-100. I got the "No points!" error whereas with +/-101. it seems
to work...


The main problem of this approach is that I need to sample my implicit
function to retrieve the number of connected components, and I have no
infos on the bounds of my model apart from the fact that the boolean
operations will remain within a global "world" representing the bounds
at the beginning of the boolean ops, i.e. I can't reduce the bounds of
my sampling domain.


Moreover I have to use a vtkImplicitDataSet to have those connected
components back as implicit functions, i.e. starting from a
vtkImplcitFunction I need to sample, contour and clean it, afterwards
passing it through a vtkPolyDataConnectivityFilter to finally
retransform it in a implicit function by using the vtkImplicitDataSet.
The whole process seems quite inadequate to me....

But I may be wrong in the way I'm doing it, I'd appreciate to know if
there is a simpler way to get the components of an implicit function.



Concerning your suggestions, do I need to contour the implicit functions
with several contours? wouldn't it "inflate" the volume represented by
my implicit functions??


Thanks again 


Jim

Le lun 07/02/2005 à 22:07, David.Pont at ForestResearch.co.nz a écrit :
> 
> 
> vtkusers-bounces at vtk.org wrote on 08/02/2005 03:29:55:
> 
> > 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.
> >
> 
>   Jim,
>     how do you display the implicit function ? do you render the output of
> the Contour filter and/or CleanPolyData filters ?
> I just ask because it can be easy to 'miss' implicit functions, ie are you
> sure the Bounds and SampleDimensions for the SampleFunction are suitable
> for the surface, especially after it has been 'cut' into pieces. If the
> bounds are wrong you miss the surface completely, if the sample dimensions
> are too large the surface can fall between sample positions.
> Just a few suggestions, I have lost time on these kinds of problems before.
> Can you check the range of data from the SampleFunction, then contour that
> range with several contours. This would reveal how the sample space relates
> to the surface.
> 
>    Dave P
> 
> >
> > 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
> >
> > _______________________________________________
> > This is the private VTK discussion list.
> > Please keep messages on-topic. Check the FAQ at: http://www.vtk.
> > org/Wiki/VTK_FAQ
> > Follow this link to subscribe/unsubscribe:
> > http://www.vtk.org/mailman/listinfo/vtkusers
> 




More information about the vtkusers mailing list