| 331 | } |
| 332 | |
| 333 | PointsPrimitivePtr mergePoints( const std::vector<const PointsPrimitive *> &pointsPrimitives, const Canceller *canceller /* = nullptr */ ) |
| 334 | { |
| 335 | size_t totalPointCount = 0; |
| 336 | typedef std::map<std::string, IECore::TypeId> FoundPrimvars; |
| 337 | FoundPrimvars foundPrimvars; |
| 338 | |
| 339 | PrimitiveVariableMap constantPrimVars; |
| 340 | |
| 341 | std::vector<PointsPrimitivePtr> validatedPointsPrimitives( pointsPrimitives.size() ); |
| 342 | |
| 343 | // find out which primvars can be merged |
| 344 | for( size_t i = 0; i < pointsPrimitives.size(); ++i ) |
| 345 | { |
| 346 | PointsPrimitivePtr pointsPrimitive = validatedPointsPrimitives[i] = pointsPrimitives[i]->copy(); |
| 347 | |
| 348 | totalPointCount += pointsPrimitive->getNumPoints(); |
| 349 | PrimitiveVariableMap &variables = pointsPrimitive->variables; |
| 350 | for( PrimitiveVariableMap::iterator it = variables.begin(); it != variables.end(); ++it ) |
| 351 | { |
| 352 | DataPtr data = it->second.data; |
| 353 | const IECore::TypeId typeId = data->typeId(); |
| 354 | PrimitiveVariable::Interpolation interpolation = it->second.interpolation; |
| 355 | const std::string &name = it->first; |
| 356 | |
| 357 | bool bExistingConstant = constantPrimVars.find( name ) != constantPrimVars.end(); |
| 358 | FoundPrimvars::const_iterator fIt = foundPrimvars.find( name ); |
| 359 | bool bExistingVertex = fIt != foundPrimvars.end(); |
| 360 | |
| 361 | if( interpolation == PrimitiveVariable::Constant ) |
| 362 | { |
| 363 | if( bExistingVertex ) |
| 364 | { |
| 365 | std::string msg = boost::str( boost::format( "PointsAlgo::mergePoints mismatching primvar %s" ) % name ); |
| 366 | throw InvalidArgumentException( msg ); |
| 367 | } |
| 368 | |
| 369 | if( !bExistingConstant ) |
| 370 | { |
| 371 | constantPrimVars[name] = it->second; |
| 372 | } |
| 373 | continue; |
| 374 | } |
| 375 | |
| 376 | if( interpolation == PrimitiveVariable::Vertex ) |
| 377 | { |
| 378 | |
| 379 | PrimitiveVariableMap::const_iterator constantPrimVarIt = constantPrimVars.find( name ); |
| 380 | if( constantPrimVarIt != constantPrimVars.end() ) |
| 381 | { |
| 382 | std::string msg = boost::str( boost::format( "PointsAlgo::mergePoints mismatching primvar %s" ) % name ); |
| 383 | throw InvalidArgumentException( msg ); |
| 384 | } |
| 385 | |
| 386 | if( !bExistingVertex ) |
| 387 | { |
| 388 | foundPrimvars[name] = typeId; |
| 389 | } |
| 390 | else |
no test coverage detected