00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 #ifndef _SO_NORMAL_GENERATOR_
00053 #define _SO_NORMAL_GENERATOR_
00054
00055 #include <Inventor/SbLinear.h>
00056 #include <Inventor/elements/SoNeighborToleranceElement.h>
00057
00058
00059 #include <Inventor/STL/vector>
00060 #include <Inventor/STL/utility>
00061
00102 {
00103
00104 public:
00105
00109 SoNormalGenerator(
00110 const SbBool isCCW,
00111 const int approxNumVertices=16,
00112 const int approxNumFaces=6,
00113 const float creaseAngle =0.0f,
00114 const float toleranceFactor = SoNeighborToleranceElement::getDefault()
00115 );
00116
00120 ~SoNormalGenerator();
00121
00128 void setupApproxShapeSize(const int32_t approxNumVertices,const int32_t approxNumFaces);
00129
00134 void beginPolygon();
00135 void polygonVertex(const SbVec3f &point);
00136 void endPolygon();
00137
00139 void triangle(const SbVec3f &p1,const SbVec3f &p2,const SbVec3f &p3);
00140
00151 void setupIndexedVertexArray(const SbVec3f* pointArray);
00152
00158 void setupIndexedConnectivity(const int32_t* connectivityArray);
00159
00164 void polygonVertex(const int32_t pointIndex);
00165
00170 void triangle(const int32_t index1,const int32_t index2,const int32_t index3);
00171
00173 void generate();
00174
00180 int getNumNormals() const { return numVertNormals; }
00181
00186 void setNumNormals(int newNum);
00187
00192 const SbVec3f *getNormals() const
00193 { return vertNormals; }
00194
00199 const SbVec3f & getNormal(int32_t i) const
00200 { return vertNormals[i]; }
00201
00210 void setNormal(int32_t index, const SbVec3f &newNormal);
00211
00218 int32_t numNormalCrack() const
00219 {return m_numNormalCrack; };
00220
00221 private:
00222
00223
00224
00225
00226
00227 void setNormalBuffer(int32_t numNormals, const SbVec3f *normals);
00228
00232 bool isIndexedMode() const
00233 {return m_isIndexedMode; }
00234
00235 private:
00236 void endPolygon_( int32_t numVertices );
00237
00238 inline void addPolygonNormal( const SbVec3f &vec1, const SbVec3f &vec2 )
00239 { polygonSum += (vec1).cross(vec2); }
00240
00241 private:
00242
00243
00244
00245
00246
00247
00248
00249 SbVec3f *points, *faceNormals, *vertNormals;
00250 int32_t *pointIndexes;
00251 int32_t numPoints, numVertNormals;
00252 int32_t maxPoints, maxFaceNormals, maxVertNormals;
00253 SbVec3f polygonSum;
00254
00255
00256 SbBool m_isCCW;
00257 float m_creaseAngle;
00258 float m_toleranceFactor;
00259
00260 int32_t m_approxNumVertices;
00261 int32_t m_approxNumFaces;
00262 int32_t m_faceIndex;
00263 int32_t m_pointIndex;
00264
00265
00266 int32_t beginPolygonIndex;
00267 SbBox3f m_bbox;
00268
00269
00270 int m_numNormalCrack;
00271 bool m_isIndexedMode;
00272 int32_t *m_userConnectivity;
00273
00274
00275 void growPointsArray(const int requestedMaxPoints);
00276
00277 void growNormalFaceArray(const int requestedNormalFaceArraySize);
00278
00279
00280 inline bool needToComputeConnectivity( ) const
00281 { return (( m_creaseAngle != 0.0f ) && ( m_userConnectivity == NULL )); }
00282
00283
00284
00285
00286 int32_t* computeConnectivity( std::vector < std::pair< int, size_t > > &indicesClasses );
00287
00288
00289 void evalConnectedVerticesIndicesClasses( int32_t* indirect, size_t numPoints,
00290 std::vector < std::pair< int, size_t > > &indicesClasses ) const;
00291
00292
00293 static SbBool equal(const SbVec3f &a, const SbVec3f &b, const float tol);
00294
00295 static SbBool s_useOldTolerance;
00296 };
00297
00298 #endif
00299
00300
00301