Easy3D 2.5.3
picker_surface_mesh.h
1
2/********************************************************************
3 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
4 * https://3d.bk.tudelft.nl/liangliang/
5 *
6 * This file is part of Easy3D. If it is useful in your research/work,
7 * I would be grateful if you show your appreciation by citing it:
8 * ------------------------------------------------------------------
9 * Liangliang Nan.
10 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
11 * for processing and rendering 3D data.
12 * Journal of Open Source Software, 6(64), 3255, 2021.
13 * ------------------------------------------------------------------
14 *
15 * Easy3D is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License Version 3
17 * as published by the Free Software Foundation.
18 *
19 * Easy3D is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 ********************************************************************/
27
28#ifndef EASY3D_GUI_PICKER_SURFACE_MESH_H
29#define EASY3D_GUI_PICKER_SURFACE_MESH_H
30
31#include <easy3d/gui/picker.h>
32#include <easy3d/core/surface_mesh.h>
33
34
35namespace easy3d {
36
37 class ShaderProgram;
38
44 class SurfaceMeshPicker : public Picker {
45 public:
46 explicit SurfaceMeshPicker(const Camera *cam);
47
48 ~SurfaceMeshPicker() override = default;
49
50 //------------------ sensitivity ---------------------
51
54 unsigned int resolution() const { return hit_resolution_; }
57 void set_resolution(unsigned int r) { hit_resolution_ = r; }
58
59 //--------------- pick a single element ---------------
60
70 SurfaceMesh::Face pick_face(SurfaceMesh *model, int x, int y);
71
81 SurfaceMesh::Vertex pick_vertex(SurfaceMesh *model, int x, int y);
82
92 SurfaceMesh::Halfedge pick_edge(SurfaceMesh *model, int x, int y);
93
107
121
122 //-------------------- query after picking ----------------------
123
131
142 vec3 picked_point(SurfaceMesh *model, SurfaceMesh::Face picked_face, int x, int y) const;
143
144
145 //------------------ multiple selection of faces ------------------
146
152 std::vector<SurfaceMesh::Face> pick_faces(SurfaceMesh *model, const Rect &rect);
153
159 std::vector<SurfaceMesh::Face> pick_faces(SurfaceMesh *model, const Polygon2 &plg);
160
161 private:
162 // selection implemented in GPU (using shader program)
163 SurfaceMesh::Face pick_face_gpu(SurfaceMesh *model, int x, int y, ShaderProgram* program);
164
165 // selection implemented in CPU (with OpenMP if supported)
166 SurfaceMesh::Face pick_face_cpu(SurfaceMesh *model, int x, int y);
167
168 Plane3 face_plane(SurfaceMesh *model, SurfaceMesh::Face face) const;
169
173 static inline bool do_intersect(SurfaceMesh *model, SurfaceMesh::Face picked_face, const OrientedLine3 &line) {
174 // Uses Plucker coordinates (see OrientedLine)
175 Sign face_sign = ZERO;
176 for (auto h : model->halfedges(picked_face)) {
177 auto s = model->source(h);
178 auto t = model->target(h);
179 const OrientedLine3 edge_line(model->position(t), model->position(s));
180 Sign sign = OrientedLine3::side(line, edge_line);
181 if (sign != ZERO) {
182 if (face_sign != ZERO && sign != face_sign)
183 return false;
184 face_sign = sign;
185 }
186 }
187 return true;
188 }
189
190 private:
191 unsigned int hit_resolution_; // in pixels
192 SurfaceMesh::Face picked_face_;
193 };
194
195}
196
197
198#endif // EASY3D_GUI_PICKER_SURFACE_MESH_H
A perspective or orthographic camera.
Definition: camera.h:116
OrientedLine implements plucker coordinates, which enables oriented lines to be compared.
Definition: oriented_line.h:43
static Sign side(const GenericOrientedLine< FT > &a, const GenericOrientedLine< FT > &b)
Definition: oriented_line.h:97
A 2D polygon representation.
Definition: polygon.h:41
The GenericRect class defines a rectangle in the 2D space.
Definition: rect.h:42
Base class for picking mechanism.
Definition: picker.h:43
OpenGL Shader Compilation.
Definition: shader_program.h:78
A halfedge data structure for polygonal meshes of 2-manifold.
Definition: surface_mesh.h:52
const vec3 & position(Vertex v) const
position of a vertex (read only)
Definition: surface_mesh.h:1928
Vertex source(Halfedge h) const
returns the vertex the halfedge h emanates from
Definition: surface_mesh.h:1217
Vertex target(Halfedge h) const
returns the vertex the halfedge h points to
Definition: surface_mesh.h:1211
HalfedgeContainer halfedges() const
returns halfedge container for C++11 range-based for-loops
Definition: surface_mesh.h:1649
Implementation of picking elements (i.e, vertices, faces, edges) from a surface mesh.
Definition: picker_surface_mesh.h:44
SurfaceMesh::Face picked_face() const
Query the previously picked face.
Definition: picker_surface_mesh.cpp:172
unsigned int resolution() const
Returns the picker resolution (in pixels).
Definition: picker_surface_mesh.h:54
vec3 picked_point(SurfaceMesh *model, SurfaceMesh::Face picked_face, int x, int y) const
Query the coordinate of the previously picked position, which is the intersection between the picking...
Definition: picker_surface_mesh.cpp:180
SurfaceMesh::Halfedge pick_edge(SurfaceMesh *model, int x, int y)
Pick an edge from a surface mesh given the cursor position.
Definition: picker_surface_mesh.cpp:159
SurfaceMesh::Face pick_face(SurfaceMesh *model, int x, int y)
Definition: picker_surface_mesh.cpp:49
std::vector< SurfaceMesh::Face > pick_faces(SurfaceMesh *model, const Rect &rect)
Pick faces of a surface mesh by a rectangle.
Definition: picker_surface_mesh.cpp:355
SurfaceMesh::Vertex pick_vertex(SurfaceMesh *model, int x, int y)
Pick a vertex from a surface mesh given the cursor position.
Definition: picker_surface_mesh.cpp:109
void set_resolution(unsigned int r)
Sets the picker resolution (in pixels).
Definition: picker_surface_mesh.h:57
Definition: collider.cpp:182
Sign
The sign.
Definition: oriented_line.h:20
Sign sign(T x)
returns the sign of a value.
Definition: oriented_line.h:28
Definition: surface_mesh.h:134
Definition: surface_mesh.h:114
Definition: surface_mesh.h:104