Basic Image AlgorithmS Library 2.8.0

ThreeDOutOpenSceneGraph.hh

00001 #ifndef __ThreeDOutOpenSceneGraph_hh__
00002 #define __ThreeDOutOpenSceneGraph_hh__
00003 
00004 #include <bias_config.h>
00005 #include <Base/Common/FileHandling.hh>
00006 #include <Utils/ThreeDOut.hh>
00007 
00008 namespace osg {
00009   class Node;
00010   class Group;
00011   class Geode;
00012   class Geometry;
00013 
00014   template <class T> class ref_ptr;
00015 }
00016 
00017 
00018 namespace BIAS {
00019    /** @class ThreeDOutOpenSceneGraph
00020        @brief a class for exporting ThreeDOut objects to OSG scene graphs
00021        @ingroup g_glviewer
00022        @author Grauel 10/2007 
00023    */
00024 
00025   class BIASGLviewer_EXPORT ThreeDOutOpenSceneGraph
00026     : public BIAS::ThreeDOut
00027   {
00028   public:
00029     ThreeDOutOpenSceneGraph(const BIAS::ThreeDOutParameters& params=
00030                             BIAS::ThreeDOutParameters());
00031     virtual ~ThreeDOutOpenSceneGraph();
00032 
00033     /** @brief Generic write method (wrapper for OpenSceneGraphOut). */
00034     virtual int WriteToFile(const std::string &filename) {
00035       if (BIAS::FileHandling::Extension(filename).compare("wrl") == 0)
00036         return VRMLOut(filename);
00037       else
00038         return OpenSceneGraphOut(filename);
00039     }
00040 
00041     /** @brief save ThreeDOut object as OpenSceneGraph
00042         saves an Open Scene Graph and the needed textures
00043         @param filename filename of scene graph (XXXX.osg or XXXXXXX.ive)
00044         OpenScenegraphOut() saves the textures contained in ThreeDOut
00045         to disk, since they can't be embedded in .osg-files.
00046         the filename will be used as prefix for the texture file names.
00047         In case of saving an osg binary format file (.ive)
00048         the textures will be included in this file.
00049     */
00050     int OpenSceneGraphOut(const std::string &filename) const;
00051 
00052     /** @brief Get ThreeDOut object as OpenSceneGraph structure
00053         @param sg an empty ref_ptr 
00054         after calling GetOpenSceneGraph sg points to the scene graph structure 
00055     */
00056     int GetOpenSceneGraph(osg::ref_ptr<osg::Group>& sg, bool exporttextures=false) const;
00057 
00058     /** @brief Set the file extension and type of the saved textures
00059         @param ext a string with no leading point. e.g. "jpeg"
00060         if OpenScenegraphOut() is called the textures contained in ThreeDOut
00061         are saved to disk. the default type of this textures is "tif".
00062         By calling SetImageFileExtension() the file type/extension can be
00063         changed. */
00064     void SetImageFileExtension(std::string ext)
00065     { TexImgExtension_ = ext; }
00066 
00067 
00068   protected:    
00069     int GetSceneGraph_(osg::ref_ptr<osg::Group>& sg,
00070                        bool exporttextures,
00071                        const std::string &filename ) const;
00072 
00073     void AddOSGLines_(osg::ref_ptr<osg::Group>& Rootnode) const;
00074 
00075     //    copy internal points (from ThreeDOut) into a new subtree of
00076     //    @param Rootnode
00077     void AddOSGPoints_(osg::ref_ptr<osg::Group>& Rootnode) const;
00078 
00079     /** create one transform (IndexedFaceSets), add another transform
00080      for each indexed face set, then convert all indexed face-set data
00081      from ThreeDOut  */
00082     osg::Node * AddOSGIndexedFaceSets_(bool exporttextures,
00083                                 std::string graphfilename) const;
00084 
00085    
00086  
00087     void AddOSGImage_(osg::ref_ptr<osg::Group>& Rootnode,
00088                       bool exportTextures,
00089                       std::string graphfilename) const;
00090     
00091     //can be used for standard and camera elliposoids
00092     void AddOSGEllipsoids_(osg::ref_ptr<osg::Group>& rootNode, 
00093                       bool camEllipsoids=false) const;
00094     void AddOSGPMatrix_(osg::ref_ptr<osg::Group>& rootNode) const;
00095 
00096     std::string 
00097        GenerateFilename_(std::string graphfilename,
00098                          std::string subname,
00099                          unsigned int texnumber) const;
00100 
00101     std::string TexImgExtension_;
00102     
00103   };
00104 
00105 
00106 } // namespace
00107 
00108 
00109 #endif // __ThreeDOutOpenSceneGraph_hh__
 All Classes Functions Variables Typedefs Enumerations Enumerator Friends