geolib2
show.cpp
Go to the documentation of this file.
1 #include <geolib/io/import.h>
2 #include <geolib/serialization.h>
4 #include <geolib/Shape.h>
5 
6 #include <opencv2/highgui/highgui.hpp>
7 
8 double CANVAS_WIDTH = 640;
9 double CANVAS_HEIGHT = 480;
10 
11 int main(int argc, char **argv) {
12 
13  if (argc != 2) {
14  std::cout << "Usage: show INPUT_FILE" << std::endl;
15  return 1;
16  }
17 
18  geo::serialization::registerDeserializer<geo::Shape>();
19 
20  std::string filename = argv[1];
21 
22  // first try own file format
24 
25  if (!shape) {
26  // If fails, try using assimp
27  shape = geo::io::readMeshFile(filename);
28 
29  if (!shape) {
30  std::cout << "Could not load " << argv[1] << std::endl;
31  return 1;
32  }
33  }
34 
36  554.2559327880068 * CANVAS_WIDTH / 640, 554.2559327880068 * CANVAS_HEIGHT / 480,
37  320.5 * CANVAS_WIDTH / 640, 240.5 * CANVAS_HEIGHT / 480,
38  0, 0);
39 
40  double r = shape->getMaxRadius();
41  double dist = r * 3;
42 
43  double angle = 0;
44 
45  while (true) {
46  geo::Pose3D pose(dist, 0, 0, 0, 0, angle);
47 
48  // * * * * * * DEPTH CAMERA * * * * * *
49 
50  cv::Mat depth_image = cv::Mat(CANVAS_HEIGHT, CANVAS_WIDTH, CV_32FC1, 0.0);
51  cam.rasterize(*shape, geo::Pose3D(0, 0, 0, 1.57, 0, -1.57), pose, depth_image);
52 
53  for(int y = 0; y < depth_image.rows; ++y) {
54  for(int x = 0; x < depth_image.cols; ++x) {
55  float d = depth_image.at<float>(y, x);
56  if (d > 0) {
57  depth_image.at<float>(y, x) = (d - dist + r) / (2 * r);
58  }
59  }
60  }
61 
62  cv::imshow("visualization", depth_image);
63  char key = cv::waitKey(10);
64  if (key == 'q')
65  {
66  break;
67  }
68 
69  angle += 0.07;
70  }
71 
72  return 0;
73 }
Shape.h
std::string
std::shared_ptr
geo::DepthCamera::rasterize
RasterizeResult rasterize(const Shape &shape, const Pose3D &pose, cv::Mat &image, PointerMap &pointer_map=EMPTY_POINTER_MAP, void *pointer=0, TriangleMap &triangle_map=EMPTY_TRIANGLE_MAP) const
rasterize: render a 3D shape onto a 2D image
Definition: DepthCamera.cpp:114
geo::Transform3T
Definition: math_types.h:19
geo::serialization::fromFile
static ShapePtr fromFile(const std::string &filename)
Definition: serialization.cpp:46
std::cout
geo::io::readMeshFile
ShapePtr readMeshFile(const std::string &filename, const geo::Vec3 &scale)
Definition: import.cpp:112
CANVAS_HEIGHT
double CANVAS_HEIGHT
Definition: show.cpp:9
DepthCamera.h
CANVAS_WIDTH
double CANVAS_WIDTH
Definition: show.cpp:8
std::endl
T endl(T... args)
geo::DepthCamera
Definition: DepthCamera.h:159
serialization.h
main
int main(int argc, char **argv)
Definition: show.cpp:11
import.h