Skip to content
Snippets Groups Projects
Commit 9dbd662d authored by Luc Hermitte's avatar Luc Hermitte
Browse files

REFACT: Change new/delete to vectors

-> more robust toward memory leaks
parent 7a6cca26
No related branches found
No related tags found
1 merge request!1Resolve "Adapt DiapOTB SARCartesianMeanEstimation to keep shadows"
......@@ -855,7 +855,8 @@ SARDEMPolygonsAnalysisImageFilter< TImageIn, TImageOut, TImageDEM, TImageSAR, TF
// Allocate outValueTab (size = nbCol)
ImageOutPixelType *outValueTab = new ImageOutPixelType[nbCol];
// ImageOutPixelType *outValueTab = new ImageOutPixelType[nbCol];
std::vector<ImageOutPixelType> outValueTab(nbCol);
// Allocate Vectors for polygon storage (vector of vectors to separate line and colunm of polygon into DEM)
std::vector<std::vector<ImageInPixelType> * > Polygon_SideInUp_Vec;
......@@ -877,16 +878,14 @@ SARDEMPolygonsAnalysisImageFilter< TImageIn, TImageOut, TImageDEM, TImageSAR, TF
InputIterator InIt_LL(this->GetInput(), inputRegionForThread);
// Allocate Vectors for polygon storage for this line of DEM
std::vector<ImageInPixelType> * Polygon_SideInUp_VecLine = new std::vector<ImageInPixelType>[nbDEMLines];
std::vector<ImageInPixelType> * Polygon_SideInDown_VecLine = new std::vector<ImageInPixelType>[nbDEMLines];
std::vector<ImageInPixelType> * Polygon_SideOutUp_VecLine = new std::vector<ImageInPixelType>[nbDEMLines];
std::vector<ImageInPixelType> * Polygon_SideOutDown_VecLine = new std::vector<ImageInPixelType>[nbDEMLines];
std::vector<std::vector<ImageInPixelType>> Polygon_SideInUp_VecLine(nbDEMLines);
std::vector<std::vector<ImageInPixelType>> Polygon_SideInDown_VecLine(nbDEMLines);
std::vector<std::vector<ImageInPixelType>> Polygon_SideOutUp_VecLine(nbDEMLines);
std::vector<std::vector<ImageInPixelType>> Polygon_SideOutDown_VecLine(nbDEMLines);
// Pixel of otb::VectorImage (input) : 4 Components : C, L, Z and Y
int i_InSideUp, i_InSideDown, i_OutSideUp, i_OutSideDown;
InputIterator * tabInIt [4];
tabInIt[0] = &InIt_UL;
tabInIt[1] = &InIt_UR;
......@@ -916,7 +915,7 @@ SARDEMPolygonsAnalysisImageFilter< TImageIn, TImageOut, TImageDEM, TImageSAR, TF
}
// Initialize outValueTab
m_FunctionOnPolygon->initalize(nbCol, outValueTab, threadId);
m_FunctionOnPolygon->initalize(nbCol, outValueTab.data(), threadId);
// Loop on Line into SAR Geometry
for (int ind_Line_Into_SARGeo = ind_Line_start; ind_Line_Into_SARGeo < ind_Line_end;
......@@ -1027,7 +1026,7 @@ SARDEMPolygonsAnalysisImageFilter< TImageIn, TImageOut, TImageDEM, TImageSAR, TF
///////////////////////////// Scan of all selected polygons to extract wanted data //////////////
this->PolygonsScan(ind_Line_Into_SARGeo, &Polygon_SideInUp_Vec,
&Polygon_SideInDown_Vec, &Polygon_SideOutUp_Vec,
&Polygon_SideOutDown_Vec, firstCol, nbCol, outValueTab, threadId);
&Polygon_SideOutDown_Vec, firstCol, nbCol, outValueTab.data(), threadId);
// Clear Vectors
for (unsigned int k = 0; k < nbDEMLines; k++)
......@@ -1046,7 +1045,7 @@ SARDEMPolygonsAnalysisImageFilter< TImageIn, TImageOut, TImageDEM, TImageSAR, TF
} // End Loop on Line into SAR Geometry
// After the scan : Synthetize results
m_FunctionOnPolygon->synthetize(nbCol, outValueTab, threadId);
m_FunctionOnPolygon->synthetize(nbCol, outValueTab.data(), threadId);
// Assignate the output with the contribution of the current polygons
int counter = 0;
......@@ -1064,15 +1063,8 @@ SARDEMPolygonsAnalysisImageFilter< TImageIn, TImageOut, TImageDEM, TImageSAR, TF
} // End lines (Main output)
delete [] Polygon_SideInUp_VecLine;
delete [] Polygon_SideInDown_VecLine;
delete [] Polygon_SideOutUp_VecLine;
delete [] Polygon_SideOutDown_VecLine;
delete [] outValueTab;
}
} /*namespace otb*/
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment