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 "PartioAttribute.h"
49 #include "PartioIterator.h"
50 
51 namespace Partio{
52 
54 typedef uint64_t ParticleIndex;
55 
56 class ParticlesData;
57 // Particle Collection Interface
59 
65 {
66 protected:
67  virtual ~ParticlesInfo() {}
68 public:
69  friend void freeCached(ParticlesData* particles);
70 
74  virtual void release() const=0;
75 
77  virtual int numAttributes() const=0;
78 
80  virtual int numParticles() const=0;
81 
83  virtual bool attributeInfo(const char* attributeName,ParticleAttribute& attribute) const=0;
84 
86  virtual bool attributeInfo(const int attributeInfo,ParticleAttribute& attribute) const=0;
87 };
88 
89 // Particle Data Interface
91 
96 {
97 protected:
98  virtual ~ParticlesData() {}
99 public:
100 
102 
106  template<class T> inline void data(const ParticleAttribute& attribute,
107  const int indexCount,const ParticleIndex* particleIndices,const bool sorted,T* values)
108  {
109  assert(typeCheck<T>(attribute.type));
110  dataInternalMultiple(attribute,indexCount,particleIndices,sorted,(char*)values);
111  }
112 
113  template<class T> inline const T* data(const ParticleAttribute& attribute,
114  const ParticleIndex particleIndex) const
115  {
116  // TODO: add type checking
117  return static_cast<T*>(dataInternal(attribute,particleIndex));
118  }
119 
121  virtual const std::vector<std::string>& indexedStrs(const ParticleAttribute& attr) const=0;
122 
124  virtual int lookupIndexedStr(const ParticleAttribute& attribute,const char* str) const=0;
125 
130  virtual void dataAsFloat(const ParticleAttribute& attribute,const int indexCount,
131  const ParticleIndex* particleIndices,const bool sorted,float* values) const=0;
132 
136  virtual void findPoints(const float bboxMin[3],const float bboxMax[3],
137  std::vector<ParticleIndex>& points) const=0;
138 
144  virtual float findNPoints(const float center[3],int nPoints,const float maxRadius,
145  std::vector<ParticleIndex>& points,std::vector<float>& pointDistancesSquared) const=0;
146 
150  virtual int findNPoints(const float center[3],int nPoints,const float maxRadius,
151  ParticleIndex *points, float *pointDistancesSquared, float *finalRadius2) const=0;
152 
154  virtual const_iterator setupConstIterator() const=0;
155 
157  const_iterator begin() const
158  {return setupConstIterator();}
159 
161  const_iterator end() const
162  {return const_iterator();}
163 
164 private:
165  virtual void* dataInternal(const ParticleAttribute& attribute,const ParticleIndex particleIndex) const=0;
166  virtual void dataInternalMultiple(const ParticleAttribute& attribute,const int indexCount,
167  const ParticleIndex* particleIndices,const bool sorted,char* values) const=0;
168 };
169 
170 // Particle Mutable Data Interface
172 
177 {
178 protected:
180 
181 public:
182 
184 
187  template<class T> inline T* dataWrite(const ParticleAttribute& attribute,
188  const ParticleIndex particleIndex) const
189  {
190  // TODO: add type checking
191  return static_cast<T*>(dataInternal(attribute,particleIndex));
192  }
193 
195  virtual int registerIndexedStr(const ParticleAttribute& attribute,const char* str)=0;
196 
199  virtual void sort()=0;
200 
202  virtual ParticleAttribute addAttribute(const char* attribute,ParticleAttributeType type,
203  const int count)=0;
204 
206  virtual ParticleIndex addParticle()=0;
207 
210  virtual iterator addParticles(const int count)=0;
211 
213  iterator begin()
214  {return setupIterator();}
215 
217  iterator end()
218  {return iterator();}
219 
221  virtual iterator setupIterator()=0;
222 
223 private:
224  virtual void* dataInternal(const ParticleAttribute& attribute,const ParticleIndex particleIndex) const=0;
225 };
226 
228 ParticlesDataMutable* create();
229 
230 ParticlesDataMutable* createInterleave();
231 
234 ParticlesDataMutable* read(const char* filename);
235 
238 ParticlesInfo* readHeaders(const char* filename);
239 
242 void write(const char* filename,const ParticlesData&,const bool forceCompressed=false);
243 
244 
246 
252 ParticlesData* readCached(const char* filename,const bool sort);
253 
255 
260 void beginCachedAccess(ParticlesData* particles);
261 
263 
269 void endCachedAccess(ParticlesData* particles);
270 
272 void print(const ParticlesData* particles);
273 
274 }
275 #endif
virtual void release() const =0
ParticleIterator< true > const_iterator
Definition: Partio.h:101
virtual const std::vector< std::string > & indexedStrs(const ParticleAttribute &attr) const =0
All indexed strings for an attribute.
virtual int numParticles() const =0
Number of per-particle attributes.
virtual void * dataInternal(const ParticleAttribute &attribute, const ParticleIndex particleIndex) const =0
virtual int registerIndexedStr(const ParticleAttribute &attribute, const char *str)=0
Returns a token for the given string. This allows efficient storage of string data.
iterator begin()
Produce a beginning iterator for the particles.
Definition: Partio.h:213
ParticlesDataMutable * create()
Provides an empty particle instance, freed with p->release()
Particle Collection Interface.
Definition: Partio.h:64
ParticleIterator< false > iterator
Definition: Partio.h:183
void data(const ParticleAttribute &attribute, const int indexCount, const ParticleIndex *particleIndices, const bool sorted, T *values)
Definition: Partio.h:106
virtual iterator addParticles(const int count)=0
void write(const char *filename, const ParticlesData &, const bool forceCompressed=false)
Particle Data Interface.
Definition: Partio.h:95
virtual const_iterator setupConstIterator() const =0
Produce a const iterator.
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.
iterator end()
Produce a ending iterator for the particles.
Definition: Partio.h:217
Definition: PartioIterator.h:66
virtual void findPoints(const float bboxMin[3], const float bboxMax[3], std::vector< ParticleIndex > &points) const =0
virtual float findNPoints(const float center[3], int nPoints, const float maxRadius, std::vector< ParticleIndex > &points, std::vector< float > &pointDistancesSquared) const =0
uint64_t ParticleIndex
Opaque random access method to a single particle. No number is implied or guaranteed.
Definition: Partio.h:54
const T * data(const ParticleAttribute &attribute, const ParticleIndex particleIndex) const
Definition: Partio.h:113
void endCachedAccess(ParticlesData *particles)
End accessing data in a cached file.
const_iterator end() const
Produce a ending iterator for the particles.
Definition: Partio.h:161
virtual ~ParticlesDataMutable()
Definition: Partio.h:179
virtual void dataAsFloat(const ParticleAttribute &attribute, const int indexCount, const ParticleIndex *particleIndices, const bool sorted, float *values) const =0
friend void freeCached(ParticlesData *particles)
Particle Mutable Data Interface.
Definition: Partio.h:176
ParticlesDataMutable * read(const char *filename)
ParticlesDataMutable * createInterleave()
void beginCachedAccess(ParticlesData *particles)
Begin accessing data in a cached file.
virtual int numAttributes() const =0
Number of particles in the structure.
virtual ~ParticlesData()
Definition: Partio.h:98
virtual void * dataInternal(const ParticleAttribute &attribute, const ParticleIndex particleIndex) const =0
ParticlesData * readCached(const char *filename, const bool sort)
Cached (only one copy) read only way to read a particle file.
virtual iterator setupIterator()=0
Produce a const iterator.
const_iterator begin() const
Produce a beginning iterator for the particles.
Definition: Partio.h:157
virtual void dataInternalMultiple(const ParticleAttribute &attribute, const int indexCount, const ParticleIndex *particleIndices, const bool sorted, char *values) const =0
Particle Collection Interface.
Definition: PartioAttribute.h:96
Definition: Partio.h:51
virtual ParticleIndex addParticle()=0
Add a particle to the particle set. Returns the offset to the particle.
virtual ~ParticlesInfo()
Definition: Partio.h:67
T * dataWrite(const ParticleAttribute &attribute, const ParticleIndex particleIndex) const
Definition: Partio.h:187
ParticleAttributeType
Definition: PartioAttribute.h:47
virtual bool attributeInfo(const char *attributeName, ParticleAttribute &attribute) const =0
Lookup an attribute by name and store a handle to the attribute.
ParticlesInfo * readHeaders(const char *filename)
void print(const ParticlesData *particles)
Prints a subset of particle data in a textual form.
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.
ParticleAttributeType type
Type of attribute.
Definition: PartioAttribute.h:100