Skip to content

Commit

Permalink
Fix intersectedTriangle
Browse files Browse the repository at this point in the history
Refactor enveloping point and small fix in predicates.h
  • Loading branch information
artem-ogre authored and artem-hexagon committed May 3, 2022
1 parent ed13ed7 commit 3f7043d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 33 deletions.
62 changes: 36 additions & 26 deletions CDT/include/CDT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const SuperGeometryType::Enum superGeomType = SuperGeometryType::SuperTriangle;
const VertexInsertionOrder::Enum vertexInsertionOrder =
VertexInsertionOrder::Randomized;
const IntersectingConstraintEdges::Enum intersectingEdgesStrategy =
IntersectingConstraintEdges::Resolve;
IntersectingConstraintEdges::Ignore;
const float minDistToConstraintEdge(0);

} // namespace defaults
Expand Down Expand Up @@ -493,7 +493,7 @@ void Triangulation<T, TNearPointLocator>::insertEdge(
const Edge half1(iVleft, iNewVert);
const Edge half2(iNewVert, iVright);
const BoundaryOverlapCount overlaps = overlapCount[splitEdge];
// remove edge tha wa split
// remove the edge that will be split
fixedEdges.erase(splitEdge);
overlapCount.erase(splitEdge);
// add split edge's halves
Expand Down Expand Up @@ -637,7 +637,7 @@ void Triangulation<T, TNearPointLocator>::conformToEdge(
const Edge half1(iVleft, iNewVert);
const Edge half2(iNewVert, iVright);
const BoundaryOverlapCount overlaps = overlapCount[splitEdge];
// remove edge tha wa split
// remove the edge that will be split
fixedEdges.erase(splitEdge);
overlapCount.erase(splitEdge);
// add split edge's halves
Expand Down Expand Up @@ -752,40 +752,50 @@ Triangulation<T, TNearPointLocator>::intersectedTriangle(
const T orientationTolerance) const
{
typedef std::vector<TriInd>::const_iterator TriIndCit;
VertInd closestP1 = noVertex;
VertInd closestP2 = noVertex;
T closestOrientP1 = std::numeric_limits<T>::max();
for(TriIndCit it = candidates.begin(); it != candidates.end(); ++it)
{
const TriInd iT = *it;
const Triangle t = triangles[iT];
const Index i = vertexInd(t, iA);
const VertInd iP1 = t.vertices[cw(i)];
const VertInd iP2 = t.vertices[ccw(i)];
const PtLineLocation::Enum locP2 =
locatePointLine(vertices[iP2], a, b, orientationTolerance);
if(locP2 == PtLineLocation::Left)
continue;
const T orientP1 = orient2D(vertices[iP1], a, b);
const PtLineLocation::Enum locP1 =
classifyOrientation(orientP1, orientationTolerance);
if(locP2 == PtLineLocation::Right && locP1 == PtLineLocation::Left)
return make_tuple(iT, iP1, iP2);
if(locP1 == PtLineLocation::OnLine)
const T orientP2 = orient2D(vertices[iP2], a, b);
const PtLineLocation::Enum locP2 = classifyOrientation(orientP2);
if(locP2 == PtLineLocation::Right)
{
if(!orientationTolerance)
return make_tuple(noNeighbor, iP1, iP2);
// tolerance is used: find the closest left point to the line
if(orientP1 < closestOrientP1)
const VertInd iP1 = t.vertices[cw(i)];
const T orientP1 = orient2D(vertices[iP1], a, b);
const PtLineLocation::Enum locP1 = classifyOrientation(orientP1);
if(locP1 == PtLineLocation::OnLine)
{
return make_tuple(noNeighbor, iP1, iP1);
}
if(locP1 == PtLineLocation::Left)
{
closestP1 = iP1;
closestP2 = iP2;
closestOrientP1 = orientP1;
if(orientationTolerance)
{
T closestOrient;
VertInd iClosestP;
if(std::abs(orientP1) <= std::abs(orientP2))
{
closestOrient = orientP1;
iClosestP = iP1;
}
else
{
closestOrient = orientP2;
iClosestP = iP2;
}
if(classifyOrientation(
closestOrient, orientationTolerance) ==
PtLineLocation::OnLine)
{
return make_tuple(noNeighbor, iClosestP, iClosestP);
}
}
return make_tuple(iT, iP1, iP2);
}
}
}
if(orientationTolerance && closestP1 != noVertex)
return make_tuple(noNeighbor, closestP1, closestP2);
throw std::runtime_error("Could not find vertex triangle intersected by "
"edge. Note: can be caused by duplicate points.");
}
Expand Down
23 changes: 17 additions & 6 deletions CDT/include/CDTUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ typedef char couldnt_parse_cxx_standard[-1]; ///< Error: couldn't parse standard
namespace CDT
{
using std::array;
using std::get;
using std::make_tuple;
using std::mt19937;
using std::tie;
using std::get;
using std::tuple;
using std::unordered_map;
using std::unordered_set;
Expand All @@ -80,9 +80,9 @@ using std::unordered_set;
namespace CDT
{
using boost::array;
using boost::get;
using boost::make_tuple;
using boost::tie;
using boost::get;
using boost::tuple;
using boost::unordered_map;
using boost::unordered_set;
Expand Down Expand Up @@ -157,6 +157,20 @@ struct CDT_EXPORT Box2d
{
V2d<T> min; ///< min box corner
V2d<T> max; ///< max box corner

/// Envelop box around a point
void envelopPoint(const V2d<T>& p)
{
envelopPoint(p.x, p.y);
}
/// Envelop box around a point with given coordinates
void envelopPoint(const T x, const T y)
{
min.x = std::min(x, min.x);
max.x = std::max(x, max.x);
min.y = std::min(y, min.y);
max.y = std::max(y, max.y);
}
};

/// Bounding box of a collection of custom 2D points given coordinate getters
Expand All @@ -175,10 +189,7 @@ Box2d<T> envelopBox(
Box2d<T> box = {{max, max}, {-max, -max}};
for(; first != last; ++first)
{
box.min.x = std::min(getX(*first), box.min.x);
box.max.x = std::max(getX(*first), box.max.x);
box.min.y = std::min(getY(*first), box.min.y);
box.max.y = std::max(getY(*first), box.max.y);
box.envelopPoint(getX(*first), getY(*first));
}
return box;
}
Expand Down
2 changes: 1 addition & 1 deletion CDT/include/predicates.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ namespace stdx {
return result;
}
}
#endif // CXX11_IS_SUPPORTED
#endif // PREDICATES_CXX11_IS_SUPPORTED

namespace detail {
template<typename T> class ExpansionBase;
Expand Down

0 comments on commit 3f7043d

Please sign in to comment.