------------------------------------------------------------------------------
| 1141 | |
| 1142 | //------------------------------------------------------------------------------ |
| 1143 | void vtkDendrogramItem::SetColorArray(const char* arrayName) |
| 1144 | { |
| 1145 | this->ColorArray = |
| 1146 | vtkArrayDownCast<vtkDoubleArray>(this->Tree->GetVertexData()->GetArray(arrayName)); |
| 1147 | if (!this->ColorArray) |
| 1148 | { |
| 1149 | vtkErrorMacro("Could not downcast " << arrayName << " to a vtkDoubleArray"); |
| 1150 | this->ColorTree = false; |
| 1151 | return; |
| 1152 | } |
| 1153 | |
| 1154 | this->ColorTree = true; |
| 1155 | |
| 1156 | double minValue = VTK_DOUBLE_MAX; |
| 1157 | double maxValue = VTK_DOUBLE_MIN; |
| 1158 | |
| 1159 | for (vtkIdType id = 0; id < this->ColorArray->GetNumberOfTuples(); ++id) |
| 1160 | { |
| 1161 | double d = this->ColorArray->GetValue(id); |
| 1162 | maxValue = std::max(d, maxValue); |
| 1163 | minValue = std::min(d, minValue); |
| 1164 | } |
| 1165 | |
| 1166 | // special case: when there is no range of values to display, all edges should |
| 1167 | // be drawn in grey. Without this, all the edges would be drawn in either red |
| 1168 | // or blue. |
| 1169 | if (minValue == maxValue) |
| 1170 | { |
| 1171 | this->TreeLookupTable->SetNumberOfTableValues(1); |
| 1172 | this->TreeLookupTable->SetTableValue(0, 0.60, 0.60, 0.60); |
| 1173 | // this is done to prevent the legend from being drawn |
| 1174 | this->LegendPositionSet = true; |
| 1175 | return; |
| 1176 | } |
| 1177 | |
| 1178 | // how much we vary the colors from step to step |
| 1179 | double inc = 0.06; |
| 1180 | |
| 1181 | // setup the color lookup table. It will contain 10 shades of red, |
| 1182 | // 10 shades of blue, and a grey neutral value. |
| 1183 | |
| 1184 | this->TreeLookupTable->SetNumberOfTableValues(21); |
| 1185 | if (fabs(maxValue) > fabs(minValue)) |
| 1186 | { |
| 1187 | this->TreeLookupTable->SetRange(-maxValue, maxValue); |
| 1188 | } |
| 1189 | else |
| 1190 | { |
| 1191 | this->TreeLookupTable->SetRange(minValue, -minValue); |
| 1192 | } |
| 1193 | for (vtkIdType i = 0; i < 10; ++i) |
| 1194 | { |
| 1195 | this->TreeLookupTable->SetTableValue(i, 1.0, 0.25 + inc * i, 0.25 + inc * i); |
| 1196 | } |
| 1197 | this->TreeLookupTable->SetTableValue(10, 0.60, 0.60, 0.60); |
| 1198 | for (vtkIdType i = 11; i < 21; ++i) |
| 1199 | { |
| 1200 | this->TreeLookupTable->SetTableValue(i, 0.85 - inc * (i - 10), 0.85 - inc * (i - 10), 1.0); |
no test coverage detected