Index: DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs =================================================================== diff -u -r3893 -r4000 --- DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 3893) +++ DamEngine/trunk/src/Deltares.DamEngine.Data/Geometry/GeometryGenerator.cs (.../GeometryGenerator.cs) (revision 4000) @@ -35,10 +35,12 @@ private readonly Dictionary geometryCurveForwardsIsUsed = new Dictionary(); private readonly Dictionary geometryCurveReversedIsUsed = new Dictionary(); private readonly GeometryData geometryData; + private readonly Dictionary> geometryLoopDirections = new Dictionary>(); + // private readonly List intersectedCurveList = new List(); private readonly List newlyDetectedSurfaceList = new List(); - + /// /// Regenerates the geometry. /// @@ -56,8 +58,8 @@ SetupCurveSurfaceAssociations(); - bool firstRegeneration = true; - + var firstRegeneration = true; + while (true) { // break up all curves at intersections @@ -70,7 +72,7 @@ int curvesCount = geometryData.Curves.Count; // initialise IsUsed of all curves to false - for (int index1 = 0; index1 < curvesCount; index1++) + for (var index1 = 0; index1 < curvesCount; index1++) { SetIsUsed(geometryData.Curves[index1], CurveDirection.Forward, false); SetIsUsed(geometryData.Curves[index1], CurveDirection.Reverse, false); @@ -81,7 +83,7 @@ // clear the effected & intersected curve list //intersectedCurveList.Clear(); only when really needed - + if (result < 0) { if (!firstRegeneration) @@ -93,6 +95,7 @@ { break; } + firstRegeneration = false; } } @@ -110,11 +113,13 @@ { return false; } + aEditedLoop.CurveList.Add(aCurve); if (!geometryLoopDirections.ContainsKey(aEditedLoop)) { geometryLoopDirections.Add(aEditedLoop, new List()); } + geometryLoopDirections[aEditedLoop].Add(aDirection); return true; } @@ -137,6 +142,7 @@ geometryData.Surfaces.Add(newSurface); return newSurface; } + return null; } @@ -156,7 +162,7 @@ int curvesCount = aGeometryLoop.CurveList.Count; - for (int index = 0; index < curvesCount; index++) + for (var index = 0; index < curvesCount; index++) { // Note Bka: Checking the direction does allow one curve to be added to ONE loop twice! // This produces some strange surfaces (see LoopDetectionCase5) but that seems to be required @@ -165,6 +171,7 @@ return index; } } + return -1; } @@ -212,10 +219,8 @@ { return geometryCurveForwardsIsUsed[aCurve]; } - else - { - return geometryCurveReversedIsUsed[aCurve]; - } + + return geometryCurveReversedIsUsed[aCurve]; } /// @@ -227,7 +232,7 @@ var doublePoints = new Dictionary(); // Make sure all points (as pointers) in curves are in the point list - foreach (var curve in geometryData.Curves) + foreach (GeometryCurve curve in geometryData.Curves) { if (!geometryData.Points.Contains(curve.HeadPoint)) { @@ -241,9 +246,9 @@ } // find double points (by location!) in point list and register them with original - for (int i = 0; i < geometryData.Points.Count; i++) + for (var i = 0; i < geometryData.Points.Count; i++) { - for (int j = 0; j < i; j++) + for (var j = 0; j < i; j++) { if (i != j && geometryData.Points[i].LocationEquals(geometryData.Points[j])) { @@ -255,9 +260,9 @@ } // replace double points in curves with originals - foreach (var doublePoint in doublePoints.Keys) + foreach (Point2D doublePoint in doublePoints.Keys) { - foreach (var curve in geometryData.Curves) + foreach (GeometryCurve curve in geometryData.Curves) { if (curve.HeadPoint == doublePoint) { @@ -272,7 +277,7 @@ } // remove curves which have the same head as end point - foreach (var curve in geometryData.Curves.ToArray()) + foreach (GeometryCurve curve in geometryData.Curves.ToArray()) { if (curve.HeadPoint == curve.EndPoint) { @@ -282,10 +287,10 @@ geometryData.NewlyEffectedCurves.Remove(curve); } - foreach (var surface in geometryData.Surfaces) + foreach (GeometrySurface surface in geometryData.Surfaces) { surface.OuterLoop.CurveList.Remove(curve); - foreach (var loop in surface.InnerLoops) + foreach (GeometryLoop loop in surface.InnerLoops) { loop.CurveList.Remove(curve); } @@ -294,15 +299,16 @@ } // removing curves from loops in surfaces may have created invalid surfaces, remove those here - foreach (var surface in geometryData.Surfaces.ToArray()) + foreach (GeometrySurface surface in geometryData.Surfaces.ToArray()) { if (!surface.OuterLoop.HasArea()) { geometryData.Surfaces.Remove(surface); } } + // remove double points from point list - foreach (var point in doublePoints.Keys) + foreach (Point2D point in doublePoints.Keys) { geometryData.Points.Remove(point); @@ -328,16 +334,17 @@ var attachedCurveList = new List(); // start the first iteration - for (int index = 0; index < curvesCount * 2; index++) + for (var index = 0; index < curvesCount * 2; index++) { - var curveIndex = index / 2; + int curveIndex = index / 2; // look for current curve - var currentCurve = geometryData.Curves[curveIndex]; + GeometryCurve currentCurve = geometryData.Curves[curveIndex]; if (currentCurve == null) { continue; } + // check the direction CurveDirection currentCurveDirection; if (index % 2 == 0) @@ -346,6 +353,7 @@ { continue; } + currentCurveDirection = CurveDirection.Forward; // get the direction of the current curve } else @@ -354,6 +362,7 @@ { continue; } + currentCurveDirection = CurveDirection.Reverse; // get the direction of the current curve } @@ -364,8 +373,8 @@ newLoopList.Add(newLoop); // initialise LoopBeginCurve - var loopBeginCurve = geometryData.Curves[curveIndex]; - var loopBeginDirection = currentCurveDirection; + GeometryCurve loopBeginCurve = geometryData.Curves[curveIndex]; + CurveDirection loopBeginDirection = currentCurveDirection; while (true) { @@ -383,21 +392,19 @@ //TODO:Show error message box break; } - else - { - return -1; - } + + return -1; } - var curveEndPoint = currentCurve.GetEndPoint(currentCurveDirection); + Point2D curveEndPoint = currentCurve.GetEndPoint(currentCurveDirection); attachedCurveList.Clear(); var minAngle = 365.0; var minIndex = 0; // find all the curves that are connected to the Current Curve at curveEndPoint - for (int index2 = 0; index2 < curvesCount; index2++) + for (var index2 = 0; index2 < curvesCount; index2++) { - var curve = geometryData.Curves[index2]; + GeometryCurve curve = geometryData.Curves[index2]; if (curve.LocationEquals(currentCurve)) // lets not get the reverse direction of the current curve here { continue; @@ -422,21 +429,19 @@ currentCurveDirection = oppCurrentDirection; continue; } - else - { - break; - } + + break; } // we have aValue1 set of curves, find the one that turns right the most if (attachedCurveList.Count > 1) { minIndex = -1; - var point1 = currentCurve.GetEndPoint(currentCurveDirection); - var point2 = currentCurve.GetHeadPoint(currentCurveDirection); + Point2D point1 = currentCurve.GetEndPoint(currentCurveDirection); + Point2D point2 = currentCurve.GetHeadPoint(currentCurveDirection); - for (int index2 = 0; index2 < attachedCurveList.Count; index2++) + for (var index2 = 0; index2 < attachedCurveList.Count; index2++) { var point3 = new Point2D(); var point4 = new Point2D(); @@ -446,7 +451,7 @@ point4.X = attachedCurveList[index2].GetEndPoint().X; point4.Z = attachedCurveList[index2].GetEndPoint().Z; - var angle = Routines2D.FindAngle(point1, point2, point3, point4); + double angle = Routines2D.FindAngle(point1, point2, point3, point4); if (angle < minAngle) { @@ -497,15 +502,16 @@ GeometrySurface newSurface; var newSurfaceList = new List(); - for (int index = 0; index < loopsCount; index++) + for (var index = 0; index < loopsCount; index++) { - var loop = aNewLoopList[index]; + GeometryLoop loop = aNewLoopList[index]; curvesCount = loop.CurveList.Count; if (curvesCount < 2) // dont create aValue1 surface for loops that have less than 2 curves { continue; } + if (curvesCount == 2) // if only 2 curves in loop, make sure they are distinct (non-repeated) { if (loop.CurveList[0] == loop.CurveList[1]) @@ -548,27 +554,29 @@ // clear the left and right surfaces for all curves (some curves will have redundant data) curvesCount = geometryData.Curves.Count; - for (int index = 0; index < curvesCount; index++) + for (var index = 0; index < curvesCount; index++) { geometryData.Curves[index].SurfaceAtRight = null; geometryData.Curves[index].SurfaceAtLeft = null; } // for the new surfaces -- assign the left/right surfaces for comprising curves, and find inner loops - var surfacesCount = newSurfaceList.Count; - for (int index = 0; index < surfacesCount; index++) + int surfacesCount = newSurfaceList.Count; + for (var index = 0; index < surfacesCount; index++) { newSurface = newSurfaceList[index]; AssignSurfaceAtLeftOrRightToCurves(newSurface); object newSurfaceObject = newSurface /*new object()*/; CheckAndAddInnerLoops(ref newSurfaceObject); //newSurface = (GeometrySurface)newSurfaceObject; } + if (newSurfacesGeoDtaObjectList.Count > 0) { var lNewSurfaces = new List(); GetNewlyDetectedSurfaces(ref lNewSurfaces); } + return surfacesCount; } @@ -585,13 +593,13 @@ return true; } - for (int index = 0; index < curvesCount; index++) + for (var index = 0; index < curvesCount; index++) { - var curve = aLoop.CurveList[index]; - var direction = geometryLoopDirections[aLoop][index]; + GeometryCurve curve = aLoop.CurveList[index]; + CurveDirection direction = geometryLoopDirections[aLoop][index]; var foundOppDirection = false; - for (int index1 = 0; index1 < curvesCount; index1++) + for (var index1 = 0; index1 < curvesCount; index1++) { if (index == index1) { @@ -610,6 +618,7 @@ return false; } } + return true; } @@ -624,9 +633,9 @@ return null; } - for (int index = 0; index < curvesCount; index++) + for (var index = 0; index < curvesCount; index++) { - var curve = aLoop.CurveList[index]; + GeometryCurve curve = aLoop.CurveList[index]; if (geometryLoopDirections[aLoop][index] == CurveDirection.Forward) { if (curve.SurfaceAtRight != null) @@ -649,7 +658,7 @@ var maxTimesSurfacesFound = 0; var noTimesSurfaceFound = 0; - for (int index1 = 0; index1 < curvesCount; index1++) + for (var index1 = 0; index1 < curvesCount; index1++) { if (geometryLoopDirections[aLoop][index] == CurveDirection.Forward) { @@ -673,6 +682,7 @@ reassignmentSurface = surface; } } + return reassignmentSurface; } @@ -685,7 +695,7 @@ { GeometryLoop loop = surface.OuterLoop; int curvesCount = loop.CurveList.Count; - bool isClockwise = true; + var isClockwise = true; try { @@ -700,7 +710,7 @@ Debug.WriteLine(e.Message); } - for (int index = 0; index < curvesCount; index++) + for (var index = 0; index < curvesCount; index++) { if (isClockwise) { @@ -731,15 +741,15 @@ { // clear the data int count = geometryData.Curves.Count; - for (int i = 0; i < count; i++) + for (var i = 0; i < count; i++) { geometryData.Curves[i].SurfaceAtLeft = null; geometryData.Curves[i].SurfaceAtRight = null; } // reset count = geometryData.Surfaces.Count; - for (int i = 0; i < count; i++) + for (var i = 0; i < count; i++) { AssignSurfaceAtLeftOrRightToCurves(geometryData.Surfaces[i]); } @@ -761,7 +771,7 @@ private void SetUpGeometryLoopDirections() { geometryLoopDirections.Clear(); - foreach (var loop in geometryData.Loops) + foreach (GeometryLoop loop in geometryData.Loops) { if (!geometryLoopDirections.ContainsKey(loop)) { @@ -790,7 +800,7 @@ } // the rest of the curves - for (int index1 = 1; index1 < aLoop.CurveList.Count; index1++) + for (var index1 = 1; index1 < aLoop.CurveList.Count; index1++) { if (loopPoint == aLoop.CurveList[index1].HeadPoint) { @@ -812,15 +822,15 @@ /// private void CheckAndAddInnerLoops(ref object aNewSurface) { - var newSurface = (GeometrySurface)aNewSurface; + var newSurface = (GeometrySurface) aNewSurface; int surfaceCount = geometryData.Surfaces.Count; - var newLoop = newSurface.OuterLoop; + GeometryLoop newLoop = newSurface.OuterLoop; int newPointCount = newLoop.CurveList.Count; List newPolygon = newLoop.CalcPoints; newSurface.InnerLoops.Clear(); - for (int index = 0; index < surfaceCount; index++) + for (var index = 0; index < surfaceCount; index++) { if (newSurface == geometryData.Surfaces[index]) { @@ -831,12 +841,12 @@ var outerPointCount = 0; var isOnPointCount = 0; var hasOnPointCount = 0; - var loop = geometryData.Surfaces[index].OuterLoop; - var polygon = loop.CalcPoints; - var existingLoopPointCount = polygon.Count; + GeometryLoop loop = geometryData.Surfaces[index].OuterLoop; + List polygon = loop.CalcPoints; + int existingLoopPointCount = polygon.Count; // check if it is an inner loop - for (int innerIndex = 0; innerIndex < newPointCount; innerIndex++) + for (var innerIndex = 0; innerIndex < newPointCount; innerIndex++) { PointInPolygon location = Routines2D.CheckIfPointIsInPolygon(loop, newPolygon[innerIndex].X, newPolygon[innerIndex].Z); @@ -851,7 +861,7 @@ } // check if it has an inner loop - for (int innerIndex1 = 0; innerIndex1 < existingLoopPointCount; innerIndex1++) + for (var innerIndex1 = 0; innerIndex1 < existingLoopPointCount; innerIndex1++) { PointInPolygon location = Routines2D.CheckIfPointIsInPolygon(newLoop, polygon[innerIndex1].X, polygon[innerIndex1].Z); @@ -892,42 +902,27 @@ internal struct DirectionCurve { - private readonly GeometryCurve curve; - private readonly CurveDirection direction; - internal DirectionCurve(GeometryCurve aCurve, CurveDirection aDirection) { - curve = aCurve; - direction = aDirection; + Curve = aCurve; + Direction = aDirection; } - internal GeometryCurve Curve - { - get - { - return curve; - } - } + internal GeometryCurve Curve { get; } - internal CurveDirection Direction - { - get - { - return direction; - } - } + internal CurveDirection Direction { get; } internal Point2D GetHeadPoint() { - return curve.GetHeadPoint(direction); + return Curve.GetHeadPoint(Direction); } internal Point2D GetEndPoint() { - return curve.GetEndPoint(direction); + return Curve.GetEndPoint(Direction); } } #endregion } -} +} \ No newline at end of file