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

Method resamplePrimitiveVariable

src/IECoreScene/MeshAlgoResample.cpp:287–385  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285} // namespace
286
287void IECoreScene::MeshAlgo::resamplePrimitiveVariable( const MeshPrimitive *mesh, PrimitiveVariable& primitiveVariable, PrimitiveVariable::Interpolation interpolation, const Canceller *canceller )
288{
289 PrimitiveVariable::Interpolation srcInterpolation = primitiveVariable.interpolation;
290 if ( srcInterpolation == interpolation )
291 {
292 return;
293 }
294
295 DataPtr dstData = nullptr;
296 DataPtr srcData = nullptr;
297
298 if( primitiveVariable.indices )
299 {
300 if( srcInterpolation < interpolation )
301 {
302 // upsampling can be a resampling of indices
303 srcData = primitiveVariable.indices;
304 }
305 else
306 {
307 // downsampling forces index expansion to
308 // simplify the algorithms.
309 // \todo: allow indices to be maintained.
310 Canceller::check( canceller );
311 srcData = primitiveVariable.expandedData();
312 primitiveVariable.indices = nullptr;
313 }
314 }
315 else
316 {
317 // with no indices we can just resample the data
318 srcData = primitiveVariable.data;
319 }
320
321 // average array to single value
322 if ( interpolation == PrimitiveVariable::Constant )
323 {
324 IECoreScene::Detail::AverageValueFromVector fn;
325 dstData = dispatch( srcData.get(), fn );
326 primitiveVariable = PrimitiveVariable( interpolation, dstData );
327 return;
328 }
329
330 if ( primitiveVariable.interpolation == PrimitiveVariable::Constant )
331 {
332 IECoreScene::Detail::FillVectorFromValue fn( mesh->variableSize( interpolation ) );
333 DataPtr arrayData = dispatch( srcData.get(), fn );
334 if (arrayData)
335 {
336 primitiveVariable = PrimitiveVariable(interpolation, arrayData);
337 }
338 return;
339 }
340
341 if( interpolation == PrimitiveVariable::Uniform )
342 {
343 if( srcInterpolation == PrimitiveVariable::Varying || srcInterpolation == PrimitiveVariable::Vertex )
344 {

Calls 4

PrimitiveVariableFunction · 0.85
expandedDataMethod · 0.80
getMethod · 0.45
variableSizeMethod · 0.45