Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
SoSFImage3.h
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 : Patrick Vigneras (Nov 1999)
22**=======================================================================*/
23
24#ifndef _SO_SF_IMAGE_3_
25#define _SO_SF_IMAGE_3_
26
27#include <Inventor/fields/SoSubField.h>
28#include <Inventor/SbLinear.h>
29#include <Inventor/SbPList.h>
30#include <Inventor/devices/SoBufferObject.h>
31#include <Inventor/fields/SoSFImage.h>
32
34
36//
37// SoSFImage3 subclass of SoSField. This field handles 3 dimensional images,
38// that is a set of same-type (number of components) and same-size images.
39// It is basically useful for 3d texturing (see Inventor/nodes/SoTexture3.h).
40// This field uses a lot of memory (a simple 256x256x256 image in
41// grayscale already takes 16MB of memory). Therefore, as opposed to the
42// other fields, this field provides a way to manage memory and avoid
43// useless copies of data. This is essentially done through the CopyPolicy
44// enumeration and the set/isNeverWrite methods. The CopyPolicy provides
45// four types of memory management:
46// COPY is the default and is consistent with all other fields: any buffer
47// passed is copied and the memory management is done inside the field;
48// NO_COPY only uses a pointer given by the application which remains
49// responsible for the memory management;
50// NO_COPY_AND_DELETE accepts pointers from the application (ie does not
51// copy the buffer) but the field takes responsability for the memory
52// management. Note that this case is only intended for buffers
53// created with the operator 'new';
54// NO_COPY_AND_FREE is essentially the same as above but applies the function
55// 'free' on the pointer instead of the operator 'delete'.
56// Furthermore, two methods, is/setNeverWrite allow to write or not write
57// out the data stored in this field. By default, the 'never write' condition
58// is TRUE.
59//
61
120class SoSFImage3 : public SoSField {
121
122 // Uses only some of the standard field stuff (because there is no
123 // SbImage type):
124 SO_SFIELD_REQUIRED_HEADER(SoSFImage3);
125 SO_SFIELD_CONSTRUCTOR_HEADER(SoSFImage3);
126
127public:
128
158
167 const void* getValue( SbVec3i32& size, int& nc, SoSFImage::DataType& dataType ) const;
168
178 const unsigned char* getValue( SbVec3s& size, int& nc ) const;
179
187 SoBufferObject* getBufferObject( SbVec3i32& size, int& nc, SoSFImage::DataType& dataType ) const;
188
196 SoBufferObject* getBufferObject( SbVec3s& size, int& nc ) const;
197
202 void setValue( const SbVec3i32& size, int nc,
203 SoSFImage::DataType dataType,
204 const void* data,
205 CopyPolicy copy = COPY );
206
218 void setValue( const SbVec3i32& size, int nc,
219 SoSFImage::DataType dataType,
220 SoBufferObject* bufferObject,
221 CopyPolicy copy = COPY );
222
227 void setValue( const SbVec3s &size,
228 int nc,
229 unsigned char *bytes,
230 CopyPolicy copy = COPY );
231
235 void setValue( const SbVec3s &size,
236 int nc,
237 SoBufferObject* bufferObject,
238 CopyPolicy copy = COPY );
239
249 void setSubValue( const SbVec3i32& subSize,
250 const SbVec3i32& offset,
251 void* bytes,
252 CopyPolicy copy = COPY );
253
264 void setSubValue( const SbVec3s& subSize,
265 const SbVec3s& offset,
266 unsigned char* bytes,
267 CopyPolicy copy = COPY );
268
278 void setSubValues( const SbVec3i32* subSizes,
279 const SbVec3i32* offsets,
280 int num,
281 void** data,
282 CopyPolicy copy = COPY );
283
294 void setSubValues( const SbVec3s* subSizes,
295 const SbVec3s* offsets,
296 int num,
297 unsigned char** bytes,
298 CopyPolicy copy = COPY );
299
303 int operator==(const SoSFImage3 &f) const;
307 int operator!=(const SoSFImage3 &f) const
308 { return ! ((*this) == f); }
309
325 void* startEditing( SbVec3i32& size, int& nc, SoSFImage::DataType& dataType );
326
343 unsigned char* startEditing( SbVec3s& size, int& nc );
344
360
370 void* getSubTexture( int index, SbVec3i32& size, SbVec3i32& offset, SoSFImage::DataType& dataType );
371
383 unsigned char* getSubTexture( int index, SbVec3s& size, SbVec3s& offset );
384
391 SbBool hasSubTextures(int &numSubTextures);
392
399 void setNeverWrite(SbBool neverWrite);
407 { return m_neverWrite; }
408
409
411
413 int getNumComponents() const;
414
415 private:
416
417 static void initClass();
418 static void exitClass();
419 void resetSubTextures();
420
421 void deleteBytesArray();
422
424 SbBool hasTransparency() const;
425
427 void setHasTransparency(SoSFImage::HasTransparency status)
428 {
429 m_hasTransparencyState = status;
430 }
431
432private:
433
434 // Width, height and depth of image
435 SbVec3i32 m_size;
436
437 // Number of components per pixel
438 int m_numComponents;
439
443 unsigned char* m_buffer;
444
445 // Buffer object which contains the data.
446 SoRef<SoBufferObject> m_bufferObject;
447
451 SoRef<SoCpuBufferObject> m_cpuBufferObject;
452
453 CopyPolicy m_copyPolicy;
454
455 // list of [subSize,offset,bytes,copypolicy]
456 SbPList m_subTextures;
457
458 SbBool m_neverWrite;
459
460 SoSFImage::DataType m_dataType;
461
462 SoSFImage::HasTransparency m_hasTransparencyState;
463
464 size_t getImageValueSize() const;
465
466 // Reading and writing
467 virtual SbBool readValue(SoInput *in);
468 virtual void writeValue(SoOutput *out) const;
469};
470
471inline SoBufferObject*
473{
474 return m_bufferObject.ptr();
475}
476
477inline int
479{
480 return m_numComponents;
481}
482
483#endif /* _SO_SF_IMAGE_3_ */
484
List of generic (void *) pointers.
Definition SbPList.h:77
3D vector class.
Definition SbVec.h:1517
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> 3D vector class.
Definition SbVec.h:1797
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Abstract base cl...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> CPU buffer objec...
Used to read Open Inventor data files.
Definition SoInput.h:363
Used to write Open Inventor data files.
Definition SoOutput.h:186
Smart pointer for any class inheriting SoRefCounter.
Definition SoRef.h:90
T * ptr() const
Cast to C pointer.
Definition SoRef.h:167
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Field containing...
Definition SoSFImage3.h:120
SoBufferObject * getBufferObject(SbVec3i32 &size, int &nc, SoSFImage::DataType &dataType) const
Returns the pixels in the image as a buffer object.
SbBool isNeverWrite()
As this field may have to handle large amounts of data and its representation in an ....
Definition SoSFImage3.h:406
void setSubValues(const SbVec3s *subSizes, const SbVec3s *offsets, int num, unsigned char **bytes, CopyPolicy copy=COPY)
These methods may be used for subtexturing: instead of replacing the entire texture in texture memory...
const void * getValue(SbVec3i32 &size, int &nc, SoSFImage::DataType &dataType) const
Returns the pixels in the image as an array of values of type <dataType>.
SoBufferObject * getBufferObject(SbVec3s &size, int &nc) const
Returns the pixels in the image as a buffer object.
void setSubValue(const SbVec3i32 &subSize, const SbVec3i32 &offset, void *bytes, CopyPolicy copy=COPY)
These methods may be used for subtexturing: instead of replacing the entire texture in texture memory...
int operator==(const SoSFImage3 &f) const
Equality/inequality tests.
void setValue(const SbVec3i32 &size, int nc, SoSFImage::DataType dataType, const void *data, CopyPolicy copy=COPY)
Sets the value of this field to be an image of the given size, with the given number of components,...
void * getSubTexture(int index, SbVec3i32 &size, SbVec3i32 &offset, SoSFImage::DataType &dataType)
Returns a buffer to a given subTexture set by setSubValue, setSubValues, or a startEditing()/finishEd...
void setSubValue(const SbVec3s &subSize, const SbVec3s &offset, unsigned char *bytes, CopyPolicy copy=COPY)
These methods may be used for subtexturing: instead of replacing the entire texture in texture memory...
const unsigned char * getValue(SbVec3s &size, int &nc) const
Returns the pixels in the image as an array of unsigned chars.
unsigned char * startEditing(SbVec3s &size, int &nc)
These methods can be used to efficiently edit the values in an image field.
void setValue(const SbVec3s &size, int nc, unsigned char *bytes, CopyPolicy copy=COPY)
Sets the value of this field to be an image of the given size, with the given number of components,...
int operator!=(const SoSFImage3 &f) const
Equality/inequality tests.
Definition SoSFImage3.h:307
CopyPolicy
SoSFImage3 may be manipulating some large amounts of memory.
Definition SoSFImage3.h:138
@ NO_COPY_AND_FREE
Passed buffer used, SoSFImage3 will free .
Definition SoSFImage3.h:156
@ NO_COPY
Passed buffer used , user will delete .
Definition SoSFImage3.h:146
@ COPY
Open Inventor will make a copy of the data (default)
Definition SoSFImage3.h:142
@ NO_COPY_AND_DELETE
Passed buffer used, SoSFImage3 will delete .
Definition SoSFImage3.h:151
void setSubValues(const SbVec3i32 *subSizes, const SbVec3i32 *offsets, int num, void **data, CopyPolicy copy=COPY)
These methods may be used for subtexturing: instead of replacing the entire texture in texture memory...
SoBufferObject * getBufferObject() const
Definition SoSFImage3.h:472
void setValue(const SbVec3s &size, int nc, SoBufferObject *bufferObject, CopyPolicy copy=COPY)
Sets the value of this field to be an image of the given size, with the given number of components,...
void * startEditing(SbVec3i32 &size, int &nc, SoSFImage::DataType &dataType)
These methods can be used to efficiently edit the values in an image field.
SbBool hasSubTextures(int &numSubTextures)
Returns TRUE if subTextures have been defined or FALSE if none have been defined.
void setNeverWrite(SbBool neverWrite)
As this field may have to handle large amounts of data and its representation in an ....
int getNumComponents() const
Returns the number of components in each pixels of the image.
Definition SoSFImage3.h:478
void finishEditing()
These methods can be used to efficiently edit the values in an image field.
void setValue(const SbVec3i32 &size, int nc, SoSFImage::DataType dataType, SoBufferObject *bufferObject, CopyPolicy copy=COPY)
Sets the value of this field to be an image of the given size, with the given number of components,...
unsigned char * getSubTexture(int index, SbVec3s &size, SbVec3s &offset)
Returns a buffer to a given subTexture set by setSubValue, setSubValues, or a startEditing()/finishEd...
DataType
Encoding data type.
Definition SoSFImage.h:147
Abstract base class for all single-value fields.
Definition SoSField.h:93
int SbBool
Boolean type.
Definition SbBase.h:87