Exemplo n.º 1
0
        public ILiDARData Open(string fileName)
        {
            LasReader reader = new LasReader(fileName);
            reader.initialize();

            // how many points do we have?
            ulong numPoints = reader.getNumPoints();
            // create the point buffer we'll read into
            // make it only hold 128 points a time, so we can show iterating
            Schema schema = reader.getSchema();
            SchemaLayout layout = new SchemaLayout(schema);
            PointBuffer data = new PointBuffer(layout, 128);

            // get the dimensions (fields) of the point record for the X, Y, and Z values
            int offsetX = schema.getDimensionIndex(Dimension.Field.Field_X, Dimension.DataType.Int32);
            int offsetY = schema.getDimensionIndex(Dimension.Field.Field_Y, Dimension.DataType.Int32);
            int offsetZ = schema.getDimensionIndex(Dimension.Field.Field_Z, Dimension.DataType.Int32);
            Dimension dimensionX = schema.getDimension((uint)offsetX);
            Dimension dimensionY = schema.getDimension((uint)offsetY);
            Dimension dimensionZ = schema.getDimension((uint)offsetZ);

            // make the iterator to read from the file
            StageSequentialIterator iter = reader.createSequentialIterator();

            uint totalRead = 0;

            while (!iter.atEnd())
            {
                uint numRead = iter.read(data);
                totalRead += numRead;
                 // did we just read the first block of 128 points?
                // if so, let's check the first point in the buffer
                // (which is point number 0 in the file) and make sure 
                // it is correct
                if (iter.getIndex() == 128)
                {
                    uint pointIndex = 0;

                    // get the raw data from the 1st point record in the point buffer
                    int x0raw = data.getField_Int32(pointIndex, offsetX);
                    int y0raw = data.getField_Int32(pointIndex, offsetY);
                    int z0raw = data.getField_Int32(pointIndex, offsetZ);

                    // LAS stores the data in scaled integer form: undo the scaling
                    // so we can see the real values as doubles
                    double x0 = dimensionX.applyScaling_Int32(x0raw);
                    double y0 = dimensionY.applyScaling_Int32(y0raw);
                    double z0 = dimensionZ.applyScaling_Int32(z0raw);

                    // make sure the X, Y, Z fields are correct!
                    //Debug.Assert(x0 == 637012.240000);
                    //Debug.Assert(y0 == 849028.310000);
                    //Debug.Assert(z0 == 431.660000);
                    Console.WriteLine("point 0 is correct");
                }
            }
            return new LiDARData();
        }
Exemplo n.º 2
0
        public LiDARDataSet(string filename)
        {
            //here read the maxX, maxY from the las file header
            //and change the Extent property
            LasReader Reader = new LasReader(filename);
            Reader.initialize();
            ulong PointNum = Reader.getNumPoints();
            int ArrayLength = (int)PointNum;
            //Range_double range = Reader.getBounds();
            //Reader.getBounds
            //Bounds_double ll = Reader.getBounds();
            Schema schema = Reader.getSchema();
            PointBuffer data = new PointBuffer(schema, (uint)PointNum);

            // get the dimensions (fields) of the point record for the X, Y, and Z values
            int offsetX = schema.getDimensionIndex(DimensionId.Id.X_i32);
            int offsetY = schema.getDimensionIndex(DimensionId.Id.Y_i32);
            int offsetZ = schema.getDimensionIndex(DimensionId.Id.Z_i32);
            Dimension dimensionX = schema.getDimension((uint)offsetX);
            Dimension dimensionY = schema.getDimension((uint)offsetY);
            Dimension dimensionZ = schema.getDimension((uint)offsetZ);

            // make the iterator to read from the file
            StageSequentialIterator iter = Reader.createSequentialIterator();
            uint numRead = iter.read(data);

            int xraw = data.getField_Int32(0, offsetX);
            int yraw = data.getField_Int32(0, offsetY);

            // LAS stores the data in scaled integer form: undo the scaling
            // so we can see the real values as doubles
            double MinX, MaxX, MinY, MaxY;
            MinX = MaxX = dimensionX.applyScaling_Int32(xraw);
            MinY = MaxY = dimensionY.applyScaling_Int32(yraw);

            for (int i = 1; i < ArrayLength; i++)
            {
                xraw = data.getField_Int32((uint)i, offsetX);
                yraw = data.getField_Int32((uint)i, offsetY);

                // LAS stores the data in scaled integer form: undo the scaling
                // so we can see the real values as doubles
                double x = dimensionX.applyScaling_Int32(xraw);
                double y = dimensionY.applyScaling_Int32(yraw);

                if (x < MinX) MinX = x;
                if (x > MaxX) MaxX = x;
                if (y < MinY) MinY = y;
                if (y > MaxY) MaxY = y;
            }
            setupExtent = new Extent(MinX, MinY, MaxX, MaxY);
        }
Exemplo n.º 3
0
        /// <summary>
        /// This method simulates loading the array of points from the LAS file.
        /// Right now it is generating random points that are within the
        /// view extent.
        /// </summary>
        /// <param name="boundingBox">the view extent</param>
        /// <returns>array of the points in [x y x y ... order]</returns>
        public double[] GetPointArray(Extent boundingBox)
        {
            LasReader Reader = new LasReader("C:\\Tile_1.las");

            Reader.initialize();
            ulong numPoints   = Reader.getNumPoints();
            int   ArrayLength = (int)numPoints;

            double[] pointArray = new double[numPoints];

            Random rnd  = new Random();
            double xMin = boundingBox.MinX;
            double yMin = boundingBox.MinY;

            // create the point buffer we'll read into
            // make it only hold 128 points a time, so we can show iterating
            Schema      schema = Reader.getSchema();
            PointBuffer data   = new PointBuffer(schema, (uint)numPoints);

            // get the dimensions (fields) of the point record for the X, Y, and Z values
            int       offsetX    = schema.getDimensionIndex(DimensionId.Id.X_i32);
            int       offsetY    = schema.getDimensionIndex(DimensionId.Id.Y_i32);
            int       offsetZ    = schema.getDimensionIndex(DimensionId.Id.Z_i32);
            Dimension dimensionX = schema.getDimension((uint)offsetX);
            Dimension dimensionY = schema.getDimension((uint)offsetY);
            Dimension dimensionZ = schema.getDimension((uint)offsetZ);

            // make the iterator to read from the file
            StageSequentialIterator iter = Reader.createSequentialIterator();
            uint numRead = iter.read(data);

            for (int i = 0; i < ArrayLength; i++)
            {
                int xraw = data.getField_Int32((uint)i, offsetX);
                int yraw = data.getField_Int32((uint)i, offsetY);
                int zraw = data.getField_Int32((uint)i, offsetZ);

                // LAS stores the data in scaled integer form: undo the scaling
                // so we can see the real values as doubles
                double x = dimensionX.applyScaling_Int32(xraw);
                double y = dimensionY.applyScaling_Int32(yraw);
                double z = dimensionZ.applyScaling_Int32(zraw);

                //double randomX = xMin + rnd.NextDouble() * boundingBox.Width;
                //double randomY = yMin + rnd.NextDouble() * boundingBox.Height;
                pointArray[i] = x;
                i             = i + 1;
                pointArray[i] = y;
            }
            return(pointArray);
        }
        private void DrawSection(Graphics g, PointBuffer points, int start, int length)
        {
            if (length > 1) // DrawLines crashes if there isn't at least two points
            {
                Point[] _buffer;

                _buffer = ArrayPool <Point> .Shared.Allocate(length);

                points.CopyTo(start, _buffer, 0, length);

                g.DrawLines(_tailPen, _buffer);

                ArrayPool <Point> .Shared.Free(_buffer);
            }
        }
        private bool HasSplitResults(PointBuffer _snakeBody)
        {
            bool result;

            result = false;

            for (int i = 1; i < _snakeBody.Size; i++)
            {
                if (Geometry.GetDistance(_snakeBody.PeekAt(i - 1), _snakeBody.PeekAt(i)) > 1)
                {
                    result = true;
                    break;
                }
            }

            return(result);
        }
Exemplo n.º 6
0
        /// <summary>
        /// This method simulates loading the array of points from the LAS file.
        /// Right now it is generating random points that are within the
        /// view extent.
        /// </summary>
        /// <param name="boundingBox">the view extent</param>
        /// <returns>array of the points in [x y x y ... order]</returns>
        public double[] GetPointArray(Extent boundingBox)
        {
            LasReader Reader = new LasReader("C:\\Tile_1.las");
            Reader.initialize();
            ulong numPoints = Reader.getNumPoints();
            int ArrayLength = (int)numPoints;

            double[] pointArray = new double[numPoints];

            Random rnd = new Random();
            double xMin = boundingBox.MinX;
            double yMin = boundingBox.MinY;

            // create the point buffer we'll read into
            // make it only hold 128 points a time, so we can show iterating
            Schema schema = Reader.getSchema();
            PointBuffer data = new PointBuffer(schema, (uint)numPoints);

            // get the dimensions (fields) of the point record for the X, Y, and Z values
            int offsetX = schema.getDimensionIndex(DimensionId.Id.X_i32);
            int offsetY = schema.getDimensionIndex(DimensionId.Id.Y_i32);
            int offsetZ = schema.getDimensionIndex(DimensionId.Id.Z_i32);
            Dimension dimensionX = schema.getDimension((uint)offsetX);
            Dimension dimensionY = schema.getDimension((uint)offsetY);
            Dimension dimensionZ = schema.getDimension((uint)offsetZ);

            // make the iterator to read from the file
            StageSequentialIterator iter = Reader.createSequentialIterator();
            uint numRead = iter.read(data);
            for (int i = 0; i < ArrayLength; i++)
            {
                int xraw = data.getField_Int32((uint)i, offsetX);
                int yraw = data.getField_Int32((uint)i, offsetY);
                int zraw = data.getField_Int32((uint)i, offsetZ);

                // LAS stores the data in scaled integer form: undo the scaling
                // so we can see the real values as doubles
                double x = dimensionX.applyScaling_Int32(xraw);
                double y = dimensionY.applyScaling_Int32(yraw);
                double z = dimensionZ.applyScaling_Int32(zraw);

                //double randomX = xMin + rnd.NextDouble() * boundingBox.Width;
                //double randomY = yMin + rnd.NextDouble() * boundingBox.Height;
                pointArray[i] = x;
                i = i + 1;
                pointArray[i] = y;
            }
            return pointArray;
        }
Exemplo n.º 7
0
        private void Test1()
        {
            Console.WriteLine("Starting LasReader test");

            // create the reader
            LasReader reader = new LasReader("../../test/data/1.2-with-color.las");
            reader.initialize();

            // how many points do we have?
            ulong numPoints = reader.getNumPoints();
            Debug.Assert(numPoints == 1065);

            Bounds_double bounds = reader.getBounds();
            Debug.Assert(closeTo(bounds.getMinimum().get(0), 635619.85));
            Debug.Assert(closeTo(bounds.getMinimum().get(1), 848899.70000000007));
            Debug.Assert(closeTo(bounds.getMinimum().get(2), 406.59000000000003));
            Debug.Assert(closeTo(bounds.getMaximum().get(0), 638982.55));
            Debug.Assert(closeTo(bounds.getMaximum().get(1), 853535.43));
            Debug.Assert(closeTo(bounds.getMaximum().get(2), 586.38));

            // create the point buffer we'll read into
            // make it only hold 128 points a time, so we can show iterating
            Schema schema = reader.getSchema();
            PointBuffer data = new PointBuffer(schema, 128);

            // get the dimensions (fields) of the point record for the X, Y, and Z values
            int offsetX = schema.getDimensionIndex(DimensionId.Id.X_i32);
            int offsetY = schema.getDimensionIndex(DimensionId.Id.Y_i32);
            int offsetZ = schema.getDimensionIndex(DimensionId.Id.Z_i32);
            Dimension dimensionX = schema.getDimension((uint)offsetX);
            Dimension dimensionY = schema.getDimension((uint)offsetY);
            Dimension dimensionZ = schema.getDimension((uint)offsetZ);

            // make the iterator to read from the file
            StageSequentialIterator iter = reader.createSequentialIterator();

            uint totalRead = 0;

            while (!iter.atEnd())
            {
                uint numRead = iter.read(data);
                totalRead += numRead;

                Console.WriteLine(numRead + " points read this time");

                // did we just read the first block of 128 points?
                // if so, let's check the first point in the buffer
                // (which is point number 0 in the file) and make sure
                // it is correct
                if (iter.getIndex() == 128)
                {
                    uint pointIndex = 0;

                    // get the raw data from the 1st point record in the point buffer
                    int x0raw = data.getField_Int32(pointIndex, offsetX);
                    int y0raw = data.getField_Int32(pointIndex, offsetY);
                    int z0raw = data.getField_Int32(pointIndex, offsetZ);

                    // LAS stores the data in scaled integer form: undo the scaling
                    // so we can see the real values as doubles
                    double x0 = dimensionX.applyScaling_Int32(x0raw);
                    double y0 = dimensionY.applyScaling_Int32(y0raw);
                    double z0 = dimensionZ.applyScaling_Int32(z0raw);

                    // make sure the X, Y, Z fields are correct!
                    Debug.Assert(x0 == 637012.240000);
                    Debug.Assert(y0 == 849028.310000);
                    Debug.Assert(z0 == 431.660000);
                    Console.WriteLine("point 0 is correct");
                }
            }

            // make sure we have read all the points in the file
            Debug.Assert(totalRead == numPoints);

            return;
        }
        private void DrawStrandTail(Graphics g, PointBuffer points)
        {
            if (points.Size > 1)
            {
                // don't do this!
                //g.DrawLines(_bodyPen, points.ToArray());

                if (!this.HasSplitResults(points))
                {
                    Point[] _buffer;

                    // this isn't great, but as Graphics.DrawLines
                    // isn't enlightened enough to take a start and length,
                    // we copy the buffer out of the CircularBuffer into an
                    // existing byte array so in theory we aren't allocating
                    // an array over and over again

                    _buffer = ArrayPool <Point> .Shared.Allocate(points.Size);

                    points.CopyTo(_buffer);

                    g.DrawLines(_tailPen, _buffer);

                    ArrayPool <Point> .Shared.Free(_buffer);
                }
                else
                {
                    int   start;
                    Point previous;
                    Point current;

                    // if we've wrapped the playing field, I can't just
                    // call DrawLines with the entire buffer as we'll get
                    // lines drawn across the entire playing field, so
                    // instead I need to break it down into smaller buffers

                    start    = 0;
                    previous = points.PeekAt(0);

                    for (int i = 1; i < points.Size; i++)
                    {
                        current = points.PeekAt(i);

                        if (Geometry.GetDistance(previous, current) > 1)
                        {
                            // here we have a split, so let us grab a subset of
                            // the buffer and draw our lines
                            this.DrawSection(g, points, start, i - start);
                            start = i;
                        }

                        previous = current;
                    }

                    if (start < points.Size)
                    {
                        this.DrawSection(g, points, start, points.Size - start);
                    }
                }
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LiDarDataSet"/> class.
        /// </summary>
        /// <param name="filename">Name of the file that is used in this dataset.</param>
        public LiDarDataSet(string filename)
        {
            // here read the maxX, maxY from the las file header
            // and change the Extent property
            LasReader reader = new LasReader(filename);

            reader.initialize();
            ulong pointNum    = reader.getNumPoints();
            int   arrayLength = (int)pointNum;

            Schema      schema = reader.getSchema();
            PointBuffer data   = new PointBuffer(schema, (uint)pointNum);

            // get the dimensions (fields) of the point record for the X, Y, and Z values
            int       offsetX    = schema.getDimensionIndex(DimensionId.Id.X_i32);
            int       offsetY    = schema.getDimensionIndex(DimensionId.Id.Y_i32);
            int       offsetZ    = schema.getDimensionIndex(DimensionId.Id.Z_i32);
            Dimension dimensionX = schema.getDimension((uint)offsetX);
            Dimension dimensionY = schema.getDimension((uint)offsetY);

            schema.getDimension((uint)offsetZ);

            // make the iterator to read from the file
            StageSequentialIterator iter = reader.createSequentialIterator();

            iter.read(data);

            int xraw = data.getField_Int32(0, offsetX);
            int yraw = data.getField_Int32(0, offsetY);

            // LAS stores the data in scaled integer form: undo the scaling
            // so we can see the real values as doubles
            double maxX, maxY;
            var    minX = maxX = dimensionX.applyScaling_Int32(xraw);
            var    minY = maxY = dimensionY.applyScaling_Int32(yraw);

            for (int i = 1; i < arrayLength; i++)
            {
                xraw = data.getField_Int32((uint)i, offsetX);
                yraw = data.getField_Int32((uint)i, offsetY);

                // LAS stores the data in scaled integer form: undo the scaling
                // so we can see the real values as doubles
                double x = dimensionX.applyScaling_Int32(xraw);
                double y = dimensionY.applyScaling_Int32(yraw);

                if (x < minX)
                {
                    minX = x;
                }
                if (x > maxX)
                {
                    maxX = x;
                }
                if (y < minY)
                {
                    minY = y;
                }
                if (y > maxY)
                {
                    maxY = y;
                }
            }

            _setupExtent = new Extent(minX, minY, maxX, maxY);
        }
Exemplo n.º 10
0
        /// <inheritdoc />
        /// <summary>
        ///     This section when called will read the data that is contained in
        ///     the list that was passed in from the constructor.
        /// </summary>
        public override void ReadSection()
        {
            // Iterate through the list of tagged data
            for (var currentIndex = StartIndex;
                 currentIndex < DataList.Length;
                 ++currentIndex)
            {
                // set the current data
                var currentData = DataList.GetPair(currentIndex);

                // Set the ending index of the file and break out of the loop
                if (currentData.GroupCode == GroupCodesBase.EndSectionMarker)
                {
                    EndIndex = currentIndex;
                    break;
                }

                // The master switch for the values
                switch (currentData.Value)
                {
                /*
                 * All Entities Cases will follow the same formula:
                 * 1. Create a new Buffer class
                 * 2. pass the Data list to the buffer class with the starting
                 *    index of the entity.
                 * 3. Add the entity to the entity list
                 */

                // LINE
                case LineGroupCodes.StartMarker:
                    var lineBuffer = new LineBuffer();
                    lineBuffer.Parse(DataList, currentIndex);
                    Entities.Add(new Line(lineBuffer));
                    continue;

                // LWPOLYLINE
                case LwPolylineCodes.StartMarker:
                    var lwPolyLineBuffer = new LwPolyLineBuffer();
                    lwPolyLineBuffer.Parse(DataList, currentIndex);
                    Entities.Add(new LwPolyLine(lwPolyLineBuffer));
                    continue;

                // HATCH
                case HatchCodes.StartMarker:
                    var hatchBuffer = new HatchBuffer();
                    hatchBuffer.Parse(DataList, currentIndex);
                    Entities.Add(new Hatch(hatchBuffer));
                    continue;

                // ARC
                case CircularArcCodes.ArcStartMarker:
                    var arcBuffer = new CircularArcBuffer();
                    arcBuffer.Parse(DataList, currentIndex);
                    Entities.Add(new CircularArc(arcBuffer));
                    continue;

                // TEXT
                case TextCodes.StartMarker:
                    var textBuffer = new TextBuffer();
                    textBuffer.Parse(DataList, currentIndex);
                    Entities.Add(new Text(textBuffer));
                    continue;

                // MTEXT
                case MTextCodes.StartMarker:
                    var mTextBuffer = new MTextBuffer();
                    mTextBuffer.Parse(DataList, currentIndex);
                    Entities.Add(new MText(mTextBuffer));
                    continue;

                // POINT
                case PointCodes.StartMarker:
                    var pointBuffer = new PointBuffer();
                    pointBuffer.Parse(DataList, currentIndex);
                    Entities.Add(new Point(pointBuffer));
                    continue;

                // CIRCLE
                case CircularArcCodes.CircleStartMarker:
                    var circleBuffer = new CircularArcBuffer();
                    circleBuffer.Parse(DataList, currentIndex);
                    Entities.Add(new Circle(circleBuffer));
                    break;

                // DEFAULT
                default:
                    continue;
                }
            }
        }
Exemplo n.º 11
0
        public LiDARDataSet(string filename)
        {
            //here read the maxX, maxY from the las file header
            //and change the Extent property
            LasReader Reader = new LasReader(filename);

            Reader.initialize();
            ulong PointNum    = Reader.getNumPoints();
            int   ArrayLength = (int)PointNum;
            //Range_double range = Reader.getBounds();
            //Reader.getBounds
            //Bounds_double ll = Reader.getBounds();
            Schema      schema = Reader.getSchema();
            PointBuffer data   = new PointBuffer(schema, (uint)PointNum);

            // get the dimensions (fields) of the point record for the X, Y, and Z values
            int       offsetX    = schema.getDimensionIndex(DimensionId.Id.X_i32);
            int       offsetY    = schema.getDimensionIndex(DimensionId.Id.Y_i32);
            int       offsetZ    = schema.getDimensionIndex(DimensionId.Id.Z_i32);
            Dimension dimensionX = schema.getDimension((uint)offsetX);
            Dimension dimensionY = schema.getDimension((uint)offsetY);
            Dimension dimensionZ = schema.getDimension((uint)offsetZ);

            // make the iterator to read from the file
            StageSequentialIterator iter = Reader.createSequentialIterator();
            uint numRead = iter.read(data);

            int xraw = data.getField_Int32(0, offsetX);
            int yraw = data.getField_Int32(0, offsetY);

            // LAS stores the data in scaled integer form: undo the scaling
            // so we can see the real values as doubles
            double MinX, MaxX, MinY, MaxY;

            MinX = MaxX = dimensionX.applyScaling_Int32(xraw);
            MinY = MaxY = dimensionY.applyScaling_Int32(yraw);

            for (int i = 1; i < ArrayLength; i++)
            {
                xraw = data.getField_Int32((uint)i, offsetX);
                yraw = data.getField_Int32((uint)i, offsetY);

                // LAS stores the data in scaled integer form: undo the scaling
                // so we can see the real values as doubles
                double x = dimensionX.applyScaling_Int32(xraw);
                double y = dimensionY.applyScaling_Int32(yraw);

                if (x < MinX)
                {
                    MinX = x;
                }
                if (x > MaxX)
                {
                    MaxX = x;
                }
                if (y < MinY)
                {
                    MinY = y;
                }
                if (y > MaxY)
                {
                    MaxY = y;
                }
            }
            setupExtent = new Extent(MinX, MinY, MaxX, MaxY);
        }
Exemplo n.º 12
0
        private void Test1()
        {
            Console.WriteLine("Starting LasReader test");

            // create the reader
            LasReader reader = new LasReader("../../test/data/1.2-with-color.las");

            reader.initialize();

            // how many points do we have?
            ulong numPoints = reader.getNumPoints();

            Debug.Assert(numPoints == 1065);

            Bounds_double bounds = reader.getBounds();

            Debug.Assert(closeTo(bounds.getMinimum().get(0), 635619.85));
            Debug.Assert(closeTo(bounds.getMinimum().get(1), 848899.70000000007));
            Debug.Assert(closeTo(bounds.getMinimum().get(2), 406.59000000000003));
            Debug.Assert(closeTo(bounds.getMaximum().get(0), 638982.55));
            Debug.Assert(closeTo(bounds.getMaximum().get(1), 853535.43));
            Debug.Assert(closeTo(bounds.getMaximum().get(2), 586.38));

            // create the point buffer we'll read into
            // make it only hold 128 points a time, so we can show iterating
            Schema      schema = reader.getSchema();
            PointBuffer data   = new PointBuffer(schema, 128);

            // get the dimensions (fields) of the point record for the X, Y, and Z values
            int       offsetX    = schema.getDimensionIndex(DimensionId.Id.X_i32);
            int       offsetY    = schema.getDimensionIndex(DimensionId.Id.Y_i32);
            int       offsetZ    = schema.getDimensionIndex(DimensionId.Id.Z_i32);
            Dimension dimensionX = schema.getDimension((uint)offsetX);
            Dimension dimensionY = schema.getDimension((uint)offsetY);
            Dimension dimensionZ = schema.getDimension((uint)offsetZ);

            // make the iterator to read from the file
            StageSequentialIterator iter = reader.createSequentialIterator();

            uint totalRead = 0;

            while (!iter.atEnd())
            {
                uint numRead = iter.read(data);
                totalRead += numRead;

                Console.WriteLine(numRead + " points read this time");

                // did we just read the first block of 128 points?
                // if so, let's check the first point in the buffer
                // (which is point number 0 in the file) and make sure
                // it is correct
                if (iter.getIndex() == 128)
                {
                    uint pointIndex = 0;

                    // get the raw data from the 1st point record in the point buffer
                    int x0raw = data.getField_Int32(pointIndex, offsetX);
                    int y0raw = data.getField_Int32(pointIndex, offsetY);
                    int z0raw = data.getField_Int32(pointIndex, offsetZ);

                    // LAS stores the data in scaled integer form: undo the scaling
                    // so we can see the real values as doubles
                    double x0 = dimensionX.applyScaling_Int32(x0raw);
                    double y0 = dimensionY.applyScaling_Int32(y0raw);
                    double z0 = dimensionZ.applyScaling_Int32(z0raw);

                    // make sure the X, Y, Z fields are correct!
                    Debug.Assert(x0 == 637012.240000);
                    Debug.Assert(y0 == 849028.310000);
                    Debug.Assert(z0 == 431.660000);
                    Console.WriteLine("point 0 is correct");
                }
            }

            // make sure we have read all the points in the file
            Debug.Assert(totalRead == numPoints);

            return;
        }
Exemplo n.º 13
-1
        public ILiDARData Open(string fileName)
        {
            LasReader reader = new LasReader(fileName);

            reader.initialize();

            // how many points do we have?
            ulong numPoints = reader.getNumPoints();
            // create the point buffer we'll read into
            // make it only hold 128 points a time, so we can show iterating
            Schema       schema = reader.getSchema();
            SchemaLayout layout = new SchemaLayout(schema);
            PointBuffer  data   = new PointBuffer(layout, 128);

            // get the dimensions (fields) of the point record for the X, Y, and Z values
            int       offsetX    = schema.getDimensionIndex(Dimension.Field.Field_X, Dimension.DataType.Int32);
            int       offsetY    = schema.getDimensionIndex(Dimension.Field.Field_Y, Dimension.DataType.Int32);
            int       offsetZ    = schema.getDimensionIndex(Dimension.Field.Field_Z, Dimension.DataType.Int32);
            Dimension dimensionX = schema.getDimension((uint)offsetX);
            Dimension dimensionY = schema.getDimension((uint)offsetY);
            Dimension dimensionZ = schema.getDimension((uint)offsetZ);

            // make the iterator to read from the file
            StageSequentialIterator iter = reader.createSequentialIterator();

            uint totalRead = 0;

            while (!iter.atEnd())
            {
                uint numRead = iter.read(data);
                totalRead += numRead;
                // did we just read the first block of 128 points?
                // if so, let's check the first point in the buffer
                // (which is point number 0 in the file) and make sure
                // it is correct
                if (iter.getIndex() == 128)
                {
                    uint pointIndex = 0;

                    // get the raw data from the 1st point record in the point buffer
                    int x0raw = data.getField_Int32(pointIndex, offsetX);
                    int y0raw = data.getField_Int32(pointIndex, offsetY);
                    int z0raw = data.getField_Int32(pointIndex, offsetZ);

                    // LAS stores the data in scaled integer form: undo the scaling
                    // so we can see the real values as doubles
                    double x0 = dimensionX.applyScaling_Int32(x0raw);
                    double y0 = dimensionY.applyScaling_Int32(y0raw);
                    double z0 = dimensionZ.applyScaling_Int32(z0raw);

                    // make sure the X, Y, Z fields are correct!
                    //Debug.Assert(x0 == 637012.240000);
                    //Debug.Assert(y0 == 849028.310000);
                    //Debug.Assert(z0 == 431.660000);
                    Console.WriteLine("point 0 is correct");
                }
            }
            return(new LiDARData());
        }