Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
OpenSceneGraphHelper.hh
1 #ifndef __OPNESCENEGRAPHHELPER_HH__
2 #define __OPNESCENEGRAPHHELPER_HH__
3 #include <bias_config.h>
4 
5 #include <Base/Image/Image.hh>
6 #include <Utils/TriangleMesh.hh>
7 #include <string>
8 
9 namespace osg {
10  class Node;
11  class Group;
12  class Geode;
13  class Geometry;
14  class Image;
15  class Matrixd;
16  class Vec3f;
17  template <class T> class ref_ptr;
18  typedef class Vec3f Vec3;
19  typedef class Matrixd Matrix;
20 }
21 
22 // why the forward declarations? breaks on win32. fkellner
23 /*
24 namespace BIAS {
25  class TriangleMesh;
26  template <class T> class Image;
27  template <class T> class Matrix4x4;
28 }
29 */
30 
31 
32 namespace BIAS {
33 
34 
35 /**
36  * @class OpenSceneGraphHelper
37  * @brief Utility class for using OpenSceneGraph
38  * @ingroup g_glviewer
39  * @author MIP
40 */
41  class BIASGLviewer_EXPORT OpenSceneGraphHelper {
42  public:
45 
46 
47 
48  /** @brief conversion function */
49  static bool BIASimageToOSGimage(const BIAS::Image<unsigned char>& in,
50  osg::Image* out, bool copydata);
51 
52  static bool OSGimageToBIASimage(const osg::Image* in,
54 
55  /** this is the new method which takes a triangle mesh and creates
56  an osg branch avoiding the copying into ThreeDOut.
57  */
58  static osg::Node* CreateBranchIndexedFaceSets(const BIAS::TriangleMesh& mesh
59  ,const std::string& name);
60 
61 
62  static bool OSG2BIASMatrix( const osg::Matrixd& OsgMat,
63  BIAS::Matrix4x4<double>& BiasMat);
64 
65  static bool BIAS2OSGMatrix(const BIAS::Matrix4x4<double>& BiasMat,
66  osg::Matrixd& OsgMat);
67 
68  /** checks max texture size and adjusts */
69  static bool AdjustImageSizeToGPULimit(BIAS::Image<unsigned char>& tex);
70 
71 
72  /** Checks if the node contains additional information in form of a
73  key value pair. Throws an exception when node is NULL.
74  @author woelk 11/2009 */
75  static bool HasInfo(const osg::ref_ptr<osg::Node> node,
76  const std::string &key, std::string &value);
77 
78  /** Removes key value pair from node. Returns false if info was not
79  contained in the node. Throws an exception when node is NULL.
80  @author woelk 11/2009 */
81  static bool RemoveInfo(osg::ref_ptr<osg::Node> node,
82  const std::string &key);
83 
84  /** Adds or sets information to the node. Returns false if info is
85  overwritten. Throws an exception when node is NULL.
86  @author woelk 11/2009 */
87  static bool AddOrSetInfo(osg::ref_ptr<osg::Node> node,
88  const std::string &key,
89  const std::string &value);
90 
91  /** returns the associated info as key_value pairs */
92  static void GetInfo(const osg::ref_ptr<osg::Node> node,
93  std::map<std::string, std::string> &key_val);
94 
95  /** Finds a node downwards of node who has a matching key value
96  pair. Returns NULL if no node with a matching key value pair is found.
97  Throws an exception when node is NULL.
98  @author woelk 11/2009 */
100  FindNodeWithInfo(const osg::ref_ptr<osg::Node> node,
101  const std::string &key,
102  const std::string &value);
103 
104  /** Prints the content of the info associated with node to cout */
105  static void DumpInfo(const osg::ref_ptr<osg::Node> node);
106 
107  /** Returns a vector of all nodes containing an info characterised by key.
108  The search is conducted starting by node and proceeding downwards of
109  node.
110  @author woelk 11/2009 */
111  static std::vector<osg::ref_ptr<osg::Node> >
112  FindNodesWithInfo(const osg::ref_ptr<osg::Node> node,
113  const std::string &key);
114 
115  protected:
116  /// helper function for FindNodesWithInfo
117  static void
118  FindNodesWithInfoHelper_(const osg::ref_ptr<osg::Node> CurrentNode,
119  const std::string &key,
120  std::vector<osg::ref_ptr<osg::Node> > &result);
121 
122  }; //class OpenSceneGraphHelper
123 
124  /// stream operator for osg matrix (woelk 10/2009)
125  std::ostream &operator<<(std::ostream& os, const osg::Matrix& m);
126  /// stream operator for osg vector (woelk 10/2009)
127  std::ostream &operator<<(std::ostream& os, const osg::Vec3& v);
128 
129 
130 
131 }//namespace
132 #endif
class Vec3f Vec3
Create and represent a 3D triangle mesh.
Definition: TriangleMesh.hh:84
class Matrixd Matrix
std::ostream & operator<<(std::ostream &os, const Array2D< T > &arg)
Definition: Array2D.hh:260
Utility class for using OpenSceneGraph.