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
00964
00965 bool isAccumulated();
00966
00967 static SbBool getCurrentMatrixDifference(SoState* state, const SoLDM::DataSetIdPair& idPair, SbMatrix& geomMatrix);
00968
00969
00970 void lookForSceneGraphChange(SoAction* action);
00971
00972
00973 virtual SoBufferObject* getDataOneSlice( const SbVec3i32& tileSize, SoBufferObject* tileData, int Zaxis, int slice);
00974 virtual void releaseDataOneSlice(SoBufferObject *sliceDataBuffer);
00975
00976
00977
00978 virtual LDMSliceAccessor* getAppropriateSliceAccessor(const SoLDM::DataSetIdPair& p);
00979 virtual SoLDMReader* getAppropriateLDMReader( const SbString& )
00980 { return NULL; };
00981
00982
00983 bool getCenter(SoLDMTileID tileID, SbVec3f& center)const;
00984
00985 SoLDMMediator* getMediator() const
00986 {
00987 return m_mediator;
00988 };
00989 void setMediator(SoLDMMediator* m);
00990
00991 virtual bool createTex(int Zaxis, SoState *state, const SbVec3i32 &tileSize, SoBufferObject *tileDataBuffer, SoTransferFunction *transferFunction,
00992 SoBufferObject*& textureBufferObject, int alphaUse = 0);
00993
00994
00996 void* getTexData(const void* tileBuffer,
00997 int numElem,
00998 SoTransferFunction* transferFunction,
00999 int alphaUse,
01000 int texPrec,
01001 void *textureBuffer,
01002 SoDataRange* datarange,
01003 SoDataCompositor* dataCompositor);
01004
01005
01006
01007
01008
01009 SoBufferObject* getTexData(SoBufferObject* tileBufferObject,
01010 SoTransferFunction* transferFunction,
01011 int alphaUse,
01012 int texPrec,
01013 SoBufferObject* textureBufferObject,
01014 SoDataRange* dataRange,
01015 SoDataCompositor* dataCompositor);
01016
01017 int getRGBAInternalFormat() const;
01018
01019 virtual void updateColorTable(SoState *, SoTransferFunction *);
01020
01021 SoLDMResourceManager& getResourceManager() { return *m_resourceManager; }
01022
01027 virtual int getTexPrec(SoState*);
01028
01034 void getTextureFormat(SoTransferFunction::GLColorMapType colorMapType,
01035 GLenum& format,
01036 GLenum& dataType,
01037 GLint& internalFormat) const;
01038
01039
01040 virtual void drawTilesInMainMemory(SoGLRenderAction* action, const SoLDM::DataSetIdPair& idPair);
01041
01042
01043
01044 void copyLDMParameters(SoLDMMediator *mediator);
01045
01051 virtual bool isMultidataEnabled() const { return m_multidataEnabled; }
01052
01053
01054 enum BoxColor {
01055 GREY,
01056 RED,
01057 BLUE,
01058 GREEN,
01059 FULL_RES_GREY,
01060 FULL_RES_GREEN
01061 };
01062
01067 unsigned short getId() const
01068 { return m_id; }
01069
01073 bool hasReadError();
01074
01078 inline bool isEmpty()
01079 {
01080 const SbVec3i32& dim = getDimension();
01081 return ( dim[0] == 0 || dim[1] == 0 || dim[2] == 0 );
01082 };
01083
01088 struct DatumElement{
01089 SoDataSet::DataType type;
01090 int num;
01091 };
01092
01099 float convertToNormalizedTextureSpace(SoState *state, const float data);
01100
01104 void setFirstTraversalDone(bool flag);
01105
01109 bool isFirstTraversalDone() const;
01110
01111 virtual bool isPalettedTexture(SoState*);
01112
01113
01114
01115
01116 virtual uint64_t getTileSignature(const SoLDMTileID& tileId);
01117
01123 inline void setOwnedReader( SoVolumeReader &reader )
01124 { setReader( reader, TRUE ); };
01125
01126
01127
01128
01129
01130
01131 void refVolRender( int contextId );
01132 void unrefVolRender( int contextId );
01133
01140 int getBestEqualResolution() const;
01141
01143 void invalidateHistogram();
01144
01146 SbVec2f getDataTypeMinMax() const;
01147
01155 SoLDMTileID getTileCharacteristics(const SoLDMTileID& tile, SbBox3i32& tileBox, SbVec3i32& tileDim) const;
01156
01160 bool supportUndefinedVoxel(SoState* state);
01161
01162 private:
01163
01165 SoDataSet();
01166
01168 virtual ~SoDataSet();
01169
01170 inline virtual void computeLighting( const SbVec3i32& , SoBufferObject* ) {};
01171
01175 virtual void setElement(SoState* state);
01176
01180 bool isUsingUserExtent();
01181
01182
01183
01184
01185
01186
01187
01188
01189 virtual bool enableMultidata(SoState* state);
01190
01191
01192 virtual SoVolumeReader* getAppropriateReader();
01193
01195 bool m_forcePow2TileDim;
01196
01197
01198 SoRef<SoFieldContainer> m_reader;
01199
01200 bool load(SoState*);
01201 virtual void unload();
01202 virtual void releaseMemory();
01203
01204
01205 bool m_multidataEnabled;
01206
01207 SbVec3i32 m_dimension;
01208 bool m_initialized;
01209
01210 SbDataType m_type;
01211 int m_numBits;
01212
01213
01214 bool m_dataCharRead;
01215
01216 SbString m_filename;
01217 virtual void updateFilename();
01218
01219
01220 unsigned short m_id;
01221
01222
01226 virtual void readerChanged();
01227
01228 void initReader();
01229
01230 virtual SoLDMMediator *createMediator();
01231 SoLDMMediator* m_mediator;
01232
01233 SoMultiDataSeparator *m_MultiDataSeparator;
01234
01235 SoLDMResourceManager* m_resourceManager;
01236
01237 void getTransferFunction(SoTransferFunction *transferFunction, int alphaUse,
01238 int &shift, int &offset, int &nrgba, unsigned int * &rgba);
01239
01240
01241
01242
01243 virtual void buildTile(SoLDMTileID tileID, SoBufferObject* buffer);
01244
01245 SoVolumeHistogram *m_histogram;
01246
01248 virtual void ldmAction(SoLdmValuationAction* action);
01249
01253 virtual SbBool isRGBAData();
01254
01255 SoINTERNAL private:
01256
01261 virtual SoLDMGeomElement* getAppropriateElement( SoLDMGeometry* SO_UNUSED_PARAM(v) )
01262 {
01263 return NULL;
01264 }
01265
01269 virtual unsigned short getMaxTexturePrecisionBits() const { return 16; }
01270
01271 SoSFFieldContainer customReader;
01272 SoSFBool customReaderOwnerShip;
01273
01278 SoSFLDMDataTransform editingStack;
01279
01280 private:
01281
01283 void commonConstructor();
01284
01289 bool computeBestEqualResolution(const std::vector<size_t>& tilesByLvlVec);
01290
01294 struct MTstruct {
01295 SoBufferObject *tmpTexture;
01296 SoCpuBufferUniform *tmpTextureUniform;
01297 SoBufferObject *tmpColormap;
01298 SoBufferObject *tmpTexturePermute;
01299 };
01300
01301 #ifndef HIDDEN_FROM_DOC
01302 friend class SoLDMMediator;
01303 friend class SoCpuBufferFromVolumeReaderImpl;
01304 #endif
01305 friend class SoLdmValuationAction;
01306 friend class SoLDMGeometry;
01307 };
01308
01309 #ifdef _MSC_VER
01310 #pragma warning( pop )
01311 #endif
01312
01313 #endif // _SO_DATA_SET_
01314
01315
01316