Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into dev_convertLab
Browse files Browse the repository at this point in the history
  • Loading branch information
cvere committed Jul 4, 2019
2 parents 85e0b58 + be20eac commit 801fcd4
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 108 deletions.
3 changes: 0 additions & 3 deletions src/aliceVision/depthMap/DepthSimMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,6 @@ void DepthSimMap::load(int rc, int fromScale)
imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::depthMap, fromScale), width, height, depthMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);
imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::simMap, fromScale), width, height, simMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);

imageAlgo::transposeImage(width, height, depthMap.getDataWritable());
imageAlgo::transposeImage(width, height, simMap.getDataWritable());

initFromDepthMapTAndSimMapT(&depthMap, &simMap, fromScale);
}

Expand Down
180 changes: 78 additions & 102 deletions src/aliceVision/fuseCut/Fuser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ bool Fuser::updateInSurr(int pixSizeBall, int pixSizeBallWSP, Point3d& p, int rc

int d = pixSizeBall;

float sim = (*simMap)[cell.x * h + cell.y];
float sim = (*simMap)[cell.y * w + cell.x];
if(sim >= 1.0f)
{
d = pixSizeBallWSP;
Expand All @@ -117,13 +117,13 @@ bool Fuser::updateInSurr(int pixSizeBall, int pixSizeBallWSP, Point3d& p, int rc
for(ncell.y = std::max(0, cell.y - d); ncell.y <= std::min(h - 1, cell.y + d); ncell.y++)
{
// printf("%i %i %i %i %i %i %i %i\n",ncell.x,ncell.y,w,h,w*h,depthMap->size(),cam,scale);
float depth = (*depthMap)[ncell.x * h + ncell.y];
float depth = (*depthMap)[ncell.y * w + ncell.x];
// Point3d p1 = mp->CArr[rc] +
// (mp->iCamArr[rc]*Point2d((float)ncell.x*(float)scale,(float)ncell.y*(float)scale)).normalize()*depth;
// if ( (p1-p).size() < pixSize ) {
if(fabs(pixDepth - depth) < pixSize)
{
(*numOfPtsMap)[ncell.x * h + ncell.y]++;
(*numOfPtsMap)[ncell.y * w + ncell.x]++;
}
}
}
Expand Down Expand Up @@ -166,9 +166,6 @@ bool Fuser::filterGroupsRC(int rc, int pixSizeBall, int pixSizeBallWSP, int nNea

imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::depthMap, 1), width, height, depthMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);
imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::simMap, 1), width, height, simMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);

imageAlgo::transposeImage(width, height, depthMap.getDataWritable());
imageAlgo::transposeImage(width, height, simMap.getDataWritable());
}

std::vector<unsigned char> numOfModalsMap(w * h, 0);
Expand Down Expand Up @@ -196,26 +193,22 @@ bool Fuser::filterGroupsRC(int rc, int pixSizeBall, int pixSizeBallWSP, int nNea

{
int width, height;

imageIO::readImage(getFileNameFromIndex(mp, tc, mvsUtils::EFileType::depthMap, 1), width, height, tcdepthMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);

// transpose image in-place, width/height are no more valid after this function.
imageAlgo::transposeImage(width, height, tcdepthMap.getDataWritable());
}

if(!tcdepthMap.empty())
{
for(int i = 0; i < sizeOfStaticVector<float>(&tcdepthMap); i++)
{
int x = i / h;
int y = i % h;
float depth = tcdepthMap[i];
if(depth > 0.0f)
for(int y = 0; y < h; ++y)
for(int x = 0; x < w; ++x)
{
Point3d p = mp->CArr[tc] + (mp->iCamArr[tc] * Point2d((float)x, (float)y)).normalize() * depth;
updateInSurr(pixSizeBall, pixSizeBallWSP, p, rc, tc, numOfPtsMap, &depthMap, &simMap, 1);
float depth = tcdepthMap[y * w + x];
if(depth > 0.0f)
{
Point3d p = mp->CArr[tc] + (mp->iCamArr[tc] * Point2d((float)x, (float)y)).normalize() * depth;
updateInSurr(pixSizeBall, pixSizeBallWSP, p, rc, tc, numOfPtsMap, &depthMap, &simMap, 1);
}
}
}


for(int i = 0; i < w * h; i++)
{
Expand All @@ -227,7 +220,6 @@ bool Fuser::filterGroupsRC(int rc, int pixSizeBall, int pixSizeBallWSP, int nNea
{
using namespace imageIO;
OutputFileColorSpace colorspace(EImageColorSpace::NO_CONVERSION);
imageAlgo::transposeImage(h, w, numOfModalsMap);
writeImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::nmodMap), w, h, numOfModalsMap, EImageQuality::LOSSLESS, colorspace);
}

Expand Down Expand Up @@ -274,10 +266,6 @@ bool Fuser::filterDepthMapsRC(int rc, int minNumOfModals, int minNumOfModalsWSP2
imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::depthMap, 1), width, height, depthMap, imageIO::EImageColorSpace::NO_CONVERSION);
imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::simMap, 1), width, height, simMap, imageIO::EImageColorSpace::NO_CONVERSION);
imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::nmodMap), width, height, numOfModalsMap, imageIO::EImageColorSpace::NO_CONVERSION);

imageAlgo::transposeImage(width, height, depthMap);
imageAlgo::transposeImage(width, height, simMap);
imageAlgo::transposeImage(width, height, numOfModalsMap);
}

int nbDepthValues = 0;
Expand Down Expand Up @@ -310,9 +298,6 @@ bool Fuser::filterDepthMapsRC(int rc, int minNumOfModals, int minNumOfModalsWSP2
++nbDepthValues;
}

imageAlgo::transposeImage(h, w, depthMap);
imageAlgo::transposeImage(h, w, simMap);

oiio::ParamValueList metadata = imageIO::getMetadataFromMap(mp->getMetadata(rc));
metadata.push_back(oiio::ParamValue("AliceVision:nbDepthValues", oiio::TypeDesc::INT32, 1, &nbDepthValues));
metadata.push_back(oiio::ParamValue("AliceVision:downscale", mp->getDownscaleFactor(rc)));
Expand Down Expand Up @@ -351,39 +336,37 @@ float Fuser::computeAveragePixelSizeInHexahedron(Point3d* hexah, int step, int s
{
int rc = cams[c];
int h = mp->getHeight(rc) / scaleuse;
int w = mp->getWidth(rc) / scaleuse;
StaticVector<float> rcdepthMap;

{
int width, height;

imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::depthMap, scale), width, height, rcdepthMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);

imageAlgo::transposeImage(width, height, rcdepthMap.getDataWritable());
}

for(int i = 0; i < rcdepthMap.size(); i++)
{
int x = i / h;
int y = i % h;
float depth = rcdepthMap[i];
if(depth > 0.0f)
for(int y = 0; y < h; y++)
for(int x = 0; x < w; ++x)
{
if(j % step == 0)
float depth = rcdepthMap[y * w + x];
if(depth > 0.0f)
{
Point3d p = mp->CArr[rc] +
(mp->iCamArr[rc] * Point2d((float)x * (float)scaleuse, (float)y * (float)scaleuse))
.normalize() *
depth;
if(mvsUtils::isPointInHexahedron(p, hexah))
if(j % step == 0)
{
float v = mp->getCamPixelSize(p, rc);
av += v; // WARNING: the value may be too big for a float
nav += 1.0f;
minv = std::min(minv, v);
Point3d p = mp->CArr[rc] +
(mp->iCamArr[rc] * Point2d((float)x * (float)scaleuse, (float)y * (float)scaleuse))
.normalize() *
depth;
if(mvsUtils::isPointInHexahedron(p, hexah))
{
float v = mp->getCamPixelSize(p, rc);
av += v; // WARNING: the value may be too big for a float
nav += 1.0f;
minv = std::min(minv, v);
}
}
j++;
}
j++;
}
}
//mvsUtils::printfEstimate(c, cams.size(), t1);
}
//mvsUtils::finishEstimate();
Expand Down Expand Up @@ -448,21 +431,19 @@ void Fuser::divideSpaceFromDepthMaps(Point3d* hexah, float& minPixSize)
Stat3d s3d = Stat3d();
for(int rc = 0; rc < mp->ncams; rc++)
{
int h = mp->getHeight(rc);
int w = mp->getWidth(rc);

StaticVector<float> depthMap;
{
int width, height;

imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::depthMap, scale), width, height, depthMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);

imageAlgo::transposeImage(width, height, depthMap.getDataWritable());
}

for(int i = 0; i < sizeOfStaticVector<float>(&depthMap); i += stepPts)
{
int x = i / h;
int y = i % h;
int x = i % w;
int y = i / w;
float depth = depthMap[i];
if(depth > 0.0f)
{
Expand Down Expand Up @@ -494,21 +475,19 @@ void Fuser::divideSpaceFromDepthMaps(Point3d* hexah, float& minPixSize)

for(int rc = 0; rc < mp->ncams; ++rc)
{
int h = mp->getHeight(rc);
int w = mp->getWidth(rc);

StaticVector<float> depthMap;
{
int width, height;

imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::depthMap, scale), width, height, depthMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);

imageAlgo::transposeImage(width, height, depthMap.getDataWritable());
}

for(int i = 0; i < depthMap.size(); i += stepPts)
{
int x = i / h;
int y = i % h;
int x = i % w;
int y = i / w;
float depth = depthMap[i];
if(depth > 0.0f)
{
Expand Down Expand Up @@ -767,9 +746,6 @@ std::string generateTempPtsSimsFiles(std::string tmpDir, mvsUtils::MultiViewPara

imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::depthMap, scale), width, height, depthMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);
imageIO::readImage(getFileNameFromIndex(mp, rc, mvsUtils::EFileType::simMap, scale), width, height, simMap.getDataWritable(), imageIO::EImageColorSpace::NO_CONVERSION);

imageAlgo::transposeImage(width, height, depthMap.getDataWritable());
imageAlgo::transposeImage(width, height, simMap.getDataWritable());
}

if(addRandomNoise)
Expand All @@ -790,54 +766,54 @@ std::string generateTempPtsSimsFiles(std::string tmpDir, mvsUtils::MultiViewPara
srand(time(nullptr));

long t1 = clock();
for(int id = 0; id < idsAlive->size(); id++)
{
int i = (*idsAlive)[(*randIdsAlive)[id]];
int x = i / h;
int y = i % h;
double depth = depthMap[i];

double sim = simMap[i];
if(depth > 0.0f)
for(int y = 0; y < h; ++y)
for(int x = 0; x < w; ++x)
{
Point3d p = mp->CArr[rc] +
int id = y * w + x;
int i = (*idsAlive)[(*randIdsAlive)[id]];
double depth = depthMap[i];

double sim = simMap[i];
if(depth > 0.0f)
{
Point3d p = mp->CArr[rc] +
(mp->iCamArr[rc] * Point2d((double)x * (double)scaleuse, (double)y * (double)scaleuse))
.normalize() *
depth;

if(id < nnoisePts)
{
double pixSize = mp->getCamPixelSize(p, rc);
int rid = rand() % (2 * noisPixSizeDistHalfThr + 1);
rid = rid - noisPixSizeDistHalfThr;
double rdepthAdd = pixSize * (double)rid;
depth = depth + rdepthAdd;
p = mp->CArr[rc] +
(mp->iCamArr[rc] * Point2d((double)x * (double)scaleuse, (double)y * (double)scaleuse))
.normalize() *
depth;
}

if(id < nnoisePts)
{
double pixSize = mp->getCamPixelSize(p, rc);
int rid = rand() % (2 * noisPixSizeDistHalfThr + 1);
rid = rid - noisPixSizeDistHalfThr;
double rdepthAdd = pixSize * (double)rid;
depth = depth + rdepthAdd;
p = mp->CArr[rc] +
(mp->iCamArr[rc] * Point2d((double)x * (double)scaleuse, (double)y * (double)scaleuse))
.normalize() *
depth;
}

pts->push_back(p);
sims->push_back(sim);
if((*minMaxDepths)[rc].x < 0.0f)
{
(*minMaxDepths)[rc].x = depth;
}
else
{
(*minMaxDepths)[rc].x = std::min((*minMaxDepths)[rc].x, depth);
}
if((*minMaxDepths)[rc].y < 0.0f)
{
(*minMaxDepths)[rc].y = depth;
}
else
{
(*minMaxDepths)[rc].y = std::max((*minMaxDepths)[rc].y, depth);
pts->push_back(p);
sims->push_back(sim);
if((*minMaxDepths)[rc].x < 0.0f)
{
(*minMaxDepths)[rc].x = depth;
}
else
{
(*minMaxDepths)[rc].x = std::min((*minMaxDepths)[rc].x, depth);
}
if((*minMaxDepths)[rc].y < 0.0f)
{
(*minMaxDepths)[rc].y = depth;
}
else
{
(*minMaxDepths)[rc].y = std::max((*minMaxDepths)[rc].y, depth);
}
}
}
}
if(mp->verbose)
mvsUtils::printfElapsedTime(t1);

Expand Down
11 changes: 8 additions & 3 deletions src/aliceVision/mesh/Texturing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -509,15 +509,20 @@ void Texturing::generateTexturesSubSet(const mvsUtils::MultiViewParams& mp,
// retrieve triangle 3D and UV coordinates
Point2d triPixs[3];
Point3d triPts[3];
auto triangleUvIds = trisUvIds[triangleId];
// compute the Bottom-Left minima of the current UDIM for [0,1] range remapping
Point2d udimBL;
udimBL.x = std::floor(std::min(std::min(uvCoords[triangleUvIds[0]].x, uvCoords[triangleUvIds[1]].x), uvCoords[triangleUvIds[2]].x));
udimBL.y = std::floor(std::min(std::min(uvCoords[triangleUvIds[0]].y, uvCoords[triangleUvIds[1]].y), uvCoords[triangleUvIds[2]].y));

for(int k = 0; k < 3; k++)
{
const int pointIndex = (*me->tris)[triangleId].v[k];
triPts[k] = (*me->pts)[pointIndex]; // 3D coordinates
const int uvPointIndex = trisUvIds[triangleId].m[k];
const int uvPointIndex = triangleUvIds.m[k];
Point2d uv = uvCoords[uvPointIndex];
uv.x -= std::floor(uv.x);
uv.y -= std::floor(uv.y);
// UDIM: remap coordinates between [0,1]
uv = uv - udimBL;

triPixs[k] = uv * texParams.textureSide; // UV coordinates
}
Expand Down

0 comments on commit 801fcd4

Please sign in to comment.