예제 #1
0
        void CacheTime()
        {
            paramToTimeCache = new float[Curves.Count, Globals.BEZIER_PARAM_CACHE_NUM_SAMPLES];

            for (int i = 0; i < Curves.Count; ++i)
            {
                for (int j = 0; j < Globals.BEZIER_PARAM_CACHE_NUM_SAMPLES; ++j)
                {
                    var thisPoint = Curves[i].Sample(((float)j) / (Globals.BEZIER_PARAM_CACHE_NUM_SAMPLES - 1));

                    int minIdx = inputPointsTree.FindNearestPoint(thisPoint);

                    paramToTimeCache[i, j] = AllInputPointTimes[minIdx];
                }

                for (int j = 1; j < Globals.BEZIER_PARAM_CACHE_NUM_SAMPLES; ++j)
                {
                    if (paramToTimeCache[i, j] - paramToTimeCache[i, j - 1] < 1e-6)
                    {
                        int s  = j - 1;
                        int e1 = j + 1;
                        while (e1 < Globals.BEZIER_PARAM_CACHE_NUM_SAMPLES &&
                               paramToTimeCache[i, e1] - paramToTimeCache[i, j] < 1e-6)
                        {
                            e1++;
                        }
                        e1--;

                        int e2 = e1 + 1;
                        while (e2 < Globals.BEZIER_PARAM_CACHE_NUM_SAMPLES &&
                               paramToTimeCache[i, e2] - paramToTimeCache[i, e1 + 1] < 1e-6)
                        {
                            e2++;
                        }
                        e2--;

                        if (s == 0 && e2 == e1)
                        {
                            throw new Exception("time Param is degenerate across Bezier " + i);
                        }
                        else if (s == 0)
                        {
                            _RedistParam(i, s, e2);
                        }
                        else if (e2 == e1)
                        {
                            _RedistParam(i, s - 1, e1);
                        }
                        else
                        {
                            int m = (s + e1) / 2;
                            _RedistParam(i, s - 1, m);
                            _RedistParam(i, m + 1, e2);
                        }

                        j = e2 + 1;
                    }
                }
            }
        }
예제 #2
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);
       */
  }
예제 #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);
      }
  }
예제 #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);
  }