Atoms Crowd  4.1.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 loadPrevFrame(int frame);
64 
66 
67  void loadFrame(int frame);
68 
70  void loadNextFrame(int frame);
71 
73  void loadPrevFrameHeader(int frame);
74 
76 
77  void loadFrameHeader(int frame);
78 
80  void loadNextFrameHeader(int frame);
81 
83  size_t numAgents() const;
84 
86  int startFrame() const;
87 
89  int endFrame() const;
90 
92  int currentFrame() const;
93 
95  int prevFrame() const;
96 
98  int nextFrame() const;
99 
102 
105 
108 
110 
114  void loadBoundingBox(double time, AtomsCore::Box3& box) const;
115 
117 
122  void loadAgent(double time, unsigned int agentId, Atoms::Agent& agent) const;
123 
125 
130  void loadAgentBoundingBox(double time, unsigned int agentId, AtomsCore::Box3& box) const;
131 
133 
138  void loadAgentPose(double time, unsigned int agentId, AtomsCore::Pose& pose) const;
139 
141 
146  void loadAgentMetadata(double time, unsigned int agentId, AtomsCore::MapMetadata& metadata) const;
147 
149  void clear();
150 
152 
156  static bool exportCacheFrame(
157  const std::string& cachePath,
158  const std::string& cacheName,
159  long frame,
160  const std::vector<AtomsPtr<Atoms::AgentGroup>>& agentGroups,
161  std::unordered_map<size_t, size_t>& cacheIdMap,
162  std::set<std::string>& agentTypes,
163  size_t tags,
164  bool useSkinMeshBBox = false);
165 
167  void processMetadata(AtomsCore::MapMetadata &outMetadata, std::vector<const AtomsCore::MapMetadata*> &inMetadatas, const std::vector<double> &inputWeightVector) const;
168 
170  void blendPose(size_t numJoints, std::vector<const AtomsCore::Pose*>& posePorts, std::vector<double>& weightPorts, AtomsCore::Pose& outPose) const;
171 
173  const std::string& agentType(double time, unsigned int agentId) const;
174 
176  const AtomsCore::Vector3& agentPosition(double time, unsigned int agentId) const;
177 
179  const std::string& agentVariation(double time, unsigned int agentId) const;
180 
182  int agentColorVariation(double time, unsigned int agentId) const;
183 
185  const std::string& agentLod(double time, unsigned int agentId) const;
186 
188  const AtomsCore::Vector3& agentVelocity(double time, unsigned int agentId) const;
189 
191  const std::vector<int>& agentIds(double time) const;
192 
194  const std::vector<int>& agentsCreated(double time) const;
195 
197  const std::vector<int>& agentsDeleted(double time) const;
198 
200  size_t numAgentsCreated(double time) const;
201 
203  size_t numAgentsDeleted(double time) const;
204 
206  void setAgentsToLoad(const std::vector<int>& agents);
207 
209  const std::string& cacheName() const;
210 
212  const std::string& cachePath() const;
213 
215  /*
216  Get an agent type from the local AgentTypes or from the global AgentTypes singleton
217  If an agent type desn't exists it loads from the cache folder and store isnide the local agentypes
218  if asGlobal is false or on the global singleton if it's true.
219  \param agentTypeName Agne type name
220  \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
221  */
222  AgentTypePtr loadAgentType(const std::string& agentTypeName, bool asGlobal = true);
223 
226 
228  const AgentTypes& agentTypes() const;
229 
230  private:
231 
233  void readData(FrameData& data, int frame, int& m_currentFrame) const;
234 
235  void readDataKeys(FrameData& data, int frame, std::vector<std::string>& keys, int& m_currentFrame) const;
236 
237  void readFrameHeaderData(FrameData& data, int frame, int& m_currentFrame) const;
238 
239  private:
240 
242  Atoms::AgentTypes m_agentTypes;
243 
245  AtomsCore::MapMetadata m_header;
246 
248  FrameData m_prevFrameData;
249 
251  FrameData m_currentFrameData;
252 
254  FrameData m_nextFrameData;
255 
256  std::vector<std::string> m_agentIdsToLoad;
257 
259  std::string m_cachePath;
260 
262  std::string m_cacheName;
263 
265  int m_startFrame;
266 
268  int m_endFrame;
269 
271  int m_prevFrame;
272 
274  int m_currentFrame;
275 
277  int m_nextFrame;
278 
279  std::vector<int> m_emptyIds;
280 
281  std::string m_emptyString;
282 
283  AtomsCore::Vector3 m_emptyVector;
284  };
285 }
Atoms::AtomsCache::agentsCreated
const std::vector< int > & agentsCreated(double time) const
Gets the list of agent created.
Atoms::AtomsCache::FrameData
Definition: AtomsCache.h:22
Atoms::AtomsCache::clear
void clear()
Clear all the loaded frames.
Atoms::AtomsCache::agentIds
const std::vector< int > & agentIds(double time) const
Gets agent ids.
Atoms::AtomsCache::agentVariation
const std::string & agentVariation(double time, unsigned int agentId) const
Get the agent variation.
Atoms::AtomsCache::numAgents
size_t numAgents() const
Get the number of agents.
Atoms::AtomsCache::currentFrame
int currentFrame() const
Get the current frame.
Atoms::AtomsCache::agentsDeleted
const std::vector< int > & agentsDeleted(double time) const
Gets the list of agent deleted.
Atoms::AtomsCache::nextFrame
int nextFrame() const
Get the next frame.
Atoms::AtomsCache::frameData
FrameData & frameData()
Get the current frame data.
Atoms::AtomsCache::loadBoundingBox
void loadBoundingBox(double time, AtomsCore::Box3 &box) const
Loads bbox.
Atoms::AtomsCache::processMetadata
void processMetadata(AtomsCore::MapMetadata &outMetadata, std::vector< const AtomsCore::MapMetadata * > &inMetadatas, const std::vector< double > &inputWeightVector) const
Blends multiple mapmetadata.
Atoms::AtomsCache::agentVelocity
const AtomsCore::Vector3 & agentVelocity(double time, unsigned int agentId) const
Gets the agent velocity.
Atoms::AtomsCache::loadNextFrame
void loadNextFrame(int frame)
Loads a cache frame and stores the next frame data (usually used for the next frame during the motion...
Atoms::AtomsCache::setAgentsToLoad
void setAgentsToLoad(const std::vector< int > &agents)
Sets the agents to be loaded from the cache.
Atoms::AtomsCache::cachePath
const std::string & cachePath() const
Return the cache path.
Atoms::AtomsCache::endFrame
int endFrame() const
Get the end frame.
Atoms::AtomsCache
Definition: AtomsCache.h:18
Atoms::AtomsCache::agentLod
const std::string & agentLod(double time, unsigned int agentId) const
Get the agent lod.
AtomsCore::Box3
AtomsMath::Box3 Box3
Bounding box class.
Definition: AtomsMath.h:74
Atoms::AtomsCache::exportCacheFrame
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.
Atoms::AtomsCache::agentTypes
AgentTypes & agentTypes()
Return the local agent types object.
Atoms::AgentTypePtr
AtomsPtr< AgentType > AgentTypePtr
Agent type pointer.
Definition: AgentType.h:17
Atoms::Agent
Agent.
Definition: Agent.h:38
Atoms::AtomsCache::loadAgentType
AgentTypePtr loadAgentType(const std::string &agentTypeName, bool asGlobal=true)
Load and get an agent type.
Atoms::AtomsCache::numAgentsCreated
size_t numAgentsCreated(double time) const
Gets the number of agents created.
Atoms::AtomsCache::AtomsCache
AtomsCache(const std::string &cachePath, const std::string &cacheName)
Constructor.
Atoms::AtomsCache::loadAgentBoundingBox
void loadAgentBoundingBox(double time, unsigned int agentId, AtomsCore::Box3 &box) const
Loads an agent bbox.
Atoms::AtomsCache::startFrame
int startFrame() const
Get the start frame.
Atoms::AtomsCache::blendPose
void blendPose(size_t numJoints, std::vector< const AtomsCore::Pose * > &posePorts, std::vector< double > &weightPorts, AtomsCore::Pose &outPose) const
Blends pose.
AtomsCore::Vector3
AtomsMath::Vector3 Vector3
Vector3 class.
Definition: AtomsMath.h:57
Atoms::AtomsCache::agentColorVariation
int agentColorVariation(double time, unsigned int agentId) const
Get the agent variation.
Atoms::AtomsCache::loadNextFrameHeader
void loadNextFrameHeader(int frame)
Loads a cache frame and stores the next frame data (usually used for the next frame during the motion...
Atoms::AtomsCache::loadFrameHeader
void loadFrameHeader(int frame)
Loads a cache frame header and stores the current frame data.
Atoms::AtomsCache::loadPrevFrame
void loadPrevFrame(int frame)
Loads a cache frame and store in the previous frame (usually used for the previous frame during the m...
Atoms::AtomsCache::prevFrameData
FrameData & prevFrameData()
Get the previous frame data.
Atoms::AtomsCache::AtomsCache
AtomsCache(const std::string &cachePath, const std::string &cacheName, const std::vector< int > &agents)
Constructor.
Atoms::AtomsCache::nextFrameData
FrameData & nextFrameData()
Get the next frame data.
Atoms::AtomsCache::loadAgentMetadata
void loadAgentMetadata(double time, unsigned int agentId, AtomsCore::MapMetadata &metadata) const
Loads an agent metadata.
Atoms
Atoms namespace.
Definition: Agent.h:28
Atoms::AtomsCache::loadAgent
void loadAgent(double time, unsigned int agentId, Atoms::Agent &agent) const
Loads all data for an agent.
Atoms::AgentTypes
Container for all agent types.
Definition: AgentTypes.h:20
Atoms::AtomsCache::numAgentsDeleted
size_t numAgentsDeleted(double time) const
Gets the number of agent deleted.
AtomsCore::MapMetadata
MapMetadata class.
Definition: MapMetadata.h:24
Atoms::AtomsCache::openCache
bool openCache(const std::string &cachePath, const std::string &cacheName, const std::vector< int > &agents)
Opens a cache.
Atoms::AtomsCache::loadFrame
void loadFrame(int frame)
Loads a cache frame and stores the current frame data.
Atoms::AtomsCache::agentPosition
const AtomsCore::Vector3 & agentPosition(double time, unsigned int agentId) const
Gets the agent position.
Atoms::AtomsCache::agentTypes
const AgentTypes & agentTypes() const
Return the local agent types object.
AtomsCore::Pose
Pose class.
Definition: Pose.h:32
Atoms::AtomsCache::loadAgentPose
void loadAgentPose(double time, unsigned int agentId, AtomsCore::Pose &pose) const
Loads an agent pose.
Atoms::AtomsCache::agentType
const std::string & agentType(double time, unsigned int agentId) const
Gets the agent type.
Atoms::AtomsCache::loadPrevFrameHeader
void loadPrevFrameHeader(int frame)
Loads a cache frame header and store in the previuos frame (usually used for the previous frame durin...
Atoms::AtomsCache::openCache
bool openCache(const std::string &cachePath, const std::string &cacheName)
Opens a cache.
Atoms::AtomsCache::~AtomsCache
~AtomsCache()
Destructor.
Atoms::AtomsCache::prevFrame
int prevFrame() const
Get the previous frame.
Atoms::AtomsCache::cacheName
const std::string & cacheName() const
Return the cache name.
Atoms::AtomsCache::AtomsCache
AtomsCache()
Constructor.