Easy3D 2.5.3
visualization_cross_section

The source file containing the main() function:

1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#include <easy3d/renderer/camera.h>
28#include <easy3d/util/resource.h>
29#include <easy3d/util/initializer.h>
30#include <easy3d/util/timer.h>
31
32#include "viewer.h"
33
34
35using namespace easy3d;
36
37int test_cross_section(int duration) {
38 CrossSection viewer("CrossSection");
39 viewer.camera()->setViewDirection(vec3(-1, 1, -1));
40
41 const std::string file_name = resource::directory() + "/data/bunny.ply";
42 if (!viewer.add_model(file_name)) {
43 LOG(ERROR) << "failed to load model. Please make sure the file exists and format is correct.";
44 return EXIT_FAILURE;
45 }
46
47 viewer.set_usage("testing cross section...");
48
49 Timer<>::single_shot(duration, (Viewer*)&viewer, &Viewer::exit);
50 return viewer.run();
51}
A light-weight implementation of the timer mechanism.
Definition: timer.h:49
The built-in Easy3D viewer.
Definition: viewer.h:61
Definition: collider.cpp:182

The header file of the viewer class:

1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_TESTS_CROSS_SECTION_H
28#define EASY3D_TESTS_CROSS_SECTION_H
29
30#include <easy3d/viewer/viewer.h>
31
32namespace easy3d {
33
34 class CrossSection : public Viewer
35 {
36 public:
37 explicit CrossSection(const std::string& title);
38 ~CrossSection() override;
39
40 protected:
41 // manipulate the crosssection plane
42 bool mouse_drag_event(int x, int y, int dx, int dy, int button, int modifiers) override;
43
44 // draw the clipping plane
45 void post_draw() override;
46 };
47
48}
49
50#endif // EASY3D_TESTS_CROSS_SECTION_H

The source file of the viewer class:

1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#include "viewer.h"
28#include <easy3d/renderer/clipping_plane.h>
29#include <easy3d/renderer/manipulated_frame.h>
30#include <easy3d/renderer/manipulator.h>
31
32
33namespace easy3d {
34
35 CrossSection::CrossSection(const std::string &title) : Viewer(title) {
36 // Code of interest:
38 }
39
40 CrossSection::~CrossSection() {
41 // Disable it (otherwise it affects the visualization in subsequent tests)
43 }
44
45 void CrossSection::post_draw() {
46 // Code of interest:
47 ClippingPlane::instance()->draw(camera());
48
49 Viewer::post_draw();
50 }
51
52 bool CrossSection::mouse_drag_event(int x, int y, int dx, int dy, int button, int modifiers) {
53 ManipulatedFrame* frame = ClippingPlane::instance()->manipulator()->frame();
54
55 if (pressed_button_ == BUTTON_LEFT)
56 frame->action_rotate(x, y, dx, dy, camera_, ManipulatedFrame::NONE);
57 else if (pressed_button_ == BUTTON_RIGHT)
58 frame->action_translate(x, y, dx, dy, camera_, ManipulatedFrame::NONE);
59 else
60 return Viewer::mouse_drag_event(x, y, dx, dy, button, modifiers);
61
62 return false;
63 }
64
65}
static ClippingPlane * instance()
Definition: clipping_plane.cpp:61
virtual Manipulator * manipulator()
returns the manipulator attached to the clipping plane.
Definition: clipping_plane.h:106
void draw(Camera *cam) const
draws the clipping plane itself.
Definition: clipping_plane.cpp:132
void set_enabled(bool b)
enables/disables the clipping plane.
Definition: clipping_plane.h:56
virtual void action_rotate(int mouse_x, int mouse_y, int mouse_dx, int mouse_dy, Camera *camera, ScreenAxis axis)
Definition: manipulated_frame.cpp:113
ManipulatedFrame * frame()
Returns the manipulated frame.
Definition: manipulator.h:73