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/nodes/SoShaderParameter.h>
00029 #include <Inventor/nodes/SoGroup.h>
00030 #include <Inventor/nodes/SoTextureUnit.h>
00031 #include <Inventor/fields/SoSFBool.h>
00032 #include <Inventor/fields/SoSFBitMask.h>
00033 #include <Inventor/fields/SoSFEnum.h>
00034 #include <Inventor/fields/SoSFFloat.h>
00035 #include <Inventor/fields/SoSFVec3f.h>
00036 #include <Inventor/fields/SoSFInt32.h>
00037 #include <Inventor/SbBox.h>
00038
00039 #include <Inventor/STL/vector>
00040 #include <Inventor/STL/map>
00041
00042 #include <VolumeViz/nodes/SoVolumeShape.h>
00043
00044 #include <VolumeViz/LDM/SoLDMTileID.h>
00045
00046 class SbProjection;
00047 class SoFrameBufferObject;
00048 class SoGLProgramGLSL;
00049 class SoGLTexture;
00050 class SoVRImageSpaceEffects;
00051 class SoLDMTileID;
00052 class SoLdmSubDivisionIsosurfacePolicy;
00053 class SoLdmSubDivisionPolicy;
00054 class SoLdmSubDivisionTransferFunctionPolicy;
00055 class SoShaderProgram;
00056 class SoVolumeGroup;
00057 class SoVolumeIsosurface;
00058 class SoVolumeRenderInterface;
00059 class SoVolumeRenderRaycast;
00060 class SoVolumeRenderLdm;
00061 class SoVolumeRenderLdm;
00062 class SoVolumeRenderPaging;
00063 class SoVolumeRenderingQuality;
00064 class SoVolumeStateVr;
00065 class SoVolumeRenderDetail;
00066 class SoNodeSensor;
00067 class SoVolumeOffscreenImpl;
00068 class SoProgressIndicator;
00069
00070 #ifdef _WIN32
00071 #pragma warning( push )
00072 #pragma warning(disable:4251)
00073 #endif
00074
00754 class SoVolumeRender : public SoVolumeShape {
00755 SO_NODE_HEADER( SoVolumeRender );
00756
00757 public:
00758
00762 enum LowResMode
00763 {
00767 DECREASE_NONE = 1,
00774 DECREASE_SLICES = 1 << 1,
00779 DECREASE_SCREEN_RESOLUTION = 1 << 2
00780 } ;
00781
00782
00784 enum NumSlicesControl {
00789 ALL,
00794 MANUAL,
00817 AUTOMATIC,
00825 MAIN_AXIS
00826 };
00827
00840 SoSFEnum numSlicesControl;
00841
00850 SoSFInt32 numSlices;
00851
00869 SoSFBitMask lowResMode;
00870
00878 SoSFInt32 lowScreenResolutionScale;
00879
00880
00897 SoSFBool subdivideTile;
00898
00909 SoSFBool fixedNumSlicesInRoi;
00910
00928 SoSFInt32 projectedTileSubdivision;
00929
00939 SoSFBool opacityCorrection;
00940
00945 enum RenderMode
00946 {
00948 VOLUME_RENDERING = 0,
00949
00952 MIN_INTENSITY_PROJECTION,
00953
00956 MAX_INTENSITY_PROJECTION,
00957
00964 SUM_INTENSITY_PROJECTION,
00965
00972 AVERAGE_INTENSITY_PROJECTION
00973 };
00974
01005 SoSFEnum renderMode;
01006
01011 enum SamplingAlignment
01012 {
01014 VIEW_ALIGNED = 0,
01016 DATA_ALIGNED,
01019 BOUNDARY_ALIGNED,
01038 SMOOTH_BOUNDARY_ALIGNED,
01039 };
01040
01068 SoSFEnum samplingAlignment;
01069
01086 SoSFFloat opacityThreshold;
01087
01091 SoVolumeRender();
01092
01108 void setRenderProgress(SoProgressIndicator* ps) { m_renderProgress = ps; }
01109
01113 enum AbortCode {
01117 CONTINUE,
01122 ABORT,
01126 SKIP
01127 };
01128
01132 typedef AbortCode SoVolumeRenderAbortCB(int totalElems, int thisElem, void *userData);
01133
01153 void setAbortCallback( SoVolumeRenderAbortCB *func, void *userData = NULL);
01154
01155
01156 #if 1 SoDEPRECATED
01176 SoSFBool lighting;
01177 SoDEPRECATED
01183 SoSFVec3f lightDirection;
01184 SoDEPRECATED
01190 SoSFFloat lightIntensity;
01191
01192 #endif
01194 #if 1 SoDEPRECATED
01203 SoSFBool viewAlignedSlices;
01204
01205 #endif
01207
01208 private:
01210 virtual void computeBBox(SoAction *, SbBox3f &box, SbVec3f ¢er);
01211
01213 virtual void rayPick(SoRayPickAction *action);
01214
01215
01216 private:
01217
01219 static void initClass();
01220
01222 static void exitClass();
01223
01227 SoVolumeRenderingQuality* getVolumeRenderingQuality( SoState* state ) const;
01228
01232 SoVolumeOffscreenImpl* getVolumeOffscreenImpl() const;
01233
01234 #if 1 SoDEPRECATED
01237
01238 #endif
01242 bool needOivDepth(SoState* state, GLenum& internalDepthFormat);
01243
01248 bool needRttColor(SoState* state, GLenum& internalColorFormat) const;
01249
01252 bool needRttEdgeDetect(SoState* state, GLenum& internalFormat) const;
01253
01256 bool needRttBoundaryDepth(SoState* state, GLenum& internalFormat) const;
01257
01260 bool needRttBoundaryColor(SoState* state, GLenum& internalFormat) const;
01261
01263 SamplingAlignment getSamplingAlignment(SoState* state) const;
01264
01266 void removeDsFromRegList(SoDataSet* pDs);
01267
01269 virtual void notify(SoNotList *list);
01270
01274 void onUserInteractionChange(SoState*state, bool stopMoving);
01275
01276
01277 private:
01278
01279 virtual ~SoVolumeRender();
01280
01281 void createVolumeRender( SoState* state );
01282
01283 void generatePrimitives(SoAction *action);
01284
01285 void doRendering(SoGLRenderAction *action);
01286
01287 void setupVolumeRenderInterface(SoState* state);
01288
01289 SoDetail *createTriangleDetail(SoRayPickAction *,
01290 const SoPrimitiveVertex *v1,
01291 const SoPrimitiveVertex *,
01292 const SoPrimitiveVertex *,
01293 SoPickedPoint *);
01294
01299 void beginOffscreenRendering( SoGLRenderAction* action );
01300
01305 void endOffscreenRendering( SoGLRenderAction* action );
01306
01310 void setupFrontToBackGlState(SoState* state);
01311
01316 SbBool shouldGLRender(SoGLRenderAction *renderAction, SbBool isPointsOrLines);
01317
01318
01319 SoINTERNAL private:
01320
01322 virtual void ldmAction(SoLdmValuationAction* action);
01323
01324
01325 private:
01326
01327 #if 1 SoDEPRECATED
01329 SoSFBool useEarlyZ;SoDEPRECATED
01331 SoSFInt32 numEarlyZPasses;SoDEPRECATED
01333 SoSFBool gpuVertexGen;
01334 #endif
01337 static SoVolumeData* getVolumeData(SoState* state);
01338
01340 void fillDetail(SoRayPickAction* rpa, SoVolumeRenderDetail* detail, SoVolumeData* vd);
01341
01342
01344 static bool canSubdivideTiles(SoState* state);
01345
01347 bool isRaycastingEnabled(SoState* state) const;
01348
01349 SoVolumeRenderAbortCB *m_abortCBfunc;
01350 void *m_abortCBuserData;
01351 void GLRenderTex2D3D(SoGLRenderAction* action);
01352
01356 void useOffscreenRendering(SoGLRenderAction* action);
01357
01361 void initInternalShaders();
01362
01363 void GLRenderTex2D3DLDMSortedTiles(SoState* state, const SbMatrix& mpvmx,
01364 int Zaxis, float sliceSpacing, float sliceOffset,
01365 const SoLDM::TileIdVector& tiles,
01366 const std::vector<SbBox3i32>& boxes,
01367 const SbVec3f& eyeAxis, int textype,
01368 const SbVec3f& scale);
01369 void GLRenderTex2D3DLDMUnsortedTiles(SoState* state, const SbMatrix& mpvmx,
01370 int Zaxis, float sliceSpacing, float sliceOffset,
01371 const SoLDM::TileIdVector& tiles,
01372 const SbBox3i32 * const boxes, int numBoxes,
01373 const SbVec3f& eyeAxis, int textype, int numSliceToDraw,
01374 float min, float max,
01375 const SbVec3f& scale);
01376
01377 void setupDepthPeelingTextures(SoGLRenderAction *action);
01378
01380 SoVRImageSpaceEffects* m_imageSpaceEffects;
01381
01388 int m_vpScale;
01389
01392 int m_lowScreenResScale;
01393
01394 SoShaderParameter1i *m_opacityTex;
01395 SoGLProgramGLSL* m_binaryOpacityComposeShader;
01396
01397 SoShaderProgram* m_writeFragShader;
01398
01399 SoVolumeIsosurface* m_volumeIsosurface;
01400
01404 void deleteShadersFboTextures();
01405
01409 void updateLowResScale( SoState* state );
01410
01414 void registerCtxId(const SoLDM::DsVector &dsVector, int ctxId);
01415
01419 void unregisterCtxId(const SoLDM::DsVector &dsVector, int ctxId);
01420
01422 bool m_useLowResMove;
01423
01425 bool m_useLowNumSliceMove;
01426
01427 SoVolumeRenderLdm* m_vriLdm;
01428 SoVolumeRenderRaycast* m_vriRaycast;
01429 SoVolumeRenderInterface* m_vri;
01430
01431 bool m_frontToBackComposition;
01432
01433
01434 SoLDM::DsVector m_prevDsList;
01435
01436
01437 static void volDataDeleteCB(void* data, SoSensor *sensor);
01438
01439
01440 int m_prevRegisteredCtxId;
01441
01442 SoVolumeStateVr* m_vs;
01443
01444 SoProgressIndicator* m_renderProgress;
01445 SoVolumeOffscreenImpl* m_volumeOffscreenImpl;
01446
01447
01448 std::map<SoDataSet*, SoNodeSensor*> m_mapDsSensor;
01449
01450 friend class SoVolumeRenderInterface;
01451 friend class SoVolumeRenderLdm;
01452 friend class SoVolumeRenderRaycast;
01453
01454 SoRef<SoGroup> m_depthPeelingSG;
01455 SoRef<SoGroup> m_depthPeelingColorTexGroup;
01456 SoRef<SoTextureUnit> m_depthPeelingColorTexUnit;
01457 SoRef<SoGroup> m_depthPeelingDepthTexGroup;
01458 SoRef<SoTextureUnit> m_depthPeelingDepthTexUnit;
01459 };
01460
01461 #if defined(_WIN32)
01462 #pragma warning( pop )
01463 #endif
01464
01465 #endif // _SO_VOLUME_RENDER_
01466
01467
01468