ed
heightmap_to_mesh.cpp
Go to the documentation of this file.
1 #include "../src/models/shape_loader_private.h"
2 
3 #include <geolib/io/export.h>
4 #include <geolib/Shape.h>
5 
6 
7 int main(int argc, char **argv)
8 {
9 
10  // Parse command-line arguments
11  if (argc < 3 || argc > 7) {
12  std::cout << "Usage: ed_heightmap_to_mesh INPUT_IMAGE OUTPUT_FILE RESOLUTION [BLOCK_HEIGHT] [ORIGIN_X ORIGIN_Y]" << std::endl;
13  return 1;
14  }
15 
16  std::string input_file = argv[1];
17  std::string output_file = argv[2];
18 
19  double resolution = 0.2;
20  if (argc > 2) {
21  resolution = atof(argv[3]);
22  }
23 
24  double block_height = 1;
25  if (argc > 3) {
26  block_height = atof(argv[4]);
27  }
28 
29  double origin_x = 0, origin_y = 0;
30  if (argc > 5) {
31  if (argc < 7) {
32  std::cout << "ORIGIN_X and ORIGIN_Y are optional, but shoud be provided together" << std::endl;
33  return 1;
34  }
35  origin_x = atof(argv[5]);
36  origin_y = atof(argv[6]);
37  }
38 
39  // Call shape loader. This will generate a mesh from the file
41  geo::ShapePtr shape = ed::models::getHeightMapShape(input_file, geo::Vec3(origin_x, origin_y, 0), block_height,
42  resolution, resolution, false, error);
43 
44  if(!shape)
45  {
46  std::cout << "could not load heightmap: " << input_file << std::endl << error.str() << std::endl;
47  return 1;
48  }
49 
50  if (!geo::io::writeMeshFile(output_file, *shape))
51  {
52  std::cout << "Could not convert loaded shape to mesh file: " << output_file << std::endl;
53  return 1;
54  }
55 
56  std::cout << "Succesfully converted: '" << input_file << "' to '" << output_file <<"'. With " <<
57  shape->getMesh().getPoints().size() << " points and " << shape->getMesh().getTriangleIs().size() <<
58  " triangles." << std::endl;
59 
60  return 0;
61 }
std::string
std::shared_ptr
export.h
geo::Vec3T
Shape.h
std::stringstream
main
int main(int argc, char **argv)
Definition: heightmap_to_mesh.cpp:7
geo::io::writeMeshFile
bool writeMeshFile(const std::string &filename, const Shape &shape, std::string format="")
std::cout
ed::log::error
std::ostream & error()
Definition: logging.cpp:74
std::endl
T endl(T... args)
ed::models::getHeightMapShape
geo::ShapePtr getHeightMapShape(cv::Mat &image_orig, const geo::Vec3 &pos, const geo::Vec3 &size, const bool inverted, std::stringstream &error)
getHeightMapShape convert grayscale image in a heigtmap mesh
Definition: shape_loader.cpp:213