Partio

PartioAttribute.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
42#ifndef _PartioParticleAttribute_h_
43#define _PartioParticleAttribute_h_
44 namespace Partio{
45
46// Particle Types
47 enum ParticleAttributeType {NONE=0,VECTOR=1,FLOAT=2,INT=3,INDEXEDSTR=4};
48
49 template<ParticleAttributeType ENUMTYPE> struct ETYPE_TO_TYPE
50{struct UNUSABLE;typedef UNUSABLE TYPE;};
51 template<> struct ETYPE_TO_TYPE<VECTOR>{typedef float TYPE;};
52 template<> struct ETYPE_TO_TYPE<FLOAT>{typedef float TYPE;};
53 template<> struct ETYPE_TO_TYPE<INT>{typedef int TYPE;};
54 template<> struct ETYPE_TO_TYPE<INDEXEDSTR>{typedef int TYPE;};
55
56 template<class T1,class T2> struct
57 IS_SAME{static const bool value=false;};
58 template<class T> struct IS_SAME<T,T>{static const bool value=true;};
59
60 template<class T> bool
61 typeCheck(const ParticleAttributeType& type)
62{
63 // if T is void, don't bother checking what we passed in
64 if (IS_SAME<T,void>::value) return true;
65 switch(type){
66 case VECTOR: return IS_SAME<typename ETYPE_TO_TYPE<VECTOR>::TYPE,T>::value;
67 case FLOAT: return IS_SAME<typename ETYPE_TO_TYPE<FLOAT>::TYPE,T>::value;
68 case INT: return IS_SAME<typename ETYPE_TO_TYPE<INT>::TYPE,T>::value;
69 case INDEXEDSTR: return IS_SAME<typename ETYPE_TO_TYPE<INDEXEDSTR>::TYPE,T>::value;
70 default: return false; // unknown type
71 }
72}
73
74 inline
75 int TypeSize(ParticleAttributeType attrType)
76{
77 switch(attrType){
78 case NONE: return 0;
79 case VECTOR: return sizeof(float);
80 case FLOAT: return sizeof(float);
81 case INT: return sizeof(int);
82 case INDEXEDSTR: return sizeof(int);
83 default: return 0;
84 }
85}
86
87std::string TypeName(ParticleAttributeType attrType);
88
89// Particle Attribute Specifier
91
96 class ParticleAttribute
97{
98 public:
100 ParticleAttributeType type{NONE};
101
103 int count{0};
104
106 std::string name;
107
109 int attributeIndex{-1};
110
113 // std::string comment;
114};
115
116// Fixed Attribute Specifier
118
123 class FixedAttribute
124{
125 public:
127 ParticleAttributeType type{NONE};
128
130 int count{0};
131
133 std::string name;
134
136 int attributeIndex{-1};
137
140 // std::string comment;
141};
142}
143#endif
Partio::FixedAttribute
Fixed Attribute Interface.
Definition PartioAttribute.h:124
Partio::FixedAttribute::type
ParticleAttributeType type
Type of attribute.
Definition PartioAttribute.h:127
Partio::FixedAttribute::name
std::string name
Name of attribute.
Definition PartioAttribute.h:133
Partio::FixedAttribute::attributeIndex
int attributeIndex
Internal method of fast access, user should not use or change.
Definition PartioAttribute.h:136
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::attributeIndex
int attributeIndex
Internal method of fast access, user should not use or change.
Definition PartioAttribute.h:109
Partio::ParticleAttribute::name
std::string name
Name of attribute.
Definition PartioAttribute.h:106
Partio::ParticleAttribute::type
ParticleAttributeType type
Type of attribute.
Definition PartioAttribute.h:100
Partio
Definition Partio.h:52
Partio::typeCheck
bool typeCheck(const ParticleAttributeType &type)
Definition PartioAttribute.h:61
Partio::TypeSize
int TypeSize(ParticleAttributeType attrType)
Definition PartioAttribute.h:75
Partio::ParticleAttributeType
ParticleAttributeType
Definition PartioAttribute.h:47
Partio::VECTOR
@ VECTOR
Definition PartioAttribute.h:47
Partio::INT
@ INT
Definition PartioAttribute.h:47
Partio::NONE
@ NONE
Definition PartioAttribute.h:47
Partio::FLOAT
@ FLOAT
Definition PartioAttribute.h:47
Partio::INDEXEDSTR
@ INDEXEDSTR
Definition PartioAttribute.h:47
Partio::TypeName
std::string TypeName(ParticleAttributeType attrType)
Partio::ETYPE_TO_TYPE< FLOAT >::TYPE
float TYPE
Definition PartioAttribute.h:52
Partio::ETYPE_TO_TYPE< INDEXEDSTR >::TYPE
int TYPE
Definition PartioAttribute.h:54
Partio::ETYPE_TO_TYPE< INT >::TYPE
int TYPE
Definition PartioAttribute.h:53
Partio::ETYPE_TO_TYPE< VECTOR >::TYPE
float TYPE
Definition PartioAttribute.h:51
Partio::ETYPE_TO_TYPE
Definition PartioAttribute.h:50
Partio::ETYPE_TO_TYPE::TYPE
UNUSABLE TYPE
Definition PartioAttribute.h:50
Partio::IS_SAME
Definition PartioAttribute.h:57
Partio::IS_SAME::value
static const bool value
Definition PartioAttribute.h:57