28#include <easy3d/core/model.h>
29#include <easy3d/renderer/renderer.h>
30#include <easy3d/renderer/drawable_points.h>
31#include <easy3d/util/resource.h>
32#include <easy3d/util/initializer.h>
40int main(
int argc,
char **argv) {
45 VirtualScanner viewer(EXAMPLE_TITLE);
47 const std::string file_name = resource::directory() +
"/data/house/house.obj";
48 Model *model = viewer.add_model(file_name,
true);
50 LOG(ERROR) <<
"failed to load model. Please make sure the file exists and format is correct.";
56 d->
set_visible(
false);
The base class of renderable 3D models.
Definition: model.h:49
Renderer * renderer()
Gets the renderer of this model.
Definition: model.h:94
PointsDrawable * get_points_drawable(const std::string &name) const
Definition: renderer.cpp:286
Definition: collider.cpp:182
void initialize(bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition: initializer.cpp:35
28#include <easy3d/core/point_cloud.h>
29#include <easy3d/renderer/camera.h>
30#include <easy3d/renderer/read_pixel.h>
31#include <easy3d/renderer/framebuffer_object.h>
32#include <easy3d/algo/gaussian_noise.h>
37VirtualScanner::VirtualScanner(
const std::string &title)
41 camera()->setUpVector(
vec3(0, 1, 0));
44 "-------------- Virtual Scanner usage -------------- \n"
45 "- change the view using the mouse.\n"
46 "- press the 'Space' key to perform scanning. Everything (and only those) visible\n"
47 " will be captured in a point cloud.\n"
48 "- press 'n' to toggle Gaussian noise.\n"
49 "---------------------------------------------------------- \n";
53bool VirtualScanner::key_press_event(
int key,
int modifiers) {
54 if (key == KEY_SPACE && modifiers == 0) {
56 framebuffer_size(fw, fh);
59 fbo.add_depth_buffer(GL_DEPTH_COMPONENT32F);
62 glClear(GL_DEPTH_BUFFER_BIT);
66 std::vector<float> depths;
67 fbo.read_depth(depths,
false);
69 const mat4& MVP = camera()->modelViewProjectionMatrix();
71 const int viewport[] = { 0, 0, width_, height_};
73 std::vector<vec3> points;
74 for (
int x=0; x<width_; ++x) {
75 for (
int y=0; y<height_; ++y) {
78 const int idx =
static_cast<int>(
static_cast<float>(y) * dpi_scaling() *
static_cast<float>(fw) +
static_cast<float>(x) * dpi_scaling());
80 const int idx =
static_cast<int>(y * fw + x);
82 const float d = depths[idx];
84 vec3 vs(
static_cast<float>(x),
static_cast<float>(y), d);
85 vs.x =
static_cast<float>(vs.x -
static_cast<float>(
viewport[0])) /
static_cast<float>(
viewport[2]) * 2.0f - 1.0f;
86 vs.y =
static_cast<float>(vs.y -
static_cast<float>(
viewport[1])) /
static_cast<float>(
viewport[3]) * 2.0f - 1.0f;
87 vs.z = vs.z * 2.0f - 1.0f;
88 points.push_back(invMVP * vs);
93 if (!points.empty()) {
95 for (
const auto& p : points)
99 const float ratio = 0.0001f;
100 const float sigma = current_model()->bounding_box().radius() * ratio;
101 GaussianNoise::apply(cloud, sigma);
102 std::cout <<
"Gaussian noise added (sigma = " << ratio <<
" * model radius)" << std::endl;
110 else if (key == KEY_N && modifiers == 0) {
111 add_noise_ = !add_noise_;
113 std::cout <<
"add_noise = ON" << std::endl;
115 std::cout <<
"add_noise = OFF" << std::endl;
119 return Viewer::key_press_event(key, modifiers);
An implementation of framebuffer object (FBO).
Definition: framebuffer_object.h:122
A data structure for point clouds.
Definition: point_cloud.h:45
Vertex add_vertex(const vec3 &p)
add a new vertex with position p
Definition: point_cloud.cpp:177
virtual Model * add_model(const std::string &file_name, bool create_default_drawables=true)
Add a model from a file to the viewer to be visualized. On success, the viewer will be in charge of t...
Definition: viewer.cpp:1204
Mat< N, N, T > inverse(const Mat< N, N, T > &m)
Return the inverse of N x N (square) matrix m.
Definition: mat.h:977