KiCad PCB EDA Suite
CYLINDER Class Reference

A vertical cylinder. More...

#include <cylinder_3d.h>

Inheritance diagram for CYLINDER:
OBJECT_3D

Public Member Functions

 CYLINDER (SFVEC2F aCenterPoint, float aZmin, float aZmax, float aRadius)
 
void SetColor (SFVEC3F aObjColor)
 
bool Intersect (const RAY &aRay, HITINFO &aHitInfo) const override
 
bool IntersectP (const RAY &aRay, float aMaxDistance) const override
 
bool Intersects (const BBOX_3D &aBBox) const override
 
SFVEC3F GetDiffuseColor (const HITINFO &aHitInfo) const override
 
const void SetBoardItem (BOARD_ITEM *aBoardItem)
 
BOARD_ITEMGetBoardItem () const
 
void SetMaterial (const MATERIAL *aMaterial)
 
const MATERIALGetMaterial () const
 
float GetModelTransparency () const
 
void SetModelTransparency (float aModelTransparency)
 
const BBOX_3DGetBBox () const
 
const SFVEC3FGetCentroid () const
 

Protected Attributes

BBOX_3D m_bbox
 
SFVEC3F m_centroid
 
OBJECT_3D_TYPE m_obj_type
 
const MATERIALm_material
 
BOARD_ITEMm_boardItem
 
float m_modelTransparency
 

Private Attributes

SFVEC2F m_center
 
float m_radius_squared
 
float m_inv_radius
 
SFVEC3F m_diffusecolor
 

Detailed Description

A vertical cylinder.

Definition at line 37 of file cylinder_3d.h.

Constructor & Destructor Documentation

◆ CYLINDER()

CYLINDER::CYLINDER ( SFVEC2F  aCenterPoint,
float  aZmin,
float  aZmax,
float  aRadius 
)
Parameters
aCenterPoint= position of the vertical cylinder axis in the XY plane
aZmin= bottom position (Z axis)
aZmax= top position (Z axis)
aRadius= radius of the cylinder

Definition at line 34 of file cylinder_3d.cpp.

36 {
37  m_center = aCenterPoint;
38  m_radius_squared = aRadius * aRadius;
39  m_inv_radius = 1.0f / aRadius;
40 
41  m_bbox.Set( SFVEC3F( aCenterPoint.x - aRadius, aCenterPoint.y - aRadius, aZmin ),
42  SFVEC3F( aCenterPoint.x + aRadius, aCenterPoint.y + aRadius, aZmax ) );
45 }
float m_radius_squared
Definition: cylinder_3d.h:57
float m_inv_radius
Definition: cylinder_3d.h:58
OBJECT_3D(OBJECT_3D_TYPE aObjType)
Definition: object_3d.cpp:41
SFVEC3F GetCenter() const
Return the center point of the bounding box.
Definition: bbox_3d.cpp:132
BBOX_3D m_bbox
Definition: object_3d.h:97
void Set(const SFVEC3F &aPbMin, const SFVEC3F &aPbMax)
Set bounding box with new parameters.
Definition: bbox_3d.cpp:68
void ScaleNextUp()
Scale a bounding box to the next float representation making it larger.
Definition: bbox_3d.cpp:203
SFVEC3F m_centroid
Definition: object_3d.h:98
SFVEC2F m_center
Definition: cylinder_3d.h:56
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44

References BBOX_3D::GetCenter(), OBJECT_3D::m_bbox, m_center, OBJECT_3D::m_centroid, m_inv_radius, m_radius_squared, BBOX_3D::ScaleNextUp(), and BBOX_3D::Set().

Member Function Documentation

◆ GetBBox()

const BBOX_3D& OBJECT_3D::GetBBox ( ) const
inlineinherited

Definition at line 92 of file object_3d.h.

92 { return m_bbox; }
BBOX_3D m_bbox
Definition: object_3d.h:97

References OBJECT_3D::m_bbox.

Referenced by CONTAINER_3D_BASE::Add(), and BVH_PBRT::Intersect().

◆ GetBoardItem()

BOARD_ITEM* OBJECT_3D::GetBoardItem ( ) const
inlineinherited

Definition at line 56 of file object_3d.h.

56 { return m_boardItem; }
BOARD_ITEM * m_boardItem
Definition: object_3d.h:102

References OBJECT_3D::m_boardItem.

Referenced by RENDER_3D_RAYTRACE::IntersectBoardItem().

◆ GetCentroid()

const SFVEC3F& OBJECT_3D::GetCentroid ( ) const
inlineinherited

Definition at line 94 of file object_3d.h.

94 { return m_centroid; }
SFVEC3F m_centroid
Definition: object_3d.h:98

References OBJECT_3D::m_centroid.

◆ GetDiffuseColor()

SFVEC3F CYLINDER::GetDiffuseColor ( const HITINFO aHitInfo) const
overridevirtual

Implements OBJECT_3D.

Definition at line 170 of file cylinder_3d.cpp.

171 {
172  (void)aHitInfo; // unused
173 
174  return m_diffusecolor;
175 }
SFVEC3F m_diffusecolor
Definition: cylinder_3d.h:59

References m_diffusecolor.

◆ GetMaterial()

const MATERIAL* OBJECT_3D::GetMaterial ( ) const
inlineinherited

Definition at line 64 of file object_3d.h.

64 { return m_material; }
const MATERIAL * m_material
Definition: object_3d.h:100

References OBJECT_3D::m_material.

Referenced by BVH_PBRT::IntersectP(), and RENDER_3D_RAYTRACE::shadeHit().

◆ GetModelTransparency()

float OBJECT_3D::GetModelTransparency ( ) const
inlineinherited

Definition at line 65 of file object_3d.h.

65 { return m_modelTransparency; }
float m_modelTransparency
Definition: object_3d.h:106

References OBJECT_3D::m_modelTransparency.

Referenced by RENDER_3D_RAYTRACE::shadeHit().

◆ Intersect()

bool CYLINDER::Intersect ( const RAY aRay,
HITINFO aHitInfo 
) const
overridevirtual
Returns
true if the aRay intersects the object.

Implements OBJECT_3D.

Definition at line 48 of file cylinder_3d.cpp.

49 {
50  // Based on: http://www.cs.utah.edu/~lha/Code%206620%20/Ray4/Cylinder.cpp
51  // Ray-sphere intersection: geometric
52  const double OCx_Start = aRay.m_Origin.x - m_center.x;
53  const double OCy_Start = aRay.m_Origin.y - m_center.y;
54 
55  const double p_dot_p = OCx_Start * OCx_Start + OCy_Start * OCy_Start;
56 
57  const double a = (double)aRay.m_Dir.x * (double)aRay.m_Dir.x +
58  (double)aRay.m_Dir.y * (double)aRay.m_Dir.y;
59  const double b = (double)aRay.m_Dir.x * (double)OCx_Start +
60  (double)aRay.m_Dir.y * (double)OCy_Start;
61  const double c = p_dot_p - m_radius_squared;
62 
63  const float delta = (float) ( b * b - a * c );
64 
65  bool hitResult = false;
66 
67  if( delta > FLT_EPSILON )
68  {
69  const float inv_a = 1.0 / a;
70 
71  const float sdelta = sqrtf( delta );
72  const float t = (-b - sdelta) * inv_a;
73  const float z = aRay.m_Origin.z + t * aRay.m_Dir.z;
74 
75  if( ( z >= m_bbox.Min().z ) && ( z <= m_bbox.Max().z ) )
76  {
77  if( t < aHitInfo.m_tHit )
78  {
79  hitResult = true;
80  aHitInfo.m_tHit = t;
81  }
82  }
83 
84  if( !hitResult )
85  {
86  const float t1 = (-b + sdelta) * inv_a;
87  const float z1 = aRay.m_Origin.z + t1 * aRay.m_Dir.z;
88 
89  if( ( z1 > m_bbox.Min().z ) && ( z1 < m_bbox.Max().z ) )
90  {
91  if( t1 < aHitInfo.m_tHit )
92  {
93  hitResult = true;
94  aHitInfo.m_tHit = t1;
95  }
96  }
97  }
98  }
99 
100  if( hitResult )
101  {
102  aHitInfo.m_HitPoint = aRay.at( aHitInfo.m_tHit );
103 
104  const SFVEC2F hitPoint2D = SFVEC2F( aHitInfo.m_HitPoint.x, aHitInfo.m_HitPoint.y );
105 
106  aHitInfo.m_HitNormal = SFVEC3F( -( hitPoint2D.x - m_center.x ) * m_inv_radius,
107  -( hitPoint2D.y - m_center.y ) * m_inv_radius, 0.0f );
108 
109  m_material->Generate( aHitInfo.m_HitNormal, aRay, aHitInfo );
110 
111  aHitInfo.pHitObject = this;
112  }
113 
114  return hitResult;
115 }
float m_radius_squared
Definition: cylinder_3d.h:57
const SFVEC3F & Max() const
Return the maximum vertex pointer.
Definition: bbox_3d.h:198
void Generate(SFVEC3F &aNormal, const RAY &aRay, const HITINFO &aHitInfo) const
Definition: material.cpp:93
float m_inv_radius
Definition: cylinder_3d.h:58
float m_tHit
( 4) distance
Definition: hitinfo.h:43
SFVEC3F at(float t) const
Definition: ray.h:89
const SFVEC3F & Min() const
Return the minimum vertex pointer.
Definition: bbox_3d.h:191
SFVEC3F m_HitPoint
(12) hit position
Definition: hitinfo.h:49
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
BBOX_3D m_bbox
Definition: object_3d.h:97
const MATERIAL * m_material
Definition: object_3d.h:100
const OBJECT_3D * pHitObject
( 4) Object that was hitted
Definition: hitinfo.h:45
SFVEC3F m_Dir
Definition: ray.h:72
SFVEC3F m_Origin
Definition: ray.h:69
SFVEC2F m_center
Definition: cylinder_3d.h:56
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
SFVEC3F m_HitNormal
(12) normal at the hit point
Definition: hitinfo.h:42

References RAY::at(), MATERIAL::Generate(), OBJECT_3D::m_bbox, m_center, RAY::m_Dir, HITINFO::m_HitNormal, HITINFO::m_HitPoint, m_inv_radius, OBJECT_3D::m_material, RAY::m_Origin, m_radius_squared, HITINFO::m_tHit, BBOX_3D::Max(), BBOX_3D::Min(), and HITINFO::pHitObject.

◆ IntersectP()

bool CYLINDER::IntersectP ( const RAY aRay,
float  aMaxDistance 
) const
overridevirtual
Parameters
aMaxDistanceis the maximum distance of the test.
Returns
true if aRay intersects the object.

Implements OBJECT_3D.

Definition at line 118 of file cylinder_3d.cpp.

119 {
120  // Based on: http://www.cs.utah.edu/~lha/Code%206620%20/Ray4/Cylinder.cpp
121  // Ray-sphere intersection: geometric
122  const double OCx_Start = aRay.m_Origin.x - m_center.x;
123  const double OCy_Start = aRay.m_Origin.y - m_center.y;
124 
125  const double p_dot_p = OCx_Start * OCx_Start + OCy_Start * OCy_Start;
126 
127  const double a = (double)aRay.m_Dir.x * (double)aRay.m_Dir.x +
128  (double)aRay.m_Dir.y * (double)aRay.m_Dir.y;
129  const double b = (double)aRay.m_Dir.x * (double)OCx_Start +
130  (double)aRay.m_Dir.y * (double)OCy_Start;
131  const double c = p_dot_p - m_radius_squared;
132 
133  const float delta = (float) ( b * b - a * c );
134 
135  if( delta > FLT_EPSILON )
136  {
137  const float inv_a = 1.0 / a;
138 
139  const float sdelta = sqrtf( delta );
140  const float t = ( -b - sdelta ) * inv_a;
141  const float z = aRay.m_Origin.z + t * aRay.m_Dir.z;
142 
143  if( ( z >= m_bbox.Min().z ) && ( z <= m_bbox.Max().z ) )
144  {
145  if( t < aMaxDistance )
146  return true;
147  }
148 
149  const float t1 = ( -b + sdelta ) * inv_a;
150  const float z1 = aRay.m_Origin.z + t1 * aRay.m_Dir.z;
151 
152  if( ( z1 > m_bbox.Min().z ) && ( z1 < m_bbox.Max().z ) )
153  {
154  if( t1 < aMaxDistance )
155  return true;
156  }
157  }
158 
159  return false;
160 }
float m_radius_squared
Definition: cylinder_3d.h:57
const SFVEC3F & Max() const
Return the maximum vertex pointer.
Definition: bbox_3d.h:198
const SFVEC3F & Min() const
Return the minimum vertex pointer.
Definition: bbox_3d.h:191
BBOX_3D m_bbox
Definition: object_3d.h:97
SFVEC3F m_Dir
Definition: ray.h:72
SFVEC3F m_Origin
Definition: ray.h:69
SFVEC2F m_center
Definition: cylinder_3d.h:56

References OBJECT_3D::m_bbox, m_center, RAY::m_Dir, RAY::m_Origin, m_radius_squared, BBOX_3D::Max(), and BBOX_3D::Min().

◆ Intersects()

bool CYLINDER::Intersects ( const BBOX_3D aBBox) const
overridevirtual
Returns
true if this object intersects aBBox.

Implements OBJECT_3D.

Definition at line 163 of file cylinder_3d.cpp.

164 {
165  // !TODO: improve
166  return m_bbox.Intersects( aBBox );
167 }
BBOX_3D m_bbox
Definition: object_3d.h:97
bool Intersects(const BBOX_3D &aBBox) const
Test if a bounding box intersects this box.
Definition: bbox_3d.cpp:227

References BBOX_3D::Intersects(), and OBJECT_3D::m_bbox.

◆ SetBoardItem()

const void OBJECT_3D::SetBoardItem ( BOARD_ITEM aBoardItem)
inlineinherited

Definition at line 55 of file object_3d.h.

55 { m_boardItem = aBoardItem; }
BOARD_ITEM * m_boardItem
Definition: object_3d.h:102

References OBJECT_3D::m_boardItem.

Referenced by RENDER_3D_RAYTRACE::addModels().

◆ SetColor()

void CYLINDER::SetColor ( SFVEC3F  aObjColor)
inline

Definition at line 48 of file cylinder_3d.h.

48 { m_diffusecolor = aObjColor; }
SFVEC3F m_diffusecolor
Definition: cylinder_3d.h:59

References m_diffusecolor.

Referenced by RENDER_3D_RAYTRACE::Reload().

◆ SetMaterial()

void OBJECT_3D::SetMaterial ( const MATERIAL aMaterial)
inlineinherited

Definition at line 58 of file object_3d.h.

59  {
60  m_material = aMaterial;
61  m_modelTransparency = aMaterial->GetTransparency(); // Default transparency is from material
62  }
float GetTransparency() const
Definition: material.h:277
float m_modelTransparency
Definition: object_3d.h:106
const MATERIAL * m_material
Definition: object_3d.h:100

References MATERIAL::GetTransparency(), OBJECT_3D::m_material, and OBJECT_3D::m_modelTransparency.

Referenced by RENDER_3D_RAYTRACE::addModels(), RENDER_3D_RAYTRACE::createItemsFromContainer(), RENDER_3D_RAYTRACE::createObject(), RENDER_3D_RAYTRACE::insertHole(), and RENDER_3D_RAYTRACE::Reload().

◆ SetModelTransparency()

void OBJECT_3D::SetModelTransparency ( float  aModelTransparency)
inlineinherited

Definition at line 66 of file object_3d.h.

67  {
68  m_modelTransparency = aModelTransparency;
69  }
float m_modelTransparency
Definition: object_3d.h:106

References OBJECT_3D::m_modelTransparency.

Referenced by RENDER_3D_RAYTRACE::addModels().

Member Data Documentation

◆ m_bbox

◆ m_boardItem

BOARD_ITEM* OBJECT_3D::m_boardItem
protectedinherited

◆ m_center

SFVEC2F CYLINDER::m_center
private

Definition at line 56 of file cylinder_3d.h.

Referenced by CYLINDER(), Intersect(), and IntersectP().

◆ m_centroid

◆ m_diffusecolor

SFVEC3F CYLINDER::m_diffusecolor
private

Definition at line 59 of file cylinder_3d.h.

Referenced by GetDiffuseColor(), and SetColor().

◆ m_inv_radius

float CYLINDER::m_inv_radius
private

Definition at line 58 of file cylinder_3d.h.

Referenced by CYLINDER(), and Intersect().

◆ m_material

◆ m_modelTransparency

float OBJECT_3D::m_modelTransparency
protectedinherited

◆ m_obj_type

OBJECT_3D_TYPE OBJECT_3D::m_obj_type
protectedinherited

Definition at line 99 of file object_3d.h.

Referenced by OBJECT_3D::OBJECT_3D().

◆ m_radius_squared

float CYLINDER::m_radius_squared
private

Definition at line 57 of file cylinder_3d.h.

Referenced by CYLINDER(), Intersect(), and IntersectP().


The documentation for this class was generated from the following files: