Atoms Crowd  7.0.0
AtomsCache.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 
11 #include <Atoms/Globals.h>
12 #include <Atoms/AgentGroup.h>
13 #include <Atoms/AgentTypes.h>
14 
15 namespace Atoms
16 {
17  class ATOMS_EXPORT AtomsCache
18  {
19  public:
20 
21  class FrameData
22  {
23  public:
24  AtomsPtr<AtomsCore::MapMetadata> pose;
25  AtomsPtr<AtomsCore::MapMetadata> metadata;
26  AtomsPtr<AtomsCore::MapMetadata> frame;
27  AtomsPtr<AtomsCore::MapMetadata> header;
28  };
29 
32 
34  /*
35  \param cachePath cache folder path
36  \param cacheName cache name without .atoms
37  */
38  AtomsCache(const std::string& cachePath, const std::string& cacheName);
39 
41  /*
42  \param cachePath cache folder path
43  \param cacheName cache name without .atoms
44  \param agents Agents ids, it loads only those agents form the cache
45  */
46  AtomsCache(const std::string& cachePath, const std::string& cacheName, const std::vector<int>& agents);
47 
50 
52 
54  bool openCache(const std::string& cachePath, const std::string& cacheName);
55 
57 
60  bool openCache(const std::string& cachePath, const std::string& cacheName, const std::vector<int>& agents);
61 
63  void loadTime(double time);
64 
66  void loadPrevFrame(int frame);
67 
69 
70  void loadFrame(int frame);
71 
73  void loadNextFrame(int frame);
74 
76  void loadPrevFrameHeader(int frame);
77 
79 
80  void loadFrameHeader(int frame);
81 
83  void loadNextFrameHeader(int frame);
84 
86  size_t numAgents() const;
87 
89  int startFrame() const;
90 
92  int endFrame() const;
93 
95  int currentFrame() const;
96 
98  int prevFrame() const;
99 
101  int nextFrame() const;
102 
105 
108 
111 
113 
117  void loadBoundingBox(double time, AtomsCore::Box3& box) const;
118 
120 
125  void loadAgent(double time, unsigned int agentId, Atoms::Agent& agent) const;
126 
128 
133  void loadAgentBoundingBox(double time, unsigned int agentId, AtomsCore::Box3& box) const;
134 
136 
141  void loadAgentPose(double time, unsigned int agentId, AtomsCore::Pose& pose) const;
142 
144 
149  void loadAgentMetadata(double time, unsigned int agentId, AtomsCore::MapMetadata& metadata) const;
150 
152  void clear();
153 
155 
159  static bool exportCacheFrame(
160  const std::string& cachePath,
161  const std::string& cacheName,
162  long frame,
163  const std::vector<AtomsPtr<Atoms::AgentGroup>>& agentGroups,
164  std::unordered_map<size_t, size_t>& cacheIdMap,
165  std::set<std::string>& agentTypes,
166  size_t tags,
167  bool useSkinMeshBBox = false);
168 
170  void processMetadata(AtomsCore::MapMetadata &outMetadata, std::vector<const AtomsCore::MapMetadata*> &inMetadatas, const std::vector<double> &inputWeightVector) const;
171 
173  void blendPose(size_t numJoints, std::vector<const AtomsCore::Pose*>& posePorts, std::vector<double>& weightPorts, AtomsCore::Pose& outPose) const;
174 
176  const std::string& agentType(double time, unsigned int agentId) const;
177 
179  const AtomsCore::Vector3& agentPosition(double time, unsigned int agentId) const;
180 
182  const std::string& agentVariation(double time, unsigned int agentId) const;
183 
185  const std::vector<std::string>& agentVariationOverrides(double time, unsigned int agentId) const;
186 
188  const int agentVariationSeed(double time, unsigned int agentId) const;
189 
191  const std::vector<std::string>& agentsVariationsGeoMatOverride(double time, unsigned int agentId) const;
192 
194  const std::vector<std::string>& agentsVariationsGeometryFilter(double time, unsigned int agentId) const;
195 
197  int agentColorVariation(double time, unsigned int agentId) const;
198 
200  int agentSourceGroupId(double time, unsigned int agentId) const;
201 
203  const std::string& agentLod(double time, unsigned int agentId) const;
204 
206  const AtomsCore::Vector3& agentVelocity(double time, unsigned int agentId) const;
207 
209  const std::vector<int>& agentIds(double time) const;
210 
212  const std::vector<int>& agentsCreated(double time) const;
213 
215  const std::vector<int>& agentsDeleted(double time) const;
216 
218  size_t numAgentsCreated(double time) const;
219 
221  size_t numAgentsDeleted(double time) const;
222 
224  void setAgentsToLoad(const std::vector<int>& agents);
225 
227  const std::string& cacheName() const;
228 
230  const std::string& cachePath() const;
231 
233  /*
234  Get an agent type from the local AgentTypes or from the global AgentTypes singleton
235  If an agent type desn't exists it loads from the cache folder and store isnide the local agentypes
236  if asGlobal is false or on the global singleton if it's true.
237  \param agentTypeName Agne type name
238  \param asGlobal If false, it stores the agent type loaded from the cache inside the local agentTypes, else it stores inside the global AgetnTypes singleton
239  */
240  AgentTypePtr loadAgentType(const std::string& agentTypeName, bool asGlobal = true);
241 
244 
246  const AgentTypes& agentTypes() const;
247 
248  private:
249 
250  int clampFrame(int frame) const;
251 
253  void readData(FrameData& data, int frame, int& m_currentFrame) const;
254 
255  void readDataKeys(FrameData& data, int frame, std::vector<std::string>& keys, int& m_currentFrame) const;
256 
257  void readFrameHeaderData(FrameData& data, int frame, int& m_currentFrame) const;
258 
259  private:
260 
262  Atoms::AgentTypes m_agentTypes;
263 
265  AtomsCore::MapMetadata m_header;
266 
268  FrameData m_prevFrameData;
269 
271  FrameData m_currentFrameData;
272 
274  FrameData m_nextFrameData;
275 
276  std::vector<std::string> m_agentIdsToLoad;
277 
279  std::string m_cachePath;
280 
282  std::string m_cacheName;
283 
285  int m_startFrame;
286 
288  int m_endFrame;
289 
291  int m_prevFrame;
292 
294  int m_currentFrame;
295 
297  int m_nextFrame;
298 
299  std::vector<int> m_emptyIds;
300 
301  std::string m_emptyString;
302 
303  std::vector<std::string> m_emptyStringVector;
304 
305  AtomsCore::Vector3 m_emptyVector;
306  };
307 }
Agent.
Definition: Agent.h:44
Container for all agent types.
Definition: AgentTypes.h:20
Definition: AtomsCache.h:22
Definition: AtomsCache.h:18
void loadTime(double time)
Loads the pre/next and current frame given the input time.
const std::string & cachePath() const
Return the cache path.
const std::vector< int > & agentIds(double time) const
Gets agent ids.
void loadNextFrame(int frame)
Loads a cache frame and stores the next frame data (usually used for the next frame during the motion...
void clear()
Clear all the loaded frames.
const std::string & agentLod(double time, unsigned int agentId) const
Get the agent lod.
const std::string & agentType(double time, unsigned int agentId) const
Gets the agent type.
size_t numAgents() const
Get the number of agents.
const std::string & cacheName() const
Return the cache name.
const std::vector< std::string > & agentsVariationsGeometryFilter(double time, unsigned int agentId) const
Get the agent variation geo filter overrides.
bool openCache(const std::string &cachePath, const std::string &cacheName, const std::vector< int > &agents)
Opens a cache.
const std::vector< std::string > & agentsVariationsGeoMatOverride(double time, unsigned int agentId) const
Get the agent variation geo mat overrides.
size_t numAgentsCreated(double time) const
Gets the number of agents created.
int prevFrame() const
Get the previous frame.
void loadAgentMetadata(double time, unsigned int agentId, AtomsCore::MapMetadata &metadata) const
Loads an agent metadata.
void loadFrameHeader(int frame)
Loads a cache frame header and stores the current frame data.
const std::vector< std::string > & agentVariationOverrides(double time, unsigned int agentId) const
Get the agent variation overrides.
int nextFrame() const
Get the next frame.
const AgentTypes & agentTypes() const
Return the local agent types object.
AtomsCache()
Constructor.
AgentTypes & agentTypes()
Return the local agent types object.
bool openCache(const std::string &cachePath, const std::string &cacheName)
Opens a cache.
void loadAgent(double time, unsigned int agentId, Atoms::Agent &agent) const
Loads all data for an agent.
FrameData & nextFrameData()
Get the next frame data.
int startFrame() const
Get the start frame.
void processMetadata(AtomsCore::MapMetadata &outMetadata, std::vector< const AtomsCore::MapMetadata * > &inMetadatas, const std::vector< double > &inputWeightVector) const
Blends multiple mapmetadata.
void loadNextFrameHeader(int frame)
Loads a cache frame and stores the next frame data (usually used for the next frame during the motion...
const int agentVariationSeed(double time, unsigned int agentId) const
Get the agent variation seed.
static bool exportCacheFrame(const std::string &cachePath, const std::string &cacheName, long frame, const std::vector< AtomsPtr< Atoms::AgentGroup >> &agentGroups, std::unordered_map< size_t, size_t > &cacheIdMap, std::set< std::string > &agentTypes, size_t tags, bool useSkinMeshBBox=false)
Exports a single frame cache file.
void loadAgentBoundingBox(double time, unsigned int agentId, AtomsCore::Box3 &box) const
Loads an agent bbox.
const AtomsCore::Vector3 & agentPosition(double time, unsigned int agentId) const
Gets the agent position.
FrameData & prevFrameData()
Get the previous frame data.
void loadBoundingBox(double time, AtomsCore::Box3 &box) const
Loads bbox.
const std::string & agentVariation(double time, unsigned int agentId) const
Get the agent variation.
void loadPrevFrameHeader(int frame)
Loads a cache frame header and store in the previuos frame (usually used for the previous frame durin...
int currentFrame() const
Get the current frame.
int endFrame() const
Get the end frame.
const AtomsCore::Vector3 & agentVelocity(double time, unsigned int agentId) const
Gets the agent velocity.
const std::vector< int > & agentsCreated(double time) const
Gets the list of agent created.
void setAgentsToLoad(const std::vector< int > &agents)
Sets the agents to be loaded from the cache.
AgentTypePtr loadAgentType(const std::string &agentTypeName, bool asGlobal=true)
Load and get an agent type.
void blendPose(size_t numJoints, std::vector< const AtomsCore::Pose * > &posePorts, std::vector< double > &weightPorts, AtomsCore::Pose &outPose) const
Blends pose.
AtomsCache(const std::string &cachePath, const std::string &cacheName)
Constructor.
const std::vector< int > & agentsDeleted(double time) const
Gets the list of agent deleted.
AtomsCache(const std::string &cachePath, const std::string &cacheName, const std::vector< int > &agents)
Constructor.
FrameData & frameData()
Get the current frame data.
void loadAgentPose(double time, unsigned int agentId, AtomsCore::Pose &pose) const
Loads an agent pose.
int agentSourceGroupId(double time, unsigned int agentId) const
Get the agent source group id.
void loadFrame(int frame)
Loads a cache frame and stores the current frame data.
int agentColorVariation(double time, unsigned int agentId) const
Get the agent variation.
~AtomsCache()
Destructor.
size_t numAgentsDeleted(double time) const
Gets the number of agent deleted.
void loadPrevFrame(int frame)
Loads a cache frame and store in the previous frame (usually used for the previous frame during the m...
MapMetadata class.
Definition: MapMetadata.h:24
Pose class.
Definition: Pose.h:32
AtomsMath::Box3 Box3
Bounding box class.
Definition: AtomsMath.h:74
AtomsMath::Vector3 Vector3
Vector3 class.
Definition: AtomsMath.h:57
Atoms namespace.
Definition: Agent.h:29
AtomsPtr< AgentType > AgentTypePtr
Agent type pointer.
Definition: AgentType.h:17