From 27a1b6442b51941cfea051cc90882980dd956fd9 Mon Sep 17 00:00:00 2001 From: Abdelrahman AL MAROUK Date: Mon, 18 Mar 2024 15:27:27 +0100 Subject: [PATCH] [filterSfM] update code to follow latest merges --- src/software/pipeline/main_filterSfM.cpp | 43 +++++++++---------- .../pipeline/main_prepareDenseScene.cpp | 18 ++++---- 2 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/software/pipeline/main_filterSfM.cpp b/src/software/pipeline/main_filterSfM.cpp index be88b0bc93..230a0809c0 100644 --- a/src/software/pipeline/main_filterSfM.cpp +++ b/src/software/pipeline/main_filterSfM.cpp @@ -165,7 +165,7 @@ struct ObservationsAdaptator inline size_t kdtree_get_point_count() const { return _data.size(); } // Returns the dim'th component of the idx'th point in the class: - inline T kdtree_get_pt(const size_t idx, int dim) const { return _data[idx].x(dim); } + inline T kdtree_get_pt(const size_t idx, int dim) const { return _data[idx].getCoordinates()(dim); } // Optional bounding-box computation: return false to default to a standard bbox computation loop. // Return true if the BBOX was already computed by the class and returned in "bb" so it can be avoided to redo it @@ -353,7 +353,7 @@ ObservationsPerView getObservationsPerViews(SfMData& sfmData) ObservationsPerView observationsPerView; for(auto& landIt : sfmData.getLandmarks()) { - for(const auto& obsIt : landIt.second.observations) + for(const auto& obsIt : landIt.second.getObservations()) { IndexT viewId = obsIt.first; auto& landmarksSet = observationsPerView[viewId]; @@ -376,7 +376,7 @@ void filterLandmarks_step1(SfMData& sfmData, ALICEVISION_LOG_INFO("Removing landmarks having an insufficient number of observations: started."); for(auto& it : sfmData.getLandmarks()) { - if(it.second.observations.size() < params.minNbObservationsPerLandmark) + if (it.second.getObservations().size() < params.minNbObservationsPerLandmark) continue; landmarksData[i++] = it.second; } @@ -415,10 +415,10 @@ void filterLandmarks_step2(SfMData& sfmData, for(auto i = 0; i < landmarksData.size(); i++) { const sfmData::Landmark& landmark = landmarksData[i]; - const auto& nbObservations = landmark.observations.size(); + const auto& nbObservations = landmark.getObservations().size(); auto& [viewIds, neighbors] = viewData[i]; viewIds.reserve(nbObservations); - for(const auto& observationPair : landmark.observations) + for (const auto& observationPair : landmark.getObservations()) { const IndexT viewId = observationPair.first; viewIds.push_back(viewId); @@ -504,12 +504,12 @@ void filterLandmarks_step3(SfMData& sfmData, // compute landmark pixSize double pixSize = 0.; int n = 0; - for(const auto& observationPair : landmark.observations) + for (const auto& observationPair : landmark.getObservations()) { const IndexT viewId = observationPair.first; pixSize += mp.getCamPixelSize(Point3d(landmark.X.x(), landmark.X.y(), landmark.X.z()), mp.getIndexFromViewId(viewId), - params.useFeatureScale ? observationPair.second.scale : 1); + params.useFeatureScale ? observationPair.second.getScale() : 1); n++; } pixSize /= n; @@ -594,13 +594,13 @@ void computeInitialObservationScores(SfMData& sfmData, std::vector& l const sfmData::Landmark& landmark = *landmarksData[i]; // compute observation scores - const auto& nbObservations = landmark.observations.size(); + const auto& nbObservations = landmark.getObservations().size(); auto& [viewIds, viewScores] = viewScoresData[i]; viewIds.reserve(nbObservations); viewScores.reserve(nbObservations); // accumulator for normalizing the scores double total = 0.; - for(const auto& observationPair : landmark.observations) + for (const auto& observationPair : landmark.getObservations()) { const IndexT viewId = observationPair.first; const sfmData::View& view = *(sfmData.getViews().at(viewId)); @@ -869,7 +869,7 @@ void removeNonObservedLandmarks(SfMData& sfmData) const auto& initialNbLandmarks = sfmData.getLandmarks().size(); for(auto it = sfmData.getLandmarks().begin(); it != sfmData.getLandmarks().end();) { - if(it->second.observations.size() == 0) + if (it->second.getObservations().size() == 0) it = sfmData.getLandmarks().erase(it); else ++it; @@ -920,14 +920,13 @@ bool filterObservations3D(SfMData& sfmData, const FilterParams::FilterObservatio // keep only observations with best scores Observations filteredObservations; - size_t maxNbObservationsPerLandmark = - std::min(static_cast(params.maxNbObservationsPerLandmark), landmark.observations.size()); + size_t maxNbObservationsPerLandmark = std::min(static_cast(params.maxNbObservationsPerLandmark), landmark.getObservations().size()); for(auto j = 0; j < maxNbObservationsPerLandmark; j++) { // add observation only if it's an original observation and not augmented const auto& viewId = viewIds[idx[j]]; - const auto& obsIt = landmark.observations.find(viewId); - if(obsIt != landmark.observations.end()) + const auto& obsIt = landmark.getObservations().find(viewId); + if (obsIt != landmark.getObservations().end()) filteredObservations[viewId] = obsIt->second; else if (params.observationsPropagationKeep) { @@ -939,7 +938,7 @@ bool filterObservations3D(SfMData& sfmData, const FilterParams::FilterObservatio filteredObservations[viewId] = Observation(x, UndefinedIndexT, 0.0); } } - landmark.observations = std::move(filteredObservations); + landmark.getObservations() = std::move(filteredObservations); } ALICEVISION_LOG_INFO("Selecting observations with best scores: done"); @@ -970,7 +969,7 @@ double filter2DView(SfMData& sfmData, const FilterParams::FilterObservations2DPa std::vector distances_(nbNeighbors_); KnnNonZeroSearch resultSet(nbNeighbors_); resultSet.init(&indices_[0], &distances_[0]); - tree.findNeighbors(resultSet, obs.x.data()); + tree.findNeighbors(resultSet, obs.getCoordinates().data()); const auto& nbFound = resultSet.size(); if(nbFound == 0) continue; @@ -1023,7 +1022,7 @@ double filter2DView(SfMData& sfmData, const FilterParams::FilterObservations2DPa } bool filterObservations2D(SfMData& sfmData, const FilterParams::FilterObservations2DParams& params, - HashMap& estimatedRadii) + std::map& estimatedRadii) { std::set viewIds = sfmData.getValidViews(); std::vector estimatedRadii_(viewIds.size(), -1.); @@ -1046,7 +1045,7 @@ bool filterObservations2D(SfMData& sfmData, const FilterParams::FilterObservatio // clear and update landmark observations for(auto& landmark : sfmData.getLandmarks()) { - landmark.second.observations.clear(); + landmark.second.getObservations().clear(); } for(int i = 0; i < viewIds.size(); ++i) { @@ -1064,7 +1063,7 @@ bool filterObservations2D(SfMData& sfmData, const FilterParams::FilterObservatio auto& landmarks = observationsIt->second.second; for(int j = 0; j < observations.size(); j++) { - landmarks[j]->observations[viewId] = observations[j]; + landmarks[j]->getObservations()[viewId] = observations[j]; } } } @@ -1163,7 +1162,7 @@ int aliceVision_main(int argc, char *argv[]) // Read the input SfM scene SfMData sfmData; - if(!sfmDataIO::Load(sfmData, inputSfmFilename, sfmDataIO::ESfMData::ALL)) + if(!sfmDataIO::load(sfmData, inputSfmFilename, sfmDataIO::ESfMData::ALL)) { ALICEVISION_LOG_ERROR("The input SfMData file '" << inputSfmFilename << "' cannot be read."); return EXIT_FAILURE; @@ -1188,7 +1187,7 @@ int aliceVision_main(int argc, char *argv[]) if(params.filterObservations2D.enabled) { - HashMap estimatedRadii; + std::map estimatedRadii; ALICEVISION_LOG_INFO("Filtering observations in 2D: started."); filterObservations2D(sfmData, params.filterObservations2D, estimatedRadii); ALICEVISION_LOG_INFO("Filtering observations in 2D: done."); @@ -1206,7 +1205,7 @@ int aliceVision_main(int argc, char *argv[]) } } - sfmDataIO::Save(sfmData, outputSfmFilename, sfmDataIO::ESfMData::ALL); + sfmDataIO::save(sfmData, outputSfmFilename, sfmDataIO::ESfMData::ALL); return EXIT_SUCCESS; } diff --git a/src/software/pipeline/main_prepareDenseScene.cpp b/src/software/pipeline/main_prepareDenseScene.cpp index 2e1daed7e2..8a735468c6 100644 --- a/src/software/pipeline/main_prepareDenseScene.cpp +++ b/src/software/pipeline/main_prepareDenseScene.cpp @@ -95,7 +95,7 @@ ObservationsPerView getObservationsPerViews(const SfMData& sfmData) ObservationsPerView observationsPerView; for(auto& landIt : sfmData.getLandmarks()) { - for(const auto& obsIt : landIt.second.observations) + for (const auto& obsIt : landIt.second.getObservations()) { IndexT viewId = obsIt.first; auto& observationsSet = observationsPerView[viewId]; @@ -155,7 +155,7 @@ bool prepareDenseScene(const SfMData& sfmData, bool doMaskLandmarks = landmarksMaskScale > 0.f; ObservationsPerView observationsPerView; - HashMap estimatedRadii; + std::map estimatedRadii; if (doMaskLandmarks) { observationsPerView = std::move(getObservationsPerViews(sfmData)); @@ -334,11 +334,13 @@ bool prepareDenseScene(const SfMData& sfmData, for(const auto& observation : observations) { const auto& obs = *observation; - for(int y = std::max(obs.x.y() - r, 0.); - y <= std::min(obs.x.y() + r, (double)maskLandmarks.Height() - 1); y++) + for (int y = std::max(obs.getCoordinates().y() - r, 0.); + y <= std::min(obs.getCoordinates().y() + r, (double)maskLandmarks.height() - 1); + y++) { - for(int x = std::max(obs.x.x() - r, 0.); - x <= std::min(obs.x.x() + r, (double)maskLandmarks.Width() - 1); x++) + for (int x = std::max(obs.getCoordinates().x() - r, 0.); + x <= std::min(obs.getCoordinates().x() + r, (double)maskLandmarks.width() - 1); + x++) { maskLandmarks(y, x) = std::numeric_limits::max(); } @@ -356,13 +358,13 @@ bool prepareDenseScene(const SfMData& sfmData, dstColorImage, cam, metadata, srcImage, evCorrection, exposureCompensation, [&maskLoaded, &mask, &maskLandmarks, &doMaskLandmarks](Image& image) { - if(maskLoaded && (image.Width() * image.Height() != mask.Width() * mask.Height())) + if(maskLoaded && (image.width() * image.height() != mask.width() * mask.height())) { ALICEVISION_LOG_WARNING("Invalid image mask size: mask is ignored."); return; } - for(int pix = 0; pix < image.Width() * image.Height(); ++pix) + for(int pix = 0; pix < image.width() * image.height(); ++pix) { image(pix).a() = (maskLoaded && mask(pix) == 0) ? 0.f : (doMaskLandmarks && maskLandmarks(pix) == 127) ? .5f : 1.f; }