本文整理汇总了C++中ParamSet::FindFloat方法的典型用法代码示例。如果您正苦于以下问题:C++ ParamSet::FindFloat方法的具体用法?C++ ParamSet::FindFloat怎么用?C++ ParamSet::FindFloat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParamSet
的用法示例。
在下文中一共展示了ParamSet::FindFloat方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: MakeMedium
std::shared_ptr<Medium> MakeMedium(const std::string &name,
const ParamSet ¶mSet,
const Transform &medium2world) {
Float sig_a_rgb[3] = {.0011f, .0024f, .014f},
sig_s_rgb[3] = {2.55f, 3.21f, 3.77f};
Spectrum sig_a = Spectrum::FromRGB(sig_a_rgb),
sig_s = Spectrum::FromRGB(sig_s_rgb);
std::string preset = paramSet.FindOneString("preset", "");
bool found = GetMediumScatteringProperties(preset, &sig_a, &sig_s);
if (preset != "" && !found)
Warning("Material preset \"%s\" not found. Using defaults.",
preset.c_str());
Float scale = paramSet.FindOneFloat("scale", 1.f);
Float g = paramSet.FindOneFloat("g", 0.0f);
sig_a = paramSet.FindOneSpectrum("sigma_a", sig_a) * scale;
sig_s = paramSet.FindOneSpectrum("sigma_s", sig_s) * scale;
Medium *m = NULL;
if (name == "homogeneous") {
m = new HomogeneousMedium(sig_a, sig_s, g);
} else if (name == "heterogeneous") {
int nitems;
const Float *data = paramSet.FindFloat("density", &nitems);
if (!data) {
Error("No \"density\" values provided for heterogeneous medium?");
return NULL;
}
int nx = paramSet.FindOneInt("nx", 1);
int ny = paramSet.FindOneInt("ny", 1);
int nz = paramSet.FindOneInt("nz", 1);
Point3f p0 = paramSet.FindOnePoint3f("p0", Point3f(0.f, 0.f, 0.f));
Point3f p1 = paramSet.FindOnePoint3f("p1", Point3f(1.f, 1.f, 1.f));
if (nitems != nx * ny * nz) {
Error(
"GridDensityMedium has %d density values; expected nx*ny*nz = "
"%d",
nitems, nx * ny * nz);
return NULL;
}
Transform data2Medium = Translate(Vector3f(p0)) *
Scale(p1.x - p0.x, p1.y - p0.y, p1.z - p0.z);
m = new GridDensityMedium(sig_a, sig_s, g, nx, ny, nz,
medium2world * data2Medium, data);
} else
Warning("Medium \"%s\" unknown.", name.c_str());
paramSet.ReportUnused();
return std::shared_ptr<Medium>(m);
}
示例2: CreateTriangleMesh
std::vector<std::shared_ptr<Shape>> CreateNURBS(const Transform *o2w,
const Transform *w2o,
bool reverseOrientation,
const ParamSet ¶ms) {
int nu = params.FindOneInt("nu", -1);
if (nu == -1) {
Error("Must provide number of control points \"nu\" with NURBS shape.");
return std::vector<std::shared_ptr<Shape>>();
}
int uorder = params.FindOneInt("uorder", -1);
if (uorder == -1) {
Error("Must provide u order \"uorder\" with NURBS shape.");
return std::vector<std::shared_ptr<Shape>>();
}
int nuknots, nvknots;
const Float *uknots = params.FindFloat("uknots", &nuknots);
if (uknots == nullptr) {
Error("Must provide u knot vector \"uknots\" with NURBS shape.");
return std::vector<std::shared_ptr<Shape>>();
}
if (nuknots != nu + uorder) {
Error(
"Number of knots in u knot vector %d doesn't match sum of "
"number of u control points %d and u order %d.",
nuknots, nu, uorder);
return std::vector<std::shared_ptr<Shape>>();
}
Float u0 = params.FindOneFloat("u0", uknots[uorder - 1]);
Float u1 = params.FindOneFloat("u1", uknots[nu]);
int nv = params.FindOneInt("nv", -1);
if (nv == -1) {
Error("Must provide number of control points \"nv\" with NURBS shape.");
return std::vector<std::shared_ptr<Shape>>();
}
int vorder = params.FindOneInt("vorder", -1);
if (vorder == -1) {
Error("Must provide v order \"vorder\" with NURBS shape.");
return std::vector<std::shared_ptr<Shape>>();
}
const Float *vknots = params.FindFloat("vknots", &nvknots);
if (vknots == nullptr) {
Error("Must provide v knot vector \"vknots\" with NURBS shape.");
return std::vector<std::shared_ptr<Shape>>();
}
if (nvknots != nv + vorder) {
Error(
"Number of knots in v knot vector %d doesn't match sum of "
"number of v control points %d and v order %d.",
nvknots, nv, vorder);
return std::vector<std::shared_ptr<Shape>>();
}
Float v0 = params.FindOneFloat("v0", vknots[vorder - 1]);
Float v1 = params.FindOneFloat("v1", vknots[nv]);
bool isHomogeneous = false;
int npts;
const Float *P = (const Float *)params.FindPoint3f("P", &npts);
if (!P) {
P = params.FindFloat("Pw", &npts);
if (!P) {
Error(
"Must provide control points via \"P\" or \"Pw\" parameter to "
"NURBS shape.");
return std::vector<std::shared_ptr<Shape>>();
}
if ((npts % 4) != 0) {
Error(
"Number of \"Pw\" control points provided to NURBS shape must "
"be "
"multiple of four");
return std::vector<std::shared_ptr<Shape>>();
}
npts /= 4;
isHomogeneous = true;
}
if (npts != nu * nv) {
Error("NURBS shape was expecting %dx%d=%d control points, was given %d",
nu, nv, nu * nv, npts);
return std::vector<std::shared_ptr<Shape>>();
}
// Compute NURBS dicing rates
int diceu = 30, dicev = 30;
std::unique_ptr<Float[]> ueval(new Float[diceu]);
std::unique_ptr<Float[]> veval(new Float[dicev]);
std::unique_ptr<Point3f[]> evalPs(new Point3f[diceu * dicev]);
std::unique_ptr<Normal3f[]> evalNs(new Normal3f[diceu * dicev]);
int i;
for (i = 0; i < diceu; ++i)
ueval[i] = Lerp((float)i / (float)(diceu - 1), u0, u1);
for (i = 0; i < dicev; ++i)
veval[i] = Lerp((float)i / (float)(dicev - 1), v0, v1);
//.........这里部分代码省略.........
示例3: CreateTriangleMesh
std::vector<std::shared_ptr<Shape>> CreateTriangleMeshShape(
const Transform *o2w, const Transform *w2o, bool reverseOrientation,
const ParamSet ¶ms,
std::map<std::string, std::shared_ptr<Texture<Float>>> *floatTextures) {
int nvi, npi, nuvi, nsi, nni;
const int *vi = params.FindInt("indices", &nvi);
const Point3f *P = params.FindPoint3f("P", &npi);
const Point2f *uvs = params.FindPoint2f("uv", &nuvi);
if (!uvs) uvs = params.FindPoint2f("st", &nuvi);
std::vector<Point2f> tempUVs;
if (!uvs) {
const Float *fuv = params.FindFloat("uv", &nuvi);
if (!fuv) fuv = params.FindFloat("st", &nuvi);
if (fuv) {
nuvi /= 2;
tempUVs.reserve(nuvi);
for (int i = 0; i < nuvi; ++i)
tempUVs.push_back(Point2f(fuv[2 * i], fuv[2 * i + 1]));
uvs = &tempUVs[0];
}
}
bool discardDegenerateUVs =
params.FindOneBool("discarddegenerateUVs", false);
if (uvs) {
if (nuvi < npi) {
Error(
"Not enough of \"uv\"s for triangle mesh. Expencted %d, "
"found %d. Discarding.",
npi, nuvi);
uvs = nullptr;
} else if (nuvi > npi)
Warning(
"More \"uv\"s provided than will be used for triangle "
"mesh. (%d expcted, %d found)",
npi, nuvi);
}
if (!vi) {
Error(
"Vertex indices \"indices\" not provided with triangle mesh shape");
return std::vector<std::shared_ptr<Shape>>();
}
if (!P) {
Error("Vertex positions \"P\" not provided with triangle mesh shape");
return std::vector<std::shared_ptr<Shape>>();
}
const Vector3f *S = params.FindVector3f("S", &nsi);
if (S && nsi != npi) {
Error("Number of \"S\"s for triangle mesh must match \"P\"s");
S = nullptr;
}
const Normal3f *N = params.FindNormal3f("N", &nni);
if (N && nni != npi) {
Error("Number of \"N\"s for triangle mesh must match \"P\"s");
N = nullptr;
}
if (discardDegenerateUVs && uvs && N) {
// if there are normals, check for bad uv's that
// give degenerate mappings; discard them if so
const int *vp = vi;
for (int i = 0; i < nvi; i += 3, vp += 3) {
Float area =
.5f * Cross(P[vp[0]] - P[vp[1]], P[vp[2]] - P[vp[1]]).Length();
if (area < 1e-7) continue; // ignore degenerate tris.
if ((uvs[vp[0]].x == uvs[vp[1]].x &&
uvs[vp[0]].y == uvs[vp[1]].y) ||
(uvs[vp[1]].x == uvs[vp[2]].x &&
uvs[vp[1]].y == uvs[vp[2]].y) ||
(uvs[vp[2]].x == uvs[vp[0]].x &&
uvs[vp[2]].y == uvs[vp[0]].y)) {
Warning(
"Degenerate uv coordinates in triangle mesh. Discarding "
"all uvs.");
uvs = nullptr;
break;
}
}
}
for (int i = 0; i < nvi; ++i)
if (vi[i] >= npi) {
Error(
"trianglemesh has out of-bounds vertex index %d (%d \"P\" "
"values were given",
vi[i], npi);
return std::vector<std::shared_ptr<Shape>>();
}
std::shared_ptr<Texture<Float>> alphaTex;
std::string alphaTexName = params.FindTexture("alpha");
if (alphaTexName != "") {
if (floatTextures->find(alphaTexName) != floatTextures->end())
alphaTex = (*floatTextures)[alphaTexName];
else
Error("Couldn't find float texture \"%s\" for \"alpha\" parameter",
alphaTexName.c_str());
} else if (params.FindOneFloat("alpha", 1.f) == 0.f)
alphaTex.reset(new ConstantTexture<Float>(0.f));
std::shared_ptr<Texture<Float>> shadowAlphaTex;
std::string shadowAlphaTexName = params.FindTexture("shadowalpha");
if (shadowAlphaTexName != "") {
//.........这里部分代码省略.........