00001 /*======================================================================= 00002 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00003 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00004 *** *** 00005 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00006 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00007 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00008 *** *** 00009 *** RESTRICTED RIGHTS LEGEND *** 00010 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00011 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00012 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00013 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00014 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00015 *** *** 00016 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00017 *** BORDEAUX, FRANCE *** 00018 *** ALL RIGHTS RESERVED *** 00019 **=======================================================================*/ 00020 /*======================================================================= 00021 ** Author : David Beilloin (Dec 2010) 00022 **=======================================================================*/ 00023 #ifndef _SO_OFFSCREEN_VOLUME_RENDER_H_ 00024 #define _SO_OFFSCREEN_VOLUME_RENDER_H_ 00025 00026 #include <Inventor/fields/SoSFNode.h> 00027 #include <Inventor/fields/SoSFVec3i32.h> 00028 #include <Inventor/nodes/SoGroup.h> 00029 #include <Inventor/nodes/SoSeparator.h> 00030 #include <Inventor/nodes/SoMatrixTransform.h> 00031 #include <Inventor/nodes/SoOrthographicCamera.h> 00032 #include <Inventor/SbViewportRegion.h> 00033 #include <VolumeViz/nodes/SoVolumeData.h> 00034 #include <Inventor/fields/SoSFMatrix.h> 00035 #include <Inventor/fields/SoSFPath.h> 00036 #include <Inventor/devices/SoGLBufferObject.h> 00037 00038 class SoBufferObject; 00039 class SoCamera; 00040 class SoGLTexture; 00041 class SoFrameBufferObject; 00042 class SoGLQuery; 00043 class SoSceneManager; 00044 00094 class SoOffscreenVolumeRender : public SoNode 00095 { 00096 SO_NODE_ABSTRACT_HEADER(SoOffscreenVolumeRender); 00097 00098 public: 00099 00101 SoOffscreenVolumeRender(); 00102 00104 SoSFNode volumerenderSceneGraph; 00105 00107 SoSFNode bboxSceneGraph; 00108 00110 SoSFVec3i32 boxSize; 00111 00115 SoSFBool trigger; 00116 00120 SoSFFloat opacityThreshold; 00121 00123 enum Components 00124 { 00126 ALPHA, 00128 RGBA 00129 }; 00130 00135 SoSFEnum components; 00136 00141 SbVec3i32 getMaxBoxSize(SoState*state=NULL); 00142 00143 00147 SbBox3d ijkToXyzBox(const SbBox3i32& ijkBox); 00148 00189 SoSFMatrix dataSpaceMatrix; 00190 00198 bool synchronousExtraction(SoSceneManager* sceneManager); 00199 00200 SoEXTENDER_Documented private: 00206 virtual SbBool getNextSubBox(SbBox3i32& box) = 0; 00207 00214 virtual void boxComputed(SoGLRenderAction* action, 00215 SoBufferObject* data, 00216 const SbBox3i32& box 00217 ) = 0; 00218 00219 private: 00220 00222 virtual void GLRender(SoGLRenderAction *action); 00223 00224 private: 00225 00233 SoSFPath volumerenderPath; 00234 00235 // Internal: 00236 static void initClass(); 00237 static void exitClass(); 00238 00239 SbBox3f getBoundingBox(SoAction* action); 00240 00241 void setSliceNumber(SoState* state, int slice); 00242 void beginOffscreenRendering(SoState* state); 00243 void endOffscreenRendering(SoState* state); 00244 virtual void notify(SoNotList *list); 00245 00246 // check that the not is OK to do SoVolumeRender offscreen operation 00247 bool isReady() const; 00248 00249 private: 00251 virtual ~SoOffscreenVolumeRender(); 00252 00255 SbBox3i32 m_currentSubBox; 00256 00259 int m_currentSliceNumberInSubBox; 00260 00264 int m_currentSubBoxNumber; 00265 00266 private: 00267 void adjustCameraClippingPlanes(SoCamera* camera, const SbViewportRegion& viewport, SoNode* sceneRoot, SoNode* cameraSceneGraph); 00268 00269 SoOrthographicCamera* m_camera; 00270 00277 SoRef<SoGLBufferObject> m_pbo[2]; 00278 00281 SoGLTexture* m_texture[2]; 00282 00285 SoFrameBufferObject* m_fbo[2]; 00286 00289 int m_currentPBO; 00290 00293 int m_prevPBO; 00294 00296 SoGLQuery* m_occlusionQuery; 00297 00300 bool m_emptyBox; 00301 00302 SbXfBox3d m_xfExtractionBbox; 00303 00304 private: 00305 // Used to add a scaleFactor to both bboxSceneGraph and volumerenderSceneGraph 00306 // to avoid camera extraction aspectRatio imprecision issues 00307 SoRef<SoSeparator> m_internal_bboxSceneGraph; 00308 SoRef<SoMatrixTransform> m_internal_matrix; 00309 00316 std::vector<bool> m_sliceCleared; 00317 }; 00318 00319 #endif //_SO_OFFSCREEN_VOLUME_RENDER_H_ 00320 00321 00322