Пример #1
0
        public KdTree(int maxDepth, int maxLeavePrimitives, SceneDatabase sceneDatabase)
        {
            mMaxNumOfPrimitives = maxLeavePrimitives;
            mMaxDepth           = maxDepth;

            //
            List <RTGeometry> allGeom  = new List <RTGeometry>();
            Vector3           worldMin = new Vector3(float.MaxValue);
            Vector3           worldMax = new Vector3(float.MinValue);

            // we need to compute the compute the world min/max
            for (int i = 0; i < sceneDatabase.GetNumGeom(); i++)
            {
                RTGeometry g = sceneDatabase.GetGeom(i);
                allGeom.Add(g);
                worldMin = Vector3.Min(worldMin, g.Min);
                worldMax = Vector3.Max(worldMax, g.Max);
            }

            int rootDepth = 0;

            mRoot = new KdTreeNode(worldMin, worldMax, new KdTreeAxis(rootDepth), allGeom);

            BuildKDTree(mRoot, rootDepth, allGeom);
        }
Пример #2
0
        public void BuildKDTree(KdTreeNode node, int depth, List<RTGeometry> geomList)
        {
            if (MetStopCriteria(node, depth, geomList.Count))
            {
                node.SetGeomList(geomList);
                return;
            }

            List<RTGeometry> leftList = new List<RTGeometry>();
            List<RTGeometry> rightList = new List<RTGeometry>();
            foreach (RTGeometry g in geomList)
            {
                if (g.LeftOf(node.SplitAxis, node.SplitPosition))
                    leftList.Add(g);
                if (g.RightOf(node.SplitAxis, node.SplitPosition))
                    rightList.Add(g);
            }

            Vector3 leftMin, leftMax, rightMin, rightMax;
            leftMin = node.Bounds.Min;
            leftMax = node.Bounds.Max;
            rightMin = leftMin;
            rightMax = leftMax;
            leftMax = node.SplitAxis.SetVectorComponent(leftMax, node.SplitPosition);
            rightMin = node.SplitAxis.SetVectorComponent(rightMin, node.SplitPosition);

            KdTreeAxis nextAxis = node.SplitAxis.NextSplitAxis;
            node.LeftChild = new KdTreeNode(leftMin, leftMax, nextAxis, leftList);
            node.RightChild = new KdTreeNode(rightMin, rightMax, nextAxis, rightList);

            BuildKDTree(node.LeftChild, depth + 1, leftList);
            BuildKDTree(node.RightChild, depth + 1, rightList);
        }
 internal void AddBox(RayTracer_552.KdTreeNode node, UWB_PrimitiveList list)
 {
     defineBox(list, node.Bounds.Min, node.Bounds.Max);
     if (!node.IsLeafNode())
     {
         AddBox(node.LeftChild, list);
         AddBox(node.RightChild, list);
     }
 }
Пример #4
0
        public KdTreeNode(Vector3 min, Vector3 max, KdTreeAxis useAxis, List <RTGeometry> list)
        {
            mLeft      = null;
            mRight     = null;
            mGeomList  = null;
            mBounds    = new BoundingBox(min, max);
            mSplitAxis = new KdTreeAxis(useAxis);

            ComputeSplitPosition(list);
        }
        internal void AddRTKdTree(RayTracer_552.KdTreeNode rootNode)
        {
            UWB_SceneNode n = new UWB_SceneNode();

            m_SceneDatabase.insertChildNode(n);
            UWB_PrimitiveList list = new UWB_PrimitiveList();

            n.setPrimitive(list);
            AddBox(rootNode, list);
        }
        public KdTreeNode(Vector3 min, Vector3 max, KdTreeAxis useAxis, List<RTGeometry> list)
        {
            mLeft = null;
            mRight = null;
            mGeomList = null;
            mBounds = new BoundingBox(min, max);
            mSplitAxis = new KdTreeAxis(useAxis);

            ComputeSplitPosition(list);
        }
Пример #7
0
        public void BuildKDTree(KdTreeNode node, int depth, List <RTGeometry> geomList)
        {
            if (MetStopCriteria(node, depth, geomList.Count))
            {
                node.SetGeomList(geomList);
                return;
            }

            List <RTGeometry> leftList  = new List <RTGeometry>();
            List <RTGeometry> rightList = new List <RTGeometry>();

            foreach (RTGeometry g in geomList)
            {
                if (g.LeftOf(node.SplitAxis, node.SplitPosition))
                {
                    leftList.Add(g);
                }
                if (g.RightOf(node.SplitAxis, node.SplitPosition))
                {
                    rightList.Add(g);
                }
            }

            Vector3 leftMin, leftMax, rightMin, rightMax;

            leftMin  = node.Bounds.Min;
            leftMax  = node.Bounds.Max;
            rightMin = leftMin;
            rightMax = leftMax;
            leftMax  = node.SplitAxis.SetVectorComponent(leftMax, node.SplitPosition);
            rightMin = node.SplitAxis.SetVectorComponent(rightMin, node.SplitPosition);

            KdTreeAxis nextAxis = node.SplitAxis.NextSplitAxis;

            node.LeftChild  = new KdTreeNode(leftMin, leftMax, nextAxis, leftList);
            node.RightChild = new KdTreeNode(rightMin, rightMax, nextAxis, rightList);

            BuildKDTree(node.LeftChild, depth + 1, leftList);
            BuildKDTree(node.RightChild, depth + 1, rightList);
        }
Пример #8
0
        public KdTree(int maxDepth, int maxLeavePrimitives, SceneDatabase sceneDatabase)
        {
            mMaxNumOfPrimitives = maxLeavePrimitives;
            mMaxDepth = maxDepth;

            //
            List<RTGeometry> allGeom = new List<RTGeometry>();
            Vector3 worldMin = new Vector3(float.MaxValue);
            Vector3 worldMax = new Vector3(float.MinValue);

            // we need to compute the compute the world min/max
            for (int i = 0; i < sceneDatabase.GetNumGeom(); i++)
            {
                RTGeometry g = sceneDatabase.GetGeom(i);
                allGeom.Add(g);
                worldMin = Vector3.Min(worldMin, g.Min);
                worldMax = Vector3.Max(worldMax, g.Max);
            }

            int rootDepth = 0;
            mRoot = new KdTreeNode(worldMin, worldMax, new KdTreeAxis(rootDepth), allGeom);

            BuildKDTree(mRoot, rootDepth, allGeom);
        }
Пример #9
0
 private bool MetStopCriteria(KdTreeNode node, int depth, int numOfPrimitiveInNode)
 {
     return (depth > mMaxDepth || numOfPrimitiveInNode <= mMaxNumOfPrimitives);
 }
Пример #10
0
 private bool MetStopCriteria(KdTreeNode node, int depth, int numOfPrimitiveInNode)
 {
     return(depth > mMaxDepth || numOfPrimitiveInNode <= mMaxNumOfPrimitives);
 }