Overte C++ Documentation
OctalCode.h
1 //
2 // OctalCode.h
3 // libraries/shared/src
4 //
5 // Created by Stephen Birarda on 3/15/13.
6 // Copyright 2013 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_OctalCode_h
13 #define hifi_OctalCode_h
14 
15 #include <vector>
16 #include <QString>
17 
18 #include <memory>
19 
20 const int BITS_IN_OCTAL = 3;
21 const int NUMBER_OF_COLORS = 3; // RGB!
22 const int SIZE_OF_COLOR_DATA = NUMBER_OF_COLORS * sizeof(unsigned char); // size in bytes
23 const int RED_INDEX = 0;
24 const int GREEN_INDEX = 1;
25 const int BLUE_INDEX = 2;
26 
27 using OctalCodePtr = std::shared_ptr<unsigned char>;
28 using OctalCodePtrList = std::vector<OctalCodePtr>;
29 
30 void printOctalCode(const unsigned char* octalCode);
31 size_t bytesRequiredForCodeLength(unsigned char threeBitCodes);
32 int branchIndexWithDescendant(const unsigned char* ancestorOctalCode, const unsigned char* descendantOctalCode);
33 unsigned char* childOctalCode(const unsigned char* parentOctalCode, int childNumber);
34 
35 const int OVERFLOWED_OCTCODE_BUFFER = -1;
36 const int UNKNOWN_OCTCODE_LENGTH = -2;
37 
41 int numberOfThreeBitSectionsInCode(const unsigned char* octalCode, int maxBytes = UNKNOWN_OCTCODE_LENGTH);
42 
43 const int CHECK_NODE_ONLY = -1;
44 bool isAncestorOf(const unsigned char* possibleAncestor, const unsigned char* possibleDescendent,
45  int descendentsChild = CHECK_NODE_ONLY);
46 
47 void copyFirstVertexForCode(const unsigned char* octalCode, float* output);
48 
49 struct VoxelPositionSize {
50  float x, y, z, s;
51 };
52 void voxelDetailsForCode(const unsigned char* octalCode, VoxelPositionSize& voxelPositionSize);
53 
54 typedef enum {
55  ILLEGAL_CODE = -2,
56  LESS_THAN = -1,
57  EXACT_MATCH = 0,
58  GREATER_THAN = 1
59 } OctalCodeComparison;
60 
61 OctalCodeComparison compareOctalCodes(const unsigned char* code1, const unsigned char* code2);
62 
63 OctalCodePtr createOctalCodePtr(size_t size);
64 QString octalCodeToHexString(const unsigned char* octalCode);
65 OctalCodePtr hexStringToOctalCode(const QString& input);
66 
67 #endif // hifi_OctalCode_h