Esempio 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);
       */
  }
Esempio n. 2
0
 public DistPoint2Circle2(Vector2D PointIn, Circle2d circleIn)
 {
     point = PointIn; circle = circleIn;
 }
Esempio n. 3
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);
  }
Esempio n. 4
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);
      }
  }
Esempio n. 5
0
 public void CodeCircle2d(ref Circle2d v)
 {
     CodeV2d(ref v.Center); CodeDouble(ref v.Radius);
 }
    /// <summary>
    /// 根据Separating Axis Theorem理论实现
    /// https://www.sevenson.com.au/actionscript/sat/
    /// https://github.com/sevdanski/SAT_AS3
    /// </summary>
    /// <param name="convex1"></param>
    /// <param name="convex2"></param>
    /// <returns></returns>
    public static CollisionInfo Circle2dWithConvex2d(Circle2d circleA, Convex2d polygonA, bool flip, bool docalc)
    {
        CollisionInfo result = new CollisionInfo();

        if (flip)
        {
            result.shapeA = polygonA;
            result.shapeB = circleA;
        }
        else
        {
            result.shapeA = circleA;
            result.shapeB = polygonA;
        }
        result.shapeAContained = true;
        result.shapeBContained = true;

        // get the offset
        Vector2L vOffset = new Vector2L(polygonA.m_pos.x - circleA.m_pos.x, polygonA.m_pos.y - circleA.m_pos.y);

        // get the vertices
        List <Vector2L> p1 = polygonA.GetRotateList();

        // find the closest point
        Vector2L closestPoint = new Vector2L();
        FloatL   minDist      = FloatL.MaxValue;

        foreach (var iter in p1)
        {
            FloatL currentDist = (circleA.m_pos - (polygonA.m_pos + iter)).sqrMagnitude;
            if (currentDist < minDist)
            {
                minDist      = currentDist;
                closestPoint = polygonA.m_pos + iter;
            }
        }

        // make a normal of this vector
        Vector2L vAxis = closestPoint - circleA.m_pos;

        vAxis.Normalize();

        // project polygon A
        FloatL min0 = Vector2L.Dot(vAxis, p1[0]);
        FloatL max0 = min0;

        for (int j = 1; j < p1.Count; ++j)
        {
            FloatL t = Vector2L.Dot(vAxis, p1[j]);
            if (t < min0)
            {
                min0 = t;
            }
            if (t > max0)
            {
                max0 = t;
            }
        }

        // project circle A
        FloatL min1 = Vector2L.Dot(vAxis, Vector2L.zero);
        FloatL max1 = min1 + circleA.m_radius;

        min1 -= circleA.m_radius;

        // shift polygonA's projected points
        FloatL sOffset = Vector2L.Dot(vAxis, vOffset);

        min0 += sOffset;
        max0 += sOffset;

        // test for intersections
        FloatL d0 = min0 - max1;
        FloatL d1 = min1 - max0;

        if (d0 > 0 || d1 > 0)
        {
            // gap found
            return(null);
        }

        FloatL shortestDist = FloatL.MaxValue;

        if (docalc)
        {
            FloatL distmin = (max1 - min0) * -1;              //Math.min(dist0, dist1);
            if (flip)
            {
                distmin *= -1;
            }
            FloatL distminAbs = (distmin < 0) ? distmin * -1 : distmin;

            // check for containment
            if (!flip)
            {
                if (max0 > max1 || min0 < min1)
                {
                    result.shapeAContained = false;
                }
                if (max1 > max0 || min1 < min0)
                {
                    result.shapeBContained = false;
                }
            }
            else
            {
                if (max0 < max1 || min0 > min1)
                {
                    result.shapeAContained = false;
                }
                if (max1 < max0 || min1 > min0)
                {
                    result.shapeBContained = false;
                }
            }

            // this distance is shorter so use it...
            result.distance = distmin;
            result.vector   = vAxis;
            //
            shortestDist = distminAbs;
        }

        // loop through all of the axis on the first polygon
        for (int i = 0; i < p1.Count; i++)
        {
            // find the axis that we will project onto
            vAxis = GetAxisNormal(p1, i);

            // project polygon A
            min0 = Vector2L.Dot(vAxis, p1[0]);
            max0 = min0;

            //
            for (int j = 1; j < p1.Count; j++)
            {
                FloatL t = Vector2L.Dot(vAxis, p1[j]);
                if (t < min0)
                {
                    min0 = t;
                }
                if (t > max0)
                {
                    max0 = t;
                }
            }

            // project circle A
            min1  = Vector2L.Dot(vAxis, new Vector2L(0, 0));
            max1  = min1 + circleA.m_radius;
            min1 -= circleA.m_radius;

            // shift polygonA's projected points
            sOffset = Vector2L.Dot(vAxis, vOffset);
            min0   += sOffset;
            max0   += sOffset;

            // test for intersections
            d0 = min0 - max1;
            d1 = min1 - max0;

            if (d0 > 0 || d1 > 0)
            {
                // gap found
                return(null);
            }

            if (docalc)
            {
                // check for containment
                if (!flip)
                {
                    if (max0 > max1 || min0 < min1)
                    {
                        result.shapeAContained = false;
                    }
                    if (max1 > max0 || min1 < min0)
                    {
                        result.shapeBContained = false;
                    }
                }
                else
                {
                    if (max0 < max1 || min0 > min1)
                    {
                        result.shapeAContained = false;
                    }
                    if (max1 < max0 || min1 > min0)
                    {
                        result.shapeBContained = false;
                    }
                }

                FloatL distmin = (max1 - min0) * -1;
                if (flip)
                {
                    distmin *= -1;
                }
                FloatL distminAbs = (distmin < 0) ? distmin * -1 : distmin;
                if (distminAbs < shortestDist)
                {
                    // this distance is shorter so use it...
                    result.distance = distmin;
                    result.vector   = vAxis;
                    //
                    shortestDist = distminAbs;
                }
            }
        }

        // if you are here then no gap was found
        return(result);
    }
Esempio n. 7
0
 public void Include(Circle2d circle)
 {
     this.Include(ref circle);
 }
Esempio n. 8
0
    public static void DrawSphere(Vector2 center, float radius, Color color)
    {
        Circle2d circle2 = new Circle2d(center, radius);

        DrawSphere(ref circle2, color);
    }
        public void Circle2d_Parse4()
        {
            var a = new Circle2d(new V2d(1.2, double.NaN), 5.6);

            Assert.IsTrue(Circle2d.Parse(a.ToString()).IsInvalid);
        }
Esempio n. 10
0
        public void Circle2d_Parse6()
        {
            var a = new Circle2d(V2d.NaN, double.NaN);

            Assert.IsTrue(Circle2d.Parse(a.ToString()).IsInvalid);
        }
Esempio n. 11
0
        public void Circle2d_Area()
        {
            var a = new Circle2d(V2d.Zero, 3.0);

            Assert.IsTrue(a.Area == 9 * PI);
        }
Esempio n. 12
0
        public void Circle2d_Circumference()
        {
            var a = new Circle2d(V2d.Zero, 3.0);

            Assert.IsTrue(a.Circumference == 6 * PI);
        }
Esempio n. 13
0
        public void Circle2d_RadiusSquared()
        {
            var a = new Circle2d(V2d.Zero, 2.0);

            Assert.IsTrue(a.RadiusSquared == 4.0);
        }
 public void CodeCircle2d(ref Circle2d v)
 {
     throw new NotImplementedException();
 }
 public void CodeCircle2d(ref Circle2d v)
 {
     AddValue(v.ToString());
 }