All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Projector.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 /*
18  * Desc: Projector
19  * Author: Jared Duke, (some maintainence by John Hsu)
20  */
21 
22 #ifndef _PROJECTOR_HH_
23 #define _PROJECTOR_HH_
24 
25 #include <string>
26 #include <map>
27 #include <list>
28 #include <sdf/sdf.hh>
29 
31 
32 #include "gazebo/msgs/msgs.hh"
33 #include "gazebo/transport/transport.hh"
35 
36 namespace gazebo
37 {
38  namespace rendering
39  {
42 
45  class Projector
46  {
49  public: Projector(VisualPtr _parent);
50 
52  public: virtual ~Projector();
53 
56  public: void Load(sdf::ElementPtr _sdf);
57 
60  public: void Load(const msgs::Projector &_msg);
61 
69  public: void Load(const std::string &_name,
70  const math::Pose &_pose = math::Pose(0, 0, 0, 0, 0, 0),
71  const std::string &_textureName = "",
72  double _nearClip = 0.25,
73  double _farClip = 15.0,
74  double _fov = M_PI * 0.25);
75 
78  public: void SetTexture(const std::string &_textureName);
79 
81  public: void Toggle();
82 
85  public: VisualPtr GetParent();
86 
89  public: void SetEnabled(bool _enabled);
90 
91  private: void OnMsg(ConstProjectorPtr &_msg);
92 
93  private: VisualPtr visual;
94  private: transport::NodePtr node;
95  private: transport::SubscriberPtr controlSub;
96 
101  private: class ProjectorFrameListener : public Ogre::FrameListener
102  {
104  public: ProjectorFrameListener();
105 
107  public: virtual ~ProjectorFrameListener();
108 
109  public: void Init(VisualPtr _visual,
110  const std::string &_textureName,
111  double _near = 0.5,
112  double _far = 10,
113  double _fov = 0.785398163);
114 
115  public: virtual bool frameStarted(const Ogre::FrameEvent &_evt);
116 
117  public: void SetTexture(const std::string &_textureName);
118 
119  public: void SetEnabled(bool _enabled);
120  public: void SetUsingShaders(bool _usingShaders);
121 
122  public: void SetPose(const math::Pose &_pose);
123 
124  private: void SetSceneNode();
125 
126  private: void SetFrustumClipDistance(double _near, double _far);
127  private: void SetFrustumFOV(double _fov);
128  private: void AddPassToAllMaterials();
129  private: void AddPassToVisibleMaterials();
130  private: void AddPassToMaterials(std::list<std::string> &_matList);
131  private: void AddPassToMaterial(const std::string &_matName);
132  private: void RemovePassFromMaterials();
133  private: void RemovePassFromMaterial(const std::string &_matName);
134 
135  public: bool enabled;
136  public: bool initialized;
137  private: bool usingShaders;
138 
139  private: std::string nodeName;
140  private: std::string filterNodeName;
141 
142  private: std::string textureName;
143 
144  private: Ogre::Frustum *frustum;
145  private: Ogre::Frustum *filterFrustum;
146  private: Ogre::PlaneBoundedVolumeListSceneQuery *projectorQuery;
147 
148  private: VisualPtr visual;
149 
150  private: Ogre::SceneNode *node;
151  private: Ogre::SceneNode *filterNode;
152  private: Ogre::SceneManager *sceneMgr;
153  private: std::map<std::string, Ogre::Pass*> projectorTargets;
154  };
156 
158  private: ProjectorFrameListener projector;
159  };
161  }
162 }
163 #endif