protected override bool GetNextSliverArea(out double area, out double perimeter) { _latestPartSegments = null; if (!_enumValid) { area = double.NaN; perimeter = double.NaN; return(false); } SegmentProxy segment = Assert.NotNull(_segmentsEnum.Current); int currentPart = segment.PartIndex; int segmentCount = _indexedMultiPatch.GetPartSegmentCount(currentPart); var partSegments = new List <SegmentProxy>(segmentCount) { segment }; while ((_enumValid = _segmentsEnum.MoveNext()) && Assert.NotNull(_segmentsEnum.Current).PartIndex == currentPart) { partSegments.Add(_segmentsEnum.Current); } List <Pnt> planePoints = QaGeometryUtils.GetPoints(partSegments); Plane plane = QaGeometryUtils.CreatePlane((IEnumerable <SegmentProxy>)partSegments); QaGeometryUtils.CalculateProjectedArea(plane, planePoints, out area, out perimeter); _latestPartSegments = partSegments; return(true); }
private void ValidateTri(List <WKSPointZ> wksPointZs, bool isDefined) { List <Pnt> points = wksPointZs.Select(wksPointZ => QaGeometryUtils.CreatePoint3D(wksPointZ)).ToList(); var pointsWithoutEndPoint = new List <Pnt>(points); pointsWithoutEndPoint.RemoveAt(points.Count - 1); Plane plane = QaGeometryUtils.CreatePlane(pointsWithoutEndPoint); Assert.True(plane.IsDefined == isDefined); }
public void IsPlaneVerticalTest() { var construction = new MultiPatchConstruction(); construction.StartRing(0, 0, 0) .Add(5, 0, 0) .Add(5, 0, 5) .Add(0, 0, 5); IMultiPatch multiPatch = construction.MultiPatch; IIndexedMultiPatch indexedMultiPatch = QaGeometryUtils.CreateIndexedMultiPatch(multiPatch); Plane plane = QaGeometryUtils.CreatePlane(indexedMultiPatch.GetSegments()); WKSPointZ normal = plane.GetNormalVector(); Assert.AreEqual(0, normal.Z); }
public void CanProjectToPlaneTest() { var construction = new MultiPatchConstruction(); construction.StartRing(0, 0, 0) .Add(5, 0, 0) .Add(5, 0, 5) .Add(0, 0, 5); IMultiPatch multiPatch = construction.MultiPatch; IIndexedMultiPatch indexedMultiPatch = QaGeometryUtils.CreateIndexedMultiPatch(multiPatch); IList <Pnt> points = QaGeometryUtils.GetPoints(indexedMultiPatch.GetSegments()); Plane plane = QaGeometryUtils.CreatePlane(points); IList <WKSPointZ> projected = QaGeometryUtils.ProjectToPlane(plane, points); ValidateForm(indexedMultiPatch, projected); }
public override VerticalFace ReadFace() { _latestPartSegments = null; if (!_enumValid) { return(null); } int currentPart = Assert.NotNull(_segmentsEnum.Current).PartIndex; int segmentCount = _indexedSegments.GetPartSegmentCount(currentPart); var partSegments = new List <SegmentProxy>(segmentCount) { _segmentsEnum.Current }; if (_segmentsEnum.Current == null) { return(null); } double zMin = _segmentsEnum.Current.GetStart(true)[2]; double zMax = zMin; while ((_enumValid = _segmentsEnum.MoveNext()) && Assert.NotNull(_segmentsEnum.Current).PartIndex == currentPart) { partSegments.Add(_segmentsEnum.Current); if (_segmentsEnum.Current != null) { double z = _segmentsEnum.Current.GetStart(true)[2]; zMin = Math.Min(z, zMin); zMax = Math.Max(z, zMax); } } Plane plane = QaGeometryUtils.CreatePlane((IEnumerable <SegmentProxy>)partSegments); _latestPartSegments = partSegments; return(new VerticalFace(plane, zMax - zMin)); }
public void CanCalculateVerticalProjectedAreaDiagonalXY() { var wksPointZs = new List <WKSPointZ> { new WKSPointZ { X = 0, Y = 0, Z = 0 }, new WKSPointZ { X = 10, Y = 10, Z = 0 }, new WKSPointZ { X = 10, Y = 10, Z = 10 }, new WKSPointZ { X = 0, Y = 0, Z = 10 }, new WKSPointZ { X = 0, Y = 0, Z = 0 } }; List <Pnt> points = wksPointZs.Select(wksPointZ => QaGeometryUtils.CreatePoint3D(wksPointZ)).ToList(); var pointsWithoutEndPoint = new List <Pnt>(points); pointsWithoutEndPoint.RemoveAt(points.Count - 1); Plane plane = QaGeometryUtils.CreatePlane(pointsWithoutEndPoint); double area; double perimeter; QaGeometryUtils.CalculateProjectedArea(plane, points, out area, out perimeter); Console.WriteLine(@"area: {0} perimeter: {1}", area, perimeter); const double e = 0.0000001; Assert.AreEqual(141.421356237309, Math.Abs(area), e); Assert.AreEqual(48.2842712474619, perimeter, e); }
public void CanCalculateVerticalProjectedAreaConstantX2() { // using coordinates from an actual building face (exactly north-south oriented) var wksPointZs = new List <WKSPointZ> { new WKSPointZ { X = 2722584.8725, Y = 1252311.12875, Z = 618.42624999999 }, new WKSPointZ { X = 2722584.8725, Y = 1252309.3725, Z = 619.654999999984 }, new WKSPointZ { X = 2722584.8725, Y = 1252304.75375, Z = 616.388749999984 }, new WKSPointZ { X = 2722584.8725, Y = 1252311.12875, Z = 618.42624999999 } }; List <Pnt> points = wksPointZs.Select(wksPointZ => QaGeometryUtils.CreatePoint3D(wksPointZ)).ToList(); var pointsWithoutEndPoint = new List <Pnt>(points); pointsWithoutEndPoint.RemoveAt(points.Count - 1); Plane plane = QaGeometryUtils.CreatePlane(pointsWithoutEndPoint); double area; double perimeter; QaGeometryUtils.CalculateProjectedArea(plane, points, out area, out perimeter); Console.WriteLine(@"area: {0} perimeter: {1}", area, perimeter); const double e = 0.000001; Assert.AreEqual(5.70582031258122, Math.Abs(area), e); Assert.AreEqual(14.4930667883504, perimeter, e); }
public void CanCalculateHorizontalProjectedArea() { var wksPointZs = new List <WKSPointZ> { new WKSPointZ { X = 0, Y = 0, Z = 0 }, new WKSPointZ { X = 10, Y = 0, Z = 0 }, new WKSPointZ { X = 10, Y = 10, Z = 0 }, new WKSPointZ { X = 0, Y = 10, Z = 0 }, new WKSPointZ { X = 0, Y = 0, Z = 0 } }; List <Pnt> points = wksPointZs.Select(wksPointZ => QaGeometryUtils.CreatePoint3D(wksPointZ)).ToList(); var pointsWithoutEndPoint = new List <Pnt>(points); pointsWithoutEndPoint.RemoveAt(points.Count - 1); Plane plane = QaGeometryUtils.CreatePlane(pointsWithoutEndPoint); double area; double perimeter; QaGeometryUtils.CalculateProjectedArea(plane, points, out area, out perimeter); Console.WriteLine(@"area: {0} perimeter: {1}", area, perimeter); Assert.AreEqual(100, Math.Abs(area)); Assert.AreEqual(40, perimeter); }
private void Initialize() { _indexedMultipatch = GetAdaptedMultiPatch(); IMultiPatch multiPatch = _indexedMultipatch.BaseGeometry; _verticalFaceSegments = new List <SegmentProxy>(); var patches = (IGeometryCollection)multiPatch; var verticalPatchParts = new Dictionary <int, List <int> >(); int patchCount = patches.GeometryCount; for (int patchIndex = 0; patchIndex < patchCount; patchIndex++) { List <int> partIndexes = _indexedMultipatch.GetPartIndexes(patchIndex); foreach (int partIndex in partIndexes) { int partSegmentCount = _indexedMultipatch.GetPartSegmentCount(partIndex); var segments = new List <SegmentProxy>(partSegmentCount); for (int segmentIndex = 0; segmentIndex < partSegmentCount; segmentIndex++) { segments.Add( _indexedMultipatch.GetSegment(partIndex, segmentIndex)); } Plane plane = QaGeometryUtils.CreatePlane( (IEnumerable <SegmentProxy>)segments); if (Math.Abs(plane.GetNormalVector().Z) < double.Epsilon) { List <int> verticalParts; if (!verticalPatchParts.TryGetValue( patchIndex, out verticalParts)) { verticalParts = new List <int>(); verticalPatchParts.Add(patchIndex, verticalParts); } verticalParts.Add(partIndex); _verticalFaceSegments.AddRange(segments); } } } if (verticalPatchParts.Count > 0) { object missing = Type.Missing; IMultiPatch nonVerticalMultiPatch = new MultiPatchClass { SpatialReference = multiPatch.SpatialReference }; for (int patchIndex = 0; patchIndex < patchCount; patchIndex++) { List <int> verticalParts; IGeometry patch = ((IGeometryCollection)multiPatch).Geometry[patchIndex]; if (!verticalPatchParts.TryGetValue( patchIndex, out verticalParts)) { IGeometry clone = GeometryFactory.Clone(patch); ((IGeometryCollection)nonVerticalMultiPatch).AddGeometry( clone, ref missing, ref missing); var ring = patch as IRing; if (ring != null) { bool isBeginning = false; esriMultiPatchRingType ringType = multiPatch.GetRingType(ring, ref isBeginning); nonVerticalMultiPatch.PutRingType( (IRing)clone, ringType); } } else { if (patch is IRing) { continue; } List <int> partIndexes = _indexedMultipatch.GetPartIndexes(patchIndex); foreach (int partIndex in partIndexes) { if (verticalParts.Contains(partIndex)) { continue; } int partSegmentCount = _indexedMultipatch.GetPartSegmentCount(partIndex); var points = new List <WKSPointZ>(3); for (int segmentIndex = 0; segmentIndex < partSegmentCount; segmentIndex++) { SegmentProxy segment = _indexedMultipatch.GetSegment( partIndex, segmentIndex); const bool as3D = true; Pnt p = segment.GetStart(as3D); points.Add( WKSPointZUtils.CreatePoint(p.X, p.Y, p[2])); } IRing ring = CreateRing(points); ((IGeometryCollection)nonVerticalMultiPatch).AddGeometry( ring, ref missing, ref missing); } } } _nonVerticalMultipatch = nonVerticalMultiPatch; } else { _nonVerticalMultipatch = multiPatch; } }