33 const float dAng = 2 *
M_PIf / m_slices;
36 std::vector<mrpt::math::TPoint2Df> circle(m_slices);
37 for (
unsigned int i = 0; i < m_slices; i++, a += dAng)
43 const float r0 = m_baseRadius, r1 = m_topRadius;
45 const float wall_tilt = std::atan2(r0 - r1, m_height);
46 const float coswt = std::cos(wall_tilt), sinwt = std::sin(wall_tilt);
49 for (
unsigned int i = 0; i < m_slices; i++)
51 const auto ip = (i + 1) % m_slices;
55 TPoint3Df(r0 * circle[i].x, r0 * circle[i].y, .0f),
56 TPoint3Df(r0 * circle[ip].x, r0 * circle[ip].y, .0f),
57 TPoint3Df(r1 * circle[i].x, r1 * circle[i].y, m_height),
59 TVector3Df(-coswt * circle[i].y, coswt * circle[i].x, sinwt),
60 TVector3Df(-coswt * circle[ip].y, coswt * circle[ip].x, sinwt),
61 TVector3Df(-coswt * circle[i].y, coswt * circle[i].x, sinwt));
65 TPoint3Df(r0 * circle[ip].x, r0 * circle[ip].y, .0f),
66 TPoint3Df(r1 * circle[ip].x, r1 * circle[ip].y, m_height),
67 TPoint3Df(r1 * circle[i].x, r1 * circle[i].y, m_height),
69 TVector3Df(-coswt * circle[ip].y, coswt * circle[ip].x, sinwt),
70 TVector3Df(-coswt * circle[ip].y, coswt * circle[ip].x, sinwt),
71 TVector3Df(-coswt * circle[i].y, coswt * circle[i].x, sinwt));
75 for (
unsigned int i = 0; i < m_slices; i++)
77 const auto ip = (i + 1) % m_slices;
79 TPoint3Df(r0 * circle[i].x, r0 * circle[i].y, .0f),
80 TPoint3Df(r0 * circle[ip].x, r0 * circle[ip].y, .0f),
84 TPoint3Df(r1 * circle[i].x, r1 * circle[i].y, m_height),
85 TPoint3Df(r1 * circle[ip].x, r1 * circle[ip].y, m_height),
90 for (
auto& t : tris) t.setColor(m_color);
96 out[
"baseRadius"] = m_baseRadius;
97 out[
"topRadius"] = m_topRadius;
98 out[
"height"] = m_height;
99 out[
"slices"] = m_slices;
100 out[
"hasBottomBase"] = m_hasBottomBase;
101 out[
"hasTopBase"] = m_hasTopBase;
111 m_baseRadius =
static_cast<float>(in[
"baseRadius"]);
112 m_topRadius =
static_cast<float>(in[
"topRadius"]);
113 m_height =
static_cast<float>(in[
"height"]);
114 m_slices =
static_cast<uint32_t
>(in[
"slices"]);
115 m_hasBottomBase =
static_cast<bool>(in[
"hasBottomBase"]);
116 m_hasTopBase =
static_cast<bool>(in[
"hasTopBase"]);
126 writeToStreamRender(
out);
128 out << m_baseRadius << m_topRadius << m_height << m_slices
129 << m_hasBottomBase << m_hasTopBase;
138 readFromStreamRender(in);
139 in >> m_baseRadius >> m_topRadius >> m_height >> m_slices;
147 in >> m_hasBottomBase >> m_hasTopBase;
155 bool solveEqn(
double a,
double b,
double c,
double& t)
166 double delta =
square(b) - a * c;
168 return (t = -b / a) >= 0;
174 t = (-b - delta) / a;
177 else if (-b + delta > 0)
179 t = (-b + delta) / a;
203 if (!reachesHeight(zz))
return false;
205 return getRadius(zz, r)
216 if (m_hasBottomBase && (tZ0 = -lin.
pBase.
z / lin.
director[2]) > 0)
221 if (nDist <= m_baseRadius)
230 if (tZ0 > 0 && (!fnd || tZ0 < dist))
235 if (nDist <= m_topRadius)
242 if (m_baseRadius == m_topRadius)
250 if ((!fnd || nDist < dist) &&
259 double slope = (m_topRadius - m_baseRadius) / m_height;
264 (m_baseRadius + slope * lin.
pBase.
z) * slope *
269 if ((!fnd || nDist < dist) &&
282 bb_min.x = -std::max(m_baseRadius, m_topRadius);
286 bb_max.x = std::max(m_baseRadius, m_topRadius);
#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.
The base class of 3D objects that can be directly rendered through OpenGL.
TPoint3D pBase
Base point.
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Virtual base class for "schematic archives" (JSON, XML,...)
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
float d2f(const double d)
shortcut for static_cast<float>(double)
This base provides a set of functions for maths stuff.
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
A cylinder or cone whose base lies in the XY plane.
TVector3D director
Director vector.
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...
#define SCHEMA_DESERIALIZE_DATATYPE_VERSION()
For use inside serializeFrom(CSchemeArchiveBase) methods.
return_t square(const num_t x)
Inline function for the square of a number.
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.
double getEpsilon()
Gets the value of the geometric epsilon (default = 1e-5)
void createFromPoseX(const mrpt::math::TPose3D &p, TLine3D &r)
Gets a 3D line corresponding to the X axis in a given pose.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
mrpt::vision::TStereoCalibResults out
void unitarize()
Unitarize director vector.
bool traceRay(const mrpt::poses::CPose3D &o, double &dist) const override
Simulation of ray-trace, given a pose.
bool solveEqn(double a, double b, double c, double &t)
#define ASSERT_ABOVE_(__A, __B)
The namespace for 3D scene representation and rendering.
TPoint3D_< float > TPoint3Df
#define SCHEMA_SERIALIZE_DATATYPE_VERSION(ser_version)
For use inside all serializeTo(CSchemeArchiveBase) methods.
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
3D line, represented by a base point and a director vector.