Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoVolumeHistogram.h
Go to the documentation of this file.
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2024 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : T.DUFOUR (May 2004)
22**=======================================================================*/
23
24#ifndef _SO_VOLUME_HISTOGRAM_
25#define _SO_VOLUME_HISTOGRAM_
26
27#ifdef _MSC_VER
28#pragma warning( push )
29#pragma warning(disable:4251)
30#pragma warning(disable:4127)
31#endif
32
33#include <Inventor/SbDataType.h>
34#include <Inventor/SbLinear.h>
36
37#include <Inventor/STL/limits>
38#include <Inventor/STL/vector>
39
40class SoBufferObject;
41class SoArithmetic;
42
77{
78public:
82 SoVolumeHistogram(const SbDataType &dataType);
83
88
94 void setInputValueRange( double rangeMin, double rangeMax );
95
100 void setUndefinedValue( const double undefinedValue)
101 { m_undefinedValue=undefinedValue; }
102
107 double getUndefinedValue() const
108 { return m_undefinedValue; };
109
114 size_t getHistoSize() const;
115
122 int64_t* getHistogram();
123
128 int64_t getNumValues(size_t entry);
129
133 int64_t getValue(size_t entry);
134
138 double getValueD(size_t entry);
139
144 int64_t getMinValue() const;
145
150 int64_t getMaxValue() const;
151
156 double getMinValueD() const;
157
162 double getMaxValueD() const;
163
168 double getMax() const;
169
174 double getMin() const;
175
181
186 inline void addValues(SoBufferObject* values, const int numValues);
187
191 inline void addValues(SoBufferObject* values, const SbVec3i32& arrayDim);
192
196 void addValues(SoBufferObject* values, const SbVec3i32& arrayDim, const SbBox3i32& range);
197
201 void set(const std::vector<int64_t> & histo);
202
206 void set(const std::vector<int64_t>& histo, const std::vector<double>& values);
207
211 template<typename T> inline size_t getEntry(T value) const;
212
222 static void computeMinMax(
223 SoBufferObject* valuesBuffer,
224 const SbDataType& dataType,
225 const SbVec3i32& arrayDim,
226 const SbBox3i32& range,
227 double& min,
228 double& max
229 );
230
242 SoBufferObject* valuesBuffer,
243 const double undefinedValue,
244 const SbDataType& dataType,
245 const SbVec3i32& arrayDim,
246 const SbBox3i32& range,
247 double& min,
248 double& max
249 );
250
258 static void computeMinMax(
259 void* valuesBuffer,
260 const SbDataType& dataType,
261 const SbVec3i32& arrayDim,
262 SbVec2d& minMax);
263
273 void* valuesBuffer,
274 const double undefinedValue,
275 const SbDataType& dataType,
276 const SbVec3i32& arrayDim,
277 SbVec2d& minMax
278 );
279
280private:
284 static void initClass();
285 static void exitClass();
286
287private:
291 template<typename T> inline size_t getEntryInternal(T value) const;
292
298 template<typename T> inline size_t getEntryCaster(T value) const;
299
301 unsigned int computeNumSignificantBits() const;
302
303 std::vector<int64_t> m_histo; // histogram
304 int64_t m_valueMin; // min integer value of the dataset for integer data types
305 int64_t m_valueMax; // max integer value of the dataset for integer data types
306 double m_valueMinD; // min integer value of the dataset for floating data types
307 double m_valueMaxD; // max integer value of the dataset for floating data types
308 unsigned int m_numSignificantBits; // number of significant bits, only relevant for integer data types
309
310 SbDataType m_dataType; // data type
311 double m_rangeMin; // for floating data type.
312 double m_rangeMax; // for floating data type.
313 double m_undefinedValue; // undefined Value.
314
315 // makeStats template
316 template <typename T>
317 void makeStat(
318 const void* values,
319 const SbVec3i32& arrayDim,
320 const SbBox3i32& range
321 );
322
323 static SoArithmetic* s_arithmeticInterface;
324};
325
326/*******************************************************************************/
327void
328SoVolumeHistogram::addValues(SoBufferObject* values, const int numValues)
329{
330 addValues(values, SbVec3i32(numValues, 1, 1), SbBox3i32(SbVec3i32(0, 0, 0), SbVec3i32(numValues, 1, 1)));
331}
332
333/*******************************************************************************/
335{
336 addValues(values, arrayDim, SbBox3i32(SbVec3i32(0,0,0),arrayDim));
337}
338
339/*******************************************************************************/
340template<typename T> size_t
341SoVolumeHistogram::getEntryInternal(T value) const
342{
343 assert(m_dataType.isInteger());
344 assert(sizeof(T) <= 4);
345 size_t offset = 0;
346 size_t factor = 1;
347
348 if ( std::numeric_limits<T>::is_signed )
349 offset = (sizeof(T) >= 2) ? 0x8000 : 0x80;
350
351 if ( sizeof(T) == 4 )
352 factor = (size_t)0x10000;
353
354 size_t entry = (size_t)(value/int64_t(factor)+int64_t(offset));
355
356 return entry;
357}
358
359/*******************************************************************************/
360template<typename T> size_t
361SoVolumeHistogram::getEntryCaster(T value) const
362{
363 return getEntryInternal(T(value));
364}
365
366/*******************************************************************************/
367template<typename T> size_t
369{
370 size_t ret = 0;
371
372 switch (m_dataType)
373 {
375 ret = getEntryInternal<unsigned short>((unsigned short)value);
376 break;
378 ret = getEntryInternal<uint32_t>((uint32_t)value);
379 break;
381 ret = getEntryInternal<signed char>((signed char)value);
382 break;
384 ret = getEntryInternal<signed short>((signed short)value);
385 break;
387 ret = getEntryInternal<int32_t>((int32_t)value);
388 break;
390 ret = getEntryInternal<float>((float)value);
391 break;
393 ret = getEntryInternal<unsigned char>((unsigned char)value);
394 break;
396 ret = getEntryInternal<double>((double)value);
397 break;
398 default:
399 assert(0);
400 break;
401 }
402
403 return ret;
404}
405
406/*******************************************************************************/
407template<> inline size_t
408SoVolumeHistogram::getEntryInternal<float>(float value) const
409{
410 assert(m_dataType == SbDataType::FLOAT);
411 if ( m_rangeMax == m_rangeMin )
412 return 0;
413 double factorDouble = 0.0f;
414 factorDouble = 0xffff / (m_rangeMax - m_rangeMin);
415 size_t entry = (size_t)((value-m_rangeMin)*factorDouble);
416
417 return SbMathHelper::Clamp(entry, (size_t)0, (size_t)0xffff);
418}
419
420/*******************************************************************************/
421template<> inline size_t
422SoVolumeHistogram::getEntryInternal<double>(double value) const
423{
424 assert(m_dataType == SbDataType::DOUBLE);
425 if ( m_rangeMax == m_rangeMin )
426 return 0;
427 double factorDouble = 0.0f;
428 factorDouble = 0xffff / (m_rangeMax - m_rangeMin);
429 size_t entry = (size_t)((value-m_rangeMin)*factorDouble);
430
431 return SbMathHelper::Clamp(entry, (size_t)0, (size_t)0xffff);
432}
433
434#ifdef _MSC_VER
435#pragma warning( pop )
436#endif
437
438#endif /* _SO_VOLUME_HISTOGRAM_ */
439
440
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> 3D box class.
Definition SbBox.h:96
Class encoding a data type.
Definition SbDataType.h:58
SbBool isInteger() const
Returns true if the type is an integer type.
Definition SbDataType.h:274
@ FLOAT
float
Definition SbDataType.h:78
@ SIGNED_BYTE
signed byte
Definition SbDataType.h:72
@ UNSIGNED_INT32
unsigned int (32bits)
Definition SbDataType.h:70
@ DOUBLE
Double.
Definition SbDataType.h:80
@ UNSIGNED_BYTE
unsigned byte
Definition SbDataType.h:66
@ SIGNED_SHORT
signed short
Definition SbDataType.h:74
@ UNSIGNED_SHORT
unsigned short
Definition SbDataType.h:68
@ SIGNED_INT32
signed int (32bits)
Definition SbDataType.h:76
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> 2D vector class ...
Definition SbVec.h:314
3D vector class.
Definition SbVec.h:1517
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Arithmetic funct...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
Volume Data Histogram.
void set(const std::vector< int64_t > &histo)
Set the histogram.
void addValues(SoBufferObject *values, const int numValues)
Add to the histogram a 1D array of values.
void setUndefinedValue(const double undefinedValue)
Setup the undefined value to ignore when computing the histogram.
static void computeMinMaxWithUndefined(SoBufferObject *valuesBuffer, const double undefinedValue, const SbDataType &dataType, const SbVec3i32 &arrayDim, const SbBox3i32 &range, double &min, double &max)
Compute min max.
double getMaxValueD() const
Returns the max value of the dataset for floating data types.
static void computeMinMax(void *valuesBuffer, const SbDataType &dataType, const SbVec3i32 &arrayDim, SbVec2d &minMax)
Compute min max.
static void computeMinMax(SoBufferObject *valuesBuffer, const SbDataType &dataType, const SbVec3i32 &arrayDim, const SbBox3i32 &range, double &min, double &max)
Compute min max.
size_t getEntry(T value) const
Returns the histogram entry corresponding to the value.
size_t getHistoSize() const
Returns the size of the histogram.
double getMax() const
Returns the max value of the dataset according to the specified data type.
int64_t getNumValues(size_t entry)
Returns the histogram value corresponding to the entry.
int64_t getMaxValue() const
Returns the max value of the dataset for integer data types.
double getValueD(size_t entry)
Returns the value corresponding to the entry for floating data types.
int64_t getValue(size_t entry)
Returns the value corresponding to the entry for integer data types.
void addValues(SoBufferObject *values, const SbVec3i32 &arrayDim, const SbBox3i32 &range)
Add to the histogram the values in the specified range inside the given array.
~SoVolumeHistogram()
Destructor.
int64_t * getHistogram()
Returns a 64 bit integer pointer to the histogram data, the size of the histogram array is getHistoSi...
void set(const std::vector< int64_t > &histo, const std::vector< double > &values)
Set the histogram.
int getNumSignificantBits() const
Returns the number of significant bits for the dataset, only relevant for integer data types.
static void computeMinMaxWithUndefined(void *valuesBuffer, const double undefinedValue, const SbDataType &dataType, const SbVec3i32 &arrayDim, SbVec2d &minMax)
Compute min max.
double getUndefinedValue() const
return the current undefined value.
double getMinValueD() const
Returns the min value of the dataset for floating data types.
SoVolumeHistogram(const SbDataType &dataType)
Constructor.
int64_t getMinValue() const
Returns the min value of the dataset for integer data types.
void setInputValueRange(double rangeMin, double rangeMax)
For floating data type, specifies the range the histogram has to be computed in.
double getMin() const
Returns the max value of the dataset according to the specified data type.
T Clamp(T a, T minV, T maxV)
Clamps value to given range [minV, maxV].