| 128 | } |
| 129 | |
| 130 | bool writePDC(const char* filename,const ParticlesData& p,const bool compressed,std::ostream* errorStream){ |
| 131 | unique_ptr<ostream> output( |
| 132 | compressed ? |
| 133 | Gzip_Out(filename,ios::out|ios::binary) |
| 134 | :new std::ofstream(filename,ios::out|ios::binary)); |
| 135 | |
| 136 | if(!*output){ |
| 137 | if(errorStream) *errorStream << "Partio Unable to open file " << filename << endl; |
| 138 | return false; |
| 139 | } |
| 140 | |
| 141 | // write .pdc header |
| 142 | write<LITEND>(*output, PDC_MAGIC); |
| 143 | write<BIGEND>(*output, (int)1); // version |
| 144 | write<BIGEND>(*output, (int)1); // bitorder |
| 145 | write<BIGEND>(*output, (int)0); // tmp1 |
| 146 | write<BIGEND>(*output, (int)0); // tmp2 |
| 147 | write<BIGEND>(*output, (int)p.numParticles()); |
| 148 | write<BIGEND>(*output, (int)p.numAttributes()); |
| 149 | |
| 150 | for(int attrIndex = 0; attrIndex < p.numAttributes(); attrIndex++){ |
| 151 | ParticleAttribute attr; |
| 152 | p.attributeInfo(attrIndex,attr); |
| 153 | |
| 154 | // write attribute name |
| 155 | write<BIGEND>(*output, (int)attr.name.length()); |
| 156 | output->write(attr.name.c_str(), (int)attr.name.length()); |
| 157 | |
| 158 | // write type |
| 159 | int count = 1; // FLOAT |
| 160 | if(attr.type == VECTOR){ |
| 161 | count = 3; |
| 162 | } |
| 163 | write<BIGEND>(*output, (int)(count+2)); |
| 164 | |
| 165 | // write data |
| 166 | for(int partIndex = 0; partIndex < p.numParticles(); partIndex++){ |
| 167 | const float* data = p.data<float>(attr, partIndex); |
| 168 | for(int dim = 0; dim < count; dim++){ |
| 169 | write<BIGEND>(*output, (double)data[dim]); |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | return true; |
| 174 | } |
| 175 | |
| 176 | }// end of namespace Partio |
nothing calls this directly
no test coverage detected