diff --git a/src/aliceVision/depthMap/RefineRc.cpp b/src/aliceVision/depthMap/RefineRc.cpp index e687f79b3a..2f100f45d8 100644 --- a/src/aliceVision/depthMap/RefineRc.cpp +++ b/src/aliceVision/depthMap/RefineRc.cpp @@ -238,7 +238,7 @@ bool RefineRc::refinerc(bool checkIfExists) ALICEVISION_LOG_DEBUG("Refine CUDA (rc: " << (_rc + 1) << " / " << _sp->mp->ncams << ")"); // generate default depthSimMap if rc has no tcam - if(_refineTCams.size() == 0 || _depths == nullptr) + if(_refineTCams.size() == 0 || _depths.empty()) { _depthSimMapOpt = new DepthSimMap(_rc, _sp->mp, 1, 1); return true; diff --git a/src/aliceVision/depthMap/SemiGlobalMatchingParams.cpp b/src/aliceVision/depthMap/SemiGlobalMatchingParams.cpp index d62b4ff07a..ade55a4a6f 100644 --- a/src/aliceVision/depthMap/SemiGlobalMatchingParams.cpp +++ b/src/aliceVision/depthMap/SemiGlobalMatchingParams.cpp @@ -124,7 +124,7 @@ std::string SemiGlobalMatchingParams::getSGM_depthsFileName(IndexT viewId) DepthSimMap* SemiGlobalMatchingParams::getDepthSimMapFromBestIdVal(int w, int h, StaticVector* volumeBestIdVal, int scale, int step, int rc, int zborder, - StaticVector* planesDepths) + const StaticVector& planesDepths) { long tall = clock(); @@ -142,9 +142,9 @@ DepthSimMap* SemiGlobalMatchingParams::getDepthSimMapFromBestIdVal(int w, int h, Pixel pixScale1 = Pixel(pix.x * scale, pix.y * scale); float sim = (*volumeBestIdVal)[y * volDimX + x].value; int fpdepthId = (*volumeBestIdVal)[y * volDimX + x].id; - if((fpdepthId >= zborder) && (fpdepthId < planesDepths->size() - zborder)) + if((fpdepthId >= zborder) && (fpdepthId < planesDepths.size() - zborder)) { - float fpPlaneDepth = (*planesDepths)[fpdepthId]; + float fpPlaneDepth = planesDepths[fpdepthId]; Point3d planen = (mp->iRArr[rc] * Point3d(0.0f, 0.0f, 1.0f)).normalize(); Point3d planep = mp->CArr[rc] + planen * fpPlaneDepth; Point3d v = (mp->iCamArr[rc] * Point2d((float)(pixScale1.x), (float)(pixScale1.y))).normalize(); diff --git a/src/aliceVision/depthMap/SemiGlobalMatchingParams.hpp b/src/aliceVision/depthMap/SemiGlobalMatchingParams.hpp index bef96124f4..ad0d3791c3 100644 --- a/src/aliceVision/depthMap/SemiGlobalMatchingParams.hpp +++ b/src/aliceVision/depthMap/SemiGlobalMatchingParams.hpp @@ -59,7 +59,7 @@ class SemiGlobalMatchingParams ~SemiGlobalMatchingParams(void); DepthSimMap* getDepthSimMapFromBestIdVal(int w, int h, StaticVector* volumeBestIdVal, int scale, - int step, int rc, int zborder, StaticVector* planesDepths); + int step, int rc, int zborder, const StaticVector& planesDepths); std::string getREFINE_photo_depthMapFileName(IndexT viewId, int scale, int step); std::string getREFINE_photo_simMapFileName(IndexT viewId, int scale, int step); diff --git a/src/aliceVision/depthMap/SemiGlobalMatchingRc.cpp b/src/aliceVision/depthMap/SemiGlobalMatchingRc.cpp index 80075445af..6444bac177 100644 --- a/src/aliceVision/depthMap/SemiGlobalMatchingRc.cpp +++ b/src/aliceVision/depthMap/SemiGlobalMatchingRc.cpp @@ -48,20 +48,19 @@ SemiGlobalMatchingRc::SemiGlobalMatchingRc(int rc, int scale, int step, SemiGlob SemiGlobalMatchingRc::~SemiGlobalMatchingRc() { delete _volumeBestIdVal; - delete _depths; } bool SemiGlobalMatchingRc::selectBestDepthsRange(int nDepthsThr, StaticVector* rcSeedsDistsAsc) { - if(_depths->size() <= nDepthsThr) + if(_depths.size() <= nDepthsThr) return true; StaticVector votes; - votes.reserve(_depths->size() - nDepthsThr); - for(int i = 0; i < _depths->size() - nDepthsThr; i++) + votes.reserve(_depths.size() - nDepthsThr); + for(int i = 0; i < _depths.size() - nDepthsThr; i++) { - const float d1 = (*_depths)[i]; - const float d2 = (*_depths)[i + nDepthsThr - 1]; + const float d1 = _depths[i]; + const float d2 = _depths[i + nDepthsThr - 1]; int id1 = rcSeedsDistsAsc->indexOfNearestSorted(d1); int id2 = rcSeedsDistsAsc->indexOfNearestSorted(d2); @@ -78,32 +77,31 @@ bool SemiGlobalMatchingRc::selectBestDepthsRange(int nDepthsThr, StaticVector* depthsNew; - depthsNew->reserve(nDepthsThr); + StaticVector depthsNew; + depthsNew.reserve(nDepthsThr); const int id1 = votes.maxValId(); const int id2 = id1 + nDepthsThr - 1; for(int i = id1; i <= id2; i++) - depthsNew->push_back((*_depths)[i]); + depthsNew.push_back(_depths[i]); std::swap(_depths, depthsNew); - delete depthsNew; return true; } bool SemiGlobalMatchingRc::selectBestDepthsRange(int nDepthsThr, StaticVector*>* alldepths) { - if(_depths->size() <= nDepthsThr) + if(_depths.size() <= nDepthsThr) return true; StaticVector votes; - votes.reserve(_depths->size() - nDepthsThr); + votes.reserve(_depths.size() - nDepthsThr); - for(int i = 0; i < _depths->size() - nDepthsThr; i++) + for(int i = 0; i < _depths.size() - nDepthsThr; i++) { - const float d1 = (*_depths)[i]; - const float d2 = (*_depths)[i + nDepthsThr - 1]; + const float d1 = _depths[i]; + const float d2 = _depths[i + nDepthsThr - 1]; float overlap = 0.0f; for(int c = 0; c < alldepths->size(); c++) @@ -117,17 +115,16 @@ bool SemiGlobalMatchingRc::selectBestDepthsRange(int nDepthsThr, StaticVector* depthsNew; - depthsNew->reserve(nDepthsThr); + StaticVector depthsNew; + depthsNew.reserve(nDepthsThr); const int id1 = votes.maxValId(); const int id2 = id1 + nDepthsThr - 1; for(int i = id1; i <= id2; i++) - depthsNew->push_back((*_depths)[i]); + depthsNew.push_back(_depths[i]); std::swap(_depths, depthsNew); - delete depthsNew; return true; } @@ -172,14 +169,14 @@ void SemiGlobalMatchingRc::computeDepths(float minDepth, float maxDepth, StaticV } } - _depths = new StaticVector(); - _depths->reserve(maxNdetphs); + _depths.resize(0); + _depths.reserve(maxNdetphs); { float depth = minDepth; while(depth < maxDepth) { - _depths->push_back(depth); + _depths.push_back(depth); depth += getMinTcStepAtDepth(depth, minDepth, maxDepth, alldepths); } } @@ -238,14 +235,14 @@ void SemiGlobalMatchingRc::computeDepthsTcamsLimits(StaticVectorsize() - 1]; - int id1 = _depths->indexOfNearestSorted(d1); - int id2 = _depths->indexOfNearestSorted(d2); + int id1 = _depths.indexOfNearestSorted(d1); + int id2 = _depths.indexOfNearestSorted(d2); if(id1 == -1) id1 = 0; if(id2 == -1) - id2 = _depths->size() - 1; + id2 = _depths.size() - 1; // clamp to keep only the closest depths if we have too much inputs (> maxDepthsToSweep) id2 = std::min(id1 + _sp->maxDepthsToSweep - 1, id2); @@ -286,9 +283,9 @@ void SemiGlobalMatchingRc::computeDepthsAndResetTCams() { std::string fn = _sp->mp->getDepthMapsFolder() + std::to_string(_sp->mp->getViewId(_rc)) + "depthsAll.txt"; FILE* f = fopen(fn.c_str(), "w"); - for(int j = 0; j < _depths->size(); j++) + for(int j = 0; j < _depths.size(); j++) { - float depth = (*_depths)[j]; + float depth = _depths[j]; fprintf(f, "%f\n", depth); } fclose(f); @@ -326,9 +323,9 @@ void SemiGlobalMatchingRc::computeDepthsAndResetTCams() { std::string fn = _sp->mp->getDepthMapsFolder() + std::to_string(_sp->mp->getViewId(_rc)) + "depthsAll.txt"; FILE* f = fopen(fn.c_str(), "w"); - for(int j = 0; j < _depths->size(); j++) + for(int j = 0; j < _depths.size(); j++) { - float depth = (*_depths)[j]; + float depth = _depths[j]; fprintf(f, "%f\n", depth); } fclose(f); @@ -358,9 +355,9 @@ void SemiGlobalMatchingRc::computeDepthsAndResetTCams() { std::string fn = _sp->mp->getDepthMapsFolder() + std::to_string(_sp->mp->getViewId(_rc)) + "depths.txt"; FILE* f = fopen(fn.c_str(), "w"); - for(int j = 0; j < _depths->size(); j++) + for(int j = 0; j < _depths.size(); j++) { - float depth = (*_depths)[j]; + float depth = _depths[j]; fprintf(f, "%f\n", depth); } fclose(f); @@ -401,7 +398,7 @@ void SemiGlobalMatchingRc::computeDepthsAndResetTCams() } if(_sp->mp->verbose) - ALICEVISION_LOG_DEBUG("rc depths: " << _depths->size()); + ALICEVISION_LOG_DEBUG("rc depths: " << _depths.size()); deleteArrayOfArrays(&alldepths); } @@ -412,7 +409,7 @@ void SemiGlobalMatchingRc::getSubDepthsForTCam( int tcamid, std::vector& for(int i = 0; i<_depthsTcamsLimits[tcamid].y; i++ ) { - out[i] = (*_depths)[_depthsTcamsLimits[tcamid].x + i]; + out[i] = _depths[_depthsTcamsLimits[tcamid].x + i]; } } @@ -436,7 +433,7 @@ bool SemiGlobalMatchingRc::sgmrc(bool checkIfExists) const int volDimX = _width; const int volDimY = _height; - const int volDimZ = _depths->size(); + const int volDimZ = _depths.size(); float volumeMBinGPUMem = 0.0f; StaticVector* simVolume = nullptr; @@ -483,8 +480,8 @@ bool SemiGlobalMatchingRc::sgmrc(bool checkIfExists) if(_sp->exportIntermediateResults) { - svol->exportVolumeStep(*_depths, _rc, _scale, _step, _sp->mp->getDepthMapsFolder() + std::to_string(_sp->mp->getViewId(_rc)) + "_vol_afterReduction.abc"); - svol->export9PCSV(*_depths, _rc, _scale, _step, "afterReduction", _sp->mp->getDepthMapsFolder() + std::to_string(_sp->mp->getViewId(_rc)) + "_9p.csv"); + svol->exportVolumeStep(_depths, _rc, _scale, _step, _sp->mp->getDepthMapsFolder() + std::to_string(_sp->mp->getViewId(_rc)) + "_vol_afterReduction.abc"); + svol->export9PCSV(_depths, _rc, _scale, _step, "afterReduction", _sp->mp->getDepthMapsFolder() + std::to_string(_sp->mp->getViewId(_rc)) + "_9p.csv"); } // filter on the 3D volume to weight voxels based on their neighborhood strongness. @@ -496,8 +493,8 @@ bool SemiGlobalMatchingRc::sgmrc(bool checkIfExists) if(_sp->exportIntermediateResults) { - svol->exportVolumeStep(*_depths, _rc, _scale, _step, _sp->mp->getDepthMapsFolder() + std::to_string(_sp->mp->getViewId(_rc)) + "_vol_afterFiltering.abc"); - svol->export9PCSV(*_depths, _rc, _scale, _step, "afterFiltering", _sp->mp->getDepthMapsFolder() + std::to_string(_sp->mp->getViewId(_rc)) + "_9p.csv"); + svol->exportVolumeStep(_depths, _rc, _scale, _step, _sp->mp->getDepthMapsFolder() + std::to_string(_sp->mp->getViewId(_rc)) + "_vol_afterFiltering.abc"); + svol->export9PCSV(_depths, _rc, _scale, _step, "afterFiltering", _sp->mp->getDepthMapsFolder() + std::to_string(_sp->mp->getViewId(_rc)) + "_9p.csv"); } // for each pixel: choose the voxel with the minimal similarity value diff --git a/src/aliceVision/depthMap/SemiGlobalMatchingRc.hpp b/src/aliceVision/depthMap/SemiGlobalMatchingRc.hpp index 12226b6ff2..e1bf1d1578 100644 --- a/src/aliceVision/depthMap/SemiGlobalMatchingRc.hpp +++ b/src/aliceVision/depthMap/SemiGlobalMatchingRc.hpp @@ -36,7 +36,7 @@ class SemiGlobalMatchingRc StaticVector _sgmTCams; StaticVector _depthsTcamsLimits; StaticVector* _volumeBestIdVal = nullptr; - StaticVector* _depths = nullptr; + StaticVector _depths; SemiGlobalMatchingParams* _sp;