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 #ifndef _OSGEXTRUSIONGEOMETRY_H_
00045 #define _OSGEXTRUSIONGEOMETRY_H_
00046 #ifdef __sgi
00047 #pragma once
00048 #endif
00049
00050 #include <OSGConfig.h>
00051 #include <OSGSystemDef.h>
00052 #include <OSGBaseTypes.h>
00053 #include <OSGQuaternion.h>
00054 #include <OSGNode.h>
00055 #include <OSGGeoPropPtrs.h>
00056 #include <OSGGeometry.h>
00057
00058 #include <vector>
00059 #include <map>
00060
00061
00062 OSG_BEGIN_NAMESPACE
00063
00064
00065
00066
00067
00068
00069
00070 OSG_SYSTEMLIB_DLLMAPPING
00071 NodePtr makeExtrusion (const std::vector<Pnt2f> &crossSection,
00072 const std::vector<Quaternion> &orientation,
00073 const std::vector<Vec2f> &scale,
00074 const std::vector<Pnt3f> &spine,
00075 Real32 creaseAngle,
00076 bool beginCap,
00077 bool endCap,
00078 bool ccw,
00079 bool convex,
00080 bool buildNormal,
00081 bool buildTexCoord,
00082 UInt32 numOfSubdivision);
00083
00084 OSG_SYSTEMLIB_DLLMAPPING
00085 GeometryPtr makeExtrusionGeo(const std::vector<Pnt2f> &crossSection,
00086 const std::vector<Quaternion> &orientation,
00087 const std::vector<Vec2f> &scale,
00088 const std::vector<Pnt3f> &spine,
00089 Real32 creaseAngle,
00090 bool beginCap,
00091 bool endCap,
00092 bool ccw,
00093 bool convex,
00094 bool buildNormal,
00095 bool buildTexCoord,
00096 UInt32 numOfSubdivision);
00097
00098
00099
00100
00101
00102
00104 static const UInt32 DEF_N_CROSS_SECTION_POINTS = 5;
00105
00107 static const UInt32 DEF_N_SCALE_PARAMS = 1;
00108
00110 static const UInt32 DEF_N_SPINE_POINTS = 2;
00111
00113 static const UInt32 DEF_N_ORIENTATION_PARAMS = 1;
00114
00116 static const Real32
00117 DEF_CROSS_SECTION[DEF_N_CROSS_SECTION_POINTS][2] = {{ 1.0, 1.0},
00118 { 1.0, -1.0},
00119 {-1.0, -1.0},
00120 {-1.0, 1.0},
00121 { 1.0, 1.0}};
00123 static const Real32
00124 DEF_SCALE[DEF_N_SCALE_PARAMS][2] = {{ 1.f, 1.f }};
00125
00127 static const Real32
00128 DEF_SPINE[DEF_N_SPINE_POINTS][3] = {{ 0.f, 0.f, 0.f},
00129 { 0.f, 1.f, 0.f}};
00130
00132 static const Real32
00133 DEF_ORIENTATION[DEF_N_ORIENTATION_PARAMS][4] = {{0.f, 0.f, 1.f, 0.f}};
00134
00135
00140 class ExtrusionSurface
00141 {
00142
00143
00144 public:
00145
00146
00169 ExtrusionSurface(const std::vector<Pnt2f> &crossSection,
00170 const std::vector<Quaternion> &orientation,
00171 const std::vector<Vec2f> &scale,
00172 const std::vector<Pnt3f> &spine,
00173 Real32 creaseAngle = 0.f,
00174 bool beginCap = true,
00175 bool endCap = true,
00176 bool ccw = true,
00177 bool convex = true,
00178 bool buildNormal = true,
00179 bool buildTexCoord = true);
00180
00183
00195 GeometryPtr createGeometry(UInt32 nSubDivisions);
00196
00199
00200 protected:
00201
00202
00203
00204 private:
00205
00206
00211 ExtrusionSurface(void);
00212
00216 ExtrusionSurface(const ExtrusionSurface &source);
00217
00219 void operator =(const ExtrusionSurface &source);
00220
00221 #if !defined(OSG_DO_DOC) || defined(OSG_DOC_DEV)
00222
00226 template<class type>
00227 struct vecless
00228 {
00229 inline bool operator () (const type &a, const type &b) const;
00230 };
00231
00232 #endif
00233
00234
00235
00236
00237
00239 struct Vertex
00240 {
00241 Pnt3f position;
00242 Vec3f normal;
00243 Vec2f texCoord;
00244
00246 Vec3f adjFaceNormals[4];
00247 };
00248
00249 typedef std::vector<Pnt3f>::const_iterator Pnt3fConstIt;
00250 typedef std::vector<Matrix>::const_iterator MatrixConstIt;
00251 typedef std::pair<Pnt3fConstIt, Pnt3fConstIt> Pnt3fConstItPair;
00252
00253 typedef std::vector< std::vector< Vertex > > VertexGrid;
00254
00255 typedef std::map<Pnt3f, UInt32, vecless<Pnt3f> > PositionMap;
00256 typedef std::map<Vec3f, UInt32, vecless<Vec3f> > NormalMap;
00257 typedef std::map<Vec2f, UInt32, vecless<Vec2f> > TexCoordMap;
00258
00259
00260
00261
00262
00263
00265 std::vector<Pnt2f> _crossSection;
00266
00268 std::vector<Quaternion> _orientation;
00269
00271 std::vector<Vec2f> _scale;
00272
00274 std::vector<Pnt3f> _spine;
00275
00277 Real32 _creaseAngle;
00278
00280 bool _beginCap;
00281
00283 bool _endCap;
00284
00288 bool _ccw;
00289
00291 bool _convex;
00292
00297 bool _crossSectionClosed;
00298
00300 bool _spineClosed;
00301
00305 bool _spineCollinear;
00306
00308 bool _revolutionSurface;
00309
00311 bool _createNormals;
00312
00314 bool _createTexCoords;
00315
00320 std::vector<Matrix> _transform;
00321
00323 VertexGrid _grid;
00324
00326 PositionMap _posMap;
00327
00331 NormalMap _normalMap;
00332
00336 TexCoordMap _texCoordMap;
00337
00339 UInt32 _vertexCount;
00340
00342 UInt32 _totalVertexCount;
00343
00345 UInt32 _primitiveCount;
00346
00347
00348
00349
00350
00352 inline void calcXAxes(void);
00353
00355 inline void calcYAxes(void);
00356
00358 inline void calcZAxes(void);
00359
00361 void calcTransforms(void);
00362
00367 void calcSweepSurfacePositions(void);
00368
00372 void calcSweepSurfaceFaceNormals(void);
00373
00374
00375
00376
00377 void calcSweepSurfaceTexCoords(void);
00378
00380 void determineTopology(void);
00381
00383 void initGrid(void);
00384
00389 bool verifyInput(void);
00390
00392 void refineCrossSection(UInt32 nTimes);
00393
00395 void refineOrientation(UInt32 nTimes);
00396
00398 void refineScale(UInt32 nTimes);
00399
00401 void refineSpine(UInt32 nTimes);
00402
00410 void storeConvexCap(UInt32 spineIndex,
00411 bool invertNormal,
00412 GeoIndicesUI32Ptr indicesPtr,
00413 GeoPLengthsUI32Ptr lensPtr,
00414 GeoPTypesUI8Ptr typesPtr);
00415
00422 void storeSweepSurfaceWithNormals(GeoIndicesUI32Ptr indicesPtr,
00423 GeoPLengthsUI32Ptr lensPtr,
00424 GeoPTypesUI8Ptr typesPtr);
00425
00431 void storeSweepSurfaceWithoutNormals(GeoIndicesUI32Ptr indicesPtr,
00432 GeoPLengthsUI32Ptr lensPtr,
00433 GeoPTypesUI8Ptr typesPtr);
00434
00438 void storeMaps(GeoPositions3fPtr positionsPtr,
00439 GeoNormals3fPtr normalsPtr,
00440 GeoTexCoords2fPtr texCoordsPtr);
00441
00446 inline void storeVertex(const Vertex &vertex,
00447 GeoIndicesUI32Ptr indicesPtr);
00448
00454 inline void storePrimitive(GLenum type,
00455 GeoPLengthsUI32Ptr lensPtr,
00456 GeoPTypesUI8Ptr typesPtr);
00457
00462 template <typename PType>
00463 inline UInt32
00464 store(PType property,
00465 std::map<PType, UInt32, vecless<PType> > &propertyIndexMap);
00466
00472 template <typename PType>
00473 inline void
00474 store(const PType property,
00475 std::map<PType, UInt32, vecless<PType> > &propertyIndexMap,
00476 GeoIndicesUI32Ptr indicesPtr);
00477
00483 inline Pnt3fConstItPair getPrevAndNextIt(const Pnt3fConstIt &pIt);
00484
00488 inline Vec3f calcNonUnitYAxis(const Pnt3fConstIt &pIt);
00489
00491 inline Vec3f calcNonUnitZAxis(const Pnt3fConstIt &pIt);
00492
00494 inline Vec3f calcXAxis(const MatrixConstIt &pIt);
00495
00501 inline Vec3f calcTriangleFaceNormal(const Pnt3f &a,
00502 const Pnt3f &b,
00503 const Pnt3f &c);
00504
00510 inline Vec3f calcQuadFaceNormal(const Pnt3f &a,
00511 const Pnt3f &b,
00512 const Pnt3f &c,
00513 const Pnt3f &d);
00514
00521 inline void calcVertexNormal(Vertex *vertexPtr,
00522 UInt32 faceIndex);
00523
00524
00525
00526
00527
00528
00529 inline bool isLeft(const Pnt2f &a, const Pnt2f &b);
00530
00531 Real32 computeMinYAbs(const std::vector<Pnt2f> &contour,
00532 Real32 alpha);
00533
00534 Real32 calcBetterRotationAngle(const std::vector<Pnt2f> &contour,
00535 UInt32 nAngles);
00536
00537 bool calcOptimizedContour(const std::vector<Pnt2f> &contour,
00538 const Pnt2f &point,
00539 std::vector<Pnt2f> *optimizedContour);
00540
00541 Int32 calcWindingNumber(const std::vector<Pnt2f> &contour,
00542 const Pnt2f &point);
00543
00544
00545
00546
00547
00548
00549 void storeFaceNormalGeo(GeoIndicesUI32Ptr indicesPtr,
00550 GeoPLengthsUI32Ptr lensPtr,
00551 GeoPTypesUI8Ptr typesPtr);
00552
00553
00554 void storeVertexNormalGeo(GeoIndicesUI32Ptr indicesPtr,
00555 GeoPLengthsUI32Ptr lensPtr,
00556 GeoPTypesUI8Ptr typesPtr);
00557
00558 };
00559
00560
00561 OSG_END_NAMESPACE
00562
00563
00564 #define OSGEXTRUSIONGEOMETRY_HEADER_CVSID "@(#)$Id: $"
00565
00566 #include "OSGExtrusionGeometry.inl"
00567
00568 #endif