[vtkusers] vtkPolyDataConnectivityFilter Help

Sylvain Jaume sylvain.jaume at kitware.com
Fri Nov 25 23:32:06 EST 2005


Hi Mike,

I think this code will solve your problem:

  unsigned int numRegions = connections->GetNumberOfExtractedRegions();

  vtkClipPolyData *clip = vtkClipPolyData::New();
  clip->SetInput(connections->GetOutput() );
 
  vtkClipPolyData *clipInsideOut = vtkClipPolyData::New();
  clipInsideOut->SetInput(connections->GetOutput() );
  clipInsideOut->InsideOutOn();
 
  for (unsigned int i = 0; i < numRegions; ++i)
  {
      std::cout << "----------- Region Number " << i << "   ----------" 
<< std::endl;
 
      clip->SetValue( (float) i - 0.5 );
      clipInsideOut->SetValue( (float) i + 0.5 );
      clipInsideOut->Update();

      clipInsideOut->GetOutput()->PrintSelf(std::cout, 1);
}

Cheers,
Sylvain

Mike Jackson wrote:

>
> On Nov 23, 2005, at 6:51 PM, Sylvain Jaume wrote:
>
>> Hi Mike,
>>
>> You may want to do:
>>
>> vtkPolyDataConnectivityFilter *connections =   
>> vtkPolyDataConnectivityFilter::New();
>> connections->SetInput(data);
>> connections->SetExtractionModeToAllRegions();
>> connections->ColorRegionsOn();
>> connections->Update();
>>
>>  unsigned int numRegions = connections->GetNumberOfExtractedRegions();
>>  vtkClipPolyData *clip = vtkClipPolyData::New();
>>  clip->SetInput(connections->GetOutput() );
>>
>>  for (unsigned int i = 0; i < numRegions; ++i)
>>  {
>>      std::cout << "----------- Region Number " << i << "   
>> ----------" << std::endl;
>>      clip->SetValue( (float) i );
>>      clip->Update();
>>      clip->GetOutput()->PrintSelf(std::cout, 1);
>>  }
>>
>> You don't need  clip->GenerateClipScalarsOff();
>>
>> Cheers,
>> Sylvain
>>
>> Mike Jackson wrote:
>>
>>>
>>> On Nov 23, 2005, at 5:18 PM, Sylvain Jaume wrote:
>>>
>>>>
>>>> You could set ColorRegionsOn in vtkPolyDataConnectivityFilter.
>>>> Then use vtkClipPolyData with SetValue set to the region id (i  in  
>>>> your code).
>>>>
>>>> Cheers,
>>>> Sylvain
>>>
>>>
>>>
>>> I gave that a try, looking extensively at the docs and this is  what 
>>> I  have.
>>> //Assume data is of type vtkPolyData which has been through a  
>>> smoothing
>>> // and a Decimation, just prior to this.
>>>   vtkPolyDataConnectivityFilter *connections =   
>>> vtkPolyDataConnectivityFilter::New();
>>>   connections->SetInput(data);
>>>   connections->SetExtractionModeToAllRegions();
>>>   connections->Update();
>>>
>>>   /// Loop on each Region
>>>   unsigned int numRegions = connections- 
>>> >GetNumberOfExtractedRegions();
>>>   vtkClipPolyData *clip = vtkClipPolyData::New();
>>>   vtkImplicitBoolean *func = vtkImplicitBoolean::New();
>>>   clip->SetInput(connections->GetOutput() );
>>>   clip->SetClipFunction(func);
>>>   clip->GenerateClipScalarsOff();
>>>
>>>   for (unsigned int i = 0; i < numRegions; ++i)
>>>   {
>>>       std::cout << "----------- Region Number " << i << "   
>>> ----------" << std::endl;
>>>       clip->SetValue( (float) i );
>>>       clip->Update();
>>>       clip->GetOutput()->PrintSelf(std::cout, 1);
>>>   }
>>>
>>> When the prints go by the number of polys, vertices, cells... are  
>>> all  Zero. Any idea what I am doing wrong?
>>>
>>> I think I am getting confused about the implicit function and  
>>> whether  or not to have GenerateClipScalarsOff or  
>>> GenerateClipScalarsOn.
>>> ---
>>> Mike Jackson
>>> mike _at_ bluequartz dot net
>>>
>>>
>
> I have been working on this problem some more today but am still  
> coming up short.
>
> This is the code that I have now:
>
>   unsigned int numRegions = connections->GetNumberOfExtractedRegions();
>   vtkClipPolyData *clip = vtkClipPolyData::New();
>   clip->SetInput(connections->GetOutput() );
>   clip->InsideOutOn();
>   for (unsigned int i = 0; i < 5; ++i)
>   {
>       std::cout << "----------- Region Number " << i << "   
> ----------" << std::endl;
>       clip->SetValue( (float) i );
>       clip->Update();
>
>       clip->GetOutput()->PrintSelf(std::cout, 1);
> }
>
> But what happens is the number of polygons just keeps growing with  
> each iteration, eventually on the last iteration, the number of  
> polygons in the clip are the same as the number of original polygons.  
> So I think I am just missing something, could someone please fill me in?
>
>



More information about the vtkusers mailing list