| 110 | } |
| 111 | |
| 112 | void PDCParticleWriter::doWrite( const CompoundObject *operands ) |
| 113 | { |
| 114 | // write the header |
| 115 | int numParticles = particleCount(); |
| 116 | |
| 117 | ofstream oStream( fileName().c_str(), std::ios_base::binary | std::ios_base::out ); |
| 118 | if( !oStream.is_open() ) |
| 119 | { |
| 120 | throw IOException( ( format( "Unable to open file \"%s\"." ) % fileName() ).str() ); |
| 121 | } |
| 122 | |
| 123 | char pdc[4] = { 'P', 'D', 'C', ' ' }; |
| 124 | oStream.write( pdc, 4 ); |
| 125 | |
| 126 | int fileVersion = 1; fileVersion = asBigEndian( fileVersion ); |
| 127 | oStream.write( (const char *)&fileVersion, sizeof( fileVersion ) ); |
| 128 | |
| 129 | int one = 1; one = asBigEndian( one ); |
| 130 | oStream.write( (const char *)&one, sizeof( one ) ); |
| 131 | |
| 132 | int unused = 0; unused = asBigEndian( unused ); |
| 133 | oStream.write( (const char *)&unused, sizeof( unused ) ); |
| 134 | oStream.write( (const char *)&unused, sizeof( unused ) ); |
| 135 | |
| 136 | int numParticlesReversed = asBigEndian( numParticles ); |
| 137 | oStream.write( (const char *)&numParticlesReversed, sizeof( numParticlesReversed ) ); |
| 138 | |
| 139 | // check each attribute is of an appropriate type |
| 140 | const PrimitiveVariableMap &pv = particleObject()->variables; |
| 141 | vector<string> attrNames; |
| 142 | particleAttributes( attrNames ); |
| 143 | vector<string> checkedAttrNames; |
| 144 | for( vector<string>::const_iterator it = attrNames.begin(); it!=attrNames.end(); it++ ) |
| 145 | { |
| 146 | DataPtr attr = pv.find( *it )->second.data; |
| 147 | const IECore::TypeId t = attr->typeId(); |
| 148 | if( t==DoubleVectorDataTypeId || t==IntVectorDataTypeId || t==V3dVectorDataTypeId || |
| 149 | t==DoubleDataTypeId || t==IntDataTypeId || t==V3dDataTypeId || |
| 150 | t==FloatVectorDataTypeId || t==V3fVectorDataTypeId || t==FloatDataTypeId || t==V3fDataTypeId || |
| 151 | t==Color3fDataTypeId || t==Color3fVectorDataTypeId ) |
| 152 | { |
| 153 | checkedAttrNames.push_back( *it ); |
| 154 | } |
| 155 | else |
| 156 | { |
| 157 | msg( Msg::Warning, "PDCParticleWriter::write", format( "Attribute \"%s\" is of unsupported type \"%s\"." ) % *it % attr->typeName() ); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | // write out the attributes |
| 162 | DataCastOp castOp; |
| 163 | int numAttrs = checkedAttrNames.size(); |
| 164 | int numAttrsReversed = asBigEndian( numAttrs ); |
| 165 | oStream.write( (const char *)&numAttrsReversed, sizeof( numAttrsReversed ) ); |
| 166 | for( vector<string>::const_iterator it = checkedAttrNames.begin(); it!=checkedAttrNames.end(); it++ ) |
| 167 | { |
| 168 | int nameLength = it->size(); |
| 169 | int nameLengthReversed = asBigEndian( nameLength ); |
nothing calls this directly
no test coverage detected