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  protected:
69  int GetSceneGraph_(osg::ref_ptr<osg::Group>& sg,
70  bool exporttextures,
71  const std::string &filename ) const;
72 
73  void AddOSGLines_(osg::ref_ptr<osg::Group>& Rootnode) const;
74 
75  // copy internal points (from ThreeDOut) into a new subtree of
76  // @param Rootnode
77  void AddOSGPoints_(osg::ref_ptr<osg::Group>& Rootnode) const;
78 
79  /** create one transform (IndexedFaceSets), add another transform
80  for each indexed face set, then convert all indexed face-set data
81  from ThreeDOut */
82  osg::Node * AddOSGIndexedFaceSets_(bool exporttextures,
83  std::string graphfilename) const;
84 
85 
86 
87  void AddOSGImage_(osg::ref_ptr<osg::Group>& Rootnode,
88  bool exportTextures,
89  std::string graphfilename) const;
90 
91  //can be used for standard and camera elliposoids
92  void AddOSGEllipsoids_(osg::ref_ptr<osg::Group>& rootNode,
93  bool camEllipsoids=false) const;
94  void AddOSGPMatrix_(osg::ref_ptr<osg::Group>& rootNode) const;
95 
96  std::string
97  GenerateFilename_(std::string graphfilename,
98  std::string subname,
99  unsigned int texnumber) const;
100 
101  std::string TexImgExtension_;
102 
103  };
104 
105 
106 } // namespace
107 
108 
109 #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:336
configuration struct for drawing styles of various 3d objects
Definition: ThreeDOut.hh:296
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.