Privacy
An open-source, flexible 3D physical simulation framework
gui_helper_functions.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011, 2012, DFKI GmbH Robotics Innovation Center
3  *
4  * This file is part of the MARS simulation framework.
5  *
6  * MARS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License
8  * as published by the Free Software Foundation, either version 3
9  * of the License, or (at your option) any later version.
10  *
11  * MARS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with MARS. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #ifndef GUI_HELPER_FUCTIONS_H
22 #define GUI_HELPER_FUCTIONS_H
23 
24 #ifdef _PRINT_HEADER_
25  #warning "gui_helper_functions.h"
26 #endif
27 
28 #include <osg/Group>
29 #include <osg/Node>
30 #include <osg/Geode>
31 #include <osg/Geometry>
32 #include <osg/Texture2D>
33 #include <osg/PositionAttitudeTransform>
34 
35 #include <vector>
36 #include <sstream>
37 
38 #include <mars/interfaces/sim_common.h>
39 #include <mars/interfaces/terrainStruct.h>
40 #include <mars/interfaces/sim/LoadCenter.h>
41 
42 #include <mars/interfaces/graphics/GraphicsManagerInterface.h>
43 
44 
45 namespace mars {
46  namespace graphics {
47 
48  class GraphicsWidget;
49 
54  struct nodemanager {
55  osg::ref_ptr<osg::Group> node;
56  osg::ref_ptr<osg::PositionAttitudeTransform> transform;
57  osg::ref_ptr<osg::MatrixTransform> matrix;
58  unsigned long index;
59  std::string name;
63  }; // end of struct nodemanager
64 
65  struct nodeFileStruct {
66  std::string fileName;
67  osg::ref_ptr<osg::Node> node;
68  }; // end of struct nodeFileStruct
69 
71  std::string fileName;
72  osg::ref_ptr<osg::Texture2D> texture;
73  }; // end of struct textureFileStruct
74 
75  struct imageFileStruct {
76  std::string fileName;
77  osg::ref_ptr<osg::Image> image;
78  }; // end of struct imageFileStruct
79 
80  osg::Vec4 toOSGVec4(const mars::utils::Color &col);
81  osg::Vec4 toOSGVec4(const mars::utils::Vector &v, float w);
82 
84  class GeodeVisitor: public osg::NodeVisitor{
85  public:
86  GeodeVisitor(const std::string name);
87 
88  virtual void apply(osg::Node &searchNode);
89 
90  osg::Geode *getNode();
91 
92  private:
93  osg::Geode *resultNode;
94  std::string name;
95 
96  }; // end of class GeodeVisitor
97 
98 
101  public:
103 
104  //void setGraphicsWidget(GraphicsWidget *widget);
105  //bool validateGraphicsWidget(void);
106 
107  static void clearStates(osg::ref_ptr<osg::Node> node);
109  static mars::interfaces::snmesh convertOsgNodeToSnMesh(osg::Node *node,
110  double scaleX,
111  double scaleY,
112  double scaleZ,
113  double pivotX,
114  double pivotY,
115  double pivotZ);
116 
117  mars::utils::Vector getExtend(osg::Node* oGroup);
118  void initGraphics();
119 
120  virtual std::vector<double> getMeshSize(const std::string &filename);
121  virtual void getPhysicsFromMesh(mars::interfaces::NodeData *node);
122  virtual void readPixelData(mars::interfaces::terrainStruct *terrain);
123 
124  static osg::ref_ptr<osg::Node> readNodeFromFile(std::string fileName);
125  static osg::ref_ptr<osg::Node> readBobjFromFile(const std::string &filename);
126  static osg::ref_ptr<osg::Texture2D> loadTexture(std::string filename);
127  static osg::ref_ptr<osg::Image> loadImage(std::string filename);
128 
129  private:
130  osg::Geometry *my_geo;
131  osg::ref_ptr<osg::Vec3Array> my_v3;
133  //GraphicsWidget *gw;
134  //for compatibility
136  static std::vector<nodeFileStruct> nodeFiles;
137  // vector to prevent double load of textures
138  static std::vector<textureFileStruct> textureFiles;
139  // vector to prevent double load of images
140  static std::vector<imageFileStruct> imageFiles;
141  void getPhysicsFromNode(mars::interfaces::NodeData* node,
142  osg::ref_ptr<osg::Node> completeNode);
143  }; // end of class GuiHelper
144 
145  } // end of namespace graphics
146 } // end of namespace mars
147 
148 #endif // GUI_HELPER_FUCTIONS_H
used to get a geode from a nodegroup
mars::interfaces::NodeData snode
osg::ref_ptr< osg::Node > node
static std::vector< nodeFileStruct > nodeFiles
osg::ref_ptr< osg::MatrixTransform > matrix
osg::ref_ptr< osg::Group > node
terrainStruct is a struct to exchange height maps between the GUI and the simulation ...
Definition: terrainStruct.h:34
NodeData is a struct to exchange node information between the GUI and the simulation.
Definition: NodeData.h:52
osg::ref_ptr< osg::Node > readBobjFromFile(const std::string &filename)
Definition: Terrain.cpp:104
osg::ref_ptr< osg::Image > image
mars::utils::Quaternion r_off
static std::vector< imageFileStruct > imageFiles
osg::Vec4 toOSGVec4(const Color &col)
osg::ref_ptr< osg::PositionAttitudeTransform > transform
Copyright 2012, DFKI GmbH Robotics Innovation Center.
Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vector
Definition: Vector.h:43
Eigen::Quaternion< double, Eigen::DontAlign > Quaternion
Definition: Quaternion.h:56
interfaces::GraphicsManagerInterface * gi
osg::ref_ptr< osg::Texture2D > texture
static std::vector< textureFileStruct > textureFiles
mars::interfaces::GraphicData gs
osg::ref_ptr< osg::Vec3Array > my_v3
internal struct for GraphicManager.h connecting the node indices with the osg nodes ...