Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[depthMap] bug fix: use RAII instead of pointers #671

Merged
merged 1 commit into from
Jul 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/aliceVision/depthMap/RefineRc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ DepthSimMap* RefineRc::getDepthPixSizeMapFromSGM()
StaticVector<IdValue> volumeBestIdVal;
volumeBestIdVal.reserve(_width * _height);

for(int i = 0; i < _volumeBestIdVal->size(); i++)
for(int i = 0; i < _volumeBestIdVal.size(); i++)
{
// float sim = (*depthSimMapFinal->dsm)[i].y;
// sim = std::min(sim,mp->simThr);
const float sim = _sp->mp->simThr - 0.0001;
const int id = (*_volumeBestIdVal)[i].id;
const int id = _volumeBestIdVal[i].id;

if(id > 0)
volumeBestIdVal.push_back(IdValue(id, sim));
Expand Down
15 changes: 7 additions & 8 deletions src/aliceVision/depthMap/SemiGlobalMatchingRc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ SemiGlobalMatchingRc::SemiGlobalMatchingRc(int rc, int scale, int step, SemiGlob

SemiGlobalMatchingRc::~SemiGlobalMatchingRc()
{
delete _volumeBestIdVal;
}

bool SemiGlobalMatchingRc::selectBestDepthsRange(int nDepthsThr, StaticVector<float>* rcSeedsDistsAsc)
Expand Down Expand Up @@ -498,7 +497,7 @@ bool SemiGlobalMatchingRc::sgmrc(bool checkIfExists)

// for each pixel: choose the voxel with the minimal similarity value
const int zborder = 2;
_volumeBestIdVal = svol->getOrigVolumeBestIdValFromVolumeStepZ(zborder);
svol->getOrigVolumeBestIdValFromVolumeStepZ(_volumeBestIdVal, zborder);

delete svol;

Expand All @@ -508,8 +507,8 @@ bool SemiGlobalMatchingRc::sgmrc(bool checkIfExists)
{
if((*rcSilhoueteMap)[i])
{
(*_volumeBestIdVal)[i].id = 0;
(*_volumeBestIdVal)[i].value = 1.0f;
_volumeBestIdVal[i].id = 0;
_volumeBestIdVal[i].value = 1.0f;
}
}
delete rcSilhoueteMap;
Expand All @@ -520,13 +519,13 @@ bool SemiGlobalMatchingRc::sgmrc(bool checkIfExists)

if(_sp->exportIntermediateResults)
{
DepthSimMap* depthSimMapFinal = _sp->getDepthSimMapFromBestIdVal(_width, _height, _volumeBestIdVal, _scale, _step, _rc, zborder, _depths);
DepthSimMap* depthSimMapFinal = _sp->getDepthSimMapFromBestIdVal(_width, _height, &_volumeBestIdVal, _scale, _step, _rc, zborder, _depths);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just asking, any chances that it returns a nullptr? In case it would be better to deal with it. Also an assert(depthSimMapFinal) would not kill anyone... ;-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function cannot return null.
The refactoring done here has been started for months now. It's quite close to be merged, but it will be done after the release.
So I would prefer to limit conflicts, as most of these things (like the bug fixed in this PR) are already fixed on the other side.

depthSimMapFinal->saveToImage(_sp->mp->getDepthMapsFolder() + "sgm_" + std::to_string(_sp->mp->getViewId(_rc)) + "_" + "scale" + mvsUtils::num2str(depthSimMapFinal->scale) + "_step" + mvsUtils::num2str(depthSimMapFinal->step) + ".png", 1.0f);
delete depthSimMapFinal;

std::vector<unsigned short> volumeBestId(_volumeBestIdVal->size());
for(int i = 0; i < _volumeBestIdVal->size(); i++)
volumeBestId.at(i) = std::max(0, (*_volumeBestIdVal)[i].id);
std::vector<unsigned short> volumeBestId(_volumeBestIdVal.size());
for(int i = 0; i < _volumeBestIdVal.size(); i++)
volumeBestId.at(i) = std::max(0, _volumeBestIdVal[i].id);

using namespace imageIO;
OutputFileColorSpace colorspace(EImageColorSpace::NO_CONVERSION);
Expand Down
2 changes: 1 addition & 1 deletion src/aliceVision/depthMap/SemiGlobalMatchingRc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SemiGlobalMatchingRc

StaticVector<int> _sgmTCams;
StaticVector<Pixel> _depthsTcamsLimits;
StaticVector<IdValue>* _volumeBestIdVal = nullptr;
StaticVector<IdValue> _volumeBestIdVal;
StaticVector<float> _depths;

SemiGlobalMatchingParams* _sp;
Expand Down
13 changes: 5 additions & 8 deletions src/aliceVision/depthMap/SemiGlobalMatchingVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,15 @@ void SemiGlobalMatchingVolume::SGMoptimizeVolumeStepZ(int rc, int volStepXY, int
mvsUtils::printfElapsedTime(tall, "SemiGlobalMatchingVolume::SGMoptimizeVolumeStepZ");
}

StaticVector<IdValue>* SemiGlobalMatchingVolume::getOrigVolumeBestIdValFromVolumeStepZ(int zborder)
void SemiGlobalMatchingVolume::getOrigVolumeBestIdValFromVolumeStepZ(StaticVector<IdValue>& out_volumeBestIdVal, int zborder)
{
long tall = clock();

StaticVector<IdValue>* volumeBestIdVal = new StaticVector<IdValue>();
volumeBestIdVal->reserve(volDimX * volDimY);
volumeBestIdVal->resize_with(volDimX * volDimY, IdValue(-1, 1.0f));
out_volumeBestIdVal.reserve(volDimX * volDimY);
out_volumeBestIdVal.resize_with(volDimX * volDimY, IdValue(-1, 1.0f));
unsigned char* _volumeStepZPtr = _volumeStepZ->getDataWritable().data();
int* _volumeBestZPtr = _volumeBestZ->getDataWritable().data();
IdValue* volumeBestIdValPtr = volumeBestIdVal->getDataWritable().data();
IdValue* out_volumeBestIdValPtr = out_volumeBestIdVal.getDataWritable().data();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, I'd put an assert and if it is the case deal with the nullptr (but i don't know how the funciton works)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not possible to be null here.

for(int z = zborder; z < volDimZ / volStepZ - zborder; z++)
{
for(int y = 1; y < volDimY - 1; y++)
Expand All @@ -291,7 +290,7 @@ StaticVector<IdValue>* SemiGlobalMatchingVolume::getOrigVolumeBestIdValFromVolum
// value from volumeStepZ converted from (0, 255) to (-1, +1)
float val = (((float)_volumeStepZPtr[volumeIndex]) / 255.0f) * 2.0f - 1.0f;
int bestZ = _volumeBestZPtr[volumeIndex]; // TODO: what is bestZ?
IdValue& idVal = volumeBestIdValPtr[y * volDimX + x];
IdValue& idVal = out_volumeBestIdValPtr[y * volDimX + x];
assert(bestZ >= 0);

if(idVal.id == -1)
Expand All @@ -312,8 +311,6 @@ StaticVector<IdValue>* SemiGlobalMatchingVolume::getOrigVolumeBestIdValFromVolum

if(sp->mp->verbose)
mvsUtils::printfElapsedTime(tall, "SemiGlobalMatchingVolume::getOrigVolumeBestIdValFromVolumeStepZ ");

return volumeBestIdVal;
}

void SemiGlobalMatchingVolume::copyVolume(const StaticVector<unsigned char>* volume, int zFrom, int nZSteps)
Expand Down
2 changes: 1 addition & 1 deletion src/aliceVision/depthMap/SemiGlobalMatchingVolume.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SemiGlobalMatchingVolume
void cloneVolumeSecondStepZ();

void SGMoptimizeVolumeStepZ(int rc, int volStepXY, int volLUX, int volLUY, int scale);
StaticVector<IdValue>* getOrigVolumeBestIdValFromVolumeStepZ(int zborder);
void getOrigVolumeBestIdValFromVolumeStepZ(StaticVector<IdValue>& out_volumeBestIdVal, int zborder);

void exportVolume(StaticVector<float>& depths, int camIndex, int scale, int step, const std::string& filepath) const;
void exportVolumeStep(StaticVector<float>& depths, int camIndex, int scale, int step, const std::string& filepath) const;
Expand Down