/** * Read a point of BIN file * * @param input input file to read * @param Offset Offset to data * @param index index of points to read * @return true if success else return false */ public void readPoint(BigByteBuffer2 input, LidarHeader hdr, long index) { try { if (index > hdr.getNumPointsRecord() || index < 0) { throw new UnexpectedPointException("Out of Index"); } if (index == lasIndex) return; else lasIndex = index; int auxIndex; byte[] punto = new byte[getSizeFormat()]; byte[] aux = new byte[2]; input.position(hdr.getOffsetData() + getSizeFormat() * index); input.get(punto); setClassification((char) (punto[0] & 0xFF)); setFlightLine((char) (punto[1] & 0xFF)); aux[0] = punto[2]; aux[1] = (byte) (punto[3] & 0X3F); setIntensity(ByteUtilities.arr2Unsignedshort(aux, 0)); // bits de 0-13 setEchoInformation((byte) ((punto[3] & 0xC0) >> 2)); // bits 14 y 15 setX(ByteUtilities.arr2Int(punto, 4)); setY(ByteUtilities.arr2Int(punto, 8)); setZ(ByteUtilities.arr2Int(punto, 12)); auxIndex = 16; // si hay gps leelo if (isTimeGPS) { setTime(ByteUtilities.arr2Int(punto, auxIndex)); auxIndex += 4; } // si hay color leelo if (isColor) { char[] c = new char[4]; c[0] = (char) (punto[auxIndex] & 0xFF); c[1] = (char) (punto[auxIndex + 1] & 0xFF); c[2] = (char) (punto[auxIndex + 2] & 0xFF); c[3] = (char) (punto[auxIndex + 3] & 0xFF); setcolor(c); } } catch (UnexpectedPointException e) { e.printStackTrace(); } }
/** * Read x and y in point of BIN file * * @param input input buffer to read * @param Offset Offset to data * @param index index of points to read * @return true if success else return false */ public Point2D.Double readPoint2D(BigByteBuffer2 input, LidarHeader hdr, long index) { byte[] punto = new byte[12]; input.position((hdr.getOffsetData() + getSizeFormat() * index) + 4); input.get(punto); setX(ByteUtilities.arr2Int(punto, 4)); setY(ByteUtilities.arr2Int(punto, 8)); return new Point2D.Double( (getX() - hdr.getXOffset()) / hdr.getXScale(), (getY() - hdr.getYOffset()) / hdr.getYScale()); }
/** * Read a x, y and z in point of LAS file * * @param input input buffer to read * @param Offset Offset to data * @param index index of points to read * @return true if success else return false */ public void readPoint3D(BigByteBuffer2 input, LidarHeader hdr, long index) { byte[] punto = new byte[16]; input.position((hdr.getOffsetData() + getSizeFormat() * index) + 4); input.get(punto); setX(ByteUtilities.arr2Int(punto, 4)); setY(ByteUtilities.arr2Int(punto, 8)); setZ(ByteUtilities.arr2Int(punto, 12)); }
public Object getFieldValueByName( BigByteBuffer2 bb, String nameField, LidarHeader hdr, long index) { readPoint(bb, hdr, index); if (nameField.equalsIgnoreCase("X")) { return (getX() - hdr.getXOffset()) / hdr.getXScale(); } else if (nameField.equalsIgnoreCase("Y")) { return (getY() - hdr.getYOffset()) / hdr.getYScale(); } else if (nameField.equalsIgnoreCase("Z")) { return (getZ() - hdr.getZOffset()) / hdr.getZScale(); } else if (nameField.equalsIgnoreCase("Intensity")) { return getIntensity(); } else if (nameField.equalsIgnoreCase("Classification")) { return getClassification(); } else if (nameField.equalsIgnoreCase("Line")) { return getFlightLine(); } else if (nameField.equalsIgnoreCase("Echo")) { return getEchoInformation(); } else if (nameField.equalsIgnoreCase("Time")) { return getTime(); } else if (nameField.equalsIgnoreCase("R")) { return getR(); } else if (nameField.equalsIgnoreCase("G")) { return getG(); } else if (nameField.equalsIgnoreCase("B")) { return getB(); } else if (nameField.equalsIgnoreCase("I")) { return getI(); } return null; }
/* * Set Point from a row * @see com.dielmo.gvsig.lidar.LidarPoint#setPoint(com.hardcode.gdbms.engine.values.Value[], com.dielmo.gvsig.lidar.LidarHeader) */ public void setPoint(Object[] row, LidarHeader hdr) { double auxX = (Double) row[0]; double auxY = (Double) row[1]; double auxZ = (Double) row[2]; setX((int) (auxX * (hdr.getXScale()) + hdr.getXOffset())); setY((int) (auxY * (hdr.getYScale()) + hdr.getYOffset())); setZ((int) (auxZ * (hdr.getZScale()) + hdr.getZOffset())); setIntensity((Integer) row[3]); setClassification((char) (((Integer) (row[4])).byteValue() & 0xFF)); setFlightLine((char) (((Integer) (row[5])).byteValue() & 0xFF)); setEchoInformation(((Integer) (row[6])).byteValue()); if (hdr instanceof BINHeader) { BINHeader hdrBin = (BINHeader) hdr; if (hdrBin.getTime() > 0) { setTime((Integer) row[7]); if (hdrBin.getColor() > 0) { color[0] = (char) (((Integer) (row[8])).byteValue() & 0xFF); color[1] = (char) (((Integer) (row[9])).byteValue() & 0xFF); color[2] = (char) (((Integer) (row[10])).byteValue() & 0xFF); color[3] = (char) (((Integer) (row[11])).byteValue() & 0xFF); } } else { if (hdrBin.getColor() > 0) { color[0] = (char) (((Integer) (row[7])).byteValue() & 0xFF); color[1] = (char) (((Integer) (row[8])).byteValue() & 0xFF); color[2] = (char) (((Integer) (row[9])).byteValue() & 0xFF); color[3] = (char) (((Integer) (row[10])).byteValue() & 0xFF); } } } }
/** * get field value by index: * * <p>0 return X 1 return Y 2 return Z 3 return intensity 4 return classification 5 return Line 6 * return echo information 7-11 Time and Color RGBI * * @param bb byte buffer of data * @param indexField index of field * @param hdr LiDAR header * @param index asked point index. (row) * @return Value of row and column indicated */ public Object getFieldValueByIndex( BigByteBuffer2 bb, int indexField, LidarHeader hdr, long index) { readPoint(bb, hdr, index); switch (indexField) { case 0: return (getX() - hdr.getXOffset()) / hdr.getXScale(); case 1: return (getY() - hdr.getYOffset()) / hdr.getYScale(); case 2: return (getZ() - hdr.getZOffset()) / hdr.getZScale(); case 3: return getIntensity(); case 4: return getClassification(); case 5: return getFlightLine(); case 6: return getEchoInformation(); case 7: if (isTimeGPS) { return getTime(); } else if (isColor) { return getR(); } case 8: if (isTimeGPS) { return getR(); } else if (isColor) { return getG(); } case 9: if (isTimeGPS) { return getG(); } else if (isColor) { return getB(); } case 10: if (isTimeGPS) { return getB(); } else if (isColor) { return getI(); } case 11: if (isTimeGPS) { return getI(); } } return null; }