Ejemplo n.º 1
0
        public virtual IPointCloudBinarySource CreateSegment(long pointIndex, long pointCount)
        {
            long offset  = PointDataOffset + pointIndex * PointSizeBytes;
            var  segment = new PointCloudBinarySource(FileHandler, pointCount, Extent, Quantization, offset, PointSizeBytes);

            return(segment);
        }
Ejemplo n.º 2
0
        protected virtual IPointCloudBinarySource CreateBinaryWrapper()
        {
            // params I need?
            // (skip global encoding)
            // (skip file creation date)
            // vlrs
            // evlrs
            // attributes that make up point format
            // point count
            // quantization
            // extent
            // points by return

            // create parameters
            //Parameter<Extent3D>.Define("Extent", m_extent);
            //Parameter<SQuantization3D>.Define("Quantization", m_header.Quantization);
            //Parameter<ulong>.Define("PointCount", m_header.PointCount);

            var source = new PointCloudBinarySource(this, Count, m_extent, m_header.Quantization, PointDataOffset, PointSizeBytes);

            return(source);
        }
Ejemplo n.º 3
0
        public unsafe PointCloudBinarySource ConvertTextToBinary(string binaryPath, ProgressManager progressManager)
        {
            short pointSizeBytes = 3 * sizeof(double);

            double minX = 0, minY = 0, minZ = 0;
            double maxX = 0, maxY = 0, maxZ = 0;
            int pointCount = 0;

            using (var process = progressManager.StartProcess("ConvertTextToBinary"))
            {
                BufferInstance inputBuffer = process.AcquireBuffer(true);
                BufferInstance outputBuffer = process.AcquireBuffer(true);

                int pointsPerBuffer = outputBuffer.Length / pointSizeBytes;
                int usableBytesPerBuffer = pointsPerBuffer * pointSizeBytes;

                byte* inputBufferPtr = inputBuffer.DataPtr;
                byte* outputBufferPtr = outputBuffer.DataPtr;

                int bufferIndex = 0;
                int skipped = 0;

                using (var inputStream = StreamManager.OpenReadStream(FilePath))
                {
                    long inputLength = inputStream.Length;
                    long estimatedOutputLength = inputLength;

                    using (var outputStream = StreamManager.OpenWriteStream(binaryPath, estimatedOutputLength, 0, true))
                    {
                        int bytesRead;
                        int readStart = 0;

                        while ((bytesRead = inputStream.Read(inputBuffer.Data, readStart, inputBuffer.Length - readStart)) > 0)
                        {
                            bytesRead += readStart;
                            readStart = 0;
                            int i = 0;

                            while (i < bytesRead)
                            {
                                // identify line start
                                while (i < bytesRead && (inputBufferPtr[i] == '\r' || inputBufferPtr[i] == '\n'))
                                {
                                    ++i;
                                }

                                int lineStart = i;

                                // identify line end
                                while (i < bytesRead && inputBufferPtr[i] != '\r' && inputBufferPtr[i] != '\n')
                                {
                                    ++i;
                                }

                                // handle buffer overlap
                                if (i == bytesRead)
                                {
                                    Array.Copy(inputBuffer.Data, lineStart, inputBuffer.Data, 0, i - lineStart);
                                    readStart = i - lineStart;
                                    break;
                                }

                                // this may get overwritten if this is not a valid parse
                                double* p = (double*)(outputBufferPtr + bufferIndex);

                                if (!ParseXYZFromLine(inputBufferPtr, lineStart, i, p))
                                {
                                    ++skipped;
                                    continue;
                                }

                                if (pointCount == 0)
                                {
                                    minX = maxX = p[0];
                                    minY = maxY = p[1];
                                    minZ = maxZ = p[2];
                                }
                                else
                                {
                                    if (p[0] < minX) minX = p[0];
                                    else if (p[0] > maxX) maxX = p[0];
                                    if (p[1] < minY) minY = p[1];
                                    else if (p[1] > maxY) maxY = p[1];
                                    if (p[2] < minZ) minZ = p[2];
                                    else if (p[2] > maxZ) maxZ = p[2];
                                }

                                bufferIndex += pointSizeBytes;
                                ++pointCount;

                                // write usable buffer chunk
                                if (usableBytesPerBuffer == bufferIndex)
                                {
                                    outputStream.Write(outputBuffer.Data, 0, bufferIndex);
                                    bufferIndex = 0;
                                }
                            }

                            if (!process.Update((float)inputStream.Position / inputLength))
                                break;
                        }

                        // write remaining buffer
                        if (bufferIndex > 0)
                            outputStream.Write(outputBuffer.Data, 0, bufferIndex);
                    }
                }

                process.Log("Skipped {0} lines", skipped);
                process.LogTime("Copied {0:0,0} points", pointCount);
            }

            var extent = new Extent3D(minX, minY, minZ, maxX, maxY, maxZ);

            var source = new PointCloudBinarySource(this, pointCount, extent, null, 0, pointSizeBytes);

            return source;
        }
Ejemplo n.º 4
0
        protected virtual IPointCloudBinarySource CreateBinaryWrapper()
        {
            // params I need?
            // (skip global encoding)
            // (skip file creation date)
            // vlrs
            // evlrs
            // attributes that make up point format
            // point count
            // quantization
            // extent
            // points by return

            // create parameters
            //Parameter<Extent3D>.Define("Extent", m_extent);
            //Parameter<SQuantization3D>.Define("Quantization", m_header.Quantization);
            //Parameter<ulong>.Define("PointCount", m_header.PointCount);

            var source = new PointCloudBinarySource(this, Count, m_extent, m_header.Quantization, PointDataOffset, PointSizeBytes);

            return source;
        }
Ejemplo n.º 5
0
 public virtual IPointCloudBinarySource CreateSegment(long pointIndex, long pointCount)
 {
     long offset = PointDataOffset + pointIndex * PointSizeBytes;
     var segment = new PointCloudBinarySource(FileHandler, pointCount, Extent, Quantization, offset, PointSizeBytes);
     return segment;
 }
Ejemplo n.º 6
0
        public unsafe PointCloudBinarySource ConvertTextToBinary(string binaryPath, ProgressManager progressManager)
        {
            short pointSizeBytes = 3 * sizeof(double);

            double minX = 0, minY = 0, minZ = 0;
            double maxX = 0, maxY = 0, maxZ = 0;
            int    pointCount = 0;

            using (var process = progressManager.StartProcess("ConvertTextToBinary"))
            {
                BufferInstance inputBuffer  = process.AcquireBuffer(true);
                BufferInstance outputBuffer = process.AcquireBuffer(true);

                int pointsPerBuffer      = outputBuffer.Length / pointSizeBytes;
                int usableBytesPerBuffer = pointsPerBuffer * pointSizeBytes;

                byte *inputBufferPtr  = inputBuffer.DataPtr;
                byte *outputBufferPtr = outputBuffer.DataPtr;

                int bufferIndex = 0;
                int skipped     = 0;

                using (var inputStream = StreamManager.OpenReadStream(FilePath))
                {
                    long inputLength           = inputStream.Length;
                    long estimatedOutputLength = inputLength;

                    using (var outputStream = StreamManager.OpenWriteStream(binaryPath, estimatedOutputLength, 0, true))
                    {
                        int bytesRead;
                        int readStart = 0;

                        while ((bytesRead = inputStream.Read(inputBuffer.Data, readStart, inputBuffer.Length - readStart)) > 0)
                        {
                            bytesRead += readStart;
                            readStart  = 0;
                            int i = 0;

                            while (i < bytesRead)
                            {
                                // identify line start
                                while (i < bytesRead && (inputBufferPtr[i] == '\r' || inputBufferPtr[i] == '\n'))
                                {
                                    ++i;
                                }

                                int lineStart = i;

                                // identify line end
                                while (i < bytesRead && inputBufferPtr[i] != '\r' && inputBufferPtr[i] != '\n')
                                {
                                    ++i;
                                }

                                // handle buffer overlap
                                if (i == bytesRead)
                                {
                                    Array.Copy(inputBuffer.Data, lineStart, inputBuffer.Data, 0, i - lineStart);
                                    readStart = i - lineStart;
                                    break;
                                }

                                // this may get overwritten if this is not a valid parse
                                double *p = (double *)(outputBufferPtr + bufferIndex);

                                if (!ParseXYZFromLine(inputBufferPtr, lineStart, i, p))
                                {
                                    ++skipped;
                                    continue;
                                }

                                if (pointCount == 0)
                                {
                                    minX = maxX = p[0];
                                    minY = maxY = p[1];
                                    minZ = maxZ = p[2];
                                }
                                else
                                {
                                    if (p[0] < minX)
                                    {
                                        minX = p[0];
                                    }
                                    else if (p[0] > maxX)
                                    {
                                        maxX = p[0];
                                    }
                                    if (p[1] < minY)
                                    {
                                        minY = p[1];
                                    }
                                    else if (p[1] > maxY)
                                    {
                                        maxY = p[1];
                                    }
                                    if (p[2] < minZ)
                                    {
                                        minZ = p[2];
                                    }
                                    else if (p[2] > maxZ)
                                    {
                                        maxZ = p[2];
                                    }
                                }

                                bufferIndex += pointSizeBytes;
                                ++pointCount;

                                // write usable buffer chunk
                                if (usableBytesPerBuffer == bufferIndex)
                                {
                                    outputStream.Write(outputBuffer.Data, 0, bufferIndex);
                                    bufferIndex = 0;
                                }
                            }

                            if (!process.Update((float)inputStream.Position / inputLength))
                            {
                                break;
                            }
                        }

                        // write remaining buffer
                        if (bufferIndex > 0)
                        {
                            outputStream.Write(outputBuffer.Data, 0, bufferIndex);
                        }
                    }
                }

                process.Log("Skipped {0} lines", skipped);
                process.LogTime("Copied {0:0,0} points", pointCount);
            }

            var extent = new Extent3D(minX, minY, minZ, maxX, maxY, maxZ);

            var source = new PointCloudBinarySource(this, pointCount, extent, null, 0, pointSizeBytes);

            return(source);
        }