Graphite  Version 3
An experimental 3D geometry processing program
mesh_grob_paint_tools.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
35  * with the following (non-GPL) libraries: Qt, SuperLU, WildMagic and CGAL
36  */
37 
38 #ifndef H_OGF_MESH_GFX_TOOLS_MESH_GROB_PAINT_TOOLS_H
39 #define H_OGF_MESH_GFX_TOOLS_MESH_GROB_PAINT_TOOLS_H
40 
41 #include <OGF/mesh_gfx/common/common.h>
43 
89 namespace OGF {
90 
94  enum PaintOp {
98  PAINT_DEC
99  };
100 
101  gom_class MESH_GFX_API MeshGrobPaintTool : public MeshGrobTool {
102  public:
104 
108  void reset() override;
109 
110  gom_properties:
114  void set_value(double value);
115 
116  double get_value() const {
117  return value_;
118  }
119 
124  void set_accumulate(bool value);
125 
126  bool get_accumulate() const {
127  return accumulate_;
128  }
129 
134  void set_autorange(bool value);
135 
136  bool get_autorange() const {
137  return autorange_;
138  }
139 
145  void set_pick_vertices_only(bool value);
146 
147  bool get_pick_vertices_only() const {
148  return pick_vertices_only_;
149  }
150 
156  void set_xray_mode(bool value);
157 
158  bool get_xray_mode() const {
159  return xray_mode_;
160  }
161 
162  public:
163  void set_value_for_this_tool(double value) {
164  value_ = value;
165  }
166 
167  void set_accumulate_for_this_tool(bool value) {
168  accumulate_ = value;
169  }
170 
171  void set_autorange_for_this_tool(bool value) {
172  autorange_ = value;
173  }
174 
175  void set_pick_vertices_for_this_tool(bool value) {
176  pick_vertices_only_ = value;
177  }
178 
179  void set_xray_mode_for_this_tool(bool value) {
180  xray_mode_ = value;
181  }
182 
189  static void get_paint_tools(
190  ToolsManager* manager, vector<MeshGrobPaintTool*>& paint_tools
191  );
192 
193  protected:
194 
195  bool get_painting_parameters(
196  const RayPick& raypick,
197  PaintOp& op,
198  MeshElementsFlags& where,
199  std::string& attribute_name,
200  index_t& component
201  );
202 
203  void paint(const RayPick& p_ndc);
204 
205  protected:
206  double value_;
207  bool accumulate_;
208  bool autorange_;
209  bool pick_vertices_only_;
210  bool xray_mode_;
211 
212  index_t picked_element_;
213  };
214 
215  /**********************************************************/
216 
217 
221  gom_attribute(category, "paint")
222  gom_attribute(icon, "paint_rect")
223  gom_attribute(help, "paint attributes in rectangle")
224  gom_attribute(message, "btn1: paint; btn3: erase")
225 
226  gom_class MESH_GFX_API MeshGrobPaintRect : public MeshGrobPaintTool {
227  public:
233 
237  void grab(const RayPick& p_ndc) override;
238 
242  void drag(const RayPick& p_ndc) override;
243 
247  void release(const RayPick& p_ndc) override;
248 
249  gom_properties:
250 
251  protected:
252 
262  void paint_rect(
263  const RayPick& raypick,
264  index_t x0, index_t y0, index_t x1, index_t y1,
265  Image* mask = nullptr
266  );
267 
268  bool active_;
269  vec2 p_;
270  };
271 
272  /************************************************************************/
273 
277  gom_attribute(category, "paint")
278  gom_attribute(icon, "paint")
279  gom_attribute(help, "paint attributes")
280  gom_attribute(message, "btn1: paint; btn3: erase")
281 
282  gom_class MESH_GFX_API MeshGrobPaint : public MeshGrobPaintRect {
283  public:
289 
293  void grab(const RayPick& p_ndc) override;
294 
298  void drag(const RayPick& p_ndc) override;
299 
303  void release(const RayPick& p_ndc) override;
304 
305  gom_properties:
306 
307  void set_width(index_t value) {
308  width_ = value;
309  }
310 
311  index_t get_width() const {
312  return width_;
313  }
314 
315  void set_stroke_mode(bool value) {
316  stroke_mode_ = value;
317  }
318 
319  bool get_stroke_mode() const {
320  return stroke_mode_;
321  }
322 
323  protected:
330  std::function<void(vec2, vec2, vec2, vec2)> doit
331  );
332 
333  protected:
334  index_t width_;
335  vec2 latest_ndc_;
336  bool stroke_mode_;
337  vector<vec2> stroke_;
338  };
339 
340  /*************************************************************/
341 
345  gom_attribute(category, "paint")
346  gom_attribute(icon, "paint_freeform")
347  gom_attribute(help, "paint attributes with free-form selection")
348  gom_attribute(message, "btn1: paint; btn3: erase")
349 
350  gom_class MESH_GFX_API MeshGrobPaintFreeform : public MeshGrobPaintRect {
351  public:
357 
361  void grab(const RayPick& p_ndc) override;
362 
366  void drag(const RayPick& p_ndc) override;
367 
371  void release(const RayPick& p_ndc) override;
372 
373  private:
374  vec2 latest_ndc_;
375  vector<vec2> selection_;
376  };
377 
378  /*****************************************************************/
379 
383  gom_attribute(category, "paint")
384  gom_attribute(icon, "paint_connected")
385  gom_attribute(help, "paint attributes on connected components")
386  gom_attribute(message, "btn1: paint; btn3: erase")
387 
388  gom_class MESH_GFX_API MeshGrobPaintConnected : public MeshGrobPaintTool {
389  public:
395 
399  void grab(const RayPick& p_ndc) override;
400 
401  gom_properties:
402 
407  void set_fill_same_value(bool x) {
408  fill_same_value_ = x;
409  }
410 
411  bool get_fill_same_value() const {
412  return fill_same_value_;
413  }
414 
419  void set_tolerance(double value) {
420  tolerance_ = value;
421  }
422 
423  double get_tolerance() const {
424  return tolerance_;
425  }
426 
427 
428  protected:
429  bool test(double reference, double value) const {
430  return !fill_same_value_ ||
431  ::fabs(reference - value) <= tolerance_;
432  }
433 
434  private:
435  bool fill_same_value_;
436  double tolerance_;
437  };
438 
439  /**********************************************************************/
440 
444  gom_attribute(category, "paint")
445  gom_attribute(icon, "pipette")
446  gom_attribute(help, "probe attributes")
447  gom_attribute(message, "btn1: probe attributes")
448 
449  gom_class MESH_GFX_API MeshGrobProbe : public MeshGrobTool {
450  public:
456 
460  void grab(const RayPick& p_ndc) override;
461 
465  void drag(const RayPick& p_ndc) override;
466 
470  void release(const RayPick& p_ndc) override;
471 
472  protected:
473  void probe(const RayPick& p_ndc);
474 
475  private:
476  bool picked_;
477  bool grabbed_;
478  double value_;
479  vec2 latest_ndc_;
480  std::string message_;
481  };
482 
483  /********************************************************/
484 
488  gom_attribute(category, "paint")
489  gom_attribute(icon, "ruler")
490  gom_attribute(help, "measures distances on a mesh")
491 
492  gom_class MESH_GFX_API MeshGrobRuler : public MeshGrobTool {
493  public:
499 
503  void grab(const RayPick& p_ndc) override;
504 
508  void drag(const RayPick& p_ndc) override;
509 
513  void release(const RayPick& p_ndc) override;
514 
515  protected:
516  bool pick(const RayPick& p_ndc, vec3& p);
517  void show_distance(const RayPick& p_ndc);
518 
519  private:
520  bool p_picked_;
521  vec3 p_;
522  vec2 latest_ndc_;
523  };
524 
525  /*******************************************************/
526 
527 }
528 
529 #endif
An image.
Definition: image.h:59
Vector with aligned memory allocation.
Definition: memory.h:635
Paint attributes in connected components.
MeshGrobPaintConnected(ToolsManager *parent)
MeshGrobPaintConnected constructor.
void set_tolerance(double value)
Tolerance used if fill_same_value os set.
void grab(const RayPick &p_ndc) override
Paint attributes using free-form selection.
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.
MeshGrobPaintFreeform(ToolsManager *parent)
MeshGrobPaintFreeform constructor.
A rect selection tool that paints attribute values in a mesh.
void grab(const RayPick &p_ndc) override
MeshGrobPaintRect(ToolsManager *parent)
MeshGrobPaint constructor.
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.
void reset() override
Resets this Tool.
static void get_paint_tools(ToolsManager *manager, vector< MeshGrobPaintTool * > &paint_tools)
Gets all paint tools from the ToolsManager.
void set_xray_mode(bool value)
If set, pick everything that falls within the rect, else pick only visible elements.
void set_accumulate(bool value)
If set, value is added to previous value when painting.
void set_pick_vertices_only(bool value)
If set, vertex attributes can be only painted by directly picking vertices, else one can pick facets ...
void set_autorange(bool value)
If set, colormap range is continuously updated when painting.
A tool that paints attribute values in a mesh.
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.
void grab(const RayPick &p_ndc) override
void for_each_stroke_quad(std::function< void(vec2, vec2, vec2, vec2)> doit)
Calls a user function for each quad of the stroke.
MeshGrobPaint(ToolsManager *parent)
MeshGrobPaint constructor.
A tool that probes attribute values in a mesh.
void grab(const RayPick &p_ndc) override
MeshGrobProbe(ToolsManager *parent)
MeshGrobPaint constructor.
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.
A tool that measures distances.
void drag(const RayPick &p_ndc) override
The event handler for mouse drag events.
void release(const RayPick &p_ndc) override
The event handler for mouse release events.
void grab(const RayPick &p_ndc) override
MeshGrobRuler(ToolsManager *parent)
MeshGrobPaint constructor.
Base class for tools that operate on MeshGrob.
Manages the Tool objects associated with a given Grob class.
Definition: tools_manager.h:62
Base classes for tools that operate on MeshGrob.
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Global Graphite namespace.
Definition: common.h:76
PaintOp
A painting operation.
Represents the information related with a picking event.
Definition: ray_picker.h:64