Partio

Partio.h
Go to the documentation of this file.
1/*
2 PARTIO SOFTWARE
3 Copyright 2010 Disney Enterprises, Inc. All rights reserved
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are
7 met:
8
9* Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12* Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the
15 distribution.
16
17* The names "Disney", "Walt Disney Pictures", "Walt Disney Animation
18 Studios" or the names of its contributors may NOT be used to
19 endorse or promote products derived from this software without
20 specific prior written permission from Walt Disney Pictures.
21
22 Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND
23 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
24 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
25 FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED.
26 IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR
27 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY
31 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
34*/
35
41#ifndef _Partioh_
42#define _Partioh_
43
44#include <string>
45#include <vector>
46#include <map>
47#include <stdint.h>
48#include <string.h>
49#include "PartioAttribute.h"
50#include "PartioIterator.h"
51
52 namespace Partio{
53
55 typedef uint64_t ParticleIndex;
56
57 class ParticlesData;
58 class ParticlesDataMutable;
59// Particle Collection Interface
61
66 class ParticlesInfo
67{
68 protected:
69 virtual ~ParticlesInfo() {}
70 public:
71
75 virtual void release()=0;
76
78 virtual int numParticles() const=0;
79
81 virtual int numAttributes() const=0;
83 virtual int numFixedAttributes() const=0;
84
86 virtual bool attributeInfo(const char* attributeName,ParticleAttribute& attribute) const=0;
88 virtual bool fixedAttributeInfo(const char* attributeName,FixedAttribute& attribute) const=0;
89
91 virtual bool attributeInfo(const int index,ParticleAttribute& attribute) const=0;
93 virtual bool fixedAttributeInfo(const int index,FixedAttribute& attribute) const=0;
94};
95
96// Particle Data Interface
98
102 class ParticlesData:public ParticlesInfo
103{
104 protected:
105 virtual ~ParticlesData() {}
106 public:
107 friend void freeCached(ParticlesData* particles);
108
109 typedef ParticleIterator<true> const_iterator;
110
114 template<class T> inline void data(const ParticleAttribute& attribute,
115 const int indexCount,const ParticleIndex* particleIndices,const bool sorted,T* values)
116 {
117 assert(typeCheck<T>(attribute.type));
118 dataInternalMultiple(attribute,indexCount,particleIndices,sorted,(char*)values);
119 }
120
121 template<class T> inline const T* data(const ParticleAttribute& attribute,
122 const ParticleIndex particleIndex) const
123 {
124 // TODO: add type checking
125 return static_cast<T*>(dataInternal(attribute,particleIndex));
126 }
127
128 template<class T> inline const T* fixedData(const FixedAttribute& attribute) const
129 {
130 // TODO: add type checking
131 return static_cast<T*>(fixedDataInternal(attribute));
132 }
133
135 virtual const std::vector<std::string>& indexedStrs(const ParticleAttribute& attr) const=0;
137 virtual const std::vector<std::string>& fixedIndexedStrs(const FixedAttribute& attr) const=0;
138
140 virtual int lookupIndexedStr(const ParticleAttribute& attribute,const char* str) const=0;
142 virtual int lookupFixedIndexedStr(const FixedAttribute& attribute,const char* str) const=0;
143
148 virtual void dataAsFloat(const ParticleAttribute& attribute,const int indexCount,
149 const ParticleIndex* particleIndices,const bool sorted,float* values) const=0;
150
154 virtual void findPoints(const float bboxMin[3],const float bboxMax[3],
155 std::vector<ParticleIndex>& points) const=0;
156
162 virtual float findNPoints(const float center[3],int nPoints,const float maxRadius,
163 std::vector<ParticleIndex>& points,std::vector<float>& pointDistancesSquared) const=0;
164
168 virtual int findNPoints(const float center[3],int nPoints,const float maxRadius,
169 ParticleIndex *points, float *pointDistancesSquared, float *finalRadius2) const=0;
170
172 virtual const_iterator setupConstIterator(const int index=0) const=0;
173
175 const_iterator begin() const
176 {return setupConstIterator();}
177
179 const_iterator end() const
180 {return const_iterator();}
181
182 private:
183 virtual void* dataInternal(const ParticleAttribute& attribute,const ParticleIndex particleIndex) const=0;
184 virtual void* fixedDataInternal(const FixedAttribute& attribute) const=0;
185 virtual void dataInternalMultiple(const ParticleAttribute& attribute,const int indexCount,
186 const ParticleIndex* particleIndices,const bool sorted,char* values) const=0;
187};
188
189// Particle Mutable Data Interface
191
195 class ParticlesDataMutable:public ParticlesData
196{
197 protected:
198 virtual ~ParticlesDataMutable(){}
199
200 public:
201
202 typedef ParticleIterator<false> iterator;
203
206 template<class T> inline T* dataWrite(const ParticleAttribute& attribute,
207 const ParticleIndex particleIndex) const
208 {
209 // TODO: add type checking
210 return static_cast<T*>(dataInternal(attribute,particleIndex));
211 }
212
215 template<class T> inline T* fixedDataWrite(const FixedAttribute& attribute) const
216 {
217 // TODO: add type checking
218 return static_cast<T*>(fixedDataInternal(attribute));
219 }
220
222 template<class T> inline void set(const ParticleAttribute& attribute,
223 const ParticleIndex particleIndex, const T* data) {
224 T* ptr = static_cast<T*>(dataInternal(attribute, particleIndex));
225 if (ptr) memcpy(ptr, data, attribute.count * TypeSize(attribute.type));
226 }
227
228 template<class T> inline void setFixed(const FixedAttribute& attribute, const T* data) {
229 T* ptr = static_cast<T*>(fixedDataInternal(attribute));
230 memcpy(ptr, data, attribute.count * TypeSize(attribute.type));
231 }
232
234 virtual int registerIndexedStr(const ParticleAttribute& attribute,const char* str)=0;
236 virtual int registerFixedIndexedStr(const FixedAttribute& attribute,const char* str)=0;
237
239 virtual void setIndexedStr(const ParticleAttribute& attribute,int indexedStringToken,const char* str)=0;
241 virtual void setFixedIndexedStr(const FixedAttribute& attribute,int indexedStringToken,const char* str)=0;
242
245 virtual void sort()=0;
246
248 virtual ParticleAttribute addAttribute(const char* attribute,ParticleAttributeType type,
249 const int count)=0;
250
252 virtual FixedAttribute addFixedAttribute(const char* attribute,ParticleAttributeType type,
253 const int count)=0;
254
256 virtual ParticleIndex addParticle()=0;
257
260 virtual iterator addParticles(const int count)=0;
261
263 iterator begin()
264 {return setupIterator();}
265
267 iterator end()
268 {return iterator();}
269
271 virtual iterator setupIterator(const int index=0)=0;
272
273 private:
274 virtual void* dataInternal(const ParticleAttribute& attribute,const ParticleIndex particleIndex) const=0;
275 virtual void* fixedDataInternal(const FixedAttribute& attribute) const=0;
276};
277
279 ParticlesDataMutable* create();
280
281 ParticlesDataMutable* createInterleave();
282
286 ParticlesDataMutable* cloneSchema(const ParticlesData&, const std::map<std::string, std::string>* attrNameMap = nullptr);
287
292 ParticlesDataMutable* clone(const ParticlesData&, bool particles=true, const std::map<std::string, std::string>* attrNameMap = nullptr);
293
296 ParticlesDataMutable* read(const char* filename,const bool verbose=true,std::ostream& errorStream=std::cerr);
297
300 ParticlesInfo* readHeaders(const char* filename,const bool verbose=true,std::ostream& errorStream=std::cerr);
301
304 void write(const char* filename,const ParticlesData&,const bool forceCompressed=false,bool verbose=true,std::ostream& errorStream=std::cerr);
305
307
313 ParticlesData* readCached(const char* filename,const bool sort,const bool verbose=true,std::ostream& errorStream=std::cerr);
314
316
321 void beginCachedAccess(ParticlesData* particles);
322
324
330 void endCachedAccess(ParticlesData* particles);
331
333 void print(const ParticlesData* particles);
334
335 ParticlesDataMutable* computeClustering(ParticlesDataMutable* particles, const int numNeighbors,const double radiusSearch,const double radiusInside,const int connections,const double density);
336
338
347 void merge(ParticlesDataMutable& base, const ParticlesData& delta, const std::string& identifier0=std::string(), const std::string& identifier1=std::string());
348
349}
350#endif
PartioAttribute.h
PartioIterator.h
Partio::FixedAttribute
Fixed Attribute Interface.
Definition PartioAttribute.h:124
Partio::ParticleAttribute
Particle Collection Interface.
Definition PartioAttribute.h:97
Partio::ParticleIterator
Definition PartioIterator.h:125
Partio::ParticlesDataMutable
Particle Mutable Data Interface.
Definition Partio.h:196
Partio::ParticlesDataMutable::addParticle
virtual ParticleIndex addParticle()=0
Add a particle to the particle set. Returns the offset to the particle.
Partio::ParticlesDataMutable::set
void set(const ParticleAttribute &attribute, const ParticleIndex particleIndex, const T *data)
Set particle value for attribute.
Definition Partio.h:222
Partio::ParticlesDataMutable::addFixedAttribute
virtual FixedAttribute addFixedAttribute(const char *attribute, ParticleAttributeType type, const int count)=0
Adds a fixed attribute with the provided name, type and count.
Partio::ParticlesDataMutable::setFixed
void setFixed(const FixedAttribute &attribute, const T *data)
Definition Partio.h:228
Partio::ParticlesDataMutable::setFixedIndexedStr
virtual void setFixedIndexedStr(const FixedAttribute &attribute, int indexedStringToken, const char *str)=0
Returns a token for the given string. This allows efficient storage of string data.
Partio::ParticlesDataMutable::addAttribute
virtual ParticleAttribute addAttribute(const char *attribute, ParticleAttributeType type, const int count)=0
Adds an attribute to the particle with the provided name, type and count.
Partio::ParticlesDataMutable::sort
virtual void sort()=0
Partio::ParticlesDataMutable::end
iterator end()
Produce a ending iterator for the particles.
Definition Partio.h:267
Partio::ParticlesDataMutable::iterator
ParticleIterator< false > iterator
Definition Partio.h:202
Partio::ParticlesDataMutable::registerFixedIndexedStr
virtual int registerFixedIndexedStr(const FixedAttribute &attribute, const char *str)=0
Returns a token for the given string. This allows efficient storage of string data.
Partio::ParticlesDataMutable::begin
iterator begin()
Produce a beginning iterator for the particles.
Definition Partio.h:263
Partio::ParticlesDataMutable::dataInternal
virtual void * dataInternal(const ParticleAttribute &attribute, const ParticleIndex particleIndex) const =0
Partio::ParticlesDataMutable::dataWrite
T * dataWrite(const ParticleAttribute &attribute, const ParticleIndex particleIndex) const
Definition Partio.h:206
Partio::ParticlesDataMutable::setupIterator
virtual iterator setupIterator(const int index=0)=0
Produce a const iterator.
Partio::ParticlesDataMutable::registerIndexedStr
virtual int registerIndexedStr(const ParticleAttribute &attribute, const char *str)=0
Returns a token for the given string. This allows efficient storage of string data.
Partio::ParticlesDataMutable::~ParticlesDataMutable
virtual ~ParticlesDataMutable()
Definition Partio.h:198
Partio::ParticlesDataMutable::fixedDataInternal
virtual void * fixedDataInternal(const FixedAttribute &attribute) const =0
Partio::ParticlesDataMutable::addParticles
virtual iterator addParticles(const int count)=0
Partio::ParticlesDataMutable::fixedDataWrite
T * fixedDataWrite(const FixedAttribute &attribute) const
Definition Partio.h:215
Partio::ParticlesDataMutable::setIndexedStr
virtual void setIndexedStr(const ParticleAttribute &attribute, int indexedStringToken, const char *str)=0
Returns a token for the given string. This allows efficient storage of string data.
Partio::ParticlesData
Particle Data Interface.
Definition Partio.h:103
Partio::ParticlesData::findPoints
virtual void findPoints(const float bboxMin[3], const float bboxMax[3], std::vector< ParticleIndex > &points) const =0
Partio::ParticlesData::fixedIndexedStrs
virtual const std::vector< std::string > & fixedIndexedStrs(const FixedAttribute &attr) const =0
All indexed strings for an attribute.
Partio::ParticlesData::indexedStrs
virtual const std::vector< std::string > & indexedStrs(const ParticleAttribute &attr) const =0
All indexed strings for an attribute.
Partio::ParticlesData::freeCached
friend void freeCached(ParticlesData *particles)
Partio::ParticlesData::setupConstIterator
virtual const_iterator setupConstIterator(const int index=0) const =0
Produce a const iterator.
Partio::ParticlesData::begin
const_iterator begin() const
Produce a beginning iterator for the particles.
Definition Partio.h:175
Partio::ParticlesData::end
const_iterator end() const
Produce a ending iterator for the particles.
Definition Partio.h:179
Partio::ParticlesData::const_iterator
ParticleIterator< true > const_iterator
Definition Partio.h:109
Partio::ParticlesData::data
const T * data(const ParticleAttribute &attribute, const ParticleIndex particleIndex) const
Definition Partio.h:121
Partio::ParticlesData::lookupFixedIndexedStr
virtual int lookupFixedIndexedStr(const FixedAttribute &attribute, const char *str) const =0
Looks up the index for a given string for a given attribute, returns -1 if not found.
Partio::ParticlesData::fixedDataInternal
virtual void * fixedDataInternal(const FixedAttribute &attribute) const =0
Partio::ParticlesData::~ParticlesData
virtual ~ParticlesData()
Definition Partio.h:105
Partio::ParticlesData::dataInternalMultiple
virtual void dataInternalMultiple(const ParticleAttribute &attribute, const int indexCount, const ParticleIndex *particleIndices, const bool sorted, char *values) const =0
Partio::ParticlesData::dataInternal
virtual void * dataInternal(const ParticleAttribute &attribute, const ParticleIndex particleIndex) const =0
Partio::ParticlesData::findNPoints
virtual float findNPoints(const float center[3], int nPoints, const float maxRadius, std::vector< ParticleIndex > &points, std::vector< float > &pointDistancesSquared) const =0
Partio::ParticlesData::lookupIndexedStr
virtual int lookupIndexedStr(const ParticleAttribute &attribute, const char *str) const =0
Looks up the index for a given string for a given attribute, returns -1 if not found.
Partio::ParticlesData::data
void data(const ParticleAttribute &attribute, const int indexCount, const ParticleIndex *particleIndices, const bool sorted, T *values)
Definition Partio.h:114
Partio::ParticlesData::dataAsFloat
virtual void dataAsFloat(const ParticleAttribute &attribute, const int indexCount, const ParticleIndex *particleIndices, const bool sorted, float *values) const =0
Partio::ParticlesData::fixedData
const T * fixedData(const FixedAttribute &attribute) const
Definition Partio.h:128
Partio::ParticlesData::findNPoints
virtual int findNPoints(const float center[3], int nPoints, const float maxRadius, ParticleIndex *points, float *pointDistancesSquared, float *finalRadius2) const =0
Partio::ParticlesInfo
Particle Collection Interface.
Definition Partio.h:67
Partio::ParticlesInfo::release
virtual void release()=0
Partio::ParticlesInfo::attributeInfo
virtual bool attributeInfo(const int index, ParticleAttribute &attribute) const =0
Lookup an attribute by index and store a handle to the attribute.
Partio::ParticlesInfo::attributeInfo
virtual bool attributeInfo(const char *attributeName, ParticleAttribute &attribute) const =0
Lookup an attribute by name and store a handle to the attribute.
Partio::ParticlesInfo::numAttributes
virtual int numAttributes() const =0
Number of per-particle attributes.
Partio::ParticlesInfo::fixedAttributeInfo
virtual bool fixedAttributeInfo(const int index, FixedAttribute &attribute) const =0
Lookup an attribute by index and store a handle to the attribute.
Partio::ParticlesInfo::~ParticlesInfo
virtual ~ParticlesInfo()
Definition Partio.h:69
Partio::ParticlesInfo::numFixedAttributes
virtual int numFixedAttributes() const =0
Number of fixed attributes.
Partio::ParticlesInfo::numParticles
virtual int numParticles() const =0
Number of particles in the structure.
Partio::ParticlesInfo::fixedAttributeInfo
virtual bool fixedAttributeInfo(const char *attributeName, FixedAttribute &attribute) const =0
Lookup an attribute by name and store a handle to the attribute.
Partio
Definition Partio.h:52
Partio::beginCachedAccess
void beginCachedAccess(ParticlesData *particles)
Begin accessing data in a cached file.
Partio::computeClustering
ParticlesDataMutable * computeClustering(ParticlesDataMutable *particles, const int numNeighbors, const double radiusSearch, const double radiusInside, const int connections, const double density)
Partio::typeCheck
bool typeCheck(const ParticleAttributeType &type)
Definition PartioAttribute.h:61
Partio::readHeaders
ParticlesInfo * readHeaders(const char *filename, const bool verbose=true, std::ostream &errorStream=std::cerr)
Partio::create
ParticlesDataMutable * create()
Provides an empty particle instance, freed with p->release()
Partio::ParticleIndex
uint64_t ParticleIndex
Opaque random access method to a single particle. No number is implied or guaranteed.
Definition Partio.h:55
Partio::clone
ParticlesDataMutable * clone(const ParticlesData &, bool particles=true, const std::map< std::string, std::string > *attrNameMap=nullptr)
Partio::TypeSize
int TypeSize(ParticleAttributeType attrType)
Definition PartioAttribute.h:75
Partio::merge
void merge(ParticlesDataMutable &base, const ParticlesData &delta, const std::string &identifier0=std::string(), const std::string &identifier1=std::string())
Merges one particle set into another.
Partio::ParticleAttributeType
ParticleAttributeType
Definition PartioAttribute.h:47
Partio::readCached
ParticlesData * readCached(const char *filename, const bool sort, const bool verbose=true, std::ostream &errorStream=std::cerr)
Cached (only one copy) read only way to read a particle file.
Partio::write
void write(const char *filename, const ParticlesData &, const bool forceCompressed=false, bool verbose=true, std::ostream &errorStream=std::cerr)
Partio::createInterleave
ParticlesDataMutable * createInterleave()
Partio::cloneSchema
ParticlesDataMutable * cloneSchema(const ParticlesData &, const std::map< std::string, std::string > *attrNameMap=nullptr)
Partio::print
void print(const ParticlesData *particles)
Prints a subset of particle data in a textual form.
Partio::endCachedAccess
void endCachedAccess(ParticlesData *particles)
End accessing data in a cached file.
Partio::read
ParticlesDataMutable * read(const char *filename, const bool verbose=true, std::ostream &errorStream=std::cerr)