コード例 #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);
       */
  }
コード例 #2
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);
  }
コード例 #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 List <CubicBezier> FitBezier(List <Vector3> pts, List <float> times, bool useRdp = true)
        {
            AllInputPoints = new List <Vector3d>(pts.Count);

            foreach (var pt in pts)
            {
                AllInputPoints.Add(pt);
            }
            inputPointsTree = new PointAABBTree3(new PointSet(AllInputPoints.ToArray()));

            AllInputPointTimes = times;

            if (useRdp)
            {
                var reduced = CurvePreprocess.RdpReduce(pts, Globals.RDP_ERROR, out List <int> keepIdx);
                PointsKeepIdx = keepIdx;
                InputPoints   = reduced;
                Curves        = new List <CubicBezier>(CurveFit.Fit(reduced, Globals.BEZIER_FIT_MAX_ERROR));
            }
            else
            {
                InputPoints = pts;
                Curves      = new List <CubicBezier>(CurveFit.Fit(pts, Globals.BEZIER_FIT_MAX_ERROR));
            }

            Curves[0] = new CubicBezier(
                Curves[0].p0,
                Curves[0].p0 + (Curves[0].p1 - Curves[0].p0).magnitude * Vector3.forward,
                Curves[0].p2,
                Curves[0].p3);

            if (Curves.Count == 0)
            {
                ControlPoints = new Vector3[0];
            }
            else
            {
                ControlPoints    = new Vector3[1 + 3 * Curves.Count];
                ControlPoints[0] = Curves[0].p0;
            }
            for (int i = 0; i < Curves.Count; ++i)
            {
                ControlPoints[3 * i + 1] = Curves[i].p1;
                ControlPoints[3 * i + 2] = Curves[i].p2;
                ControlPoints[3 * i + 3] = Curves[i].p3;
            }


            float[] cpData = new float[ControlPoints.Length * 3];
            for (int i = 0; i < ControlPoints.Length; ++i)
            {
                cpData[3 * i + 0] = ControlPoints[i].x;
                cpData[3 * i + 1] = ControlPoints[i].y;
                cpData[3 * i + 2] = ControlPoints[i].z;
            }

            if (_path != IntPtr.Zero)
            {
                _DeleteUnmanagedPathObject(_path);
            }
            _path = _CreateUnmanagedPathObject(cpData, ControlPoints.Length);

            CacheArcLength();

            if (times.Count == 0)
            {
                paramToTimeCache = paramToArcLengthCache;
            }
            else
            {
                CacheTime();
            }

            InputPointArcLengths = new List <float>(InputPoints.Count);
            foreach (var pt in InputPoints)
            {
                var res = GetClosestPoint(pt, out Vector3 closest, out int bezierIdx, out float param);
                if (res)
                {
                    InputPointArcLengths.Add(GetArcLengthFromSplineParam(bezierIdx, param));
                }
                else
                {
                    throw new Exception("Something horrible happened!");
                }
            }

            return(Curves);
        }