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 ( 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.

References CLAYER_TRIANGLE_CONTAINER::CLAYER_TRIANGLE_CONTAINER().

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

Member Function Documentation

void CLAYER_TRIANGLES::AddToMiddleContourns ( const SHAPE_LINE_CHAIN outlinePath,
float  zBot,
float  zTop,
double  aBiuTo3Du,
bool  aInvertFaceDirection 
)

Definition at line 239 of file clayer_triangles.cpp.

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

Referenced by 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().

244 {
245  std::vector< SFVEC2F >contournPoints;
246 
247  contournPoints.clear();
248  contournPoints.reserve( outlinePath.PointCount() + 2 );
249 
250  const VECTOR2I &firstV = outlinePath.CPoint( 0 );
251 
252  SFVEC2F lastV = SFVEC2F( firstV.x * aBiuTo3Du,
253  -firstV.y * aBiuTo3Du );
254 
255  contournPoints.push_back( lastV );
256 
257  for( unsigned int i = 1; i < (unsigned int)outlinePath.PointCount(); ++i )
258  {
259  const VECTOR2I & v = outlinePath.CPoint( i );
260 
261  const SFVEC2F vf = SFVEC2F( v.x * aBiuTo3Du,
262  -v.y * aBiuTo3Du );
263 
264  if( vf != lastV ) // Do not add repeated points
265  {
266  lastV = vf;
267  contournPoints.push_back( vf );
268  }
269  }
270 
271  // Add first position fo the list to close the path
272  if( lastV != contournPoints[0] )
273  contournPoints.push_back( contournPoints[0] );
274 
275  AddToMiddleContourns( contournPoints, zBot, zTop, aInvertFaceDirection );
276 }
int PointCount() const
Function PointCount()
Class VECTOR2 defines a general 2D-vector/point.
Definition: vector2d.h:61
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
const VECTOR2I & CPoint(int aIndex) const
Function CPoint()
void CLAYER_TRIANGLES::AddToMiddleContourns ( const SHAPE_POLY_SET aPolySet,
float  zBot,
float  zTop,
double  aBiuTo3Du,
bool  aInvertFaceDirection 
)

Definition at line 279 of file clayer_triangles.cpp.

References SHAPE_POLY_SET::CHole(), SHAPE_POLY_SET::COutline(), SHAPE_POLY_SET::HoleCount(), i, SHAPE_POLY_SET::OutlineCount(), and SHAPE_LINE_CHAIN::PointCount().

284 {
285  wxASSERT( aPolySet.OutlineCount() > 0 );
286 
287  if( aPolySet.OutlineCount() == 0 )
288  return;
289 
290  // Calculate an estimation of points to reserve
291  unsigned int nrContournPointsToReserve = 0;
292 
293  for( int i = 0; i < aPolySet.OutlineCount(); ++i )
294  {
295  const SHAPE_LINE_CHAIN& pathOutline = aPolySet.COutline( i );
296 
297  nrContournPointsToReserve += pathOutline.PointCount();
298 
299  for( int h = 0; h < aPolySet.HoleCount( i ); ++h )
300  {
301  const SHAPE_LINE_CHAIN &hole = aPolySet.CHole( i, h );
302 
303  nrContournPointsToReserve += hole.PointCount();
304  }
305  }
306 
307  // Request to reserve more space
308  m_layer_middle_contourns_quads->Reserve_More( nrContournPointsToReserve * 2,
309  true );
310 
311  std::atomic<int> nextItem( 0 );
312  std::atomic<size_t> threadsFinished( 0 );
313 
314  size_t parallelThreadCount = std::min<size_t>(
315  std::max<size_t>( std::thread::hardware_concurrency(), 2 ),
316  static_cast<size_t>( aPolySet.OutlineCount() ) );
317  for( size_t ii = 0; ii < parallelThreadCount; ++ii )
318  {
319  std::thread t = std::thread( [&]()
320  {
321  for( int i = nextItem.fetch_add( 1 );
322  i < aPolySet.OutlineCount();
323  i = nextItem.fetch_add( 1 ) )
324  {
325  // Add outline
326  const SHAPE_LINE_CHAIN& pathOutline = aPolySet.COutline( i );
327 
328  AddToMiddleContourns( pathOutline, zBot, zTop, aBiuTo3Du, aInvertFaceDirection );
329 
330  // Add holes for this outline
331  for( int h = 0; h < aPolySet.HoleCount( i ); ++h )
332  {
333  const SHAPE_LINE_CHAIN &hole = aPolySet.CHole( i, h );
334  AddToMiddleContourns( hole, zBot, zTop, aBiuTo3Du, aInvertFaceDirection );
335  }
336  }
337 
338  threadsFinished++;
339  } );
340 
341  t.detach();
342  }
343 
344  while( threadsFinished < parallelThreadCount )
345  std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
346 }
int PointCount() const
Function PointCount()
int HoleCount(int aOutline) const
Returns the number of holes in a given outline
const SHAPE_LINE_CHAIN & CHole(int aOutline, int aHole) const
int OutlineCount() const
Returns the number of outlines in the set
CLAYER_TRIANGLE_CONTAINER * m_layer_middle_contourns_quads
const SHAPE_LINE_CHAIN & COutline(int aIndex) const
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.
size_t i
Definition: json11.cpp:597
void CLAYER_TRIANGLES::AddToMiddleContourns ( const std::vector< SFVEC2F > &  aContournPoints,
float  zBot,
float  zTop,
bool  aInvertFaceDirection 
)

Definition at line 148 of file clayer_triangles.cpp.

References i.

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 
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 
180  const SFVEC2F n = glm::normalize( v1 - v0 );
181 
182  contournNormals[i] = SFVEC2F( -n.y, n.x );
183  }
184  }
185 
186 
187  if( aInvertFaceDirection )
188  std::swap( zBot, zTop );
189 
190  const unsigned int nContournsToProcess = ( aContournPoints.size() - 1 );
191 
192  for( unsigned int i = 0; i < nContournsToProcess; ++i )
193  {
194  SFVEC2F lastNormal;
195 
196  if( i > 0 )
197  lastNormal = contournNormals[i - 1];
198  else
199  lastNormal = contournNormals[nContournsToProcess - 1];
200 
201  SFVEC2F n0 = contournNormals[i];
202 
203  // Only interpolate the normal if the angle is closer
204  if( glm::dot( n0, lastNormal ) > 0.5f )
205  n0 = glm::normalize( n0 + lastNormal );
206 
207  SFVEC2F nextNormal;
208 
209  if( i < (nContournsToProcess - 1) )
210  nextNormal = contournNormals[i + 1];
211  else
212  nextNormal = contournNormals[0];
213 
214  SFVEC2F n1 = contournNormals[i];
215 
216  if( glm::dot( n1, nextNormal ) > 0.5f )
217  n1 = glm::normalize( n1 + nextNormal );
218 
219  const SFVEC3F n3d0 = SFVEC3F( n0.x, n0.y, 0.0f );
220  const SFVEC3F n3d1 = SFVEC3F( n1.x, n1.y, 0.0f );
221 
222  const SFVEC2F &v0 = aContournPoints[i + 0];
223  const SFVEC2F &v1 = aContournPoints[i + 1];
224 
225  {
226  std::lock_guard<std::mutex> lock( m_middle_layer_lock );
227  m_layer_middle_contourns_quads->AddQuad( SFVEC3F( v0.x, v0.y, zTop ),
228  SFVEC3F( v1.x, v1.y, zTop ),
229  SFVEC3F( v1.x, v1.y, zBot ),
230  SFVEC3F( v0.x, v0.y, zBot ) );
231 
232  m_layer_middle_contourns_quads->AddNormal( n3d0, n3d1, n3d1, n3d0 );
233  }
234  }
235  }
236 }
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.
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

CLAYER_TRIANGLE_CONTAINER* CLAYER_TRIANGLES::m_layer_bot_segment_ends
CLAYER_TRIANGLE_CONTAINER* CLAYER_TRIANGLES::m_layer_middle_contourns_quads

Definition at line 182 of file clayer_triangles.h.

Referenced by CLAYERS_OGL_DISP_LISTS::CLAYERS_OGL_DISP_LISTS().

CLAYER_TRIANGLE_CONTAINER* CLAYER_TRIANGLES::m_layer_top_segment_ends
std::mutex CLAYER_TRIANGLES::m_middle_layer_lock

Definition at line 178 of file clayer_triangles.h.


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