Skip to content

Commit

Permalink
[fuseCut] DelaunayGraphCut: remove unnecessary neighbourCellToTheCamO…
Browse files Browse the repository at this point in the history
…nTheRay function (CRITIC)

Remove the unnecessary neighborCellToTheCamOnTheRay function by using rayCellIntersection directly in loops and use mirrorFacet when it' s necessary to ensure loop recursion and get the next cell.
  • Loading branch information
dsmtE committed Jul 7, 2020
1 parent 4aaf816 commit d13085f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 75 deletions.
109 changes: 67 additions & 42 deletions src/aliceVision/fuseCut/DelaunayGraphCut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1722,10 +1722,14 @@ void DelaunayGraphCut::fillGraphPartPtRc(int& out_nstepsFront, int& out_nstepsBe
++nsteps;

Point3d pold = p;
Facet f1, f2;
Facet outFacet;
Point3d lpi;
// find cell which is nearest to the cam and which is intersected with cam-p ray
if(!nearestNeighbourCellToTheCamOnTheRay(mp->CArr[cam], p, ci, f1, f2, lpi))

// Intersection with the next facet in the current tetrahedron (ci) in order to find the cell nearest to the
// cam which is intersected with cam-p ray
// true here mean nearest
const bool nearestFarest = true;
if(!rayCellIntersection(mp->CArr[cam], p, ci, outFacet, nearestFarest, lpi))
{
ok = false;
}
Expand All @@ -1735,14 +1739,16 @@ void DelaunayGraphCut::fillGraphPartPtRc(int& out_nstepsFront, int& out_nstepsBe

{
#pragma OMP_ATOMIC_UPDATE
_cellsAttr[f1.cellIndex].gEdgeVisWeight[f1.localVertexIndex] += weight * dist;
_cellsAttr[outFacet.cellIndex].gEdgeVisWeight[outFacet.localVertexIndex] += weight * dist;
}

if(f2.cellIndex == GEO::NO_CELL)
// Take the mirror facet to iterate over the next cell
ci = mirrorFacet(outFacet).cellIndex;

if(ci == GEO::NO_CELL)
ok = false;
ci = f2.cellIndex;
p = lpi;
lastFinite = f2.cellIndex;
lastFinite = ci;
}
}

Expand All @@ -1758,7 +1764,7 @@ void DelaunayGraphCut::fillGraphPartPtRc(int& out_nstepsFront, int& out_nstepsBe
out_nstepsBehind = 0;
// get the tetrahedron next to point p on the ray from c
Facet f1 = getFacetBehindVertexOnTheRayToTheCam(vertexIndex, cam);
Facet f2;
Facet outFacet;

CellIndex ci = f1.cellIndex;
if(ci != GEO::NO_CELL)
Expand Down Expand Up @@ -1788,8 +1794,12 @@ void DelaunayGraphCut::fillGraphPartPtRc(int& out_nstepsFront, int& out_nstepsBe

Point3d pold = p;
Point3d lpi;
// find cell which is farest to the cam and which intersect cam-p ray
if((!farestNeighbourCellToTheCamOnTheRay(mp->CArr[cam], p, ci, f1, f2, lpi)) ||

// Intersection with the next facet in the current tetrahedron (ci) in order to find the cell farest to the
// cam which is intersected with cam-p ray
// False here mean farest
const bool nearestFarest = false;
if(!rayCellIntersection(mp->CArr[cam], p, ci, outFacet, nearestFarest, lpi) ||
((po - pold).size() >= maxDist) || (!allPoints))
{
ok = false;
Expand All @@ -1804,16 +1814,18 @@ void DelaunayGraphCut::fillGraphPartPtRc(int& out_nstepsFront, int& out_nstepsBe

float dist = distFcn(maxDist, (po - pold).size(), distFcnHeight);

if(f2.cellIndex == GEO::NO_CELL)
// Take the mirror facet to iterate over the next cell
const Facet mFacet = mirrorFacet(outFacet);
ci = mFacet.cellIndex;
if(ci == GEO::NO_CELL)
{
ok = false;
}
else
{
#pragma OMP_ATOMIC_UPDATE
_cellsAttr[f2.cellIndex].gEdgeVisWeight[f2.localVertexIndex] += weight * dist;
_cellsAttr[ci].gEdgeVisWeight[mFacet.localVertexIndex] += weight * dist;
}
ci = f2.cellIndex;
p = lpi;
}
}
Expand Down Expand Up @@ -1865,14 +1877,12 @@ void DelaunayGraphCut::forceTedgesByGradientCVPR11(bool fixesSigma, float nPixel
Facet fFirst = getFacetInFrontVertexOnTheRayToTheCam(vi, cam);

// get the tetrahedron next to point p on the ray from c
Facet f2;
Facet f1 = getFacetBehindVertexOnTheRayToTheCam(vi, cam);

if((fFirst.cellIndex != GEO::NO_CELL) && (f1.cellIndex != GEO::NO_CELL) && (!isInfiniteCell(f1.cellIndex)))
{
float eFirst = _cellsAttr[fFirst.cellIndex].out;

f2 = mirrorFacet(f1);
CellIndex ci = f1.cellIndex;
Point3d p = po; // HAS TO BE HERE !!!
float maxDist = nPixelSizeBehind * mp->getCamPixelSize(p, cam);
Expand All @@ -1886,29 +1896,30 @@ void DelaunayGraphCut::forceTedgesByGradientCVPR11(bool fixesSigma, float nPixel
{
Point3d pold = p;
Point3d lpi;
Facet ff1, ff2;
// find cell which is farest to the cam and which is
// intersected with cam-p
// ray
if((!farestNeighbourCellToTheCamOnTheRay(mp->CArr[cam], p, ci, ff1, ff2, lpi)) ||
Facet outFacet;

// Intersection with the next facet in the current tetrahedron (ci) in order to find the cell farest
// to the cam which is intersected with cam-p ray
// False here mean farest
const bool nearestFarest = false;
if(!rayCellIntersection(mp->CArr[cam], p, ci, outFacet, nearestFarest, lpi) ||
((po - pold).size() >= maxDist))
{
ok = false;
}
else
{
if(ff2.cellIndex == GEO::NO_CELL)
// Take the mirror facet to iterate over the next cell
ci = mirrorFacet(outFacet).cellIndex;
if(ci == GEO::NO_CELL)
ok = false;
ci = ff2.cellIndex;
p = lpi;
f1 = ff1;
f2 = ff2;
}
}

if(ci != GEO::NO_CELL)
{
float eLast = _cellsAttr[f2.cellIndex].out;
float eLast = _cellsAttr[ci].out;
if((eFirst > eLast) && (eFirst < beta) && (eLast / eFirst < delta))
{
#pragma OMP_ATOMIC_UPDATE
Expand Down Expand Up @@ -2021,19 +2032,23 @@ void DelaunayGraphCut::forceTedgesByGradientIJCV(bool fixesSigma, float nPixelSi
maxSilent = std::max(maxSilent, c.out);
}

Facet f1, f2;
Facet outFacet;
Point3d lpi;
// find cell which is nearest to the cam and which intersect cam-p ray
// Intersection with the next facet in the current tetrahedron (ci) in order to find the cell nearest
// to the cam which is intersected with cam-p ray
// True here mean nearest
const bool nearestFarest = true;
if(((p - po).size() > (nsigmaJumpPart + nsigmaFrontSilentPart) * maxDist) || // (2 + 2) * sigma
(!nearestNeighbourCellToTheCamOnTheRay(mp->CArr[cam], p, ci, f1, f2, lpi)))
!rayCellIntersection(mp->CArr[cam], p, ci, outFacet, nearestFarest, lpi))
{
ok = false;
}
else
{
if(f2.cellIndex == GEO::NO_CELL)
// Take the mirror facet to iterate over the next cell
ci = mirrorFacet(outFacet).cellIndex;
if(ci == GEO::NO_CELL)
ok = false;
ci = f2.cellIndex;
p = lpi;
}
}
Expand All @@ -2056,19 +2071,24 @@ void DelaunayGraphCut::forceTedgesByGradientIJCV(bool fixesSigma, float nPixelSi
minSilent = std::min(minSilent, c.out);
maxSilent = std::max(maxSilent, c.out);

Facet f1, f2;
Facet outFacet;
Point3d lpi;
// find cell which is farest to the cam and which intersect cam-p ray

// Intersection with the next facet in the current tetrahedron (ci) in order to find the cell farest
// to the cam which is intersected with cam-p ray
// False here mean farest
const bool nearestFarest = false;
if(((p - po).size() > nsigmaBackSilentPart * maxDist) || // (p-po).size() > 2 * sigma
(!farestNeighbourCellToTheCamOnTheRay(mp->CArr[cam], p, ci, f1, f2, lpi)))
!rayCellIntersection(mp->CArr[cam], p, ci, outFacet, nearestFarest, lpi))
{
ok = false;
}
else
{
if(f2.cellIndex == GEO::NO_CELL)
// Take the mirror facet to iterate over the next cell
ci = mirrorFacet(outFacet).cellIndex;
if(ci == GEO::NO_CELL)
ok = false;
ci = f2.cellIndex;
p = lpi;
}
}
Expand Down Expand Up @@ -2201,26 +2221,31 @@ void DelaunayGraphCut::updateGraphFromTmpPtsCamsHexahRC(int rc, Point3d hexah[8]
_cellsAttr[tmp_ci].out += weight;
}

Facet f1, f2;
Facet outFacet;
Point3d lpi;
// find cell which is nearest to the pont and which is
// intersected with point-p ray
if(!farestNeighbourCellToTheCamOnTheRay(camBehind, p, tmp_ci, f1, f2, lpi))

// Intersection with the next facet in the current tetrahedron (ci) in order to find the cell farest
// to the cam which is intersected with cam-p ray
// False here mean farest
const bool nearestFarest = false;
if(!rayCellIntersection(camBehind, p, tmp_ci, outFacet, nearestFarest, lpi))
{
ok = false;
}
else
{
if(f2.cellIndex == GEO::NO_CELL)
// Take the mirror facet to iterate over the next cell
const Facet mFacet = mirrorFacet(outFacet);
tmp_ci = mFacet.cellIndex;
if(ci == GEO::NO_CELL)
{
ok = false;
}
else
{
#pragma OMP_ATOMIC_UPDATE
_cellsAttr[f2.cellIndex].gEdgeVisWeight[f2.localVertexIndex] += weight;
_cellsAttr[tmp_ci].gEdgeVisWeight[mFacet.localVertexIndex] += weight;
}
tmp_ci = f2.cellIndex;
p = lpi;
++nwup;
}
Expand Down
33 changes: 0 additions & 33 deletions src/aliceVision/fuseCut/DelaunayGraphCut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,6 @@ class DelaunayGraphCut
bool rayCellIntersection(const Point3d& camCenter, const Point3d& p, GEO::index_t tetrahedronIndex, Facet& outFacet,
bool nearestFarest, Point3d& outIntersectPt) const;

inline bool neighbourCellToTheCamOnTheRay(const Point3d& camC, const Point3d& p, int tetrahedron, bool nearestFarest,
Facet& f1, Facet& f2, Point3d& outIntersectPt) const;
inline bool nearestNeighbourCellToTheCamOnTheRay(const Point3d& camC, const Point3d& p, int tetrahedron, Facet& f1, Facet& f2,
Point3d& outIntersectPt) const;
inline bool farestNeighbourCellToTheCamOnTheRay(const Point3d& camC, const Point3d& p, int tetrahedron, Facet& f1, Facet& f2,
Point3d& outIntersectPt) const;

inline Facet getFacetInFrontVertexOnTheRayToTheCam(int vertexIndex, int cam) const;
Facet getFacetInFrontVertexOnTheRayToThePoint3d(VertexIndex vi, Point3d& ptt) const;
Facet getFacetBehindVertexOnTheRayToTheCam(VertexIndex vi, int cam) const;
Expand Down Expand Up @@ -349,32 +342,6 @@ class DelaunayGraphCut
mesh::Mesh* createMesh(bool filterHelperPointsTriangles = true);
};

inline bool DelaunayGraphCut::neighbourCellToTheCamOnTheRay(const Point3d& camC, const Point3d& p, int tetrahedron, bool nearestFarest,
Facet& f1, Facet& f2, Point3d& outIntersectPt) const
{
f2.cellIndex = GEO::NO_CELL;
f2.localVertexIndex = GEO::NO_VERTEX;
outIntersectPt = p;

if(rayCellIntersection(camC, p, tetrahedron, f1, nearestFarest, outIntersectPt))
{
f2 = mirrorFacet(f1);
return true;
}
return false;
}

inline bool DelaunayGraphCut::nearestNeighbourCellToTheCamOnTheRay(const Point3d& camC, const Point3d& p, int tetrahedron, Facet& f1, Facet& f2,
Point3d& outIntersectPt) const
{
return neighbourCellToTheCamOnTheRay(camC, p, tetrahedron, true, f1, f2, outIntersectPt);
}
inline bool DelaunayGraphCut::farestNeighbourCellToTheCamOnTheRay(const Point3d& camC, const Point3d& p, int tetrahedron, Facet& f1, Facet& f2,
Point3d& outIntersectPt) const
{
return neighbourCellToTheCamOnTheRay(camC, p, tetrahedron, false, f1, f2, outIntersectPt);
}

inline DelaunayGraphCut::Facet DelaunayGraphCut::getFacetInFrontVertexOnTheRayToTheCam(int vertexIndex,
int cam) const
{
Expand Down

0 comments on commit d13085f

Please sign in to comment.