| 79 | } |
| 80 | |
| 81 | void ParticleWriter::particleAttributes( std::vector<std::string> &names ) |
| 82 | { |
| 83 | // find all attributes of the particle object with appropriate amounts of data |
| 84 | size_t numParticles = particleCount(); |
| 85 | vector<string> allNames; |
| 86 | ConstPointsPrimitivePtr cd = particleObject(); |
| 87 | for( PrimitiveVariableMap::const_iterator it=cd->variables.begin(); it!=cd->variables.end(); it++ ) |
| 88 | { |
| 89 | if ( testTypedData<TypeTraits::IsVectorTypedData>( it->second.data.get() ) ) |
| 90 | { |
| 91 | size_t s = despatchTypedData< TypedDataSize, TypeTraits::IsVectorTypedData >( it->second.data.get() ); |
| 92 | if( s==numParticles ) |
| 93 | { |
| 94 | allNames.push_back( it->first ); |
| 95 | } |
| 96 | else |
| 97 | { |
| 98 | msg( Msg::Warning, "ParticleWriter::particleAttributes", format( "Ignoring attribute \"%s\" due to insufficient elements (expected %d but found %d)." ) % it->first % numParticles % s ); |
| 99 | } |
| 100 | } |
| 101 | else if ( testTypedData<TypeTraits::IsSimpleTypedData>( it->second.data.get() ) ) |
| 102 | { |
| 103 | // it's not data of a vector type but it could be of a simple type |
| 104 | // in which case it's suitable for saving as a constant particle attribute |
| 105 | |
| 106 | despatchTypedData< TypedDataAddress, TypeTraits::IsSimpleTypedData >( it->second.data.get() ); |
| 107 | allNames.push_back( it->first ); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | const StringVectorData *d = static_cast<const StringVectorData *>( parameters()->parameter<StringVectorParameter>( "attributes" )->getValue() ); |
| 112 | if( !d->readable().size() ) |
| 113 | { |
| 114 | names = allNames; |
| 115 | return; |
| 116 | } |
| 117 | |
| 118 | names.clear(); |
| 119 | for( vector<string>::const_iterator it = d->readable().begin(); it!=d->readable().end(); it++ ) |
| 120 | { |
| 121 | if( find( allNames.begin(), allNames.end(), *it )!=allNames.end() ) |
| 122 | { |
| 123 | names.push_back( *it ); |
| 124 | } |
| 125 | else |
| 126 | { |
| 127 | msg( Msg::Warning, "ParticleWriter::particleAttributes", format( "Attribute \"%s\" requested via parameters but is not available." ) % *it ); |
| 128 | } |
| 129 | } |
| 130 | } |