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

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 138 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 109 of file clayer_triangles.cpp.

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.

110 {
111  wxASSERT( aNrReservedTriangles > 0 );
112 
113  m_layer_top_segment_ends = new CLAYER_TRIANGLE_CONTAINER( aNrReservedTriangles,
114  false );
115  m_layer_top_triangles = new CLAYER_TRIANGLE_CONTAINER( aNrReservedTriangles,
116  false );
117  m_layer_middle_contourns_quads = new CLAYER_TRIANGLE_CONTAINER( aNrReservedTriangles,
118  true );
119  m_layer_bot_triangles = new CLAYER_TRIANGLE_CONTAINER( aNrReservedTriangles,
120  false );
121  m_layer_bot_segment_ends = new CLAYER_TRIANGLE_CONTAINER( aNrReservedTriangles,
122  false );
123 }
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 126 of file clayer_triangles.cpp.

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.

127 {
130 
131  delete m_layer_top_triangles;
133 
136 
137  delete m_layer_bot_triangles;
139 
142 }
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 236 of file clayer_triangles.cpp.

References SHAPE_LINE_CHAIN::CPoint(), 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().

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

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

281 {
282  wxASSERT( aPolySet.OutlineCount() > 0 );
283 
284  if( aPolySet.OutlineCount() == 0 )
285  return;
286 
287  // Calculate an estimation of points to reserve
288  unsigned int nrContournPointsToReserve = 0;
289 
290  for( int i = 0; i < aPolySet.OutlineCount(); ++i )
291  {
292  const SHAPE_LINE_CHAIN& pathOutline = aPolySet.COutline( i );
293 
294  nrContournPointsToReserve += pathOutline.PointCount();
295 
296  for( int h = 0; h < aPolySet.HoleCount( i ); ++h )
297  {
298  const SHAPE_LINE_CHAIN &hole = aPolySet.CHole( i, h );
299 
300  nrContournPointsToReserve += hole.PointCount();
301  }
302  }
303 
304  // Request to reserve more space
305  m_layer_middle_contourns_quads->Reserve_More( nrContournPointsToReserve * 2,
306  true );
307 
308  #pragma omp parallel for
309  for( signed int i = 0; i < aPolySet.OutlineCount(); ++i )
310  {
311  // Add outline
312  const SHAPE_LINE_CHAIN& pathOutline = aPolySet.COutline( i );
313 
314  AddToMiddleContourns( pathOutline, zBot, zTop, aBiuTo3Du, aInvertFaceDirection );
315 
316  // Add holes for this outline
317  for( int h = 0; h < aPolySet.HoleCount( i ); ++h )
318  {
319  const SHAPE_LINE_CHAIN &hole = aPolySet.CHole( i, h );
320  AddToMiddleContourns( hole, zBot, zTop, aBiuTo3Du, aInvertFaceDirection );
321  }
322  }
323 }
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.
void CLAYER_TRIANGLES::AddToMiddleContourns ( const std::vector< SFVEC2F > &  aContournPoints,
float  zBot,
float  zTop,
bool  aInvertFaceDirection 
)

Definition at line 145 of file clayer_triangles.cpp.

References CLAYER_TRIANGLE_CONTAINER::AddNormal(), CLAYER_TRIANGLE_CONTAINER::AddQuad(), and m_layer_middle_contourns_quads.

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

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