Exemplo n.º 1
0
            /// <summary>
            /// Creates a new BFSOctree out of a DynamicOctree.
            /// </summary>
            /// <param name="octree">The DynamicOctree to create this BFSOctree out of.</param>
            public BFSOctree(DynamicOctree octree)
            {
                dimension = octree.dimension;

                uint leafCount = octree.getLeafCount();
                _innerNodes = new BFSInnerNode[octree.getNodeCount() - leafCount];
                _leaves = new BFSLeaf[leafCount];

                convert(octree);
            }
Exemplo n.º 2
0
            /// <summary>
            /// Converts this triangle mesh into a DynamicOctree.
            /// !Important: Although nodes can have as few as 1 and as many as 8
            /// children, all leavs have the same depth. This is an important property that
            /// allows the created octree to be rendred on a CUDA implementation of asvo.
            /// </summary>
            /// <param name="maxLevel">The maximum node level/depth of any node in
            /// the created DynamicOctree.</param>
            /// <returns>A DynamicOctree representing this triangle mesh.</returns>
            private DynamicOctree toDynamicOctree(byte maxLevel)
            {
                DynamicOctree result;
                Vector3 min, max, center;
                float minX, minY, minZ, maxX, maxY, maxZ;
                double dimension, halfDimension;
                minX = minY = minZ = float.MaxValue;
                maxX = maxY = maxZ = float.MinValue;

                for (int i = 0; i < _vertices.Length; ++i)
                {
                    if (_vertices[i].position.X < minX)
                        minX = _vertices[i].position.X;
                    if (_vertices[i].position.X > maxX)
                        maxX = _vertices[i].position.X;

                    if (_vertices[i].position.Y < minY)
                        minY = _vertices[i].position.Y;
                    if (_vertices[i].position.Y > maxY)
                        maxY = _vertices[i].position.Y;

                    if (_vertices[i].position.Z < minZ)
                        minZ = _vertices[i].position.Z;
                    if (_vertices[i].position.Z > maxZ)
                        maxZ = _vertices[i].position.Z;
                }

                dimension = ((double)maxX) - ((double)minX);
                if ((((double)maxY) - ((double)minY)) > dimension)
                    dimension = ((double)maxY) - ((double)minY);
                if ((((double)maxZ) - ((double)minZ)) > dimension)
                    dimension = ((double)maxZ) - ((double)minZ);

                halfDimension = dimension * 0.5;
                center = new Vector3((maxX - minX) * 0.5f + minX,
                                     (maxY - minY) * 0.5f + minY,
                                     (maxZ - minZ) * 0.5f + minZ);

                min = center - new Vector3((float)halfDimension);
                max = center + new Vector3((float)halfDimension);

                result = new DynamicOctree(max.X - min.X);

                Vector3[] triangle = new Vector3[3];
                for (int i = 0; i < _indices.Length - 2; i += 3)
                {
                    minX = minY = minZ = float.MaxValue;
                    maxX = maxY = maxZ = float.MinValue;

                    for (int j = 0; j < 3; ++j)
                    {
                        triangle[j] = _vertices[_indices[i + j]].position;

                        if (triangle[j].X < minX)
                            minX = triangle[j].X;
                        if (triangle[j].X > maxX)
                            maxX = triangle[j].X;

                        if (triangle[j].Y < minY)
                            minY = triangle[j].Y;
                        if (triangle[j].Y > maxY)
                            maxY = triangle[j].Y;

                        if (triangle[j].Z < minZ)
                            minZ = triangle[j].Z;
                        if (triangle[j].Z > maxZ)
                            maxZ = triangle[j].Z;
                    }

                    traverse(0,
                             0, 0, 0,
                             min, dimension,
                             i,
                             new Vector3(minX, minY, minZ),
                             new Vector3(maxX, maxY, maxZ),
                             0, maxLevel,
                             result);
                }

                _vertices = null;
                _indices = null;

                return result;
            }