28{
29 TCLAP::CmdLine cmd(
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, "
36 "the "
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 " +
44 ".\n"
45 "Copyright (c) 2012-2024, OpenGeoSys Community "
46 "(http://www.opengeosys.org)",
48 TCLAP::ValueArg<double> gamma_arg(
49 "g", "gamma",
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");
54 cmd.add(gamma_arg);
55 TCLAP::ValueArg<std::size_t> max_points_arg(
56 "p", "max-points",
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(
61 "e", "max-elevation",
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(
66 "o", "output",
67 "Path to output polydata files (*.vtp). Specifying 'file.vtp' will "
68 "make the programme write a series of files called 'file0.vtp', "
69 "'file1.vtp', etc.",
70 true, "", "output file name");
71 cmd.add(output_arg);
72 TCLAP::ValueArg<std::string> input_arg(
73 "i", "input",
74 "Path to input raster files (*.asc). Specifying 'file.asc' will make "
75 "the programme look for a series of files called 'file0.asc', "
76 "'file1.asc', etc.",
77 true, "", "input file name");
78 cmd.add(input_arg);
79 cmd.parse(argc, argv);
80
82
83 std::string const input_name = input_arg.getValue().c_str();
84 std::string const output_name = output_arg.getValue().c_str();
85
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;
91
94
97
98
99 std::cout << "Starting export... ";
100 double global_min = std::numeric_limits<double>::max();
101 double global_max = 0;
102
103 std::size_t n_rasters = 0;
104 for (std::size_t i = 0;; ++i)
105 {
106 std::string const file_name =
107 ibase_name + std::to_string(i) + ifile_ext;
108 std::unique_ptr<GeoLib::Raster> r(
110 if (r == nullptr)
111 {
112 n_rasters = i;
113 break;
114 }
115
116 for (auto it = r->begin(); it != r->end(); ++it)
117 {
118 if (*it != r->getHeader().no_data)
119 {
120 global_min = std::min(*it, global_min);
121 global_max = std::max(*it, global_max);
122 }
123 }
124 }
125
126 for (std::size_t i = 0; i < n_rasters; ++i)
127 {
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());
136 geo_image->Update();
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);
148 if (pd_alg)
149 {
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());
156 pd_writer->Write();
157 }
158 }
159 std::cout << "done." << std::endl;
160 return EXIT_SUCCESS;
161}
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