------------------------------------------------------------------------------
| 2178 | |
| 2179 | //------------------------------------------------------------------------------ |
| 2180 | int vtkScalarBarActor::MapAnnotationLabels( |
| 2181 | vtkScalarsToColors* lkup, double start, double delta, const double* range) |
| 2182 | { |
| 2183 | int numNotes = lkup->GetNumberOfAnnotatedValues(); |
| 2184 | bool indexed = lkup->GetIndexedLookup() != 0; |
| 2185 | bool vertical = (this->Orientation == VTK_ORIENT_VERTICAL); |
| 2186 | vtkColor4d fltCol; |
| 2187 | double drange = range[1] - range[0]; |
| 2188 | // I. If we are not in indexed mode, we must sort the labels that we can |
| 2189 | // position by their order of appearance (since placement gives |
| 2190 | // precedence to the median label). Hence, we use a map to accumulate |
| 2191 | // labels. |
| 2192 | this->P->Labels.clear(); |
| 2193 | this->P->LabelColors.clear(); |
| 2194 | if (numNotes > 0) |
| 2195 | { |
| 2196 | for (int i = 0; i < numNotes; ++i) |
| 2197 | { |
| 2198 | std::string label = lkup->GetAnnotation(i); |
| 2199 | lkup->GetAnnotationColor(lkup->GetAnnotatedValue(i), fltCol.GetData()); |
| 2200 | double x; |
| 2201 | bool canPositionLabel = !label.empty(); |
| 2202 | if (canPositionLabel) |
| 2203 | { |
| 2204 | if (indexed) |
| 2205 | { |
| 2206 | // Vertical orientation in indexed lookup mode is a special case: |
| 2207 | // The first swatch is placed at the top (highest y coordinate). |
| 2208 | // All other cases (all horizontal, interval-mode vertical) order |
| 2209 | // labels from lowest coordinate to highest. |
| 2210 | x = vertical ? start + (numNotes - i - 0.5) * delta / numNotes |
| 2211 | : start + (i + 0.5) * delta / numNotes; |
| 2212 | } |
| 2213 | else |
| 2214 | { |
| 2215 | vtkVariant pos = lkup->GetAnnotatedValue(i); |
| 2216 | x = pos.ToDouble(&canPositionLabel); |
| 2217 | if (canPositionLabel) |
| 2218 | { // Also do not draw if label is outside the scalar bar range. |
| 2219 | canPositionLabel = (x >= range[0] && x <= range[1]); |
| 2220 | } |
| 2221 | x = canPositionLabel ? (start + (x - range[0]) * delta / drange) : vtkMath::Nan(); |
| 2222 | } |
| 2223 | } |
| 2224 | if (canPositionLabel) |
| 2225 | { |
| 2226 | this->P->Labels[x] = label; |
| 2227 | // Obtain a color for leader lines |
| 2228 | vtkColor3ub intCol; |
| 2229 | for (int j = 0; j < 3; ++j) |
| 2230 | { |
| 2231 | intCol.GetData()[j] = static_cast<unsigned char>(fltCol.GetData()[j] * 255.); |
| 2232 | } |
| 2233 | this->P->LabelColors[x] = intCol; |
| 2234 | } |
| 2235 | } |
| 2236 | } |
| 2237 |
no test coverage detected