10 #include "vtkDoubleArray.h"
11 #include "vtkLookupTable.h"
13 #include "vtkObjectFactory.h"
14 #include "vtkStringArray.h"
15 #include "vtkVariantArray.h"
22 this->AnnotatedValuesInFullSet =
NULL;
23 this->AnnotationsInFullSet =
NULL;
24 this->IndexedColorsInFullSet = vtkDoubleArray::New();
25 this->IndexedColorsInFullSet->SetNumberOfComponents(3);
26 this->IndexedOpacitiesInFullSet = vtkDoubleArray::New();
27 this->IndexedOpacitiesInFullSet->SetNumberOfComponents(1);
29 this->ActiveAnnotatedValues = vtkVariantArray::New();
31 this->UseActiveValues = 1;
37 if (this->AnnotatedValuesInFullSet) {
38 this->AnnotatedValuesInFullSet->Delete();
41 if (this->AnnotationsInFullSet) {
42 this->AnnotationsInFullSet->Delete();
45 if (this->IndexedOpacitiesInFullSet) {
46 this->IndexedOpacitiesInFullSet->Delete();
49 if (this->IndexedColorsInFullSet) {
50 this->IndexedColorsInFullSet->Delete();
53 if (this->ActiveAnnotatedValues) {
54 this->ActiveAnnotatedValues->Delete();
60 vtkAbstractArray* values, vtkStringArray* annotations) {
61 if ((values && !annotations) || (!values && annotations))
return;
63 if (values && annotations &&
64 values->GetNumberOfTuples() != annotations->GetNumberOfTuples()) {
65 vtkErrorMacro(<<
"Values and annotations do not have the same number "
67 << values->GetNumberOfTuples() <<
" and "
68 << annotations->GetNumberOfTuples()
69 <<
", respectively. Ignoring.");
73 if (this->AnnotatedValuesInFullSet && !values) {
74 this->AnnotatedValuesInFullSet->Delete();
75 this->AnnotatedValuesInFullSet = 0;
77 if (this->AnnotatedValuesInFullSet) {
78 if (this->AnnotatedValuesInFullSet->GetDataType() !=
79 values->GetDataType()) {
80 this->AnnotatedValuesInFullSet->Delete();
81 this->AnnotatedValuesInFullSet = 0;
84 if (!this->AnnotatedValuesInFullSet) {
85 this->AnnotatedValuesInFullSet =
86 vtkAbstractArray::CreateArray(values->GetDataType());
89 bool sameVals = (values == this->AnnotatedValuesInFullSet);
90 if (!sameVals && values) {
91 this->AnnotatedValuesInFullSet->DeepCopy(values);
94 if (this->AnnotationsInFullSet && !annotations) {
95 this->AnnotationsInFullSet->Delete();
96 this->AnnotationsInFullSet = 0;
97 }
else if (!this->AnnotationsInFullSet && annotations) {
98 this->AnnotationsInFullSet = vtkStringArray::New();
100 bool sameText = (annotations == this->AnnotationsInFullSet);
102 this->AnnotationsInFullSet->DeepCopy(annotations);
110 vtkVariant value, std::string annotation) {
112 bool modified =
false;
113 if (this->AnnotatedValuesInFullSet) {
114 idx = this->AnnotatedValuesInFullSet->LookupValue(value);
116 if (this->AnnotationsInFullSet->GetValue(idx) != annotation) {
117 this->AnnotationsInFullSet->SetValue(idx, annotation);
121 idx = this->AnnotationsInFullSet->InsertNextValue(annotation);
122 this->AnnotatedValuesInFullSet->InsertVariantValue(idx, value);
126 vtkErrorMacro(<<
"AnnotatedValuesInFullSet is NULL");
138 std::string value, std::string annotation) {
140 vtkVariant val(value);
142 x = val.ToDouble(&valid);
145 }
else if (value ==
"") {
155 if (!this->AnnotationsInFullSet) {
156 vtkVariantArray* va = vtkVariantArray::New();
157 vtkStringArray* sa = vtkStringArray::New();
162 this->AnnotatedValuesInFullSet->Initialize();
163 this->AnnotationsInFullSet->Initialize();
169 if (this->ActiveAnnotatedValues->GetNumberOfTuples() > 0) {
170 this->ActiveAnnotatedValues->Initialize();
178 this->ActiveAnnotatedValues->InsertNextValue(value.c_str());
186 static_cast<int>(this->IndexedColorsInFullSet->GetNumberOfTuples())) {
187 vtkIdType old = this->IndexedColorsInFullSet->GetNumberOfTuples();
188 this->IndexedColorsInFullSet->SetNumberOfTuples(n);
190 for (
int i = 0; i < 3; i++) {
191 this->IndexedColorsInFullSet->FillComponent(i, 0.0);
200 unsigned int index,
double r,
double g,
double b) {
201 if (index >=
static_cast<unsigned int>(
202 this->IndexedColorsInFullSet->GetNumberOfTuples())) {
209 double currentRGB[3];
210 this->IndexedColorsInFullSet->GetTypedTuple(index, currentRGB);
211 if (currentRGB[0] != r || currentRGB[1] != g || currentRGB[2] != b) {
212 double rgb[3] = {r, g, b};
213 this->IndexedColorsInFullSet->SetTypedTuple(index,
rgb);
221 return static_cast<int>(this->IndexedColorsInFullSet->GetNumberOfTuples());
226 unsigned int index,
double*
rgb) {
227 if (index >=
static_cast<unsigned int>(
228 this->IndexedColorsInFullSet->GetNumberOfTuples())) {
229 vtkErrorMacro(<<
"Index out of range. Color not set.");
233 this->IndexedColorsInFullSet->GetTypedTuple(index,
rgb);
239 if (n !=
static_cast<int>(
240 this->IndexedOpacitiesInFullSet->GetNumberOfTuples())) {
241 vtkIdType old = this->IndexedOpacitiesInFullSet->GetNumberOfTuples();
242 this->IndexedOpacitiesInFullSet->SetNumberOfTuples(n);
244 this->IndexedOpacitiesInFullSet->FillComponent(0, 1.0);
252 unsigned int index,
double alpha) {
254 static_cast<unsigned int>(
255 this->IndexedOpacitiesInFullSet->GetNumberOfTuples())) {
261 this->IndexedOpacitiesInFullSet->GetTypedTuple(index, ¤tAlpha);
262 if (currentAlpha != alpha) {
263 this->IndexedOpacitiesInFullSet->SetTypedTuple(index, &alpha);
271 return static_cast<int>(
272 this->IndexedOpacitiesInFullSet->GetNumberOfTuples());
277 unsigned int index,
double* alpha) {
279 static_cast<unsigned int>(
280 this->IndexedOpacitiesInFullSet->GetNumberOfTuples())) {
281 vtkErrorMacro(<<
"Index out of range. Opacity not set.");
285 this->IndexedOpacitiesInFullSet->GetTypedTuple(index, alpha);
290 if (this->BuildTime > this->GetMTime()) {
295 this->ResetAnnotations();
297 int annotationCount = 0;
299 if (this->AnnotatedValuesInFullSet) {
300 vtkNew<vtkVariantArray> builtValues;
301 vtkNew<vtkStringArray> builtAnnotations;
303 for (vtkIdType i = 0;
304 i < this->AnnotatedValuesInFullSet->GetNumberOfTuples(); ++i) {
305 std::string annotation = this->AnnotationsInFullSet->GetValue(i);
307 this->AnnotatedValuesInFullSet->GetVariantValue(i);
309 bool useAnnotation =
true;
310 if (this->IndexedLookup && this->UseActiveValues) {
311 vtkIdType
id = this->ActiveAnnotatedValues->LookupValue(value);
313 useAnnotation =
false;
318 builtValues->InsertNextValue(value);
319 builtAnnotations->InsertNextValue(annotation);
321 if (i < this->IndexedColorsInFullSet->GetNumberOfTuples()) {
324 if (this->EnableOpacityMapping &&
325 i < this->IndexedOpacitiesInFullSet
326 ->GetNumberOfTuples()) {
336 this->SetAnnotations(builtValues.GetPointer(),
337 builtAnnotations.GetPointer());
340 this->Superclass::Build();
342 this->BuildTime.Modified();
348 this->Superclass::PrintSelf(os, indent);
void SetNumberOfIndexedColorsInFullSet(int n)
void SetActiveAnnotatedValue(std::string value)
int GetNumberOfIndexedColorsInFullSet()
void SetIndexedColorInFullSet(unsigned int index, double r, double g, double b)
virtual vtkIdType SetAnnotationInFullSet(vtkVariant value, std::string annotation)
void GetIndexedOpacityInFullSet(unsigned int index, double *alpha)
void SetIndexedOpacityInFullSet(unsigned int index, double alpha)
vtkDiscretizableColorTransferFunctionCustom()
~vtkDiscretizableColorTransferFunctionCustom() override
void PrintSelf(ostream &os, vtkIndent indent) override
void SetIndexedColorRGBA(unsigned int index, const double rgba[4])
void SetNumberOfIndexedOpacitiesInFullSet(int n)
virtual void ResetAnnotationsInFullSet()
virtual void SetAnnotationsInFullSet(vtkAbstractArray *values, vtkStringArray *annotations)
int GetNumberOfIndexedOpacitiesInFullSet()
void ResetActiveAnnotatedValues()
void GetIndexedColorInFullSet(unsigned int index, double rgb[3])
vtkStandardNewMacro(vtkDiscretizableColorTransferFunctionCustom)