Easy3D 2.6.1
Loading...
Searching...
No Matches
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:
50 explicit SurfaceMeshPicker(const Camera *cam);
54 ~SurfaceMeshPicker() override = default;
55
56 //------------------ sensitivity ---------------------
57
63 unsigned int resolution() const { return hit_resolution_; }
69 void set_resolution(unsigned int r) { hit_resolution_ = r; }
70
71 //--------------- pick a single element ---------------
72
83 SurfaceMesh::Face pick_face(SurfaceMesh *model, int x, int y);
84
95 SurfaceMesh::Vertex pick_vertex(SurfaceMesh *model, int x, int y);
96
107 SurfaceMesh::Halfedge pick_edge(SurfaceMesh *model, int x, int y);
108
123
138
139 //-------------------- query after picking ----------------------
140
148
160 vec3 picked_point(SurfaceMesh *model, SurfaceMesh::Face picked_face, int x, int y) const;
161
162
163 //------------------ multiple selection of faces ------------------
164
171 std::vector<SurfaceMesh::Face> pick_faces(SurfaceMesh *model, const Rect &rect);
172
179 std::vector<SurfaceMesh::Face> pick_faces(SurfaceMesh *model, const Polygon2 &plg);
180
181 private:
182 // selection implemented in GPU (using shader program)
183 SurfaceMesh::Face pick_face_gpu(SurfaceMesh *model, int x, int y, ShaderProgram* program);
184
185 // selection implemented in CPU (with OpenMP if supported)
186 SurfaceMesh::Face pick_face_cpu(SurfaceMesh *model, int x, int y);
187
188 Plane3 face_plane(SurfaceMesh *model, SurfaceMesh::Face face) const;
189
193 static bool do_intersect(SurfaceMesh *model, SurfaceMesh::Face picked_face, const OrientedLine3 &line) {
194 // Uses Plucker coordinates (see OrientedLine)
195 Sign face_sign = ZERO;
196 for (auto h : model->halfedges(picked_face)) {
197 auto s = model->source(h);
198 auto t = model->target(h);
199 const OrientedLine3 edge_line(model->position(t), model->position(s));
200 Sign sign = OrientedLine3::side(line, edge_line);
201 if (sign != ZERO) {
202 if (face_sign != ZERO && sign != face_sign)
203 return false;
204 face_sign = sign;
205 }
206 }
207 return true;
208 }
209
210 private:
211 unsigned int hit_resolution_; // in pixels
212 SurfaceMesh::Face picked_face_;
213 };
214
215}
216
217
218#endif // EASY3D_GUI_PICKER_SURFACE_MESH_H
A perspective or orthographic camera.
Definition camera.h:113
static Sign side(const GenericOrientedLine< float > &a, const GenericOrientedLine< float > &b)
Picker(const Camera *cam)
Constructor.
Definition picker.cpp:39
OpenGL Shader Compilation.
Definition shader_program.h:75
A halfedge data structure for polygonal meshes of 2-manifold.
Definition surface_mesh.h:51
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:63
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)
Pick a face from a surface mesh given the cursor position.
Definition picker_surface_mesh.cpp:49
SurfaceMeshPicker(const Camera *cam)
Constructor.
Definition picker_surface_mesh.cpp:41
~SurfaceMeshPicker() override=default
Destructor.
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:69
Definition collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
GenericOrientedLine< float > OrientedLine3
A 3D oriented line of float type.
Definition types.h:95
GenericPolygon< float > Polygon2
A 2D polygon of float type.
Definition types.h:116
GenericRect< float > Rect
A 2D axis-aligned rectangle of float type.
Definition types.h:111
Sign sign(T x)
returns the sign of a value.
Definition oriented_line.h:28
GenericPlane< float > Plane3
A 3D plane of float type.
Definition types.h:103
Sign
The sign.
Definition oriented_line.h:20
Definition surface_mesh.h:191
This type represents a halfedge (internally it is basically an index).
Definition surface_mesh.h:155
This type represents a vertex (internally it is basically an index).
Definition surface_mesh.h:135