--User changes

Add the ability to set the current xform by pressing F1 - F32.
 Add the ability to toggle an entire row or column of xaos values.

--Bug fixes
 Prevent xform index flickering whenever changing the number of xforms.

--Code changes
 Remove ForEach() wrappers and replace with range based for loops with auto.
 Replace every regular for loop with a range based one where applicable. Note this doesn't work everywhere.
 Make event filter application wide.
 Add parameter to FillXforms() to specify the index to select, default 0.
 Rename some scroll areas and layouts to names that make sense, rather than their designer defaults.
This commit is contained in:
mfeemster
2015-05-03 17:13:14 -07:00
parent cd5669d0ef
commit e005b4c20e
29 changed files with 282 additions and 212 deletions

View File

@ -543,7 +543,7 @@ public:
{
bool b = false;
ForEach(m_Xforms, [&](const Xform<T>& xform) { b |= xform.XaosPresent(); });//If at least one entry is not equal to 1, then xaos is present.
for (auto& xform : m_Xforms) b |= xform.XaosPresent();//If at least one entry is not equal to 1, then xaos is present.
return b;
}
@ -553,7 +553,7 @@ public:
/// </summary>
void ClearXaos()
{
ForEach(m_Xforms, [&](Xform<T>& xform) { xform.ClearXaos(); });
for (auto& xform : m_Xforms) xform.ClearXaos();
}
/// <summary>
@ -605,7 +605,7 @@ public:
{
T weight = T(1) / m_Xforms.size();
ForEach(m_Xforms, [&](Xform<T>& xform) { xform.m_Weight = weight; });
for (auto& xform : m_Xforms) xform.m_Weight = weight;
}
/// <summary>
@ -620,8 +620,8 @@ public:
if (normalizedWeights.size() != m_Xforms.size())
normalizedWeights.resize(m_Xforms.size());
ForEach(m_Xforms, [&](Xform<T>& xform) { norm += xform.m_Weight; });
ForEach(normalizedWeights, [&](T& weight) { weight = (norm == T(0) ? T(0) : m_Xforms[i].m_Weight / norm); i++; });
for (auto& xform : m_Xforms) norm += xform.m_Weight;
for (auto& weight : normalizedWeights) { weight = (norm == T(0) ? T(0) : m_Xforms[i].m_Weight / norm); i++; }
}
/// <summary>
@ -635,7 +635,8 @@ public:
size_t i = 0, xformIndex = 0, totalVarCount = m_FinalXform.TotalVariationCount();
variations.clear();
ForEach(m_Xforms, [&](const Xform<T>& xform) { totalVarCount += xform.TotalVariationCount(); });
for (auto& xform : m_Xforms) totalVarCount += xform.TotalVariationCount();
variations.reserve(totalVarCount);
while (Xform<T>* xform = GetTotalXform(xformIndex++))
@ -672,7 +673,7 @@ public:
{
bool flattened = false;
ForEach(m_Xforms, [&](Xform<T>& xform) { flattened |= xform.Flatten(names); });
for (auto& xform : m_Xforms) flattened |= xform.Flatten(names);
return flattened;
}
@ -685,12 +686,12 @@ public:
{
bool unflattened = false;
ForEach(m_Xforms, [&](Xform<T>& xform)
for (auto& xform : m_Xforms)
{
unflattened |= xform.DeleteVariationById(VAR_PRE_FLATTEN);
unflattened |= xform.DeleteVariationById(VAR_FLATTEN);
unflattened |= xform.DeleteVariationById(VAR_POST_FLATTEN);
});
}
return unflattened;
}

View File

@ -83,9 +83,9 @@ public:
f.write(temp.c_str(), temp.size());
}
for (size_t i = 0; i < embers.size(); i++)
for (auto& ember : embers)
{
string s = ToString(embers[i], "", printEditDepth, doEdits, intPalette, hexPalette);
string s = ToString(ember, "", printEditDepth, doEdits, intPalette, hexPalette);
f.write(s.c_str(), s.size());
}
@ -202,7 +202,7 @@ public:
ember.GetPresentVariations(variations, false);
if (!variations.empty())
ForEach(variations, [&] (Variation<T>* var) { os << var->Name() << (var != variations.back() ? " " : "\""); });
for (auto var : variations) os << var->Name() << (var != variations.back() ? " " : "\"");
else
os << "\"";

View File

@ -472,8 +472,8 @@ public:
{
Xform<T> xform;
for (size_t xf = 0; xf < xforms.size(); xf++)
MergeXformVariations1Way(xforms[xf], &xform, false, clearWeights);
for (auto xf : xforms)
MergeXformVariations1Way(xf, &xform, false, clearWeights);
return xform;
}

View File

@ -88,8 +88,8 @@ void Renderer<T, bucketT>::ComputeBounds()
//Check the size of the density estimation filter.
//If the radius of the density estimation filter is greater than the
//gutter width, have to pad with more. Otherwise, use the same value.
for (size_t i = 0; i < m_Embers.size(); i++)
maxDEFilterWidth = std::max<size_t>(size_t(ceil(m_Embers[i].m_MaxRadDE) * m_Ember.m_Supersample), maxDEFilterWidth);
for (auto& ember : m_Embers)
maxDEFilterWidth = std::max<size_t>(size_t(ceil(ember.m_MaxRadDE) * m_Ember.m_Supersample), maxDEFilterWidth);
//Need an extra ss = (int)floor(m_Supersample / 2.0) of pixels so that a local iteration count for DE can be determined.//SMOULDER
if (maxDEFilterWidth > 0)
@ -748,16 +748,16 @@ bool Renderer<T, bucketT>::Alloc()
b &= (m_Samples.size() == m_ThreadsToUse);
}
for (size_t i = 0; i < m_Samples.size(); i++)
for (auto& sample : m_Samples)
{
if (m_Samples[i].size() != SubBatchSize())
if (sample.size() != SubBatchSize())
{
m_Samples[i].resize(SubBatchSize());
sample.resize(SubBatchSize());
if (m_ReclaimOnResize)
m_Samples[i].shrink_to_fit();
sample.shrink_to_fit();
b &= (m_Samples[i].size() == SubBatchSize());
b &= (sample.size() == SubBatchSize());
}
}
@ -1214,6 +1214,9 @@ EmberStats Renderer<T, bucketT>::Iterate(size_t iterCount, size_t temporalSample
#else
parallel_for(size_t(0), m_ThreadsToUse, [&] (size_t threadIndex)
{
#endif
#ifdef WIN32
//SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL);
#endif
//Timing t;
IterParams<T> params;
@ -1441,7 +1444,7 @@ void Renderer<T, bucketT>::Accumulate(QTIsaac<ISAAC_SIZE, ISAAC_INT>& rand, Poin
{
size_t histIndex, intColorIndex, histSize = m_HistBuckets.size();
bucketT colorIndex, colorIndexFrac;
const tvec4<bucketT, glm::defaultp>* dmap = &(palette->m_Entries[0]);
auto dmap = palette->m_Entries.data();
//T oneColDiv2 = m_CarToRas.OneCol() / 2;
//T oneRowDiv2 = m_CarToRas.OneRow() / 2;

View File

@ -21,18 +21,6 @@ static inline bool FindIf(c& container, pr pred)
return std::find_if(container.begin(), container.end(), pred) != container.end();
}
/// <summary>
/// Thin wrapper around std::for_each() to relieve the caller of having to
/// pass the implicitly obvious .begin() and .end().
/// </summary>
/// <param name="container">The container to call for_each() on</param>
/// <param name="pred">The lambda to call on each element</param>
template<class c, class fn>
static inline void ForEach(c& container, fn func)
{
std::for_each(container.begin(), container.end(), func);
}
/// <summary>
/// Thin wrapper around computing the total size of a vector.
/// </summary>
@ -149,7 +137,7 @@ public:
{
stringstream ss;
ForEach(errorReport, [&](const string& s) { ss << s << endl; });
for (auto& s : errorReport) ss << s << endl;
return ss.str();
}

View File

@ -1678,11 +1678,14 @@ public:
{
bool b = false;
ForEach(m_Params, [&](ParamWithName<T>& param)
for (auto& param : m_Params)
{
if (!_stricmp(param.Name().c_str(), name))
{
b = true;
});
break;
}
}
return b;
}
@ -1694,9 +1697,9 @@ public:
/// <returns>A pointer to the parameter value if the name matched, else false.</returns>
T* GetParam(const char* name)
{
for (size_t i = 0; i < m_Params.size(); i++)
if (!_stricmp(m_Params[i].Name().c_str(), name))
return m_Params[i].Param();
for (auto& param : m_Params)
if (!_stricmp(param.Name().c_str(), name))
return param.Param();
return nullptr;
}
@ -1708,9 +1711,9 @@ public:
/// <returns>A parameter value if the name matched, else 0.</returns>
T GetParamVal(const char* name) const
{
for (size_t i = 0; i < m_Params.size(); i++)
if (!_stricmp(m_Params[i].Name().c_str(), name))
return m_Params[i].ParamVal();
for (auto& param : m_Params)
if (!_stricmp(param.Name().c_str(), name))
return param.ParamVal();
return 0;
}
@ -1725,14 +1728,15 @@ public:
{
bool b = false;
ForEach(m_Params, [&](ParamWithName<T>& param)
for (auto& param : m_Params)
{
if (!_stricmp(param.Name().c_str(), name))
{
param.Set(val);
b = true;
break;
}
});
}
if (b)
this->Precalc();
@ -1772,7 +1776,7 @@ public:
virtual void Random(QTIsaac<ISAAC_SIZE, ISAAC_INT>& rand) override
{
Variation<T>::Random(rand);
ForEach(m_Params, [&](ParamWithName<T>& param) { param.Set(rand.Frand11<T>()); });
for (auto& param : m_Params) param.Set(rand.Frand11<T>());
this->Precalc();
}
@ -1781,7 +1785,7 @@ public:
/// </summary>
void Clear()
{
ForEach(m_Params, [&](ParamWithName<T>& param) { *(param.Param()) = 0; });
for (auto& param : m_Params) *(param.Param()) = 0;
this->Precalc();
}
@ -1795,11 +1799,11 @@ public:
vector<string> vec;
vec.reserve(m_Params.size());
ForEach(m_Params, [&](const ParamWithName<T>& param)
for (auto& param : m_Params)
{
if ((includePrecalcs && param.IsPrecalc()) || !param.IsPrecalc())
vec.push_back(param.Name());
});
}
return vec;
}
@ -1813,7 +1817,7 @@ public:
ostringstream ss;
ss << Variation<T>::ToString() << endl;
ForEach(m_Params, [&](const ParamWithName<T>& param) { ss << param.ToString() << endl; });
for (auto& param : m_Params) ss << param.ToString() << endl;
return ss.str();
}

View File

@ -342,16 +342,16 @@ public:
ADDPREPOSTREGVAR(DCTriangle)
ADDPREPOSTREGVAR(DCZTransl)
ForEach(m_Variations, [&](Variation<T>* var) { var->Precalc(); });
for (auto var : m_Variations) var->Precalc();
std::sort(m_Variations.begin(), m_Variations.end(), [&](const Variation<T>* var1, const Variation<T>* var2) { return var1->VariationId() < var2->VariationId(); });
m_RegVariations.reserve(m_Variations.size() / 3);
m_PreVariations.reserve(m_Variations.size() / 3);
m_PostVariations.reserve(m_Variations.size() / 3);
ForEach(m_Variations, [&](Variation<T>* var) { if (var->VarType() == VARTYPE_REG) m_RegVariations.push_back(var); });
ForEach(m_Variations, [&](Variation<T>* var) { if (var->VarType() == VARTYPE_PRE) m_PreVariations.push_back(var); });
ForEach(m_Variations, [&](Variation<T>* var) { if (var->VarType() == VARTYPE_POST) m_PostVariations.push_back(var); });
for (auto var : m_Variations) if (var->VarType() == VARTYPE_REG) m_RegVariations.push_back(var);
for (auto var : m_Variations) if (var->VarType() == VARTYPE_PRE) m_PreVariations.push_back(var);
for (auto var : m_Variations) if (var->VarType() == VARTYPE_POST) m_PostVariations.push_back(var);
//Keep a list of which variations derive from ParametricVariation.
//Note that these are not new copies, rather just pointers to the original instances in m_Variations.

View File

@ -365,11 +365,11 @@ public:
const_cast<Xform<T>*>(this)->AllVarsFunc([&] (vector<Variation<T>*>& variations, bool& keepGoing)
{
for (size_t i = 0; i < variations.size(); i++)
for (auto v : variations)
{
if (variations[i] != nullptr && variations[i]->VariationId() == id)
if (v != nullptr && v->VariationId() == id)
{
var = variations[i];
var = v;
keepGoing = false;
break;
}
@ -390,11 +390,11 @@ public:
const_cast<Xform<T>*>(this)->AllVarsFunc([&] (vector<Variation<T>*>& variations, bool& keepGoing)
{
for (size_t i = 0; i < variations.size(); i++)
for (auto v : variations)
{
if (variations[i] != nullptr && variations[i]->Name() == name)
if (v != nullptr && v->Name() == name)
{
var = variations[i];
var = v;
keepGoing = false;
break;
}
@ -593,8 +593,8 @@ public:
{
T norm = 0;
ForEach(variations, [&](Variation<T>* var) { norm += var->m_Weight; });
ForEach(variations, [&](Variation<T>* var) { var->m_Weight /= norm; });
for (auto var : variations) norm += var->m_Weight;
for (auto var : variations) var->m_Weight /= norm;
});
}
@ -839,45 +839,30 @@ public:
m_HasPreOrRegularVars = PreVariationCount() > 0 || VariationCount() > 0;
//Only set precalcs for regular variations, they work differently for pre and post.
for (size_t i = 0; i < m_Variations.size(); i++)
for (auto var : m_Variations)
{
if (m_Variations[i]->NeedPrecalcSumSquares())
if (var->NeedPrecalcSumSquares())
m_NeedPrecalcSumSquares = true;
if (m_Variations[i]->NeedPrecalcSqrtSumSquares())
if (var->NeedPrecalcSqrtSumSquares())
m_NeedPrecalcSqrtSumSquares = true;
if (m_Variations[i]->NeedPrecalcAngles())
if (var->NeedPrecalcAngles())
m_NeedPrecalcAngles = true;
if (m_Variations[i]->NeedPrecalcAtanXY())
if (var->NeedPrecalcAtanXY())
m_NeedPrecalcAtanXY = true;
if (m_Variations[i]->NeedPrecalcAtanYX())
if (var->NeedPrecalcAtanYX())
m_NeedPrecalcAtanYX = true;
}
AllVarsFunc([&] (vector<Variation<T>*>& variations, bool& keepGoing)
{
for (size_t i = 0; i < variations.size(); i++)
for (auto var : variations)
{
/*if (variations[i]->NeedPrecalcSumSquares())
m_NeedPrecalcSumSquares = true;
if (variations[i]->NeedPrecalcSqrtSumSquares())
m_NeedPrecalcSqrtSumSquares = true;
if (variations[i]->NeedPrecalcAngles())
m_NeedPrecalcAngles = true;
if (variations[i]->NeedPrecalcAtanXY())
m_NeedPrecalcAtanXY = true;
if (variations[i]->NeedPrecalcAtanYX())
m_NeedPrecalcAtanYX = true;*/
variations[i]->ParentXform(this);
variations[i]->Precalc();
var->ParentXform(this);
var->Precalc();
}
});
}
@ -925,10 +910,9 @@ public:
{
AllVarsFunc([&] (vector<Variation<T>*>& variations, bool& keepGoing)
{
for (size_t i = 0; i < variations.size(); i++)
for (auto var : variations)
//for (size_t i = 0; i < variations.size(); i++)
{
Variation<T>* var = variations[i];
if (var->m_Weight != 0)//This should never happen, but just to be safe.
{
if (FindIf(names, [&] (const string& s) -> bool { return !_stricmp(s.c_str(), var->Name().c_str()); }))//If any variation is present, don't flatten.
@ -942,14 +926,15 @@ public:
//Now traverse the parameters for this variation.
if (ParametricVariation<T>* parVar = dynamic_cast<ParametricVariation<T>*>(var))//If any parametric variation parameter is present and non-zero, don't flatten.
{
ForEach(names, [&] (const string& s)
for (auto& s : names)
{
if (parVar->GetParamVal(s.c_str()) != 0)
{
shouldFlatten = false;
keepGoing = false;
break;
}
});
}
}
}
});
@ -1175,16 +1160,16 @@ public:
const_cast<Xform<T>*>(this)->AllVarsFunc([&] (vector<Variation<T>*>& variations, bool& keepGoing)
{
for (size_t i = 0; i < variations.size(); i++)
ss << variations[i]->ToString() << endl;
for (auto var : variations)
ss << var->ToString() << endl;
ss << endl;
});
if (XaosPresent())
{
for (size_t i = 0; i < m_Xaos.size(); i++)
ss << m_Xaos[i] << " ";
for (auto xaos : m_Xaos)
ss << xaos << " ";
ss << endl;
}

View File

@ -1261,11 +1261,9 @@ private:
/// <returns>The corrected name if one was found, else the passed in name.</returns>
static string GetCorrectedParamName(vector<pair<string, string>>& vec, const char* name)
{
for (size_t i = 0; i < vec.size(); i++)
{
if (!_stricmp(vec[i].first.c_str(), name))
return vec[i].second;
}
for (auto& v : vec)
if (!_stricmp(v.first.c_str(), name))
return v.second;
return name;
}
@ -1281,21 +1279,21 @@ private:
/// <returns>The corrected name if one was found, else the passed in name.</returns>
static string GetCorrectedVariationName(vector<pair<pair<string, string>, vector<string>>>& vec, xmlAttrPtr att)
{
for (size_t i = 0; i < vec.size(); i++)
for (auto& v : vec)
{
if (!_stricmp(vec[i].first.first.c_str(), CCX(att->name)))//Do case insensitive here.
if (!_stricmp(v.first.first.c_str(), CCX(att->name)))//Do case insensitive here.
{
if (!vec[i].second.empty())
if (!v.second.empty())
{
for (size_t j = 0; j < vec[i].second.size(); j++)
for (size_t j = 0; j < v.second.size(); j++)
{
if (XmlContainsTag(att, vec[i].second[j].c_str()))
return vec[i].first.second;
if (XmlContainsTag(att, v.second[j].c_str()))
return v.first.second;
}
}
else
{
return vec[i].first.second;
return v.first.second;
}
}
}