Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SbImageDataVoxel.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-2023 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : Julien Sallanne (Feb 2014)
22**=======================================================================*/
23
24#ifndef _SB_IMAGEDATAVOXEL_H_
25#define _SB_IMAGEDATAVOXEL_H_
26
27#include <ImageViz/SoImageViz.h>
30
32class SoDEPRECATED SbImageDataVoxel
47{
48public:
53 SbImageDataVoxel(const SbImageDataType& channelType, SoBufferObject* buffer, size_t offset);
54
57
60
63
65 inline const SbImageDataType& getImageDataType() const { return m_imageDataType; }
66
72 template <typename TypeOut> TypeOut castValue(size_t channelIndex) const;
73
79 template <typename TypeOut> TypeOut& getValue(size_t channelIndex);
80
81 template <typename TypeOut> const TypeOut& getValue(size_t channelIndex) const;
82
83private:
84
86 void* getDataPtr() const;
87
88private:
89
90 SbImageDataType m_imageDataType;
91 // Used to keep constructor buffer. It is mapped in SbImageDataVoxel constructor and
92 // unmapped in destructor.
93 SoRef<SoBufferObject> m_buffer;
94 // Offset use to map m_buffer to m_cpuBuffer.
95 size_t m_offset;
96 // CPU buffer containing data. It is mapped in SbImageDataVoxel constructor and
97 // unmapped in destructor. Basically, m_cpuBuffer = m_buffer->map() + offset;
98 SoRef<SoCpuBufferObject> m_cpuBuffer;
99 // Pointer to channels. Basically, m_ptr = m_cpuBuffer->map();
100 void* m_ptr;
101};
102
103
104//-----------------------------------------------------------------------------
105template <typename TypeOut>
106TypeOut
108{
109 if ( i >= getImageDataType().getNumChannel() )
110 throw SbException("out of range");
111
112 TypeOut dataValue;
113
114 switch ( m_imageDataType.getDataType() )
115 {
116 case SbDataType::UNSIGNED_BYTE : dataValue = TypeOut(((unsigned char*) m_ptr)[i]); break;
117 case SbDataType::UNSIGNED_SHORT: dataValue = TypeOut(((unsigned short*) m_ptr)[i]); break;
118 case SbDataType::UNSIGNED_INT32: dataValue = TypeOut(((unsigned int*) m_ptr)[i]); break;
119 case SbDataType::SIGNED_BYTE : dataValue = TypeOut(((signed char*) m_ptr)[i]); break;
120 case SbDataType::SIGNED_SHORT : dataValue = TypeOut(((signed short*) m_ptr)[i]); break;
121 case SbDataType::SIGNED_INT32 : dataValue = TypeOut(((signed int*) m_ptr)[i]); break;
122 case SbDataType::FLOAT : dataValue = TypeOut(((float*) m_ptr)[i]); break;
123 case SbDataType::DOUBLE : dataValue = TypeOut(((double*) m_ptr)[i]); break;
124 default : SoDebugError::postWarning("SbImageDataVoxel::castValue()", "Unknown data type %s", m_imageDataType.getDataType().getString().toLatin1()); dataValue = 0; break;
125 }
126 return dataValue;
127}
128
129//-----------------------------------------------------------------------------
130template <typename TypeOut>
131const TypeOut&
133{
134 if ( i >= getImageDataType().getNumChannel() )
135 throw SbException("out of range");
136
137 TypeOut returnValue;
138 const SbDataType dataTypeOut = SbDataType::getTemplateType(returnValue);
139
140 if ( dataTypeOut != getImageDataType().getDataType() )
141 throw SbException("inconsistent dataType");
142
143 return ((TypeOut*) m_ptr)[i];
144}
145
146//-----------------------------------------------------------------------------
147template <typename TypeOut>
148TypeOut&
150{
151 if ( i >= getImageDataType().getNumChannel() )
152 throw SbException("out of range");
153
154 TypeOut returnValue;
155 const SbDataType dataTypeOut = SbDataType::getTemplateType(returnValue);
156
157 if ( dataTypeOut != getImageDataType().getDataType() )
158 throw SbException("inconsistent dataType");
159
160 return ((TypeOut*) m_ptr)[i];
161}
162
163#endif // _SB_IMAGEDATAVOXEL_H_
164
valueRef getValue() const
Definition SoSubField.h:234
Class encoding a data type.
Definition SbDataType.h:58
@ 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
SbString getString() const
Returns the type as a string, e.g.
<a href="IconLegend.html"><img src="extIP.gif" alt="ImageViz" border="0"></a> Basic class representi...
const SbDataType & getDataType() const
Return type of channels.
<a href="IconLegend.html"><img src="extIP.gif" alt="ImageViz" border="0"></a> Utility class used to ...
TypeOut castValue(size_t channelIndex) const
Return value casted to the proper type.
SbImageDataVoxel(const SbImageDataVoxel &)
Copy constructor.
TypeOut & getValue(size_t channelIndex)
Return reference to values.
const SbImageDataVoxel & operator=(const SbImageDataVoxel &right)
Copy operator.
SbImageDataVoxel(const SbImageDataType &channelType, SoBufferObject *buffer, size_t offset)
const SbImageDataType & getImageDataType() const
Return channel type.
~SbImageDataVoxel()
Unmap buffer.
const char * toLatin1() const
Returns the string as a Latin-1/ASCII C string.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
static void postWarning(const char *methodName, const char *formatString ...)
Posts a warning.
Smart pointer for any class inheriting SoRefCounter.
Definition SoRef.h:90