Skip to content
This repository
Browse code

Add point2las

  • Loading branch information...
commit beb2a48a0ba8027cf5ec5c35d740905551c5e89c 1 parent 1b831c4
Oleg Alexandrov oleg-alexandrov authored

Showing 1 changed file with 118 additions and 0 deletions. Show diff stats Hide diff stats

  1. +118 0 src/asp/Tools/point2las.cc
118 src/asp/Tools/point2las.cc
... ... @@ -0,0 +1,118 @@
  1 +// __BEGIN_LICENSE__
  2 +// Copyright (c) 2009-2012, United States Government as represented by the
  3 +// Administrator of the National Aeronautics and Space Administration. All
  4 +// rights reserved.
  5 +//
  6 +// The NGT platform is licensed under the Apache License, Version 2.0 (the
  7 +// "License"); you may not use this file except in compliance with the
  8 +// License. You may obtain a copy of the License at
  9 +// http://www.apache.org/licenses/LICENSE-2.0
  10 +//
  11 +// Unless required by applicable law or agreed to in writing, software
  12 +// distributed under the License is distributed on an "AS IS" BASIS,
  13 +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14 +// See the License for the specific language governing permissions and
  15 +// limitations under the License.
  16 +// __END_LICENSE__
  17 +
  18 +
  19 +/// \file point2las.cc
  20 +///
  21 +
  22 +#include <fstream>
  23 +#include <iostream>
  24 +#include <string>
  25 +#include <boost/program_options.hpp>
  26 +#include <liblas/liblas.hpp>
  27 +
  28 +#include <asp/Core/Macros.h>
  29 +#include <asp/Core/Common.h>
  30 +
  31 +#include <vw/FileIO.h>
  32 +#include <vw/Image.h>
  33 +#include <vw/Math.h>
  34 +
  35 +using namespace vw;
  36 +namespace po = boost::program_options;
  37 +
  38 +// Allows FileIO to correctly read/write these pixel types
  39 +namespace vw {
  40 + template<> struct PixelFormatID<Vector3> { static const PixelFormatEnum value = VW_PIXEL_GENERIC_3_CHANNEL; };
  41 + template<> struct PixelFormatID<Vector4> { static const PixelFormatEnum value = VW_PIXEL_GENERIC_4_CHANNEL; };
  42 +}
  43 +
  44 +struct Options : asp::BaseOptions {
  45 +
  46 + // Input
  47 + std::string pointcloud_filename;
  48 +
  49 + // Output
  50 + std::string out_prefix; // output_file_type;
  51 +};
  52 +
  53 +void handle_arguments( int argc, char *argv[], Options& opt ) {
  54 +
  55 + po::options_description general_options("General Options");
  56 + general_options.add_options()
  57 + ("output-prefix,o", po::value(&opt.out_prefix), "Specify the output prefix");
  58 + //("output-filetype,t", po::value(&opt.output_file_type)->default_value("las"),
  59 + // "Specify the output file [las laz]");
  60 +
  61 + general_options.add( asp::BaseOptionsDescription(opt) );
  62 +
  63 + po::options_description positional("");
  64 + positional.add_options()
  65 + ("input-file", po::value(&opt.pointcloud_filename), "Input Point Cloud");
  66 +
  67 + po::positional_options_description positional_desc;
  68 + positional_desc.add("input-file", 1);
  69 +
  70 + std::string usage("<point-cloud> ...");
  71 + po::variables_map vm =
  72 + asp::check_command_line( argc, argv, opt, general_options,
  73 + positional, positional_desc, usage );
  74 +
  75 + if ( opt.pointcloud_filename.empty() )
  76 + vw_throw( ArgumentErr() << "Missing point cloud.\n"
  77 + << usage << general_options );
  78 +
  79 + if ( opt.out_prefix.empty() )
  80 + opt.out_prefix =
  81 + asp::prefix_from_filename( opt.pointcloud_filename );
  82 +
  83 +}
  84 +
  85 +int main( int argc, char *argv[] ) {
  86 +
  87 + // To do: Test the performance when switching from rows to cols.
  88 + // To do: Deal with the issue of scale and shift when converting
  89 + // to las to not lose precision.
  90 +
  91 + Options opt;
  92 + try {
  93 + handle_arguments( argc, argv, opt );
  94 +
  95 + DiskImageView<Vector4> point_disk_image(opt.pointcloud_filename);
  96 +
  97 + liblas::Header header;
  98 + header.SetDataFormatId(liblas::ePointFormat1);
  99 +
  100 + std::string lasFile = opt.out_prefix + ".las";
  101 + std::ofstream ofs;
  102 + ofs.open(lasFile.c_str(), std::ios::out | std::ios::binary);
  103 + liblas::Writer writer(ofs, header);
  104 +
  105 + for (int row = 0; row < point_disk_image.rows(); row++){
  106 + for (int col = 0; col < point_disk_image.cols(); col++){
  107 + Vector4 const& point = point_disk_image(row, col);
  108 + liblas::Point las_point;
  109 + las_point.SetCoordinates(point[0], point[1], point[2]);
  110 + writer.WritePoint(las_point);
  111 + }
  112 + }
  113 +
  114 +
  115 + } ASP_STANDARD_CATCHES;
  116 +
  117 + return 0;
  118 +}

0 comments on commit beb2a48

Please sign in to comment.
Something went wrong with that request. Please try again.