42 std::array<mrpt::math::TPoint3Df, 8> pts;
43 for (
size_t j = 0; j < 2; j++)
45 const float r = j == 0 ? m_min_distance : m_max_distance;
46 for (
size_t i = 0; i < 4; i++) pts[4 * j + i].x = r;
47 pts[4 * j + 0].y = -r * tan(m_fov_horz_left);
48 pts[4 * j + 1].y = -r * tan(m_fov_horz_left);
49 pts[4 * j + 2].y = r * tan(m_fov_horz_right);
50 pts[4 * j + 3].y = r * tan(m_fov_horz_right);
51 pts[4 * j + 0].z = -r * tan(m_fov_vert_down);
52 pts[4 * j + 1].z = r * tan(m_fov_vert_up);
53 pts[4 * j + 2].z = -r * tan(m_fov_vert_down);
54 pts[4 * j + 3].z = r * tan(m_fov_vert_up);
65 const std::array<mrpt::math::TPoint3Df, 8> pts = computeFrustumCorners();
67 const std::array<int, 16> draw_path = {0, 1, 3, 2, 0, 4, 6, 2,
68 3, 7, 6, 4, 5, 7, 5, 1};
71 for (
size_t idx = 0; idx < draw_path.size(); idx++)
73 const unsigned int idx_next = (idx + 1) % draw_path.size();
74 vbd.emplace_back(pts[draw_path[idx]]);
75 vbd.emplace_back(pts[draw_path[idx_next]]);
78 cbd.assign(vbd.size(), m_color);
85 const std::array<mrpt::math::TPoint3Df, 8> pts = computeFrustumCorners();
87 tris.emplace_back(pts[0], pts[2], pts[6]);
88 tris.emplace_back(pts[6], pts[4], pts[0]);
90 tris.emplace_back(pts[2], pts[3], pts[7]);
91 tris.emplace_back(pts[7], pts[6], pts[2]);
93 tris.emplace_back(pts[4], pts[6], pts[7]);
94 tris.emplace_back(pts[7], pts[5], pts[4]);
96 tris.emplace_back(pts[1], pts[5], pts[7]);
97 tris.emplace_back(pts[7], pts[3], pts[1]);
99 tris.emplace_back(pts[1], pts[5], pts[7]);
100 tris.emplace_back(pts[7], pts[3], pts[1]);
102 tris.emplace_back(pts[4], pts[5], pts[1]);
103 tris.emplace_back(pts[1], pts[0], pts[4]);
106 for (
auto& t : tris) t.setColor(m_planes_color);
115 m_planes_color(0xE0, 0x00, 0x00, 0x50)
128 float near_distance,
float far_distance,
float horz_FOV_degrees,
129 float vert_FOV_degrees,
float lineWidth,
bool draw_lines,
bool draw_planes)
130 : m_min_distance(near_distance),
131 m_max_distance(far_distance),
132 m_fov_horz_left(
mrpt::
DEG2RAD(.5f * horz_FOV_degrees)),
133 m_fov_horz_right(
mrpt::
DEG2RAD(.5f * horz_FOV_degrees)),
134 m_fov_vert_down(
mrpt::
DEG2RAD(.5f * vert_FOV_degrees)),
135 m_fov_vert_up(
mrpt::
DEG2RAD(.5f * vert_FOV_degrees)),
136 m_draw_lines(draw_lines),
137 m_draw_planes(draw_planes),
138 m_planes_color(0xE0, 0x00, 0x00, 0x50)
174 [[maybe_unused]]
double& dist)
const 181 const float near_distance,
const float far_distance)
206 const float fov_horz_left_degrees,
const float fov_horz_right_degrees)
217 const float fov_vert_down_degrees,
const float fov_vert_up_degrees)
233 for (
int j = 0; j < 2; j++)
236 for (
int i = 0; i < 4; i++) pts[4 * j + i].x = r;
248 std::numeric_limits<double>::max(), std::numeric_limits<double>::max(),
249 std::numeric_limits<double>::max());
251 -std::numeric_limits<double>::max(),
252 -std::numeric_limits<double>::max(),
253 -std::numeric_limits<double>::max());
void keep_min(T &var, const K test_val)
If the second argument is below the first one, set the first argument to this lower value...
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
void onUpdateBuffers_Triangles() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
#define THROW_EXCEPTION(msg)
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
void notifyChange() const
Call to enable calling renderUpdateBuffers() before the next render() rendering iteration.
void onUpdateBuffers_Wireframe() override
Must be implemented in derived classes to update the geometric entities to be drawn in "m_*_buffer" f...
float m_min_distance
Near and far planes.
void setVertFOV(const float fov_vert_degrees)
Changes vertical FOV (symmetric)
Renderizable generic renderer for objects using the triangles shader.
std::array< mrpt::math::TPoint3Df, 8 > computeFrustumCorners() const
void setLineWidth(float w)
void setHorzFOV(const float fov_horz_degrees)
Changes horizontal FOV (symmetric)
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
mrpt::poses::CPose3D m_pose
6D pose wrt the parent coordinate reference.
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.
Context for calls to render()
std::vector< mrpt::math::TPoint3Df > m_vertex_buffer_data
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
This base provides a set of functions for maths stuff.
void writeToStreamRender(mrpt::serialization::CArchive &out) const
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
constexpr double DEG2RAD(const double x)
Degrees to radians.
CFrustum()
Basic empty constructor.
static constexpr shader_id_t WIREFRAME
TPoint3D_< double > TPoint3D
Lightweight 3D point.
static constexpr shader_id_t TRIANGLES
void keep_max(T &var, const K test_val)
If the second argument is above the first one, set the first argument to this higher value...
std::vector< mrpt::img::TColor > m_color_buffer_data
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Virtual base class for "archives": classes abstracting I/O streams.
std::vector< mrpt::opengl::TTriangle > m_triangles
List of triangles.
mrpt::img::TColor m_planes_color
float m_fov_horz_left
Semi FOVs (in radians)
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
mrpt::vision::TStereoCalibResults out
void setNearFarPlanes(const float near_distance, const float far_distance)
Changes distance of near & far planes.
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
The namespace for 3D scene representation and rendering.
void setVertFOVAsymmetric(const float fov_vert_down_degrees, const float fov_vert_up_degrees)
Changes vertical FOV (asymmetric)
A solid or wireframe frustum in 3D (a rectangular truncated pyramid), with arbitrary (possibly assyme...
void readFromStreamRender(mrpt::serialization::CArchive &in)
void composePoint(double lx, double ly, double lz, double &gx, double &gy, double &gz, mrpt::optional_ref< mrpt::math::CMatrixDouble33 > out_jacobian_df_dpoint=std::nullopt, mrpt::optional_ref< mrpt::math::CMatrixDouble36 > out_jacobian_df_dpose=std::nullopt, mrpt::optional_ref< mrpt::math::CMatrixDouble36 > out_jacobian_df_dse3=std::nullopt, bool use_small_rot_approx=false) const
An alternative, slightly more efficient way of doing with G and L being 3D points and P this 6D pose...
void getBoundingBox(mrpt::math::TPoint3D &bb_min, mrpt::math::TPoint3D &bb_max) const override
Evaluates the bounding box of this object (including possible children) in the coordinate frame of th...
void setHorzFOVAsymmetric(const float fov_horz_left_degrees, const float fov_horz_right_degrees)
Changes horizontal FOV (asymmetric)
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
float m_fov_vert_down
Semi FOVs (in radians)
void render(const RenderContext &rc) const override
Implements the rendering of 3D objects in each class derived from CRenderizable.
void renderUpdateBuffers() const override
Called whenever m_outdatedBuffers is true: used to re-generate OpenGL vertex buffers, etc.