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()); }
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(); }