Skip to content

Commit

Permalink
[mesh] Texturing: code cleaning & setting param default value
Browse files Browse the repository at this point in the history
code cleaning + setting multiBandDownscale default value to 4 + renaming ImagesCache::ImgPtr to ImagesCache::ImgSharedPtr
  • Loading branch information
cvere committed Jun 13, 2019
1 parent 850ca7a commit 118ed54
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/aliceVision/depthMap/cuda/PlaneSweepingCuda.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
namespace aliceVision {
namespace depthMap {

inline const uchar4 get( mvsUtils::ImagesCache::ImgPtr img, int x, int y )
inline const uchar4 get( mvsUtils::ImagesCache::ImgSharedPtr img, int x, int y )
{
const Color floatRGB = img->at(x,y) * 255.0f;

Expand Down Expand Up @@ -137,7 +137,7 @@ void cps_fillCameraData(mvsUtils::ImagesCache* ic, cameraStruct* cam, int c, mvs
// cam->tex_hmh_g->getBuffer(),
// cam->tex_hmh_b->getBuffer(), mp->indexes[c], mp, true, 1, 0);

mvsUtils::ImagesCache::ImgPtr img = ic->getImg_sync(c);
mvsUtils::ImagesCache::ImgSharedPtr img = ic->getImg_sync(c);

Pixel pix;
{
Expand Down
25 changes: 12 additions & 13 deletions src/aliceVision/mesh/Texturing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,17 @@ void Texturing::generateUVsBasicMethod(mvsUtils::MultiViewParams& mp)
void Texturing::generateTextures(const mvsUtils::MultiViewParams &mp,
const boost::filesystem::path &outPath, imageIO::EImageFileType textureFileType)
{
ALICEVISION_LOG_INFO("Texturing: Use multiband blending with the following contributions per band:");

texParams.multiBandNbContrib.erase(std::remove(std::begin(texParams.multiBandNbContrib), std::end(texParams.multiBandNbContrib), 0),
std::end(texParams.multiBandNbContrib));
texParams.nbBand = texParams.multiBandNbContrib.size();
// Ensure that contribution levels do not contain 0 and are sorted (as each frequency band contributes to lower bands).
auto& m = texParams.multiBandNbContrib;
m.erase(std::remove(std::begin(m), std::end(m), 0), std::end(m));
texParams.nbBand = m.size();

if(!std::is_sorted(std::begin(texParams.multiBandNbContrib), std::end(texParams.multiBandNbContrib)))
if(!std::is_sorted(std::begin(m), std::end(m)))
{
ALICEVISION_LOG_INFO("Sorting contributions per band (necessary).");
std::sort(std::begin(texParams.multiBandNbContrib), std::end(texParams.multiBandNbContrib));

std::sort(std::begin(m), std::end(m));
}
ALICEVISION_LOG_INFO("Texturing: Use multiband blending with the following contributions per band:");
for(int c: texParams.multiBandNbContrib)
{
ALICEVISION_LOG_INFO(" - " << c);
Expand Down Expand Up @@ -454,10 +453,9 @@ void Texturing::generateTexturesSubSet(const mvsUtils::MultiViewParams& mp,
camContribution[atlasID].resize(texParams.nbBand);
camContribution.at(atlasID)[band].emplace_back(triangleID, triangleScore);

if(contrib + 1 == nbContribLevel)
if(contrib + 1 == texParams.multiBandNbContrib[band])
{
++band;
nbContribLevel = texParams.multiBandNbContrib[band];
}
}
}
Expand All @@ -477,14 +475,14 @@ void Texturing::generateTexturesSubSet(const mvsUtils::MultiViewParams& mp,

if(cameraContributions.empty())
{
ALICEVISION_LOG_INFO("- camera " << camId + 1 << "/" << mp.ncams << " unused.");
ALICEVISION_LOG_INFO("- camera " << mp.getViewId(camId) << " (" << camId + 1 << "/" << mp.ncams << ") unused.");
continue;
}
ALICEVISION_LOG_INFO("- camera " << camId + 1 << "/" << mp.ncams << " with contributions to " << cameraContributions.size() << " texture files:");
ALICEVISION_LOG_INFO("- camera " << mp.getViewId(camId) << " (" << camId + 1 << "/" << mp.ncams << ") with contributions to " << cameraContributions.size() << " texture files:");

//Load camera image from cache
imageCache.refreshData(camId);
mvsUtils::ImagesCache::ImgPtr imgPtr = imageCache.getImg_sync(camId);
mvsUtils::ImagesCache::ImgSharedPtr imgPtr = imageCache.getImg_sync(camId);
const Image& camImg = *imgPtr;

//Calculate laplacianPyramid
Expand Down Expand Up @@ -601,6 +599,7 @@ void Texturing::generateTexturesSubSet(const mvsUtils::MultiViewParams& mp,

#if TEXTURING_MBB_DEBUG
{
// write the number of contribution per atlas frequency bands
for(std::size_t level = 0; level < accuPyramid.pyramid.size(); ++level)
{
AccuImage& atlasLevelTexture = accuPyramid.pyramid[level];
Expand Down
2 changes: 1 addition & 1 deletion src/aliceVision/mesh/Texturing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct TexturingParams
{
bool useScore = true;
unsigned int nbBand = 4;
unsigned int multiBandDownscale = 2;
unsigned int multiBandDownscale = 4;
std::vector<int> multiBandNbContrib = {1, 5, 10, 0}; // number of contributions per frequency band for the multi-band blending

double bestScoreThreshold = 0.0; //< 0.0 to disable filtering based on threshold to relative best score
Expand Down
2 changes: 1 addition & 1 deletion src/aliceVision/mvsUtils/ImagesCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ Color ImagesCache::getPixelValueInterpolated(const Point2d* pix, int camId)
{
// get the image index in the memory
const int i = camIdMapId[camId];
const ImgPtr& img = imgs[i];
const ImgSharedPtr& img = imgs[i];

const int xp = static_cast<int>(pix->x);
const int yp = static_cast<int>(pix->y);
Expand Down
6 changes: 3 additions & 3 deletions src/aliceVision/mvsUtils/ImagesCache.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class ImagesCache
public:
const MultiViewParams* mp;

typedef std::shared_ptr<Image> ImgPtr;
typedef std::shared_ptr<Image> ImgSharedPtr;

private:
ImagesCache(const ImagesCache&) = delete;

int N_PRELOADED_IMAGES;
std::vector<ImgPtr> imgs;
std::vector<ImgSharedPtr> imgs;

std::vector<int> camIdMapId;
std::vector<int> mapIdCamId;
Expand All @@ -50,7 +50,7 @@ class ImagesCache
void setCacheSize(int nbPreload);
~ImagesCache();

inline ImgPtr getImg_sync( int camId )
inline ImgSharedPtr getImg_sync( int camId )
{
refreshData_sync(camId);
const int imageId = camIdMapId[camId];
Expand Down

0 comments on commit 118ed54

Please sign in to comment.