<commit_before>// __BEGIN_LICENSE__
//  Copyright (c) 2009-2013, United States Government as represented by the
//  Administrator of the National Aeronautics and Space Administration. All
//  rights reserved.
//
//  The NGT platform is licensed under the Apache License, Version 2.0 (the
//  "License"); you may not use this file except in compliance with the
//  License. You may obtain a copy of the License at
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
// __END_LICENSE__


/// \file pc_merge.cc
///
/// A simple tool to merge multiple point cloud files into a single file.

#include <asp/Core/PointUtils.h>
#include <asp/Core/Macros.h>
#include <asp/Core/Common.h>
#include <asp/Core/InpaintView.h>

#include <vw/Core/Stopwatch.h>
#include <vw/Mosaic/ImageComposite.h>
#include <vw/FileIO/DiskImageUtils.h>
#include <vw/Cartography/PointImageManipulation.h>

#include <limits>

using namespace vw;
using namespace vw::cartography;
namespace po = boost::program_options;
namespace fs = boost::filesystem;

// Allows FileIO to correctly read/write these pixel types
namespace vw {
  typedef Vector<float64,4> Vector4;
  typedef Vector<float64,6> Vector6;
  template<> struct PixelFormatID<Vector3>   { static const PixelFormatEnum value = VW_PIXEL_GENERIC_3_CHANNEL; };
  template<> struct PixelFormatID<Vector3f>  { static const PixelFormatEnum value = VW_PIXEL_GENERIC_3_CHANNEL; };
  template<> struct PixelFormatID<Vector4>   { static const PixelFormatEnum value = VW_PIXEL_GENERIC_4_CHANNEL; };
  template<> struct PixelFormatID<Vector6>   { static const PixelFormatEnum value = VW_PIXEL_GENERIC_6_CHANNEL; };
}

struct Options : asp::BaseOptions {
  // Input
  std::vector<std::string> pointcloud_files;

  // Settings
  //float nodata_value;
  bool  write_double;  ///< If true, output file is double instead of float

  // Output
  std::string out_path;

  // Defaults that the user doesn't need to see.
  Options() : //nodata_value(-std::numeric_limits<float>::max()), 
              write_double(false)
             {}
};


void handle_arguments( int argc, char *argv[], Options& opt ) {

  po::options_description general_options("General Options");
  general_options.add_options()
    //("nodata-value",      po::value(&opt.nodata_value)->default_value(-std::numeric_limits<float>::max()),
    //         "Set the nodata value.")
    ("output-path,o",   po::value(&opt.out_path),                             "Specify the output path.")
    ("write-double,d", po::value(&opt.write_double)->default_value(false), "Write a double precision output file.");

  general_options.add( asp::BaseOptionsDescription(opt) );

  po::options_description positional("");
  positional.add_options()
    ("input-files", po::value< std::vector<std::string> >(), "Input files");

  po::positional_options_description positional_desc;
  positional_desc.add("input-files", -1);

  std::string usage("[options] <point-clouds> ");
  bool allow_unregistered = false;
  std::vector<std::string> unregistered;
  po::variables_map vm =
    asp::check_command_line( argc, argv, opt, general_options, general_options,
                             positional, positional_desc, usage,
                             allow_unregistered, unregistered );

  if (vm.count("input-files") == 0)
    vw_throw( ArgumentErr() << "Missing input point clouds.\n"
                            << usage << general_options );
  opt.pointcloud_files = vm["input-files"].as< std::vector<std::string> >();

  //// Turn on logging to file
  //asp::log_to_file(argc, argv, "", opt.out_prefix);


}


/// Read given files and form an image composite.
/// - Each input point cloud is a 2d arrangement of 3d points.
/// - This function combines them into a simple patchwork mosaic without
///   regard for the actual xyz values of the points.
template<class PixelT>
ImageViewRef<PixelT> form_composite(std::vector<std::string> const & files){

  VW_ASSERT(files.size() >= 1, ArgumentErr() << "Expecting at least one file.\n");

  // TODO: Is there any requirement for the spacing?
  int spacing = 1;

  vw::mosaic::ImageComposite<PixelT> composite_image;
  composite_image.set_draft_mode(true); // Images will be disjoint, no need for fancy stuff

  for (int i = 0; i < (int)files.size(); i++){

    ImageViewRef<PixelT> I = asp::read_cloud< math::VectorSize<PixelT>::value >(files[i]);

    // We will stack the images in the composite side by side. Images which
    // are wider than tall will be transposed.
    // To do: A more efficient approach would be to also stack one
    // image on top of each other, if some images are not too tall.<commit_msg>pc_merge uses the same spacing as point2dem<commit_after>// __BEGIN_LICENSE__
//  Copyright (c) 2009-2013, United States Government as represented by the
//  Administrator of the National Aeronautics and Space Administration. All
//  rights reserved.
//
//  The NGT platform is licensed under the Apache License, Version 2.0 (the
//  "License"); you may not use this file except in compliance with the
//  License. You may obtain a copy of the License at
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
// __END_LICENSE__


/// \file pc_merge.cc
///
/// A simple tool to merge multiple point cloud files into a single file.

#include <asp/Core/PointUtils.h>
#include <asp/Core/Macros.h>
#include <asp/Core/Common.h>
#include <asp/Core/OrthoRasterizer.h>

#include <vw/Core/Stopwatch.h>
#include <vw/Mosaic/ImageComposite.h>
#include <vw/FileIO/DiskImageUtils.h>
#include <vw/Cartography/PointImageManipulation.h>

#include <limits>

using namespace vw;
using namespace vw::cartography;
namespace po = boost::program_options;
namespace fs = boost::filesystem;

// Allows FileIO to correctly read/write these pixel types
namespace vw {
  typedef Vector<float64,4> Vector4;
  typedef Vector<float64,6> Vector6;
  template<> struct PixelFormatID<Vector3>   { static const PixelFormatEnum value = VW_PIXEL_GENERIC_3_CHANNEL; };
  template<> struct PixelFormatID<Vector3f>  { static const PixelFormatEnum value = VW_PIXEL_GENERIC_3_CHANNEL; };
  template<> struct PixelFormatID<Vector4>   { static const PixelFormatEnum value = VW_PIXEL_GENERIC_4_CHANNEL; };
  template<> struct PixelFormatID<Vector6>   { static const PixelFormatEnum value = VW_PIXEL_GENERIC_6_CHANNEL; };
}

struct Options : asp::BaseOptions {
  // Input
  std::vector<std::string> pointcloud_files;

  // Settings
  //float nodata_value;
  bool  write_double;  ///< If true, output file is double instead of float

  // Output
  std::string out_path;

  // Defaults that the user doesn't need to see.
  Options() : //nodata_value(-std::numeric_limits<float>::max()), 
              write_double(false)
             {}
};


void handle_arguments( int argc, char *argv[], Options& opt ) {

  po::options_description general_options("General Options");
  general_options.add_options()
    //("nodata-value",      po::value(&opt.nodata_value)->default_value(-std::numeric_limits<float>::max()),
    //         "Set the nodata value.")
    ("output-path,o",   po::value(&opt.out_path),                             "Specify the output path.")
    ("write-double,d", po::value(&opt.write_double)->default_value(false), "Write a double precision output file.");

  general_options.add( asp::BaseOptionsDescription(opt) );

  po::options_description positional("");
  positional.add_options()
    ("input-files", po::value< std::vector<std::string> >(), "Input files");

  po::positional_options_description positional_desc;
  positional_desc.add("input-files", -1);

  std::string usage("[options] <point-clouds> ");
  bool allow_unregistered = false;
  std::vector<std::string> unregistered;
  po::variables_map vm =
    asp::check_command_line( argc, argv, opt, general_options, general_options,
                             positional, positional_desc, usage,
                             allow_unregistered, unregistered );

  if (vm.count("input-files") == 0)
    vw_throw( ArgumentErr() << "Missing input point clouds.\n"
                            << usage << general_options );
  opt.pointcloud_files = vm["input-files"].as< std::vector<std::string> >();

  //// Turn on logging to file
  //asp::log_to_file(argc, argv, "", opt.out_prefix);


}


/// Read given files and form an image composite.
/// - Each input point cloud is a 2d arrangement of 3d points.
/// - This function combines them into a simple patchwork mosaic without
///   regard for the actual xyz values of the points.
template<class PixelT>
ImageViewRef<PixelT> form_composite(std::vector<std::string> const & files){

  VW_ASSERT(files.size() >= 1, ArgumentErr() << "Expecting at least one file.\n");

  // This is the same spacing used by point2dem for improved performance.
  int spacing = asp::OrthoRasterizerView::max_subblock_size();

  vw::mosaic::ImageComposite<PixelT> composite_image;
  composite_image.set_draft_mode(true); // Images will be disjoint, no need for fancy stuff

  for (int i = 0; i < (int)files.size(); i++){

    ImageViewRef<PixelT> I = asp::read_cloud< math::VectorSize<PixelT>::value >(files[i]);

    // We will stack the images in the composite side by side. Images which
    // are wider than tall will be transposed.
    // To do: A more efficient approach would be to also stack one
    // image on top of each other, if some images are not too tall.
{'fraction_non_alphanumeric': 0.12076038019009505, 'fraction_numerical': 0.007103551775887944, 'mean_word_length': 3.7622677465459744, 'pattern_counts': {'":': 0, '<': 93, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3711931', 'n_tokens_mistral': 3049, 'n_tokens_neox': 2934, 'n_words': 916}