FaceGen 3 SDKs Reference
Loading...
Searching...
No Matches
FanControls.hpp
1//
2// Copyright (c) Singular Inversions Inc. 2001.
3//
4// Authors: Andrew Beatty
5// Date: June 25, 2001
6//
7
8#ifndef FAN_CONTROLS_HPP
9#define FAN_CONTROLS_HPP
10
11#include "FgSerial.hpp"
12#include "Fg3Face.hpp"
13#include "matrixCT.hpp"
14#include "binaryFile.hpp"
15
16namespace Fg {
17
25 typedef enum // Enumerate racial groups
26{
27 FANRACE_ALL = 0,
28 FANRACE_AFRO,
29 FANRACE_EASIA,
30 FANRACE_SASIA,
31 FANRACE_EURO,
32
33 FANRACE_SIZE
34
35} FanRaceE;
36
38String8s
39fg3RaceLabels();
40
41typedef enum // Enumerate attributes
42{
43 FANATT_AGE = 0,
44 FANATT_GENDER,
45
46 FANATT_SIZE
47
48} FanAttribE;
49
50typedef enum // Enumerate genders
51{
52 FANGENDER_MALE = 0,
53 FANGENDER_FEMALE,
54
55 FANGENDER_SIZE // Also used to indicate any gender.
56
57} FanGender;
58
59struct FanLinCtlS // Linear Control Structure
60{
61 FanLinCtlS() : useWideChar(false) {}
62
63 MatF ctl; // Covariant row vector represents 1 std.
64 // linear control.
65 std::string label;
66
67 // Added the following 2 to handle cases where unicode are used.
68 std::wstring wlabel;
69 bool useWideChar;
70};
71
72struct Sam3LinCtrls // All linear control groups.
73{
74 Svec<FanLinCtlS> grp[FANTYPE_SIZE][FANSYMM_SIZE];
75
76 bool readFromFile(FutBinaryFileC &file,
77 uint dim[FANTYPE_SIZE][FANSYMM_SIZE],
78 bool useWideChar=false);
79 bool writeToFile(FutBinaryFileC &file,
80 const uint dim[FANTYPE_SIZE][FANSYMM_SIZE],
81 bool useWideChar=false) const;
82 void setBasis(FanTypeE,FanSymmE,uint);
83};
84
86{
87 MatF mean[FANTYPE_SIZE]; // Column vector over geometry
88
89 // Columns are the eigenbasis, and dimensions are concatenation
90 // of geometry & texture (symmetric only). Transforms from Mahalanobis
91 // coords for this race into global face space coords.
92 MatF eigBasis;
93
94 // Inverse of the PARTITIONED eigenbasis matrices - transforms from
95 // global face space partioned coords to partitioned Mahalanobis
96 // coords for this race.
97 MatF invEigBasis[FANTYPE_SIZE];
98};
99
101{
102 MatF ctl[FANTYPE_SIZE]; // Row vector represents 1 std. linear control.
103 float scale;
104 float off;
105};
106
107struct FanPrtOffLinCtlS // Partitioned OLC - separate
108{ // controls for Geo & Tex subspaces
109 MatF ctl; // Row vector represents 1 std. linear control.
110 float scale;
111 float off;
112};
113
115{
116 MatF mean[FANTYPE_SIZE]; // Column vector.
117 MatF eigBasis; // Distribution eigenbasis over combined space.
118};
119
122{
123 bool initialized; // Have the controls been initialized ?
124 // Race-attribute controls
125 FanRaceDistS distrib[FANRACE_SIZE];
126 FanPrtOffLinCtlS attr[FANRACE_SIZE][FANATT_SIZE][FANTYPE_SIZE];
127 // Race-race controls.
128 FanOffLinCtlS raceCtrls[FANRACE_SIZE][FANRACE_SIZE];
129 // The orthogonal basis vectors of the caricature null space. (row
130 // vector, spans the attribute subspace).
131 MatF basis[FANRACE_SIZE][FANTYPE_SIZE][FANATT_SIZE];
132 // The inverse attribute covariance matrix:
133 Mat22F invAttCov[FANRACE_SIZE][FANTYPE_SIZE];
134
135 // The male and female separated distributions for all races:
136 FanGenderDist genderDistrib[FANGENDER_SIZE];
137
138 Sam3NLCtrls() : initialized(false) {};
139
140 bool readFromFile(FutBinaryFileC &file,uint dim[FANTYPE_SIZE][FANSYMM_SIZE]);
141 float getAttribute(FanRaceE,FanAttribE,FanTypeE,Sam3Coord const &) const;
142 void setAttributes(FanRaceE,FanTypeE,const float val[FANATT_SIZE],Sam3Coord &) const;
143 float getCaricature(FanRaceE,FanTypeE,FanSymmE,Sam3Coord const &) const;
144 void setCaricature_(FanRaceE,FanTypeE,FanSymmE,float,Sam3Coord &) const;
145 float getRace(FanRaceE,FanRaceE,Sam3Coord const &,FanTypeE type=FANTYPE_SIZE) const;
146 float getRaceCS(FanRaceE,FanRaceE,Floats const &) const;
147 void setRace_(FanRaceE,FanRaceE,float,Sam3Coord &,FanTypeE type=FANTYPE_SIZE) const;
148
152 FanRaceE race,
153 FanGender gender,
154 float GSstdev=1.0f,
155 float GAstdev=1.0f,
156 float TSstdev=1.0f) const;
157
161 FanGender gender,
162 float GSstdev=1.0f,
163 float GAstdev=1.0f,
164 float TSstdev=1.0f) const;
165
167 Floats
169 float randomness,
170 Floats const & baseCoord) const;
171
175 float randomness,
176 Sam3Coord const & baseCoord) const;
177
178 void reflect(FanRaceE,Sam3Coord &) const;
179
182 void
184
188 FanGender gend,
189 float GSstdev=1.0f,
190 float GAstdev=1.0f,
191 float TSstdev=1.0f) const;
192
193private:
195 randomUnimodal(
196 FanRaceE race,
197 float GSstdev,
198 float GAstdev,
199 float TSstdev) const;
200};
201
202}
203
204#endif
FanTypeE
Enumerate the statistical model types.
Definition Fg3Face.hpp:25
FanSymmE
Enumerate symmetry types.
Definition Fg3Face.hpp:37
FaceGen face space coordinate.
Definition Fg3Face.hpp:49
Non-linear controls include demographics, caricature and asymmetry:
Floats geneticRandom(float randomness, Floats const &baseCoord) const
Genetic random for a type/symm component:
void geneticTween(FanTypeE, FanSymmE, float, Sam3Coord const &, Sam3Coord const &, Sam3Coord &)
Sam3Coord genderRandom(FanGender gend, float GSstdev=1.0f, float GAstdev=1.0f, float TSstdev=1.0f) const
Random face from gender-specific distributions:
Sam3Coord randomHispanic(FanGender gender, float GSstdev=1.0f, float GAstdev=1.0f, float TSstdev=1.0f) const
Random face coordinate to approximate hispanic faces.
Sam3Coord geneticRandom(float randomness, Sam3Coord const &baseCoord) const
A type/symm coord component.
Sam3Coord random(FanRaceE race, FanGender gender, float GSstdev=1.0f, float GAstdev=1.0f, float TSstdev=1.0f) const
Random face coordinate from given racial group and gender: