コード例 #1
0
        private void Update()
        {
            if (alignmentManager == null)
            {
                FindAlignmentManager();
            }
            if (triangulator != null && isVisible)
            {
                // Find the three closest SpacePins this frame
                Interpolant interpolantThisFrame = triangulator.Find(GetLockedHeadPosition());

                if (interpolantThisFrame != null)
                {
                    currentInterpolant = interpolantThisFrame;

                    // Only generate new mesh if SpacePins are different from the currently generated ones
                    if (!Enumerable.SequenceEqual(interpolantThisFrame.idx, lastGeneratedTriangleIDs) || triangleIsDirty || (AnyWeightInTriangleZero() && currentBoundaryVertexIDx == -1) || (!AnyWeightInTriangleZero() && currentBoundaryVertexIDx != -1))
                    {
                        GenerateMeshes();
                        lastGeneratedTriangleIDs = interpolantThisFrame.idx;
                    }
                    // if SpacePins are same update the vertices in case the current SpacePins moved somehow,
                    // or there is a boundary vertex that needs to be snapped to the headset position every frame.
                    else
                    {
                        UpdateVertexPositions();
                    }

                    UpdateMaterialProperties();
                    UpdatePercentageTexts();
                }
            }
        }
コード例 #2
0
        public void TriangulatorTestObtuseTriangle()
        {
            ITriangulator triangulator = CreateDefaultTriangulator();

            // Use the Assert class to test conditions
            Vector3[] vertices = { new Vector3(0, 0, 0), new Vector3(2, 0, 0), new Vector3(1, 0, 0.04f) };
            triangulator.Add(vertices);

            Interpolant interp = triangulator.Find(new Vector3(0, 0, 0));

            CheckWeight(interp, 0, 1);
            CheckWeightsZero(interp, new int[] { 1, 2 });

            interp = triangulator.Find(new Vector3(2.0f, 0, 0));
            CheckWeight(interp, 1, 1);
            CheckWeightsZero(interp, new int[] { 0, 2 });

            /// This one is outside the triangle, but should interpolate to the obtuse vertex exactly.
            interp = triangulator.Find(new Vector3(1.0f, 0, 02f));
            CheckWeight(interp, 2, 1);
            CheckWeightsZero(interp, new int[] { 0, 1 });

            interp = triangulator.Find(new Vector3(1.0f, 0, 0.0f));
            //CheckWeight(interp, 2, 1);
            //CheckWeightsZero(interp, new int[] { 0, 1 });
        }
コード例 #3
0
 private static void CheckWeightsZero(Interpolant interp, int[] idx)
 {
     for (int i = 0; i < idx.Length; ++i)
     {
         CheckWeightZero(interp, idx[i]);
     }
 }
コード例 #4
0
 private static void CheckWeightZero(Interpolant interp, int idx)
 {
     for (int i = 0; i < interp.idx.Length; ++i)
     {
         if (interp.idx[i] == idx)
         {
             Assert.AreEqual(interp.weights[i], 0);
         }
     }
 }
コード例 #5
0
        private static void CheckWeight(Interpolant interp, int idx, float weight)
        {
            int found = 0;

            for (int i = 0; i < interp.idx.Length; ++i)
            {
                if (interp.idx[i] == idx && interp.weights[i] > 0)
                {
                    Assert.IsTrue(FloatCompare(interp.weights[i], weight));
                    ++found;
                }
            }
            // If the input weight is non-zero, there should be exactly one non-zero weight occurrence of it.
            Assert.IsTrue((weight == 0 && found == 0) || (weight > 0 && found == 1));
        }
コード例 #6
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var X2D = new double[2][] {
                new double[2] {
                    0, 1
                },
                new double[2] {
                    0, 1
                }
            };

            X2D = new double[2][] {
                new double[3] {
                    0, 0.25, 1
                },
                new double[3] {
                    0, 0.5, 1
                }
            };
            //var Z2D = new double[9] { 1, 1, 1, 1, 1, 1, 1, 1, 1 };
            var Z2D = new double[9] {
                1, 2, 3, 4, 2, -3, 1, 2, 3
            };

            //var Z2D = new double[4] { 1, 2, 3, 4 };
            //Z2D = new double[6] { 1, 2, 3, 1, 2, 3 };


            Z = Z2D;

            grid = new Grid(X2D);
            gp   = new IvyCore.Parametric.Point(grid);
            Zpts = this.ConstructFieldView(grid, Z);


            var p = new Point3d();

            DA.GetData(0, ref p);

            int n = Math.Min(gp.Dim, 3);

            for (int i = 0; i < n; i++)
            {
                gp[i] = p[i];
            }

            int cellIndex = gp.CellIndex();
            var cell      = gp.Grid.Cells[cellIndex];

            Interpolant interp = cell.GetInterpolant(gp);
            double      zlerp  = interp.Lerp(Z);
            //for (int i = 0; i < LERP.Length; i++)
            //{
            //    int index = cell.VerticesIndex[i];
            //    zlerp += LERP[i] * Z[index];
            //}

            var cellPts = new Point3d[5];

            double[] node;
            node       = grid.Nodes[cell.VerticesIndex[0]].Coord;
            cellPts[0] = new Point3d(node[0], node[1], 0);

            node       = grid.Nodes[cell.VerticesIndex[1]].Coord;
            cellPts[1] = new Point3d(node[0], node[1], 0);

            node       = grid.Nodes[cell.VerticesIndex[3]].Coord;
            cellPts[2] = new Point3d(node[0], node[1], 0);

            node       = grid.Nodes[cell.VerticesIndex[2]].Coord;
            cellPts[3] = new Point3d(node[0], node[1], 0);

            cellPts[4] = cellPts[0];

            var contour = new PolylineCurve(cellPts);

            p.Z = zlerp;

            DA.SetData(0, p);
            DA.SetDataList(1, Zpts);
            DA.SetData(2, contour);
            DA.SetData(3, grid.Info());
        }