Open Inventor Release 2024.1.0
 
Loading...
Searching...
No Matches
SoJp3dDataCompressor.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 : VSG (MMM YYYY)
22**=======================================================================*/
23
24
25#pragma once
26
28class SoDEPRECATED SoJp3dDataCompressor : public SoDataCompressor
63{
65
66public:
71
76
85
90 virtual bool isLossless();
91
101 virtual size_t compress( void* src, size_t srcLen, const TileInfo& tileInfo );
102
112 virtual size_t uncompress( void* dst, size_t dstLen, const TileInfo& tileInfo );
113
114
115private:
127 template<typename T, typename MappingType>
128 static void map( T* src, MappingType* dst, size_t sampleCount, const SbVec2d& range );
129
141 template <typename T, typename MappingType>
142 static void unmap( MappingType* src, T* dst, size_t sampleCount, const SbVec2d& range );
143
149 size_t uncompressRaw( void* dst, size_t dstLen, const TileInfo& tileInfo );
150
156 template <typename T>
157 size_t uncompressAndUnmap( void* dst, size_t dstLen, const TileInfo& tileInfo );
158};
159
160//*****************************************************************************
161template<typename T, typename MappingType>
162void
163SoJp3dDataCompressor::map( T* src, MappingType* dst, size_t sampleCount, const SbVec2d& range )
164{
165 double rangeOffset = range[0];
166 double rangeMax = range[1] - range[0];
167 double ratio = 0.0;
168
169 for ( size_t i = 0; i < sampleCount; ++i )
170 {
171 ratio = ( static_cast<double>( src[i] ) - rangeOffset ) / rangeMax;
172 dst[i] = static_cast<MappingType>( ratio * std::numeric_limits<uint16_t>::max() );
173 }
174}
175
176//*****************************************************************************
177template <typename T, typename MappingType>
178void
179SoJp3dDataCompressor::unmap( MappingType* src, T* dst, size_t sampleCount, const SbVec2d& range )
180{
181 double rangeMin = range[0];
182 double rangeMax = range[1];
183 double mappingRange = rangeMax - rangeMin;
184 double ratio = 0.0;
185
186 for ( size_t i = 0; i < sampleCount; ++i )
187 {
188 ratio = static_cast<double>( src[i] ) / std::numeric_limits<MappingType>::max();
189 dst[i] = static_cast<T>( rangeMin + ratio*mappingRange );
190 }
191}
192
193//*****************************************************************************
194template <typename T>
195size_t
196SoJp3dDataCompressor::uncompressAndUnmap( void* dst, size_t dstLen, const TileInfo& tileInfo )
197{
198 T* dstBuffer = reinterpret_cast<T*>( dst );
199
200 size_t sampleCount = tileInfo.dims[0];
201 sampleCount *= tileInfo.dims[1];
202 sampleCount *= tileInfo.dims[2];
203
204 size_t dstSampleCount = dstLen / sizeof( T );
205
206 if ( sampleCount > dstSampleCount )
207 {
209 "SoJp3dDataCompressor::uncompressAndUnmap",
210 "%ld samples to uncompress, only space for %ld samples in destination.", sampleCount, dstSampleCount
211 );
212
213 return 0;
214 }
215
216 std::vector<uint16_t> mapBuffer( sampleCount );
217 size_t uncompressedBytes = uncompressRaw( &mapBuffer[0], mapBuffer.size() * sizeof( uint16_t ), tileInfo );
218 size_t uncompressedSamples = uncompressedBytes / sizeof( uint16_t );
219
220 if ( uncompressedSamples != sampleCount )
221 {
223 "SoJp3dDataCompressor::uncompressAndUnmap",
224 "incorrect sample count, %ld sampled decoded on %ld.", uncompressedSamples, sampleCount
225 );
226
227 return 0;
228 }
229
230 unmap( &mapBuffer[0], dstBuffer, mapBuffer.size(), tileInfo.range );
231
232 return mapBuffer.size() * sizeof( T );
233}
#define SO_TYPED_CLASS_HEADER()
Class for smart character strings.
Definition SbString.h:202
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> 2D vector class ...
Definition SbVec.h:314
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Data com...
static void post(const char *methodName, const char *formatString ...)
Posts an error.
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> JP3D dat...
virtual size_t uncompress(void *dst, size_t dstLen, const TileInfo &tileInfo)
Uncompresses data from the internal buffer to the given buffer.
SoJp3dDataCompressor()
Constructor.
virtual ~SoJp3dDataCompressor()
Destructor.
virtual SbString getCompressionFormatName() const
Returns the name of the compression algorithm used by this class.
virtual size_t compress(void *src, size_t srcLen, const TileInfo &tileInfo)
Compresses the given buffer into the internal buffer.
virtual bool isLossless()
Checks if the compression is lossless.
T rangeMax()
Returns the maximum finite value representable by the numeric type T.
T rangeMin()
Returns the lowest finite value representable by the numeric type T, that is, a finite value x such t...
This structure contains the dimension and the type of the tile being processed.