// Function to find out all of the possibly intersecting pairs of triangles, and also to find out which triangles are not possibly intersecting anything
        public static void CullIntersections(CSGModel a, CSGModel b, SparseBoolMatrix.PairCallback pairCallback, SafeTriangleCallback safeCallback)
        {
            ModelIntersectTree tree = new ModelIntersectTree(a, b);             // create the tree (operations are done automatically by the constructor

            // make lists of all the triangle indices in each of the input objects
            HashSet<long> aSafe = new HashSet<long>();
            HashSet<long> bSafe = new HashSet<long>();
            foreach (long i in tree.allItems[0])
                aSafe.Add(i);
            foreach (long j in tree.allItems[1])
                bSafe.Add(j);

            // iterate through all of the pairs
            tree.ForLeafLevelPairs(
                (i, j) =>
                {
                    aSafe.Remove(i);                                            // if an item is in a pair with another item, it isn't safe, so we remove it from the safe list
                    bSafe.Remove(j);

                    pairCallback(i, j);                                         // call the user-defined callback
                });

            foreach (long i in aSafe)                                           // let the user know which ones were determined to be 'safe'
                safeCallback(0, i);
            foreach (long j in bSafe)
                safeCallback(1, j);
        }
Beispiel #2
0
        // Subdivides this ModelIntersectTree, splitting it at the specified point (which ought to be insidwe this grid's AABB)
        public void Subdivide(Vec3 split)
        {
            this.split = split;
            int max_child_subd = max_subdivisions - 1;

            children = new ModelIntersectTree[2, 2, 2];
            double[][] array = new double[][]
            {
                new double[] { bounds.array[0][0], split.x, bounds.array[0][1] },
                new double[] { bounds.array[1][0], split.y, bounds.array[1][1] },
                new double[] { bounds.array[2][0], split.z, bounds.array[2][1] }
            };
            for (int i = 0; i < 2; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    for (int k = 0; k < 2; k++)
                    {
                        children[i, j, k] = new ModelIntersectTree(new AABB
                        {
                            array = new double[][] {
                                new double[] { array[0][i], array[0][i + 1] },
                                new double[] { array[1][j], array[1][j + 1] },
                                new double[] { array[2][k], array[2][k + 1] }
                            }
                        }, max_child_subd);
                    }
                }
            }
            foreach (ModelIntersectTree child in children)
            {
                foreach (Octree.Item item in items[0])
                {
                    child.InsertItem(0, item);
                }
                foreach (Octree.Item item in items[1])
                {
                    child.InsertItem(1, item);
                }
            }
        }
Beispiel #3
0
        // Function to find out all of the possibly intersecting pairs of triangles, and also to find out which triangles are not possibly intersecting anything
        public static void CullIntersections(CSGModel a, CSGModel b, SparseBoolMatrix.PairCallback pairCallback, SafeTriangleCallback safeCallback)
        {
            ModelIntersectTree tree = new ModelIntersectTree(a, b);             // create the tree (operations are done automatically by the constructor

            // make lists of all the triangle indices in each of the input objects
            HashSet <long> aSafe = new HashSet <long>();
            HashSet <long> bSafe = new HashSet <long>();

            foreach (long i in tree.allItems[0])
            {
                aSafe.Add(i);
            }
            foreach (long j in tree.allItems[1])
            {
                bSafe.Add(j);
            }

            // iterate through all of the pairs
            tree.ForLeafLevelPairs(
                (i, j) =>
            {
                aSafe.Remove(i);                                                // if an item is in a pair with another item, it isn't safe, so we remove it from the safe list
                bSafe.Remove(j);

                pairCallback(i, j);                                             // call the user-defined callback
            });

            foreach (long i in aSafe)                                           // let the user know which ones were determined to be 'safe'
            {
                safeCallback(0, i);
            }
            foreach (long j in bSafe)
            {
                safeCallback(1, j);
            }
        }
Beispiel #4
0
        // Similar, but without the part for finding out all the stuff stuff that's safe
        public static void CullIntersections(CSGModel a, CSGModel b, SparseBoolMatrix.PairCallback pairCallback)
        {
            ModelIntersectTree tree = new ModelIntersectTree(a, b);             // create the tree (operations are done automatically by the constructor

            tree.ForLeafLevelPairs(pairCallback);                               // iterate through all of the pairs and call the user-defined callback
        }
 // Subdivides this ModelIntersectTree, splitting it at the specified point (which ought to be insidwe this grid's AABB)
 public void Subdivide(Vec3 split)
 {
     this.split = split;
     int max_child_subd = max_subdivisions - 1;
     children = new ModelIntersectTree[2, 2, 2];
     double[][] array = new double[][]
     {
         new double[] { bounds.array[0][0], split.x, bounds.array[0][1] },
         new double[] { bounds.array[1][0], split.y, bounds.array[1][1] },
         new double[] { bounds.array[2][0], split.z, bounds.array[2][1] }
     };
     for (int i = 0; i < 2; i++)
         for (int j = 0; j < 2; j++)
             for (int k = 0; k < 2; k++)
             {
                 children[i, j, k] = new ModelIntersectTree(new AABB
                 {
                     array = new double[][] {
                         new double[] { array[0][i], array[0][i + 1] },
                         new double[] { array[1][j], array[1][j + 1] },
                         new double[] { array[2][k], array[2][k + 1] } }
                 }, max_child_subd);
             }
     foreach (ModelIntersectTree child in children)
     {
         foreach (Octree.Item item in items[0])
             child.InsertItem(0, item);
         foreach (Octree.Item item in items[1])
             child.InsertItem(1, item);
     }
 }
 // Similar, but without the part for finding out all the stuff stuff that's safe
 public static void CullIntersections(CSGModel a, CSGModel b, SparseBoolMatrix.PairCallback pairCallback)
 {
     ModelIntersectTree tree = new ModelIntersectTree(a, b);             // create the tree (operations are done automatically by the constructor
     tree.ForLeafLevelPairs(pairCallback);                               // iterate through all of the pairs and call the user-defined callback
 }