Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
SoNormalGenerator.h
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Thad Beier (MMM yyyy)
25** Modified by : Paul S. Strauss (MMM yyyy)
26**=======================================================================*/
27/*=======================================================================
28 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
29 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
30 *** ***
31 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
32 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
33 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
34 *** ***
35 *** RESTRICTED RIGHTS LEGEND ***
36 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
37 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
38 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
39 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
40 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
41 *** ***
42 *** COPYRIGHT (C) 1996-2014 BY FEI S.A.S, ***
43 *** BORDEAUX, FRANCE ***
44 *** ALL RIGHTS RESERVED ***
45**=======================================================================*/
46/*=======================================================================
47** Modified by : VSG (MMM YYYY)
48**=======================================================================*/
49
50
51
52#ifndef _SO_NORMAL_GENERATOR_
53#define _SO_NORMAL_GENERATOR_
54
55#include <Inventor/SbLinear.h>
56#include <Inventor/elements/SoNeighborToleranceElement.h>
57
58
59#include <Inventor/STL/vector>
60#include <Inventor/STL/utility>
61
102{
103
104 public:
105
109 SoNormalGenerator(
110 const SbBool isCCW,
111 const int approxNumVertices=16,
112 const int approxNumFaces=6,
113 const float creaseAngle =0.0f,
114 const float toleranceFactor = SoNeighborToleranceElement::getDefault()
115 );
116
120 ~SoNormalGenerator();
121
128 void setupApproxShapeSize(const int32_t approxNumVertices,const int32_t approxNumFaces);
129
134 void beginPolygon();
135 void polygonVertex(const SbVec3f &point);
136 void endPolygon();
137
139 void triangle(const SbVec3f &p1,const SbVec3f &p2,const SbVec3f &p3);
140
151 void setupIndexedVertexArray(const SbVec3f* pointArray);
152
158 void setupIndexedConnectivity(const int32_t* connectivityArray);
159
164 void polygonVertex(const int32_t pointIndex);
165
170 void triangle(const int32_t index1,const int32_t index2,const int32_t index3);
171
173 void generate();
174
180 int getNumNormals() const { return numVertNormals; }
181
186 void setNumNormals(int newNum);
187
192 const SbVec3f *getNormals() const
193 { return vertNormals; }
194
199 const SbVec3f & getNormal(int32_t i) const
200 { return vertNormals[i]; }
201
210 void setNormal(int32_t index, const SbVec3f &newNormal);
211
218 int32_t numNormalCrack() const
219 {return m_numNormalCrack; };
220
221private:
222 /*
223 * Some shapes may need to adjust or reorder all normals after
224 * generation. This method can be used to change all normal in one
225 * shot without any copy.
226 */
227 void setNormalBuffer(int32_t numNormals, const SbVec3f *normals);
228
232 bool isIndexedMode() const
233 {return m_isIndexedMode; }
234
235private:
236 void endPolygon_( int32_t numVertices );
237
238 inline void addPolygonNormal( const SbVec3f &vec1, const SbVec3f &vec2 )
239 { polygonSum += (vec1).cross(vec2); }
240
241 private:
242 // Arrays of vertex points, face normals, and vertex normals. The
243 // face normals are stored one per vertex. The other vars are the
244 // number of items in the arrays, and the allocated sizes of the
245 // arrays. Since the points and faceNormals arrays are always the
246 // same size, no need for extra variables.
247 // Depending on setupIndexedVertexArray call or not, data are used
248 // from points or pointsIndex array.
249 SbVec3f *points, *faceNormals, *vertNormals;
250 int32_t *pointIndexes;
251 int32_t numPoints, numVertNormals;
252 int32_t maxPoints, maxFaceNormals, maxVertNormals;
253 SbVec3f polygonSum;
254
255 // Flag: if TRUE, polygons are oriented counter-clockwise
256 SbBool m_isCCW;
257 float m_creaseAngle;
258 float m_toleranceFactor;
259
260 int32_t m_approxNumVertices;
261 int32_t m_approxNumFaces;
262 int32_t m_faceIndex;
263 int32_t m_pointIndex;
264
265 // Index into points array where current polygon started
266 int32_t beginPolygonIndex;
267 SbBox3f m_bbox;
268
269 //
270 int m_numNormalCrack;
271 bool m_isIndexedMode;
272 int32_t *m_userConnectivity;
273
274 // grow point or pointsIndexes array depending on current number of point.
275 void growPointsArray(const int requestedMaxPoints);
276 // grow current facenormals array .
277 void growNormalFaceArray(const int requestedNormalFaceArraySize);
278
279
280 inline bool needToComputeConnectivity( ) const
281 { return (( m_creaseAngle != 0.0f ) && ( m_userConnectivity == NULL )); }
282
283 // compute a double link list of points that are connected.
284 // the resulting array has numPoints size
285 // the caller is responsible to release the array allocated by this method
286 int32_t* computeConnectivity( std::vector < std::pair< int, size_t > > &indicesClasses );
287
288 // determine point equivalence class length
289 void evalConnectedVerticesIndicesClasses( int32_t* indirect, size_t numPoints,
290 std::vector < std::pair< int, size_t > > &indicesClasses ) const;
291
292 // Returns TRUE if the two points are the same within given tolerance
293 static SbBool equal(const SbVec3f &a, const SbVec3f &b, const float tol);
294
295 static SbBool s_useOldTolerance;
296};
297
298#endif /* _SO_NORMAL_GENERATOR_ */
299
300
3D box class.
Definition SbBox.h:649
3D vector class.
Definition SbVec.h:932
static float getDefault()
Returns the default tolerance factor value.
int SbBool
Boolean type.
Definition SbBase.h:87