]> Creatis software - creaVtk.git/commitdiff
#3339 creaVtk Bug New Normal - Memory leak CreateMeshFromPoints PolyDataToImageData
authorEduardo DAVILA <davila@localhost.localdomain>
Sun, 12 Jan 2020 21:35:15 +0000 (22:35 +0100)
committerEduardo DAVILA <davila@localhost.localdomain>
Sun, 12 Jan 2020 21:35:15 +0000 (22:35 +0100)
bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkCreateMeshFromPoints.h
bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataToImageData.cxx
bbtk_creaVtk_PKG/src/bbcreaVtkPolyDataToImageData.h

index 4ed177a7ec71d907e1c1931910fe52cd6a93d44c..b141e0257287999a8a218992cb9262b1171750cc 100644 (file)
@@ -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 = " <<bbGetOutputOut() << std::endl;
-
-
-printf("EED CreateMeshFromPoints::Process Start\n");
-
-  
                std::vector<double> lstX                = bbGetInputLstX();
                std::vector<double> lstY                = bbGetInputLstY();
                std::vector<double> lstZ                = bbGetInputLstZ();
                std::vector<int> 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<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
+//                     vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
+                       if (points!=NULL) points->Delete();
+                       points = vtkPoints::New();
                        int i,sizeLstX  =       lstX.size();
                        for (i=0;i<sizeLstX;i++)
                        {
                                points->InsertNextPoint(lstX[i],lstY[i],lstZ[i]);
                        } // for i
-
-                       vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New();
+//                     vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::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<sizeLstIdexes-1;i++)
                        {
-                               sizeSegment1=lstIndexs[i];
-                               sizeSegment2=lstIndexs[i+1];
-
+                               sizeSegment1 = lstIndexs[i];
+                               sizeSegment2 = lstIndexs[i+1];
                                vtkSmartPointer<vtkTriangleStrip> triangleStrip = vtkSmartPointer<vtkTriangleStrip>::New();
                                triangleStrip->GetPointIds()->SetNumberOfIds(sizeSegment1+sizeSegment2);
-
                                maxElements=sizeSegment1;
                                if (maxElements<sizeSegment2) maxElements=sizeSegment2;
-                               maxSegment1=iGeneral+sizeSegment1;
-                               maxSegment2=iGeneral+sizeSegment1+sizeSegment2;
-                               iSeg1=iGeneral;
-                               iSeg2=iGeneral+sizeSegment1;
+                               maxSegment1     = iGeneral+sizeSegment1;
+                               maxSegment2     = iGeneral+sizeSegment1+sizeSegment2;
+                               iSeg1           = iGeneral;
+                               iSeg2           = iGeneral+sizeSegment1;
                                for (ii=0; ii<maxElements; ii++)
                                {
                                        triangleStrip->GetPointIds()->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)
index 1c03523c25811bb9d552e907148e43c01adc5d72..94eda536855fad203a12c246e6420e34a5e5c37c 100644 (file)
@@ -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)
 //===== 
index 2e80837c8b0050c437d8e8262755ee3be7a1a5d1..b5a495f11662c44b6352a6e2548db97ef8bfffbf 100644 (file)
@@ -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 = " <<bbGetOutputOut() << std::endl;
 
-       if ((bbGetInputInPolyData()!=NULL) && (bbGetInputInImage()!=NULL))
+       if ((bbGetInputInPolyData()!=NULL) && (bbGetInputInImage()!=NULL) )
        {
 
 printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .................;\n ");
@@ -64,26 +54,34 @@ printf("EED Warnning!! PolyDataToImageData::Process    Clean this code .........
                int ext[6];
                bbGetInputInImage()->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)
index 91e73cd784fd1dba8a2fcfce283f03a547f2d97b..b5fd4b3bd0926ff74ebb3bde1d423ab072b84fb6 100644 (file)
 
 #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)
 //=====