CameraLensPrivate.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2016 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 #ifndef _GAZEBO_RENDERING_CAMERA_LENS_PRIVATE_HH_
19 #define _GAZEBO_RENDERING_CAMERA_LENS_PRIVATE_HH_
20 
21 #include <map>
22 #include <mutex>
23 #include <string>
24 #include <tuple>
25 #include <utility>
26 #include <vector>
27 
28 #include <ignition/math.hh>
29 #include <ignition/math/Vector3.hh>
30 
31 #include <sdf/sdf.hh>
32 
33 
34 namespace gazebo
35 {
36  namespace rendering
37  {
38  // forward declaration
39  class WideAngleCamera;
40 
43  {
45  public: double c1 = 1.0;
46 
48  public: double c2 = 1.0;
49 
51  public: double c3 = 0.0;
52 
54  public: double f = 1.0;
55 
57  public: double cutOffAngle = IGN_PI*0.5;
58 
60  public: class MapFunctionEnum
61  {
64  public: explicit MapFunctionEnum(const std::string &_str)
65  {
66  for (auto item : variants)
67  {
68  if (std::get<0>(item) == _str)
69  {
70  value = item;
71  return;
72  }
73  }
74 
75  // function provided is not in array
76  throw std::invalid_argument("Unknown function ["+_str+"]");
77  }
78 
83  public: ignition::math::Vector3d AsVector3d() const
84  {
85  return std::get<1>(value);
86  }
87 
90  public: std::string AsString() const
91  {
92  return std::get<0>(value);
93  }
94 
97  public: float Apply(const float _t)
98  {
99  return std::get<2>(value)(_t);
100  }
101 
106  {
107  this->value = _fun.value;
108  return *this;
109  }
110 
113  private: const std::vector<
114  std::tuple<std::string, ignition::math::Vector3d,
115  std::function<float (float)> > > variants = {
116  std::make_tuple("sin",
117  ignition::math::Vector3d::UnitX,
118  std::function<float (float)>(
119  static_cast<float (*)(float)>(&std::sin))),
120  std::make_tuple("tan",
121  ignition::math::Vector3d::UnitY,
122  std::function<float (float)>(
123  static_cast<float (*)(float)>(&std::tan))),
124  std::make_tuple("id",
125  ignition::math::Vector3d::UnitZ,
126  std::function<float (float)>(
127  [](float t) -> float
128  {
129  return t;
130  }))};
131 
133  private: decltype(variants)::value_type value;
134  };
135 
139 
141  public: sdf::ElementPtr sdf;
142 
144  public: std::recursive_mutex dataMutex;
145  };
146  }
147 }
148 
149 #endif
MapFunctionEnum & operator=(const MapFunctionEnum &_fun)
Assignment operator.
Definition: CameraLensPrivate.hh:105
Enumeration of functions that can be casted to some other types.
Definition: CameraLensPrivate.hh:60
MapFunctionEnum(const std::string &_str)
Constructor.
Definition: CameraLensPrivate.hh:64
MapFunctionEnum fun
fun component of the mapping function,
Definition: CameraLensPrivate.hh:138
std::string AsString() const
Cast to std::string.
Definition: CameraLensPrivate.hh:90
std::recursive_mutex dataMutex
Mutex to lock when getting or setting lens data.
Definition: CameraLensPrivate.hh:144
ignition::math::Vector3d AsVector3d() const
Cast to ignition::math::Vector3d, this vector is passed to shader to avoid branching.
Definition: CameraLensPrivate.hh:83
double c3
Angle offset factor.
Definition: CameraLensPrivate.hh:51
double c1
Linear scale factor.
Definition: CameraLensPrivate.hh:45
double f
Linear scale factor, may be adjusted in runtime.
Definition: CameraLensPrivate.hh:54
float Apply(const float _t)
Apply function to float value.
Definition: CameraLensPrivate.hh:97
sdf::ElementPtr sdf
SDF element of the lens.
Definition: CameraLensPrivate.hh:141
double c2
Angle scale factor.
Definition: CameraLensPrivate.hh:48
double cutOffAngle
Visible field of view.
Definition: CameraLensPrivate.hh:57
Private fields of camera lens.
Definition: CameraLensPrivate.hh:42