$darkmode
frustum.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Robert Bosch GmbH
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  * SPDX-License-Identifier: Apache-2.0
17  */
22 #pragma once
23 
24 #include <cmath> // for M_PI
25 
26 #include <fable/confable.hpp> // for Confable
27 #include <fable/json.hpp> // for Json
28 #include <fable/schema.hpp> // for Schema, Struct, make_schema
29 
30 #define M_2X_PI (2 * M_PI)
31 
32 namespace cloe {
33 
37 struct Frustum : public fable::Confable {
38  double fov_h{M_2X_PI};
39  double offset_h{0.0};
40  double fov_v{M_2X_PI};
41  double offset_v{0.0};
42  double clip_near{0.0};
43  double clip_far{480.0};
44 
45  void to_json(fable::Json& j) const override {
46  j = fable::Json{
47  {"fov_h", fov_h}, {"offset_h", offset_h}, {"fov_v", fov_v},
48  {"offset_v", offset_v}, {"clip_near", clip_near}, {"clip_far", clip_far},
49  };
50  }
51 
52  void from_conf(const fable::Conf& c) override {
53  assert(clip_near < clip_far);
55  if (clip_near >= clip_far) {
56  c.throw_error("expect frustum near < far clipping plane, got near={} >= far={}", clip_near,
57  clip_far);
58  }
59  }
60 
61  protected:
63  // clang-format off
64  using namespace fable::schema; // NOLINT
65  return Struct{
66  {"fov_h", make_schema(&fov_h, "horizontal field of view [rad]").bounds(0, M_2X_PI)},
67  {"offset_h", make_schema(&offset_h, "horizontal field-of-view offset [rad]").bounds(-M_2X_PI, M_2X_PI)},
68  {"fov_v", make_schema(&fov_v, "vertical field of view [rad]").bounds(0, M_2X_PI)},
69  {"offset_v", make_schema(&offset_v, "vertical field-of-view offset [rad]").bounds(-M_2X_PI, M_2X_PI)},
70  {"clip_near", make_schema(&clip_near, "near clipping plane [m]").minimum(0)},
71  {"clip_far", make_schema(&clip_far, "far clipping plane [m]").minimum(0)},
72  };
73  // clang-format on
74  }
75 
76  CONFABLE_FRIENDS(Frustum)
77 };
78 
79 } // namespace cloe
Definition: conf.hpp:76
Definition: confable.hpp:43
virtual void from_conf(const Conf &c)
Definition: confable.cpp:70
Definition: schema.hpp:175
Definition: struct.hpp:70
nlohmann::json Json
Definition: fable_fwd.hpp:35
Definition: frustum.hpp:37
void from_conf(const fable::Conf &c) override
Definition: frustum.hpp:52
void to_json(fable::Json &j) const override
Definition: frustum.hpp:45
fable::Schema schema_impl() override
Definition: frustum.hpp:62