Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoNormalBundle.h
Go to the documentation of this file.
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 : Paul S. Strauss (MMM yyyy)
25**=======================================================================*/
26/*=======================================================================
27 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
28 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
29 *** ***
30 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
31 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
32 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
33 *** ***
34 *** RESTRICTED RIGHTS LEGEND ***
35 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
36 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
37 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
38 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
39 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
40 *** ***
41 *** COPYRIGHT (C) 1996-2017 BY FEI S.A.S, ***
42 *** BORDEAUX, FRANCE ***
43 *** ALL RIGHTS RESERVED ***
44**=======================================================================*/
45/*=======================================================================
46** Modified by : VSG (MMM YYYY)
47**=======================================================================*/
48
49
50#ifndef _SO_NORMAL_BUNDLE
51#define _SO_NORMAL_BUNDLE
52
57
58class SoNormalCache;
59
61//
62// Class: SoNormalBundle
63//
64// Bundle that allows shapes to deal with normals and normal bindings
65// more easily. This class provides a fairly simple interface to
66// normal handling, including normal generation.
67//
68// This class can be used during either rendering or primitive
69// generation. For primitive generation, the get() method can be used
70// to access normals. For GL rendering, the send() method can be used
71// to send normals to GL.
72//
74
75{
76
77 public:
78
79 // Constructor - takes the action the bundle is used for and a
80 // flag to indicate whether the bundle is being used for
81 // rendering. If this is TRUE, the bundle can be used to send
82 // normals to GL.
83 SoNormalBundle( SoAction *action, SbBool forRendering );
84
85 // Destructor
86 virtual ~SoNormalBundle();
87
88 // Returns TRUE if normals need to be generated.
89 SbBool shouldGenerate(int numNeeded);
90
91 // Initializes generation in the case where shouldGenerate() is
92 // not called. (shouldGenerate() does this automatically).
93 void initGenerator(int initialNum = 100);
94
96 //
97 // If shouldGenerate() returns TRUE, these methods can be used by
98 // shapes to specify the geometry to generate normals for. They
99 // are front-ends to methods on the SoNormalGenerator class:
100 //
101
102 // Send a polygon's worth of vertices. Begin a polygon, send as
103 // many vertices as you want, and then end the polygon.
105 { generator->beginPolygon(); }
106 void polygonVertex(const SbVec3f &point)
107 { generator->polygonVertex(point); }
109 { generator->endPolygon(); }
110
111 // Send a triangle
112 void triangle(const SbVec3f &p1,
113 const SbVec3f &p2,
114 const SbVec3f &p3)
115 { generator->triangle(p1, p2, p3); }
116
117 // See SoNormalGenerator for details.
118 void setupIndexedVertexArray(const SbVec3f* pointArray)
119 { generator->setupIndexedVertexArray(pointArray); }
120 void polygonVertex(const int32_t index)
121 { generator->polygonVertex(index); }
122 void triangle(const int32_t index1,const int32_t index2,const int32_t index3)
123 { generator->triangle(index1,index2,index3); }
124 void setupIndexedConnectivity(const int32_t* connectivityArray)
125 { generator->setupIndexedConnectivity(connectivityArray); }
126 void setupApproxShapeSize(const int32_t numVert,const int32_t numFace)
127 { generator->setupApproxShapeSize(numVert,numFace); }
128
129 // Calculates the normals once all vertices have been sent. The
130 // normals are stored by the bundle so the caller does not have to
131 // deal with them directly. The startIndex argument specifies the
132 // index at which the generated normals will begin-- it can be
133 // used by shapes that allow the coordinates and normals to be
134 // offset (non-indexed shapes). If addToState is TRUE, the
135 // state will be pushed, the normals will be added to the
136 // state; otherwise, you can just use
137 // getGeneratedNormals/getNumGeneratedNormals to get the generated
138 // normals.
139 //
140 // The normal bundle DOES NOT FREE the generated normals! It is
141 // expected that normals will be added to a normal cache, and the
142 // normal cache will free the normals.
143 //
144 void generate(int startIndex = 0,
145 SbBool addToState=TRUE);
146
147 // Returns the generated normals.
149 { return generator->getNormals(); }
151 { return generator->getNumNormals(); }
153 {
154 if (m_isIndexedNormal)
156 else
158 }
159
160
161 // This allows shapes that generate their own normals (for
162 // efficiency) to store the resulting normals in the state. The
163 // bundle takes care of pushing/popping the state.
164 // Note: This method only adds the normals to the state, it does
165 // NOT store a pointer to them (so you cannot call the
166 // getGenerated() routines)
167 void set(
168 int32_t numNormals,
169 const SbVec3f *normals,
170 const SoNormalBindingElement::Binding binding /*= SoNormalBindingElement::PER_VERTEX */,
171 const int startIndex = 0
172 );
173
174 // to set the SoNormalBundle from a SoNormalCache
175 void set(SoNormalCache* nc);
176
177 // Returns indexed normal. This can be used for primitive
178 // generation or during rendering
179 const SbVec3f& get(int index) const
180 { return normElt->getNum() != 0 ? normElt->get(index - m_startIndex) : s_zVers; }
181
182 // Sends indexed normal to the GL, for use only during GL rendering
183 virtual void send(int index) const;
184
185 // return the number of normal crack
186 // -1 if the info is not available.
187 int numNormalCrack() const
188 { return generator->numNormalCrack(); }
189
190 int getStartIndex() const
191 { return m_startIndex; }
192
193 private:
194
195 SoNormalGenerator *generator; // Normal generator
196
197 private:
198 // Normal elements:
199 const SoNormalElement *normElt;
200 const SoNormalElement *GLNormElt;
201
202 SbBool isRendering; // Bundle being used for rendering
203 SbBool pushedState; // We pushed state to set normals
204 SoNode *currentNode; // Node that created the bundle
205 bool m_isIndexedNormal;
206 static const SbVec3f s_zVers;
207 int m_startIndex; // this the offset used in indexing the normals WITHOUT allocating useless memory
208 bool m_normSetOrGen;
209
210};
211
212#endif /* _SO_NORMAL_BUNDLE */
213
#define TRUE
Possible value of SbBool.
Definition SbBase.h:77
SbBool shouldGenerate(int numNeeded)
void initGenerator(int initialNum=100)
void endPolygon()
void set(int32_t numNormals, const SbVec3f *normals, const SoNormalBindingElement::Binding binding, const int startIndex=0)
void beginPolygon()
Send a polygon's worth of vertices.
void triangle(const SbVec3f &p1, const SbVec3f &p2, const SbVec3f &p3)
Send a triangle.
int numNormalCrack() const
const SbVec3f & get(int index) const
int getStartIndex() const
int getNumGeneratedNormals() const
void setupIndexedConnectivity(const int32_t *connectivityArray)
Specifies a per-vertex connectivity array.
const SbVec3f * getGeneratedNormals() const
SoNormalBindingElement::Binding getNormalBinding() const
void polygonVertex(const SbVec3f &point)
void setupApproxShapeSize(const int32_t numVert, const int32_t numFace)
Resets the approximative number of vertices and faces that we have to generate normals for.
virtual ~SoNormalBundle()
virtual void send(int index) const
void setupIndexedVertexArray(const SbVec3f *pointArray)
Specifies a pointer to the array of points that will be used in subsequent calls to polygonVertex(ind...
void generate()
Calculate the normals once all vertices have been sent.
3D vector class.
Definition SbVec.h:932
Abstract base class for all actions.
Definition SoAction.h:132
Abstract base class for all database nodes.
Definition SoNode.h:145
Binding
The choice of values is for compatibility with Open Inventor 2.0 binary format files:
@ PER_VERTEX
One normal for each vertex.
@ PER_VERTEX_INDEXED
One normal for each vertex, indexed.
Allows read-only access to the top element in the state.
int32_t getNum() const
Returns the number of normal vectors in an instance.
const SbVec3f & get(int index) const
Returns the indexed normal from an element.
int SbBool
Boolean type.
Definition SbBase.h:87