gwnavruntime/basesystem/intcoordsystem.h Source File

intcoordsystem.h
Go to the documentation of this file.
1 /*
2 * Copyright 2015 Autodesk, Inc. All rights reserved.
3 * Use of this software is subject to the terms of the Autodesk license agreement and any attachments or Appendices thereto provided at the time of installation or download,
4 * or which otherwise accompanies this software in either electronic or hard copy form, or which is signed by you and accepted by Autodesk.
5 */
6 
7 
8 // primary contact: LASI - secondary contact: GUAL
9 #ifndef Navigation_IntCoordSystem_H
10 #define Navigation_IntCoordSystem_H
11 
12 
16 
17 
18 namespace Kaim
19 {
20 
21 #define KY_IntToPixelBitShift 7
22 #define KY_PixelSizeInIntCoord 128
23 #define KY_HalfPixelSizeInIntCoord 64
24 #define KY_PixelSizeInIntCoord_Float 128.0f
25 
26 class IntCoordSystem
27 {
28 public:
29  // [-320;-193] is snapped to -2
30  // [-192; -65] is snapped to -1
31  // [ -64; 64] is snapped to 0
32  // [ 65; 192] is snapped to 1
33  // [ 193; 320] is snapped to 2
34  // [ 321; 448] is snapped to 3
35  // ...
36  static inline KyInt32 NearestPixelCoord(KyInt32 x) { return IntToPixelCoord(x + Kaim::Isel(x, KY_HalfPixelSizeInIntCoord-1, KY_HalfPixelSizeInIntCoord)); }
37  static inline KyInt32 NearestPixelCoord(KyInt64 x) { return IntToPixelCoord(x + Kaim::Lsel(x, KY_HalfPixelSizeInIntCoord-1, KY_HalfPixelSizeInIntCoord)); }
38 
39  static inline KyInt32 IntPixelSize() { return KY_PixelSizeInIntCoord; }
40 
41  static inline KyInt32 IntToPixelCoord(KyInt32 intCoord) { return intCoord >> KY_IntToPixelBitShift; }
42  static inline KyInt32 IntToPixelCoord(KyInt64 intCoord) { return (KyInt32)(intCoord >> KY_IntToPixelBitShift); }
43  static inline KyInt32 PixelCoordToInt(KyInt32 pixelCoord) { return pixelCoord << KY_IntToPixelBitShift; }
44 
45  // one unit of Int in meter
46  static inline KyFloat32 IntegerPrecision(KyFloat32 rasterPrecision) { return rasterPrecision / KY_PixelSizeInIntCoord_Float; }
47  static inline KyFloat32 InvIntegerPrecision(KyFloat32 rasterPrecision) { return KY_PixelSizeInIntCoord_Float / rasterPrecision; }
48 
49  //PERF WARNING: Int->Float cast = LHS on PPC
50  static inline KyFloat32 IntToNavigation_Dist(KyInt32 intDist, KyFloat32 rasterPrecision)
51  {
52  return IntToNavigation(intDist, IntegerPrecision(rasterPrecision));
53  }
54 
55  //PERF WARNING: Int->Float cast = LHS on PPC
56  static inline KyInt32 NavigationToInt_Dist(KyFloat32 dist, KyFloat32 rasterPrecision)
57  {
58  return NavigationToInt(dist, InvIntegerPrecision(rasterPrecision));
59  }
60 
61  static inline void IntToNavigation_Pos(const Vec2i& intPos, Vec2f& pos, KyFloat32 rasterPrecision)
62  {
63  KyFloat32 integerPrecision = IntegerPrecision(rasterPrecision);
64  pos.x = IntToNavigation(intPos.x, integerPrecision);
65  pos.y = IntToNavigation(intPos.y, integerPrecision);
66  }
67 
68  //PERF WARNING: Int->Float cast = LHS on PPC
69  static inline void IntToNavigation_Pos(const Vec3i& intPos, Vec3f& pos, KyFloat32 rasterPrecision)
70  {
71  KyFloat32 integerPrecision = IntegerPrecision(rasterPrecision);
72  pos.x = IntToNavigation(intPos.x, integerPrecision);
73  pos.y = IntToNavigation(intPos.y, integerPrecision);
74  pos.z = IntToNavigation(intPos.z, integerPrecision);
75  }
76 
77  //PERF WARNING: Int->Float cast = LHS on PPC
78  static inline void PixelToNavigation_Pos(const Vec3i& intPos, Vec3f& pos, KyFloat32 integerPrecision)
79  {
80  pos.x = (KyFloat32)(PixelCoordToInt(intPos.x) * integerPrecision);
81  pos.y = (KyFloat32)(PixelCoordToInt(intPos.y) * integerPrecision);
82  pos.z = (KyFloat32)(PixelCoordToInt(intPos.z) * integerPrecision);
83  }
84 
85  //PERF WARNING: Int->Float cast = LHS on PPC
86  static inline void NavigationToInt_Pos(const Vec2f& pos, Vec2i& intPos, KyFloat32 rasterPrecision)
87  {
88  KyFloat32 invIntegerPrecision = InvIntegerPrecision(rasterPrecision);
89  intPos.x = NavigationToInt(pos.x, invIntegerPrecision);
90  intPos.y = NavigationToInt(pos.y, invIntegerPrecision);
91  }
92 
93  //PERF WARNING: Int->Float cast = LHS on PPC
94  static inline void NavigationToInt_Pos(const Vec3f& pos, Vec3i& intPos, KyFloat32 rasterPrecision)
95  {
96  KyFloat32 invIntegerPrecision = InvIntegerPrecision(rasterPrecision);
97  intPos.x = NavigationToInt(pos.x, invIntegerPrecision);
98  intPos.y = NavigationToInt(pos.y, invIntegerPrecision);
99  intPos.z = NavigationToInt(pos.z, invIntegerPrecision);
100  }
101 
102 private:
103  //PERF WARNING: Int->Float cast = LHS on PPC
104  static inline KyFloat32 IntToNavigation(KyInt32 intDist, KyFloat32 integerPrecision)
105  {
106  return ((KyFloat32)intDist) * integerPrecision;
107  }
108  //PERF WARNING: Int->Float cast = LHS on PPC
109  static inline KyInt32 NavigationToInt(KyFloat32 dist, KyFloat32 invIntegerPrecision)
110  {
111  return NearestInt(dist * invIntegerPrecision);
112  }
113 };
114 
115 }
116 
117 #endif
118 
KyInt32 Isel(KyInt32 a, KyInt32 x, KyInt32 y)
If a is greater than 0, returns x. Otherwise, returns y.
Definition: fastmath.h:70
int KyInt32
Type used internally to represent a 32-bit integer.
Definition: types.h:35
Definition: gamekitcrowddispersion.h:20
__int64 KyInt64
Type used internally to represent a 64-bit integer.
Definition: types.h:37
float KyFloat32
Type used internally to represent a 32-bit floating-point number.
Definition: types.h:43
KyInt64 Lsel(KyInt64 a, KyInt64 x, KyInt64 y)
If a is greater than 0, returns x. Otherwise, returns y.
Definition: fastmath.h:80