[vtkusers] Connected Components

Michael Jackson mike.jackson at bluequartz.net
Mon Nov 24 09:44:41 EST 2008


First off you need a matching con->Delete() for the  
vtkPolyDataConnectivityFilter * con =  
vtkPolyDataConnectivityFilter::New(); function otherwise you are  
leaking that filter object.

Next, I bet this takes a really long time to run because for 10,000  
components, you have to run the same filter 10,000 times. How about  
this filter instead:

//Find all the discrete components
vtkSmartPointer<DiscreteParticleFilter> connectivity =  
vtkSmartPointer<DiscreteParticleFilter>::New();
connectivity->SetInput( mc->GetOutput() );
connectivity->Update(); //Force the pipeline to execute ...
vtkPolyData* currentComponent = NULL;
vtkPolyDataCollection* components = connectivity->GetPolyRegions();
components->InitTraversal(); //Init the enumeration
int count = components->GetNumberOfItems();

//Iterate over each PolyLoop and decide how to triangulate it
for (int i = 0; i < count; ++i) {
   currentComponent = components->GetNextItem();
   // Add Mapper and Actor code from below
	vtkPolyDataMapper *polymap;
	vtkActor * polyact;
	
	//std::cout<<connect->GetOutput()->GetNumberOfCells()<<std::endl;
		
	polymap = vtkPolyDataMapper::New();
	polymap->SetInput(currentComponent);
	polyact = vtkActor::New();
	polyact->SetMapper(polymap);
	renderer->AddActor(polyact);
	
	vtkBoxWidget *boxWidget = vtkBoxWidget::New();
	boxWidget->SetInteractor(iren);
	boxWidget->SetPlaceFactor(1);
	boxWidget->SetProp3D(polyact);
	boxWidget->PlaceWidget();
	boxWidget->SetOutlineFaceWires(1);
	boxWidget->SetScalingEnabled(0);
	boxWidget->SetRotationEnabled(1);
	boxWidget->OutlineFaceWiresOff();
	boxWidget->OutlineCursorWiresOff();
	boxWidget->HandlesOff();
	boxWidget->On();

	vtkMyCallback *callback = vtkMyCallback::New();
	boxWidget->AddObserver(vtkCommand::InteractionEvent, callback);
}

I am attaching the source files.

_________________________________________________________
Mike Jackson                  mike.jackson at bluequartz.net
BlueQuartz Software                    www.bluequartz.net
Principal Software Engineer                  Dayton, Ohio

-------------- next part --------------
A non-text attachment was scrubbed...
Name: DiscreteParticleFilter.cpp
Type: application/octet-stream
Size: 11763 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081124/cc792499/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DiscreteParticleFilter.h
Type: application/octet-stream
Size: 6957 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20081124/cc792499/attachment-0001.obj>
-------------- next part --------------


On Nov 24, 2008, at 9:13 AM, prabhat246 wrote:

>
> Hi,
>
> I have a object containing large no. of multiple connected  
> components(say
> 10,000). I want to be able to transform each component seperately.   
> I am
> doing it in following way.
>
> for(int i = 0; i< NoOfRegions; i++)
> 	{
> 	vtkPolyDataConnectivityFilter * con =  
> vtkPolyDataConnectivityFilter::New();
> 	con->SetInput(mc->GetOutput());
> 	con->SetExtractionModeToSpecifiedRegions();
> 	con->AddSpecifiedRegion(i);
> 	connect->Update();
>
> 	vtkPolyDataMapper *polymap;
> 	vtkActor * polyact;
> 	
> 	//std::cout<<connect->GetOutput()->GetNumberOfCells()<<std::endl;
> 		
> 	polymap = vtkPolyDataMapper::New();
> 	polymap->SetInput(con->GetOutput());
> 	polyact = vtkActor::New();
> 	polyact->SetMapper(polymap);
> 	renderer->AddActor(polyact);
> 	
> 	vtkBoxWidget *boxWidget = vtkBoxWidget::New();
> 	boxWidget->SetInteractor(iren);
> 	boxWidget->SetPlaceFactor(1);
> 	boxWidget->SetProp3D(polyact);
> 	boxWidget->PlaceWidget();
> 	boxWidget->SetOutlineFaceWires(1);
> 	boxWidget->SetScalingEnabled(0);
> 	boxWidget->SetRotationEnabled(1);
> 	boxWidget->OutlineFaceWiresOff();
> 	boxWidget->OutlineCursorWiresOff();
> 	boxWidget->HandlesOff();
> 	boxWidget->On();
>
> 	vtkMyCallback *callback = vtkMyCallback::New();
> 	boxWidget->AddObserver(vtkCommand::InteractionEvent, callback);
> 	}
>
>
> But It runs successfully if I have less no. of components say 10 but  
> it
> crashes on large no of componenets.. I feel that It is due to memory  
> crash.
> Of course all these objects inside loop are not being deleted.
>
> is there anything that can be avoided to save memory?? or Is there  
> any other
> lighter way to do this???
> Please help me out.
>
> Thanks a lot
> Prabhat Kumar Gupta
>
> -- 
> View this message in context: http://www.nabble.com/Connected-Components-tp20661092p20661092.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
>
> _______________________________________________
> 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