vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ObjectEffect.h
Go to the documentation of this file.
1 #ifndef OBJECTEFFECT_H
2 #define OBJECTEFFECT_H
3 
4 #include <vrecko/Ability.h>
5 #include <osg/Group>
6 #include <osg/ShapeDrawable>
7 #include <helpers/DynamicArray.h>
8 #include <vrecko/SP_CommonDefs.h>
9 
10 using namespace vrecko;
11 
12 namespace APObjectUtils
13 {
14 
15  class ObjectEffect: public Ability
16  {
17  public:
18 
19  enum EffectType {
21  // Nothing is displayed
23  // Displays bounding sphere of the object
25  // Displays bounding box of the object
27  // Changes the object to be transparent. The transparency value is retrieved from alpha part of the [color]
28  // The COLOR values are IGNORED.
29  // Alternatively, you can use "Colorize", which includes the color values.
31  // Changes the object material to specified color.
32  // THIS INCLUDES TRANSPARENCY AS WELL.
33  // Alternatively, you can use "Transparency", which ignores the color values.
35  // Displays collision pairs.
36  // Requires that there is a collision detection registered
37  // in the Scene through Scene::addPartitioningSceneInterface().
38  // If also PartitioningObjectInterface was registered, it will be used automatically.
40  // Displays a layer of spher ebounding volumes. (The layer index can be changed.)
41  // REQUIRES that current object has either SphereBVH_Object_Data or SNCH_Object_Data ability
43  // Displays SNCH cones.
44  // REQUIRES that current object has either SNCH_Object_Data ability
47  // Displays vertex normals.
48  // REQUIRES that current object has either SphereBVH_Object_Data or SNCH_Object_Data ability
50  // Displays face normals.
51  // REQUIRES that current object has either SphereBVH_Object_Data or SNCH_Object_Data ability
53  // Similar to "Transparency" effect, but this time the object is also rendered on top of other objects.
54  // The COLOR values are IGNORED.
55  // Alternatively, you can use "ColorizeOnTop", which includes the color values.
57  // Similar to "Colorize", but object is rendered on top of other objects.
58  // THIS INCLUDES TRANSPARENCY AS WELL.
59  // Alternatively, you can use "TransparencyOnTop", which ignores the color values.
61  // Visualize the voxel grid.
62  // REQUIRES that the owner object has the VoxelGrid_Object_Data ability
64  // Visualize the voxel grid.
65  // REQUIRES that the owner object has the VoxelGrid_Object_Data ability
67  // Visualize the point shell.
68  // REQUIRES that the owner object has the PointShell_Object_Data ability
70  // Turns on the double-sided rendering
72  // displays the normals of faces
73  // require to Pointshell_Object_Data
74  };
75 
76  ObjectEffect();
77  virtual ~ObjectEffect();
78 
80  virtual void preInitialize();
82  virtual void postInitialize();
84  virtual bool loadXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *pParametersNode);
86  virtual void update();
88 // virtual void processEvent(const std::string &strInputName, void *pValue);
90  virtual void clean();
91 
92  void setEffectType(EffectType newType);
93  EffectType getEffectType(void) { return effectType; }
94 
95  bool isEffectCreated() { return bEffectCreated; }
96 
97  protected:
99 
101 
102  int iDistanceFieldValue; // used for a DistanceField/Voxel Grid Show
103 
104  osg::Vec4 color;
105  int iLevelMin, iLevelMax;
106  // used for SphereBVH/SNCH/PointShell: Min and Max level o hierarchy to display
107  // The level numbering starts from 0 (root, min. level).
108  // Either variable can be -1, which means the lowest (iLevelMin)
109  // or the highest (iLevelMax) level.
110  inline int getLevelMin() { return iLevelMin; }
111  inline int getLevelMax() { return iLevelMax; }
112  void setLevelMinMax(int newLevelMin, int newLevelMax);
113 
114  float fRadius;
115  // used for PointShell: Point radius for visualization
116 
118  // SphereBVH/SNCH: Render leaf nodes, if a level was selected, which has not been
119  // reached in the current subtree
121  // Collisions: Perform no calculations and only use the data that is
122  // available if anyone else is performing any calculations in the bakcground.
123 
124  osg::ref_ptr<EnvironmentObject> graphicObject;
125  osg::ref_ptr<osg::Geode> osgGeode;
126  osg::ref_ptr<osg::MatrixTransform> osgTransform;
127  osg::ref_ptr<osg::Sphere> shapeSphere;
128  osg::ref_ptr<osg::Box> shapeBox;
129  osg::ref_ptr<osg::ShapeDrawable> shapeDraw;
130 
131  std::vector<osg::ref_ptr<osg::ShapeDrawable>> shapeDrawables;
132 
133  osg::ref_ptr<osg::StateSet> originalStateSet;
134  // StateSet of the owner object before the effect was applied.
135  // This StateSet will be restored when the effect is destroyed.
136 
138  // For displaying colisions
139 
140  void createEffect();
141  bool createEffect_SphereHierarchy_ProcessLevel(
142  vrecko::Ability *dataAbility, void *node, int iCurrentLevel);
143  // helper function for creating SphereBVH/SNCH hierarchy
144  bool createEffect_PointShellHierarchy_ProcessLevel( vrecko::Ability *dataAbility, void *node, int iCurrentLevel, bool draw);
145  // helper function for creating PointShell hierarchy
146  bool draw_Effect_PointShellHierarchy_Node(vrecko::Ability *dataAbility, void *node, int iCurrentLevel);
147  // draws Nodes from pointshell
148  bool createEffect_Lines(vrecko::Ability *dataAbility);
149  // For Collisions effect, the [dataAbility] is not used (might be NULL)
150  bool createEffect_Reconstruction(vrecko::Ability *dataAbility);
151  // For SNCHFaceGroups where original objects are recreated entirely from the SNCH_Object_Data ability
152  bool createEffect_VoxelGrid(vrecko::Ability *dataAbility);
153  // For the VoxelGrid effect
154  void destroyEffect();
155 
156  void HSVtoRGB (float *r, float *g, float *b, float h, float s, float v);
157  // Ranges are from 0.0 to 1.0
158 
159  DECLARE_INPUT(ShiftLevels, MessageInt);
160  };
161 
162 }
163 
164 
165 #endif