| 142 | } |
| 143 | |
| 144 | bool 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 | } |
nothing calls this directly
no test coverage detected