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_DATA_
00024 #define _SO_VOLUME_DATA_
00025
00026 #ifdef _MSC_VER
00027 #pragma warning( push )
00028 #pragma warning(disable:4251)
00029 #endif
00030
00031 #include <Inventor/STL/map>
00032 #include <Inventor/STL/vector>
00033
00034 #include <Inventor/SbBox.h>
00035 #include <Inventor/SbPList.h>
00036 #include <Inventor/fields/SoSFBool.h>
00037 #include <Inventor/fields/SoSFEnum.h>
00038 #include <Inventor/fields/SoSFMemObj.h>
00039 #include <Inventor/fields/SoSFString.h>
00040 #include <Inventor/fields/SoSFUShort.h>
00041 #include <Inventor/fields/SoSFInt32.h>
00042 #include <Inventor/fields/SoSFArray3D.h>
00043
00044 #include <LDM/SoLDMDataAccess.h>
00045 #include <LDM/SoLDMMediator.h>
00046 #include <LDM/SoLDMTileID.h>
00047 #include <LDM/nodes/SoDataSet.h>
00048 #include <LDM/nodes/SoTransferFunction.h>
00049 #include <LDM/readers/SoVolumeReader.h>
00050
00051 #include <VolumeViz/nodes/SoVolumeRendering.h>
00052
00053 class SoGLRenderAction;
00054 class SoCallbackAction;
00055 class SoWriteAction;
00056 class SoVolumeReader;
00057 class SoCache;
00058 class SoNodeDependencies;
00059 class SoState;
00060 class SoGLVolCacheList;
00061 class SoVolumeHistogram;
00062 class SoDataCompositor;
00063 class SoVolumeShader;
00064
00065
00066 class SoLDMTileManager;
00067 class SoLDMTileVisitor;
00068 class SoLDMNodeFrontManager;
00069 class SoLDMTextureManager;
00070 class SoLDMGeometry;
00071 class SoLDMResourceManager;
00072
00073
00074 class SoDataExtract;
00075 class LDMDefaultSliceAccessor;
00076 class SoVolumeData;
00077
00715 class SoVolumeData : public SoDataSet, public SoVolumeRendering
00716 {
00717 SO_NODE_HEADER( SoVolumeData );
00718
00719 public:
00720 using SoDataSet::getTexData;
00721
00722
00723 typedef SoLDMDataAccess LDMDataAccess;
00724 typedef SoLDMMediator::LDMManagerAccess LDMManagerAccess;
00725 typedef ::LDMResourceParameter LDMResourceParameter;
00726
00730 SoVolumeData();
00731
00757 SoSFBool usePalettedTexture;
00758
00759
00769 SoSFBool useSharedPalettedTexture;
00770
00779 SoSFBool useExtendedData;
00780
00805 SoSFArray3D data;
00806
00823 SoSFBool dataRGBA;
00824
00826 virtual SbBool getMinMax( int64_t &min, int64_t &max);
00827
00829 virtual SbBool getMinMax( double &min, double &max);
00830
00872
00873
00874
00875 SbBool getHistogram( int &length, int64_t* &histogram);
00876
00885 void updateRegions(const SbBox3i32 *region, int num_regions);
00886
00894 void updateTilesInTextureMemory(SoLDMTileID* tiles, int numTiles);
00895
00902 virtual SbVec3f voxelToXYZ(const SbVec3f &dataPosition) const;
00903
00909 virtual SbBox3f voxelToXYZ(const SbBox3f& box) const;
00910
00916 virtual SbVec3f XYZToVoxel(const SbVec3f &dataPosition);
00917
00923 virtual SbBox3f XYZToVoxel(const SbBox3f &xyzBox);
00924
00930 void setRGBAData(const bool flag);
00931
00932
00933 #if 1 SoDEPRECATED
00939 SoVolumeData* subSetting( const SbBox3s& region );
00940 SoDEPRECATED
00946 void updateRegions( const SbBox3s *region, int num_regions );
00947 SoDEPRECATED
00953 void loadRegions( const SbBox3s *region, int num_regions, SoState* state, SoTransferFunction* transFunc );
00954 SoDEPRECATED
00959 void setSubSamplingLevel(const SbVec3s& ROISampling, const SbVec3s& secondarySampling);
00960 SoDEPRECATED
00966 void getSubSamplingLevel(SbVec3s &ROISampling, SbVec3s &secondarySampling);
00967 SoDEPRECATED
00972 void setPageSize(SbVec3s& size);
00973 SoDEPRECATED
00978 void setVolumeData( const SbVec3s &dimension, void *data,
00979 SoDataSet::DataType type=UNSIGNED_BYTE,
00980 int numSignificantBits = 0 );
00981
00982 #endif
00985 #if 1
00987 #ifndef HIDDEN_FROM_DOC
00988
00992 SoSFInt32 volumeDataId;
00993 #else
00994 SoDEPRECATED
00995 SoSFInt32 volumeDataId;
00996 #endif
00997 SoDEPRECATED
00999 void setVolumeSize( const SbBox3f &size );
01000 SoDEPRECATED
01002 const SbBox3f& getVolumeSize();
01003 SoDEPRECATED
01012 void setVolumeData( const SbVec3i32 &dimension, SoMemoryObject* data, SoDataSet::DataType type=UNSIGNED_BYTE, int numSignificantBits = 0 );
01013 SoDEPRECATED
01018 void setVolumeData( const SbVec3i32 &dimension, void *data, SoDataSet::DataType type=UNSIGNED_BYTE, int numSignificantBits = 0 );
01019 SoDEPRECATED
01021 SbBool getVolumeData( SbVec3i32 &dimension, void *&data, SoDataSet::DataType &type, int *numSignificantBits = NULL );
01022 SoDEPRECATED
01038 SbBool getMinMax( int &min, int &max);
01039
01040 SoDEPRECATED
01042 SbBool getVolumeData( SbVec3s &dimension, void *&data,
01043 SoDataSet::DataType &type, int *numSignificantBits = NULL );
01044 SoDEPRECATED
01058 SbBool getHistogram ( int &length, int* &histogram);
01059 SoDEPRECATED
01061 static int getMaxNumVolumes() ;
01062
01063 #endif
01065 #if 1 SoDEPRECATED
01075 void setPaging(SbBool);
01076 SoDEPRECATED
01078 SbVec3i32 getDimension() { return SoDataSet::getDimension(); }
01079
01080 #endif
01083 #if 1 SoDEPRECATED
01091 SoSFEnum storageHint;
01092 SoDEPRECATED enum
01095 StorageHint {
01097 AUTO,
01099 TEX2D_MULTI,
01101 TEX2D = TEX2D_MULTI,
01103 TEX3D,
01105 MEMORY,
01106 #ifndef HIDDEN_FROM_DOC
01107
01108 VOLUMEPRO,
01110 TEX2D_SINGLE
01111 #endif // HIDDEN_FROM_DOC
01112 };
01113
01114 #endif
01117 #if 1 SoDEPRECATED
01123 SbVec3i32 getPageSize();
01124 SoDEPRECATED enum
01129 SubMethod {
01131 NEAREST,
01133 MAX,
01135 AVERAGE
01136 };
01137 SoDEPRECATED enum
01142 OverMethod {
01144 NONE,
01146 CONSTANT,
01148 LINEAR,
01150 CUBIC
01151 };
01152 SoDEPRECATED
01161 void enableSubSampling(SbBool enable);
01162 SoDEPRECATED
01167 SbBool isSubSamplingEnabled(){ return FALSE; }
01168 SoDEPRECATED
01174 void enableAutoSubSampling(SbBool enable);
01175 SoDEPRECATED
01180 SbBool isAutoSubSamplingEnabled(){ return FALSE; }
01181 SoDEPRECATED
01187 void enableAutoUnSampling(SbBool enable);
01188 SoDEPRECATED
01193 SbBool isAutoUnSamplingEnabled(){ return FALSE; }
01194 SoDEPRECATED
01200 void unSample();
01201 SoDEPRECATED
01209 void setSubSamplingMethod(SubMethod method);
01210 SoDEPRECATED
01222 void setSubSamplingLevel(const SbVec3i32& ROISampling, const SbVec3i32& secondarySampling);
01223 SoDEPRECATED
01229 void getSubSamplingLevel(SbVec3i32 &ROISampling, SbVec3i32 &secondarySampling);
01230 SoDEPRECATED
01243 SoVolumeData *reSampling( const SbVec3i32 &dimension, SoVolumeData::SubMethod subMethod, SoVolumeData::OverMethod = NONE);
01244 SoDEPRECATED
01250 SoVolumeData *subSetting( const SbBox3i32 ®ion );
01251 SoDEPRECATED
01256 void setTexMemorySize(int size);
01257 SoDEPRECATED
01262 int getTexMemorySize();
01263 SoDEPRECATED
01268 void setPageSize(int size);
01269 SoDEPRECATED
01274 void setPageSize(SbVec3i32& size);
01275 SoDEPRECATED
01307 void loadRegions(const SbBox3i32 * region, int num_regions,SoState* state,SoTransferFunction* transFunc);
01308 SoDEPRECATED
01313 SbBool isPaging();
01314
01315 #endif
01317 private:
01318
01320 SbVec3d getVoxelSize() const;
01321
01322 virtual void updateTile( const SbBox3i32 ®ion, const SoLDMTileID& tileId );
01323 virtual void drawTilesInMainMemory(SoState *state);
01324
01325 enum Cmd{
01326 CREATE_NODE,
01327 UPDATE_REGIONS,
01328 SET_LDM,
01329 SET_PAGING
01330 };
01331
01335 virtual void notify(SoNotList *list);
01336
01337 int64_t getValue (SbVec3i32 &pos, SbBool real = FALSE);
01338 double getValueD(const SbVec3i32 &pos, SbBool real = FALSE);
01339 int64_t loadDataValue(void* value, const SbVec3i32 &pos, void*& data, SoBufferObject *dataBufferObject, SbBool real);
01340
01341 static void initClass();
01342 static void exitClass();
01343
01344 virtual void updateColorTable(SoState *, SoTransferFunction *);
01345 void loadData(SoAction* action, SbBool& texLoadedOrReloaded);
01346
01347 SoTransferFunction::GLColorMapType installColorMap(SoState*, int alphaUse=0);
01348 SoTransferFunction::GLColorMapType getColorMapType(SoState*);
01349 SbVec3i32& getDimensionPowerOf2();
01350 SbVec3f& getTexRatio();
01351
01352
01353 void setLighting(SoState* state, SbBool);
01354 void setLightDirection(SoState* state,const SbVec3f&);
01355 void setLightIntensity(SoState* state,float);
01356
01357 virtual bool isPalettedTexture(SoState* state);
01358 int isSharedPalettedTexture();
01359
01360
01361 static void sceneGraphChangeCB(void* , SoSensor*);
01362
01363
01364 #if 1 SoDEPRECATED
01367 void updateColorTable(SoState *, SoVolumeData::StorageHint textype,SoTransferFunction *);
01368
01369 #endif
01371 private:
01372
01373 virtual void doAction( SoAction *action );
01374 virtual void GLRender( SoGLRenderAction *action );
01375 virtual SoLDMTileManager::LDMSliceAccessor* getAppropriateSliceAccessor(const SoLDM::DataSetIdPair& p);
01376 virtual SoLDMReader* getAppropriateLDMReader( const SbString& pathname);
01377 virtual void useFakeData(SoLDMTileID tileID, SoBufferObject* bufferObject);
01378
01379
01380
01381 virtual int32_t getRenderUnitID() const;
01382
01383 private:
01384 virtual SoLDMGeomElement* getAppropriateElement(SoLDMGeometry* v);
01385
01387 void getVolumeTexGen(SbVec4d texGen[3]) const;
01388
01390 SbMatrix getVolumeTexGen() const;
01391
01393 SbVec3f getVolumeTextureRatio() const;
01394
01396 SbBox3f toTextureSpace(const SbBox3f& bbox) const;
01397
01398 private:
01399
01404 virtual void readerChanged();
01405
01409 virtual void setElement(SoState* state);
01410
01411 virtual SoVolumeReader *getAppropriateReader();
01412
01413
01414 virtual ~SoVolumeData();
01415 void releaseMemory();
01416
01417 virtual bool enableMultidata(SoState* state);
01418
01419
01420 virtual void readChar();
01421
01425 virtual void unload();
01426
01430 virtual void updateFilename();
01431
01435 virtual SbBool isRGBAData();
01436
01438 virtual void buildTile(SoLDMTileID tileID, SoBufferObject* buffer);
01439
01440 private:
01445 void resetData();
01446
01448 void forceStorageHint();
01449
01453 void updateData3D();
01454
01455
01456
01457 static SoDataExtract* s_dataExtractAlgorithms;
01458
01459 void releaseTextures(SoState* state);
01460 void setDimension(const SbVec3i32 &);
01461 void setDimensionPowerOf2();
01462
01463 SbBool initData(SoState*);
01464 SbBool initReader();
01465 private:
01466
01467 void drawOctree(SoGLRenderAction* pGLRA);
01468
01469
01470 virtual int getTexPrec(SoState*state);
01471
01472 private:
01473
01474
01475 SbBool m_tilesInRAMalreadyDrawn;
01476
01477
01478 SoDataCompositor* m_dataCompositor;
01479
01480 void extendData(int, void*);
01481 void extendData1(int, int, void*);
01482
01483 void computeStatData(SbBool flag = FALSE);
01484 int fswGetDataChar(SbBox3f &, DataType &, SbVec3i32 &);
01485 void fswAbort();
01486 void fswSkipSlice(int);
01487 void* fswGetNextSlice(int);
01488 void fswEnd();
01489
01490 void *m_fswSliceData;
01491 SoCache *m_texElementDependency;
01492 SoNodeDependencies* m_dataRangeElementDependency;
01493 SbVec3i32 m_dimensionPowerOf2;
01494 SbVec3f m_texRatio;
01495 SbBool m_lighting;
01496 int m_lightDir[3];
01497 int m_lightInt;
01498 int m_ambCol[3];
01499 int m_specCol[3];
01500 int m_shininess;
01501
01502 SoGLVolCacheList* m_VRTexList;
01503
01505
01506
01507
01508
01509
01511 friend class SoLDMMediator::LDMManagerAccess;
01512
01513 std::map<const SoVolumeShader *, bool> m_rectilinearCoordinatesUpdated;
01515 #if 1 SoDEPRECATED
01518 int64_t subSample(SoDataSet::DataType,int,SbVec3i32&,void*,int,int,int,int,SoVolumeData::SubMethod);
01519 SoDEPRECATED
01521 double subSampleD(SoDataSet::DataType,int,SbVec3i32&,void*,int,int,int,int,SoVolumeData::SubMethod);
01522
01523 #endif
01525 private:
01526 virtual void getDataOneObliqueSlice( const SbVec3i32& tileSize, SoBufferObject* tileData, int Zaxis, const SbPlane& plane, SoBufferObject* slicedata, int interp );
01527 virtual SoBufferObject* getDataOneSlice( const SbVec3i32& tileSize, SoBufferObject* tileData, int Zaxis, int slice);
01528
01529 virtual void computeLighting( const SbVec3i32 & tileSize, SoBufferObject* rgbaBuffer );
01530 SbBox3f getLDMOutliningBox();
01531
01536 virtual SoBufferObject* getTransformedTile(const SoLDMTileID& tile,
01537 const SoLDM::DataSetIdPair& p,
01538 SoState * state=NULL,
01539 const bool useExtendedData = false);
01540
01541 public:
01545 enum CoordinateType {
01549 COORDINATES_UNIFORM = SoVolumeReader::COORDINATES_UNIFORM,
01553 COORDINATES_RECTILINEAR = SoVolumeReader::COORDINATES_RECTILINEAR
01554 };
01555
01556 CoordinateType getCoordinateType() const
01557 {
01558 return m_coordinateType;
01559 }
01560
01566 enum Axis {
01567 X,
01568 Y,
01569 Z
01570 };
01571
01577 const std::vector<float>& getRectilinearCoordinates(Axis axis) const;
01578
01580 virtual SbBool startEditing(int &transactionId );
01581
01583 virtual int editTile( const SoLDMTileID& tileId, SoBufferObject* userData );
01584
01586 virtual int editSubVolume( const SbBox3i32& subVolume, SoBufferObject* userData );
01587
01589 virtual int editTile( const SoLDMTileID& tileId, const double& value );
01590
01592 virtual int editSubVolume( const SbBox3i32& subVolume, const double& value );
01593
01595 virtual int editSurfaceShape( const SoNode* surfaceShape, const float& thickness, const double& newValue );
01596
01598 virtual int editSolidShape( const SoNode* solidShape, const double& value );
01599
01601 virtual int editBoxes(
01602 const std::vector<SbVec3i32>& boxCenters,
01603 const int& boxSize,
01604 const double& newValue
01605 );
01606
01608 virtual SbBool finishEditing(int transactionId);
01609
01611 virtual SbBool undoEditing( int transactionId );
01612
01614 virtual SbBool redoEditing( int transactionId );
01615
01617 virtual SbBool saveEditing(bool recomputeLowerResolution = TRUE, const std::vector<char*> convertionParameters = std::vector<char*>(), SaveEditingCB* callback = NULL );
01618
01619 private:
01620
01623 SbBool saveEditing( SoVolumeWriter* writer, SaveEditingCB* callback = NULL );
01624
01628 const std::vector<float>& getInvertedRectilinearCoordinates(Axis axis) const;
01629
01633 virtual void drawXYZBox(SoState* state, BoxColor color, const SbBox3f& box);
01634
01638 virtual void drawIJKBox(SoState* state, BoxColor color, const SbBox3f& box, const SoLDMTileID& tile,
01639 bool subTile = false);
01640 virtual void drawIJKBox(SoState* state, BoxColor color, const SbBox3f& box, bool fullRes, bool subTile = false);
01641 virtual void drawIJKBox(SoState* state, BoxColor color, const SbBox3f& box, bool subTile = false);
01642
01643 void setupRectilinearCoordinates(const SbVec3i32&);
01644 bool isRectilinearCoordinatesUpdated(const SoVolumeShader* s);
01645 void resetRectilinearCoordinatesUpdated(const SoVolumeShader* s);
01646
01647 SbVec3f computeRectilinearCoordinate(const SbVec3f& vertex);
01648 SbBox3f computeRectilinearCoordinate(const SbBox3f& box);
01649
01650 SbVec3f computeInvertedRectilinearCoordinate(const SbVec3f& vertex);
01651 SbBox3f computeInvertedRectilinearCoordinate(const SbBox3f& box);
01652
01653 void setDefaultValue( const double defValue );
01654 double getDefaultValue() const;
01655
01659 SbBox3f getXYZCoordinates(const SbBox3i32& box, const SbBox3i32& cropped);
01660
01665 SbBox3f getSubtileXYZCoordinates(const SbBox3i32& fullTileBox,
01666 const SbBox3i32& subTileBox,
01667 const SbBox3i32& cropped);
01668
01669 private:
01670
01677 virtual SbBool doSaveEditing( SoVolumeWriter* writer, std::vector<SbBox3i32>& savedRegion, SaveEditingCB callback = NULL );
01678
01679 private:
01681 void bindVolumeDataToDrawStyle(SoAction* action);
01682
01683 template <typename T> void copySliceData(const SbVec3i32& pageSize,
01684 SoBufferObject *pageData, int Zaxis,
01685 const SbPlane& plane, SoBufferObject *slicedata, int interpVal);
01686
01687 std::vector<float> m_invertedRectilinearCoordinates[3];
01688 std::vector<float> m_rectilinearCoordinates[3];
01689 CoordinateType m_coordinateType;
01690
01694 void setVolumeDataCompatibily(const SbVec3i32 &dimension,
01695 void* dataPtr,
01696 SoDataSet::DataType type = UNSIGNED_BYTE,
01697 int numSignificantBits = 0);
01698
01700 static void drawPoint(SoLDMTileID &tileID,int level,float levelmax);
01701
01702 int m_numRenderCaches;
01703 SbThreadMutex* m_threadMutex;
01704
01705
01706 double m_defaultValue;
01707
01710 SbBool m_editingStackDirty;
01711 };
01712
01713 #ifdef _MSC_VER
01714 #pragma warning( pop )
01715 #endif
01716
01717 #endif // _SO_VOLUME_DATA_
01718
01719
01720