28int main(
int argc,
char* argv[])
31 "Batch conversion of raster files into VTK point cloud data.\n"
32 "A series of raster files is converted into point clouds by creating a "
33 "number of random points based on the intensity value in each pixel "
34 "(the higher the value, the more points. The [x,y]-extend of these "
35 "random points is limited by the extent of the pixel they represent, "
36 "the elevation is limited by the max-elevation parameter. Likewise, "
38 "maximum number of points per pixel is limited by the max-points "
39 "parameter. The increase of the number of points in relation to the "
40 "pixel value is indicated by gamma, where 1 is a linear increase and "
41 "values smaller or larger than 1 indicate a logarithmic or exponential "
42 "increase, respectively.\n\n"
43 "OpenGeoSys-6 software, version " +
46 "Copyright (c) 2012-2025, OpenGeoSys Community "
47 "(http://www.opengeosys.org)",
49 TCLAP::ValueArg<double> gamma_arg(
51 "Exponental increase coefficient. A value of '1' indicates a linear "
52 "increase, smaller or larger values indicate a logarithmic or "
53 "exponential increase, respectively (default: 1).",
54 false, 0.0,
"exponential increase");
56 TCLAP::ValueArg<std::size_t> max_points_arg(
58 "Maximum number of points per pixel (default: 1000), "
60 false, 0,
"maximum points per pixel");
61 cmd.add(max_points_arg);
62 TCLAP::ValueArg<double> max_height_arg(
64 "Maximum elevation of randomly created points "
66 false, 0.0,
"maximum point elevation");
67 cmd.add(max_height_arg);
68 TCLAP::ValueArg<std::string> output_arg(
70 "Output (.vtp). Path to output polydata files. "
71 "Specifying 'file.vtp' will "
72 "make the programme write a series of files called 'file0.vtp', "
74 true,
"",
"OUTPUT_FILE");
76 TCLAP::ValueArg<std::string> input_arg(
78 "Input (.asc). Path to input raster files. "
79 "Specifying 'file.asc' will make "
80 "the programme look for a series of files called 'file0.asc', "
82 true,
"",
"INPUT_FILE");
85 cmd.add(log_level_arg);
86 cmd.parse(argc, argv);
91 std::string
const input_name = input_arg.getValue().c_str();
92 std::string
const output_name = output_arg.getValue().c_str();
94 double const max_height =
95 (max_height_arg.isSet()) ? max_height_arg.getValue() : 5000;
96 std::size_t
const max_points =
97 (max_points_arg.isSet()) ? max_points_arg.getValue() : 1000;
98 double const gamma = (gamma_arg.isSet()) ? gamma_arg.getValue() : 1;
107 std::cout <<
"Starting export... ";
108 double global_min = std::numeric_limits<double>::max();
109 double global_max = 0;
111 std::size_t n_rasters = 0;
112 for (std::size_t i = 0;; ++i)
114 std::string
const file_name =
115 ibase_name + std::to_string(i) + ifile_ext;
116 std::unique_ptr<GeoLib::Raster> r(
124 for (
auto it = r->begin(); it != r->end(); ++it)
126 if (*it != r->getHeader().no_data)
128 global_min = std::min(*it, global_min);
129 global_max = std::max(*it, global_max);
134 for (std::size_t i = 0; i < n_rasters; ++i)
136 std::string
const file_name =
137 ibase_name + std::to_string(i) + ifile_ext;
138 vtkSmartPointer<VtkGeoImageSource> geo_image =
139 vtkSmartPointer<VtkGeoImageSource>::New();
140 geo_image->readImage(QString::fromStdString(file_name));
143 point_cloud_filter->SetInputConnection(geo_image->GetOutputPort());
145 point_cloud_filter->SetMinValueRange(global_min);
146 point_cloud_filter->SetMaxValueRange(global_max);
147 point_cloud_filter->SetMinHeight(0);
148 point_cloud_filter->SetMaxHeight(max_height);
149 point_cloud_filter->SetIsLinear(
false);
150 point_cloud_filter->SetMinNumberOfPointsPerCell(0);
151 point_cloud_filter->SetMaxNumberOfPointsPerCell(max_points);
152 point_cloud_filter->SetGamma(gamma);
153 point_cloud_filter->Update();
154 vtkSmartPointer<vtkPolyDataAlgorithm>
const pd_alg =
155 dynamic_cast<vtkPolyDataAlgorithm*
>(point_cloud_filter);
158 std::string
const output =
159 obase_name + std::to_string(i) + ofile_ext;
160 vtkSmartPointer<vtkXMLPolyDataWriter> pd_writer =
161 vtkSmartPointer<vtkXMLPolyDataWriter>::New();
162 pd_writer->SetInputData(pd_alg->GetOutputDataObject(0));
163 pd_writer->SetFileName(output.c_str());
167 std::cout <<
"done." << std::endl;