PxCoreUtilityTypes.h
Go to the documentation of this file.
1 //
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions
4 // are met:
5 // * Redistributions of source code must retain the above copyright
6 // notice, this list of conditions and the following disclaimer.
7 // * Redistributions in binary form must reproduce the above copyright
8 // notice, this list of conditions and the following disclaimer in the
9 // documentation and/or other materials provided with the distribution.
10 // * Neither the name of NVIDIA CORPORATION nor the names of its
11 // contributors may be used to endorse or promote products derived
12 // from this software without specific prior written permission.
13 //
14 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
15 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26 // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved.
27 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
28 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
29 
30 
31 #ifndef PX_CORE_UTILTY_TYPES_H
32 #define PX_CORE_UTILTY_TYPES_H
33 
37 #include "foundation/PxAssert.h"
38 #include "foundation/PxMemory.h"
39 
40 #if !PX_DOXYGEN
41 namespace physx
42 {
43 #endif
44 
45 
47 {
54  const void* data;
55 
56  PxStridedData() : stride( 0 ), data( NULL ) {}
57 
58  template<typename TDataType>
59  PX_INLINE const TDataType& at( PxU32 idx ) const
60  {
61  PxU32 theStride( stride );
62  if ( theStride == 0 )
63  theStride = sizeof( TDataType );
64  PxU32 offset( theStride * idx );
65  return *(reinterpret_cast<const TDataType*>( reinterpret_cast< const PxU8* >( data ) + offset ));
66  }
67 };
68 
69 template<typename TDataType>
71 {
73  const TDataType* data;
74 
76  : stride( 0 )
77  , data( NULL )
78  {
79  }
80 
81 };
82 
84 {
86  PxBoundedData() : count( 0 ) {}
87 };
88 
89 template<PxU8 TNumBytes>
90 struct PxPadding
91 {
92  PxU8 mPadding[TNumBytes];
94  {
95  for ( PxU8 idx =0; idx < TNumBytes; ++idx )
96  mPadding[idx] = 0;
97  }
98 };
99 
100 template <PxU32 NB_ELEMENTS> class PxFixedSizeLookupTable
101 {
102 //= ATTENTION! =====================================================================================
103 // Changing the data layout of this class breaks the binary serialization format. See comments for
104 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
105 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
106 // accordingly.
107 //==================================================================================================
108 public:
109 
111  : mNbDataPairs(0)
112  {
113  }
114 
116 
117  PxFixedSizeLookupTable(const PxReal* dataPairs, const PxU32 numDataPairs)
118  {
119  PxMemCopy(mDataPairs,dataPairs,sizeof(PxReal)*2*numDataPairs);
120  mNbDataPairs=numDataPairs;
121  }
122 
124  {
125  PxMemCopy(mDataPairs,src.mDataPairs,sizeof(PxReal)*2*src.mNbDataPairs);
126  mNbDataPairs=src.mNbDataPairs;
127  }
128 
130  {
131  }
132 
134  {
135  PxMemCopy(mDataPairs,src.mDataPairs,sizeof(PxReal)*2*src.mNbDataPairs);
136  mNbDataPairs=src.mNbDataPairs;
137  return *this;
138  }
139 
140  PX_FORCE_INLINE void addPair(const PxReal x, const PxReal y)
141  {
142  PX_ASSERT(mNbDataPairs<NB_ELEMENTS);
143  mDataPairs[2*mNbDataPairs+0]=x;
144  mDataPairs[2*mNbDataPairs+1]=y;
145  mNbDataPairs++;
146  }
147 
149  {
150  if(0==mNbDataPairs)
151  {
152  PX_ASSERT(false);
153  return 0;
154  }
155 
156  if(1==mNbDataPairs || x<getX(0))
157  {
158  return getY(0);
159  }
160 
161  PxReal x0=getX(0);
162  PxReal y0=getY(0);
163 
164  for(PxU32 i=1;i<mNbDataPairs;i++)
165  {
166  const PxReal x1=getX(i);
167  const PxReal y1=getY(i);
168 
169  if((x>=x0)&&(x<x1))
170  {
171  return (y0+(y1-y0)*(x-x0)/(x1-x0));
172  }
173 
174  x0=x1;
175  y0=y1;
176  }
177 
178  PX_ASSERT(x>=getX(mNbDataPairs-1));
179  return getY(mNbDataPairs-1);
180  }
181 
182  PxU32 getNbDataPairs() const {return mNbDataPairs;}
183 
184  void clear()
185  {
186  memset(mDataPairs, 0, NB_ELEMENTS*2*sizeof(PxReal));
187  mNbDataPairs = 0;
188  }
189 
191  {
192  return mDataPairs[2*i];
193  }
195  {
196  return mDataPairs[2*i+1];
197  }
198 
199  PxReal mDataPairs[2*NB_ELEMENTS];
201  PxU32 mPad[3];
202 
203 
204 };
205 
206 #if !PX_DOXYGEN
207 } // namespace physx
208 #endif
209 
211 #endif
Definition: GuContactBuffer.h:37
PxFixedSizeLookupTable(const PxFixedSizeLookupTable &src)
Definition: PxCoreUtilityTypes.h:123
Definition: PxCoreUtilityTypes.h:70
PxFixedSizeLookupTable(const PxEMPTY)
Definition: PxCoreUtilityTypes.h:115
PxFixedSizeLookupTable(const PxReal *dataPairs, const PxU32 numDataPairs)
Definition: PxCoreUtilityTypes.h:117
PX_INLINE const TDataType & at(PxU32 idx) const
Definition: PxCoreUtilityTypes.h:59
#define PX_FORCE_INLINE
Definition: PxPreprocessor.h:351
float PxReal
Definition: PxSimpleTypes.h:78
PX_FORCE_INLINE void * PxMemCopy(void *dest, const void *src, PxU32 count)
Copies the bytes of one memory block to another. The memory blocks must not overlap.
Definition: PxMemory.h:84
PxTypedStridedData()
Definition: PxCoreUtilityTypes.h:75
PxU32 mNbDataPairs
Definition: PxCoreUtilityTypes.h:200
PxFixedSizeLookupTable()
Definition: PxCoreUtilityTypes.h:110
Definition: PxCoreUtilityTypes.h:100
PxU32 stride
The offset in bytes between consecutive samples in the data.
Definition: PxCoreUtilityTypes.h:53
PX_FORCE_INLINE void addPair(const PxReal x, const PxReal y)
Definition: PxCoreUtilityTypes.h:140
PX_FORCE_INLINE PxReal getX(const PxU32 i) const
Definition: PxCoreUtilityTypes.h:190
uint8_t PxU8
Definition: PxSimpleTypes.h:75
PxPadding()
Definition: PxCoreUtilityTypes.h:93
PxU32 count
Definition: PxCoreUtilityTypes.h:85
const void * data
Definition: PxCoreUtilityTypes.h:54
Definition: PxCoreUtilityTypes.h:46
Definition: PxCoreUtilityTypes.h:90
PxFixedSizeLookupTable & operator=(const PxFixedSizeLookupTable &src)
Definition: PxCoreUtilityTypes.h:133
PxEMPTY
Definition: Px.h:70
PX_FORCE_INLINE PxReal getY(const PxU32 i) const
Definition: PxCoreUtilityTypes.h:194
PxReal mDataPairs[2 *NB_ELEMENTS]
Definition: PxCoreUtilityTypes.h:199
#define PX_ASSERT(exp)
Definition: PxAssert.h:59
~PxFixedSizeLookupTable()
Definition: PxCoreUtilityTypes.h:129
PxBoundedData()
Definition: PxCoreUtilityTypes.h:86
uint32_t PxU32
Definition: Px.h:48
PxStridedData()
Definition: PxCoreUtilityTypes.h:56
PX_FORCE_INLINE PxReal getYVal(const PxReal x) const
Definition: PxCoreUtilityTypes.h:148
#define PX_INLINE
Definition: PxPreprocessor.h:336
Definition: PxCoreUtilityTypes.h:83
void clear()
Definition: PxCoreUtilityTypes.h:184
const TDataType * data
Definition: PxCoreUtilityTypes.h:73
PxU32 getNbDataPairs() const
Definition: PxCoreUtilityTypes.h:182
PxU32 stride
Definition: PxCoreUtilityTypes.h:72