예제 #1
0
        private Vector4[] CreateFileData(out float minx, out float miny, out float minz, out float maxx, out float maxy, out float maxz)
        {
            //string file = "../../test/data/1.2-with-color.las";
            string file = "../../test/data/hobu.las";

            Vector4 red   = new Vector4(1, 0, 0, 1);
            Vector4 green = new Vector4(0, 1, 0, 1);
            Vector4 blue  = new Vector4(0, 0, 1, 1);

            List <Vector4> points = new List <Vector4>();

            istream istr = Utils.openFile(file);

            m_reader = new LiblasReader(istr);

            Stage stage = m_reader;
            {
                int np = (int)m_reader.getNumPoints();
                if (np > 100000)
                {
                    int step = np / 100000;
                    m_filter = new DecimationFilter(m_reader, step);
                    stage    = m_filter;
                }
            }

            Header        header = stage.getHeader();
            Bounds_double bounds = header.getBounds();

            minx = (float)bounds.getMinimum(0);
            miny = (float)bounds.getMinimum(1);
            minz = (float)bounds.getMinimum(2);
            maxx = (float)bounds.getMaximum(0);
            maxy = (float)bounds.getMaximum(1);
            maxz = (float)bounds.getMaximum(2);

            // 1.2-with-color
            //minx 635619.9f
            //miny 848899.7f
            //minz 406.59f
            //maxx 638982.563
            //maxy 853535.438
            //maxz 586.38

            ulong numPoints = stage.getNumPoints();
            //numPoints = Math.Min(numPoints, 100000);

            Schema       schema = stage.getHeader().getSchema();
            SchemaLayout layout = new SchemaLayout(schema);

            PointData data = new PointData(layout, (uint)numPoints);

            uint numRead = stage.read(data);

            uint offsetX  = (uint)schema.getDimensionIndex(Dimension.Field.Field_X);
            uint offsetY  = (uint)schema.getDimensionIndex(Dimension.Field.Field_Y);
            uint offsetZ  = (uint)schema.getDimensionIndex(Dimension.Field.Field_Z);
            uint offsetR  = (uint)schema.getDimensionIndex(Dimension.Field.Field_Red);
            uint offsetG  = (uint)schema.getDimensionIndex(Dimension.Field.Field_Green);
            uint offsetBG = (uint)schema.getDimensionIndex(Dimension.Field.Field_Blue);

            for (uint index = 0; index < numRead; index++)
            {
                Int32 xraw = data.getField_Int32(index, offsetX);
                Int32 yraw = data.getField_Int32(index, offsetY);
                Int32 zraw = data.getField_Int32(index, offsetZ);
                float x    = (float)schema.getDimension(offsetX).getNumericValue_Int32(xraw);
                float y    = (float)schema.getDimension(offsetY).getNumericValue_Int32(yraw);
                float z    = (float)schema.getDimension(offsetZ).getNumericValue_Int32(zraw);

                if (index == 0)
                {
                    minx = maxx = x;
                    miny = maxy = y;
                    minz = maxz = z;
                }
                else
                {
                    minx = Math.Min(x, minx);
                    miny = Math.Min(y, miny);
                    minz = Math.Min(z, minz);
                    maxx = Math.Max(x, maxx);
                    maxy = Math.Max(y, maxy);
                    maxz = Math.Max(z, maxz);
                }

                UInt16 r = data.getField_UInt16(index, offsetX);
                UInt16 g = data.getField_UInt16(index, offsetY);
                UInt16 b = data.getField_UInt16(index, offsetZ);

                points.Add(new Vector4(x, y, z, 1));

                float rf = (float)r / 65535.0f;
                float gf = (float)g / 65535.0f;
                float bf = (float)b / 65535.0f;
                points.Add(new Vector4(rf, gf, bf, 1));
                //points.Add(blue);
            }

            Utils.closeFile(istr);

            return(points.ToArray());
        }
예제 #2
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;
        }