From: Eduardo DAVILA Date: Sun, 12 Jan 2020 21:35:15 +0000 (+0100) Subject: #3339 creaVtk Bug New Normal - Memory leak CreateMeshFromPoints PolyDataToImageData X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=644dfd4ee6908a0afac46f4839b518c8f972ecd6;p=creaVtk.git #3339 creaVtk Bug New Normal - Memory leak CreateMeshFromPoints PolyDataToImageData --- diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx index 4ed177a..b141e02 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx @@ -4,12 +4,7 @@ #include "bbcreaVtkCreateMeshFromPoints.h" #include "bbcreaVtkPackage.h" -#include "vtkPoints.h" #include "vtkTriangleStrip.h" -#include "vtkCellArray.h" - -#include "vtkCleanPolyData.h" -#include "vtkTriangleFilter.h" namespace bbcreaVtk { @@ -36,53 +31,44 @@ void CreateMeshFromPoints::Process() // bbSetOutputOut( bbGetInputIn() ); // std::cout << "Output value = " < lstX = bbGetInputLstX(); std::vector lstY = bbGetInputLstY(); std::vector lstZ = bbGetInputLstZ(); std::vector lstIndexs = bbGetInputLstIndexs(); - - if ( (lstIndexs.size()<=1) || (lstX.size()==0) || (lstX.size()!=lstY.size()) || (lstY.size()!=lstZ.size()) ) { printf("Warnning! CreateMeshFromPoints::Process: List of points X Y Z and LstIndexes is not correct\n"); } else { - int ii,sizeSegment1,sizeSegment2; int endSegment; - - vtkSmartPointer points = vtkSmartPointer::New(); +// vtkSmartPointer points = vtkSmartPointer::New(); + if (points!=NULL) points->Delete(); + points = vtkPoints::New(); int i,sizeLstX = lstX.size(); for (i=0;iInsertNextPoint(lstX[i],lstY[i],lstZ[i]); } // for i - - vtkSmartPointer cells = vtkSmartPointer::New(); +// vtkSmartPointer cells = vtkSmartPointer::New(); + if (cells!=NULL) cells->Delete(); + cells = vtkCellArray::New(); int maxElements; int maxSegment1,maxSegment2; int iSeg1,iSeg2; - int iGeneral = 0; int sizeLstIdexes=lstIndexs.size(); for (i=0; i triangleStrip = vtkSmartPointer::New(); triangleStrip->GetPointIds()->SetNumberOfIds(sizeSegment1+sizeSegment2); - maxElements=sizeSegment1; if (maxElementsGetPointIds()->SetId(ii*2 ,iSeg1); @@ -94,28 +80,24 @@ printf("EED CreateMeshFromPoints::Process Start\n"); } // for ii iGeneral=iGeneral+sizeSegment1; cells->InsertNextCell(triangleStrip); - } //for LstIndexs - - vtkPolyData *polydata = vtkPolyData::New(); +// vtkPolyData *polydata = vtkPolyData::New(); + if (polydata!=NULL) polydata->Delete(); + polydata = vtkPolyData::New(); polydata->SetPoints(points); polydata->SetStrips(cells); - - vtkCleanPolyData *clean=vtkCleanPolyData::New(); +// vtkCleanPolyData *clean=vtkCleanPolyData::New(); + if (clean!=NULL) clean->Delete(); + clean = vtkCleanPolyData::New(); clean->SetInputData(polydata); clean->Update(); - - vtkTriangleFilter *triangle = vtkTriangleFilter::New(); +// vtkTriangleFilter *triangle = vtkTriangleFilter::New(); + if (triangle!=NULL) triangle->Delete(); + triangle = vtkTriangleFilter::New(); triangle->SetInputData( clean->GetOutput() ); triangle->Update(); - bbSetOutputOut( clean->GetOutput() ); - }// if listXYZ size - -printf("EED CreateMeshFromPoints::Process End\n"); - - } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) @@ -126,7 +108,11 @@ void CreateMeshFromPoints::bbUserSetDefaultValues() // SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX // Here we initialize the input 'In' to 0 // bbSetInputIn(0); - + points = NULL; + cells = NULL; + polydata = NULL; + clean = NULL; + triangle = NULL; } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.h b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.h index 1c03523..94eda53 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.h +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.h @@ -8,7 +8,11 @@ #include "bbtkAtomicBlackBox.h" #include "iostream" +#include "vtkPoints.h" +#include "vtkCellArray.h" #include "vtkPolyData.h" +#include "vtkCleanPolyData.h" +#include "vtkTriangleFilter.h" namespace bbcreaVtk @@ -29,6 +33,13 @@ class bbcreaVtk_EXPORT CreateMeshFromPoints BBTK_DECLARE_OUTPUT(Out,vtkPolyData*); BBTK_PROCESS(Process); void Process(); + + vtkPoints *points; + vtkCellArray *cells; + vtkPolyData *polydata; + vtkCleanPolyData *clean; + vtkTriangleFilter *triangle; + //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //===== diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataToImageData.cxx b/bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataToImageData.cxx index 2e80837..b5a495f 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataToImageData.cxx +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataToImageData.cxx @@ -4,16 +4,6 @@ #include "bbcreaVtkPolyDataToImageData.h" #include "bbcreaVtkPackage.h" -#include "vtkPolyDataToImageStencil.h" -#include "vtkImageStencil.h" - -#include "vtkCleanPolyData.h" -#include "vtkTriangleFilter.h" - -#include "vtkExtractVOI.h" -#include "vtkExtractVOI.h" - - namespace bbcreaVtk { @@ -41,7 +31,7 @@ void PolyDataToImageData::Process() // bbSetOutputOut( bbGetInputIn() ); // std::cout << "Output value = " <GetExtent( ext ); - vtkCleanPolyData *clean1 = vtkCleanPolyData::New(); +// vtkCleanPolyData *clean1 = vtkCleanPolyData::New(); + if (clean1!=NULL) clean1->Delete(); + clean1 = vtkCleanPolyData::New(); clean1->SetInputData( bbGetInputInPolyData() ); clean1->Update(); vtkTriangleFilter *triangle1 = vtkTriangleFilter::New(); triangle1->SetInputData( clean1->GetOutput() ); triangle1->Update(); - vtkPolyDataToImageStencil *dataToStencil = vtkPolyDataToImageStencil::New(); +// vtkPolyDataToImageStencil *dataToStencil = vtkPolyDataToImageStencil::New(); + if (dataToStencil!=NULL) dataToStencil->Delete(); + dataToStencil = vtkPolyDataToImageStencil::New(); dataToStencil->SetInputData( triangle1->GetOutput() ); dataToStencil->SetOutputWholeExtent( ext ); dataToStencil->Update(); - vtkExtractVOI *extract = vtkExtractVOI::New(); +// vtkExtractVOI *extract = vtkExtractVOI::New(); + if (extract!=NULL) extract->Delete(); + extract = vtkExtractVOI::New(); extract->SetVOI( ext ); extract->SetSampleRate(1, 1, 1); extract->SetInputData( bbGetInputInImage() ); extract->ReleaseDataFlagOff(); extract->Update(); - vtkImageStencil *stencil = vtkImageStencil::New(); +// vtkImageStencil *stencil = vtkImageStencil::New(); + if (stencil!=NULL) stencil->Delete(); + stencil = vtkImageStencil::New(); stencil->SetInputData( extract->GetOutput() ); stencil->Update(); stencil->SetStencilData( dataToStencil->GetOutput() ); @@ -120,8 +118,11 @@ void PolyDataToImageData::bbUserInitializeProcessing() // Here does nothing // but this is where you should allocate the internal/output pointers // if any + clean1 = NULL; + dataToStencil = NULL; + extract = NULL; + stencil = NULL; - } //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) diff --git a/bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataToImageData.h b/bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataToImageData.h index 91e73cd..b5fd4b3 100644 --- a/bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataToImageData.h +++ b/bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataToImageData.h @@ -10,6 +10,12 @@ #include "vtkPolyData.h" #include "vtkImageData.h" +#include "vtkPolyDataToImageStencil.h" +#include "vtkImageStencil.h" +#include "vtkCleanPolyData.h" +#include "vtkTriangleFilter.h" +#include "vtkExtractVOI.h" +#include "vtkExtractVOI.h" namespace bbcreaVtk { @@ -29,6 +35,12 @@ class bbcreaVtk_EXPORT PolyDataToImageData BBTK_DECLARE_OUTPUT(Out,vtkImageData*); BBTK_PROCESS(Process); void Process(); + + vtkCleanPolyData *clean1; + vtkPolyDataToImageStencil *dataToStencil; + vtkExtractVOI *extract; + vtkImageStencil *stencil; + //===== // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) //=====