| 29 | vtkStandardNewMacro(vtkDGTransformResponder); |
| 30 | |
| 31 | bool vtkDGTransformResponder::Query( |
| 32 | vtkCellGridTransform::Query* request, vtkCellMetadata* cellType, vtkCellGridResponders* caches) |
| 33 | { |
| 34 | (void)cellType; |
| 35 | (void)caches; |
| 36 | |
| 37 | std::string cellTypeName = cellType->GetClassName(); |
| 38 | vtkStringToken cellTypeToken(cellTypeName); |
| 39 | auto* dgCell = vtkDGCell::SafeDownCast(cellType); |
| 40 | if (!dgCell) |
| 41 | { |
| 42 | vtkErrorMacro("Unsupported cell type \"" << cellTypeName << "\"."); |
| 43 | return false; |
| 44 | } |
| 45 | |
| 46 | auto* attribute = request->GetCellAttribute(); |
| 47 | if (!attribute) |
| 48 | { |
| 49 | attribute = cellType->GetCellGrid()->GetShapeAttribute(); |
| 50 | } |
| 51 | auto cellTypeInfo = attribute->GetCellTypeInfo(cellTypeToken); |
| 52 | |
| 53 | auto it = cellTypeInfo.ArraysByRole.find("values"); |
| 54 | if (it == cellTypeInfo.ArraysByRole.end() || !vtkDataArray::SafeDownCast(it->second)) |
| 55 | { |
| 56 | vtkErrorMacro("No array in \"values\" role or the array was not a vtkDataArray."); |
| 57 | return false; |
| 58 | } |
| 59 | auto* values = vtkDataArray::SafeDownCast(it->second); |
| 60 | int nc = values->GetNumberOfComponents(); |
| 61 | auto basisOp = dgCell->GetOperatorEntry("Basis"_token, cellTypeInfo); |
| 62 | bool dofSharing = cellTypeInfo.DOFSharing.IsValid(); |
| 63 | |
| 64 | // ncpb = number of components per basis function: |
| 65 | // nvpt = number of 3-d vectors per tuple: |
| 66 | int ncpb = (dofSharing ? nc : nc / basisOp.NumberOfFunctions); |
| 67 | int nvpt = (dofSharing ? nc / 3 : nc / 3); |
| 68 | // TODO: Handle nvpt == 9 as well to transform matrices. |
| 69 | if (ncpb != 3) |
| 70 | { |
| 71 | vtkErrorMacro("Values to be transformed must be 3-d vectors."); |
| 72 | return false; |
| 73 | } |
| 74 | bool ok = true; |
| 75 | |
| 76 | auto xfm = request->GetTransform(); |
| 77 | auto* transformedValues = request->CreateNewDataArray(values); |
| 78 | vtkIdType nt = values->GetNumberOfTuples(); |
| 79 | transformedValues->SetName(values->GetName()); |
| 80 | transformedValues->SetNumberOfComponents(values->GetNumberOfComponents()); |
| 81 | transformedValues->SetNumberOfTuples(values->GetNumberOfTuples()); |
| 82 | // Note that we keep values and transformedValues around at the same |
| 83 | // time in order to always apply transforms in the highest possible |
| 84 | // precision before writing to the transformedValues array. |
| 85 | // If you are reading this, DO NOT try to speed things up in a way that |
| 86 | // loses precision; always use TransformPoint(double*, double*). |
| 87 | if (dofSharing) |
| 88 | { |
nothing calls this directly
no test coverage detected