Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ThreeDOutOpenSceneGraph.hh
1 #ifndef __ThreeDOutOpenSceneGraph_hh__
2 #define __ThreeDOutOpenSceneGraph_hh__
3 
4 #include <bias_config.h>
5 #include <Base/Common/FileHandling.hh>
6 #include <Utils/ThreeDOut.hh>
7 
8 namespace osg {
9  class Node;
10  class Group;
11  class Geode;
12  class Geometry;
13 
14  template <class T> class ref_ptr;
15 }
16 
17 
18 namespace BIAS {
19  /** @class ThreeDOutOpenSceneGraph
20  @brief a class for exporting ThreeDOut objects to OSG scene graphs
21  @ingroup g_glviewer
22  @author Grauel 10/2007
23  */
24 
25  class BIASGLviewer_EXPORT ThreeDOutOpenSceneGraph
26  : public BIAS::ThreeDOut
27  {
28  public:
31  virtual ~ThreeDOutOpenSceneGraph();
32 
33  /** @brief Generic write method (wrapper for OpenSceneGraphOut). */
34  virtual int WriteToFile(const std::string &filename) {
35  if (BIAS::FileHandling::Extension(filename).compare("wrl") == 0)
36  return VRMLOut(filename);
37  else
38  return OpenSceneGraphOut(filename);
39  }
40 
41  /** @brief save ThreeDOut object as OpenSceneGraph
42  saves an Open Scene Graph and the needed textures
43  @param filename filename of scene graph (XXXX.osg or XXXXXXX.ive)
44  OpenScenegraphOut() saves the textures contained in ThreeDOut
45  to disk, since they can't be embedded in .osg-files.
46  the filename will be used as prefix for the texture file names.
47  In case of saving an osg binary format file (.ive)
48  the textures will be included in this file.
49  */
50  int OpenSceneGraphOut(const std::string &filename) const;
51 
52  /** @brief Get ThreeDOut object as OpenSceneGraph structure
53  @param sg an empty ref_ptr
54  after calling GetOpenSceneGraph sg points to the scene graph structure
55  */
56  int GetOpenSceneGraph(osg::ref_ptr<osg::Group>& sg, bool exporttextures=false) const;
57 
58  /** @brief Set the file extension and type of the saved textures
59  @param ext a string with no leading point. e.g. "jpeg"
60  if OpenScenegraphOut() is called the textures contained in ThreeDOut
61  are saved to disk. the default type of this textures is "tif".
62  By calling SetImageFileExtension() the file type/extension can be
63  changed. */
64  void SetImageFileExtension(std::string ext)
65  { TexImgExtension_ = ext; }
66 
67 
68 
69  protected:
70  int GetSceneGraph_(osg::ref_ptr<osg::Group>& sg,
71  bool exporttextures,
72  const std::string &filename ) const;
73 
74  void AddOSGLines_(osg::ref_ptr<osg::Group>& Rootnode) const;
75 
76  void AddOSGTexts_(osg::ref_ptr<osg::Group>& Rootnode) const;
77 
78  // copy internal points (from ThreeDOut) into a new subtree of
79  // @param Rootnode
80  void AddOSGPoints_(osg::ref_ptr<osg::Group>& Rootnode) const;
81 
82  /** create one transform (IndexedFaceSets), add another transform
83  for each indexed face set, then convert all indexed face-set data
84  from ThreeDOut */
85  osg::Node * AddOSGIndexedFaceSets_(bool exporttextures,
86  std::string graphfilename) const;
87 
88 
89 
90  void AddOSGImage_(osg::ref_ptr<osg::Group>& Rootnode,
91  bool exportTextures,
92  std::string graphfilename) const;
93 
94  //can be used for standard and camera elliposoids
95  void AddOSGEllipsoids_(osg::ref_ptr<osg::Group>& rootNode,
96  bool camEllipsoids=false) const;
97  void AddOSGPMatrix_(osg::ref_ptr<osg::Group>& rootNode) const;
98 
99  std::string
100  GenerateFilename_(std::string graphfilename,
101  std::string subname,
102  unsigned int texnumber) const;
103 
104  std::string TexImgExtension_;
105 
106  };
107 
108 
109 } // namespace
110 
111 
112 #endif // __ThreeDOutOpenSceneGraph_hh__
void SetImageFileExtension(std::string ext)
Set the file extension and type of the saved textures.
Unified output of 3D entities via OpenGL or VRML.
Definition: ThreeDOut.hh:349
configuration struct for drawing styles of various 3d objects
Definition: ThreeDOut.hh:309
virtual int WriteToFile(const std::string &filename)
Generic write method (wrapper for OpenSceneGraphOut).
a class for exporting ThreeDOut objects to OSG scene graphs
static std::string Extension(const std::string &fullname)
Get file extension (without dot!) from given path and filename.