/*========================================================================= Program: Visualization Toolkit Module: vtkCPExodusIINodalCoordinatesTemplate.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 "vtkCPExodusIINodalCoordinatesTemplate.h" #include "vtkIdList.h" #include "vtkObjectFactory.h" #include "vtkVariant.h" #include "vtkVariantCast.h" //------------------------------------------------------------------------------ // Can't use vtkStandardNewMacro with a template. template vtkCPExodusIINodalCoordinatesTemplate* vtkCPExodusIINodalCoordinatesTemplate::New() { VTK_STANDARD_NEW_BODY(vtkCPExodusIINodalCoordinatesTemplate); } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::PrintSelf(ostream& os, vtkIndent indent) { this->vtkCPExodusIINodalCoordinatesTemplate::Superclass::PrintSelf(os, indent); os << indent << "XArray: " << this->XArray << std::endl; os << indent << "YArray: " << this->YArray << std::endl; os << indent << "ZArray: " << this->ZArray << std::endl; os << indent << "TempDoubleArray: " << this->TempDoubleArray << std::endl; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::Initialize() { delete[] this->XArray; this->XArray = nullptr; delete[] this->YArray; this->YArray = nullptr; delete[] this->ZArray; this->ZArray = nullptr; delete[] this->TempDoubleArray; this->TempDoubleArray = nullptr; this->MaxId = -1; this->Size = 0; this->NumberOfComponents = 1; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::GetTuples( vtkIdList* ptIds, vtkAbstractArray* output) { vtkDataArray* outArray = vtkDataArray::FastDownCast(output); if (!outArray) { vtkWarningMacro(<< "Input is not a vtkDataArray"); return; } vtkIdType numTuples = ptIds->GetNumberOfIds(); outArray->SetNumberOfComponents(this->NumberOfComponents); outArray->SetNumberOfTuples(numTuples); const vtkIdType numPoints = ptIds->GetNumberOfIds(); for (vtkIdType i = 0; i < numPoints; ++i) { outArray->SetTuple(i, this->GetTuple(ptIds->GetId(i))); } } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::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; } for (vtkIdType daTupleId = 0; p1 <= p2; ++p1) { da->SetTuple(daTupleId++, this->GetTuple(p1)); } } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::Squeeze() { // noop } //------------------------------------------------------------------------------ template vtkArrayIterator* vtkCPExodusIINodalCoordinatesTemplate::NewIterator() { vtkErrorMacro(<< "Not implemented."); return nullptr; } //------------------------------------------------------------------------------ template vtkIdType vtkCPExodusIINodalCoordinatesTemplate::LookupValue(vtkVariant value) { bool valid = true; Scalar val = vtkVariantCast(value, &valid); if (valid) { return this->Lookup(val, 0); } return -1; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::LookupValue(vtkVariant value, vtkIdList* ids) { bool valid = true; Scalar val = vtkVariantCast(value, &valid); ids->Reset(); if (valid) { vtkIdType index = 0; while ((index = this->Lookup(val, index)) >= 0) { ids->InsertNextId(index++); } } } //------------------------------------------------------------------------------ template vtkVariant vtkCPExodusIINodalCoordinatesTemplate::GetVariantValue(vtkIdType idx) { return vtkVariant(this->GetValueReference(idx)); } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::ClearLookup() { // no-op, no fast lookup implemented. } //------------------------------------------------------------------------------ template double* vtkCPExodusIINodalCoordinatesTemplate::GetTuple(vtkIdType i) { this->GetTuple(i, this->TempDoubleArray); return this->TempDoubleArray; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::GetTuple(vtkIdType i, double* tuple) { tuple[0] = static_cast(this->XArray[i]); tuple[1] = static_cast(this->YArray[i]); if (this->ZArray != nullptr) { tuple[2] = static_cast(this->ZArray[i]); } } //------------------------------------------------------------------------------ template vtkIdType vtkCPExodusIINodalCoordinatesTemplate::LookupTypedValue(Scalar value) { return this->Lookup(value, 0); } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::LookupTypedValue(Scalar value, vtkIdList* ids) { ids->Reset(); vtkIdType index = 0; while ((index = this->Lookup(value, index)) >= 0) { ids->InsertNextId(index++); } } //------------------------------------------------------------------------------ template typename vtkCPExodusIINodalCoordinatesTemplate::ValueType vtkCPExodusIINodalCoordinatesTemplate::GetValue(vtkIdType idx) const { return const_cast*>(this)->GetValueReference(idx); } //------------------------------------------------------------------------------ template typename vtkCPExodusIINodalCoordinatesTemplate::ValueType& vtkCPExodusIINodalCoordinatesTemplate::GetValueReference(vtkIdType idx) { const vtkIdType tuple = idx / this->NumberOfComponents; const vtkIdType comp = idx % this->NumberOfComponents; switch (comp) { case 0: return this->XArray[tuple]; case 1: return this->YArray[tuple]; case 2: return this->ZArray[tuple]; default: vtkErrorMacro(<< "Invalid number of components."); static Scalar dummy(0); return dummy; } } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::GetTypedTuple( vtkIdType tupleId, Scalar* tuple) const { tuple[0] = this->XArray[tupleId]; tuple[1] = this->YArray[tupleId]; if (this->ZArray != nullptr) { tuple[2] = this->ZArray[tupleId]; } } //------------------------------------------------------------------------------ template vtkTypeBool vtkCPExodusIINodalCoordinatesTemplate::Allocate(vtkIdType, vtkIdType) { vtkErrorMacro("Read only container."); return 0; } //------------------------------------------------------------------------------ template vtkTypeBool vtkCPExodusIINodalCoordinatesTemplate::Resize(vtkIdType) { vtkErrorMacro("Read only container."); return 0; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::SetNumberOfTuples(vtkIdType) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::SetTuple( vtkIdType, vtkIdType, vtkAbstractArray*) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::SetTuple(vtkIdType, const float*) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::SetTuple(vtkIdType, const double*) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::InsertTuple( vtkIdType, vtkIdType, vtkAbstractArray*) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::InsertTuple(vtkIdType, const float*) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::InsertTuple(vtkIdType, const double*) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::InsertTuples( vtkIdList*, vtkIdList*, vtkAbstractArray*) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::InsertTuples( vtkIdType, vtkIdType, vtkIdType, vtkAbstractArray*) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template vtkIdType vtkCPExodusIINodalCoordinatesTemplate::InsertNextTuple( vtkIdType, vtkAbstractArray*) { vtkErrorMacro("Read only container."); return -1; } //------------------------------------------------------------------------------ template vtkIdType vtkCPExodusIINodalCoordinatesTemplate::InsertNextTuple(const float*) { vtkErrorMacro("Read only container."); return -1; } //------------------------------------------------------------------------------ template vtkIdType vtkCPExodusIINodalCoordinatesTemplate::InsertNextTuple(const double*) { vtkErrorMacro("Read only container."); return -1; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::DeepCopy(vtkAbstractArray*) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::DeepCopy(vtkDataArray*) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::InterpolateTuple( vtkIdType, vtkIdList*, vtkAbstractArray*, double*) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::InterpolateTuple( vtkIdType, vtkIdType, vtkAbstractArray*, vtkIdType, vtkAbstractArray*, double) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::SetVariantValue(vtkIdType, vtkVariant) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::InsertVariantValue(vtkIdType, vtkVariant) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::RemoveTuple(vtkIdType) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::RemoveFirstTuple() { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::RemoveLastTuple() { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::SetTypedTuple(vtkIdType, const Scalar*) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::InsertTypedTuple(vtkIdType, const Scalar*) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template vtkIdType vtkCPExodusIINodalCoordinatesTemplate::InsertNextTypedTuple(const Scalar*) { vtkErrorMacro("Read only container."); return -1; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::SetValue(vtkIdType, Scalar) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template vtkIdType vtkCPExodusIINodalCoordinatesTemplate::InsertNextValue(Scalar) { vtkErrorMacro("Read only container."); return -1; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::InsertValue(vtkIdType, Scalar) { vtkErrorMacro("Read only container."); return; } //------------------------------------------------------------------------------ template vtkCPExodusIINodalCoordinatesTemplate::vtkCPExodusIINodalCoordinatesTemplate() : XArray(nullptr) , YArray(nullptr) , ZArray(nullptr) , TempDoubleArray(nullptr) { } //------------------------------------------------------------------------------ template vtkCPExodusIINodalCoordinatesTemplate::~vtkCPExodusIINodalCoordinatesTemplate() { delete[] this->XArray; delete[] this->YArray; delete[] this->ZArray; delete[] this->TempDoubleArray; } //------------------------------------------------------------------------------ template void vtkCPExodusIINodalCoordinatesTemplate::SetExodusScalarArrays( Scalar* x, Scalar* y, Scalar* z, vtkIdType numPoints) { Initialize(); this->XArray = x; this->YArray = y; this->ZArray = z; this->NumberOfComponents = (z != nullptr) ? 3 : 2; this->Size = this->NumberOfComponents * numPoints; this->MaxId = this->Size - 1; this->TempDoubleArray = new double[this->NumberOfComponents]; this->Modified(); } //------------------------------------------------------------------------------ template vtkIdType vtkCPExodusIINodalCoordinatesTemplate::Lookup(const Scalar& val, vtkIdType index) { while (index <= this->MaxId) { if (this->GetValueReference(index++) == val) { return index; } } return -1; }