/*============================================================================== Program: Visualization Toolkit Module: vtkMappedDataArray.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. ==============================================================================*/ #ifndef vtkMappedDataArray_txx #define vtkMappedDataArray_txx #include "vtkMappedDataArray.h" #include "vtkVariant.h" // for vtkVariant //------------------------------------------------------------------------------ template vtkMappedDataArray::vtkMappedDataArray() { this->TemporaryScalarPointer = nullptr; this->TemporaryScalarPointerSize = 0; } //------------------------------------------------------------------------------ template vtkMappedDataArray::~vtkMappedDataArray() { delete[] this->TemporaryScalarPointer; this->TemporaryScalarPointer = nullptr; this->TemporaryScalarPointerSize = 0; } //------------------------------------------------------------------------------ template void* vtkMappedDataArray::GetVoidPointer(vtkIdType id) { vtkWarningMacro(<< "GetVoidPointer called. This is very expensive for " "vtkMappedDataArray subclasses, since the scalar array must " "be generated for each call. Consider using " "a vtkTypedDataArrayIterator instead."); size_t numValues = this->NumberOfComponents * this->GetNumberOfTuples(); if (this->TemporaryScalarPointer && this->TemporaryScalarPointerSize != numValues) { delete[] this->TemporaryScalarPointer; this->TemporaryScalarPointer = nullptr; this->TemporaryScalarPointerSize = 0; } if (!this->TemporaryScalarPointer) { this->TemporaryScalarPointer = new Scalar[numValues]; this->TemporaryScalarPointerSize = numValues; } this->ExportToVoidPointer(static_cast(this->TemporaryScalarPointer)); return static_cast(this->TemporaryScalarPointer + id); } //------------------------------------------------------------------------------ template void vtkMappedDataArray::ExportToVoidPointer(void* voidPtr) { vtkTypedDataArrayIterator begin(this, 0); vtkTypedDataArrayIterator end = begin + (this->NumberOfComponents * this->GetNumberOfTuples()); Scalar* ptr = static_cast(voidPtr); while (begin != end) { *ptr = *begin; ++begin; ++ptr; } } //------------------------------------------------------------------------------ template void vtkMappedDataArray::SetVoidArray(void*, vtkIdType, int) { vtkErrorMacro(<< "SetVoidArray not supported for vtkMappedDataArray " "subclasses."); return; } //------------------------------------------------------------------------------ template void vtkMappedDataArray::SetVoidArray(void*, vtkIdType, int, int) { vtkErrorMacro(<< "SetVoidArray not supported for vtkMappedDataArray " "subclasses."); return; } //------------------------------------------------------------------------------ template void vtkMappedDataArray::DataChanged() { if (!this->TemporaryScalarPointer) { vtkWarningMacro(<< "DataChanged called, but no scalar pointer available."); return; } vtkTypedDataArrayIterator begin(this, 0); vtkTypedDataArrayIterator end = begin + this->TemporaryScalarPointerSize; Scalar* ptr = this->TemporaryScalarPointer; while (begin != end) { *begin = *ptr; ++begin; ++ptr; } this->Modified(); } //------------------------------------------------------------------------------ template inline vtkMappedDataArray* vtkMappedDataArray::FastDownCast( vtkAbstractArray* source) { if (source) { switch (source->GetArrayType()) { case vtkAbstractArray::MappedDataArray: if (vtkDataTypesCompare(source->GetDataType(), vtkTypeTraits::VTK_TYPE_ID)) { return static_cast*>(source); } default: break; } } return nullptr; } //------------------------------------------------------------------------------ template void vtkMappedDataArray::PrintSelf(ostream& os, vtkIndent indent) { this->Superclass::PrintSelf(os, indent); os << indent << "TemporaryScalarPointer: " << this->TemporaryScalarPointer << "\n"; os << indent << "TemporaryScalarPointerSize: " << this->TemporaryScalarPointerSize << "\n"; } //------------------------------------------------------------------------------ template void vtkMappedDataArray::Modified() { this->vtkTypedDataArray::Modified(); if (this->TemporaryScalarPointer == nullptr) { return; } delete[] this->TemporaryScalarPointer; this->TemporaryScalarPointer = nullptr; this->TemporaryScalarPointerSize = 0; } #endif // vtkMappedDataArray_txx