34 #pragma region LProduction 41 m_chLHS(lhs), m_wstrRHS(rhs), m_fProb(fProb){
44 #pragma endregion LProduction 51 #pragma region Settings functions 65 std::vector<LProduction> v;
70 else p->second.push_back(rule);
80 std::wstringstream wstream;
82 wstream << std::fixed << rule.
m_fProb;
110 #pragma endregion Settings functions 115 #pragma region Generate 133 for(UINT i=0; i<n; i++){
136 for(
size_t i=0; i<pSrc->size(); i++){
137 bool bRuleApplied =
false;
145 for(
auto rule: p->second){
146 fProb += rule.m_fProb;
149 *pDest += rule.m_wstrRHS;
157 *pDest += (*pSrc)[i];
160 std::swap(pSrc, pDest);
166 #pragma endregion Generate 171 #pragma region Reader functions 201 #pragma endregion Reader functions std::wstring m_wstrRHS
Right-hand side of production.
std::map< wchar_t, std::vector< LProduction > > m_mapRules
Productions.
Useful types and structures.
void Clear()
Clear the rules, buffers, and settings.
LProduction(char lhs, const std::wstring rhs, float fProb=1)
Constructor.
float randf()
Get random floating point number.
std::wstring * m_pResult
Pointer to generated string.
const bool IsStochastic() const
Is a stochastic L-system.
std::wstring m_wstrBuffer[2]
Generation buffers.
Interface for LProduction and LSystem.
Stochastic context-free production.
const std::wstring & GetRuleString() const
Get rule string.
std::wstring m_wstrRuleString
Rule string.
char m_chLHS
Left-hand side of production.
std::wstring m_wstrRoot
Root string.
const std::wstring & GetString() const
Get generated string.
const UINT GetGenerations() const
Get number of generations.
void AddRule(const LProduction &rule)
AddRule rule.
void Generate(const UINT n)
Generate L-system from stored root and rules.
float m_fProb
Probability of production applying.
bool m_bStochastic
Includes a stochastic rule.
void SetRoot(const std::wstring &omega)
Set the root string.
UINT m_nGenerations
Number of generations.