Graphite  Version 3
An experimental 3D geometry processing program
mesh_grob_tool.h
Go to the documentation of this file.
1 /*
2  * OGF/Graphite: Geometry and Graphics Programming Library + Utilities
3  * Copyright (C) 2000-2009 INRIA - Project ALICE
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * If you modify this software, you should include a notice giving the
20  * name of the person performing the modification, the date of modification,
21  * and the reason for such modification.
22  *
23  * Contact: Bruno Levy - levy@loria.fr
24  *
25  * Project ALICE
26  * LORIA, INRIA Lorraine,
27  * Campus Scientifique, BP 239
28  * 54506 VANDOEUVRE LES NANCY CEDEX
29  * FRANCE
30  *
31  * Note that the GNU General Public License does not permit incorporating
32  * the Software into proprietary programs.
33  *
34  * As an exception to the GPL, Graphite can be linked with the following
35  * (non-GPL) libraries: Qt, SuperLU, WildMagic and CGAL
36  */
37 
38 
39 #ifndef H_OGF_MESH_GFX_TOOLS_MESH_GROB_TOOL_H
40 #define H_OGF_MESH_GFX_TOOLS_MESH_GROB_TOOL_H
41 
42 #include <OGF/mesh_gfx/common/common.h>
47 
53 namespace OGF {
54 
55  /*******************************************************************/
56 
60  gom_attribute(abstract,"true")
61  gom_class MESH_GFX_API MeshGrobTool : public Tool {
62  public:
63 
69 
73  ~MeshGrobTool() override;
74 
79  MeshGrob* mesh_grob() const {
80  return dynamic_cast<MeshGrob*>(object()) ;
81  }
82 
93 
106 
117 
128 
141  const RayPick& rp, index_t& facet, index_t& corner
142  );
143 
164  const RayPick& rp, MeshElementsFlags what,
165  Image* image=nullptr,
166  index_t x0=0, index_t y0=0,
167  index_t width=0, index_t height=0
168  );
169 
177  vec3 drag_point(const RayPick& rp) const;
178 
184  const vec3& picked_point() const {
185  return picked_point_;
186  }
187 
194  const vec2& picked_ndc() const {
195  return picked_ndc_;
196  }
197 
203  double picked_depth() const {
204  return picked_depth_;
205  }
206 
207 
208  protected:
209  vec3 picked_point_;
210  vec2 picked_ndc_;
211  double picked_depth_;
212  } ;
213 
214  /*******************************************************************/
215 
216  class MeshGrobTransformTool;
217 
223  class MESH_GFX_API MeshGrobTransformSubset : public MeshGrobTool {
224  public:
225 
232 
236  void grab(const RayPick& p_ndc) override;
237 
238  protected:
247 
251  const vec3& center() const;
252 
253  MeshGrobTransformTool* transform_tool_;
254  };
255 
259  class MESH_GFX_API MeshGrobMoveSubset : public MeshGrobTransformSubset {
260  public:
267  MeshGrobTransformTool* parent
268  ) : MeshGrobTransformSubset(parent) {
269  }
270 
274  void grab(const RayPick& p_ndc) override;
275 
279  void drag(const RayPick& p_ndc) override;
280  };
281 
285  class MESH_GFX_API MeshGrobResizeSubset : public MeshGrobTransformSubset {
286  public:
287 
294  MeshGrobTransformTool* parent
295  ) : MeshGrobTransformSubset(parent) {
296  }
297 
301  void grab(const RayPick& p_ndc) override;
302 
306  void drag(const RayPick& p_ndc) override;
307  };
308 
312  class MESH_GFX_API MeshGrobScrollResizeSubset :
313  public MeshGrobTransformSubset {
314  public:
315 
323  MeshGrobTransformTool* parent, int step
324  ) : MeshGrobTransformSubset(parent), step_(step) {
325  }
326 
330  void grab(const RayPick& p_ndc) override;
331 
332  private:
333  int step_;
334  };
335 
339  class MESH_GFX_API MeshGrobRotateSubset : public MeshGrobTransformSubset {
340  public:
341 
348  MeshGrobTransformTool* parent
349  ) : MeshGrobTransformSubset(parent),
350  arc_ball_(new ArcBall) {
351  }
352 
356  void grab(const RayPick& p_ndc) override;
357 
361  void drag(const RayPick& p_ndc) override;
362 
366  void release(const RayPick& p_ndc) override;
367 
368  protected:
369  ArcBall_var arc_ball_;
370  };
371 
377  gom_attribute(abstract, "true")
378  gom_class MESH_GFX_API MeshGrobTransformTool : public MultiTool {
379  public:
380  MeshGrobTransformTool(ToolsManager* parent) : MultiTool(parent) {
381  set_tool(MOUSE_BUTTON_LEFT, new MeshGrobMoveSubset(this));
382  set_tool(MOUSE_BUTTON_MIDDLE, new MeshGrobResizeSubset(this));
383  set_tool(MOUSE_BUTTON_RIGHT, new MeshGrobRotateSubset(this));
384  set_tool(
385  MOUSE_BUTTON_WHEEL_UP,
386  new MeshGrobScrollResizeSubset(this, -1)
387  );
388  set_tool(
389  MOUSE_BUTTON_WHEEL_DOWN,
390  new MeshGrobScrollResizeSubset(this, 1)
391  );
392  prev_inverse_transform_.load_identity();
393  }
394 
398  void grab(const RayPick& p_ndc) override;
399 
403  void release(const RayPick& p_ndc) override;
404 
409  MeshGrob* mesh_grob() const {
410  return dynamic_cast<MeshGrob*>(object()) ;
411  }
412 
413  protected:
414 
422  void update_transform_subset(const mat4& M) {
423  mat4 MM = M * prev_inverse_transform_;
424  transform_subset(MM);
425  prev_inverse_transform_ = M.inverse();
426  }
427 
431  const vec3& center() const {
432  return center_;
433  }
434 
443  virtual void pick_subset(
444  MeshGrobTransformSubset* tool, const RayPick& rp
445  ) = 0;
446 
452  virtual void transform_subset(const mat4& M) = 0;
453 
458  virtual void clear_subset();
459 
466  friend class MeshGrobTransformSubset;
467  vec3 center_;
468  };
469 }
470 
471 
472 #endif
An image.
Definition: image.h:59
matrix_type inverse() const
Computes the inverse matrix.
Definition: matrix.h:335
Enables to interactively define a rotation.
Definition: arc_ball.h:67
Applies a mouse-controlled translation to a subset.
MeshGrobMoveSubset(MeshGrobTransformTool *parent)
MeshGrobMoveSubset constructor.
void drag(const RayPick &p_ndc) override
The event handler for mouse drag events.
void grab(const RayPick &p_ndc) override
Applies a mouse-controlled scaling to a subset.
void grab(const RayPick &p_ndc) override
void drag(const RayPick &p_ndc) override
The event handler for mouse drag events.
MeshGrobResizeSubset(MeshGrobTransformTool *parent)
MeshGrobResizeSubset constructor.
Applies a mouse-controlled rotation to a subset.
MeshGrobRotateSubset(MeshGrobTransformTool *parent)
MeshGrobRotateSubset constructor.
void grab(const RayPick &p_ndc) override
void release(const RayPick &p_ndc) override
The event handler for mouse release events.
void drag(const RayPick &p_ndc) override
The event handler for mouse drag events.
Applies a mouse-controlled scaling to a subset.
MeshGrobScrollResizeSubset(MeshGrobTransformTool *parent, int step)
MeshGrobResizeSubset constructor.
void grab(const RayPick &p_ndc) override
Base class for tools that operate on MeshGrob.
index_t pick_facet(const RayPick &rp)
Picks a facet.
vec3 drag_point(const RayPick &rp) const
Gets the 3D coordinate of a point dragged from the latest picked point to the actual mouse position i...
index_t pick(const RayPick &rp, MeshElementsFlags what, Image *image=nullptr, index_t x0=0, index_t y0=0, index_t width=0, index_t height=0)
Picks an element of the mesh.
~MeshGrobTool() override
MeshGrobTool destructor.
index_t pick_edge(const RayPick &rp)
Picks a edge.
index_t pick_cell(const RayPick &rp)
Picks a cell.
bool pick_facet_edge(const RayPick &rp, index_t &facet, index_t &corner)
Picks an edge of a facet.
const vec3 & picked_point() const
Gets the picked point in world coordinates.
MeshGrob * mesh_grob() const
Gets the MeshGrob this MeshGrobTool operates on.
const vec2 & picked_ndc() const
Gets the picked point in normalized device coordinates.
MeshGrobTool(ToolsManager *parent)
MeshGrobTool constructor.
index_t pick_vertex(const RayPick &rp)
Picks a vertex.
double picked_depth() const
Gets the depth of the picked point.
Base class of tools that apply 3d transform to a subset of a MeshGrob and that are attached to a Mult...
MeshGrobTransformSubset(MeshGrobTransformTool *parent)
MeshGrobTransformSubset constructor.
const vec3 & center() const
Gets the center of the subset.
void update_transform_subset(const mat4 &M)
Applies the transform M to the subset.
void grab(const RayPick &p_ndc) override
A MultiTool that applies a mouse-controlled transform to a subset.
void update_transform_subset(const mat4 &M)
Applies the transform M to the subset.
virtual void pick_subset(MeshGrobTransformSubset *tool, const RayPick &rp)=0
Gets the subset by picking.
virtual void transform_subset(const mat4 &M)=0
Applies a 3D transform to the subset.
virtual void clear_subset()
Clears the state variables that store the subset.
void release(const RayPick &p_ndc) override
The event handler for mouse release events.
void grab(const RayPick &p_ndc) override
mat4 prev_inverse_transform_
The inverse of the previous transform.
const vec3 & center() const
Gets the center of the subset.
MeshGrob * mesh_grob() const
Gets the MeshGrob this MeshGrobTransformTool operates on.
A Grob wrapper around Geogram's Mesh class.
Definition: mesh_grob.h:56
A Tool that can associate a different tool to each button of the mouse.
Definition: tool.h:199
Base class for the tools.
Definition: tool.h:61
Manages the Tool objects associated with a given Grob class.
Definition: tools_manager.h:62
the MeshGrob class.
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Global Graphite namespace.
Definition: common.h:76
Controls a 3d rotation from user mouse input.
Represents the information related with a picking event.
Definition: ray_picker.h:64
Base classes for the tools.
A class to manage the Tool objects associated with a given Grob class.