Improved comments and some renaming

This commit is contained in:
Jacob Støren 2015-11-20 09:26:27 +01:00
parent 94b713d3bf
commit 919ba80bc6
2 changed files with 33 additions and 35 deletions

View File

@ -56,7 +56,8 @@ RivCrossSectionGeometryGenerator::~RivCrossSectionGeometryGenerator()
/// \param b End of line segment /// \param b End of line segment
/// \param intersection Returns intersection point along the infinite line defined by a-b /// \param intersection Returns intersection point along the infinite line defined by a-b
/// \param normalizedDistFromA Returns the normalized (0..1) position from a to b of the intersection point. /// \param normalizedDistFromA Returns the normalized (0..1) position from a to b of the intersection point.
/// Will return values along the complete line, and HUGE_VAL if plane and line are parallel. /// Will return values along the infinite line defined by the a-b direcion,
/// and HUGE_VAL if plane and line are parallel.
/// ///
/// \return True if line segment intersects the plane /// \return True if line segment intersects the plane
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -97,33 +98,30 @@ struct ClipVx
}; };
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
/// Returns whether the triangle was hit by the plane /// Returns whether the triangle was hit by the plane.
/// isMostVxesOnPositiveSide returns true if all or two of the vxes is on the positive side of the plane /// isMostVxesOnPositiveSide returns true if all or two of the vxes is on the positive side of the plane.
/// newVx1/2.vx1ClippedEdge returns the index of the single vx that is alone on one side /// newVx1/2.vx1ClippedEdge returns the index of the single vx that is alone on one side of the plane.
/// Going newVx1 to newVx2 will make the top triangle same winding as the original triangle, /// Going newVx1 to newVx2 will make the top triangle same winding as the original triangle,
/// and thus the quad opposite winding /// and the quad opposite winding
// Except for the trivial cases where all vertices are in front // The permutations except for the trivial cases where all vertices are in front or behind plane:
// or behind plane, these are the permutations
// //
// Single vertex on positive side of plane // Single vertex on positive side of plane => isMostVxesOnPositiveSide = false
// => return a triangle
// //
// +\ /\c /\c /+ /\c . // +\ /\3 /\3 /+ /\3 .
// \ / \ / \ / + / \ + . // \ / \ / \ / + / \ + .
// \ \ / \/ ---/----\--- . // \2 \ / \/1 __1/____\2__ .
// / \ \ / /\ / \ . // / \ \ / /\ / \ .
// a/___\____\b a/_____/__\b a/________\b . // 1/___\1___\2 1/____2/__\2 1/________\2 .
// +\ /+ // +\ /+
// //
// Two vertices vertex on positive side of plane // Two vertices vertex on positive side of plane => isMostVxesOnPositiveSide = true
// => return a quad
// //
// \+ /\c /\c +/ /\c . // \+ /\3 /\3 +/ /\3 .
// \ / \ / \ / / \ . // \ / \ / \ / / \ .
// \ \ / \/ ___/____\___ . // \2 \ / \/1 __1/____\2__ .
// / \ \ / /\ + / \ + . // / \ \ / /\ + / \ + .
// a/___\____\b a/_____/__\b a/________\b . // 1/___\1___\2 1/____2/__\2 1/________\2 .
// \+ +/ // \+ +/
//-------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------
@ -1006,8 +1004,8 @@ void RivCrossSectionGeometryGenerator::calculateArrays()
p2Plane.setFromPoints(p2, p2 + m_extrusionDirection*maxSectionHeight, p2 - plane.normal() ); p2Plane.setFromPoints(p2, p2 + m_extrusionDirection*maxSectionHeight, p2 - plane.normal() );
std::vector<ClipVx> triangleClipVxes; std::vector<ClipVx> hexPlaneCutTriangleVxes;
triangleClipVxes.reserve(5*3); hexPlaneCutTriangleVxes.reserve(5*3);
std::vector<bool> isTriangleEdgeCellContour; std::vector<bool> isTriangleEdgeCellContour;
isTriangleEdgeCellContour.reserve(5*3); isTriangleEdgeCellContour.reserve(5*3);
@ -1017,7 +1015,7 @@ void RivCrossSectionGeometryGenerator::calculateArrays()
if (m_mainGrid->cells()[globalCellIdx].isInvalid()) continue; if (m_mainGrid->cells()[globalCellIdx].isInvalid()) continue;
triangleClipVxes.clear(); hexPlaneCutTriangleVxes.clear();
cvf::Vec3d cellCorners[8]; cvf::Vec3d cellCorners[8];
m_mainGrid->cellCornerVertices(globalCellIdx, cellCorners); m_mainGrid->cellCornerVertices(globalCellIdx, cellCorners);
@ -1035,13 +1033,13 @@ void RivCrossSectionGeometryGenerator::calculateArrays()
int triangleCount = planeHexIntersectionMC(plane, int triangleCount = planeHexIntersectionMC(plane,
cellCorners, cellCorners,
hexCornersIds, hexCornersIds,
&triangleClipVxes, &hexPlaneCutTriangleVxes,
&isTriangleEdgeCellContour); &isTriangleEdgeCellContour);
std::vector<ClipVx> clippedTriangleVxes; std::vector<ClipVx> clippedTriangleVxes;
std::vector<bool> isClippedTriEdgeCellContour; std::vector<bool> isClippedTriEdgeCellContour;
clipTrianglesBetweenTwoParallelPlanes(triangleClipVxes, isTriangleEdgeCellContour, p1Plane, p2Plane, clipTrianglesBetweenTwoParallelPlanes(hexPlaneCutTriangleVxes, isTriangleEdgeCellContour, p1Plane, p2Plane,
&clippedTriangleVxes, &isClippedTriEdgeCellContour); &clippedTriangleVxes, &isClippedTriEdgeCellContour);
int clippedTriangleCount = static_cast<int>(clippedTriangleVxes.size())/3; int clippedTriangleCount = static_cast<int>(clippedTriangleVxes.size())/3;
@ -1096,8 +1094,8 @@ void RivCrossSectionGeometryGenerator::calculateArrays()
} }
else else
{ {
ClipVx cvx1 = triangleClipVxes[cvx.clippedEdgeVx1Id]; ClipVx cvx1 = hexPlaneCutTriangleVxes[cvx.clippedEdgeVx1Id];
ClipVx cvx2 = triangleClipVxes[cvx.clippedEdgeVx2Id]; ClipVx cvx2 = hexPlaneCutTriangleVxes[cvx.clippedEdgeVx2Id];
m_triangleVxInterPolationData.push_back( m_triangleVxInterPolationData.push_back(
VxInterPolData(cvx1.clippedEdgeVx1Id, cvx1.clippedEdgeVx2Id, cvx1.normDistFromEdgeVx1, VxInterPolData(cvx1.clippedEdgeVx1Id, cvx1.clippedEdgeVx2Id, cvx1.normDistFromEdgeVx1,

View File

@ -75,17 +75,17 @@ private:
struct VxInterPolData struct VxInterPolData
{ {
explicit VxInterPolData(int vx1, int vx2, double normDistFrom1, explicit VxInterPolData(int edge1Vx1, int edge1Vx2, double normDistFromE1V1,
int vx3, int vx4, double normDistFrom3, int edge2Vx1, int edge2Vx2, double normDistFromE2V1,
double normDistFrom12) double normDistFromE1Cut)
: vx1Id(vx1), : vx1Id(edge1Vx1),
weight1((float)(1.0 - normDistFrom1 - normDistFrom12 + normDistFrom1*normDistFrom12)), weight1((float)(1.0 - normDistFromE1V1 - normDistFromE1Cut + normDistFromE1V1*normDistFromE1Cut)),
vx2Id(vx2), vx2Id(edge1Vx2),
weight2((float)(normDistFrom1 - normDistFrom1*normDistFrom12)), weight2((float)(normDistFromE1V1 - normDistFromE1V1*normDistFromE1Cut)),
vx3Id(vx3), vx3Id(edge2Vx1),
weight3((float)(normDistFrom12 - normDistFrom3*normDistFrom12)), weight3((float)(normDistFromE1Cut - normDistFromE2V1*normDistFromE1Cut)),
vx4Id(vx4), vx4Id(edge2Vx2),
weight4((float)(normDistFrom3*normDistFrom12)) weight4((float)(normDistFromE2V1*normDistFromE1Cut))
{} {}
int vx1Id; int vx1Id;