public void PrepareFastSearch()
 {
     tree = new TopoTriangleNode(null);
     foreach (TopoTriangle triangle in triangles)
     {
         tree.AddTriangle(triangle);
     }
 }
 public void PrepareFastSearch()
 {
     tree = new TopoTriangleNode(null);
     foreach (TopoTriangle triangle in triangles)
     {
         tree.AddTriangle(triangle);
     }
 }
        public bool RemoveTriangle(TopoTriangle triangle)
        {
            TopoTriangleNode node = FindNodeForTriangle(triangle);

            if (node != null)
            {
                return(node.triangles.Remove(triangle));
            }
            return(false);
        }
 public TopoTriangleNode(TopoTriangleNode _parent)
 {
     parent = _parent;
 }
 public void Clear()
 {
     tree = null;
     triangles.Clear();
 }
        private void TrySplit()
        {
            int newDim          = 0;
            int parentDimension = -1;

            if (parent != null)
            {
                parentDimension = parent.dimension;
            }
            RHVector3 size = box.Size;

            if (parentDimension != 0)
            {
                newDim = 0;
            }
            if (parentDimension != 1 && size.x < size.y)
            {
                newDim = 1;
            }
            if (parentDimension != 2 && size.z > size[newDim])
            {
                newDim = 2;
            }
            int    loop           = 0;
            int    maxLoop        = 4;
            double bestCenter     = 0;
            double bestPercentage = 3000;
            int    bestDim        = 0;

            for (int dim = 0; dim < 3; dim++)
            {
                if (dim == parentDimension)
                {
                    continue;
                }
                for (loop = 0; loop < maxLoop; loop++)
                {
                    int    count    = 0;
                    double testDist = box.minPoint[newDim] + size[newDim] * (1 + loop) / (maxLoop + 1);
                    foreach (TopoTriangle tri in triangles)
                    {
                        if (tri.boundingBox.maxPoint[newDim] < testDist)
                        {
                            count++;
                        }
                    }
                    double percent = 100.0 * (double)count / triangles.Count;
                    if (Math.Abs(50 - percent) < bestPercentage)
                    {
                        bestPercentage = percent;
                        bestCenter     = testDist;
                        bestDim        = dim;
                    }
                }
            }
            if (bestPercentage < 5)
            {
                nextTrySplit = (nextTrySplit * 3) / 2;
                return; // not effective enough
            }
            left           = new TopoTriangleNode(this);
            right          = new TopoTriangleNode(this);
            middle         = new TopoTriangleNode(this);
            dimension      = newDim;
            middlePosition = bestCenter;
            foreach (TopoTriangle tri in triangles)
            {
                if (tri.boundingBox.maxPoint[dimension] < middlePosition)
                {
                    left.AddTriangle(tri);
                }
                else if (tri.boundingBox.minPoint[dimension] > middlePosition)
                {
                    right.AddTriangle(tri);
                }
                else
                {
                    middle.AddTriangle(tri);
                }
            }
            triangles = null;
        }
 public TopoTriangleNode(TopoTriangleNode _parent)
 {
     parent = _parent;
 }
 public void Clear()
 {
     tree = null;
     triangles.Clear();
 }
 private void TrySplit()
 {
     int newDim = 0;
     int parentDimension = -1;
     if (parent != null)
         parentDimension = parent.dimension;
     RHVector3 size = box.Size;
     if (parentDimension != 0) newDim = 0;
     if (parentDimension != 1 && size.x < size.y) newDim = 1;
     if (parentDimension != 2 && size.z > size[newDim]) newDim = 2;
     int loop = 0;
     int maxLoop = 4;
     double bestCenter = 0;
     double bestPercentage = 3000;
     int bestDim = 0;
     for (int dim = 0; dim < 3; dim++)
     {
         if (dim == parentDimension) continue;
         for (loop = 0; loop < maxLoop; loop++)
         {
             int count = 0;
             double testDist = box.minPoint[newDim] + size[newDim] * (1 + loop) / (maxLoop + 1);
             foreach (TopoTriangle tri in triangles)
             {
                 if (tri.boundingBox.maxPoint[newDim] < testDist)
                     count++;
             }
             double percent = 100.0 * (double)count / triangles.Count;
             if (Math.Abs(50 - percent) < bestPercentage)
             {
                 bestPercentage = percent;
                 bestCenter = testDist;
                 bestDim = dim;
             }
         }
     }
     if (bestPercentage < 5)
     {
         nextTrySplit = (nextTrySplit * 3) / 2;
         return; // not effective enough
     }
     left = new TopoTriangleNode(this);
     right = new TopoTriangleNode(this);
     middle = new TopoTriangleNode(this);
     dimension = newDim;
     middlePosition = bestCenter;
     foreach (TopoTriangle tri in triangles)
     {
         if (tri.boundingBox.maxPoint[dimension] < middlePosition)
             left.AddTriangle(tri);
         else if (tri.boundingBox.minPoint[dimension] > middlePosition)
             right.AddTriangle(tri);
         else
             middle.AddTriangle(tri);
     }
     triangles = null;
 }