Пример #1
0
  public void WritePoint(ByteBuffer bb) {

    byte[] punto = new byte[getSizeFormat()];

    // byte 1
    punto[0] = (byte) (getClassification() & 0xFF);

    // byte 2
    punto[1] = (byte) (getFlightLine() & 0xFF);

    // byte 3-4
    ByteUtilities.unsignedShort2Arr(getIntensity(), punto, 2);

    // bits 7 y 8 del byte 4
    punto[3] >>= 2;
    punto[3] += getEchoInformation();

    // bytes 4-8
    ByteUtilities.int2Arr(getX(), punto, 4);

    // bytes 8-12
    ByteUtilities.int2Arr(getY(), punto, 8);

    // bytes 12-16
    ByteUtilities.int2Arr(getZ(), punto, 12);

    // si hay gps leelo
    if (isTimeGPS) {

      // bytes 16-20
      ByteUtilities.int2Arr(time, punto, 16);

      if (isColor) {
        // bytes 20-24
        punto[20] = (byte) (color[0] & 0xFF);
        punto[21] = (byte) (color[1] & 0xFF);
        punto[22] = (byte) (color[2] & 0xFF);
        punto[23] = (byte) (color[3] & 0xFF);
      }
    } else {

      // si hay color leelo
      if (isColor) {

        // bytes 16-20
        punto[16] = (byte) (color[0] & 0xFF);
        punto[17] = (byte) (color[1] & 0xFF);
        punto[18] = (byte) (color[2] & 0xFF);
        punto[19] = (byte) (color[3] & 0xFF);
      }
    }

    bb.put(punto);

    return;
  }
Пример #2
0
  /**
   * 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));
  }
Пример #3
0
  /**
   * 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();
    }
  }
Пример #4
0
  /**
   * 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());
  }
Пример #5
0
  /**
   * Generates the EPL2 commands to print an image. One command is emitted per line of the image.
   * This avoids issues with too long commands.
   *
   * @return The commands to print the image as an array of bytes, ready to be sent to the printer
   */
  public byte[] getImageCommand() throws InvalidRawImageException, UnsupportedEncodingException {
    this.getByteBuffer().clear();

    switch (languageType) {
      case ESCP:
      case ESCP2:
        appendEpsonSlices(this.getByteBuffer());
        break;
      case ZPL:
      case ZPLII:
        String zplHexAsString = ByteUtilities.getHexString(getImageAsIntArray());
        int byteLen = zplHexAsString.length() / 2;
        int perRow = byteLen / getHeight();
        StringBuilder zpl =
            new StringBuilder("^GFA,")
                .append(byteLen)
                .append(",")
                .append(byteLen)
                .append(",")
                .append(perRow)
                .append(",")
                .append(zplHexAsString);

        this.getByteBuffer().append(zpl, charset);
        break;
      case EPL:
      case EPL2:
        StringBuilder epl =
            new StringBuilder("GW")
                .append(getxPos())
                .append(",")
                .append(getyPos())
                .append(",")
                .append(getWidth() / 8)
                .append(",")
                .append(getHeight())
                .append(",");

        this.getByteBuffer().append(epl, charset).append(getBytes());
        break;
      case CPCL:
        String cpclHexAsString = ByteUtilities.getHexString(getImageAsIntArray());
        StringBuilder cpcl =
            new StringBuilder("EG ")
                .append((int) (getWidth() / 8))
                .append(" ")
                .append(getHeight())
                .append(" ")
                .append(getxPos())
                .append(" ")
                .append(getyPos())
                .append(" ")
                .append(cpclHexAsString);

        this.getByteBuffer().append(cpcl, charset);
        break;
      default:
        throw new InvalidRawImageException(
            charset.name() + " image conversion is not yet supported.");
    }
    return this.getByteBuffer().getByteArray();
  }