Esempio n. 1
0
void ParamSet::AddSampledSpectrumFiles(const string &name, const char **names,
        int nItems) {
    EraseSpectrum(name);
    Spectrum *s = new Spectrum[nItems];
    for (int i = 0; i < nItems; ++i) {
        string fn = AbsolutePath(ResolveFilename(names[i]));
        if (cachedSpectra.find(fn) != cachedSpectra.end()) {
            s[i] = cachedSpectra[fn];
            continue;
        }

        vector<float> vals;
        if (!ReadFloatFile(fn.c_str(), &vals)) {
            Warning("Unable to read SPD file \"%s\".  Using black distribution.",
                    fn.c_str());
            s[i] = Spectrum(0.);
        }
        else {
            if (vals.size() % 2) {
                Warning("Extra value found in spectrum file \"%s\". "
                        "Ignoring it.", fn.c_str());
            }
            vector<float> wls, v;
            for (uint32_t j = 0; j < vals.size() / 2; ++j) {
                wls.push_back(vals[2*j]);
                v.push_back(vals[2*j+1]);
            }
            s[i] = Spectrum::FromSampled(&wls[0], &v[0], wls.size());
        }
        cachedSpectra[fn] = s[i];
    }

    spectra.push_back(new ParamSetItem<Spectrum>(name, s, nItems));
    delete[] s;
}
Esempio n. 2
0
void ParamSet::AddRGBSpectrum(const string &name, const float *data, int nItems) {
    EraseSpectrum(name);
    Assert(nItems % 3 == 0);
    nItems /= 3;
    Spectrum *s = new Spectrum[nItems];
    for (int i = 0; i < nItems; ++i)
        s[i] = Spectrum::FromRGB(&data[3*i]);
    spectra.push_back(new ParamSetItem<Spectrum>(name, s, nItems));
    delete[] s;
}
Esempio n. 3
0
void ParamSet::AddXYZSpectrum(const std::string &name,
                              std::unique_ptr<Float[]> values, int nValues) {
    EraseSpectrum(name);
    Assert(nValues % 3 == 0);
    nValues /= 3;
    std::unique_ptr<Spectrum[]> s(new Spectrum[nValues]);
    for (int i = 0; i < nValues; ++i) s[i] = Spectrum::FromXYZ(&values[3 * i]);
    std::shared_ptr<ParamSetItem<Spectrum>> psi(
        new ParamSetItem<Spectrum>(name, std::move(s), nValues));
    spectra.push_back(psi);
}
Esempio n. 4
0
void ParamSet::AddXYZSpectrum(const std::string &name, const Float *values,
                              int nValues) {
    EraseSpectrum(name);
    Assert(nValues % 3 == 0);
    nValues /= 3;
    Spectrum *s = new Spectrum[nValues];
    for (int i = 0; i < nValues; ++i) s[i] = Spectrum::FromXYZ(&values[3 * i]);
    std::shared_ptr<ParamSetItem<Spectrum>> psi(
        new ParamSetItem<Spectrum>(name, s, nValues));
    spectra.push_back(psi);
    delete[] s;
}
Esempio n. 5
0
void ParamSet::AddSampledSpectrum(const string &name, const float *data,
        int nItems) {
    EraseSpectrum(name);
    Assert(nItems % 2 == 0);
    nItems /= 2;
    float *wl = new float[nItems], *v = new float[nItems];
    for (int i = 0; i < nItems; ++i) {
        wl[i] = data[2*i];
        v[i] = data[2*i+1];
    }
    Spectrum s = Spectrum::FromSampled(wl, v, nItems);
    spectra.push_back(new ParamSetItem<Spectrum>(name, &s, 1));
}
Esempio n. 6
0
void ParamSet::AddBlackbodySpectrum(const string &name, const float *data,
        int nItems) {
    EraseSpectrum(name);
    Assert(nItems % 2 == 0); // temperature (K), scale, ...
    nItems /= 2;
    Spectrum *s = new Spectrum[nItems];
    float *v = new float[nCIESamples];
    for (int i = 0; i < nItems; ++i) {
        Blackbody(CIE_lambda, nCIESamples, data[2*i], v);
        s[i] = data[2*i+1] * Spectrum::FromSampled(CIE_lambda, v, nCIESamples);
    }
    spectra.push_back(new ParamSetItem<Spectrum>(name, s, nItems));
    delete[] s;
    delete[] v;
}
Esempio n. 7
0
void ParamSet::AddSampledSpectrum(const std::string &name, const Float *values,
                                  int nValues) {
    EraseSpectrum(name);
    Assert(nValues % 2 == 0);
    nValues /= 2;
    Float *wl = new Float[nValues], *v = new Float[nValues];
    for (int i = 0; i < nValues; ++i) {
        wl[i] = values[2 * i];
        v[i] = values[2 * i + 1];
    }
    Spectrum s = Spectrum::FromSampled(wl, v, nValues);
    std::shared_ptr<ParamSetItem<Spectrum>> psi(
        new ParamSetItem<Spectrum>(name, &s, 1));
    spectra.push_back(psi);
}
Esempio n. 8
0
void ParamSet::AddBlackbodySpectrum(const std::string &name,
                                    const Float *values, int nValues) {
    EraseSpectrum(name);
    Assert(nValues % 2 == 0);  // temperature (K), scale, ...
    nValues /= 2;
    std::unique_ptr<Spectrum[]> s(new Spectrum[nValues]);
    std::unique_ptr<Float[]> v(new Float[nCIESamples]);
    for (int i = 0; i < nValues; ++i) {
        BlackbodyNormalized(CIE_lambda, nCIESamples, values[2 * i], v.get());
        s[i] = values[2 * i + 1] *
               Spectrum::FromSampled(CIE_lambda, v.get(), nCIESamples);
    }
    std::shared_ptr<ParamSetItem<Spectrum>> psi(
        new ParamSetItem<Spectrum>(name, s.get(), nValues));
    spectra.push_back(psi);
}
Esempio n. 9
0
void ParamSet::AddSampledSpectrum(const std::string &name,
                                  std::unique_ptr<Float[]> values,
                                  int nValues) {
    EraseSpectrum(name);
    Assert(nValues % 2 == 0);
    nValues /= 2;
    std::unique_ptr<Float[]> wl(new Float[nValues]);
    std::unique_ptr<Float[]> v(new Float[nValues]);
    for (int i = 0; i < nValues; ++i) {
        wl[i] = values[2 * i];
        v[i] = values[2 * i + 1];
    }
    std::unique_ptr<Spectrum[]> s(new Spectrum[1]);
    s[0] = Spectrum::FromSampled(wl.get(), v.get(), nValues);
    std::shared_ptr<ParamSetItem<Spectrum>> psi(
        new ParamSetItem<Spectrum>(name, std::move(s), 1));
    spectra.push_back(psi);
}
Esempio n. 10
0
void ParamSet::AddSampledSpectrumFiles(const std::string &name,
                                       const char **names, int nValues) {
    EraseSpectrum(name);
    std::unique_ptr<Spectrum[]> s(new Spectrum[nValues]);
    for (int i = 0; i < nValues; ++i) {
        std::string fn = AbsolutePath(ResolveFilename(names[i]));
        if (cachedSpectra.find(fn) != cachedSpectra.end()) {
            s[i] = cachedSpectra[fn];
            continue;
        }

        std::vector<Float> vals;
        if (!ReadFloatFile(fn.c_str(), &vals)) {
            Warning(
                "Unable to read SPD file \"%s\".  Using black distribution.",
                fn.c_str());
            s[i] = Spectrum(0.);
        } else {
            if (vals.size() % 2) {
                Warning(
                    "Extra value found in spectrum file \"%s\". "
                    "Ignoring it.",
                    fn.c_str());
            }
            std::vector<Float> wls, v;
            for (size_t j = 0; j < vals.size() / 2; ++j) {
                wls.push_back(vals[2 * j]);
                v.push_back(vals[2 * j + 1]);
            }
            s[i] = Spectrum::FromSampled(&wls[0], &v[0], wls.size());
        }
        cachedSpectra[fn] = s[i];
    }

    std::shared_ptr<ParamSetItem<Spectrum>> psi(
        new ParamSetItem<Spectrum>(name, std::move(s), nValues));
    spectra.push_back(psi);
}