00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _SO_DATA_SET_
00028 #define _SO_DATA_SET_
00029
00030 #ifdef _MSC_VER
00031 #pragma warning( push )
00032 #pragma warning(disable:4251)
00033 #endif
00034
00035
00036 #include <Inventor/SbBox.h>
00037 #include <Inventor/SbLinear.h>
00038 #include <Inventor/fields/SoSFBool.h>
00039 #include <Inventor/fields/SoSFBox3f.h>
00040 #include <Inventor/fields/SoSFEnum.h>
00041 #include <Inventor/fields/SoSFFieldContainer.h>
00042 #include <Inventor/fields/SoSFFilePathString.h>
00043 #include <Inventor/fields/SoSFFloat.h>
00044 #include <Inventor/fields/SoSFDouble.h>
00045 #include <Inventor/SbDataType.h>
00046 #include <Inventor/fields/SoSFInt32.h>
00047 #include <Inventor/fields/SoSFNode.h>
00048 #include <Inventor/fields/SoSFString.h>
00049 #include <Inventor/fields/SoSFUShort.h>
00050 #include <Inventor/misc/SoMemoryObject.h>
00051 #include <Inventor/misc/SoRef.h>
00052 #include <Inventor/nodes/SoNode.h>
00053 #include <LDM/SoLDM.h>
00054 #include <LDM/SoLDMMediator.h>
00055 #include <LDM/SoLDMTileID.h>
00056 #include <LDM/fields/SoSFLDMResourceParameters.h>
00057 #include <LDM/fields/SoSFLDMDataTransform.h>
00058 #include <LDM/nodes/SoLDMResourceParameters.h>
00059 #include <LDM/nodes/SoTransferFunction.h>
00060 #include <LDM/tiles/SoCpuBufferUniform.h>
00061 #include <Inventor/sys/SoGLType.h>
00062
00063
00064 #include <Inventor/devices/SoCpuBufferObject.h>
00065
00066 class SoGLRenderAction;
00067 class SoCallbackAction;
00068 class SoHandleEventAction;
00069 class SoWriteAction;
00070 class SoState;
00071 class SoLDMGeomElement;
00072 class SoLDMGeometry;
00073 class SoLDMReader;
00074 class SoTransferFunction;
00075 class SoMultiDataSeparator;
00076 class SoVolumeHistogram;
00077 class SoVolumeReader;
00078 class SoPerfCounterManager;
00079 class SoPerfCounter;
00080 class SoBufferObject;
00081 class SoCpuBufferUniform;
00082 class SoGLTexture;
00083 class SoCache;
00084
00085 class SoDataExtract;
00086 class SoConversion;
00087 class SoAlgorithms;
00088 class SoLDMAlgorithms;
00089 class SoLdmValuationAction;
00090 class SoDataRange;
00091
00092 class SoVolumeWriter;
00093
00094 SO_PIMPL_PUBLIC_DECLARATION(SoDataSet)
00095
00096
00097
00138 class SoDataSet : public SoNode
00139 {
00140 SO_NODE_ABSTRACT_HEADER( SoDataSet );
00141
00142 SO_PIMPL_PUBLIC_HEADER( SoDataSet );
00143
00144 public:
00145
00161 SoSFInt32 dataSetId;
00162
00187 SoSFFilePathString fileName;
00188
00202 SoSFBool useCompressedTexture;
00203
00228 SoSFUShort texturePrecision;
00229
00239 SoSFBox3f extent;
00240
00261 SoSFLDMDataTransform dataTransform;
00262
00270 SoSFBool allocateResourceOnRender;
00271
00289 SoSFDouble undefinedValue;
00290
00294 const SbVec3i32& getDimension();
00295
00299 SbVec3i32 getTileDimension();
00300
00304 unsigned int getDatumSize();
00305
00313 virtual size_t readTile( SoBufferObject*& bufferObject, SoLDMTileID tileID, bool transform );
00314
00320 virtual void readTile(SoLDMTileID tileID, SoBufferObject* buffer, bool transform);
00321
00330 virtual void writeTile( SoLDMTileID tileID, SoBufferObject* buffer, SoVolumeWriter* writer );
00331
00336 bool isInMemory( SoLDMTileID tileID ) const;
00337
00347 bool isDataInMemory( const SoLDMTileID& tileID ) const;
00348
00353 void getTileIDInMemory( std::vector<LDM_TILE_ID_TYPE>& tilesInMemory ) const;
00354
00359 SoSFLDMResourceParameters ldmResourceParameters;
00360
00365 SoLDMDataAccess & getLdmDataAccess();
00366
00374 virtual SbBool startEditing( int& transactionId );
00375
00384 virtual SbBool finishEditing( int transactionId );
00385
00394 virtual int editTile( const SoLDMTileID& tileId, SoBufferObject* userData );
00395
00405 virtual int editSubVolume( const SbBox3i32& subVolume, SoBufferObject* userData );
00406
00411 virtual int editTile( const SoLDMTileID& tileId, const double& value );
00412
00418 virtual int editSubVolume( const SbBox3i32& subVolume, const double& value );
00419
00432 virtual int editSurfaceShape( const SoNode* surfaceShape, const float& thickness, const double& value );
00433
00453 virtual int editSolidShape( const SoNode* solidShape, const double& value );
00454
00463 virtual int editBoxes(
00464 const std::vector<SbVec3i32>& boxCenters,
00465 const int& boxSize,
00466 const double& newValue
00467 );
00468
00480 virtual SbBool undoEditing( int transactionId );
00481
00493 virtual SbBool redoEditing( int transactionId );
00494
00495
00511 typedef SbBool SaveEditingCB( SoDataSet* dataSet,
00512 SoVolumeWriter* writer,
00513 int tilesRemaining,
00514 int totalTiles );
00554 virtual SbBool saveEditing( bool recomputeLowerResolution = TRUE,
00555 const std::vector<char*> conversionParameters = std::vector<char*>(), SaveEditingCB* callback = NULL );
00556
00560 virtual bool hasEditedTile();
00561
00568 SoLDMReader* getLDMReader();
00569
00576 void setLDMReader(SoLDMReader* reader);
00577
00586 inline SoVolumeReader* getReader()
00587 {return (SoVolumeReader*)m_reader.ptr();};
00588
00597 inline SoVolumeReader* getReader() const
00598 { return (SoVolumeReader*)m_reader.ptr(); };
00599
00603 enum DataType {
00605 UNSIGNED_BYTE = SbDataType::UNSIGNED_BYTE,
00607 UNSIGNED_SHORT = SbDataType::UNSIGNED_SHORT,
00609 UNSIGNED_INT32 = SbDataType::UNSIGNED_INT32,
00611 SIGNED_BYTE = SbDataType::SIGNED_BYTE,
00613 SIGNED_SHORT = SbDataType::SIGNED_SHORT,
00615 SIGNED_INT32 = SbDataType::SIGNED_INT32,
00617 FLOAT = SbDataType::FLOAT,
00619 DOUBLE = SbDataType::DOUBLE
00620 };
00621
00622
00626 static int dataSize( DataType dataType );
00627
00631 static SbBool isDataSigned( DataType dataType );
00632
00636 static SbBool isDataFloat( DataType dataType );
00637
00641 int numSigBits() const;
00642
00655 virtual SbBool getMinMax( int64_t &min, int64_t &max);
00656
00670 virtual SbBool getMinMax( double &min, double &max);
00671
00675 DataType getDataType();
00676
00680 int getDataSize();
00681
00701 void setReader( SoVolumeReader &reader, SbBool takeOwnership = FALSE );
00702
00707 static int getMaxNumDataSets() ;
00708
00723 virtual SbVec3f voxelToXYZ( const SbVec3f& dataPosition ) const;
00724
00738 virtual SbBox3f voxelToXYZ( const SbBox3f& box ) const;
00739
00753 virtual SbVec3f XYZToVoxel( const SbVec3f& dataPosition ) const;
00754
00768 virtual SbBox3f XYZToVoxel( const SbBox3f& xyzBox ) const;
00769
00770 #if 1 SoDEPRECATED
00773 virtual void readTile(SoLDMTileID tileID, unsigned char* buffer, bool transform);
00774
00802 typedef void SoLDMDataTransformFunction(SoDataSet* ds,
00803 const SbVec3i32& bufferDimension,
00804 void* bufferToTransform,
00805 const SbBox3i32& dataBox,
00806 int resolutionLevel,
00807 void* userData);
00808 SoDEPRECATED
00818 void setLDMDataTransformFunction(SoLDMDataTransformFunction* func, void* userData = NULL);
00819
00820 #endif
00822 #if 1 SoDEPRECATED
00829 int getOverlapping();
00830
00831 #endif
00833 SoEXTENDER_Documented public:
00834
00848 void resetReader();
00849
00854 const SoLDMTopoOctree* getLDMTopoOctree() const;
00855
00856 private:
00857
00859 virtual void callback( SoCallbackAction *action );
00861 virtual void GLRender( SoGLRenderAction *action );
00863 virtual void getBoundingBox(SoGetBoundingBoxAction *action);
00865 virtual void handleEvent(SoHandleEventAction* action);
00867 virtual void pick(SoPickAction *action) ;
00869 virtual void write(SoWriteAction *action);
00871 virtual void doAction( SoAction *action );
00872
00876 inline virtual void useFakeData(SoLDMTileID , SoBufferObject* ) {};
00877
00878 private:
00879
00880
00881
00882
00883 typedef std::map<SoLDMTileID, uint64_t> tileSigInCacheMap;
00884
00885 static void initClass();
00886 static void exitClass();
00887
00889 bool isReallyOfType(const SoType& type, bool derived);
00890
00896 bool isGPUDataRange( SoState* state );
00897
00903 SoBufferObject* getEditedTile( SoBufferObject* tileBuffer, const SoLDMTileID& tileId );
00904
00909 virtual SoBufferObject *getTransformedTile(const SoLDMTileID& tile,
00910 const SoLDM::DataSetIdPair& p,
00911 SoState * state=NULL,
00912 const bool useExtendedData = false);
00913
00914
00915
00916 static int getNumInstance();
00917
00919 SB_THREAD_TLS_HEADER();
00920
00922 SoLDM::DataSetIdPair getDataSetIdPair(SoState* state) const;
00923
00924 SoMultiDataSeparator *getMultiDataSeparator() { return m_MultiDataSeparator; }
00925 void setMultiDataSeparator(SoMultiDataSeparator *mds, SoLDMMediator* mediator = nullptr);
00926
00930 virtual void notify(SoNotList *list);
00931
00935 void sendParametersToLDM(SoLdmValuationAction* action);
00936
00937
00938 void ignoredByMultiDataSeparator(bool state);
00939 bool isIgnoredByMultiDataSeparator();
00940
00941
00942 virtual bool getDataCharRead() { return m_dataCharRead;};
00943
00944
00945 int getIndTexPrec() const;
00946 bool loadInMemory(SoState* s = NULL);
00947 void setListChange(bool val);
00948 bool getListChange();
00949
00950
00951
00952
00953
00954
00955
00956 unsigned short getResourcesState() const;
00957
00958
00959
00960
00961
00962 void setResourcesState( const SoLDMResourceManager::State flag, bool value );
00963
00970 int getZaxis(SoState *state, const SbBox3f& volBbox) const;
00971
00975 SbVec3f getVolCenterToEyeVector(SoState *state, const SbBox3f& volBbox) const;
00976
00978 SbVec3f getObjectSpaceEyeAxis(SoState *state) const;
00979
00980
00981 bool isAccumulated();
00982
00983 SbBool getCurrentMatrixDifference(SoState*, SbMatrix&);
00984
00985
00986 void lookForSceneGraphChange(SoAction* action);
00987
00988
00989 virtual SoBufferObject* getDataOneSlice( const SbVec3i32& tileSize, SoBufferObject* tileData, int Zaxis, int slice);
00990 virtual void releaseDataOneSlice(SoBufferObject *sliceDataBuffer);
00991
00992
00993
00994 virtual LDMSliceAccessor* getAppropriateSliceAccessor(const SoLDM::DataSetIdPair& p);
00995 virtual SoLDMReader* getAppropriateLDMReader( const SbString& )
00996 { return NULL; };
00997
00998
00999 bool getCenter(SoLDMTileID tileID, SbVec3f& center)const;
01000
01001 SoLDMMediator* getMediator() const
01002 {
01003 return m_mediator;
01004 };
01005 void setMediator(SoLDMMediator* m);
01006
01007 virtual bool createTex(int Zaxis, SoState *state, const SbVec3i32 &tileSize, SoBufferObject *tileDataBuffer, SoTransferFunction *transferFunction,
01008 SoBufferObject*& textureBufferObject, int alphaUse = 0);
01009
01010
01012 void* getTexData(const void* tileBuffer,
01013 int numElem,
01014 SoTransferFunction* transferFunction,
01015 int alphaUse,
01016 int texPrec,
01017 void *textureBuffer,
01018 SoDataRange* datarange,
01019 SoDataCompositor* dataCompositor);
01020
01021
01022
01023
01024
01025 SoBufferObject* getTexData(SoBufferObject* tileBufferObject,
01026 SoTransferFunction* transferFunction,
01027 int alphaUse,
01028 int texPrec,
01029 SoBufferObject* textureBufferObject,
01030 SoDataRange* dataRange,
01031 SoDataCompositor* dataCompositor);
01032
01033 int getRGBAInternalFormat() const;
01034
01035 virtual void updateColorTable(SoState *, SoTransferFunction *);
01036
01037 SoLDMResourceManager& getResourceManager() { return *m_resourceManager; }
01038
01043 virtual int getTexPrec(SoState*);
01044
01050 void getTextureFormat(SoTransferFunction::GLColorMapType colorMapType,
01051 GLenum& format,
01052 GLenum& dataType,
01053 GLint& internalFormat) const;
01054
01055
01056 virtual void drawTilesInMainMemory( SoGLRenderAction* action );
01057
01058
01059
01060 void copyLDMParameters(SoLDMMediator *mediator);
01061
01067 virtual bool isMultidataEnabled() const { return m_multidataEnabled; }
01068
01069
01070 enum BoxColor {
01071 GREY,
01072 RED,
01073 BLUE,
01074 GREEN,
01075 FULL_RES_GREY,
01076 FULL_RES_GREEN
01077 };
01078
01083 unsigned short getId() const
01084 { return m_id; }
01085
01089 bool hasReadError();
01090
01094 inline bool isEmpty()
01095 {
01096 const SbVec3i32& dim = getDimension();
01097 return ( dim[0] == 0 || dim[1] == 0 || dim[2] == 0 );
01098 };
01099
01104 struct DatumElement{
01105 SoDataSet::DataType type;
01106 int num;
01107 };
01108
01115 float convertToNormalizedTextureSpace(SoState *state, const float data);
01116
01120 void setFirstTraversalDone(bool flag);
01121
01125 bool isFirstTraversalDone() const;
01126
01127 virtual bool isPalettedTexture(SoState*);
01128
01129
01130
01131
01132 virtual uint64_t getTileSignature(const SoLDMTileID& tileId);
01133
01139 inline void setOwnedReader( SoVolumeReader &reader )
01140 { setReader( reader, TRUE ); };
01141
01142
01143
01144
01145
01146
01147 void refVolRender( int contextId );
01148 void unrefVolRender( int contextId );
01149
01156 int getBestEqualResolution() const;
01157
01162 void computeBestEqualResolution();
01163
01165 void invalidateHistogram();
01166
01168 SbVec2f getDataTypeMinMax() const;
01169
01177 SoLDMTileID getTileCharacteristics(const SoLDMTileID& tile, SbBox3i32& tileBox, SbVec3i32& tileDim) const;
01178
01182 bool supportUndefinedVoxel(SoState* state);
01183
01184 private:
01185
01187 SoDataSet();
01188
01190 virtual ~SoDataSet();
01191
01192 inline virtual void computeLighting( const SbVec3i32& , SoBufferObject* ) {};
01193
01197 virtual void setElement(SoState* state);
01198
01202 bool isUsingUserExtent();
01203
01204
01205
01206
01207
01208
01209
01210
01211 virtual bool enableMultidata(SoState* state);
01212
01213
01214 virtual SoVolumeReader* getAppropriateReader();
01215
01217 bool m_forcePow2TileDim;
01218
01219
01220 SoRef<SoFieldContainer> m_reader;
01221
01222 bool load(SoState*);
01223 virtual void unload();
01224 virtual void releaseMemory();
01225
01226
01227 bool m_multidataEnabled;
01228
01229 SbVec3i32 m_dimension;
01230 bool m_initialized;
01231
01232 SbDataType m_type;
01233 int m_numBits;
01234
01235
01236 bool m_dataCharRead;
01237
01238 SbString m_filename;
01239 virtual void updateFilename();
01240
01241
01242 unsigned short m_id;
01243
01244
01248 virtual void readerChanged();
01249
01250 void initReader();
01251
01252 virtual SoLDMMediator *createMediator();
01253 SoLDMMediator* m_mediator;
01254
01255 SoMultiDataSeparator *m_MultiDataSeparator;
01256
01257 SoLDMResourceManager* m_resourceManager;
01258
01259 void getTransferFunction(SoTransferFunction *transferFunction, int alphaUse,
01260 int &shift, int &offset, int &nrgba, unsigned int * &rgba);
01261
01262
01263
01264
01265 virtual void buildTile(SoLDMTileID tileID, SoBufferObject* buffer);
01266
01267 SoVolumeHistogram *m_histogram;
01268
01270 virtual void ldmAction(SoLdmValuationAction* action);
01271
01275 virtual SbBool isRGBAData();
01276
01277 SoINTERNAL private:
01278
01283 virtual SoLDMGeomElement* getAppropriateElement( SoLDMGeometry* SO_UNUSED_PARAM(v) )
01284 {
01285 return NULL;
01286 }
01287
01291 virtual unsigned short getMaxTexturePrecisionBits() const { return 16; }
01292
01293 SoSFFieldContainer customReader;
01294 SoSFBool customReaderOwnerShip;
01295
01300 SoSFLDMDataTransform editingStack;
01301
01302 private:
01303
01305 void commonConstructor();
01306
01310 struct MTstruct {
01311 SoBufferObject *tmpTexture;
01312 SoCpuBufferUniform *tmpTextureUniform;
01313 SoBufferObject *tmpColormap;
01314 SoBufferObject *tmpTexturePermute;
01315 };
01316
01317 #ifndef HIDDEN_FROM_DOC
01318 friend class SoLDMMediator;
01319 friend class SoCpuBufferFromVolumeReaderImpl;
01320 #endif
01321 friend class SoLdmValuationAction;
01322 friend class SoLDMGeometry;
01323 };
01324
01325 #ifdef _MSC_VER
01326 #pragma warning( pop )
01327 #endif
01328
01329 #endif // _SO_DATA_SET_
01330
01331
01332