KiCad PCB EDA Suite
wrlfacet.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2016 Cirilo Bernardo <[email protected]>
5 * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
31#ifndef WRLFACET_H
32#define WRLFACET_H
33
34#include <list>
35#include <vector>
36#include "wrltypes.h"
38
39
40class SGNODE;
41
42class FACET
43{
44public:
45 FACET();
46
47 void Init();
48 bool HasMinPoints();
49 bool HasColors();
50
54 void AddVertex( WRLVEC3F& aVertex, int aIndex );
55
62 void AddColor( const SGCOLOR& aColor );
63
71 float CalcFaceNormal();
72
73 void Renormalize( float aMaxValue );
74
81 void CalcVertexNormal( int aIndex, std::list< FACET* >& aFacetList, float aCreaseAngle );
82
89 bool GetWeightedNormal( int aIndex, WRLVEC3F& aNorm );
90
96 bool GetFaceNormal( WRLVEC3F& aNorm );
97
106 bool GetData( std::vector< WRLVEC3F >& aVertexList, std::vector< WRLVEC3F >& aNormalsList,
107 std::vector< SGCOLOR >& aColorsList, WRL1_ORDER aVertexOrder );
108
110 {
111 return maxIdx;
112 }
113
118 void CollectVertices( std::vector< std::list< FACET* > >& aFacetList );
119
120private:
121 std::vector< WRLVEC3F > vertices; // vertices of the facet
122 std::vector< SGCOLOR > colors; // per-vertex/per-face color (if any)
123 std::vector< int > indices; // index of each vertex
124
125 WRLVEC3F face_normal; // normal of this facet
126 std::vector< WRLVEC3F > norms; // per-vertex normals
127 std::vector< WRLVEC3F > vnweight; // angle weighted per vertex normal
128
129 int maxIdx; // maximum index used
130};
131
132
133class SHAPE
134{
135public:
137
138 FACET* NewFacet();
139 SGNODE* CalcShape( SGNODE* aParent, SGNODE* aColor, WRL1_ORDER aVertexOrder,
140 float aCreaseLimit = 0.74317, bool isVRML2 = false );
141
142private:
143 std::list< FACET* > facets;
144};
145
146#endif // WRLFACET_H
Definition: wrlfacet.h:43
WRLVEC3F face_normal
Definition: wrlfacet.h:125
std::vector< SGCOLOR > colors
Definition: wrlfacet.h:122
std::vector< WRLVEC3F > vnweight
Definition: wrlfacet.h:127
bool GetFaceNormal(WRLVEC3F &aNorm)
Retrieve the normal for this facet.
Definition: wrlfacet.cpp:445
FACET()
Definition: wrlfacet.cpp:149
bool HasMinPoints()
Definition: wrlfacet.cpp:173
void Renormalize(float aMaxValue)
Definition: wrlfacet.cpp:663
std::vector< WRLVEC3F > vertices
Definition: wrlfacet.h:121
int maxIdx
Definition: wrlfacet.h:129
bool GetWeightedNormal(int aIndex, WRLVEC3F &aNorm)
Retrieve the angle weighted normal for the given vertex index.
Definition: wrlfacet.cpp:412
float CalcFaceNormal()
Calculate the normal to the facet assuming a CCW orientation and perform the calculation of the angle...
Definition: wrlfacet.cpp:212
bool HasColors()
Definition: wrlfacet.cpp:182
void CollectVertices(std::vector< std::list< FACET * > > &aFacetList)
Add a pointer to this object at each position within aFacetList referenced by the internal vertex ind...
Definition: wrlfacet.cpp:642
void AddVertex(WRLVEC3F &aVertex, int aIndex)
Add the vertex and its associated index to the internal list of polygon vertices.
Definition: wrlfacet.cpp:191
std::vector< WRLVEC3F > norms
Definition: wrlfacet.h:126
std::vector< int > indices
Definition: wrlfacet.h:123
void CalcVertexNormal(int aIndex, std::list< FACET * > &aFacetList, float aCreaseAngle)
Calculate the weighted normal for the given vertex.
Definition: wrlfacet.cpp:329
int GetMaxIndex()
Definition: wrlfacet.h:109
void AddColor(const SGCOLOR &aColor)
Add the given RGB color to the internal list.
Definition: wrlfacet.cpp:204
void Init()
Definition: wrlfacet.cpp:158
bool GetData(std::vector< WRLVEC3F > &aVertexList, std::vector< WRLVEC3F > &aNormalsList, std::vector< SGCOLOR > &aColorsList, WRL1_ORDER aVertexOrder)
Package the internal data as triangles with corresponding per-vertex normals.
Definition: wrlfacet.cpp:462
The base class of all Scene Graph nodes.
Definition: sg_node.h:75
An abstract shape on 2D plane.
Definition: shape.h:123
FACET * NewFacet()
Definition: wrlfacet.cpp:695
SGNODE * CalcShape(SGNODE *aParent, SGNODE *aColor, WRL1_ORDER aVertexOrder, float aCreaseLimit=0.74317, bool isVRML2=false)
Definition: wrlfacet.cpp:703
std::list< FACET * > facets
Definition: wrlfacet.h:143
collects header files for all SG* wrappers and the API
declares some compound types used for VRML
WRL1_ORDER
Definition: wrltypes.h:114
glm::vec3 WRLVEC3F
Definition: wrltypes.h:188