Atoms Crowd  7.0.0
Variations.impl.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 
10 namespace Atoms
11 {
12  bool Variations::removeAgentTypeVariation(const std::string &agentTypeName)
13  {
14  std::map<std::string, AgentTypeVariation>::iterator it = m_agentTypeVariations.find(agentTypeName);
15  if (it != m_agentTypeVariations.end())
16  {
17  m_agentTypeVariations.erase(it);
18  return true;
19  }
20  return false;
21  }
22 
23  std::vector<std::string> Variations::getAgentTypeNames() const
24  {
25  std::vector<std::string> names;
26  names.reserve(m_agentTypeVariations.size());
27  for (auto it = m_agentTypeVariations.cbegin(); it != m_agentTypeVariations.cend(); it++)
28  names.push_back(it->first);
29  return names;
30  }
31 
32  AgentTypeVariationCPtr Variations::getAgentTypeVariationPtr(const std::string &agentTypeName) const
33  {
34  std::map<std::string, AgentTypeVariation>::const_iterator it = m_agentTypeVariations.find(agentTypeName);
35  if (it != m_agentTypeVariations.cend())
36  return &it->second;
37  return nullptr;
38  }
39 
40  inline VariationGeometryCPtr AgentTypeVariation::getGeometryPtr(const std::string &name) const
41  {
42  std::map<std::string, VariationGeometry>::const_iterator it = m_geos.find(name);
43  if (it != m_geos.cend())
44  return &it->second;
45  return nullptr;
46  }
47 
48  inline VariationMaterialCPtr AgentTypeVariation::getMaterialPtr(const std::string &name) const
49  {
50  std::map<std::string, VariationMaterial>::const_iterator it = m_mats.find(name);
51  if (it != m_mats.cend())
52  return &it->second;
53  return nullptr;
54  }
55 
56  inline VariationGroupCPtr AgentTypeVariation::getGroupPtr(const std::string &name) const
57  {
58  std::map<std::string, VariationGroup>::const_iterator it = m_groups.find(name);
59  if (it != m_groups.cend())
60  return &it->second;
61  return nullptr;
62  }
63 
64  inline VariationOverrideCPtr AgentTypeVariation::getOverridePtr(const std::string& name) const
65  {
66  std::map<std::string, VariationOverride>::const_iterator it = m_overrides.find(name);
67  if (it != m_overrides.cend())
68  return &it->second;
69  return nullptr;
70  }
71 
73  {
74  m_geos.clear();
75  m_mats.clear();
76  m_groups.clear();
77  m_overrides.clear();
78  m_variationTree = VariationTree(this);
79  }
80 
81  std::vector<std::string> AgentTypeVariation::getGeometryNames() const
82  {
83  std::vector<std::string> names;
84  names.reserve(m_geos.size());
85  for (auto it = m_geos.cbegin(); it != m_geos.cend(); it++)
86  names.push_back(it->first);
87  return names;
88  }
89 
90  std::vector<std::string> AgentTypeVariation::getMaterialNames() const
91  {
92  std::vector<std::string> names;
93  names.reserve(m_mats.size());
94  for (auto it = m_mats.cbegin(); it != m_mats.cend(); it++)
95  names.push_back(it->first);
96  return names;
97  }
98 
99  std::vector<std::string> AgentTypeVariation::getGroupNames() const
100  {
101  std::vector<std::string> names;
102  names.reserve(m_groups.size());
103  for (auto it = m_groups.cbegin(); it != m_groups.cend(); it++)
104  names.push_back(it->first);
105  return names;
106  }
107 
108  std::vector<std::string> AgentTypeVariation::getOverrideNames() const
109  {
110  std::vector<std::string> names;
111  names.reserve(m_overrides.size());
112  for (auto it = m_overrides.cbegin(); it != m_overrides.cend(); it++)
113  names.push_back(it->first);
114  return names;
115  }
116 
117  bool AgentTypeVariation::removeGeometry(const std::string &name)
118  {
119  std::map<std::string, VariationGeometry>::iterator it = m_geos.find(name);
120  if (it != m_geos.end())
121  {
122  m_geos.erase(it);
123  return true;
124  }
125  return false;
126  }
127 
128  bool AgentTypeVariation::removeMaterial(const std::string &name)
129  {
130  std::map<std::string, VariationMaterial>::iterator it = m_mats.find(name);
131  if (it != m_mats.end())
132  {
133  m_mats.erase(it);
134  return true;
135  }
136  return false;
137  }
138 
139  bool AgentTypeVariation::removeGroup(const std::string &name)
140  {
141  std::map<std::string, VariationGroup>::iterator it = m_groups.find(name);
142  if (it != m_groups.end())
143  {
144  m_groups.erase(it);
145  return true;
146  }
147  return false;
148  }
149 
151  {
152  m_groups.clear();
153  return true;
154  }
155 
156  bool AgentTypeVariation::removeOverride(const std::string& name)
157  {
158  std::map<std::string, VariationOverride>::iterator it = m_overrides.find(name);
159  if (it != m_overrides.end())
160  {
161  m_overrides.erase(it);
162  return true;
163  }
164  return false;
165  }
166 
168  {
169  m_overrides.clear();
170  return true;
171  }
172 
173  inline VariationGroupLodCPtr VariationGroup::getLodPtr(const std::string &name) const
174  {
175  std::map<std::string, VariationGroupLod>::const_iterator it = m_lods.find(name);
176  if (it != m_lods.cend())
177  return &it->second;
178  return nullptr;
179  }
180 
181  inline bool BaseVariationGroup::hasCombination(const std::string &geometryName, const std::string &materialName)
182  {
183  return std::find(m_combinations.begin(), m_combinations.end(), std::pair<std::string, std::string>(geometryName, materialName)) != m_combinations.end();
184  }
185 
186  bool VariationGroup::removeLod(const std::string &name)
187  {
188  std::map<std::string, VariationGroupLod>::iterator it = m_lods.find(name);
189  if (it != m_lods.end())
190  {
191  m_lods.erase(it);
192  return true;
193  }
194  return false;
195  }
196 
197  const std::pair<std::string, std::string>& BaseVariationGroup::getCombinationAtIndex(unsigned int index) const
198  {
199  if (index < m_combinations.size())
200  return m_combinations[index];
201  return m_emptyPair;
202  }
203 
205  {
206  if (index < m_combinations.size())
207  {
208  m_combinations.erase(m_combinations.begin() + index);
209  return true;
210  }
211  return false;
212  }
213 
214  std::vector<std::string> VariationGroup::getLodNames() const
215  {
216  std::vector<std::string> names;
217  names.reserve(m_lods.size());
218  for (auto it = m_lods.cbegin(); it != m_lods.cend(); it++)
219  names.push_back(it->first);
220  return names;
221  }
222 
223  size_t Variations::size() const
224  {
225  return m_agentTypeVariations.size();
226  }
227 
228  bool VariationOverride::hasGeometryFilter(const std::string& geometryName) const
229  {
230  return std::find(m_geometryFilter.begin(), m_geometryFilter.end(), geometryName) != m_geometryFilter.end();
231  }
232 
233  const std::string& VariationOverride::getGeometryFilterAtIndex(unsigned int index) const
234  {
235  if (index < m_geometryFilter.size())
236  return m_geometryFilter[index];
237  return m_emptyString;
238  }
239 
241  {
242  if (index < m_geometryFilter.size())
243  {
244  m_geometryFilter.erase(m_geometryFilter.begin() + index);
245  return true;
246  }
247  return false;
248  }
249 
251  {
252  m_variationTypes.clear();
253  m_extraGeos.clear();
254  m_materialConstraints.clear();
255  m_geoMatAlias.clear();
256  m_geoMatSuffixRepl.first = "";
257  m_geoMatSuffixRepl.second = "";
258  m_materialPrefix = "";
259  }
260 
261  void VariationTree::addVariationType(const std::string& name, const VariationTreeGeo& vg)
262  {
263  m_variationTypes.insert({ name, vg });
264  }
265 
266  void VariationTree::addExtraGeo(const std::string& name, const VariationTreeGeo& vg)
267  {
268  m_extraGeos.insert({ name, vg });
269  }
270 
271  void VariationTree::addMaterialConstraint(const std::string& name, const MaterialConstraint& mc)
272  {
273  m_materialConstraints.insert({ name, mc });
274  }
275 
276  void VariationTree::addExcludeGeometry(const std::string &name, const ExcludeGeometry& eg)
277  {
278  if (!m_atVariation->hasGeometry(eg.getSourceGeometry()))
279  {
280  AtomsUtils::Logger::error() << "Can't add exclude geometry " << name << ". Geometry " << eg.getSourceGeometry() << " does not exist";
281  return;
282  }
283 
284  if (!m_atVariation->hasGeometry(eg.getDestinationGeometry()))
285  {
286  AtomsUtils::Logger::error() << "Can't add exclude geometry " << name << ". Geometry " << eg.getDestinationGeometry() << " does not exist";
287  return;
288  }
289 
290  m_excludeGeometries.insert({ name, eg });
291  }
292 
293  bool MaterialOverride::hasMaterial(const std::string& materialName) const
294  {
295  return std::find(m_materialNames.begin(), m_materialNames.end(), materialName) != m_materialNames.end();
296  }
297 
298  void MaterialOverride::addMaterial(const std::string& materialName, const double weight)
299  {
300  m_materialNames.push_back(materialName);
301  m_materialWeights.push_back(weight);
302  }
303 
304  const std::string& MaterialOverride::getMaterialNameAtIndex(unsigned int index) const
305  {
306  if (index >= 0 && index < m_materialNames.size())
307  return m_materialNames[index];
308  return m_emptyString;
309  }
310 
311  const double MaterialOverride::getMaterialWeightAtIndex(unsigned int index) const
312  {
313  if (index >= 0 && index < m_materialWeights.size())
314  return m_materialWeights[index];
315  return 0;
316  }
317 
319  {
320  if (index >= 0 && index < m_materialNames.size())
321  {
322  m_materialNames.erase(m_materialNames.begin() + index);
323  m_materialWeights.erase(m_materialWeights.begin() + index);
324  return true;
325  }
326  return false;
327  }
328 
329 }
Agent type variation class.
Definition: Variations.h:685
bool removeGeometry(const std::string &name)
Removes a geometry.
Definition: Variations.impl.h:117
bool removeOverride(const std::string &name)
Removes an override.
Definition: Variations.impl.h:156
std::vector< std::string > getOverrideNames() const
Gets the override names.
Definition: Variations.impl.h:108
std::vector< std::string > getMaterialNames() const
Gets the material names.
Definition: Variations.impl.h:90
std::vector< std::string > getGeometryNames() const
Gets the geometry names.
Definition: Variations.impl.h:81
VariationGroupCPtr getGroupPtr(const std::string &name) const
Gets a group.
Definition: Variations.impl.h:56
VariationOverrideCPtr getOverridePtr(const std::string &name) const
Gets an override.
Definition: Variations.impl.h:64
bool removeMaterial(const std::string &name)
Removes a material.
Definition: Variations.impl.h:128
VariationMaterialCPtr getMaterialPtr(const std::string &name) const
Gets a material.
Definition: Variations.impl.h:48
bool removeAllGroups()
Removes all groups.
Definition: Variations.impl.h:150
bool hasGeometry(const std::string &name) const
Checks if this object contains a geometry.
Definition: Variations.h:766
void clear()
Clear the greomeitres, materials and variaiton groups.
Definition: Variations.impl.h:72
bool removeGroup(const std::string &name)
Removes a group.
Definition: Variations.impl.h:139
bool removeAllOverrides()
Removes all override.
Definition: Variations.impl.h:167
std::vector< std::string > getGroupNames() const
Gets the group names.
Definition: Variations.impl.h:99
VariationGeometryCPtr getGeometryPtr(const std::string &name) const
Gets a geometry.
Definition: Variations.impl.h:40
const std::pair< std::string, std::string > & getCombinationAtIndex(unsigned int index) const
Gets a combination.
Definition: Variations.impl.h:197
bool removeCombinationAtIndex(unsigned int index)
Removes a combination.
Definition: Variations.impl.h:204
bool hasCombination(const std::string &geometryName, const std::string &materialName)
Checks if this object contains this combination.
Definition: Variations.impl.h:181
std::pair< std::string, std::string > m_emptyPair
Empty combination.
Definition: Variations.h:349
std::vector< std::pair< std::string, std::string > > m_combinations
Map of combinations.
Definition: Variations.h:346
Exclude Geometry.
Definition: Variations.h:405
Material Constraint class.
Definition: Variations.h:555
void addMaterial(const std::string &materialName, const double weight=1.0)
Adds a material.
Definition: Variations.impl.h:298
bool removeMaterialAtIndex(unsigned int index)
Removes a geometry filter.
Definition: Variations.impl.h:318
const double getMaterialWeightAtIndex(unsigned int index) const
Gets a material weight.
Definition: Variations.impl.h:311
const std::string & getMaterialNameAtIndex(unsigned int index) const
Gets a material name.
Definition: Variations.impl.h:304
bool hasMaterial(const std::string &materialName) const
Checks if this object contains this materia.
Definition: Variations.impl.h:293
VariationGeometry class.
Definition: Variations.h:64
Variation group class.
Definition: Variations.h:367
VariationGroupLodCPtr getLodPtr(const std::string &name) const
Gets a lod variation group.
Definition: Variations.impl.h:173
bool removeLod(const std::string &name)
Removes a lod.
Definition: Variations.impl.h:186
std::vector< std::string > getLodNames() const
Gets all lod names stored.
Definition: Variations.impl.h:214
Variation group lod class.
Definition: Variations.h:357
Variation Material.
Definition: Variations.h:135
Variation override class.
Definition: Variations.h:427
bool removeGeometryFilterAtIndex(unsigned int index)
Removes a geometry filter.
Definition: Variations.impl.h:240
bool hasGeometryFilter(const std::string &geometryName) const
Checks if this object contains this geometry filter.
Definition: Variations.impl.h:228
const std::string & getGeometryFilterAtIndex(unsigned int index) const
Gets a geometry filter.
Definition: Variations.impl.h:233
Variation Tree Geo class.
Definition: Variations.h:500
Variation Tree class.
Definition: Variations.h:580
void addExcludeGeometry(const std::string &name, const ExcludeGeometry &mc)
add exclude geometry
Definition: Variations.impl.h:276
void addExtraGeo(const std::string &name, const VariationTreeGeo &vg)
add extra geo
Definition: Variations.impl.h:266
void clear()
clear
Definition: Variations.impl.h:250
void addMaterialConstraint(const std::string &name, const MaterialConstraint &mc)
add material constraint
Definition: Variations.impl.h:271
void addVariationType(const std::string &name, const VariationTreeGeo &vg)
add variation type
Definition: Variations.impl.h:261
std::vector< std::string > getAgentTypeNames() const
Gets the agent type names.
Definition: Variations.impl.h:23
AgentTypeVariationCPtr getAgentTypeVariationPtr(const std::string &agentTypeName) const
Gets an agent type variation.
Definition: Variations.impl.h:32
bool removeAgentTypeVariation(const std::string &agentTypeName)
Removes an agent type variation.
Definition: Variations.impl.h:12
static LogProxy error()
Get logger proxy error.
Atoms namespace.
Definition: Agent.h:29