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 
84 #ifndef _WIN32
85  #pragma GCC diagnostic push
86  #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
87 #endif
88  public: void Load(const std::string &_name,
89  const math::Pose &_pose = math::Pose(0, 0, 0, 0, 0, 0),
90  const std::string &_textureName = "",
91  double _nearClip = 0.25,
92  double _farClip = 15.0,
93  double _fov = IGN_PI * 0.25) GAZEBO_DEPRECATED(8.0);
94 #ifndef _WIN32
95  #pragma GCC diagnostic pop
96 #endif
97 
100  public: void SetTexture(const std::string &_textureName);
101 
103  public: void Toggle();
104 
107  public: VisualPtr GetParent();
108 
111  public: void SetEnabled(bool _enabled);
112 
113  private: void OnMsg(ConstProjectorPtr &_msg);
114 
115  private: VisualPtr visual;
116  private: transport::NodePtr node;
117  private: transport::SubscriberPtr controlSub;
118 
123  private: class ProjectorFrameListener : public Ogre::FrameListener
124  {
126  public: ProjectorFrameListener();
127 
129  public: virtual ~ProjectorFrameListener();
130 
131  public: void Init(VisualPtr _visual,
132  const std::string &_textureName,
133  double _near = 0.5,
134  double _far = 10,
135  double _fov = 0.785398163);
136 
137  public: virtual bool frameStarted(const Ogre::FrameEvent &_evt);
138 
139  public: void SetTexture(const std::string &_textureName);
140 
141  public: void SetEnabled(bool _enabled);
142  public: void SetUsingShaders(bool _usingShaders);
143 
145  public: void SetPose(const math::Pose &_pose) GAZEBO_DEPRECATED(8.0);
146 
149  public: void SetPose(const ignition::math::Pose3d &_pose);
150 
151  private: void SetSceneNode();
152 
153  private: void SetFrustumClipDistance(double _near, double _far);
154  private: void SetFrustumFOV(double _fov);
155  private: void AddPassToAllMaterials();
156  private: void AddPassToVisibleMaterials();
157  private: void AddPassToMaterials(std::list<std::string> &_matList);
158  private: void AddPassToMaterial(const std::string &_matName);
159  private: void RemovePassFromMaterials();
160  private: void RemovePassFromMaterial(const std::string &_matName);
161 
162  public: bool enabled;
163  public: bool initialized;
164  private: bool usingShaders;
165 
166  private: std::string nodeName;
167  private: std::string filterNodeName;
168 
169  private: std::string textureName;
170 
171  private: Ogre::Frustum *frustum;
172  private: Ogre::Frustum *filterFrustum;
173  private: Ogre::PlaneBoundedVolumeListSceneQuery *projectorQuery;
174 
175  private: VisualPtr visual;
176 
177  private: Ogre::SceneNode *node;
178  private: Ogre::SceneNode *filterNode;
179  private: Ogre::SceneManager *sceneMgr;
180  private: std::map<std::string, Ogre::Pass*> projectorTargets;
181  };
183 
185  private: ProjectorFrameListener projector;
186 
187  // Place ignition::transport objects at the end of this file to
188  // guarantee they are destructed first.
189 
191  private: ignition::transport::Node nodeIgn;
192  };
194  }
195 }
196 #endif
Encapsulates a position and rotation in three space.
Definition: Pose.hh:42
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
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:302
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:113
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.