示例#1
0
static void run_test(const char* filename, PointData& data, unsigned short compressor, int requested_version=-1, int chunk_size=-1, bool random_seeks=false)
{
  //
  // COMPRESSION
  //

  // setting up LASzip parameters
  LASzip laszip;
  if (!laszip.setup(data.point_type, data.point_size, compressor))
  {
    log("ERROR on laszip.setup(): %s\n", laszip.get_error());
  }
  if (requested_version > -1) laszip.request_version((unsigned short)requested_version);
  if (chunk_size > -1) laszip.set_chunk_size((unsigned int)chunk_size);

  // packing up LASzip
  unsigned char* bytes;
  int num;
  if (!laszip.pack(bytes, num))
  {
    log("ERROR on laszip.pack(): %s\n", laszip.get_error());
  }

  // creating the output stream
  OStream* ost = new OStream(settings->use_iostream, filename);

  // creating the zipper
  LASzipper* laszipper = make_zipper(ost, &laszip);

  // allocating the data to read from
  data.setup(laszip.num_items, laszip.items);

  // writing the points
  if (chunk_size == 0)
  {
    if (random_seeks)
      write_points_explicit_chunk_seek(laszipper, data);
    else
      write_points_explicit_chunk(laszipper, data);
  }
  else
  {
    if (random_seeks)
      write_points_seek(laszipper, data);
    else
      write_points(laszipper, data);
  }

  // cleaning up
  delete laszipper;
  delete ost;

  //
  // DECOMPRESSION
  //

  // setting up LASzip parameters
  LASzip laszip_dec;
  if (!laszip_dec.unpack(bytes, num))
  {
    log("ERROR on laszip_dec.unpack(): %s\n", laszip_dec.get_error());
  }

  // creating the input stream
  IStream* ist = new IStream(settings->use_iostream, filename);

  // creating the unzipper
  LASunzipper* lasunzipper = make_unzipper(ist, &laszip_dec);

  // allocating the data to write into
  data.setup(laszip_dec.num_items, laszip_dec.items);
  
  // reading the points
  if (random_seeks)
    read_points_seek(lasunzipper, data);
  else
    read_points(lasunzipper, data);

  // cleaning up
  delete lasunzipper;
  delete ist;

  return;
}