/*========================================================================= Program: Visualization Toolkit Module: vtkPeriodicDataArray.txx Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen All rights reserved. See Copyright.txt or http://www.kitware.com/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notice for more information. =========================================================================*/ #include "vtkArrayIteratorTemplate.h" #include "vtkIdList.h" #include "vtkVariant.h" //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::PrintSelf(ostream& os, vtkIndent indent) { this->vtkPeriodicDataArray::Superclass::PrintSelf(os, indent); os << indent << "TempScalarArray: " << this->TempScalarArray << "\n"; os << indent << "TempDoubleArray: " << this->TempDoubleArray << "\n"; } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::Initialize() { delete[] this->TempScalarArray; this->TempScalarArray = nullptr; delete[] this->TempDoubleArray; this->TempDoubleArray = nullptr; this->TempTupleIdx = -1; if (this->Data) { this->Data->Delete(); this->Data = nullptr; } this->MaxId = -1; this->Size = 0; this->InvalidRange = true; this->Normalize = false; this->Modified(); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::InitializeArray(vtkAOSDataArrayTemplate* data) { this->Initialize(); if (!data) { vtkErrorMacro(<< "No original data provided."); return; } this->NumberOfComponents = data->GetNumberOfComponents(); this->Size = data->GetSize(); this->MaxId = data->GetMaxId(); this->Data = data; this->Data->Register(nullptr); this->TempScalarArray = new Scalar[this->NumberOfComponents]; this->TempDoubleArray = new double[this->NumberOfComponents]; this->SetName(data->GetName()); this->InvalidRange = true; this->Modified(); } //------------------------------------------------------------------------------ template bool vtkPeriodicDataArray::ComputeScalarRange(double* range) { if (this->NumberOfComponents == 3) { if (this->InvalidRange) { this->ComputePeriodicRange(); } for (int i = 0; i < 3; i++) { range[i * 2] = this->PeriodicRange[i * 2 + 0]; range[i * 2 + 1] = this->PeriodicRange[i * 2 + 1]; } } else { // Not implemented for tensor for (int i = 0; i < this->NumberOfComponents; i++) { range[i * 2] = 0; range[i * 2 + 1] = 1; } } return true; } //------------------------------------------------------------------------------ template bool vtkPeriodicDataArray::ComputeVectorRange(double range[2]) { if (this->NumberOfComponents == 3 && this->Data) { this->Data->GetRange(range, -1); } else { // Not implemented for tensor range[0] = 0; range[1] = 1; } return true; } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::ComputePeriodicRange() { if (this->Data) { this->Data->GetRange(this->PeriodicRange, 0); this->Data->GetRange(this->PeriodicRange + 2, 1); this->Data->GetRange(this->PeriodicRange + 4, 2); Scalar boxPoints[8][3]; boxPoints[0][0] = this->PeriodicRange[0]; boxPoints[0][1] = this->PeriodicRange[2]; boxPoints[0][2] = this->PeriodicRange[4]; boxPoints[1][0] = this->PeriodicRange[0]; boxPoints[1][1] = this->PeriodicRange[3]; boxPoints[1][2] = this->PeriodicRange[4]; boxPoints[2][0] = this->PeriodicRange[1]; boxPoints[2][1] = this->PeriodicRange[3]; boxPoints[2][2] = this->PeriodicRange[4]; boxPoints[3][0] = this->PeriodicRange[1]; boxPoints[3][1] = this->PeriodicRange[2]; boxPoints[3][2] = this->PeriodicRange[4]; boxPoints[4][0] = this->PeriodicRange[0]; boxPoints[4][1] = this->PeriodicRange[2]; boxPoints[4][2] = this->PeriodicRange[5]; boxPoints[5][0] = this->PeriodicRange[0]; boxPoints[5][1] = this->PeriodicRange[3]; boxPoints[5][2] = this->PeriodicRange[5]; boxPoints[6][0] = this->PeriodicRange[1]; boxPoints[6][1] = this->PeriodicRange[3]; boxPoints[6][2] = this->PeriodicRange[5]; boxPoints[7][0] = this->PeriodicRange[1]; boxPoints[7][1] = this->PeriodicRange[2]; boxPoints[7][2] = this->PeriodicRange[5]; for (int i = 0; i < 8; i++) { this->Transform(boxPoints[i]); } this->PeriodicRange[0] = this->PeriodicRange[2] = this->PeriodicRange[4] = VTK_DOUBLE_MAX; this->PeriodicRange[1] = this->PeriodicRange[3] = this->PeriodicRange[5] = -VTK_DOUBLE_MAX; for (int i = 0; i < 8; i++) { for (int j = 0; j < 3; j++) { if (boxPoints[i][j] < this->PeriodicRange[2 * j]) { this->PeriodicRange[2 * j] = boxPoints[i][j]; } if (boxPoints[i][j] > this->PeriodicRange[2 * j + 1]) { this->PeriodicRange[2 * j + 1] = boxPoints[i][j]; } } } this->InvalidRange = false; } } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::GetTuples(vtkIdList* ptIds, vtkAbstractArray* output) { vtkDataArray* da = vtkDataArray::FastDownCast(output); if (!da) { vtkWarningMacro(<< "Input is not a vtkDataArray"); return; } if (da->GetNumberOfComponents() != this->GetNumberOfComponents()) { vtkWarningMacro(<< "Incorrect number of components in input array."); return; } const vtkIdType numPoints = ptIds->GetNumberOfIds(); double* tempData = new double[this->NumberOfComponents]; for (vtkIdType i = 0; i < numPoints; ++i) { this->GetTuple(ptIds->GetId(i), tempData); da->SetTuple(i, tempData); } delete[] tempData; } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::GetTuples(vtkIdType p1, vtkIdType p2, vtkAbstractArray* output) { vtkDataArray* da = vtkDataArray::FastDownCast(output); if (!da) { vtkErrorMacro(<< "Input is not a vtkDataArray"); return; } if (da->GetNumberOfComponents() != this->GetNumberOfComponents()) { vtkErrorMacro(<< "Incorrect number of components in input array."); return; } double* tempData = new double[this->NumberOfComponents]; for (vtkIdType daTupleId = 0; p1 <= p2; ++p1) { this->GetTuple(p1, tempData); da->SetTuple(daTupleId++, tempData); } delete[] tempData; } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::Squeeze() { } //------------------------------------------------------------------------------ template vtkArrayIterator* vtkPeriodicDataArray::NewIterator() { vtkArrayIteratorTemplate* iter = vtkArrayIteratorTemplate::New(); iter->Initialize(this); return iter; } //------------------------------------------------------------------------------ template vtkIdType vtkPeriodicDataArray::LookupValue(vtkVariant) { vtkErrorMacro("Lookup not implemented in this container."); return -1; } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::LookupValue(vtkVariant, vtkIdList*) { vtkErrorMacro("Lookup not implemented in this container."); } //------------------------------------------------------------------------------ template vtkVariant vtkPeriodicDataArray::GetVariantValue(vtkIdType idx) { return vtkVariant(this->GetValueReference(idx)); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::ClearLookup() { vtkErrorMacro("Lookup not implemented in this container."); } //------------------------------------------------------------------------------ template double* vtkPeriodicDataArray::GetTuple(vtkIdType i) { if (this->TempTupleIdx != i) { this->GetTypedTuple(i, this->TempScalarArray); this->TempTupleIdx = i; } for (int j = 0; j < this->NumberOfComponents; j++) { this->TempDoubleArray[j] = static_cast(this->TempScalarArray[j]); } return this->TempDoubleArray; } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::GetTuple(vtkIdType i, double* tuple) { if (this->TempTupleIdx != i) { this->GetTypedTuple(i, this->TempScalarArray); this->TempTupleIdx = i; } for (int j = 0; j < this->NumberOfComponents; j++) { tuple[j] = static_cast(this->TempScalarArray[j]); } } //------------------------------------------------------------------------------ template vtkIdType vtkPeriodicDataArray::LookupTypedValue(Scalar) { vtkErrorMacro("Lookup not implemented in this container."); return 0; } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::LookupTypedValue(Scalar, vtkIdList*) { vtkErrorMacro("Lookup not implemented in this container."); } //------------------------------------------------------------------------------ template typename vtkPeriodicDataArray::ValueType vtkPeriodicDataArray::GetValue( vtkIdType idx) const { return const_cast*>(this)->GetValueReference(idx); } //------------------------------------------------------------------------------ template typename vtkPeriodicDataArray::ValueType& vtkPeriodicDataArray::GetValueReference( vtkIdType idx) { vtkIdType tupleIdx = idx / this->NumberOfComponents; if (tupleIdx != this->TempTupleIdx) { this->GetTypedTuple(tupleIdx, this->TempScalarArray); this->TempTupleIdx = tupleIdx; } return this->TempScalarArray[idx % this->NumberOfComponents]; } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::GetTypedTuple(vtkIdType tupleId, Scalar* tuple) const { this->Data->GetTypedTuple(tupleId, tuple); this->Transform(tuple); } //------------------------------------------------------------------------------ template typename vtkPeriodicDataArray::ValueType vtkPeriodicDataArray::GetTypedComponent( vtkIdType tupleId, int compId) const { if (tupleId != this->TempTupleIdx) { this->Data->GetTypedTuple(tupleId, this->TempScalarArray); this->Transform(const_cast(this->TempScalarArray)); *const_cast(&this->TempTupleIdx) = tupleId; } return this->TempScalarArray[compId]; } //------------------------------------------------------------------------------ template unsigned long int vtkPeriodicDataArray::GetActualMemorySize() const { return static_cast( (this->NumberOfComponents * (sizeof(Scalar) + sizeof(double)) + sizeof(*this)) / 1024); } //------------------------------------------------------------------------------ template vtkTypeBool vtkPeriodicDataArray::Allocate(vtkIdType, vtkIdType) { vtkErrorMacro("Read only container."); return 0; } //------------------------------------------------------------------------------ template vtkTypeBool vtkPeriodicDataArray::Resize(vtkIdType) { vtkErrorMacro("Read only container."); return 0; } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::SetNumberOfTuples(vtkIdType) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::SetTuple(vtkIdType, vtkIdType, vtkAbstractArray*) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::SetTuple(vtkIdType, const float*) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::SetTuple(vtkIdType, const double*) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::InsertTuple(vtkIdType, vtkIdType, vtkAbstractArray*) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::InsertTuple(vtkIdType, const float*) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::InsertTuple(vtkIdType, const double*) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::InsertTuples(vtkIdList*, vtkIdList*, vtkAbstractArray*) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::InsertTuples(vtkIdType, vtkIdType, vtkIdType, vtkAbstractArray*) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template vtkIdType vtkPeriodicDataArray::InsertNextTuple(vtkIdType, vtkAbstractArray*) { vtkErrorMacro("Read only container."); return -1; } //------------------------------------------------------------------------------ template vtkIdType vtkPeriodicDataArray::InsertNextTuple(const float*) { vtkErrorMacro("Read only container."); return -1; } //------------------------------------------------------------------------------ template vtkIdType vtkPeriodicDataArray::InsertNextTuple(const double*) { vtkErrorMacro("Read only container."); return -1; } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::DeepCopy(vtkAbstractArray*) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::DeepCopy(vtkDataArray*) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::InterpolateTuple( vtkIdType, vtkIdList*, vtkAbstractArray*, double*) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::InterpolateTuple( vtkIdType, vtkIdType, vtkAbstractArray*, vtkIdType, vtkAbstractArray*, double) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::SetVariantValue(vtkIdType, vtkVariant) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::InsertVariantValue(vtkIdType, vtkVariant) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::RemoveTuple(vtkIdType) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::RemoveFirstTuple() { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::RemoveLastTuple() { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::SetTypedTuple(vtkIdType, const Scalar*) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::SetTypedComponent(vtkIdType, int, Scalar) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::InsertTypedTuple(vtkIdType, const Scalar*) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template vtkIdType vtkPeriodicDataArray::InsertNextTypedTuple(const Scalar*) { vtkErrorMacro("Read only container."); return -1; } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::SetValue(vtkIdType, Scalar) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template vtkIdType vtkPeriodicDataArray::InsertNextValue(Scalar) { vtkErrorMacro("Read only container."); return -1; } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::InsertValue(vtkIdType, Scalar) { vtkErrorMacro("Read only container."); } //------------------------------------------------------------------------------ template bool vtkPeriodicDataArray::AllocateTuples(vtkIdType) { vtkErrorMacro("Read only container."); return false; } //------------------------------------------------------------------------------ template bool vtkPeriodicDataArray::ReallocateTuples(vtkIdType) { vtkErrorMacro("Read only container."); return false; } //------------------------------------------------------------------------------ template void vtkPeriodicDataArray::InvalidateRange() { this->InvalidRange = true; } //------------------------------------------------------------------------------ template vtkPeriodicDataArray::vtkPeriodicDataArray() { this->NumberOfComponents = 0; this->TempScalarArray = nullptr; this->TempDoubleArray = nullptr; this->TempTupleIdx = -1; this->Data = nullptr; this->MaxId = -1; this->Size = 0; this->InvalidRange = true; this->Normalize = false; this->PeriodicRange[0] = this->PeriodicRange[2] = this->PeriodicRange[4] = VTK_DOUBLE_MAX; this->PeriodicRange[1] = this->PeriodicRange[3] = this->PeriodicRange[5] = -VTK_DOUBLE_MAX; } //------------------------------------------------------------------------------ template vtkPeriodicDataArray::~vtkPeriodicDataArray() { this->Initialize(); }