示例#1
0
 // Gets all unique pairs of items within this grid, or if this grid has children, from its children
 // Child grids will have better precision, so using the child grids instead of the parent might eliminate some bogus combinations
 // The results go into the result bool[,] array, which must have the proper dimensions initially
 protected virtual void GetLeafLevelPairs(SparseBoolMatrix result)
 {
     if (children == null)
     {
         foreach (Octree.Item i in items[0])
         {
             if (i.obj is CSGSourceTriangle)
             {
                 foreach (Octree.Item j in items[1])
                 {
                     if (j.obj is CSGSourceTriangle)
                     {
                         result[(i.obj as CSGSourceTriangle).id, (j.obj as CSGSourceTriangle).id] = true;
                     }
                 }
             }
         }
     }
     else
     {
         foreach (ModelIntersectTree grid in children)
         {
             grid.GetLeafLevelPairs(result);
         }
     }
 }
示例#2
0
        // Top-level version of the above function, determines the array dimensions automatically and returns the array
        protected virtual SparseBoolMatrix GetLeafLevelPairs()
        {
            SparseBoolMatrix result = new SparseBoolMatrix();

            GetLeafLevelPairs(result);
            return(result);
        }
        // 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);
        }
示例#4
0
        // Iterates through all the pairs and runs your callback function for them
        public void ForLeafLevelPairs(SparseBoolMatrix.PairCallback callback)
        {
            SparseBoolMatrix pairs = GetLeafLevelPairs();

            pairs.ForAllPairs(callback);
        }
 // Top-level version of the above function, determines the array dimensions automatically and returns the array
 protected virtual SparseBoolMatrix GetLeafLevelPairs()
 {
     SparseBoolMatrix result = new SparseBoolMatrix();
     GetLeafLevelPairs(result);
     return result;
 }
 // Gets all unique pairs of items within this grid, or if this grid has children, from its children
 // Child grids will have better precision, so using the child grids instead of the parent might eliminate some bogus combinations
 // The results go into the result bool[,] array, which must have the proper dimensions initially
 protected virtual void GetLeafLevelPairs(SparseBoolMatrix result)
 {
     if (children == null)
     {
         foreach (Octree.Item i in items[0])
             if (i.obj is CSGSourceTriangle)
                 foreach (Octree.Item j in items[1])
                     if (j.obj is CSGSourceTriangle)
                         result[(i.obj as CSGSourceTriangle).id, (j.obj as CSGSourceTriangle).id] = true;
     }
     else
     {
         foreach (ModelIntersectTree grid in children)
             grid.GetLeafLevelPairs(result);
     }
 }
 // Iterates through all the pairs and runs your callback function for them
 public void ForLeafLevelPairs(SparseBoolMatrix.PairCallback callback)
 {
     SparseBoolMatrix pairs = GetLeafLevelPairs();
     pairs.ForAllPairs(callback);
 }
 // 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
 }