public ptsDTMtriangleLine(ptsDTMpoint pt1, ptsDTMpoint pt2, ptsDTMtriangle tngle)
 {
     firstPoint = pt1;
      secondPoint = pt2;
      oneTriangle = tngle;
      theOtherTriangle = null;
 }
Example #2
0
        internal ptsDTMtriangle getTriangleContaining(ptsDTMpoint aPoint)
        {
            if (null == localGroupTriangles)
            localGroupTriangles = getTrianglesForPointInBB(aPoint).AsParallel().ToList();

             ptsDTMtriangle theTriangle =
            localGroupTriangles.FirstOrDefault(aTrngl => aTrngl.contains(aPoint));

             if (null == theTriangle)
             {
            localGroupTriangles = getTrianglesForPointInBB(aPoint).AsParallel().ToList();
            theTriangle =
               localGroupTriangles.FirstOrDefault(aTrngl => aTrngl.contains(aPoint));
             }

             return theTriangle;
        }
Example #3
0
        public void testGetTriangles(ptsDTMpoint aPoint)
        {
            aStopwatch = new Stopwatch();
             System.Console.WriteLine("given a point, return triangles by BB:");
             aStopwatch.Reset(); aStopwatch.Start();

             List<ptsDTMtriangle> triangleSubset = getTrianglesForPointInBB(aPoint) as List<ptsDTMtriangle>;

             aStopwatch.Stop(); consoleOutStopwatch(aStopwatch);
        }
Example #4
0
 public void loadFromXYZtextFile(string fileToOpen)
 {
     //ptsBoundingBox2d fileBB = new ptsBoundingBox2d()
      using (var inputFile = new StreamReader(fileToOpen))
      {
     String line;
     String[] values;
     while ((line = inputFile.ReadLine()) != null)
     {
        values = line.Split(',');
        if (values.Length != 3) continue;
        var newPt = new ptsDTMpoint(values[0], values[1], values[2]);
        GridDTMhelper.addPoint(newPt);
     }
      }
 }
Example #5
0
        public Azimuth getSlopeAzimuth(ptsDTMpoint aPoint)
        {
            ptsDTMtriangle aTriangle = getTriangleContaining(aPoint);
             if (null == aTriangle)
            return null;

             return aTriangle.givenXYgetSlopeAzimuth(aPoint);
        }
Example #6
0
 public static void addPoint(ptsDTMpoint pt)
 {
     long xGrid = (long)Math.Floor(pt.x / GridSize);
      long yGrid = (long)Math.Floor(pt.y / GridSize);
      addPoint_(new XYtuple(xGrid, yGrid), pt);
 }
 double sign(ptsDTMpoint p1, ptsDTMpoint p2, ptsDTMpoint p3)
 {
     return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y);
 }
Example #8
0
        private void LoadTINfromLandXML(string fileName)
        {
            if (!(String.Compare(Path.GetExtension(fileName), ".xml", true) == 0))
             {
            throw new ArgumentException("Filename must have xml extension.");
             }

             memoryUsed = GC.GetTotalMemory(true);
             Stopwatch stopwatch = new Stopwatch();
             List<string> trianglesAsStrings;
             setupStopWatches();

             scratchUIntPair = new UInt64pair();

             System.Console.WriteLine("Load XML document took:");
             stopwatch.Reset(); stopwatch.Start();
             LoadTimeStopwatch.Reset(); LoadTimeStopwatch.Start();
             using (XmlTextReader reader = new XmlTextReader(fileName))
             {
            stopwatch.Stop();  consoleOutStopwatch(stopwatch);
            System.Console.WriteLine("Seeking Pnts collection took:");
            stopwatch.Reset();    stopwatch.Start();
            reader.MoveToContent();
            reader.ReadToDescendant("Surface");
            string astr = reader.GetAttribute("name");

            // Read Points
            reader.ReadToDescendant("Pnts");
            stopwatch.Stop();  consoleOutStopwatch(stopwatch);

            System.Console.WriteLine("Loading All Points took:");
            stopwatch.Reset();    stopwatch.Start();
            reader.Read();
            while (!(reader.Name.Equals("Pnts") && reader.NodeType.Equals(XmlNodeType.EndElement)))
            {
               UInt64 id;
               if (reader.NodeType.Equals(XmlNodeType.Element))
               {
                  UInt64.TryParse(reader.GetAttribute("id"), out id);
                  reader.Read();
                  if (reader.NodeType.Equals(XmlNodeType.Text))
                  {
                     scratchPoint = new ptsDTMpoint(reader.Value, id);
                     if (allPoints == null)
                     {
                        createAllpointsCollection();

                        myBoundingBox = new ptsBoundingBox2d(scratchPoint.x, scratchPoint.y, scratchPoint.x, scratchPoint.y);
                     }
                     allPoints.Add(id, scratchPoint);
                     myBoundingBox.expandByPoint(scratchPoint.x, scratchPoint.y, scratchPoint.z);
                  }
               }
               reader.Read();
            }

            // Read Triangles, but only as strings
            stopwatch.Stop();  consoleOutStopwatch(stopwatch);
            System.Console.WriteLine(allPoints.Count.ToString() + " Points Total.");

            System.Console.WriteLine("Loading Triangle Reference Strings took:");
            stopwatch.Reset();    stopwatch.Start();
            trianglesAsStrings = new List<string>();
            if (!(reader.Name.Equals("Faces")))
            {
               reader.ReadToFollowing("Faces");
            }
            reader.Read();
            while (!(reader.Name.Equals("Faces") && reader.NodeType.Equals(XmlNodeType.EndElement)))
            {
               if (reader.NodeType.Equals(XmlNodeType.Text))
               {
                  trianglesAsStrings.Add(reader.Value);
               }
               reader.Read();
            }
            reader.Close();
            stopwatch.Stop();  consoleOutStopwatch(stopwatch);

            System.Console.WriteLine("Generating Triangle Collection took:");
            stopwatch.Reset();    stopwatch.Start();
             }

             // assemble the allTriangles collection
             //allTriangles = new List<ptsDTMtriangle>(trianglesAsStrings.Count);
             allTrianglesBag = new ConcurrentBag<ptsDTMtriangle>();
             Parallel.ForEach(trianglesAsStrings, refString =>
            {
               allTrianglesBag.Add(new ptsDTMtriangle(allPoints, refString));
            }
            );
             allTriangles = allTrianglesBag.OrderBy(triangle => triangle.point1.x).ToList();
             trianglesAsStrings = null; allTrianglesBag = null;
             GC.Collect(); GC.WaitForPendingFinalizers();
             memoryUsed = GC.GetTotalMemory(true) - memoryUsed;
             LoadTimeStopwatch.Stop();

             stopwatch.Stop();
             System.Console.WriteLine(allTriangles.Count().ToString() + " Total Triangles.");
             consoleOutStopwatch(stopwatch);

             //
             //System.Console.WriteLine("Indexing Triangles for adjacency took:");
             //stopwatch.Reset(); stopwatch.Start();
             //generateTriangleLineIndex();  start here
             //stopwatch.Stop(); consoleOutStopwatch(stopwatch);
        }
 public bool isPointInBoundingBox(ptsDTMpoint aPoint)
 {
     return myBoundingBox_.isPointInsideBB2d(aPoint.x, aPoint.y);
 }
        // adapted from
        // http://stackoverflow.com/questions/2049582/how-to-determine-a-point-in-a-triangle
        internal bool contains(ptsDTMpoint aPoint)
        {
            bool b1, b2, b3;

             b1 = sign(aPoint, point1, point2) < 0.0f;
             b2 = sign(aPoint, point2, point3) < 0.0f;
             b3 = sign(aPoint, point3, point1) < 0.0f;

             return ((b1 == b2) && (b2 == b3));
        }
        // End: adapted from
        public double givenXYgetZ(ptsDTMpoint aPoint)
        {
            // Use equation         ax + bx
             //                 z = ----------     taken from Wolfram Alpha
             //                        -c
             //
             //  where a is normalVec_.i, b is .j, and c is .k
             //    and X is aPoint.x - point1.x
             //    and Y is aPoint.y - point1.y
             //
             //  Ultimately add z to point1.z to get the elevation

             double X = aPoint.x - point1.x;
             double Y = aPoint.y - point1.y;

             double Z = ((normalVec.x * X) + (normalVec.y * Y)) /
                     (-1.0 * normalVec.z);

             return Z + point1.z;
        }
        public double? givenXYgetSlopePercent(ptsDTMpoint aPoint)
        {
            var normalVector = this.normalVec;
             if (0.0 == normalVector.z) return null;

             return Math.Abs (100.0 *
            Math.Sqrt(normalVector.x * normalVector.x + normalVector.y * normalVector.y) /
                        normalVector.z);
        }
        // Constructor to construct from an xml file
        public ptsDTM(string fileName)
        {
            if (!(String.Compare(Path.GetExtension(fileName), "xml", true) == 0))
             {
            //throw new notAnXMLfileException();
             }

             setupStopWatches();

             System.Console.WriteLine("");
             System.Console.WriteLine("Load XML document");
             XDocument tinXMLdoc = XDocument.Load(fileName);
             System.Console.WriteLine("Seeking Pnts collection");
             XElement root = tinXMLdoc.Elements().ToList<XElement>()[0];
             List<XElement> allXelements = root.Elements().ToList<XElement>();
             foreach (XElement anElement in allXelements)
             {
            if (String.Compare(anElement.Name.ToString(), "Surfaces") == 0)
            {
               System.Console.WriteLine("Found Surfaces Collection");
               XElement surfacesXE = anElement;
               XElement srface = surfacesXE.Elements().ToList<XElement>()[0];
               List<XElement> srfcElements = srface.Elements().ToList<XElement>();
               foreach (XElement aSubElement in srfcElements)
               {
                  if (String.Compare(aSubElement.Name.ToString(), "Definition") == 0)
                  {
                     List<XElement> dfinitionElements = aSubElement.Elements().ToList<XElement>();
                     foreach (XElement subDef in dfinitionElements)
                     {
                        System.Console.WriteLine(subDef.Name);
                        if (String.Compare(subDef.Name.ToString(), "Pnts") == 0)
                        {
                           System.Console.WriteLine("Found Pnts collection");
                           stpWatches["Process Points"].Start();
                           List<XElement> pnts = subDef.Elements().ToList<XElement>();
                           foreach (XElement pnt in pnts)
                           {
                              scratchPoint = new ptsDTMpoint(pnt.Value);
                              UInt64 index;
                              UInt64.TryParse(pnt.FirstAttribute.Value, out index);
                              if (null == allPoints)
                                 allPoints = new Dictionary<UInt64, ptsDTMpoint>();
                              allPoints.Add(index, scratchPoint);
                           }
                           pnts = null;
                           GC.Collect();   GC.WaitForPendingFinalizers();
                           stpWatches["Process Points"].Stop();
                           System.Console.WriteLine("Processing Points took:");
                           consoleOutStopwatch(stpWatches["Process Points"]);
                        }
                        if (String.Compare(subDef.Name.ToString(), "Faces") == 0)
                        {
                           ulong count;
                           count = 0;
                           stpWatches["Process Triangles"].Start();
                           List<XElement> faces = subDef.Elements().ToList<XElement>();
                           foreach (XElement aFace in faces)
                           {
                              count++;
                              scratchTriangle = new ptsDTMtriangle(allPoints, aFace.Value.ToString());
                              if (null == allTriangles_genList)
                                 allTriangles_genList = new List<ptsDTMtriangle>();
                              allTriangles_genList.Add(scratchTriangle);
                              if ((count % 100000) == 0) System.Console.WriteLine("{0} Triangles so far.", count);
                              //To Do: start here: Add function to get Indexes of points
                              //    and assign to each triangle
                              // or just hold the indices for now -- not sure -- sleep on it
                           }
                           System.Console.WriteLine("Total Triangles = {0}", count);
                           System.Console.WriteLine("Freeing Faces collection");
                           faces = null;
                           GC.Collect();   GC.WaitForPendingFinalizers();
                           System.Console.WriteLine("Copying triangle list to array");
                           allTriangles = allTriangles_genList.ToArray<ptsDTMtriangle>();
                           System.Console.WriteLine("Freeing triangle list");
                           allTriangles_genList = null;
                           GC.Collect();   GC.WaitForPendingFinalizers();

                           System.Console.WriteLine("Sorting Triangle Array in x");
                           Array.Sort(allTriangles);

                           System.Console.WriteLine("Sorting Triangle Array in y");
                           //not yet implemented

                           stpWatches["Process Triangles"].Stop();
                           System.Console.WriteLine("Processing Triangles took:");
                           consoleOutStopwatch(stpWatches["Process Triangles"]);
                        }

                        // all processing is complete by this point
                     }
                  }
               }
            }
             }
             tinXMLdoc = null;
             GC.Collect();   GC.WaitForPendingFinalizers();
        }
Example #14
0
 internal List<ptsDTMtriangle> getTrianglesForPointInBB(ptsDTMpoint aPoint)
 {
     return  (from ptsDTMtriangle triangle in allTriangles.AsParallel()
                   where triangle.isPointInBoundingBox(aPoint)
                   select triangle).ToList<ptsDTMtriangle>();
 }
        public Azimuth givenXYgetSlopeAzimuth(ptsDTMpoint aPoint)
        {
            Azimuth slopeAz = new Azimuth();
             slopeAz.setFromXY(this.normalVec.y, this.normalVec.x);

             return slopeAz;
        }
Example #16
0
        private ptsDTMpoint convertLineOfDataToPoint(string line, ulong pointIndex)
        {
            ptsDTMpoint newPt;
             string[] preParsedLine = line.Split(',');
             string[] parsedLine = preParsedLine[preParsedLine.Length-1].Split(' ');

             newPt = new ptsDTMpoint(
            pointIndex,
            Convert.ToDouble(parsedLine[0]),
            Convert.ToDouble(parsedLine[1]),
            Convert.ToDouble(parsedLine[2]));

             return newPt;
        }
Example #17
0
        public double? getElevation(ptsDTMpoint aPoint)
        {
            spinWaitForBoundingBox(2000);
             if (null == this.myBoundingBox) return null;
             ptsDTMtriangle aTriangle = getTriangleContaining(aPoint);
             if (null == aTriangle)
            return null;

             return aTriangle.givenXYgetZ(aPoint);
        }
Example #18
0
        private void LoadTINfromVRML(string fileName)
        {
            string line;
             long lineCount = 0;
             if (!(String.Compare(Path.GetExtension(fileName), ".wrl", true) == 0))
             {
            throw new ArgumentException("Filename must have wrl extension.");
             }

             System.IO.StreamReader file = new System.IO.StreamReader(fileName);
             try
             {
            while ((line = file.ReadLine()) != null)
            {
               if (false == validateVRMLfileHeader(line))
                  throw new System.IO.InvalidDataException("File not in VRML2 format.");
               break;
            }

            lineCount++;
            while ((line = file.ReadLine()) != null)
            {
               lineCount++;
               if(line.Equals("IndexedFaceSet"))
                  break;
            }

            while ((line = file.ReadLine()) != null)
            {
               lineCount++;
               if (line.Equals("point"))
               {
                  line = file.ReadLine();  // eat the open brace,  [
                  break;
               }
            }

            ulong ptIndex=0;
            while ((line = file.ReadLine()) != null)
            {
               lineCount++;
               // Read until the close brace,  [
               if(line.Equals("]"))
                  break;
               scratchPoint = convertLineOfDataToPoint(line, ptIndex);
               if (allPoints == null)
               {
                  createAllpointsCollection();
                  myBoundingBox = new ptsBoundingBox2d(scratchPoint.x, scratchPoint.y,scratchPoint.x, scratchPoint.y);
               }
               allPoints.Add(ptIndex, scratchPoint);
               ptIndex++;
               myBoundingBox.expandByPoint(scratchPoint.x, scratchPoint.y, scratchPoint.z);
            }

            while ((line = file.ReadLine()) != null)
            {
               lineCount++;
               if (line.Equals("coordIndex"))
               {
                  line = file.ReadLine();  // eat the open brace,  [
                  break;
               }
            }

            var allTriangles_ = new List<ptsDTMtriangle>();
            while ((line = file.ReadLine()) != null)
            {
               lineCount++;
               // Read until the close brace,  [
               if (line.Equals("]"))
                  break;
               scratchTriangle = convertLineOfDataToTriangle(line);
               allTriangles_.Add(scratchTriangle);
            }

            allTriangles_.Sort();
            allTriangles = allTriangles_.ToList();
             }
             finally
             {
            file.Close();
             }
        }
Example #19
0
        public double? getSlope(ptsDTMpoint aPoint)
        {
            ptsDTMtriangle aTriangle = getTriangleContaining(aPoint);
             if (null == aTriangle)
            return null;

             return aTriangle.givenXYgetSlopePercent(aPoint);
        }
Example #20
0
 private static void addPoint_(XYtuple tupl, ptsDTMpoint pt)
 {
     if (false == grid.ContainsKey(tupl))
      {
     var ptList = new List<ptsDTMpoint>();
     ptList.Add(pt);
     grid.Add(tupl, ptList);
      }
      else
      {
     grid[tupl].Add(pt);
      }
 }
Example #21
0
 public static ptsDTMpoint getAveragePoint(ptsDTMpoint pt1, ptsDTMpoint pt2, ptsDTMpoint pt3)
 {
     return new ptsDTMpoint(
     (pt1.x + pt2.x + pt3.x) / 3.0,
     (pt1.y + pt2.y + pt3.y) / 3.0,
     (pt1.z + pt2.z + pt3.z) / 3.0
     );
 }