28#include <easy3d/core/model.h>
29#include <easy3d/renderer/drawable_points.h>
30#include <easy3d/renderer/renderer.h>
31#include <easy3d/util/resource.h>
32#include <easy3d/util/initializer.h>
40int main(
int argc,
char **argv) {
44 const std::string file = resource::directory() +
"/data/polyhedron.bin";
47 PointSelection viewer(EXAMPLE_TITLE);
49 Model *model = viewer.add_model(file,
true);
51 LOG(ERROR) <<
"failed to load model. Please make sure the file exists and format is correct.";
The base class of renderable 3D models.
Definition: model.h:49
Renderer * renderer()
Gets the renderer of this model.
Definition: model.h:94
The drawable for rendering a set of points, e.g., point clouds, vertices of a mesh.
Definition: drawable_points.h:42
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/renderer/opengl.h>
29#include <easy3d/core/point_cloud.h>
30#include <easy3d/gui/picker_point_cloud.h>
31#include <easy3d/renderer/shape.h>
32#include <easy3d/renderer/drawable_points.h>
33#include <easy3d/renderer/renderer.h>
34#include <easy3d/util/logging.h>
41PointSelection::PointSelection(
const std::string &title) :
Viewer(title) {
43 "-------------- Point Selection usage -------------- \n"
44 "Press Ctrl key, then drag the mouse to select (left button) or deselect (right button) points\n"
45 "--------------------------------------------------- \n";
50bool PointSelection::mouse_press_event(
int x,
int y,
int button,
int modifiers) {
51 if (modifiers == MODIF_CTRL) {
53 polygon_.push_back(
vec2(
static_cast<float>(x),
static_cast<float>(y)));
56 return Viewer::mouse_press_event(x, y, button, modifiers);
61bool PointSelection::mouse_release_event(
int x,
int y,
int button,
int modifiers) {
62 if (modifiers == MODIF_CTRL) {
63 if (polygon_.size() >= 3) {
64 auto cloud =
dynamic_cast<PointCloud *
>(current_model());
68 picker.pick_vertices(cloud, polygon_, button == BUTTON_RIGHT);
70 picker.pick_vertices(cloud,
Rect(polygon_[0], polygon_[2]), button == BUTTON_RIGHT);
72 mark_selection(cloud);
79 return Viewer::mouse_release_event(x, y, button, modifiers);
84bool PointSelection::mouse_drag_event(
int x,
int y,
int dx,
int dy,
int button,
int modifiers) {
85 if (modifiers == MODIF_CTRL) {
87 polygon_.push_back(
vec2(
static_cast<float>(x),
static_cast<float>(y)));
89 const vec2 first_point = polygon_[0];
91 polygon_.push_back(first_point);
92 polygon_.push_back(
vec2(first_point.x,
static_cast<float>(y)));
93 polygon_.push_back(
vec2(
static_cast<float>(x),
static_cast<float>(y)));
94 polygon_.push_back(
vec2(
static_cast<float>(x), first_point.y));
98 return Viewer::mouse_drag_event(x, y, dx, dy, button, modifiers);
102void PointSelection::post_draw() {
103 if (polygon_.size() >= 3) {
105 shape::draw_polygon_wire(polygon_,
vec4(1.0f, 0.0f, 0.0f, 1.0f), width(), height(), -1.0f);
109 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
110 shape::draw_polygon_filled(polygon_,
vec4(1.0f, 0.0f, 0.0f, 0.2f), width(), height(), -0.9f);
116void PointSelection::mark_selection(
PointCloud *cloud) {
121 colors[v] = select[v] ?
vec3(1,0,0) : drawable->color().xyz();
122 drawable->set_coloring(easy3d::State::COLOR_PROPERTY, easy3d::State::VERTEX,
"v:color");
The GenericRect class defines a rectangle in the 2D space.
Definition: rect.h:42
VertexContainer vertices() const
returns vertex container for C++11 range-based for-loops
Definition: point_cloud.h:444
VertexProperty< T > vertex_property(const std::string &name, const T t=T())
if a vertex property of type T with name name exists, it is returned. otherwise this property is adde...
Definition: point_cloud.h:361
Implementation of picking points from a point cloud.
Definition: picker_point_cloud.h:44
Base class for vector types. It provides generic functionality for N dimensional vectors.
Definition: vec.h:34