22int main(
int argc,
char* argv[])
25 "Batch conversion of raster files into VTK point cloud data.\n"
26 "A series of raster files is converted into point clouds by creating a "
27 "number of random points based on the intensity value in each pixel "
28 "(the higher the value, the more points. The [x,y]-extend of these "
29 "random points is limited by the extent of the pixel they represent, "
30 "the elevation is limited by the max-elevation parameter. Likewise, "
32 "maximum number of points per pixel is limited by the max-points "
33 "parameter. The increase of the number of points in relation to the "
34 "pixel value is indicated by gamma, where 1 is a linear increase and "
35 "values smaller or larger than 1 indicate a logarithmic or exponential "
36 "increase, respectively.\n\n"
37 "OpenGeoSys-6 software, version " +
40 "Copyright (c) 2012-2026, OpenGeoSys Community "
41 "(http://www.opengeosys.org)",
43 TCLAP::ValueArg<double> gamma_arg(
45 "Exponental increase coefficient. A value of '1' indicates a linear "
46 "increase, smaller or larger values indicate a logarithmic or "
47 "exponential increase, respectively (default: 1).",
48 false, 0.0,
"exponential increase");
50 TCLAP::ValueArg<std::size_t> max_points_arg(
52 "Maximum number of points per pixel (default: 1000), "
54 false, 0,
"maximum points per pixel");
55 cmd.add(max_points_arg);
56 TCLAP::ValueArg<double> max_height_arg(
58 "Maximum elevation of randomly created points "
60 false, 0.0,
"maximum point elevation");
61 cmd.add(max_height_arg);
62 TCLAP::ValueArg<std::string> output_arg(
64 "Output (.vtp). Path to output polydata files. "
65 "Specifying 'file.vtp' will "
66 "make the programme write a series of files called 'file0.vtp', "
68 true,
"",
"OUTPUT_FILE");
70 TCLAP::ValueArg<std::string> input_arg(
72 "Input (.asc). Path to input raster files. "
73 "Specifying 'file.asc' will make "
74 "the programme look for a series of files called 'file0.asc', "
76 true,
"",
"INPUT_FILE");
79 cmd.add(log_level_arg);
80 cmd.parse(argc, argv);
85 std::string
const input_name = input_arg.getValue().c_str();
86 std::string
const output_name = output_arg.getValue().c_str();
88 double const max_height =
89 (max_height_arg.isSet()) ? max_height_arg.getValue() : 5000;
90 std::size_t
const max_points =
91 (max_points_arg.isSet()) ? max_points_arg.getValue() : 1000;
92 double const gamma = (gamma_arg.isSet()) ? gamma_arg.getValue() : 1;
101 std::cout <<
"Starting export... ";
102 double global_min = std::numeric_limits<double>::max();
103 double global_max = 0;
105 std::size_t n_rasters = 0;
106 for (std::size_t i = 0;; ++i)
108 std::string
const file_name =
109 ibase_name + std::to_string(i) + ifile_ext;
110 std::unique_ptr<GeoLib::Raster> r(
118 for (
auto it = r->begin(); it != r->end(); ++it)
120 if (*it != r->getHeader().no_data)
122 global_min = std::min(*it, global_min);
123 global_max = std::max(*it, global_max);
128 for (std::size_t i = 0; i < n_rasters; ++i)
130 std::string
const file_name =
131 ibase_name + std::to_string(i) + ifile_ext;
132 vtkSmartPointer<VtkGeoImageSource> geo_image =
133 vtkSmartPointer<VtkGeoImageSource>::New();
134 geo_image->readImage(QString::fromStdString(file_name));
137 point_cloud_filter->SetInputConnection(geo_image->GetOutputPort());
139 point_cloud_filter->SetMinValueRange(global_min);
140 point_cloud_filter->SetMaxValueRange(global_max);
141 point_cloud_filter->SetMinHeight(0);
142 point_cloud_filter->SetMaxHeight(max_height);
143 point_cloud_filter->SetIsLinear(
false);
144 point_cloud_filter->SetMinNumberOfPointsPerCell(0);
145 point_cloud_filter->SetMaxNumberOfPointsPerCell(max_points);
146 point_cloud_filter->SetGamma(gamma);
147 point_cloud_filter->Update();
148 vtkSmartPointer<vtkPolyDataAlgorithm>
const pd_alg =
149 dynamic_cast<vtkPolyDataAlgorithm*
>(point_cloud_filter);
152 std::string
const output =
153 obase_name + std::to_string(i) + ofile_ext;
154 vtkSmartPointer<vtkXMLPolyDataWriter> pd_writer =
155 vtkSmartPointer<vtkXMLPolyDataWriter>::New();
156 pd_writer->SetInputData(pd_alg->GetOutputDataObject(0));
157 pd_writer->SetFileName(output.c_str());
161 std::cout <<
"done." << std::endl;