[vtkusers] Memory leaks

janavas josenavasmolina at hotmail.com
Mon Dec 12 03:59:08 EST 2011


Hi Alex,

Thank you for your answer. I've been working in your solution but I don't
achieve what I want.

Here is my code (I did a lot of changes):

void Model::generateLungs(double isoValue, bool decimation, bool connected,
bool smooth,  QStatusBar *statusBar)
{

	cout << ": Console::GenerateLungs starts..." << endl;
	isoValue = isoValue + 1;

	if (mLungsActor == NULL ) mLungsActor = vtkSmartPointer<vtkActor>::New();
	if (mapperLungs == NULL ) mapperLungs = vtkPolyDataMapper::New();
	if (normalsLungs == NULL ) normalsLungs = vtkPolyDataNormals::New();
	if (smoothLungs == NULL ) smoothLungs = vtkSmoothPolyDataFilter::New();
	if (connectivityLungs == NULL ) connectivityLungs =
vtkPolyDataConnectivityFilter::New();
	if (triangleFilterLungs == NULL ) triangleFilterLungs =
vtkTriangleFilter::New();
	if (marchingCubesLungs == NULL ) marchingCubesLungs =
vtkMarchingCubes::New();
	
	cout << "Marching cubes " << endl;
	marchingCubesLungs->SetInput(mWashedDataLungs);
	marchingCubesLungs->SetValue(0, isoValue);
	marchingCubesLungs->ComputeScalarsOn();
	marchingCubesLungs->Update();

	cout << "Triangle filter " << endl;
	triangleFilterLungs->SetInputConnection(
marchingCubesLungs->GetOutputPort() );
	triangleFilterLungs->Update();

	if(connected)
	{
		cout << "Connectivity filter " << endl;
		connectivityLungs->SetInputConnection(
triangleFilterLungs->GetOutputPort() );
		connectivityLungs->SetExtractionModeToLargestRegion();
		connectivityLungs->Update();
	}
	if(smooth)
	{
		cout << "Smooth filter " << endl;
		if(connected) smoothLungs->SetInputConnection(
connectivityLungs->GetOutputPort());
		else
smoothLungs->SetInputConnection(triangleFilterLungs->GetOutputPort());
		smoothLungs->SetNumberOfIterations(100);
		smoothLungs->Update();
	}

	cout << "Normals filter " << endl;

	if(smooth) normalsLungs->SetInputConnection( smoothLungs->GetOutputPort()
);
	else if (connected) normalsLungs->SetInputConnection(
connectivityLungs->GetOutputPort() );
	else normalsLungs->SetInputConnection( triangleFilterLungs->GetOutputPort()
);
	normalsLungs->FlipNormalsOn();
	normalsLungs->Update();

	mLungsMesh = normalsLungs->GetOutput();

	mapperLungs->SetInput(mLungsMesh);
	mapperLungs->ScalarVisibilityOff();

	mLungsActor->SetMapper(mapperLungs);

	mLungsActor->GetProperty()->SetDiffuseColor(
	  Settings::getHandle().mLungsDiffuseColor.red()/255.,
	  Settings::getHandle().mLungsDiffuseColor.green()/255.,
	  Settings::getHandle().mLungsDiffuseColor.blue()/255.);
	mLungsActor->GetProperty()->SetSpecular(0.0);
	mLungsActor->GetProperty()->SetSpecularPower(0);
	mLungsActor->GetProperty()->SetAmbient(0.2);

mLungsActor->GetProperty()->SetOpacity(Settings::getHandle().mLungsOpacity);
	mLungsActor->SetVisibility(true);

	std::cout << ": Lungs generation finished." << std::endl;
}

What I want to do is free the memory allocated for vtkMarchingCubes,
vtkTriangleFilter, vtkPolyDataConnectivityFilter, vtkSmoothPolyDataFilter
and vtkPolyDataNormals.

I tried to do this:

mLungsMesh = normalsLungs->GetOutput();

mLungsMesh->Register(NULL);
mLungsMesh->SetSource(NULL);

normalsLungs->Delete();

but it doesn't works, when I try to render the mesh it seems that nothing
was generated. If I tried to use ReleaseDataFlagOn the result is the same.

Any other idea??

Thank you

Jose

--
View this message in context: http://vtk.1045678.n5.nabble.com/Memory-leaks-tp5037946p5067658.html
Sent from the VTK - Users mailing list archive at Nabble.com.



More information about the vtkusers mailing list