MCPcopy Create free account
hub / github.com/Kitware/VTK / extractRequiredFields

Function extractRequiredFields

Web/Python/vtkmodules/web/render_window_serializer.py:365–425  ·  view source on GitHub ↗
(
    extractedFields, parent, dataset, context, requestedFields=["Normals", "TCoords"]
)

Source from the content-addressed store, hash-verified

363
364
365def extractRequiredFields(
366 extractedFields, parent, dataset, context, requestedFields=["Normals", "TCoords"]
367):
368 arrays_to_export = set()
369 export_all = "*" in requestedFields
370 # Identify arrays to export
371 if not export_all:
372 # FIXME should evolve and support funky mapper which leverage many arrays
373 if parent and parent.IsA("vtkMapper"):
374 mapper = parent
375 scalarVisibility = mapper.GetScalarVisibility()
376 arrayAccessMode = mapper.GetArrayAccessMode()
377 colorArrayName = (
378 mapper.GetArrayName() if arrayAccessMode == 1 else mapper.GetArrayId()
379 )
380 # colorMode = mapper.GetColorMode()
381 scalarMode = mapper.GetScalarMode()
382 if scalarVisibility and scalarMode in (1, 3):
383 array_to_export = dataset.GetPointData().GetArray(colorArrayName)
384 if array_to_export is None:
385 array_to_export = dataset.GetPointData().GetScalars()
386 arrays_to_export.add(array_to_export)
387 if scalarVisibility and scalarMode in (2, 4):
388 array_to_export = dataset.GetCellData().GetArray(colorArrayName)
389 if array_to_export is None:
390 array_to_export = dataset.GetCellData().GetScalars()
391 arrays_to_export.add(array_to_export)
392 if scalarVisibility and scalarMode == 0:
393 array_to_export = dataset.GetPointData().GetScalars()
394 if array_to_export is None:
395 array_to_export = dataset.GetCellData().GetScalars()
396 arrays_to_export.add(array_to_export)
397
398 if parent and parent.IsA("vtkTexture") and dataset.GetPointData().GetScalars():
399 arrays_to_export.add(dataset.GetPointData().GetScalars())
400
401 arrays_to_export.update(
402 [
403 getattr(dataset.GetPointData(), "Get" + requestedField, lambda: None)()
404 for requestedField in requestedFields
405 ]
406 )
407
408 # Browse all arrays
409 for location, field_data in [
410 ("pointData", dataset.GetPointData()),
411 ("cellData", dataset.GetCellData()),
412 ]:
413 for array_index in range(field_data.GetNumberOfArrays()):
414 array = field_data.GetArray(array_index)
415 if export_all or array in arrays_to_export:
416 arrayMeta = getArrayDescription(array, context)
417 if arrayMeta:
418 arrayMeta["location"] = location
419 attribute = field_data.IsArrayAnAttribute(array_index)
420 arrayMeta["registration"] = (
421 "set" + field_data.GetAttributeTypeAsString(attribute)
422 if attribute >= 0

Callers 2

imagedataSerializerFunction · 0.85
polydataSerializerFunction · 0.85

Calls 15

getArrayDescriptionFunction · 0.85
IsAMethod · 0.80
GetArrayAccessModeMethod · 0.80
GetArrayIdMethod · 0.80
IsArrayAnAttributeMethod · 0.80
setFunction · 0.50
rangeClass · 0.50
GetArrayNameMethod · 0.45
GetArrayMethod · 0.45
GetPointDataMethod · 0.45
GetScalarsMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected