MCPcopy Create free account
hub / github.com/ImageEngine/cortex / doWrite

Method doWrite

src/IECoreScene/PDCParticleWriter.cpp:112–264  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112void 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 );

Callers

nothing calls this directly

Calls 15

IOExceptionFunction · 0.85
asBigEndianFunction · 0.85
typeIdMethod · 0.80
typeNameMethod · 0.80
objectParameterMethod · 0.80
setNumericValueMethod · 0.80
operateMethod · 0.80
writeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
findMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected