Exemplo n.º 1
0
  public void fpMeshPoints()
  {
      List <Vector3d> points  = new List <Vector3d>();
      List <int>      tris    = new List <int>();
      List <Vector3d> normals = new List <Vector3d>();
      float           normal  = .01f;

//string toPull = ReadString();
//string[] linesInFile = toPull.Split('\n');

      foreach (var pointCloud in ARpoints.trackables)
      {
//Debug.Log ("Lit" +pointCloud.transform.localPosition);
          int counter   = 0;
          var visualize = GameObject.FindWithTag("allPoints").GetComponent <UnityEngine.XR.ARFoundation.ARAllPointCloudPointsParticleVisualizer>();
          foreach (var kvp in visualize.m_Points)
          {
              counter++;
              points.Add(kvp.Value);
              tris.Add(counter);
              tris.Add(counter);
              tris.Add(counter);

              normals.Add(new Vector3d(normal, normal, normal));
          }
      }



      DMesh3         pointSet = DMesh3Builder.Build(points, tris, normals);
      PointAABBTree3 bvtree   = new PointAABBTree3(pointSet, true);

      bvtree.FastWindingNumber(Vector3d.Zero);
// estimate point area based on nearest-neighbour distance
      double[] areas = new double[pointSet.MaxVertexID];
      foreach (int vid in pointSet.VertexIndices())
      {
          bvtree.PointFilterF = (i) => { return(i != vid); }; // otherwise vid is nearest to vid!
          int    near_vid = bvtree.FindNearestPoint(pointSet.GetVertex(vid));
          double dist     = pointSet.GetVertex(vid).Distance(pointSet.GetVertex(near_vid));
          areas[vid] = Circle2d.RadiusArea(dist);
      }
      bvtree.FWNAreaEstimateF = (vid) => {
          return(areas[vid]);
      };
      MarchingCubes mc = new MarchingCubes();

      mc.Implicit = new PWNImplicit()
      {
          Spatial = bvtree
      };
      mc.IsoValue = 0.0;
      mc.CubeSize = bvtree.Bounds.MaxDim / 10;
      mc.Bounds   = bvtree.Bounds.Expanded(mc.CubeSize * 3);
      mc.RootMode = MarchingCubes.RootfindingModes.Bisection;
      mc.Generate();
      DMesh3 resultMesh = mc.Mesh;

      g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh);

      /*  MarchingCubes mc = new MarchingCubes();
       *   mc.Implicit = new PWNImplicit() { Spatial =  bvtree };
       *   mc.IsoValue = 0.0;
       *   mc.CubeSize = bvtree.Bounds.MaxDim / 10;
       *   mc.Bounds =  bvtree.Bounds.Expanded(mc.CubeSize * 3);
       *   mc.RootMode = MarchingCubes.RootfindingModes.Bisection;
       *   mc.Generate();
       *   DMesh3 resultMesh = mc.Mesh;
       *   g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh);
       */
  }
Exemplo n.º 2
0
 public double Value(ref Vector3d pt)
 {
     return(-(Spatial.FastWindingNumber(pt) - 0.5));
 }
Exemplo n.º 3
0
  public void takePointsinandAddtoMesh(List <Vector3d> pointers)
  {
      List <int>      tris    = new List <int>();
      List <Vector3d> normals = new List <Vector3d>();
      float           normal  = .01f;



      if (currentMesh == null)
      {
//ok so first mesh is not been created yet so create it from the first frame
          int counter = 0;
          foreach (Vector3d line in pointers)
          {
              counter++;
//Debug.Log(line);
              tris.Add(counter);
              tris.Add(counter);
              tris.Add(counter);

              normals.Add(new Vector3d(normal, normal, normal));
          }

          DMesh3         pointSet = DMesh3Builder.Build(pointers, tris, normals);
          PointAABBTree3 bvtree   = new PointAABBTree3(pointSet, true);
          bvtree.FastWindingNumber(Vector3d.Zero);
// estimate point area based on nearest-neighbour distance
          double[] areas = new double[pointSet.MaxVertexID];
          foreach (int vid in pointSet.VertexIndices())
          {
              bvtree.PointFilterF = (i) => { return(i != vid); }; // otherwise vid is nearest to vid!
              int    near_vid = bvtree.FindNearestPoint(pointSet.GetVertex(vid));
              double dist     = pointSet.GetVertex(vid).Distance(pointSet.GetVertex(near_vid));
              areas[vid] = Circle2d.RadiusArea(dist);
          }
          bvtree.FWNAreaEstimateF = (vid) => {
              return(areas[vid]);
          };
          MarchingCubes mc = new MarchingCubes();
          mc.Implicit = new PWNImplicit()
          {
              Spatial = bvtree
          };
          mc.IsoValue = 0.0;
          mc.CubeSize = bvtree.Bounds.MaxDim / 10;
          mc.Bounds   = bvtree.Bounds.Expanded(mc.CubeSize * 3);
          mc.RootMode = MarchingCubes.RootfindingModes.Bisection;
          mc.Generate();
          DMesh3 resultMesh = mc.Mesh;
          //  g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh);
          currentMesh = resultMesh;
      }
      else
      {
//ok so this is where we are proscessing second mesh
          int counter = 0;
          foreach (Vector3d line in pointers)
          {
              counter++;
//Debug.Log(line);
              tris.Add(counter);
              tris.Add(counter);
              tris.Add(counter);

              normals.Add(new Vector3d(normal, normal, normal));
          }

          DMesh3         pointSet = DMesh3Builder.Build(pointers, tris, normals);
          PointAABBTree3 bvtree   = new PointAABBTree3(pointSet, true);
          bvtree.FastWindingNumber(Vector3d.Zero);
// estimate point area based on nearest-neighbour distance
          double[] areas = new double[pointSet.MaxVertexID];
          foreach (int vid in pointSet.VertexIndices())
          {
              bvtree.PointFilterF = (i) => { return(i != vid); }; // otherwise vid is nearest to vid!
              int    near_vid = bvtree.FindNearestPoint(pointSet.GetVertex(vid));
              double dist     = pointSet.GetVertex(vid).Distance(pointSet.GetVertex(near_vid));
              areas[vid] = Circle2d.RadiusArea(dist);
          }
          bvtree.FWNAreaEstimateF = (vid) => {
              return(areas[vid]);
          };
          MarchingCubes mc = new MarchingCubes();
          mc.Implicit = new PWNImplicit()
          {
              Spatial = bvtree
          };
          mc.IsoValue = 0.0;
          mc.CubeSize = bvtree.Bounds.MaxDim / 10;
          mc.Bounds   = bvtree.Bounds.Expanded(mc.CubeSize * 3);
          mc.RootMode = MarchingCubes.RootfindingModes.Bisection;
          mc.Generate();
          DMesh3     resultMesh = mc.Mesh;
          MeshEditor editor     = new MeshEditor(currentMesh);

          editor.AppendMesh(resultMesh, currentMesh.AllocateTriangleGroup());
//suspected its crashing after mesh is over 64000 faces,
          faceLog.text = "Vertex Count =  " + transform.gameObject.GetComponent <MeshFilter>().mesh.triangles.Length;

          g3UnityUtils.SetGOMesh(transform.gameObject, currentMesh);
      }
  }
Exemplo n.º 4
0
  public void fpMeshPointsfromTextFileWithaSecondPoints()
  {
//this is used in the fast points winding scene to optimize algorithm and make sure its working well
//it reads points via text files and then meshes them
      List <Vector3d> points  = new List <Vector3d>();
      List <int>      tris    = new List <int>();
      List <Vector3d> normals = new List <Vector3d>();
      float           normal  = .01f;

      string toPull = ReadString();

      string[] linesInFile = toPull.Split('\n');

      int counter = 0;

      foreach (string line in linesInFile)
      {
          counter++;
//Debug.Log(line);

          if (!string.IsNullOrEmpty(line))
          {
              points.Add(StringToVector3(line));
              tris.Add(counter);
              tris.Add(counter);
              tris.Add(counter);

              normals.Add(new Vector3d(normal, normal, normal));
          }
      }

      DMesh3         pointSet = DMesh3Builder.Build(points, tris, normals);
      PointAABBTree3 bvtree   = new PointAABBTree3(pointSet, true);

      bvtree.FastWindingNumber(Vector3d.Zero);
// estimate point area based on nearest-neighbour distance
      double[] areas = new double[pointSet.MaxVertexID];
      foreach (int vid in pointSet.VertexIndices())
      {
          bvtree.PointFilterF = (i) => { return(i != vid); }; // otherwise vid is nearest to vid!
          int    near_vid = bvtree.FindNearestPoint(pointSet.GetVertex(vid));
          double dist     = pointSet.GetVertex(vid).Distance(pointSet.GetVertex(near_vid));
          areas[vid] = Circle2d.RadiusArea(dist);
      }
      bvtree.FWNAreaEstimateF = (vid) => {
          return(areas[vid]);
      };
      MarchingCubes mc = new MarchingCubes();

      mc.Implicit = new PWNImplicit()
      {
          Spatial = bvtree
      };
      mc.IsoValue = 0.0;
      mc.CubeSize = bvtree.Bounds.MaxDim / 50;
      mc.Bounds   = bvtree.Bounds.Expanded(mc.CubeSize * 3);
      mc.RootMode = MarchingCubes.RootfindingModes.Bisection;
      mc.Generate();
      DMesh3 resultMesh = mc.Mesh;

      g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh);

      /*  MarchingCubes mc = new MarchingCubes();
       *   mc.Implicit = new PWNImplicit() { Spatial =  bvtree };
       *   mc.IsoValue = 0.0;
       *   mc.CubeSize = bvtree.Bounds.MaxDim / 10;
       *   mc.Bounds =  bvtree.Bounds.Expanded(mc.CubeSize * 3);
       *   mc.RootMode = MarchingCubes.RootfindingModes.Bisection;
       *   mc.Generate();
       *   DMesh3 resultMesh = mc.Mesh;
       *   g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh);
       */
//ok now that we meshed the first point set, lets try to take in a second frame of points and then add to orginal dmesh
      points  = new List <Vector3d>();
      tris    = new List <int>();
      normals = new List <Vector3d>();


      toPull      = ReadString1();
      linesInFile = toPull.Split('\n');

      counter = 0;
      foreach (string line in linesInFile)
      {
          counter++;
          Debug.Log(line);

          if (!string.IsNullOrEmpty(line))
          {
              points.Add(StringToVector3(line));
              tris.Add(counter);
              tris.Add(counter);
              tris.Add(counter);

              normals.Add(new Vector3d(normal, normal, normal));
          }
      }
      pointSet = DMesh3Builder.Build(points, tris, normals);
      bvtree   = new PointAABBTree3(pointSet, true);
      bvtree.FastWindingNumber(Vector3d.Zero);
// estimate point area based on nearest-neighbour distance
      areas = new double[pointSet.MaxVertexID];
      foreach (int vid in pointSet.VertexIndices())
      {
          bvtree.PointFilterF = (i) => { return(i != vid); }; // otherwise vid is nearest to vid!
          int    near_vid = bvtree.FindNearestPoint(pointSet.GetVertex(vid));
          double dist     = pointSet.GetVertex(vid).Distance(pointSet.GetVertex(near_vid));
          areas[vid] = Circle2d.RadiusArea(dist);
      }
      bvtree.FWNAreaEstimateF = (vid) => {
          return(areas[vid]);
      };
      mc          = new MarchingCubes();
      mc.Implicit = new PWNImplicit()
      {
          Spatial = bvtree
      };
      mc.IsoValue = 0.0;
      mc.CubeSize = bvtree.Bounds.MaxDim / 50;
      mc.Bounds   = bvtree.Bounds.Expanded(mc.CubeSize * 3);
      mc.RootMode = MarchingCubes.RootfindingModes.Bisection;
      mc.Generate();
      DMesh3     resultMesh1 = mc.Mesh;
      MeshEditor editor      = new MeshEditor(resultMesh);

      editor.AppendMesh(resultMesh1, resultMesh.AllocateTriangleGroup());

      g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh1);

      //  g3UnityUtils.SetGOMesh(transform.gameObject, resultMesh);
  }