Exemplo n.º 1
0
 public void computeBoundingBox()
 {
     myBoundingBox_ = new ptsBoundingBox2d
     (point1.x, point1.y, point1.z,
     point1.x, point1.y, point1.z);
      myBoundingBox_.expandByPoint(point2.x, point2.y, point2.z);
      myBoundingBox_.expandByPoint(point3.x, point3.y, point3.z);
 }
Exemplo n.º 2
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();
             }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
 private ptsBoundingBox2d ComputeBB()
 {
     Debug.WriteLine("Starting ComputeBB on {0}.", Thread.CurrentThread.ManagedThreadId);
      Stopwatch sw = new Stopwatch(); sw.Start();
      var point1 = this.allPoints.FirstOrDefault().Value;
      var returnBB = new ptsBoundingBox2d(
     point1.x, point1.y, point1.z, point1.x, point1.y, point1.z);
      Parallel.ForEach(this.allPoints,
     p => returnBB.expandByPoint(p.Value.x, p.Value.y, p.Value.z)
     );
      sw.Stop();
      Debug.WriteLine(String.Format("Compute BB took {0}", sw.Elapsed));
      return returnBB;
 }