MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / writePDA

Function writePDA

extern/partio/src/lib/io/PDA.cpp:144–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

142}
143
144bool writePDA(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream)
145{
146 unique_ptr<ostream> output(
147 compressed ?
148 Gzip_Out(filename,ios::out|ios::binary)
149 :new ofstream(filename,ios::out|ios::binary));
150
151 *output<<"ATTRIBUTES"<<endl;
152
153 vector<ParticleAttribute> attrs;
154 for (int aIndex=0;aIndex<p.numAttributes();aIndex++){
155 attrs.push_back(ParticleAttribute());
156 p.attributeInfo(aIndex,attrs[aIndex]);
157 *output<<" "<<attrs[aIndex].name;
158 }
159 *output<<endl;
160
161 // TODO: assert right count
162 *output<<"TYPES"<<endl;
163 for (int aIndex=0;aIndex<p.numAttributes();aIndex++){
164 switch(attrs[aIndex].type){
165 case FLOAT: *output<<" R";break;
166 case VECTOR: *output<<" V";break;
167 case INDEXEDSTR:
168 case INT: *output<<" I";break;
169 case NONE: assert(false); break; // TODO: more graceful
170 }
171 }
172 *output<<endl;
173
174 *output<<"NUMBER_OF_PARTICLES: "<<p.numParticles()<<endl;
175 *output<<"BEGIN DATA"<<endl;
176
177 for(int particleIndex=0;particleIndex<p.numParticles();particleIndex++){
178 for(unsigned int attrIndex=0;attrIndex<attrs.size();attrIndex++){
179 if(attrs[attrIndex].type==Partio::INT || attrs[attrIndex].type==Partio::INDEXEDSTR){
180 const int* data=p.data<int>(attrs[attrIndex],particleIndex);
181 for(int count=0;count<attrs[attrIndex].count;count++)
182 *output<<data[count]<<" ";
183 }else if(attrs[attrIndex].type==Partio::FLOAT || attrs[attrIndex].type==Partio::VECTOR){
184 const float* data=p.data<float>(attrs[attrIndex],particleIndex);
185 for(int count=0;count<attrs[attrIndex].count;count++)
186 *output<<data[count]<<" ";
187 }
188 }
189 *output<<endl;
190 }
191 return true;
192
193}
194
195}

Callers

nothing calls this directly

Calls 5

Gzip_OutFunction · 0.85
ParticleAttributeClass · 0.85
numParticlesMethod · 0.80
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected