FaceGen 3 SDKs Reference
Loading...
Searching...
No Matches
Fg3Scm.hpp
1//
2// Copyright (c) Singular Inversions Inc. 2012
3//
4// Authors: Andrew Beatty
5// Created: Feb 14, 2012
6//
7
8#ifndef FG3SCM_HPP
9#define FG3SCM_HPP
10
11#include "Fg3Face.hpp"
12#include "FgImage.hpp"
13#include "Fg3dMeshIo.hpp"
14#include "FgMain.hpp"
15#include "FgVolume.hpp"
16
17namespace Fg {
18
25{
26 float scale;
27 Img3SC mode; // RGB deltas for [0,255] channel scaled by 1/scale above
28};
29typedef Svec<Scm3Mode> Scm3Modes;
30
31struct Scm3SA
32{
33 Scm3Modes symm;
34 Scm3Modes asym;
35};
36
37Scm3SA loadEgt(String8 const & egtFile);
38Img2F loadFim(String8 const & fimFile);
40ImgV3F scmMac(
41 Scm3Modes const & modes,
42 Floats const & coeffs);
44ImgRgba8 scmAdd(
45 ImgRgba8 const & scmMean, // SCM mean image RGBA [0,255]. Can be empty.
46 ImgV3F const & delta, // SCM delta computed with 'scmMac'. Can be smaller than 'mean'. Or empty.
47 float outInvGamma=2.2, // Inverse gamma of return image
48 bool multithread=true); // select false if called within a multithreaded context
51Arr3D calcColorFac(
52 ImgRgba8 const & genericMap,
53 ImgRgba8 const & facegenMap,
54 ImgUC const & sampleRegion); // [0,255]
56ImgRgba8 applyColorFac(ImgRgba8 const & genericMap,Arr3D colorFac);
61Arr3D calcColorShift(
62 ImgRgba8 const & genericFaceMap,
63 ImgRgba8 const & facegenFaceMap,
65 ImgUC const & transitionMap);
67ImgRgba8 applyColorShift(ImgRgba8 const & customBodyMap,Arr3D shift);
70ImgRgba8 applyOverlay(ImgRgba8 const & base,ImgRgba8 const & overlay);
71
73struct Scm3
74{
77 ImgRgba8 mean;
79 Scm3Modes modes;
83 Img2F detailXfm;
85 float gamma = gammaDefault();
90 ImgRgba8 overlay;
93 ImgUC fadeMap;
94
95 static inline float gammaDefault() {return 2.2f; }
96
97 Scm3() {}
99 Scm3(String8 const & dirBase,String8 const & overlayColor="");
100 Scm3(
101 String8 const & imgFile,
102 String8 const & egtFile,
103 String8 const & fimFile);
104 Scm3(
105 ImgRgba8 const & meanClr,
106 String8 const & egtFile,
107 String8 const & fimFile);
108
110 bool empty() const {return (mean.empty() && overlay.empty()); }
111
114 Sam3Coord const & faceCoord,
116 bool multithread=true)
117 const
118 {
119 if (modes.empty())
120 return mean;
121 ImgV3F accDelta = scmMac(modes,faceCoord.ts(1,0));
122 return scmAdd(mean,accDelta,gamma,multithread);
123 }
124
126 ImgRgba8 applyFace(
127 Face3 const & face,
130 float detailModulation=1.0f,
132 bool multithread=true)
133 const
134 {
135 ImgRgba8 td = transformDetail(face.detail,multithread);
136 return applyFaceCoord(face.coord.ts(1,0),td,detailModulation,multithread);
137 }
138
142 ImgRgba8 transformDetail(
143 Bytes const & detailJpegBlob, // JPEG encoded modulation map in FaceGen internal layout
144 bool multithread=true) const; // select false if this function is from a multithreaded context
145
147 ImgRgba8 applyFaceCoord(
149 Floats const & ColorCoordS,
151 ImgRgba8 const & transformedDetail,
154 float detailModulation=1.0f,
155 bool multithread=true) // select false if calling within multithreaded context
156 const;
157};
158typedef Svec<Scm3> Scm3s;
159
160// Return the skin sample region (skin areas not including any areas where beard or eyebrow hair can grow, or the nose):
161ImgUC getSkinSampleRegion(Img2F const & detailXfm);
162
165inline ImgRgba8 customizeBase(
166 ImgRgba8 const & facegenBase, // the skin color map created by FaceGen 'scm' command
167 ImgRgba8 const & customBase, // your replacement
168 ImgUC const & transition, // transition from FaceGen (black) to your (white) map
169 Arr3D colorShift) // computed previously using 'calcColorShift'
170{
171 return imgBlend(facegenBase,applyColorShift(customBase,colorShift),transition);
172}
173
174// optional add zero modes to the end:
175Volume<Arr3F> loadEgtScm4(String8 const & egtFile,size_t padZero=0);
176
177// Required: modes.dims() == [coeffs.size(),acc.width(),acc.height()]
178void multAcc_(Volume<Arr3F> const & modes,Floats const & coeffs,Img3F & acc);
179// Required: modes.dims()[0] == coeffs.size():
180Img3F multAcc(Volume<Arr3F> const & modes,Floats const & coeffs);
181
182struct ScbLpp
183{
184 Img3F base; // RGB [0,1]
185 Volume<Arr3F> modes; // Z: image-Y, Y: image-X, X: mode deltas scaled for [0,1]
186
187 ScbLpp(String8 const & dirBase);
188
189 size_t numModes() const {return modes.dims()[0]; }
190 Vec2UI dims() const {return base.dims(); }
191 inline Img3F apply(Floats const & coord) const {return base + multAcc(modes,coord); }
192 ImgRgba8 apply(Floats const & coord,float gamma) const;
193};
194
195
198void cmdScm3Base(CLArgs const &); // SCM integration custom base command
199
200}
201
202#endif
Bytes detail
JPEG-encoded detail modulation in internal UV layout.
Definition Fg3Face.hpp:92
Sam3Coord coord
Coordinate of this face in 'face space'.
Definition Fg3Face.hpp:90
FaceGen face space coordinate.
Definition Fg3Face.hpp:49
FaceGen 3 Statistical Color Model for a UV map:
Definition Fg3Scm.hpp:74
ImgUC fadeMap
Definition Fg3Scm.hpp:93
ImgRgba8 calcScmColorMap(Sam3Coord const &faceCoord, bool multithread=true) const
Compute the SCM color map without any detail texture, custom base or overlay:
Definition Fg3Scm.hpp:113
bool empty() const
"
Definition Fg3Scm.hpp:110
ImgRgba8 transformDetail(Bytes const &detailJpegBlob, bool multithread=true) const
Definition Fg3Scm.cpp:380
ImgRgba8 applyFace(Face3 const &face, float detailModulation=1.0f, bool multithread=true) const
Returns the final color map image for the given face:
Definition Fg3Scm.hpp:126
float gamma
Desired inverse gamma value for output color maps:
Definition Fg3Scm.hpp:85
ImgRgba8 overlay
Definition Fg3Scm.hpp:90
Img2F detailXfm
Definition Fg3Scm.hpp:83
ImgRgba8 mean
Definition Fg3Scm.hpp:77
ImgRgba8 applyFaceCoord(Floats const &ColorCoordS, ImgRgba8 const &transformedDetail, float detailModulation=1.0f, bool multithread=true) const
Returns the final color map for the given face coordinate and optional transformed detail texture:
Definition Fg3Scm.cpp:417
Scm3Modes modes
SCM modes (symmetric only) encoded with gamma=1/2.6. Size is power of 2. Can be empty.
Definition Fg3Scm.hpp:79