Gazebo Math

API Reference

7.4.0
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
27namespace gz
28{
29 namespace math
30 {
31 // Inline bracket to help doxygen filtering.
32 inline namespace GZ_MATH_VERSION_NAMESPACE {
33 //
38
60 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,
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