29 "Batch conversion of raster files into VTK point cloud data.\n"
30 "A series of raster files is converted into point clouds by creating a "
31 "number of random points based on the intensity value in each pixel "
32 "(the higher the value, the more points. The [x,y]-extend of these "
33 "random points is limited by the extent of the pixel they represent, "
34 "the elevation is limited by the max-elevation parameter. Likewise, "
36 "maximum number of points per pixel is limited by the max-points "
37 "parameter. The increase of the number of points in relation to the "
38 "pixel value is indicated by gamma, where 1 is a linear increase and "
39 "values smaller or larger than 1 indicate a logarithmic or exponential "
40 "increase, respectively.\n\n"
41 "OpenGeoSys-6 software, version " +
44 "Copyright (c) 2012-2021, OpenGeoSys Community "
45 "(http://www.opengeosys.org)",
47 TCLAP::ValueArg<double> gamma_arg(
49 "Exponental increase coefficient. A value of '1' indicates a linear "
50 "increase, smaller or larger values indicate a logarithmic or "
51 "exponential increase, respectively (default: 1).",
52 false, 0.0,
"exponential increase");
54 TCLAP::ValueArg<std::size_t> max_points_arg(
56 "Maximum number of points per pixel (default: 1000).",
false, 0,
57 "maximum points per pixel");
58 cmd.add(max_points_arg);
59 TCLAP::ValueArg<double> max_height_arg(
61 "Maximum elevation of randomly created points (default: 5000).",
false,
62 0.0,
"maximum point elevation");
63 cmd.add(max_height_arg);
64 TCLAP::ValueArg<std::string> output_arg(
66 "Path to output polydata files (*.vtp). Specifying 'file.vtp' will "
67 "make the programme write a series of files called 'file0.vtp', "
69 true,
"",
"output file name");
71 TCLAP::ValueArg<std::string> input_arg(
73 "Path to input raster files (*.asc). Specifying 'file.asc' will make "
74 "the programme look for a series of files called 'file0.asc', "
76 true,
"",
"input file name");
78 cmd.parse(argc, argv);
80 std::string
const input_name = input_arg.getValue().c_str();
81 std::string
const output_name = output_arg.getValue().c_str();
83 double const max_height =
84 (max_height_arg.isSet()) ? max_height_arg.getValue() : 5000;
85 std::size_t
const max_points =
86 (max_points_arg.isSet()) ? max_points_arg.getValue() : 1000;
87 double const gamma = (gamma_arg.isSet()) ? gamma_arg.getValue() : 1;
96 std::cout <<
"Starting export... ";
97 double global_min = std::numeric_limits<double>::max();
98 double global_max = 0;
100 std::size_t n_rasters = 0;
101 for (std::size_t i = 0;; ++i)
103 std::string
const file_name =
104 ibase_name + std::to_string(i) + ifile_ext;
105 std::unique_ptr<GeoLib::Raster>
r(
113 for (
auto it =
r->begin(); it !=
r->end(); ++it)
115 if (*it !=
r->getHeader().no_data)
117 global_min = std::min(*it, global_min);
118 global_max = std::max(*it, global_max);
123 for (std::size_t i = 0; i < n_rasters; ++i)
125 std::string
const file_name =
126 ibase_name + std::to_string(i) + ifile_ext;
127 vtkSmartPointer<VtkGeoImageSource> geo_image =
128 vtkSmartPointer<VtkGeoImageSource>::New();
129 geo_image->readImage(QString::fromStdString(file_name));
132 point_cloud_filter->SetInputConnection(geo_image->GetOutputPort());
134 point_cloud_filter->SetMinValueRange(global_min);
135 point_cloud_filter->SetMaxValueRange(global_max);
136 point_cloud_filter->SetMinHeight(0);
137 point_cloud_filter->SetMaxHeight(max_height);
138 point_cloud_filter->SetIsLinear(
false);
139 point_cloud_filter->SetMinNumberOfPointsPerCell(0);
140 point_cloud_filter->SetMaxNumberOfPointsPerCell(max_points);
141 point_cloud_filter->SetGamma(gamma);
142 point_cloud_filter->Update();
143 vtkSmartPointer<vtkPolyDataAlgorithm>
const pd_alg =
144 dynamic_cast<vtkPolyDataAlgorithm*
>(point_cloud_filter);
147 std::string
const output =
148 obase_name + std::to_string(i) + ofile_ext;
149 vtkSmartPointer<vtkXMLPolyDataWriter> pd_writer =
150 vtkSmartPointer<vtkXMLPolyDataWriter>::New();
151 pd_writer->SetInputData(pd_alg->GetOutputDataObject(0));
152 pd_writer->SetFileName(output.c_str());
156 std::cout <<
"done." << std::endl;
static GeoLib::Raster * getRasterFromASCFile(std::string const &fname)
Reads an ArcGis ASC raster file.
static VtkImageDataToPointCloudFilter * New()
Create a new objects (required because of VTKs reference counting)
std::string getFileExtension(const std::string &path)
std::string dropFileExtension(std::string const &filename)
GITINFOLIB_EXPORT const std::string ogs_version