1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkCellAttribute.h"
#include "vtkAbstractArray.h"
#include "vtkObjectFactory.h"
#include <sstream>
VTK_ABI_NAMESPACE_BEGIN
vtkStandardNewMacro(vtkCellAttribute);
void vtkCellAttribute::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Name: " << this->GetName().Data() << "\n";
os << indent << "Id: " << this->Id << "\n";
os << indent << "Type: " << this->GetAttributeType().Data() << "\n";
os << indent << "Space: " << this->GetSpace().Data() << "\n";
os << indent << "NumberOfComponents: " << this->GetNumberOfComponents() << "\n";
os << indent << "Hash: " << this->GetHash() << "\n";
os << indent << "AllArrays: (" << this->AllArrays.size() << " cell types)\n";
vtkIndent i2 = indent.GetNextIndent();
vtkIndent i3 = i2.GetNextIndent();
for (const auto& arraysByCell : this->AllArrays)
{
os << i2 << arraysByCell.first.Data() << ":\n";
for (const auto& arrayEntry : arraysByCell.second)
{
os << i3 << arrayEntry.first.Data() << ": " << arrayEntry.second->GetName() << "\n";
}
}
}
bool vtkCellAttribute::Initialize(
vtkStringToken name, vtkStringToken attributeType, vtkStringToken space, int numberOfComponents)
{
if (this->Name == name && this->AttributeType == attributeType && this->Space == space &&
this->NumberOfComponents == numberOfComponents)
{
return false;
}
this->Name = name;
this->AttributeType = attributeType;
this->Space = space;
this->NumberOfComponents = numberOfComponents;
this->AllArrays.clear();
this->Modified();
return true;
}
vtkStringToken::Hash vtkCellAttribute::GetHash() const
{
std::ostringstream str;
str << this->GetNumberOfComponents() << "-" << this->GetName().Data() << "-"
<< this->GetAttributeType().Data() << "-" << this->GetSpace().Data();
vtkStringToken result(str.str());
return result.GetId();
}
vtkCellAttribute::ArraysForCellType vtkCellAttribute::GetArraysForCellType(
vtkStringToken cellType) const
{
auto it = this->AllArrays.find(cellType);
if (it == this->AllArrays.end())
{
return {};
}
return it->second;
}
bool vtkCellAttribute::SetArraysForCellType(
vtkStringToken cellType, const ArraysForCellType& arrays)
{
auto it = this->AllArrays.find(cellType);
if (it == this->AllArrays.end() || it->second != arrays)
{
this->AllArrays[cellType] = arrays;
this->Modified();
return true;
}
return false;
}
bool vtkCellAttribute::SetColormap(vtkScalarsToColors* colormap)
{
if (colormap == this->Colormap)
{
return false;
}
this->Colormap = colormap;
this->Modified();
return true;
}
void vtkCellAttribute::ShallowCopy(vtkCellAttribute* other)
{
if (!other)
{
return;
}
this->Name = other->Name;
this->AttributeType = other->AttributeType;
this->Space = other->Space;
this->NumberOfComponents = other->NumberOfComponents;
this->AllArrays = other->AllArrays;
// Do not copy other->Id! Identifiers must be unique across attributes.
this->Colormap = other->Colormap;
}
void vtkCellAttribute::DeepCopy(
vtkCellAttribute* other, const std::map<vtkAbstractArray*, vtkAbstractArray*>& arrayRewrites)
{
if (!other)
{
return;
}
this->Name = other->Name;
this->AttributeType = other->AttributeType;
this->Space = other->Space;
this->NumberOfComponents = other->NumberOfComponents;
// Copy arrays, then rewrite pointers as directed.
this->AllArrays = other->AllArrays;
if (!arrayRewrites.empty())
{
for (auto& entry : this->AllArrays)
{
for (auto& subentry : entry.second)
{
auto it = arrayRewrites.find(subentry.second.GetPointer());
if (it != arrayRewrites.end())
{
subentry.second = it->second;
}
}
}
}
// Do not copy other->Id! Identifiers must be unique across attributes.
// Clone any colormap
if (other->Colormap)
{
this->Colormap = vtkScalarsToColors::SafeDownCast(
vtkObjectFactory::CreateInstance(other->Colormap->GetClassName()));
if (this->Colormap)
{
this->Colormap->DeepCopy(other->Colormap);
}
else
{
vtkErrorMacro("Could not clone the attribute's colormap.");
}
}
else
{
this->Colormap = nullptr;
}
}
VTK_ABI_NAMESPACE_END
|