00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined _SO_CSG_SHAPE_H_
00025 #define _SO_CSG_SHAPE_H_
00026
00027 #include <Inventor/nodes/SoShape.h>
00028 #include <Inventor/fields/SoSFNode.h>
00029 #include <Inventor/fields/SoSFEnum.h>
00030 #include <Inventor/SoPrimitiveVertex.h>
00031 #include <Inventor/threads/SbThreadMutex.h>
00032
00033 class SoFaceSet;
00034 class SoCallbackAction;
00035 class SoTransformation;
00036 class SoCache;
00037 class CachedElement;
00038
00040 namespace GetCacheDeps {
00041 class CachedElementsVector;
00042 }
00045
00129 class SoCSGShape : public SoShape
00130 {
00131 SO_NODE_HEADER( SoCSGShape );
00132
00133 public:
00134
00136 SoCSGShape();
00137
00139 enum CsgOperationType
00140 {
00142 ADD,
00144 SUB,
00146 INTERSECTION,
00148 LEFT_ONLY,
00150 RIGHT_ONLY,
00152 NOTHING,
00154 ALL
00155 };
00156
00158 SoSFNode leftOperand;
00159
00161 SoSFNode rightOperand;
00162
00166 SoSFEnum csgOperation;
00167
00172 enum CsgStatus
00173 {
00175 CSG_NO_ERROR,
00177 CSG_LIB_NOT_AVAILABLE,
00179 CSG_ERROR,
00180 };
00181
00199 void setMaxAttempt( int maxAttempt );
00200
00205 static void setRescueOperation( CsgOperationType op );
00206
00211 CsgStatus getStatus();
00212
00213 private:
00214
00215
00217 virtual void doAction( SoAction *action );
00218
00220 virtual void callback( SoCallbackAction *action );
00221
00223 virtual void GLRender( SoGLRenderAction *action );
00224
00226 virtual void rayPick( SoRayPickAction *action );
00227
00229 virtual void computeBBox( SoAction *action, SbBox3f &box, SbVec3f ¢er );
00230
00232 virtual void computeBBox(SoAction *action, SbXfBox3d &box, SbVec3d ¢er);
00233
00235 virtual void getPrimitiveCount( SoGetPrimitiveCountAction *action );
00236
00237 private:
00238
00240 static void initClass();
00241
00243 static void exitClass();
00244
00246 virtual void notify( SoNotList *list );
00247
00248 private:
00250 virtual ~SoCSGShape();
00251
00253 virtual void generatePrimitives ( SoAction *action );
00254
00255 private:
00256
00266 void collapse(const std::vector<SoPrimitiveVertex>& points, float eps, std::vector<SbVec3f*>& indexedPoints, std::vector<SbVec3f>& remainingPoints) const;
00267
00270 void shake(std::vector<SbVec3f>& points, float shift) const;
00271
00275 SoFaceSet* getShape(SoState* state);
00276
00282 bool getCacheDependencies(SoAction* action, SoNode* node, GetCacheDeps::CachedElementsVector& elements);
00283
00285 void updateCache( SoState *state, const GetCacheDeps::CachedElementsVector& dependencies, SoCache*& cache );
00286
00288 bool isCacheValid( SoState *state, SoCache* cache ) const;
00289
00294 bool generateTriangles(SoAction* action, SoNode* node, std::vector<SoPrimitiveVertex>& triangles, SoTransformation* transform = NULL );
00295
00302 void updateResult();
00303
00305 static void pushTriangleCallback(void* vec,
00306 SoCallbackAction* cb,
00307 const SoPrimitiveVertex* v1,
00308 const SoPrimitiveVertex* v2,
00309 const SoPrimitiveVertex* v3);
00310
00315 static CsgStatus computeCSG(const std::vector<SoPrimitiveVertex>& trianglesLeft,
00316 const std::vector<SoPrimitiveVertex>& trianglesRight,
00317 const CsgOperationType& operation,
00318 std::vector<SoPrimitiveVertex>& trianglesResult);
00319
00320
00323 std::vector<SoPrimitiveVertex> m_trianglesLeft;
00324
00327 std::vector<SoPrimitiveVertex> m_trianglesRight;
00328
00331 SoCache* m_leftCache;
00332
00335 SoCache* m_rightCache;
00336
00339 SoCache* m_resultCache;
00340
00347 bool m_expressedInWolrdSpace;
00348
00354 std::vector<SoPrimitiveVertex> m_triangles;
00355
00365 SoFaceSet* m_shape;
00366
00369 CsgStatus m_csgStatus;
00370
00372 mutable SbThreadMutex m_mutex;
00373
00375 int m_maxAttempt;
00376
00378 static CsgOperationType s_rescueOp;
00379
00380 };
00381
00382 #endif // _SO_CSG_SHAPE_H_
00383
00384
00385