Exemplo n.º 1
0
        private void LoadThreadFunction()
        {
            var pt = new PotreeNode(new Uri(Location));

            var points = new PointGeometry3D();
            var col    = new Color4Collection();
            var ptPos  = new Vector3Collection();
            var ptIdx  = new IntCollection();

            var j = 0;

            foreach (var p in pt.Compilation.Points)
            {
                ptPos.Add(new Vector3(p.x, p.y, p.z));
                ptIdx.Add(j);
                col.Add(new Color4(p.r / 255f, p.g / 255f, p.b / 255f, p.a / 255f));
                j++;
            }

            var additionalTurns = 0;

            if ((pt.Compilation.Points.Count / 3) * 3 != pt.Compilation.Points.Count)
            {
                additionalTurns = ((pt.Compilation.Points.Count / 3 + 1) * 3) - pt.Compilation.Points.Count;
            }

            for (int i = 0; i < additionalTurns; i++)
            {
                ptIdx.Add(ptPos.Count);

                ptPos.Add(ptPos[ptPos.Count - 1]);
                col.Add(col[col.Count - 1]);
            }

            points.Positions = ptPos;
            points.Indices   = ptIdx;
            points.Colors    = col;

            Data = points;
        }
Exemplo n.º 2
0
        public void BuiltHierarchy()
        {
            // First read masks and point numbers to a queue
            Queue <byte> masks        = new Queue <byte>();
            Queue <int>  pointNumbers = new Queue <int>();

            using (BinaryReader b = new BinaryReader(File.Open(Settings.OctreeDir + @"\r.hrc", FileMode.Open)))
            {
                int pos = 0;

                int length = (int)b.BaseStream.Length;

                while (pos < length)
                {
                    var mask           = b.ReadByte();
                    var numberOfPoints = b.ReadInt32();

                    pos += sizeof(byte) + sizeof(Int32);

                    masks.Enqueue(mask);
                    pointNumbers.Enqueue(numberOfPoints);
                }
            }

            //Now to a breadth-first search to assemble the tree
            Queue <PotreeNode> nodeQueue = new Queue <PotreeNode>();

            nodeQueue.Enqueue(this);

            var previousNode = this;

            while (nodeQueue.Count > 0)
            {
                var node = nodeQueue.Dequeue();
                previousNode._next = node;

                node.Mask            = masks.Dequeue();
                node.NodePointNumber = pointNumbers.Dequeue();

                if (node.Level >= Settings.HierarchyStepSize)
                {
                    continue;
                }

                for (int i = 0; i < 8; i++)
                {
                    if ((node.Mask >> i & 0x01) == 1)
                    {
                        var n = new PotreeNode()
                        {
                            Level       = node.Level + 1,
                            Settings    = node.Settings,
                            Compilation = node.Compilation,
                            Filename    = node.Filename + i,
                            BoundingBox = GetBoundingBox(node.BoundingBox, i)
                        };

                        nodeQueue.Enqueue(n);
                        node.Children[i] = n;
                    }
                }

                previousNode = node;
            }
        }