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)
 
void AddToMiddleContourns (const SHAPE_POLY_SET &aPolySet, float zBot, float zTop, double aBiuTo3Du, bool aInvertFaceDirection)
 
void AddToMiddleContourns (const std::vector< SFVEC2F > &aContournPoints, float zBot, float zTop, bool aInvertFaceDirection)
 

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 139 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 
)

Definition at line 237 of file clayer_triangles.cpp.

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

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

Referenced by AddToMiddleContourns(), 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::reload().

◆ AddToMiddleContourns() [2/3]

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

Definition at line 277 of file clayer_triangles.cpp.

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

References AddToMiddleContourns(), SHAPE_POLY_SET::CHole(), SHAPE_POLY_SET::COutline(), SHAPE_POLY_SET::HoleCount(), i, 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 
)

Definition at line 148 of file clayer_triangles.cpp.

152 {
153  if( aContournPoints.size() >= 4 )
154  {
155  // Calculate normals of each segment of the contourn
156  std::vector< SFVEC2F > contournNormals;
157 
158  contournNormals.clear();
159  contournNormals.resize( aContournPoints.size() - 1 );
160 
161  if( aInvertFaceDirection )
162  {
163  for( unsigned int i = 0; i < ( aContournPoints.size() - 1 ); ++i )
164  {
165  const SFVEC2F &v0 = aContournPoints[i + 0];
166  const SFVEC2F &v1 = aContournPoints[i + 1];
167  const SFVEC2F n = glm::normalize( v1 - v0 );
168 
169  contournNormals[i] = SFVEC2F( n.y,-n.x );
170  }
171  }
172  else
173  {
174  for( unsigned int i = 0; i < ( aContournPoints.size() - 1 ); ++i )
175  {
176  const SFVEC2F &v0 = aContournPoints[i + 0];
177  const SFVEC2F &v1 = aContournPoints[i + 1];
178  const SFVEC2F n = glm::normalize( v1 - v0 );
179 
180  contournNormals[i] = SFVEC2F( -n.y, n.x );
181  }
182  }
183 
184 
185  if( aInvertFaceDirection )
186  std::swap( zBot, zTop );
187 
188  const unsigned int nContournsToProcess = ( aContournPoints.size() - 1 );
189 
190  for( unsigned int i = 0; i < nContournsToProcess; ++i )
191  {
192  SFVEC2F lastNormal;
193 
194  if( i > 0 )
195  lastNormal = contournNormals[i - 1];
196  else
197  lastNormal = contournNormals[nContournsToProcess - 1];
198 
199  SFVEC2F n0 = contournNormals[i];
200 
201  // Only interpolate the normal if the angle is closer
202  if( glm::dot( n0, lastNormal ) > 0.5f )
203  n0 = glm::normalize( n0 + lastNormal );
204 
205  SFVEC2F nextNormal;
206 
207  if( i < (nContournsToProcess - 1) )
208  nextNormal = contournNormals[i + 1];
209  else
210  nextNormal = contournNormals[0];
211 
212  SFVEC2F n1 = contournNormals[i];
213 
214  if( glm::dot( n1, nextNormal ) > 0.5f )
215  n1 = glm::normalize( n1 + nextNormal );
216 
217  const SFVEC3F n3d0 = SFVEC3F( n0.x, n0.y, 0.0f );
218  const SFVEC3F n3d1 = SFVEC3F( n1.x, n1.y, 0.0f );
219 
220  const SFVEC2F &v0 = aContournPoints[i + 0];
221  const SFVEC2F &v1 = aContournPoints[i + 1];
222 
223  {
224  std::lock_guard<std::mutex> lock( m_middle_layer_lock );
225  m_layer_middle_contourns_quads->AddQuad( SFVEC3F( v0.x, v0.y, zTop ),
226  SFVEC3F( v1.x, v1.y, zTop ),
227  SFVEC3F( v1.x, v1.y, zBot ),
228  SFVEC3F( v0.x, v0.y, zBot ) );
229 
230  m_layer_middle_contourns_quads->AddNormal( n3d0, n3d1, n3d1, n3d0 );
231  }
232  }
233  }
234 }
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
size_t i
Definition: json11.cpp:597
void AddQuad(const SFVEC3F &aV1, const SFVEC3F &aV2, const SFVEC3F &aV3, const SFVEC3F &aV4)
AddQuad.

References CLAYER_TRIANGLE_CONTAINER::AddNormal(), CLAYER_TRIANGLE_CONTAINER::AddQuad(), i, 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 178 of file clayer_triangles.h.

Referenced by AddToMiddleContourns().


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