| 113 | { |
| 114 | |
| 115 | struct Expander |
| 116 | { |
| 117 | |
| 118 | Expander( const std::vector<int> &indices ) : m_indices( indices ) |
| 119 | { |
| 120 | } |
| 121 | |
| 122 | template<typename T> |
| 123 | DataPtr operator()( const GeometricTypedData<std::vector<T>> *data ) const |
| 124 | { |
| 125 | typename GeometricTypedData<std::vector<T>>::Ptr result = expand( data ); |
| 126 | result->setInterpretation( data->getInterpretation() ); |
| 127 | return result; |
| 128 | } |
| 129 | |
| 130 | template<typename T> |
| 131 | DataPtr operator()( const TypedData<std::vector<T>> *data ) const |
| 132 | { |
| 133 | return expand( data ); |
| 134 | } |
| 135 | |
| 136 | DataPtr operator()( const Data *data ) const |
| 137 | { |
| 138 | throw IECore::InvalidArgumentException( "Can only expand VectorTypedData" ); |
| 139 | } |
| 140 | |
| 141 | private : |
| 142 | |
| 143 | template<typename DataType> |
| 144 | typename DataType::Ptr expand( const DataType *data ) const |
| 145 | { |
| 146 | const typename DataType::ValueType &compactValues = data->readable(); |
| 147 | |
| 148 | typename DataType::Ptr result = new DataType(); |
| 149 | typename DataType::ValueType &expandedValues = result->writable(); |
| 150 | expandedValues.reserve( m_indices.size() ); |
| 151 | for( const auto &index : m_indices ) |
| 152 | { |
| 153 | expandedValues.push_back( compactValues[index] ); |
| 154 | } |
| 155 | |
| 156 | return result; |
| 157 | } |
| 158 | |
| 159 | const std::vector<int> &m_indices; |
| 160 | |
| 161 | }; |
| 162 | |
| 163 | } // namespace |
| 164 | |