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/SbDataType.h>
00045 #include <Inventor/fields/SoSFInt32.h>
00046 #include <Inventor/fields/SoSFNode.h>
00047 #include <Inventor/fields/SoSFString.h>
00048 #include <Inventor/fields/SoSFUShort.h>
00049 #include <Inventor/misc/SoMemoryObject.h>
00050 #include <Inventor/misc/SoRef.h>
00051 #include <Inventor/nodes/SoNode.h>
00052 #include <LDM/SoLDM.h>
00053 #include <LDM/SoLDMMediator.h>
00054 #include <LDM/SoLDMTileID.h>
00055 #include <LDM/SoLDMTileManager.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 <Inventor/sys/SoGLType.h>
00061
00062
00063 #include <Inventor/devices/SoCpuBufferObject.h>
00064
00065
00066 class SoGLRenderAction;
00067 class SoCallbackAction;
00068 class SoWriteAction;
00069 class SoState;
00070 class SoLDMGeomElement;
00071 class SoLDMGeometry;
00072 class SoLDMReader;
00073 class SoTransferFunction;
00074 class SoMultiDataSeparator;
00075 class SoVolumeHistogram;
00076 class SoVolumeReader;
00077 class SoPerfCounterManager;
00078 class SoPerfCounter;
00079 class SoBufferObject;
00080 class SoCpuBufferUniform;
00081 class SoGLTexture;
00082 class SoCache;
00083
00084 class SoDataExtract;
00085 class SoConversion;
00086 class SoAlgorithms;
00087 class SoLDMAlgorithms;
00088 class SoLdmValuationAction;
00089 class SoDataRange;
00090
00091 class SoVolumeWriter;
00092
00132 class SoDataSet : public SoNode
00133 {
00134 SO_NODE_ABSTRACT_HEADER( SoDataSet );
00135
00136 public:
00137
00153 SoSFInt32 dataSetId;
00154
00179 SoSFFilePathString fileName;
00180
00194 SoSFBool useCompressedTexture;
00195
00220 SoSFUShort texturePrecision;
00221
00231 SoSFBox3f extent;
00232
00253 SoSFLDMDataTransform dataTransform;
00254
00262 SoSFBool allocateResourceOnRender;
00263
00267 const SbVec3i32& getDimension();
00268
00272 SbVec3i32 getTileDimension();
00273
00277 unsigned int getDatumSize();
00278
00286 virtual size_t readTile( SoBufferObject*& bufferObject, SoLDMTileID tileID, bool transform );
00287
00293 virtual void readTile(SoLDMTileID tileID, SoBufferObject* buffer, bool transform);
00294
00303 virtual void writeTile( SoLDMTileID tileID, SoBufferObject* buffer, SoVolumeWriter* writer );
00304
00309 SoSFLDMResourceParameters ldmResourceParameters;
00310
00315 SoLDMDataAccess & getLdmDataAccess();
00316
00324 virtual SbBool startEditing( int& transactionId );
00325
00334 virtual SbBool finishEditing( int transactionId );
00335
00344 virtual int editTile( const SoLDMTileID& tileId, SoBufferObject* userData );
00345
00355 virtual int editSubVolume( const SbBox3i32& subVolume, SoBufferObject* userData );
00356
00361 virtual int editTile( const SoLDMTileID& tileId, const double& value );
00362
00368 virtual int editSubVolume( const SbBox3i32& subVolume, const double& value );
00369
00382 virtual int editSurfaceShape( const SoNode* surfaceShape, const float& thickness, const double& value );
00383
00403 virtual int editSolidShape( const SoNode* solidShape, const double& value );
00404
00412 virtual int editBoxes(
00413 const std::vector<SbVec3i32>& boxCenters,
00414 const int& boxSize,
00415 const double& newValue
00416 );
00417
00429 virtual SbBool undoEditing( int transactionId );
00430
00442 virtual SbBool redoEditing( int transactionId );
00443
00444
00460 typedef SbBool SaveEditingCB( SoDataSet* dataSet,
00461 SoVolumeWriter* writer,
00462 int tilesRemaining,
00463 int totalTiles );
00503 virtual SbBool saveEditing( bool recomputeLowerResolution = TRUE,
00504 const std::vector<char*> conversionParameters = std::vector<char*>(), SaveEditingCB* callback = NULL );
00505
00509 virtual bool hasEditedTile();
00510
00514 SoLDMTileManager *getTileManager() { return getLdmManagerAccess().getTileManager(); }
00515
00519 SoLDMTextureManager *getTextureManager() { return getLdmManagerAccess().getTextureManager(); }
00520
00521 #if 1 SoDEPRECATED
00527 SoLDMTileVisitor* getTileVisitor();
00528 SoDEPRECATED
00533 void setTileVisitor( SoLDMTileVisitor* tileVisitor );
00534 SoDEPRECATED
00539 SoLDMGeometry *getVVizGeometry();
00540
00541 #endif
00542
00546 SoLDMNodeFrontManager *getNodeFrontManager() { return getLdmManagerAccess().getNodeFrontManager(); }
00547
00554 SoLDMReader* getLDMReader();
00555
00562 void setLDMReader(SoLDMReader* reader);
00563
00572 inline SoVolumeReader* getReader()
00573 {return (SoVolumeReader*)m_reader.ptr();};
00574
00583 inline SoVolumeReader* getReader() const
00584 { return (SoVolumeReader*)m_reader.ptr(); };
00585
00589 enum DataType {
00591 UNSIGNED_BYTE = SbDataType::UNSIGNED_BYTE,
00593 UNSIGNED_SHORT = SbDataType::UNSIGNED_SHORT,
00595 UNSIGNED_INT32 = SbDataType::UNSIGNED_INT32,
00597 SIGNED_BYTE = SbDataType::SIGNED_BYTE,
00599 SIGNED_SHORT = SbDataType::SIGNED_SHORT,
00601 SIGNED_INT32 = SbDataType::SIGNED_INT32,
00603 FLOAT = SbDataType::FLOAT
00604 };
00605
00606
00610 static int dataSize( DataType dataType );
00611
00615 static SbBool isDataSigned( DataType dataType );
00616
00620 static SbBool isDataFloat( DataType dataType );
00621
00625 int numSigBits() const;
00626
00639 virtual SbBool getMinMax( int64_t &min, int64_t &max);
00640
00654 virtual SbBool getMinMax( double &min, double &max);
00655
00659 DataType getDataType();
00660
00664 int getDataSize();
00665
00685 void setReader( SoVolumeReader &reader, SbBool takeOwnership = FALSE );
00686
00691 static int getMaxNumDataSets() ;
00692
00693 #if 1 SoDEPRECATED
00700 SoLDMResourceParameters& getLdmResourceParameter();
00701
00702 #endif
00704 #if 1 SoDEPRECATED
00707 virtual void readTile(SoLDMTileID tileID, unsigned char* buffer, bool transform);
00708
00736 typedef void SoLDMDataTransformFunction(SoDataSet* ds,
00737 const SbVec3i32& bufferDimension,
00738 void* bufferToTransform,
00739 const SbBox3i32& dataBox,
00740 int resolutionLevel,
00741 void* userData);
00742 SoDEPRECATED
00752 void setLDMDataTransformFunction(SoLDMDataTransformFunction* func, void* userData = NULL);
00753
00754 #endif
00756 #if 1 SoDEPRECATED
00765 inline SbBool isTimeDependent()
00766 { return FALSE; }
00767 SoDEPRECATED
00775 inline int getNumTimeSteps()
00776 { return 1; }
00777 SoDEPRECATED
00783 int getOverlapping();
00784 SoDEPRECATED
00789 void setLDM(SbBool state);
00790
00791 #endif
00793 SoEXTENDER_Documented public:
00794
00797 SoLDMMediator::LDMManagerAccess &getLdmManagerAccess() { return m_mediator->ldmManagerAccess; }
00798
00812 void resetReader();
00813
00814 private:
00815
00816 virtual void callback( SoCallbackAction *action );
00817 virtual void GLRender( SoGLRenderAction *action );
00818 virtual void getBoundingBox(SoGetBoundingBoxAction *action);
00819 virtual void pick(SoPickAction *action) ;
00820 virtual void write(SoWriteAction *action);
00821
00825 inline virtual void useFakeData(SoLDMTileID , SoBufferObject* ) {};
00826
00827 private:
00828
00829
00830
00831
00832 typedef std::map<SoLDMTileID, uint64_t> tileSigInCacheMap;
00833
00834 static void initClass();
00835 static void exitClass();
00836
00838 static bool isReallyOfType(SoDataSet* ds, const SoType& type, bool derived);
00839
00845 bool isGPUDataRange( SoState* state );
00846
00852 SoBufferObject* getEditedTile( SoBufferObject* tileBuffer, const SoLDMTileID& tileId );
00853
00858 virtual SoBufferObject *getTransformedTile(const SoLDMTileID& tile,
00859 const SoLDM::DataSetIdPair& p,
00860 SoState * state=NULL,
00861 const bool useExtendedData = false);
00862
00864 SbBool isTileEdited( const SoLDMTileID& tileId );
00865
00866
00867
00868 static int getNumInstance()
00869 { return s_numInstance; }
00870
00872 SB_THREAD_TLS_HEADER();
00873
00874 typedef std::vector<SoGLTexture*> TextureList;
00875
00877 SoLDM::DataSetIdPair getDataSetIdPair(SoState* state) const;
00878
00879 SoMultiDataSeparator *getMultiDataSeparator() { return m_MultiDataSeparator; }
00880 void setMultiDataSeparator(SoMultiDataSeparator *mds);
00881
00885 virtual void notify(SoNotList *list);
00886
00890 void sendParametersToLDM(SoLdmValuationAction* action);
00891
00896 virtual SoLDMGeomElement* getAppropriateElement(SoLDMGeometry* v) = 0;
00897
00898
00899 void ignoredByMultiDataSeparator(bool state);
00900 bool isIgnoredByMultiDataSeparator() { return m_ignoredByMultiDataSeparator; }
00901
00902
00903 virtual bool getDataCharRead() { return m_dataCharRead;};
00904
00905
00906 int getIndTexPrec() const;
00907 virtual void doAction( SoAction *action );
00908 bool loadInMemory(SoState* s = NULL);
00909 void setListChange(bool val){m_listChange = val;};
00910 bool getListChange(){return m_listChange;};
00911
00912
00913
00914
00915
00916
00917
00918 inline unsigned short getResourcesState() const
00919 { return m_resourcesState;};
00920
00921
00922
00923
00924
00925 void setResourcesState( const SoLDMResourceManager::State flag, bool value );
00926
00927
00928 SbVec3i32 getEyeDataCoord(SoState* state);
00929
00936 int getZaxis(SoState *state, const SbBox3f& volBbox) const;
00937
00941 SbVec3f getVolCenterToEyeVector(SoState *state, const SbBox3f& volBbox) const;
00942
00944 SbVec3f getObjectSpaceEyeAxis(SoState *state) const;
00945
00946
00947 void setAccumulate(bool val){m_toAccumulate = val;};
00948 bool isAccumulated(){return m_toAccumulate;};
00949 bool m_toAccumulate;
00950 SbBool getCurrentMatrixDifference(SoState*, SbMatrix&);
00951
00952
00953 void lookForSceneGraphChange(SoAction* action);
00954
00955
00956 virtual SoBufferObject* getDataOneSlice( const SbVec3i32& tileSize, SoBufferObject* tileData, int Zaxis, int slice);
00957 virtual void releaseDataOneSlice(SoBufferObject *sliceDataBuffer);
00958
00959
00960
00961 virtual SoLDMTileManager::LDMSliceAccessor* getAppropriateSliceAccessor(const SoLDM::DataSetIdPair& p);
00962 virtual SoLDMReader* getAppropriateLDMReader( const SbString& )
00963 { return NULL; };
00964
00965
00970 virtual bool getBbox(SoLDMTileID tileId, SbBox3f& box);
00971
00972
00973 bool getCenter(SoLDMTileID tileID, SbVec3f& center)const;
00974
00975 SoLDMMediator* getMediator(){return m_mediator;};
00976 void setMediator(SoLDMMediator* m);
00977
00978 virtual bool createTex(int Zaxis, SoState *state, const SbVec3i32 &tileSize, SoBufferObject *tileDataBuffer, SoTransferFunction *transferFunction,
00979 SoBufferObject*& textureBufferObject, int alphaUse = 0);
00980
00981
00983 void* getTexData(const void* tileBuffer,
00984 int numElem,
00985 SoTransferFunction* transferFunction,
00986 int alphaUse,
00987 int texPrec,
00988 void *textureBuffer,
00989 SoDataRange* datarange,
00990 SoDataCompositor* dataCompositor);
00991
00992
00993
00994
00995
00996 SoBufferObject* getTexData(SoBufferObject* tileBufferObject,
00997 SoTransferFunction* transferFunction,
00998 int alphaUse,
00999 int texPrec,
01000 SoBufferObject* textureBufferObject,
01001 SoDataRange* dataRange,
01002 SoDataCompositor* dataCompositor);
01003
01004 template <typename DataClassIn>
01005 static SoBufferObject *permuteData(const SbVec3i32& , SoBufferObject* , int );
01006
01007 inline virtual void computeLighting( const SbVec3i32& , SoBufferObject* ) {};
01008 int getRGBAInternalFormat() const;
01009
01010 virtual void updateColorTable(SoState *, SoTransferFunction *);
01011
01012 SoLDMResourceManager& getResourceManager() { return *m_resourceManager; }
01013
01018 virtual int getTexPrec(SoState*);
01019
01025 void getTextureFormat(SoTransferFunction::GLColorMapType colorMapType,
01026 GLenum& format,
01027 GLenum& dataType,
01028 GLint& internalFormat) const;
01029
01030
01031 virtual void drawTilesInMainMemory(SoState *state);
01032
01033
01034
01035 void copyLDMParameters(SoLDMMediator *mediator);
01036
01042 virtual bool isMultidataEnabled() const { return m_multidataEnabled; }
01043
01044
01045 enum BoxColor {
01046 GREY,
01047 RED,
01048 BLUE,
01049 GREEN,
01050 FULL_RES_GREY,
01051 FULL_RES_GREEN
01052 };
01053
01054 enum FieldId {
01055 MAX_MAIN_MEMORY = 0,
01056 MAX_TILES_IN_MAIN_MEMORY,
01057 LOAD_POLICY,
01058 LOAD_NOTIFICATION_RATE,
01059 MAX_TEX_MEMORY,
01060 MAX_TILES_IN_TEX_MEMORY,
01061 TEX3_LOAD_RATE,
01062 MAX_2D_TEXTURES,
01063 TEX2_LOAD_RATE,
01064 MIN_RESOLUTION_THRESHOLD,
01065 MAX_RESOLUTION_THRESHOLD,
01066 TILE_SIZE,
01067 FIX_PARAMS,
01068 OVERLAPPING,
01069 TILE_HALF_LIFE,
01070 FIXED_RESOLUTION_MODE,
01071 LAST_ID
01072 };
01073
01078 unsigned short getId() const
01079 { return m_id; }
01080
01084 inline bool hasReadError()
01085 { return m_hasReadError; };
01086
01090 inline bool isEmpty()
01091 {
01092 const SbVec3i32& dim = getDimension();
01093 return ( dim[0] == 0 || dim[1] == 0 || dim[2] == 0 );
01094 };
01095
01100 struct DatumElement{
01101 SoDataSet::DataType type;
01102 int num;
01103 };
01104
01111 float convertToNormalizedTextureSpace(SoState *state, const float data);
01112
01116 inline void setFirstTraversalDone(bool flag)
01117 { m_firstTraversalDone = flag; }
01118
01122 inline bool isFirstTraversalDone() const
01123 { return m_firstTraversalDone;}
01124
01125 virtual bool isPalettedTexture(SoState*);
01126
01127
01128
01129
01130 virtual uint64_t getTileSignature(const SoLDMTileID& tileId);
01131
01132
01133 uint64_t getUniqueId();
01134
01140 inline void setOwnedReader( SoVolumeReader &reader )
01141 { setReader( reader, TRUE ); };
01142
01143
01144
01145
01146
01147
01148 void refVolRender( int contextId );
01149 void unrefVolRender( int contextId );
01150
01157 int getBestEqualResolution() const;
01158
01163 void computeBestEqualResolution();
01164
01165 private:
01166
01168 SoDataSet();
01169
01171 virtual ~SoDataSet();
01172
01176 virtual void setElement(SoState* state);
01177
01181 inline bool isUsingUserExtent()
01182 { return m_useUserExtent; };
01183
01184
01185
01186
01187
01188
01189
01190
01191 virtual bool enableMultidata(SoState* state);
01192
01193
01194 virtual SoVolumeReader* getAppropriateReader();
01195
01197 bool m_forcePow2TileDim;
01198
01199
01200 SoRef<SoFieldContainer> m_reader;
01201 SbBool m_internalReader;
01202
01203
01204 bool m_listChange;
01205
01206 bool load(SoState*);
01207 virtual void unload();
01208 virtual void releaseMemory();
01209
01210 bool assignLDMMediator(SoState* state);
01211 bool m_multidataEnabled;
01212
01213 SbVec3i32 m_dimension;
01214 bool m_initialized;
01215
01216 SbDataType m_type;
01217 int m_numBits;
01218 bool m_isDataFloat;
01219 bool m_isDataSigned;
01220 unsigned int m_datumSize;
01221
01222 bool m_deletedFlag;
01223
01224 bool m_dataCharRead;
01225
01226 SbString m_filename;
01227 virtual void updateFilename();
01228
01229
01230 void dataIDChanged(int newId);
01231 unsigned short m_id;
01232
01233 void ldmResourceParamChanged();
01234
01238 virtual void readerChanged();
01239
01244 void extentChanged();
01245
01246 void initReader();
01247 void setType(SbDataType);
01248
01249
01250 void getFilePathName( SbString& pathName, SbString& fileExtension);
01251
01252 virtual SoLDMMediator *createMediator();
01253 SoLDMMediator* m_mediator;
01254
01255 SoMultiDataSeparator *m_MultiDataSeparator;
01256 bool m_ignoredByMultiDataSeparator;
01257
01258 SoLDMResourceManager* m_resourceManager;
01259
01260 virtual int isSharedPalettedTexture() { return FALSE; }
01261
01262 void getTransferFunction(SoTransferFunction *transferFunction, int alphaUse,
01263 int &shift, int &offset, int &nrgba, unsigned int * &rgba);
01264
01265 SbVec3i32 getPow2(SbVec3i32) const;
01266
01267
01268 void drawTiles(SoState *state, const SoLDM::TileIdVector& tileIDs,
01269 const SbVec4f &tileColor, const SbVec4f &maxLevelColor,
01270 size_t maxLineWidth);
01271 template<class DataType>
01272 void buildSlice(SoCpuBufferObject& slice, const SbVec3i32& min, const SbVec3i32& max, const SbVec2i32 sampleStep);
01273
01274 template<typename _DataType>
01275 void buildLine(SoCpuBufferObject& line, const SbVec3i32& min, const SbVec3i32& max, const int sampleStep );
01276
01277
01278
01279
01280 virtual void buildTile(SoLDMTileID tileID, SoBufferObject* buffer);
01281
01282
01283 virtual void readChar();
01284
01285
01286 virtual void setUseUserUndefinedValue(bool useUserUndefinedValue);
01287
01288 bool m_useUserExtent;
01289
01290 SoVolumeHistogram *m_histogram;
01291
01292
01293 SoCache* m_dataCompositorCache;
01294
01298 struct MTstruct {
01299 SoBufferObject *tmpTexture;
01300 SoCpuBufferUniform *tmpTextureUniform;
01301 SoBufferObject *tmpColormap;
01302 SoBufferObject *tmpTexturePermute;
01303 };
01304
01305
01306 SoINTERNAL private:
01307 SoSFFieldContainer customReader;
01308 SoSFBool customReaderOwnerShip;
01309
01314 SoSFLDMDataTransform editingStack;
01315
01316 virtual void ldmAction(SoLdmValuationAction* action);
01317
01321 virtual SbBool isRGBAData();
01322
01323 private:
01325 void updateDataSetId(SoState* state);
01326
01328 void enableThinVolume();
01329
01330
01331 void updateCompositorCache(SoState *state);
01332
01336 bool isValidDimension(const SbVec3i32& dim) const;
01337
01341 void displayReadError(int err);
01342
01347 SbVec3i32 clampTileDimension(const SbVec3i32& tileDim) const;
01348
01352 static const unsigned int MAX_DATASET_DIMENSION;
01353
01357 static const int MAX_TILE_DIMENSION;
01358
01359 bool isIdUsed(int id, std::vector<SoDataSet*>);
01360
01361 #ifndef HIDDEN_FROM_DOC
01362 friend class SoLDMMediator;
01363 friend class SoLDMMediator::LDMManagerAccess;
01364 friend class SoCpuBufferFromVolumeReader;
01365 #endif
01366
01367
01368
01369
01370 template<typename _DataType>
01371 void buildTileByLine(const SbBox3i32& tileBox, SoBufferObject* bufferObject);
01372
01373
01374
01375
01376
01377
01378 template<typename _DataType>
01379 void buildTileBySlice(const SbBox3i32& tileBox, SoBufferObject* bufferObject);
01380
01381
01382 bool m_filenameChange;
01383
01387 bool m_hasReadError;
01388
01389 bool m_accumulate;
01390
01391 SoPerfCounterManager* m_perf;
01392
01393
01394 SoPerfCounter* m_nbTexGen;
01395 SoPerfCounter* m_byteGetTexData;
01396 SoPerfCounter* m_timeCreateTex;
01397 SoPerfCounter* m_timeGetTexData;
01398
01399 static SoAlgorithms* s_algorithms;
01400 static SoLDMAlgorithms* s_LDMAlgorithms;
01401
01402 bool m_firstTraversalDone;
01403 friend class SoLdmValuationAction;
01404 bool m_ldmUseInMemCompression;
01405
01406 static int s_numInstance;
01407
01408
01409
01410
01411
01412 unsigned short m_resourcesState;
01413
01414 static uint64_t s_lasUniqId;
01415
01416
01417
01418 static SbThreadMutex s_sigCacheMutex;
01419
01420
01421 tileSigInCacheMap m_tileSigInCache;
01422
01423
01424
01425
01426 std::map<int, int> m_mapContextIdRef;
01427
01428
01429
01430 int m_bestEqualResolution;
01431
01433 static bool s_GPUDataRange;
01434 };
01435
01436 #ifdef _MSC_VER
01437 #pragma warning( pop )
01438 #endif
01439
01440 #endif // _SO_DATA_SET_
01441
01442
01443