Open Inventor Reference
MeVis/ThirdParty/Sources/Inventor/inventor/lib/database/include/Inventor/nodes/SoShape.h
Go to the documentation of this file.
00001 /*
00002  *
00003  *  Copyright (C) 2000 Silicon Graphics, Inc.  All Rights Reserved. 
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Lesser General Public
00007  *  License as published by the Free Software Foundation; either
00008  *  version 2.1 of the License, or (at your option) any later version.
00009  *
00010  *  This library is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  Lesser General Public License for more details.
00014  *
00015  *  Further, this software is distributed without any warranty that it is
00016  *  free of the rightful claim of any third person regarding infringement
00017  *  or the like.  Any license provided herein, whether implied or
00018  *  otherwise, applies only to this software file.  Patent licenses, if
00019  *  any, provided herein do not apply to combinations of this program with
00020  *  other software, or any other product whatsoever.
00021  * 
00022  *  You should have received a copy of the GNU Lesser General Public
00023  *  License along with this library; if not, write to the Free Software
00024  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  *
00026  *  Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
00027  *  Mountain View, CA  94043, or:
00028  * 
00029  *  http://www.sgi.com 
00030  * 
00031  *  For further information regarding this notice, see: 
00032  * 
00033  *  http://oss.sgi.com/projects/GenInfo/NoticeExplan/
00034  *
00035  */
00036 
00037 
00038 /*
00039  * Copyright (C) 1990,91   Silicon Graphics, Inc.
00040  *
00041  _______________________________________________________________________
00042  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00043  |
00044  |   $Revision: 1.1.1.1 $
00045  |
00046  |   Description:
00047  |      This file defines the SoShape node class.
00048  |
00049  |   Author(s)          : Paul S. Strauss
00050  |
00051  ______________  S I L I C O N   G R A P H I C S   I N C .  ____________
00052  _______________________________________________________________________
00053  */
00054 
00055 #ifndef  _SO_SHAPE_
00056 #define  _SO_SHAPE_
00057 
00058 #include <Inventor/SbLinear.h>
00059 #include <Inventor/nodes/SoSubNode.h>
00060 
00061 #include <Inventor/system/SbOpenGLU.h>
00062 
00063 class SoCube;
00064 class SoDetail;
00065 class SoFaceDetail;
00066 class SoMaterialBundle;
00067 class SoPickedPoint;
00068 class SoPointDetail;
00069 class SoPrimitiveVertex;
00070 class SoState;
00071 
00072 
00074 #ifndef gluTESSELATOR
00075 #if (defined(__glu_h__) || defined(GLU_H)) && defined(GLU_VERSION_1_2)
00076 #define gluTESSELATOR  GLUtesselator
00077 #else
00078 #define gluTESSELATOR  GLUtriangulatorObj
00079 extern "C" struct GLUtriangulatorObj;
00080 #endif
00081 #endif
00082 
00083 
00084 
00087 
00098 
00099 
00100 class INVENTOR_API SoShape : public SoNode {
00101 
00102     SO_NODE_ABSTRACT_HEADER(SoShape);
00103 
00104   public:
00106     virtual SbBool      affectsState() const;
00107 
00108   SoINTERNAL public:
00109     static void         initClass();
00110 
00113     enum TriangleShape {
00114         TRIANGLE_STRIP,
00115         TRIANGLE_FAN,
00116         TRIANGLES,
00117         POLYGON
00118     };
00119 
00120   SoEXTENDER public:
00123     virtual void        getBoundingBox(SoGetBoundingBoxAction *action);
00124 
00127     virtual void        GLRender(SoGLRenderAction *action);
00128 
00132     virtual void        rayPick(SoRayPickAction *action);
00133 
00136     virtual void        callback(SoCallbackAction *action);
00137 
00142     static void         getScreenSize(SoState *state,
00143                                       const SbBox3f &boundingBox,
00144                                       SbVec2s &rectSize);
00145 
00151     virtual void        computeBBox(SoAction *action, SbBox3f &box,
00152                                     SbVec3f &center) = 0;
00153   protected:
00154 
00156     SoShape();
00157 
00161     virtual void        generatePrimitives(SoAction *action) = 0;
00162 
00166     virtual SbBool      shouldGLRender(SoGLRenderAction *action);
00167 
00170     SbBool              shouldRayPick(SoRayPickAction *action);
00171 
00176     void                beginSolidShape(SoGLRenderAction *action);
00177     void                endSolidShape(SoGLRenderAction *action);
00178 
00185     void                computeObjectSpaceRay(SoRayPickAction *action);
00186     void                computeObjectSpaceRay(SoRayPickAction *action,
00187                                               const SbMatrix &matrix);
00188 
00196     virtual SoDetail *  createTriangleDetail(SoRayPickAction *action,
00197                                              const SoPrimitiveVertex *v1,
00198                                              const SoPrimitiveVertex *v2,
00199                                              const SoPrimitiveVertex *v3,
00200                                              SoPickedPoint *pp);
00201     virtual SoDetail *  createLineSegmentDetail(SoRayPickAction *action,
00202                                                 const SoPrimitiveVertex *v1,
00203                                                 const SoPrimitiveVertex *v2,
00204                                                 SoPickedPoint *pp);
00205     virtual SoDetail *  createPointDetail(SoRayPickAction *action,
00206                                           const SoPrimitiveVertex *v,
00207                                           SoPickedPoint *pp);
00208 
00215     void                invokeTriangleCallbacks(SoAction *action,
00216                                                 const SoPrimitiveVertex *v1,
00217                                                 const SoPrimitiveVertex *v2,
00218                                                 const SoPrimitiveVertex *v3);
00219     void                invokeLineSegmentCallbacks(SoAction *action,
00220                                                   const SoPrimitiveVertex *v1,
00221                                                   const SoPrimitiveVertex *v2);
00222     void                invokePointCallbacks(SoAction *action,
00223                                              const SoPrimitiveVertex *v);
00224 
00245     void                beginShape(SoAction *action, TriangleShape shapeType,
00246                                    SoFaceDetail *faceDetail = NULL);
00247     void                shapeVertex(const SoPrimitiveVertex *v);
00248     void                endShape();
00249 
00250     virtual ~SoShape();
00251     
00254     void                GLRenderBoundingBox(SoGLRenderAction *action);
00255 
00256   private:
00257 
00262     static SoGetBoundingBoxAction       *bboxAct;
00263     static SoCube                       *bboxCube;
00264 
00268     static SbBool       sendTexCoords;  
00269     static SoMaterialBundle *matlBundle;
00270 
00272     static TriangleShape        primShapeType;  
00273     static SoFaceDetail *faceDetail;    
00274     static int          nestLevel;      
00275     static SoAction     *primAction;    
00276     static int          primVertNum;    
00277     static int          polyVertNum;    
00278     static SoShape      *primShape;     
00279 
00282     static SoPrimitiveVertex *primVerts;        
00283     static SoPointDetail     *vertDetails;      
00284     static SoPrimitiveVertex *polyVerts;        
00285     static SoPointDetail     *polyDetails;      
00286     static int numPolyVertsAllocated;   
00287     static GLUtriangulatorObj  *tobj;   
00288     
00291     void                GLRenderTriangle(SoGLRenderAction *action,
00292                                          const SoPrimitiveVertex *v1,
00293                                          const SoPrimitiveVertex *v2,
00294                                          const SoPrimitiveVertex *v3);
00295     void                GLRenderLineSegment(SoGLRenderAction *action,
00296                                             const SoPrimitiveVertex *v1,
00297                                             const SoPrimitiveVertex *v2);
00298     void                GLRenderPoint(SoGLRenderAction *action,
00299                                       const SoPrimitiveVertex *v);
00300 
00303     void                rayPickTriangle(SoRayPickAction *action,
00304                                         const SoPrimitiveVertex *v1,
00305                                         const SoPrimitiveVertex *v2,
00306                                         const SoPrimitiveVertex *v3);
00307     void                rayPickLineSegment(SoRayPickAction *action,
00308                                            const SoPrimitiveVertex *v1,
00309                                            const SoPrimitiveVertex *v2);
00310     void                rayPickPoint(SoRayPickAction *action,
00311                                      const SoPrimitiveVertex *v);
00312 
00315     void                rayPickBoundingBox(SoRayPickAction *action);
00316 
00318     void                triangleVertex(const SoPrimitiveVertex *v,
00319                                        int vertToReplace);
00320 
00322     void                allocateVerts();
00323 
00325     static void CALLBACK beginCB(GLenum primType);
00326     static void CALLBACK vtxCB(void *vertex);
00327     static void CALLBACK endCB();
00328     static void CALLBACK errorCB(GLenum err);
00329 };
00330 
00331 #endif /* _SO_SHAPE_ */