KiCad PCB EDA Suite
TRIANGLE_DISPLAY_LIST Class Reference

Store arrays of triangles to be used to create display lists. More...

#include <layer_triangles.h>

Public Member Functions

 TRIANGLE_DISPLAY_LIST (unsigned int aNrReservedTriangles)
 Initialize arrays with reserved triangles. More...
 
 ~TRIANGLE_DISPLAY_LIST ()
 
bool IsLayersSizeValid ()
 Check if the vertex arrays of the layers are as expected. More...
 
void AddToMiddleContourns (const SHAPE_LINE_CHAIN &outlinePath, float zBot, float zTop, double aBiuTo3Du, bool aInvertFaceDirection, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
 
void AddToMiddleContourns (const SHAPE_POLY_SET &aPolySet, float zBot, float zTop, double aBiuTo3Du, bool aInvertFaceDirection, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
 
void AddToMiddleContourns (const std::vector< SFVEC2F > &aContournPoints, float zBot, float zTop, bool aInvertFaceDirection, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
 

Public Attributes

std::mutex m_middle_layer_lock
 
TRIANGLE_LISTm_layer_top_segment_ends
 
TRIANGLE_LISTm_layer_top_triangles
 
TRIANGLE_LISTm_layer_middle_contourns_quads
 
TRIANGLE_LISTm_layer_bot_triangles
 
TRIANGLE_LISTm_layer_bot_segment_ends
 

Detailed Description

Store arrays of triangles to be used to create display lists.

Definition at line 94 of file layer_triangles.h.

Constructor & Destructor Documentation

◆ TRIANGLE_DISPLAY_LIST()

TRIANGLE_DISPLAY_LIST::TRIANGLE_DISPLAY_LIST ( unsigned int  aNrReservedTriangles)
explicit

Initialize arrays with reserved triangles.

Parameters
aNrReservedTrianglesis the number of triangles to reserve.

Definition at line 95 of file layer_triangles.cpp.

96 {
97  wxASSERT( aNrReservedTriangles > 0 );
98 
99  m_layer_top_segment_ends = new TRIANGLE_LIST( aNrReservedTriangles, false );
100  m_layer_top_triangles = new TRIANGLE_LIST( aNrReservedTriangles, false );
101  m_layer_middle_contourns_quads = new TRIANGLE_LIST( aNrReservedTriangles, true );
102  m_layer_bot_triangles = new TRIANGLE_LIST( aNrReservedTriangles, false );
103  m_layer_bot_segment_ends = new TRIANGLE_LIST( aNrReservedTriangles, false );
104 }
Container to manage a vector of triangles.
TRIANGLE_LIST * m_layer_middle_contourns_quads
TRIANGLE_LIST * m_layer_top_triangles
TRIANGLE_LIST * m_layer_bot_triangles
TRIANGLE_LIST * m_layer_bot_segment_ends
TRIANGLE_LIST * m_layer_top_segment_ends

References m_layer_bot_segment_ends, m_layer_bot_triangles, m_layer_middle_contourns_quads, m_layer_top_segment_ends, and m_layer_top_triangles.

◆ ~TRIANGLE_DISPLAY_LIST()

TRIANGLE_DISPLAY_LIST::~TRIANGLE_DISPLAY_LIST ( )

Definition at line 107 of file layer_triangles.cpp.

108 {
110  m_layer_top_segment_ends = nullptr;
111 
112  delete m_layer_top_triangles;
113  m_layer_top_triangles = nullptr;
114 
117 
118  delete m_layer_bot_triangles;
119  m_layer_bot_triangles = nullptr;
120 
122  m_layer_bot_segment_ends = nullptr;
123 }
TRIANGLE_LIST * m_layer_middle_contourns_quads
TRIANGLE_LIST * m_layer_top_triangles
TRIANGLE_LIST * m_layer_bot_triangles
TRIANGLE_LIST * m_layer_bot_segment_ends
TRIANGLE_LIST * m_layer_top_segment_ends

References m_layer_bot_segment_ends, m_layer_bot_triangles, m_layer_middle_contourns_quads, m_layer_top_segment_ends, and m_layer_top_triangles.

Member Function Documentation

◆ AddToMiddleContourns() [1/3]

void TRIANGLE_DISPLAY_LIST::AddToMiddleContourns ( const SHAPE_LINE_CHAIN outlinePath,
float  zBot,
float  zTop,
double  aBiuTo3Du,
bool  aInvertFaceDirection,
const BVH_CONTAINER_2D aThroughHoles = nullptr 
)

Definition at line 219 of file layer_triangles.cpp.

223 {
224  std::vector< SFVEC2F >contournPoints;
225 
226  contournPoints.clear();
227  contournPoints.reserve( outlinePath.PointCount() + 2 );
228 
229  const VECTOR2I& firstV = outlinePath.CPoint( 0 );
230 
231  SFVEC2F lastV = SFVEC2F( firstV.x * aBiuTo3Du, -firstV.y * aBiuTo3Du );
232 
233  contournPoints.push_back( lastV );
234 
235  for( unsigned int i = 1; i < (unsigned int)outlinePath.PointCount(); ++i )
236  {
237  const VECTOR2I& v = outlinePath.CPoint( i );
238 
239  const SFVEC2F vf = SFVEC2F( v.x * aBiuTo3Du, -v.y * aBiuTo3Du );
240 
241  if( vf != lastV ) // Do not add repeated points
242  {
243  lastV = vf;
244  contournPoints.push_back( vf );
245  }
246  }
247 
248  // Add first position fo the list to close the path
249  if( lastV != contournPoints[0] )
250  contournPoints.push_back( contournPoints[0] );
251 
252  AddToMiddleContourns( contournPoints, zBot, zTop, aInvertFaceDirection, aThroughHoles );
253 }
Define a general 2D-vector/point.
Definition: vector2d.h:61
int PointCount() const
Return the number of points (vertices) in this line chain.
const VECTOR2I & CPoint(int aIndex) const
Return a reference to a given point in the line chain.
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
void AddToMiddleContourns(const SHAPE_LINE_CHAIN &outlinePath, float zBot, float zTop, double aBiuTo3Du, bool aInvertFaceDirection, const BVH_CONTAINER_2D *aThroughHoles=nullptr)

References SHAPE_LINE_CHAIN::CPoint(), SHAPE_LINE_CHAIN::PointCount(), VECTOR2< T >::x, and VECTOR2< T >::y.

Referenced by AddToMiddleContourns(), RENDER_3D_OPENGL::createBoard(), RENDER_3D_OPENGL::generateCylinder(), RENDER_3D_OPENGL::generateHoles(), RENDER_3D_OPENGL::generateLayerList(), and RENDER_3D_OPENGL::generateViasAndPads().

◆ AddToMiddleContourns() [2/3]

void TRIANGLE_DISPLAY_LIST::AddToMiddleContourns ( const SHAPE_POLY_SET aPolySet,
float  zBot,
float  zTop,
double  aBiuTo3Du,
bool  aInvertFaceDirection,
const BVH_CONTAINER_2D aThroughHoles = nullptr 
)

Definition at line 256 of file layer_triangles.cpp.

260 {
261  if( aPolySet.OutlineCount() == 0 )
262  return;
263 
264  // Calculate an estimation of points to reserve
265  unsigned int nrContournPointsToReserve = 0;
266 
267  for( int i = 0; i < aPolySet.OutlineCount(); ++i )
268  {
269  const SHAPE_LINE_CHAIN& pathOutline = aPolySet.COutline( i );
270 
271  nrContournPointsToReserve += pathOutline.PointCount();
272 
273  for( int h = 0; h < aPolySet.HoleCount( i ); ++h )
274  {
275  const SHAPE_LINE_CHAIN& hole = aPolySet.CHole( i, h );
276 
277  nrContournPointsToReserve += hole.PointCount();
278  }
279  }
280 
281  // Request to reserve more space
282  m_layer_middle_contourns_quads->Reserve_More( nrContournPointsToReserve * 2, true );
283 
284  for( int i = 0; i < aPolySet.OutlineCount(); i++ )
285  {
286  // Add outline
287  const SHAPE_LINE_CHAIN& pathOutline = aPolySet.COutline( i );
288 
289  AddToMiddleContourns( pathOutline, zBot, zTop, aBiuTo3Du, aInvertFaceDirection,
290  aThroughHoles );
291 
292  // Add holes for this outline
293  for( int h = 0; h < aPolySet.HoleCount( i ); ++h )
294  {
295  const SHAPE_LINE_CHAIN& hole = aPolySet.CHole( i, h );
296  AddToMiddleContourns( hole, zBot, zTop, aBiuTo3Du, aInvertFaceDirection,
297  aThroughHoles );
298  }
299  }
300 }
int OutlineCount() const
Return the number of vertices in a given outline/hole.
TRIANGLE_LIST * m_layer_middle_contourns_quads
void Reserve_More(unsigned int aNrReservedTriangles, bool aReserveNormals)
Reserve more triangles.
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
int PointCount() const
Return the number of points (vertices) in this line chain.
void AddToMiddleContourns(const SHAPE_LINE_CHAIN &outlinePath, float zBot, float zTop, double aBiuTo3Du, bool aInvertFaceDirection, const BVH_CONTAINER_2D *aThroughHoles=nullptr)
int HoleCount(int aOutline) const
Return the reference to aIndex-th outline in the set.
Represent a polyline containing arcs as well as line segments: A chain of connected line and/or arc s...
const SHAPE_LINE_CHAIN & COutline(int aIndex) const

References AddToMiddleContourns(), SHAPE_POLY_SET::CHole(), SHAPE_POLY_SET::COutline(), SHAPE_POLY_SET::HoleCount(), m_layer_middle_contourns_quads, SHAPE_POLY_SET::OutlineCount(), SHAPE_LINE_CHAIN::PointCount(), and TRIANGLE_LIST::Reserve_More().

◆ AddToMiddleContourns() [3/3]

void TRIANGLE_DISPLAY_LIST::AddToMiddleContourns ( const std::vector< SFVEC2F > &  aContournPoints,
float  zBot,
float  zTop,
bool  aInvertFaceDirection,
const BVH_CONTAINER_2D aThroughHoles = nullptr 
)

Definition at line 126 of file layer_triangles.cpp.

129 {
130  if( aContournPoints.size() >= 4 )
131  {
132  // Calculate normals of each segment of the contourn
133  std::vector< SFVEC2F > contournNormals;
134 
135  contournNormals.clear();
136  contournNormals.resize( aContournPoints.size() - 1 );
137 
138  if( aInvertFaceDirection )
139  {
140  for( unsigned int i = 0; i < ( aContournPoints.size() - 1 ); ++i )
141  {
142  const SFVEC2F& v0 = aContournPoints[i + 0];
143  const SFVEC2F& v1 = aContournPoints[i + 1];
144  const SFVEC2F n = glm::normalize( v1 - v0 );
145 
146  contournNormals[i] = SFVEC2F( n.y,-n.x );
147  }
148  }
149  else
150  {
151  for( unsigned int i = 0; i < ( aContournPoints.size() - 1 ); ++i )
152  {
153  const SFVEC2F& v0 = aContournPoints[i + 0];
154  const SFVEC2F& v1 = aContournPoints[i + 1];
155  const SFVEC2F n = glm::normalize( v1 - v0 );
156 
157  contournNormals[i] = SFVEC2F( -n.y, n.x );
158  }
159  }
160 
161 
162  if( aInvertFaceDirection )
163  std::swap( zBot, zTop );
164 
165  const unsigned int nContournsToProcess = ( aContournPoints.size() - 1 );
166 
167  for( unsigned int i = 0; i < nContournsToProcess; ++i )
168  {
169  SFVEC2F lastNormal;
170 
171  if( i > 0 )
172  lastNormal = contournNormals[i - 1];
173  else
174  lastNormal = contournNormals[nContournsToProcess - 1];
175 
176  SFVEC2F n0 = contournNormals[i];
177 
178  // Only interpolate the normal if the angle is closer
179  if( glm::dot( n0, lastNormal ) > 0.5f )
180  n0 = glm::normalize( n0 + lastNormal );
181 
182  SFVEC2F nextNormal;
183 
184  if( i < (nContournsToProcess - 1) )
185  nextNormal = contournNormals[i + 1];
186  else
187  nextNormal = contournNormals[0];
188 
189  SFVEC2F n1 = contournNormals[i];
190 
191  if( glm::dot( n1, nextNormal ) > 0.5f )
192  n1 = glm::normalize( n1 + nextNormal );
193 
194  const SFVEC3F n3d0 = SFVEC3F( n0.x, n0.y, 0.0f );
195  const SFVEC3F n3d1 = SFVEC3F( n1.x, n1.y, 0.0f );
196 
197  const SFVEC2F& v0 = aContournPoints[i + 0];
198  const SFVEC2F& v1 = aContournPoints[i + 1];
199 
200  if( aThroughHoles && aThroughHoles->IntersectAny( RAYSEG2D( v0, v1 ) ) )
201  {
202  continue;
203  }
204  else
205  {
206  std::lock_guard<std::mutex> lock( m_middle_layer_lock );
207  m_layer_middle_contourns_quads->AddQuad( SFVEC3F( v0.x, v0.y, zTop ),
208  SFVEC3F( v1.x, v1.y, zTop ),
209  SFVEC3F( v1.x, v1.y, zBot ),
210  SFVEC3F( v0.x, v0.y, zBot ) );
211 
212  m_layer_middle_contourns_quads->AddNormal( n3d0, n3d1, n3d1, n3d0 );
213  }
214  }
215  }
216 }
bool IntersectAny(const RAYSEG2D &aSegRay) const override
Intersect and check if a segment ray hits a object or is inside it.
std::mutex m_middle_layer_lock
TRIANGLE_LIST * m_layer_middle_contourns_quads
glm::vec2 SFVEC2F
Definition: xv3d_types.h:42
void AddQuad(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3, const SFVEC3F &aV4)
glm::vec3 SFVEC3F
Definition: xv3d_types.h:44
void AddNormal(const SFVEC3F &aN1, const SFVEC3F &aN2, const SFVEC3F &aN3)
Definition: ray.h:105

References TRIANGLE_LIST::AddNormal(), TRIANGLE_LIST::AddQuad(), BVH_CONTAINER_2D::IntersectAny(), m_layer_middle_contourns_quads, and m_middle_layer_lock.

◆ IsLayersSizeValid()

bool TRIANGLE_DISPLAY_LIST::IsLayersSizeValid ( )

Check if the vertex arrays of the layers are as expected.

Returns
true if layers are correctly setup.

Member Data Documentation

◆ m_layer_bot_segment_ends

TRIANGLE_LIST* TRIANGLE_DISPLAY_LIST::m_layer_bot_segment_ends

◆ m_layer_bot_triangles

◆ m_layer_middle_contourns_quads

TRIANGLE_LIST* TRIANGLE_DISPLAY_LIST::m_layer_middle_contourns_quads

◆ m_layer_top_segment_ends

TRIANGLE_LIST* TRIANGLE_DISPLAY_LIST::m_layer_top_segment_ends

◆ m_layer_top_triangles

◆ m_middle_layer_lock

std::mutex TRIANGLE_DISPLAY_LIST::m_middle_layer_lock

Definition at line 126 of file layer_triangles.h.

Referenced by AddToMiddleContourns().


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