Projector.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 #ifndef GAZEBO_RENDERING_PROJECTOR_HH_
18 #define GAZEBO_RENDERING_PROJECTOR_HH_
19 
20 #include <string>
21 #include <map>
22 #include <list>
23 
24 #include <ignition/math/Pose3.hh>
25 #include <sdf/sdf.hh>
26 #include <ignition/transport/Node.hh>
27 
29 
30 #include "gazebo/msgs/msgs.hh"
31 #include "gazebo/transport/transport.hh"
33 #include "gazebo/util/system.hh"
34 
35 namespace gazebo
36 {
37  namespace rendering
38  {
41 
44  class GZ_RENDERING_VISIBLE Projector
45  {
48  public: explicit Projector(VisualPtr _parent);
49 
51  public: virtual ~Projector();
52 
55  public: void Load(sdf::ElementPtr _sdf);
56 
59  public: void Load(const msgs::Projector &_msg);
60 
68  public: void Load(const std::string &_name,
69  const ignition::math::Pose3d &_pose =
70  ignition::math::Pose3d::Zero,
71  const std::string &_textureName = "",
72  const double _nearClip = 0.25,
73  const double _farClip = 15.0,
74  const double _fov = IGN_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 
124  public: void SetPose(const ignition::math::Pose3d &_pose);
125 
126  private: void SetSceneNode();
127 
128  private: void SetFrustumClipDistance(double _near, double _far);
129  private: void SetFrustumFOV(double _fov);
130  private: void AddPassToAllMaterials();
131  private: void AddPassToVisibleMaterials();
132  private: void AddPassToMaterials(std::list<std::string> &_matList);
133  private: void AddPassToMaterial(const std::string &_matName);
134  private: void RemovePassFromMaterials();
135  private: void RemovePassFromMaterial(const std::string &_matName);
136 
137  public: bool enabled;
138  public: bool initialized;
139  private: bool usingShaders;
140 
141  private: std::string nodeName;
142  private: std::string filterNodeName;
143 
144  private: std::string textureName;
145 
146  private: Ogre::Frustum *frustum;
147  private: Ogre::Frustum *filterFrustum;
148  private: Ogre::PlaneBoundedVolumeListSceneQuery *projectorQuery;
149 
150  private: VisualPtr visual;
151 
152  private: Ogre::SceneNode *node;
153  private: Ogre::SceneNode *filterNode;
154  private: Ogre::SceneManager *sceneMgr;
155  private: std::map<std::string, Ogre::Pass*> projectorTargets;
156  };
158 
160  private: ProjectorFrameListener projector;
161 
162  // Place ignition::transport objects at the end of this file to
163  // guarantee they are destructed first.
164 
166  private: ignition::transport::Node nodeIgn;
167  };
169  }
170 }
171 #endif
Forward declarations for the common classes.
Definition: Animation.hh:33
boost::shared_ptr< Subscriber > SubscriberPtr
Definition: TransportTypes.hh:53
Projects a material onto surface, light a light projector.
Definition: Projector.hh:44
boost::shared_ptr< Node > NodePtr
Definition: TransportTypes.hh:57
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:113
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.