Skip to content

Commit

Permalink
[fuseCut] add struct for advanced geometry intersection function
Browse files Browse the repository at this point in the history
  • Loading branch information
dsmtE committed Jul 13, 2020
1 parent d770fde commit e6dd5f7
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/aliceVision/fuseCut/DelaunayGraphCut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2984,5 +2984,47 @@ void DelaunayGraphCut::leaveLargestFullSegmentOnly()
ALICEVISION_LOG_DEBUG("Largest full segment only done.");
}

DelaunayGraphCut::GeometryIntersection DelaunayGraphCut::lineIntersectTriangle(const Point3d& originPt, const Point3d& DirVec, const Facet& facet, Point3d& intersectPt, const float epsilon)
{
const VertexIndex AvertexIndex = getVertexIndex(facet, 0);
const VertexIndex BvertexIndex = getVertexIndex(facet, 1);
const VertexIndex CvertexIndex = getVertexIndex(facet, 2);

// const std::array<const Point3d*, 3> facetPoints = getFacetsPoints(facet);
const Point3d* A = &_verticesCoords[AvertexIndex];
const Point3d* B = &_verticesCoords[BvertexIndex];
const Point3d* C = &_verticesCoords[CvertexIndex];

const Point2d triangleUv = getLineTriangleIntersectBarycCoords(&intersectPt, A, B, C, &originPt, &DirVec);
const float u = triangleUv.x; // A to C
const float v = triangleUv.y; // A to B

if(v > -epsilon && v < epsilon) // along A C edge
{
if(u > -epsilon && u < epsilon)
return GeometryIntersection(AvertexIndex); // vertex A
if(u > 1-epsilon && u < 1 + epsilon)
return GeometryIntersection(CvertexIndex); // vertex C

return GeometryIntersection(Edge(AvertexIndex, CvertexIndex)); // edge AC
}

if(u > -epsilon && u < epsilon) // along A B edge
{
if(v > 1 - epsilon && v < 1 + epsilon)
return GeometryIntersection(BvertexIndex); // vertex B

return GeometryIntersection(Edge(AvertexIndex, BvertexIndex)); // edge AB
}

if(u + v > 1 - epsilon && u + v < 1 + epsilon)
return GeometryIntersection(Edge(BvertexIndex, CvertexIndex)); // edge BC

if(u + v < 1.0f - epsilon)
return GeometryIntersection(facet);

return GeometryIntersection(); // Return none
}

} // namespace fuseCut
} // namespace aliceVision
48 changes: 48 additions & 0 deletions src/aliceVision/fuseCut/DelaunayGraphCut.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,51 @@ class DelaunayGraphCut
VertexIndex localVertexIndex = GEO::NO_VERTEX;
};

struct Edge
{
Edge() = default;
Edge(VertexIndex v0_, VertexIndex v1_)
: v0{v0_}
, v1{v1_}
{}

VertexIndex v0 = GEO::NO_VERTEX;
VertexIndex v1 = GEO::NO_VERTEX;
};

enum class EGeometryType
{
Vertex,
Edge,
Facet,
None
};

struct GeometryIntersection
{
union
{
Facet facet;
VertexIndex vertex;
Edge edge;
};
GeometryIntersection() {}
GeometryIntersection(const Facet& f)
: facet{f}
, type{EGeometryType::Facet}
{}
GeometryIntersection(const VertexIndex& v)
: vertex{v}
, type{EGeometryType::Vertex}
{}
GeometryIntersection(const Edge& e)
: edge{e}
, type{EGeometryType::Edge}
{}

EGeometryType type = EGeometryType::None;
};

mvsUtils::MultiViewParams* mp;

GEO::Delaunay_var _tetrahedralization;
Expand Down Expand Up @@ -363,6 +408,9 @@ class DelaunayGraphCut
void leaveLargestFullSegmentOnly();

mesh::Mesh* createMesh(bool filterHelperPointsTriangles = true);

GeometryIntersection lineIntersectTriangle(const Point3d& originPt, const Point3d& DirVec, const Facet& facet,
Point3d& intersectPt, const float epsilon);
};

} // namespace fuseCut
Expand Down

0 comments on commit e6dd5f7

Please sign in to comment.