gwnavruntime/visualsystem/displayflags.h Source File

displayflags.h
Go to the documentation of this file.
1 /*
2 * Copyright 2016 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 #pragma once
8 
11 
12 namespace Kaim
13 {
14 
15 // [ styleQ 7 bits ][ styleP 7 bits ][ stylePQ 7 bits ][ Faces 3 bits ][ Precision 3 bits ][ DataType 5 bits ]
16 struct DisplayBits {
17  enum {
18  Count_DataType = 5,
19  Count_Precision = 3,
20  Count_Faces = 3,
21  Count_Style = 7,
22 
23  Offset_DataType = 0,
24  Offset_Precision = Offset_DataType + Count_DataType,
25  Offset_Faces = Offset_Precision + Count_Precision,
26  Offset_PQ = Offset_Faces + Count_Faces,
27  Offset_P = Offset_PQ + Count_Style,
28  Offset_Q = Offset_P + Count_Style,
29 
30  Mask_DataType = ((1 << Count_DataType ) - 1) << Offset_DataType,
31  Mask_Precision = ((1 << Count_Precision) - 1) << Offset_Precision,
32  Mask_Faces = ((1 << Count_Faces ) - 1) << Offset_Faces,
33  Mask_PQ = ((1 << Count_Style ) - 1) << Offset_PQ,
34  Mask_P = ((1 << Count_Style ) - 1) << Offset_P,
35  Mask_Q = ((1 << Count_Style ) - 1) << Offset_Q
36  };
37 };
38 
39 struct DisplayDataType {
40  enum Enum {
41  Point = 1,
42  PointRadius = 2,
43  PointHeight = 3,
44  PointHeightRadius = 4,
45  Segment = 5,
46  SegmentRadius = 6,
47  SegmentHeight = 7,
48  SegmentHeightRadius = 8,
49  Triangle = 9,
50  Quad = 10,
51  Box = 11,
52  Donut = 12,
53  SegmentVerticalQuad = 13,
54  OrientedBox2d = 14,
55  OrientedBox3d = 15,
56  DiskSector = 16,
57  Parabola = 17,
58  Ladder = 18
59  };
60 };
61 
62 
63 struct DisplayPrecision {
64  enum Enum {
65  _50cm = 0,
66  _10cm = 1,
67  _5cm = 2,
68  _2cm = 3,
69  _1cm = 4,
70  _5mm = 5,
71  _2mm = 6,
72  _1mm = 7
73  };
74 };
75 
76 struct DisplayFaces {
77  enum Enum {
78  All = 0,
79  SidesOnly = 1,
80  };
81 };
82 
83 
84 struct DisplayStyle {
85  enum Enum {
86  // 3d Segment
87  Line = 1,
88  Pyramid = 2,
89  PyramidInv = 3,
90  TriangleCross = 4,
91  TriangleCrossInv = 5,
92  Box = 6,
93  SquareTube = 7,
94 
95  // Vertical Segment
96  VerticalCylinder = 20,
97  VerticalPentagon = 21,
98  VerticalHexagon = 22,
99  VerticalOctogon = 23,
100  VerticalFlag = 24,
101 
102  // 2d5 Segment
103  Triangle2d5 = 30,
104  SegmentQuad2d5 = 31,
105  Capsule2d5 = 32,
106 
107  // Arrow
108  Arrow2d5 = 40,
109  Arrow2d5_Double = 41,
110  ArrowPyramid = 42,
111  ArrowPyramid_Double = 43,
112  ArrowTube = 44,
113  ArrowTube_Double = 45,
114 
115  // Point
116  LineCross3d = 50,
117  LineCross2d = 51,
118  Quad2d = 52,
119  Disk2d = 53,
120  Pentagon2d = 54,
121  Hexagon2d = 55,
122  Octogon2d = 56,
123  ArrowCross2d = 57,
124  QuadAndCross2d = 58,
125  DiskAndCross2d = 59,
126  OctogonAndCross2d = 60,
127  Diamond2d = 61,
128  DiagonalCross2d = 62,
129  DiamondAndCross2d = 63,
130  QuadAndDiagonalCross2d = 64,
131 
132  // Other Segments
133  Parabola = 80,
134  ShearedBox = 81,
135  Ladder = 82,
136  ExtrudedLine = 83,
137  };
138 };
139 
140 class DisplayFlags
141 {
142 private:
143  explicit DisplayFlags(KyUInt32 flags) : m_flags(flags) {}
144  typedef DisplayDataType DataType;
145  typedef DisplayPrecision Precision;
146  typedef DisplayFaces Faces;
147  typedef DisplayStyle Style;
148  typedef DisplayBits Bits;
149 
150 public:
151  DisplayFlags() : m_flags(0) {}
152 
153  static DisplayFlags P(DisplayStyle::Enum e) { return DisplayFlags(KyUInt32(e) << Bits::Offset_P); }
154  static DisplayFlags PQ(DisplayStyle::Enum e) { return DisplayFlags(KyUInt32(e) << Bits::Offset_PQ); }
155  static DisplayFlags Make(Precision::Enum e) { return DisplayFlags(KyUInt32(e) << Bits::Offset_Precision); }
156  static DisplayFlags Make(DisplayFaces::Enum e) { return DisplayFlags(KyUInt32(e) << Bits::Offset_Faces); }
157 
158  DisplayFlags& Set(DisplayDataType::Enum e) { m_flags = (KyUInt32(e) << Bits::Offset_DataType ) | (m_flags & ~Bits::Mask_DataType ); return *this; }
159  DisplayFlags& Set(DisplayPrecision::Enum e) { m_flags = (KyUInt32(e) << Bits::Offset_Precision) | (m_flags & ~Bits::Mask_Precision); return *this; }
160  DisplayFlags& Set(DisplayFaces::Enum e) { m_flags = (KyUInt32(e) << Bits::Offset_Faces ) | (m_flags & ~Bits::Mask_Faces ); return *this; }
161  DisplayFlags& SetPQ(DisplayStyle::Enum e) { m_flags = (KyUInt32(e) << Bits::Offset_PQ ) | (m_flags & ~Bits::Mask_PQ ); return *this; }
162  DisplayFlags& SetP(DisplayStyle::Enum e) { m_flags = (KyUInt32(e) << Bits::Offset_P ) | (m_flags & ~Bits::Mask_P ); return *this; }
163  DisplayFlags& SetQ(DisplayStyle::Enum e) { m_flags = (KyUInt32(e) << Bits::Offset_Q ) | (m_flags & ~Bits::Mask_Q ); return *this; }
164 
165  DataType::Enum GetDataType() const { return (DataType::Enum) ((m_flags & Bits::Mask_DataType ) >> Bits::Offset_DataType); }
166  Precision::Enum GetPrecisionEnum() const { return (Precision::Enum)((m_flags & Bits::Mask_Precision) >> Bits::Offset_Precision); }
167  Faces::Enum GetFaces() const { return (Faces::Enum) ((m_flags & Bits::Mask_Faces ) >> Bits::Offset_Faces); }
168  Style::Enum GetStylePQ() const { return (Style::Enum) ((m_flags & Bits::Mask_PQ ) >> Bits::Offset_PQ); }
169  Style::Enum GetStyleP() const { return (Style::Enum) ((m_flags & Bits::Mask_P ) >> Bits::Offset_P); }
170  Style::Enum GetStyleQ() const { return (Style::Enum) ((m_flags & Bits::Mask_Q ) >> Bits::Offset_Q); }
171 
172  KyFloat32 GetPrecision() const
173  {
174  Precision::Enum precision = GetPrecisionEnum();
175  switch (precision)
176  {
177  case Precision::_50cm : return 0.5f;
178  case Precision::_10cm : return 0.1f;
179  case Precision::_5cm : return 0.05f;
180  case Precision::_2cm : return 0.02f;
181  case Precision::_1cm : return 0.01f;
182  case Precision::_5mm : return 0.005f;
183  case Precision::_2mm : return 0.002f;
184  case Precision::_1mm : return 0.001f;
185  default : return 0.05f;
186  }
187  }
188 
189 public:
190  KyUInt32 m_flags;
191 };
192 
193 inline void SwapEndianness(Kaim::Endianness::Target e, DisplayFlags& self)
194 {
195  SwapEndianness(e, self.m_flags);
196 }
197 
198 
199 }
200 
std::uint32_t KyUInt32
uint32_t
Definition: types.h:29
Target
Enumerates the possible endianness types relative to the current platform.
Definition: endianness.h:27
The Autodesk Navigation namespace.
Definition: gamekitcrowddispersion.cpp:17
float KyFloat32
float
Definition: types.h:32