-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFacePoint.h
More file actions
128 lines (110 loc) · 4.37 KB
/
FacePoint.h
File metadata and controls
128 lines (110 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//
// Created by rthier on 2016.04.11..
//
#ifndef NFTSIMPLEPROJ_FACEPOINT_H
#define NFTSIMPLEPROJ_FACEPOINT_H
#include "objmasterlog.h"
#include <string>
namespace ObjMaster {
static const char *FACEPOINT_DELIMITER = "/";
static const int FACEPOINT_MAXLEN = 1024;
class FacePoint {
public:
unsigned int vIndex;
unsigned int vtIndex;
unsigned int vnIndex;
// Copies are defeaulted
FacePoint(const FacePoint &other) = default;
FacePoint& operator=(const FacePoint &other) = default;
// Moves are defaulted
FacePoint(FacePoint &&other) = default;
FacePoint& operator=(FacePoint &&other) = default;
FacePoint();
FacePoint(unsigned int vvIndex, unsigned int vvtIndex, unsigned int vvnIndex) {
vIndex = vvIndex;
vtIndex = vvtIndex;
vnIndex = vvnIndex;
}
FacePoint(char *fields);
FacePoint(const char *fields);
FacePoint(char *fields, bool forceParser);
FacePoint(const char *fields, bool forceParser);
static bool isParsable(const char *fields);
/** Gets the textual representation */
inline std::string asText() {
// Mind that in the *.obj file we need to start indexing by one!
return std::to_string(vIndex+1) + "/" + std::to_string(vtIndex+1) + "/" + std::to_string(vnIndex+1);
}
private:
// Common parts of constructors
void constructorHelper(char *fields);
};
// Very simple unit-testing approach
// it is better to have these run on the device itself and callable as normal functions than to
// test it compile-time with some unit testing framework as this way we rule out architectural
// differences better. Tests will start by logging test starts to error (when #DEBUG is set!)
// and info logs and the method returns false when anything has failed...
static bool TEST_FacePoint() {
#ifdef DEBUG
OMLOGI("TEST_FacePoint...");
#endif
// should parse
const char *vnetest = "1/1/1";
const char *vnetest2 = "2/2/3";
// should not parse
const char *vnetest3 = "v 1.0 2.0 3.0";
const char *vnetest4 = "asdafdas";
const char *vnetest5 = nullptr;
const char *vnetest6 = "";
OMLOGI("TEST_FacePoint testing: %s", vnetest);
if(FacePoint::isParsable(vnetest)) {
FacePoint fp(vnetest);
#ifdef DEBUG
OMLOGI("facepoint: %d/%d/%d", fp.vIndex, fp.vtIndex, fp.vnIndex);
OMLOGI("facepoint.asText(): %s", fp.asText().c_str());
#endif
// indexing is from 1 in the file - we use indexing from zero!
if(fp.vIndex != 0) { OMLOGE("Bad vIndex value: %d", fp.vIndex); return false; }
if(fp.vtIndex != 0) { OMLOGE("Bad vtIndex value: %d", fp.vtIndex); return false; }
if(fp.vnIndex != 0) { OMLOGE("Bad vnIndex value: %d", fp.vnIndex); return false; }
} else {
OMLOGE("Cannot parse: %s", vnetest);
return false;
}
OMLOGI("TEST_FacePoint testing(force-parse): %s", vnetest2);
if(FacePoint::isParsable(vnetest2)) {
FacePoint fp(vnetest2, true);
#ifdef DEBUG
OMLOGI("facepoint: %d/%d/%d", fp.vIndex, fp.vtIndex, fp.vnIndex);
#endif
// indexing is from 1 in the file - we use indexing from zero!
if(fp.vIndex != 1) { OMLOGE("Bad vIndex value: %d", fp.vIndex); return false; }
if(fp.vtIndex != 1) { OMLOGE("Bad vtIndex value: %d", fp.vtIndex); return false; }
if(fp.vnIndex != 2) { OMLOGE("Bad vnIndex value: %d", fp.vnIndex); return false; }
} else {
OMLOGE("Cannot parse: %s", vnetest2);
return false;
}
OMLOGI("TEST_FacePoint testing: %s", vnetest3);
if(FacePoint::isParsable(vnetest3)) {
OMLOGE("Mistakenly parsed: %s", vnetest3);
}
OMLOGI("TEST_FacePoint testing: %s", vnetest4);
if(FacePoint::isParsable(vnetest4)) {
OMLOGE("Mistakenly parsed: %s", vnetest4);
}
OMLOGI("TEST_FacePoint testing: %s", vnetest5);
if(FacePoint::isParsable(vnetest5)) {
OMLOGE("Mistakenly parsed: %s", vnetest5);
}
OMLOGI("TEST_FacePoint testing: %s", vnetest6);
if(FacePoint::isParsable(vnetest6)) {
OMLOGE("Mistakenly parsed: %s", vnetest6);
}
#ifdef DEBUG
OMLOGI("...TEST_FacePoint completed (OK)");
#endif
return true;
}
}
#endif //NFTSIMPLEPROJ_FACEPOINT_H