Gazebo Math

API Reference

6.15.1
gz/math/AdditivelySeparableScalarField3.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2022 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 GZ_MATH_SEPARABLE_SCALAR_FIELD3_HH_
18 #define GZ_MATH_SEPARABLE_SCALAR_FIELD3_HH_
19 
20 #include <limits>
21 #include <utility>
22 
23 #include <gz/math/Region3.hh>
24 #include <gz/math/Vector3.hh>
25 #include <gz/math/config.hh>
26 
27 namespace ignition
28 {
29  namespace math
30  {
31  // Inline bracket to help doxygen filtering.
32  inline namespace IGNITION_MATH_VERSION_NAMESPACE {
33  //
38  template<typename ScalarFunctionT, typename ScalarT>
62  {
69  ScalarT _k, ScalarFunctionT _p,
70  ScalarFunctionT _q, ScalarFunctionT _r)
71  : k(_k), p(std::move(_p)), q(std::move(_q)), r(std::move(_r))
72  {
73  }
74 
78  public: ScalarT Evaluate(const Vector3<ScalarT> &_point) const
79  {
80  return this->k * (
81  this->p(_point.X()) +
82  this->q(_point.Y()) +
83  this->r(_point.Z()));
84  }
85 
90  public: ScalarT operator()(const Vector3<ScalarT> &_point) const
91  {
92  return this->Evaluate(_point);
93  }
94 
101  public: ScalarT Minimum(const Region3<ScalarT> &_region,
102  Vector3<ScalarT> &_pMin) const
103  {
104  if (_region.Empty())
105  {
106  _pMin = Vector3<ScalarT>::NaN;
108  }
109  return this->k * (
110  this->p.Minimum(_region.Ix(), _pMin.X()) +
111  this->q.Minimum(_region.Iy(), _pMin.Y()) +
112  this->r.Minimum(_region.Iz(), _pMin.Z()));
113  }
114 
119  public: ScalarT Minimum(const Region3<ScalarT> &_region) const
120  {
121  Vector3<ScalarT> pMin;
122  return this->Minimum(_region, pMin);
123  }
124 
129  public: ScalarT Minimum(Vector3<ScalarT> &_pMin) const
130  {
131  return this->Minimum(Region3<ScalarT>::Unbounded, _pMin);
132  }
133 
136  public: ScalarT Minimum() const
137  {
138  Vector3<ScalarT> pMin;
139  return this->Minimum(Region3<ScalarT>::Unbounded, pMin);
140  }
141 
146  public: friend std::ostream &operator<<(
147  std::ostream &_out,
148  const gz::math::AdditivelySeparableScalarField3<
149  ScalarFunctionT, ScalarT> &_field)
150  {
151  using std::abs; // enable ADL
152  constexpr ScalarT epsilon =
154  if ((abs(_field.k) - ScalarT(1)) < epsilon)
155  {
156  if (_field.k < ScalarT(0))
157  {
158  _out << "-";
159  }
160  }
161  else
162  {
163  _out << _field.k << " ";
164  }
165  _out << "[(";
166  _field.p.Print(_out, "x");
167  _out << ") + (";
168  _field.q.Print(_out, "y");
169  _out << ") + (";
170  _field.r.Print(_out, "z");
171  return _out << ")]";
172  }
173 
175  private: ScalarT k;
176 
178  private: ScalarFunctionT p;
179 
181  private: ScalarFunctionT q;
182 
184  private: ScalarFunctionT r;
185  };
186 
187  template<typename ScalarFunctionT>
190 
191  template<typename ScalarFunctionT>
194  }
195  }
196 }
197 #endif
const Interval< T > & Iy() const
Get the y-axis interval for the region.
Definition: gz/math/Region3.hh:111
AdditivelySeparableScalarField3< ScalarFunctionT, float > AdditivelySeparableScalarField3f
Definition: gz/math/AdditivelySeparableScalarField3.hh:189
Definition: gz/math/AdditivelySeparableScalarField3.hh:27
ScalarT Minimum(Vector3< ScalarT > &_pMin) const
Compute scalar field minimum.
Definition: gz/math/AdditivelySeparableScalarField3.hh:129
AdditivelySeparableScalarField3(ScalarT _k, ScalarFunctionT _p, ScalarFunctionT _q, ScalarFunctionT _r)
Constructor.
Definition: gz/math/AdditivelySeparableScalarField3.hh:68
T quiet_NaN(T... args)
T X() const
Get the x value.
Definition: gz/math/Vector3.hh:654
friend std::ostream & operator<<(std::ostream &_out, const AdditivelySeparableScalarField3< ScalarFunctionT, ScalarT > &_field)
Stream insertion operator.
Definition: gz/math/AdditivelySeparableScalarField3.hh:146
ScalarT Minimum() const
Compute scalar field minimum.
Definition: gz/math/AdditivelySeparableScalarField3.hh:136
ScalarT Evaluate(const Vector3< ScalarT > &_point) const
Evaluate the scalar field at _point
Definition: gz/math/AdditivelySeparableScalarField3.hh:78
const Interval< T > & Ix() const
Get the x-axis interval for the region.
Definition: gz/math/Region3.hh:107
T Z() const
Get the z value.
Definition: gz/math/Vector3.hh:668
ScalarT Minimum(const Region3< ScalarT > &_region) const
Compute scalar field minimum in a _region
Definition: gz/math/AdditivelySeparableScalarField3.hh:119
STL class.
The Vector3 class represents the generic vector containing 3 elements. Since it's commonly used to ke...
Definition: gz/math/Vector3.hh:41
The AdditivelySeparableScalarField3 class constructs a scalar field F in R^3 as a sum of scalar funct...
Definition: gz/math/AdditivelySeparableScalarField3.hh:61
T epsilon(T... args)
const Interval< T > & Iz() const
Get the z-axis interval for the region.
Definition: gz/math/Region3.hh:115
STL namespace.
bool Empty() const
Check if the region is empty A region is empty if any of the intervals it is defined with (i....
Definition: gz/math/Region3.hh:121
ScalarT operator()(const Vector3< ScalarT > &_point) const
Call operator overload.
Definition: gz/math/AdditivelySeparableScalarField3.hh:90
ScalarT Minimum(const Region3< ScalarT > &_region, Vector3< ScalarT > &_pMin) const
Compute scalar field minimum in a _region
Definition: gz/math/AdditivelySeparableScalarField3.hh:101
T Y() const
Get the y value.
Definition: gz/math/Vector3.hh:661