Projector.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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 #include "gazebo/util/system.hh"
36 
37 namespace gazebo
38 {
39  namespace rendering
40  {
43 
47  {
50  public: Projector(VisualPtr _parent);
51 
53  public: virtual ~Projector();
54 
57  public: void Load(sdf::ElementPtr _sdf);
58 
61  public: void Load(const msgs::Projector &_msg);
62 
70  public: void Load(const std::string &_name,
71  const math::Pose &_pose = math::Pose(0, 0, 0, 0, 0, 0),
72  const std::string &_textureName = "",
73  double _nearClip = 0.25,
74  double _farClip = 15.0,
75  double _fov = M_PI * 0.25);
76 
79  public: void SetTexture(const std::string &_textureName);
80 
82  public: void Toggle();
83 
86  public: VisualPtr GetParent();
87 
90  public: void SetEnabled(bool _enabled);
91 
92  private: void OnMsg(ConstProjectorPtr &_msg);
93 
94  private: VisualPtr visual;
95  private: transport::NodePtr node;
96  private: transport::SubscriberPtr controlSub;
97 
102  private: class ProjectorFrameListener : public Ogre::FrameListener
103  {
105  public: ProjectorFrameListener();
106 
108  public: virtual ~ProjectorFrameListener();
109 
110  public: void Init(VisualPtr _visual,
111  const std::string &_textureName,
112  double _near = 0.5,
113  double _far = 10,
114  double _fov = 0.785398163);
115 
116  public: virtual bool frameStarted(const Ogre::FrameEvent &_evt);
117 
118  public: void SetTexture(const std::string &_textureName);
119 
120  public: void SetEnabled(bool _enabled);
121  public: void SetUsingShaders(bool _usingShaders);
122 
123  public: void SetPose(const math::Pose &_pose);
124 
125  private: void SetSceneNode();
126 
127  private: void SetFrustumClipDistance(double _near, double _far);
128  private: void SetFrustumFOV(double _fov);
129  private: void AddPassToAllMaterials();
130  private: void AddPassToVisibleMaterials();
131  private: void AddPassToMaterials(std::list<std::string> &_matList);
132  private: void AddPassToMaterial(const std::string &_matName);
133  private: void RemovePassFromMaterials();
134  private: void RemovePassFromMaterial(const std::string &_matName);
135 
136  public: bool enabled;
137  public: bool initialized;
138  private: bool usingShaders;
139 
140  private: std::string nodeName;
141  private: std::string filterNodeName;
142 
143  private: std::string textureName;
144 
145  private: Ogre::Frustum *frustum;
146  private: Ogre::Frustum *filterFrustum;
147  private: Ogre::PlaneBoundedVolumeListSceneQuery *projectorQuery;
148 
149  private: VisualPtr visual;
150 
151  private: Ogre::SceneNode *node;
152  private: Ogre::SceneNode *filterNode;
153  private: Ogre::SceneManager *sceneMgr;
154  private: std::map<std::string, Ogre::Pass*> projectorTargets;
155  };
157 
159  private: ProjectorFrameListener projector;
160  };
162  }
163 }
164 #endif
Encapsulates a position and rotation in three space.
Definition: Pose.hh:40
bool frameStarted(const Ogre::FrameEvent &evt)
Frame started.
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
Projects a material onto surface, light a light projector.
Definition: Projector.hh:46
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:102
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48