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

David.Pont at ForestResearch.co.nz David.Pont at ForestResearch.co.nz
Mon Feb 7 16:07:55 EST 2005





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