00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _SO_VOLUME_RENDER_
00024 #define _SO_VOLUME_RENDER_
00025
00026 #include <Inventor/caches/SoCache.h>
00027 #include <Inventor/nodes/SoShape.h>
00028 #include <Inventor/fields/SoSFBool.h>
00029 #include <Inventor/fields/SoSFBitMask.h>
00030 #include <Inventor/fields/SoSFEnum.h>
00031 #include <Inventor/fields/SoSFFloat.h>
00032 #include <Inventor/fields/SoSFVec3f.h>
00033 #include <Inventor/fields/SoSFInt32.h>
00034 #include <Inventor/SbBox.h>
00035
00036 #include <Inventor/STL/vector>
00037 #include <Inventor/STL/map>
00038
00039 #include <VolumeViz/nodes/SoVolumeShape.h>
00040
00041 #include <VolumeViz/LDM/SoLDMTileID.h>
00042
00043 class SbProjection;
00044 class SoFrameBufferObject;
00045 class SoGLProgramGLSL;
00046 class SoGLTexture;
00047 class SoVRImageSpaceEffects;
00048 class SoLDMTileID;
00049 class SoLdmSubDivisionIsosurfacePolicy;
00050 class SoLdmSubDivisionPolicy;
00051 class SoLdmSubDivisionTransferFunctionPolicy;
00052 class SoShaderParameter1f;
00053 class SoShaderParameter1i;
00054 class SoShaderParameter2f;
00055 class SoShaderProgram;
00056 class SoVolumeGroup;
00057 class SoVolumeIsosurface;
00058 class SoVolumeRenderInterface;
00059 class SoVolumeRenderLdm;
00060 class SoVolumeRenderPaging;
00061 class SoVolumeRenderingQuality;
00062 class SoVolumeStateVr;
00063 class SoVolumeRenderDetail;
00064 class SoNodeSensor;
00065 class SoVolumeOffscreenImpl;
00066 class SoProgressIndicator;
00067
00068 #ifdef _WIN32
00069 #pragma warning( push )
00070 #pragma warning(disable:4251)
00071 #endif
00072
00772 class SoVolumeRender : public SoVolumeShape {
00773 SO_NODE_HEADER( SoVolumeRender );
00774
00775 public:
00776
00780 enum LowResMode
00781 {
00785 DECREASE_NONE = 1,
00792 DECREASE_SLICES = 1 << 1,
00797 DECREASE_SCREEN_RESOLUTION = 1 << 2
00798 } ;
00799
00800
00802 enum NumSlicesControl {
00807 ALL,
00812 MANUAL,
00835 AUTOMATIC,
00843 MAIN_AXIS
00844 };
00845
00863 SoSFEnum numSlicesControl;
00864
00873 SoSFInt32 numSlices;
00874
00892 SoSFBitMask lowResMode;
00893
00901 SoSFInt32 lowScreenResolutionScale;
00902
00903 #if 1 SoDEPRECATED
00920 SoSFBool useEarlyZ;
00921 SoDEPRECATED
00932 SoSFInt32 numEarlyZPasses;
00933 SoDEPRECATED
00945 SoSFBool gpuVertexGen;
00946 #endif
00964 SoSFBool subdivideTile;
00965
00976 SoSFBool fixedNumSlicesInRoi;
00977
00994 SoSFInt32 projectedTileSubdivision;
00995
01005 SoSFBool opacityCorrection;
01006
01011 enum RenderMode
01012 {
01014 VOLUME_RENDERING = 0,
01015
01018 MIN_INTENSITY_PROJECTION,
01019
01022 MAX_INTENSITY_PROJECTION,
01023
01030 SUM_INTENSITY_PROJECTION,
01031
01038 AVERAGE_INTENSITY_PROJECTION
01039 };
01040
01071 SoSFEnum renderMode;
01072
01077 enum SamplingAlignment
01078 {
01080 VIEW_ALIGNED = 0,
01082 DATA_ALIGNED,
01085 BOUNDARY_ALIGNED,
01104 SMOOTH_BOUNDARY_ALIGNED,
01105 };
01106
01137 SoSFEnum samplingAlignment;
01138
01155 SoSFFloat opacityThreshold;
01156
01160 SoVolumeRender();
01161
01177 void setRenderProgress(SoProgressIndicator* ps) { m_renderProgress = ps; }
01178
01182 enum AbortCode {
01186 CONTINUE,
01191 ABORT,
01195 SKIP
01196 };
01197
01201 typedef AbortCode SoVolumeRenderAbortCB(int totalElems, int thisElem, void *userData);
01202
01222 void setAbortCallback( SoVolumeRenderAbortCB *func, void *userData = NULL);
01223
01224
01225 #if 1 SoDEPRECATED
01245 SoSFBool lighting;
01246 SoDEPRECATED
01252 SoSFVec3f lightDirection;
01253 SoDEPRECATED
01259 SoSFFloat lightIntensity;
01260
01261 #endif
01263 #if 1 SoDEPRECATED
01272 SoSFBool viewAlignedSlices;
01273
01274 #endif
01276
01277 private:
01279 virtual void computeBBox(SoAction *, SbBox3f &box, SbVec3f ¢er);
01280
01282 virtual void rayPick(SoRayPickAction *action);
01283
01284
01285 private:
01286
01288 static void initClass();
01289
01291 static void exitClass();
01292
01296 SoVolumeRenderingQuality* getVolumeRenderingQuality( SoState* state ) const;
01297
01301 SoVolumeOffscreenImpl* getVolumeOffscreenImpl() const;
01302
01303 #if 1 SoDEPRECATED
01311 static int getVolumeRaycastingSlabbingMode();
01312 SoDEPRECATED
01315 bool isSlabbingEnabled(SoState* state) const;
01316
01317 #endif
01322 bool needOivDepth(SoState* state, GLenum& internalDepthFormat);
01323
01328 bool needRttColor(SoState* state, GLenum& internalColorFormat) const;
01329
01332 bool needRttEdgeDetect(SoState* state, GLenum& internalFormat) const;
01333
01336 bool needRttBoundaryDepth(SoState* state, GLenum& internalFormat) const;
01337
01340 bool needRttBoundaryColor(SoState* state, GLenum& internalFormat) const;
01341
01343 SamplingAlignment getSamplingAlignment(SoState* state) const;
01344
01346 void removeDsFromRegList(SoDataSet* pDs);
01347
01348
01349 private:
01350
01351 virtual ~SoVolumeRender();
01352
01353 void createVolumeRender( SoState* state );
01354
01355 void generatePrimitives(SoAction *action);
01356
01357 void doRendering(SoGLRenderAction *action);
01358
01359 void setupVolumeRenderInterface(SoState* state);
01360
01361 SoDetail *createTriangleDetail(SoRayPickAction *,
01362 const SoPrimitiveVertex *v1,
01363 const SoPrimitiveVertex *,
01364 const SoPrimitiveVertex *,
01365 SoPickedPoint *);
01366
01371 void beginOffscreenRendering(SoGLRenderAction *action);
01372
01377 void endOffscreenRendering( SoState* state );
01378
01382 void setupFrontToBackGlState();
01383
01388 SbBool shouldGLRender(SoGLRenderAction *renderAction, SbBool isPointsOrLines);
01389
01391 virtual void notify(SoNotList *list);
01392
01393 SoINTERNAL private:
01395 virtual void ldmAction(SoLdmValuationAction* action);
01396
01397
01398 private:
01400 static SoVolumeData* getVolumeData(SoState* state);
01401
01403 void fillDetail(SoRayPickAction* rpa, SoVolumeRenderDetail* detail, SoVolumeData* vd);
01404
01405
01407 static bool canSubdivideTiles(SoState* state);
01408
01410 bool isRaycastingEnabled(SoState* state) const;
01411
01415 bool m_useEarlyZ;
01416
01417 SoVolumeRenderAbortCB *m_abortCBfunc;
01418 void *m_abortCBuserData;
01419 void GLRenderTex2D3D(SoGLRenderAction* action);
01420
01424 void onViewportChange(SoState* state);
01425
01429 void onUserInteractionChange(SoState*state, bool stopMoving);
01430
01434 void useOffscreenRendering(SoGLRenderAction* action);
01435
01439 void initInternalShaders();
01440
01441 void GLRenderTex2D3DLDMSortedTiles(SoState* state, const SbMatrix& mpvmx,
01442 int Zaxis, float sliceSpacing, float sliceOffset,
01443 const SoLDM::TileIdVector& tiles,
01444 const std::vector<SbBox3i32>& boxes,
01445 const SbVec3f& eyeAxis, int textype,
01446 const SbVec3f& scale);
01447 void GLRenderTex2D3DLDMUnsortedTiles(SoState* state, const SbMatrix& mpvmx,
01448 int Zaxis, float sliceSpacing, float sliceOffset,
01449 const SoLDM::TileIdVector& tiles,
01450 const SbBox3i32 * const boxes, int numBoxes,
01451 const SbVec3f& eyeAxis, int textype, int numSliceToDraw,
01452 float min, float max,
01453 const SbVec3f& scale);
01454
01455 void checkEarlyZ( SoState* state );
01456
01457 void setupDepthPeelingTextures(SoGLRenderAction *action);
01458
01460 SoVRImageSpaceEffects* m_imageSpaceEffects;
01461
01468 int m_vpScale;
01469
01472 int m_lowScreenResScale;
01473
01474 SoShaderProgram* m_earlyZShader;
01475 SoShaderParameter1i *m_opacityTex;
01476 SoGLProgramGLSL* m_binaryOpacityComposeShader;
01477
01478 SoShaderProgram* m_earlyZInBBoxShader;
01479 SoShaderProgram* m_writeFragShader;
01480
01481 SoShaderParameter2f* m_vpSizeParameter;
01482 SoShaderParameter1f* m_vvizZNear;
01483
01484 size_t m_numEarlyPasses;
01485
01486 SoVolumeIsosurface* m_volumeIsosurface;
01487
01491 void deleteShadersFboTextures();
01492
01496 void updateLowResScale( SoState* state );
01497
01501 void initTextureUnits(SoGLRenderAction *action);
01502
01506 void registerCtxId(const SoLDM::DsVector &dsVector, int ctxId);
01507
01511 void unregisterCtxId(const SoLDM::DsVector &dsVector, int ctxId);
01512
01514 bool m_useLowResMove;
01515
01517 bool m_useLowNumSliceMove;
01518
01519 bool m_showEarlyZ;
01520
01521 SoVolumeRenderInterface* m_vri;
01522
01523 bool m_frontToBackComposition;
01524
01525
01526 SoLDM::DsVector m_prevDsList;
01527
01528
01529 static void volDataDeleteCB(void* data, SoSensor *sensor);
01530
01531
01532 int m_prevRegisteredCtxId;
01533
01534 SoVolumeStateVr* m_vs;
01535
01536 SoProgressIndicator* m_renderProgress;
01537 SoVolumeOffscreenImpl* m_volumeOffscreenImpl;
01538
01539
01540 std::map<SoDataSet*, SoNodeSensor*> m_mapDsSensor;
01541
01543 static int s_volumeRaycastSlabbingMode;
01544
01545 friend class SoVolumeRenderInterface;
01546 friend class SoVolumeRenderLdm;
01547 friend class SoVolumeRenderRaycast;
01548
01549 };
01550
01551 #if defined(_WIN32)
01552 #pragma warning( pop )
01553 #endif
01554
01555 #endif // _SO_VOLUME_RENDER_
01556
01557
01558