Partio.h
Go to the documentation of this file.
/*
PARTIO SOFTWARE
Copyright 2010 Disney Enterprises, Inc. All rights reserved
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
* The names "Disney", "Walt Disney Pictures", "Walt Disney Animation
Studios" or the names of its contributors may NOT be used to
endorse or promote products derived from this software without
specific prior written permission from Walt Disney Pictures.
Disclaimer: THIS SOFTWARE IS PROVIDED BY WALT DISNEY PICTURES AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE, NONINFRINGEMENT AND TITLE ARE DISCLAIMED.
IN NO EVENT SHALL WALT DISNEY PICTURES, THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND BASED ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
*/
#ifndef _Partioh_
#define _Partioh_
#include <string>
#include <vector>
#include <map>
#include <stdint.h>
#include <string.h>
#include "PartioAttribute.h"
#include "PartioIterator.h"
namespace Partio{
typedef uint64_t ParticleIndex;
class ParticlesData;
class ParticlesDataMutable;
// Particle Collection Interface
class ParticlesInfo
{
protected:
virtual ~ParticlesInfo() {}
public:
virtual void release()=0;
virtual int numParticles() const=0;
virtual int numAttributes() const=0;
virtual int numFixedAttributes() const=0;
virtual bool attributeInfo(const char* attributeName,ParticleAttribute& attribute) const=0;
virtual bool fixedAttributeInfo(const char* attributeName,FixedAttribute& attribute) const=0;
virtual bool attributeInfo(const int index,ParticleAttribute& attribute) const=0;
virtual bool fixedAttributeInfo(const int index,FixedAttribute& attribute) const=0;
};
// Particle Data Interface
class ParticlesData:public ParticlesInfo
{
protected:
virtual ~ParticlesData() {}
public:
friend void freeCached(ParticlesData* particles);
typedef ParticleIterator<true> const_iterator;
template<class T> inline void data(const ParticleAttribute& attribute,
const int indexCount,const ParticleIndex* particleIndices,const bool sorted,T* values)
{
assert(typeCheck<T>(attribute.type));
dataInternalMultiple(attribute,indexCount,particleIndices,sorted,(char*)values);
}
template<class T> inline const T* data(const ParticleAttribute& attribute,
const ParticleIndex particleIndex) const
{
// TODO: add type checking
return static_cast<T*>(dataInternal(attribute,particleIndex));
}
template<class T> inline const T* fixedData(const FixedAttribute& attribute) const
{
// TODO: add type checking
return static_cast<T*>(fixedDataInternal(attribute));
}
virtual const std::vector<std::string>& indexedStrs(const ParticleAttribute& attr) const=0;
virtual const std::vector<std::string>& fixedIndexedStrs(const FixedAttribute& attr) const=0;
virtual int lookupIndexedStr(const ParticleAttribute& attribute,const char* str) const=0;
virtual int lookupFixedIndexedStr(const FixedAttribute& attribute,const char* str) const=0;
virtual void dataAsFloat(const ParticleAttribute& attribute,const int indexCount,
const ParticleIndex* particleIndices,const bool sorted,float* values) const=0;
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;
virtual int findNPoints(const float center[3],int nPoints,const float maxRadius,
ParticleIndex *points, float *pointDistancesSquared, float *finalRadius2) const=0;
virtual const_iterator setupConstIterator(const int index=0) const=0;
const_iterator begin() const
{return setupConstIterator();}
const_iterator end() const
{return const_iterator();}
private:
virtual void* dataInternal(const ParticleAttribute& attribute,const ParticleIndex particleIndex) const=0;
virtual void* fixedDataInternal(const FixedAttribute& attribute) const=0;
virtual void dataInternalMultiple(const ParticleAttribute& attribute,const int indexCount,
const ParticleIndex* particleIndices,const bool sorted,char* values) const=0;
};
// Particle Mutable Data Interface
class ParticlesDataMutable:public ParticlesData
{
protected:
virtual ~ParticlesDataMutable(){}
public:
typedef ParticleIterator<false> iterator;
template<class T> inline T* dataWrite(const ParticleAttribute& attribute,
const ParticleIndex particleIndex) const
{
// TODO: add type checking
return static_cast<T*>(dataInternal(attribute,particleIndex));
}
template<class T> inline T* fixedDataWrite(const FixedAttribute& attribute) const
{
// TODO: add type checking
return static_cast<T*>(fixedDataInternal(attribute));
}
template<class T> inline void set(const ParticleAttribute& attribute,
const ParticleIndex particleIndex, const T* data) {
T* ptr = static_cast<T*>(dataInternal(attribute, particleIndex));
if (ptr) memcpy(ptr, data, attribute.count * TypeSize(attribute.type));
}
template<class T> inline void setFixed(const FixedAttribute& attribute, const T* data) {
T* ptr = static_cast<T*>(fixedDataInternal(attribute));
memcpy(ptr, data, attribute.count * TypeSize(attribute.type));
}
virtual int registerIndexedStr(const ParticleAttribute& attribute,const char* str)=0;
virtual int registerFixedIndexedStr(const FixedAttribute& attribute,const char* str)=0;
virtual void setIndexedStr(const ParticleAttribute& attribute,int indexedStringToken,const char* str)=0;
virtual void setFixedIndexedStr(const FixedAttribute& attribute,int indexedStringToken,const char* str)=0;
virtual void sort()=0;
virtual ParticleAttribute addAttribute(const char* attribute,ParticleAttributeType type,
const int count)=0;
virtual FixedAttribute addFixedAttribute(const char* attribute,ParticleAttributeType type,
const int count)=0;
virtual ParticleIndex addParticle()=0;
virtual iterator addParticles(const int count)=0;
iterator begin()
{return setupIterator();}
iterator end()
{return iterator();}
virtual iterator setupIterator(const int index=0)=0;
private:
virtual void* dataInternal(const ParticleAttribute& attribute,const ParticleIndex particleIndex) const=0;
virtual void* fixedDataInternal(const FixedAttribute& attribute) const=0;
};
ParticlesDataMutable* create();
ParticlesDataMutable* createInterleave();
ParticlesDataMutable* cloneSchema(const ParticlesData&, const std::map<std::string, std::string>* attrNameMap = nullptr);
ParticlesDataMutable* clone(const ParticlesData&, bool particles=true, const std::map<std::string, std::string>* attrNameMap = nullptr);
ParticlesDataMutable* read(const char* filename,const bool verbose=true,std::ostream& errorStream=std::cerr);
ParticlesInfo* readHeaders(const char* filename,const bool verbose=true,std::ostream& errorStream=std::cerr);
void write(const char* filename,const ParticlesData&,const bool forceCompressed=false,bool verbose=true,std::ostream& errorStream=std::cerr);
ParticlesData* readCached(const char* filename,const bool sort,const bool verbose=true,std::ostream& errorStream=std::cerr);
void beginCachedAccess(ParticlesData* particles);
void endCachedAccess(ParticlesData* particles);
void print(const ParticlesData* particles);
ParticlesDataMutable* computeClustering(ParticlesDataMutable* particles, const int numNeighbors,const double radiusSearch,const double radiusInside,const int connections,const double density);
void merge(ParticlesDataMutable& base, const ParticlesData& delta, const std::string& identifier=std::string());
}
#endif
PartioAttribute.h
PartioIterator.h
Partio::FixedAttribute
Fixed Attribute Interface.
Definition: PartioAttribute.h:124
Partio::FixedAttribute::type
ParticleAttributeType type
Type of attribute.
Definition: PartioAttribute.h:127
Partio::FixedAttribute::count
int count
Number of entries, should be 3 if type is VECTOR.
Definition: PartioAttribute.h:130
Partio::ParticleAttribute
Particle Collection Interface.
Definition: PartioAttribute.h:97
Partio::ParticleAttribute::count
int count
Number of entries, should be 3 if type is VECTOR.
Definition: PartioAttribute.h:103
Partio::ParticleAttribute::type
ParticleAttributeType type
Type of attribute.
Definition: PartioAttribute.h:100
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::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::merge
void merge(ParticlesDataMutable &base, const ParticlesData &delta, const std::string &identifier=std::string())
Merges one particle set into another.
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::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)