Graphite  Version 3
An experimental 3D geometry processing program
grob.h
Go to the documentation of this file.
1 /*
2  * OGF/Graphite: Geometry and Graphics Programming Library + Utilities
3  * Copyright (C) 2000 Bruno Levy
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
24  *
25  * levy@loria.fr
26  *
27  * ISA Project
28  * LORIA, INRIA Lorraine,
29  * Campus Scientifique, BP 239
30  * 54506 VANDOEUVRE LES NANCY CEDEX
31  * FRANCE
32  *
33  * Note that the GNU General Public License does not permit incorporating
34  * the Software into proprietary programs.
35  */
36 
37 
38 #ifndef H_OGF_SCENE_GRAPH_TYPES_GROB_H
39 #define H_OGF_SCENE_GRAPH_TYPES_GROB_H
40 
43 #include <OGF/gom/types/node.h>
45 
46 #include <map>
47 
53 namespace OGF {
54 
55 //_________________________________________________________
56 
57  class CompositeGrob;
58  class SceneGraph;
59  class Commands;
60  class InputGraphiteFile;
61  class OutputGraphiteFile;
62  class Interpreter;
63 
67  gom_attribute(abstract, "true")
68  gom_class SCENE_GRAPH_API Grob : public Node {
69  public:
70 
76  Grob(CompositeGrob* parent);
77 
81  ~Grob() override;
82 
83 
91  const std::string& name() const {
92  return name_;
93  }
94 
99  virtual Box3d bbox() const = 0;
100 
106  virtual Box3d world_bbox() const;
107 
115  virtual bool is_serializable() const;
116 
124  virtual bool serialize_read(InputGraphiteFile& geofile);
125 
135  virtual bool serialize_write(OutputGraphiteFile& geofile);
136 
145  void set_shader(const std::string& value);
146 
147 
157  std::string& classname, ArgList& properties, bool pointers=true
158  );
159 
167  const std::string& classname, const ArgList& properties
168  );
169 
170 
179  return grob_attributes_;
180  }
181 
189  const ArgList& attributes() const {
190  return grob_attributes_;
191  }
192 
200  bool dirty() const {
201  return dirty_;
202  }
203 
210  void up_to_date() {
211  dirty_ = false;
212  }
213 
222  bool graphics_are_locked() const {
223  return (nb_graphics_locks_ != 0);
224  }
225 
240  void lock_graphics() {
241  ++nb_graphics_locks_;
242  dirty_ = true;
243  }
244 
260  --nb_graphics_locks_;
261  }
262 
270  static Grob* find(SceneGraph* sg, const std::string& name);
271 
272 
278 
279  gom_slots:
286  virtual void update();
287 
294  virtual void redraw();
295 
301  return scene_graph_;
302  }
303 
310  virtual bool load(const FileName& value);
311 
318  virtual bool save(const NewFileName& value);
319 
327  virtual bool append(const FileName& value);
328 
332  virtual void clear();
333 
340  virtual void rename(const std::string& value);
341 
347  virtual Grob* duplicate(SceneGraph* sg);
348 
362  virtual Object* query_interface(const std::string& name);
363 
364 
370  return attributes().nb_args();
371  }
372 
379  const std::string& ith_grob_attribute_name(index_t i) const {
380  return attributes().ith_arg_name(i);
381  }
382 
389  std::string ith_grob_attribute_value(index_t i) const {
390  return attributes().ith_arg_value(i).as_string();
391  }
392 
401  const std::string& name, const std::string& value
402  ) {
403  attributes().set_arg(name, value);
404  }
405 
406  gom_signals:
407 
413  virtual void value_changed(Grob* value);
414 
415  gom_properties:
416 
421  const std::string& get_name() const {
422  return name_;
423  }
424 
431  void set_filename(const std::string& value) {
432  filename_ = value;
433  }
434 
441  const std::string& get_filename() const {
442  return filename_;
443  }
444 
452  bool get_visible() const;
453 
460  void set_visible(bool value);
461 
466  Object* get_shader() const;
467 
473  // Stored as Object_var to avoid dependency to Shader
474  // return (ShaderManager*)(shader_manager_.get());
475  return shader_manager_;
476  }
477 
485  void set_obj_to_world_transform(const mat4& value) {
486  obj_to_world_ = value;
487  }
488 
497  return obj_to_world_;
498  }
499 
500  protected:
508  void initialize_name(const std::string& name);
509 
515  void set_shader_manager(Object* s/* ShaderManager* s */) {
516  // shader_manager_ = (Object *)s;
517  shader_manager_ = s;
518  }
519 
520  protected:
521  std::string name_;
522  std::string filename_;
523  bool visible_;
524  SceneGraph* scene_graph_;
525  mat4 obj_to_world_;
526  Object_var shader_manager_;
527  ArgList grob_attributes_;
528  bool dirty_;
529  index_t nb_graphics_locks_;
530 
531  friend class SceneGraph;
532  friend class SceneGraphShaderManager;
533  friend class ShaderManager;
534  };
535 
540 
541 //_________________________________________________________
542 
543 }
544 #endif
Represents a list of name-value pairs.
Definition: arg_list.h:65
A 3d axis aligned box.
Definition: geometry.h:235
A Composite Graphite Object.
Base class for all 3D Graphite objects.
Definition: grob.h:68
Object * get_shader_manager() const
Gets the ShaderManager associated with this Grob.
Definition: grob.h:472
const std::string & name() const
Gets the name of this Grob.
Definition: grob.h:91
virtual void rename(const std::string &value)
Renames this Grob.
SceneGraph * scene_graph() const
Gets the SceneGraph.
Definition: grob.h:300
std::string ith_grob_attribute_value(index_t i) const
gets the value of a grob attribute
Definition: grob.h:389
virtual bool serialize_read(InputGraphiteFile &geofile)
Reads this Grob from a GeoFile.
virtual bool append(const FileName &value)
Appends the content of the specified file to this Grob.
virtual bool is_serializable() const
Tests whether this Grob can be serialized in GeoFile.
void unlock_graphics()
Unlocks graphics for this VoxelGrob.
Definition: grob.h:259
void lock_graphics()
Locks graphics for this VoxelGrob.
Definition: grob.h:240
bool graphics_are_locked() const
Tests whether this VoxelGrob is locked for graphics display.
Definition: grob.h:222
Object * get_shader() const
Gets the shader associated with this Grob.
virtual bool serialize_write(OutputGraphiteFile &geofile)
Writes this Grob into a stream.
const mat4 & get_obj_to_world_transform() const
Gets the object to world transform.
Definition: grob.h:496
void set_shader(const std::string &value)
Changes the current shader of this Grob.
void set_shader_and_shader_properties(const std::string &classname, const ArgList &properties)
Sets the shader and its properties.
virtual Interpreter * interpreter()
Gets a pointer to the main Interpreter.
index_t nb_grob_attributes() const
gets the number of grob attributes
Definition: grob.h:369
virtual bool load(const FileName &value)
Replaces this Grob with the contents of a file.
virtual Object * query_interface(const std::string &name)
Creates an Interface object connected to this Grob.
void set_shader_manager(Object *s)
Sets the ShaderManager associated with this Grob.
Definition: grob.h:515
void initialize_name(const std::string &name)
Initializes the name of this Grob.
virtual Box3d bbox() const =0
Gets the bounding box.
virtual bool save(const NewFileName &value)
Saves this Grob to a file.
void up_to_date()
Tests whether this object is up to date.
Definition: grob.h:210
const std::string & ith_grob_attribute_name(index_t i) const
gets the name of a grob attribute
Definition: grob.h:379
static Grob * find(SceneGraph *sg, const std::string &name)
Finds a Grob by name.
virtual Grob * duplicate(SceneGraph *sg)
Duplicates this Grob.
const std::string & get_filename() const
Gets the filename of this Grob.
Definition: grob.h:441
virtual Box3d world_bbox() const
Gets the bounding box in world coordinates.
void set_visible(bool value)
Sets the visibility flag of this Grob.
const ArgList & attributes() const
Gets the attributes associated with this Grob.
Definition: grob.h:189
void get_shader_and_shader_properties(std::string &classname, ArgList &properties, bool pointers=true)
Gets the classname of the shader and its properties.
void set_obj_to_world_transform(const mat4 &value)
Sets the object to world transform.
Definition: grob.h:485
virtual void redraw()
Triggers update events and redraws the scene.
bool get_visible() const
Tests whether this Grob is visible.
void set_grob_attribute(const std::string &name, const std::string &value)
sets the value of a grob attribute
Definition: grob.h:400
ArgList & attributes()
Gets the attributes associated with this Grob.
Definition: grob.h:178
bool dirty() const
Gets the dirty flag.
Definition: grob.h:200
~Grob() override
Grob destructor.
Grob(CompositeGrob *parent)
Grob constructor.
void set_filename(const std::string &value)
Sets the name of this Grob.
Definition: grob.h:431
virtual void clear()
Clears this Grob.
An extension of InputGeoFile for storing a complete Graphite scenegraph in a structured binary file.
Definition: geofile.h:67
Abstract base class for the GOM interpreter.
Definition: interpreter.h:222
A template class for strings that need to have a specific type in the GOM system.
Definition: properties.h:218
A composite object in the GOM system.
Definition: node.h:58
Base class for all objects in the GOM system.
Definition: object.h:65
An extension of InputGeoFile for storing a complete Graphite scenegraph in a structured binary file.
Definition: geofile.h:129
Manages the shaders and full screen effects for the entire SceneGraph.
Represents the list of objects loaded in Graphite.
Definition: scene_graph.h:62
Manages the Shader objects associated with a Grob.
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329
Global Graphite namespace.
Definition: common.h:76
SmartPointer< Grob > Grob_var
An automatic reference-counted pointer to a Grob.
Definition: grob.h:539
The base class for all composite objects in the GOM system.
Simple geometric objects and manipulations.
Definitions common to all include files in the scene_graph library.