KiCad PCB EDA Suite
CLAYER_TRIANGLES Class Reference

The CLAYER_TRIANGLES class stores arrays of triangles to be used to create display lists. More...

#include <clayer_triangles.h>

Public Member Functions

 CLAYER_TRIANGLES (unsigned int aNrReservedTriangles)
 CLAYER_TRIANGLES - initialize arrays with reserved triangles. More...
 
 ~CLAYER_TRIANGLES ()
 ~CLAYER_TRIANGLES - Free containers More...
 
bool IsLayersSizeValid ()
 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 CBVHCONTAINER2D *aThroughHoles=nullptr)
 
void AddToMiddleContourns (const SHAPE_POLY_SET &aPolySet, float zBot, float zTop, double aBiuTo3Du, bool aInvertFaceDirection, const CBVHCONTAINER2D *aThroughHoles=nullptr)
 
void AddToMiddleContourns (const std::vector< SFVEC2F > &aContournPoints, float zBot, float zTop, bool aInvertFaceDirection, const CBVHCONTAINER2D *aThroughHoles=nullptr)
 

Public Attributes

std::mutex m_middle_layer_lock
 
CLAYER_TRIANGLE_CONTAINERm_layer_top_segment_ends
 
CLAYER_TRIANGLE_CONTAINERm_layer_top_triangles
 
CLAYER_TRIANGLE_CONTAINERm_layer_middle_contourns_quads
 
CLAYER_TRIANGLE_CONTAINERm_layer_bot_triangles
 
CLAYER_TRIANGLE_CONTAINERm_layer_bot_segment_ends
 

Detailed Description

The CLAYER_TRIANGLES class stores arrays of triangles to be used to create display lists.

Definition at line 140 of file clayer_triangles.h.

Constructor & Destructor Documentation

◆ CLAYER_TRIANGLES()

CLAYER_TRIANGLES::CLAYER_TRIANGLES ( unsigned int  aNrReservedTriangles)
explicit

CLAYER_TRIANGLES - initialize arrays with reserved triangles.

Parameters
aNrReservedTrianglesnumber of pre alloc triangles to reserve

Definition at line 112 of file clayer_triangles.cpp.

113 {
114  wxASSERT( aNrReservedTriangles > 0 );
115 
116  m_layer_top_segment_ends = new CLAYER_TRIANGLE_CONTAINER( aNrReservedTriangles,
117  false );
118  m_layer_top_triangles = new CLAYER_TRIANGLE_CONTAINER( aNrReservedTriangles,
119  false );
120  m_layer_middle_contourns_quads = new CLAYER_TRIANGLE_CONTAINER( aNrReservedTriangles,
121  true );
122  m_layer_bot_triangles = new CLAYER_TRIANGLE_CONTAINER( aNrReservedTriangles,
123  false );
124  m_layer_bot_segment_ends = new CLAYER_TRIANGLE_CONTAINER( aNrReservedTriangles,
125  false );
126 }
The CLAYER_TRIANGLE_CONTAINER class stores an manage vector of triangles.
CLAYER_TRIANGLE_CONTAINER * m_layer_top_triangles
CLAYER_TRIANGLE_CONTAINER * m_layer_middle_contourns_quads
CLAYER_TRIANGLE_CONTAINER * m_layer_bot_segment_ends
CLAYER_TRIANGLE_CONTAINER * m_layer_bot_triangles
CLAYER_TRIANGLE_CONTAINER * 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.

◆ ~CLAYER_TRIANGLES()

CLAYER_TRIANGLES::~CLAYER_TRIANGLES ( )

~CLAYER_TRIANGLES - Free containers

Definition at line 129 of file clayer_triangles.cpp.

130 {
133 
134  delete m_layer_top_triangles;
136 
139 
140  delete m_layer_bot_triangles;
142 
145 }
CLAYER_TRIANGLE_CONTAINER * m_layer_top_triangles
CLAYER_TRIANGLE_CONTAINER * m_layer_middle_contourns_quads
CLAYER_TRIANGLE_CONTAINER * m_layer_bot_segment_ends
CLAYER_TRIANGLE_CONTAINER * m_layer_bot_triangles
CLAYER_TRIANGLE_CONTAINER * 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 CLAYER_TRIANGLES::AddToMiddleContourns ( const SHAPE_LINE_CHAIN outlinePath,
float  zBot,
float  zTop,
double  aBiuTo3Du,
bool  aInvertFaceDirection,
const CBVHCONTAINER2D aThroughHoles = nullptr 
)

Definition at line 241 of file clayer_triangles.cpp.

247 {
248  std::vector< SFVEC2F >contournPoints;
249 
250  contournPoints.clear();
251  contournPoints.reserve( outlinePath.PointCount() + 2 );
252 
253  const VECTOR2I &firstV = outlinePath.CPoint( 0 );
254 
255  SFVEC2F lastV = SFVEC2F( firstV.x * aBiuTo3Du,
256  -firstV.y * aBiuTo3Du );
257 
258  contournPoints.push_back( lastV );
259 
260  for( unsigned int i = 1; i < (unsigned int)outlinePath.PointCount(); ++i )
261  {
262  const VECTOR2I & v = outlinePath.CPoint( i );
263 
264  const SFVEC2F vf = SFVEC2F( v.x * aBiuTo3Du,
265  -v.y * aBiuTo3Du );
266 
267  if( vf != lastV ) // Do not add repeated points
268  {
269  lastV = vf;
270  contournPoints.push_back( vf );
271  }
272  }
273 
274  // Add first position fo the list to close the path
275  if( lastV != contournPoints[0] )
276  contournPoints.push_back( contournPoints[0] );
277 
278  AddToMiddleContourns( contournPoints, zBot, zTop, aInvertFaceDirection, aThroughHoles );
279 }
void AddToMiddleContourns(const SHAPE_LINE_CHAIN &outlinePath, float zBot, float zTop, double aBiuTo3Du, bool aInvertFaceDirection, const CBVHCONTAINER2D *aThroughHoles=nullptr)
int PointCount() const
Function PointCount()
const VECTOR2I & CPoint(int aIndex) const
Function Point()
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45

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

Referenced by AddToMiddleContourns(), C3D_RENDER_OGL_LEGACY::createBoard(), C3D_RENDER_OGL_LEGACY::generate_3D_Vias_and_Pads(), C3D_RENDER_OGL_LEGACY::generate_cylinder(), C3D_RENDER_OGL_LEGACY::generate_holes_display_list(), and C3D_RENDER_OGL_LEGACY::generateLayerListFromContainer().

◆ AddToMiddleContourns() [2/3]

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

Definition at line 282 of file clayer_triangles.cpp.

288 {
289  if( aPolySet.OutlineCount() == 0 )
290  return;
291 
292  // Calculate an estimation of points to reserve
293  unsigned int nrContournPointsToReserve = 0;
294 
295  for( int i = 0; i < aPolySet.OutlineCount(); ++i )
296  {
297  const SHAPE_LINE_CHAIN& pathOutline = aPolySet.COutline( i );
298 
299  nrContournPointsToReserve += pathOutline.PointCount();
300 
301  for( int h = 0; h < aPolySet.HoleCount( i ); ++h )
302  {
303  const SHAPE_LINE_CHAIN &hole = aPolySet.CHole( i, h );
304 
305  nrContournPointsToReserve += hole.PointCount();
306  }
307  }
308 
309  // Request to reserve more space
310  m_layer_middle_contourns_quads->Reserve_More( nrContournPointsToReserve * 2,
311  true );
312 
313  for( int i = 0; i < aPolySet.OutlineCount(); i++ )
314  {
315  // Add outline
316  const SHAPE_LINE_CHAIN& pathOutline = aPolySet.COutline( i );
317 
318  AddToMiddleContourns( pathOutline, zBot, zTop, aBiuTo3Du, aInvertFaceDirection, aThroughHoles );
319 
320  // Add holes for this outline
321  for( int h = 0; h < aPolySet.HoleCount( i ); ++h )
322  {
323  const SHAPE_LINE_CHAIN &hole = aPolySet.CHole( i, h );
324  AddToMiddleContourns( hole, zBot, zTop, aBiuTo3Du, aInvertFaceDirection, aThroughHoles );
325  }
326  }
327 }
int OutlineCount() const
Returns the number of outlines in the set
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
void AddToMiddleContourns(const SHAPE_LINE_CHAIN &outlinePath, float zBot, float zTop, double aBiuTo3Du, bool aInvertFaceDirection, const CBVHCONTAINER2D *aThroughHoles=nullptr)
int PointCount() const
Function PointCount()
CLAYER_TRIANGLE_CONTAINER * m_layer_middle_contourns_quads
int HoleCount(int aOutline) const
Returns the number of holes in a given outline
void Reserve_More(unsigned int aNrReservedTriangles, bool aReserveNormals)
Reserve_More - reserve more triangles.
SHAPE_LINE_CHAIN.
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 CLAYER_TRIANGLE_CONTAINER::Reserve_More().

◆ AddToMiddleContourns() [3/3]

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

Definition at line 148 of file clayer_triangles.cpp.

153 {
154  if( aContournPoints.size() >= 4 )
155  {
156  // Calculate normals of each segment of the contourn
157  std::vector< SFVEC2F > contournNormals;
158 
159  contournNormals.clear();
160  contournNormals.resize( aContournPoints.size() - 1 );
161 
162  if( aInvertFaceDirection )
163  {
164  for( unsigned int i = 0; i < ( aContournPoints.size() - 1 ); ++i )
165  {
166  const SFVEC2F &v0 = aContournPoints[i + 0];
167  const SFVEC2F &v1 = aContournPoints[i + 1];
168  const SFVEC2F n = glm::normalize( v1 - v0 );
169 
170  contournNormals[i] = SFVEC2F( n.y,-n.x );
171  }
172  }
173  else
174  {
175  for( unsigned int i = 0; i < ( aContournPoints.size() - 1 ); ++i )
176  {
177  const SFVEC2F &v0 = aContournPoints[i + 0];
178  const SFVEC2F &v1 = aContournPoints[i + 1];
179  const SFVEC2F n = glm::normalize( v1 - v0 );
180 
181  contournNormals[i] = SFVEC2F( -n.y, n.x );
182  }
183  }
184 
185 
186  if( aInvertFaceDirection )
187  std::swap( zBot, zTop );
188 
189  const unsigned int nContournsToProcess = ( aContournPoints.size() - 1 );
190 
191  for( unsigned int i = 0; i < nContournsToProcess; ++i )
192  {
193  SFVEC2F lastNormal;
194 
195  if( i > 0 )
196  lastNormal = contournNormals[i - 1];
197  else
198  lastNormal = contournNormals[nContournsToProcess - 1];
199 
200  SFVEC2F n0 = contournNormals[i];
201 
202  // Only interpolate the normal if the angle is closer
203  if( glm::dot( n0, lastNormal ) > 0.5f )
204  n0 = glm::normalize( n0 + lastNormal );
205 
206  SFVEC2F nextNormal;
207 
208  if( i < (nContournsToProcess - 1) )
209  nextNormal = contournNormals[i + 1];
210  else
211  nextNormal = contournNormals[0];
212 
213  SFVEC2F n1 = contournNormals[i];
214 
215  if( glm::dot( n1, nextNormal ) > 0.5f )
216  n1 = glm::normalize( n1 + nextNormal );
217 
218  const SFVEC3F n3d0 = SFVEC3F( n0.x, n0.y, 0.0f );
219  const SFVEC3F n3d1 = SFVEC3F( n1.x, n1.y, 0.0f );
220 
221  const SFVEC2F &v0 = aContournPoints[i + 0];
222  const SFVEC2F &v1 = aContournPoints[i + 1];
223 
224  if( aThroughHoles && aThroughHoles->IntersectAny( RAYSEG2D( v0, v1 ) ) )
225  continue;
226  else
227  {
228  std::lock_guard<std::mutex> lock( m_middle_layer_lock );
229  m_layer_middle_contourns_quads->AddQuad( SFVEC3F( v0.x, v0.y, zTop ),
230  SFVEC3F( v1.x, v1.y, zTop ),
231  SFVEC3F( v1.x, v1.y, zBot ),
232  SFVEC3F( v0.x, v0.y, zBot ) );
233 
234  m_layer_middle_contourns_quads->AddNormal( n3d0, n3d1, n3d1, n3d0 );
235  }
236  }
237  }
238 }
bool IntersectAny(const RAYSEG2D &aSegRay) const override
IntersectAny - Intersect and check if a segment ray hits a object or is inside it.
std::mutex m_middle_layer_lock
glm::vec2 SFVEC2F
Definition: xv3d_types.h:45
CLAYER_TRIANGLE_CONTAINER * m_layer_middle_contourns_quads
void AddNormal(const SFVEC3F &aN1, const SFVEC3F &aN2, const SFVEC3F &aN3)
AddNormal.
glm::vec3 SFVEC3F
Definition: xv3d_types.h:47
Definition: ray.h:110
void AddQuad(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3, const SFVEC3F &aV4)
AddQuad.

References CLAYER_TRIANGLE_CONTAINER::AddNormal(), CLAYER_TRIANGLE_CONTAINER::AddQuad(), CBVHCONTAINER2D::IntersectAny(), m_layer_middle_contourns_quads, and m_middle_layer_lock.

◆ IsLayersSizeValid()

bool CLAYER_TRIANGLES::IsLayersSizeValid ( )

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

◆ m_layer_bot_triangles

◆ m_layer_middle_contourns_quads

CLAYER_TRIANGLE_CONTAINER* CLAYER_TRIANGLES::m_layer_middle_contourns_quads

◆ m_layer_top_segment_ends

◆ m_layer_top_triangles

◆ m_middle_layer_lock

std::mutex CLAYER_TRIANGLES::m_middle_layer_lock

Definition at line 182 of file clayer_triangles.h.

Referenced by AddToMiddleContourns().


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