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 <cirilo.bernardo@gmail.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
30 #ifndef WRLFACET_H
31 #define WRLFACET_H
32 
33 #include <list>
34 #include <vector>
35 #include "wrltypes.h"
36 #include "plugins/3dapi/ifsg_all.h"
37 
38 
39 class SGNODE;
40 
41 class FACET
42 {
43 private:
44  std::vector< WRLVEC3F > vertices; // vertices of the facet
45  std::vector< SGCOLOR > colors; // per-vertex/per-face color (if any)
46  std::vector< int > indices; // index of each vertex
47 
48  WRLVEC3F face_normal; // normal of this facet
49  std::vector< WRLVEC3F > norms; // per-vertex normals
50  std::vector< WRLVEC3F > vnweight; // angle weighted per vertex normal
51 
52  int maxIdx; // maximum index used
53 
54 public:
55  FACET();
56 
57  void Init();
58  bool HasMinPoints();
59  bool HasColors();
60 
66  void AddVertex( WRLVEC3F& aVertex, int aIndex );
67 
75  void AddColor( const SGCOLOR& aColor );
76 
85  float CalcFaceNormal();
86 
87  void Renormalize( float aMaxValue );
88 
96  void CalcVertexNormal( int aIndex, std::list< FACET* >& aFacetList, float aCreaseAngle );
97 
105  bool GetWeightedNormal( int aIndex, WRLVEC3F& aNorm );
106 
113  bool GetFaceNormal( WRLVEC3F& aNorm );
114 
124  bool GetData( std::vector< WRLVEC3F >& aVertexList, std::vector< WRLVEC3F >& aNormalsList,
125  std::vector< SGCOLOR >& aColorsList, WRL1_ORDER aVertexOrder );
126 
128  {
129  return maxIdx;
130  }
131 
137  void CollectVertices( std::vector< std::list< FACET* > >& aFacetList );
138 };
139 
140 
141 class SHAPE
142 {
143  std::list< FACET* > facets;
144 
145 public:
146  ~SHAPE();
147 
148  FACET* NewFacet();
149  SGNODE* CalcShape( SGNODE* aParent, SGNODE* aColor, WRL1_ORDER aVertexOrder,
150  float aCreaseLimit = 0.74317, bool isVRML2 = false );
151 };
152 
153 #endif // WRLFACET_H
SGNODE * CalcShape(SGNODE *aParent, SGNODE *aColor, WRL1_ORDER aVertexOrder, float aCreaseLimit=0.74317, bool isVRML2=false)
Definition: wrlfacet.cpp:713
glm::vec3 WRLVEC3F
Definition: wrltypes.h:185
void AddVertex(WRLVEC3F &aVertex, int aIndex)
Function AddVertex adds the vertex and its associated index to the internal list of polygon vertices.
Definition: wrlfacet.cpp:193
void Init()
Definition: wrlfacet.cpp:158
void Renormalize(float aMaxValue)
Definition: wrlfacet.cpp:671
void CollectVertices(std::vector< std::list< FACET * > > &aFacetList)
Function CollectVertices adds a pointer to this object at each position within aFacetList referenced ...
Definition: wrlfacet.cpp:648
SGNODE represents the base class of all Scene Graph nodes.
Definition: sg_node.h:76
collects header files for all SG* wrappers and the API
virtual ~SHAPE()
Definition: shape.h:90
int GetMaxIndex()
Definition: wrlfacet.h:127
void AddColor(const SGCOLOR &aColor)
Function AddColor adds the given RGB color to the internal list.
Definition: wrlfacet.cpp:208
bool GetWeightedNormal(int aIndex, WRLVEC3F &aNorm)
Function GetWeightedNormal retrieves the angle weighted normal for the given vertex index.
Definition: wrlfacet.cpp:418
WRL1_ORDER
Definition: wrltypes.h:110
bool HasColors()
Definition: wrlfacet.cpp:184
bool GetFaceNormal(WRLVEC3F &aNorm)
Function GetFaceNormal retrieves the normal for this facet.
Definition: wrlfacet.cpp:451
SHAPE.
Definition: shape.h:74
std::vector< SGCOLOR > colors
Definition: wrlfacet.h:45
std::vector< WRLVEC3F > norms
Definition: wrlfacet.h:49
WRLVEC3F face_normal
Definition: wrlfacet.h:48
void CalcVertexNormal(int aIndex, std::list< FACET * > &aFacetList, float aCreaseAngle)
Function CalcVertexNormal calculates the weighted normal for the given vertex.
Definition: wrlfacet.cpp:333
std::vector< WRLVEC3F > vertices
Definition: wrlfacet.h:44
FACET * NewFacet()
Definition: wrlfacet.cpp:705
Definition: wrlfacet.h:41
std::list< FACET * > facets
Definition: wrlfacet.h:143
float CalcFaceNormal()
Function CalcFaceNormal calculates the normal to the facet assuming a CCW orientation and performs th...
Definition: wrlfacet.cpp:216
bool GetData(std::vector< WRLVEC3F > &aVertexList, std::vector< WRLVEC3F > &aNormalsList, std::vector< SGCOLOR > &aColorsList, WRL1_ORDER aVertexOrder)
Function GetData packages the internal data as triangles with corresponding per-vertex normals.
Definition: wrlfacet.cpp:468
std::vector< WRLVEC3F > vnweight
Definition: wrlfacet.h:50
std::vector< int > indices
Definition: wrlfacet.h:46
declares some compound types used for VRML
int maxIdx
Definition: wrlfacet.h:52
FACET()
Definition: wrlfacet.cpp:149
bool HasMinPoints()
Definition: wrlfacet.cpp:175