27int main(
int argc,
char* argv[])
30 "Batch conversion of raster files into VTK point cloud data.\n"
31 "A series of raster files is converted into point clouds by creating a "
32 "number of random points based on the intensity value in each pixel "
33 "(the higher the value, the more points. The [x,y]-extend of these "
34 "random points is limited by the extent of the pixel they represent, "
35 "the elevation is limited by the max-elevation parameter. Likewise, "
37 "maximum number of points per pixel is limited by the max-points "
38 "parameter. The increase of the number of points in relation to the "
39 "pixel value is indicated by gamma, where 1 is a linear increase and "
40 "values smaller or larger than 1 indicate a logarithmic or exponential "
41 "increase, respectively.\n\n"
42 "OpenGeoSys-6 software, version " +
45 "Copyright (c) 2012-2024, OpenGeoSys Community "
46 "(http://www.opengeosys.org)",
48 TCLAP::ValueArg<double> gamma_arg(
50 "Exponental increase coefficient. A value of '1' indicates a linear "
51 "increase, smaller or larger values indicate a logarithmic or "
52 "exponential increase, respectively (default: 1).",
53 false, 0.0,
"exponential increase");
55 TCLAP::ValueArg<std::size_t> max_points_arg(
57 "Maximum number of points per pixel (default: 1000).",
false, 0,
58 "maximum points per pixel");
59 cmd.add(max_points_arg);
60 TCLAP::ValueArg<double> max_height_arg(
62 "Maximum elevation of randomly created points (default: 5000).",
false,
63 0.0,
"maximum point elevation");
64 cmd.add(max_height_arg);
65 TCLAP::ValueArg<std::string> output_arg(
67 "Path to output polydata files (*.vtp). Specifying 'file.vtp' will "
68 "make the programme write a series of files called 'file0.vtp', "
70 true,
"",
"output file name");
72 TCLAP::ValueArg<std::string> input_arg(
74 "Path to input raster files (*.asc). Specifying 'file.asc' will make "
75 "the programme look for a series of files called 'file0.asc', "
77 true,
"",
"input file name");
79 cmd.parse(argc, argv);
83 std::string
const input_name = input_arg.getValue().c_str();
84 std::string
const output_name = output_arg.getValue().c_str();
86 double const max_height =
87 (max_height_arg.isSet()) ? max_height_arg.getValue() : 5000;
88 std::size_t
const max_points =
89 (max_points_arg.isSet()) ? max_points_arg.getValue() : 1000;
90 double const gamma = (gamma_arg.isSet()) ? gamma_arg.getValue() : 1;
99 std::cout <<
"Starting export... ";
100 double global_min = std::numeric_limits<double>::max();
101 double global_max = 0;
103 std::size_t n_rasters = 0;
104 for (std::size_t i = 0;; ++i)
106 std::string
const file_name =
107 ibase_name + std::to_string(i) + ifile_ext;
108 std::unique_ptr<GeoLib::Raster> r(
116 for (
auto it = r->begin(); it != r->end(); ++it)
118 if (*it != r->getHeader().no_data)
120 global_min = std::min(*it, global_min);
121 global_max = std::max(*it, global_max);
126 for (std::size_t i = 0; i < n_rasters; ++i)
128 std::string
const file_name =
129 ibase_name + std::to_string(i) + ifile_ext;
130 vtkSmartPointer<VtkGeoImageSource> geo_image =
131 vtkSmartPointer<VtkGeoImageSource>::New();
132 geo_image->readImage(QString::fromStdString(file_name));
135 point_cloud_filter->SetInputConnection(geo_image->GetOutputPort());
137 point_cloud_filter->SetMinValueRange(global_min);
138 point_cloud_filter->SetMaxValueRange(global_max);
139 point_cloud_filter->SetMinHeight(0);
140 point_cloud_filter->SetMaxHeight(max_height);
141 point_cloud_filter->SetIsLinear(
false);
142 point_cloud_filter->SetMinNumberOfPointsPerCell(0);
143 point_cloud_filter->SetMaxNumberOfPointsPerCell(max_points);
144 point_cloud_filter->SetGamma(gamma);
145 point_cloud_filter->Update();
146 vtkSmartPointer<vtkPolyDataAlgorithm>
const pd_alg =
147 dynamic_cast<vtkPolyDataAlgorithm*
>(point_cloud_filter);
150 std::string
const output =
151 obase_name + std::to_string(i) + ofile_ext;
152 vtkSmartPointer<vtkXMLPolyDataWriter> pd_writer =
153 vtkSmartPointer<vtkXMLPolyDataWriter>::New();
154 pd_writer->SetInputData(pd_alg->GetOutputDataObject(0));
155 pd_writer->SetFileName(output.c_str());
159 std::cout <<
"done." << std::endl;