VTK-m  1.6
cont/ColorTable.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_cont_ColorTable_h
11 #define vtk_m_cont_ColorTable_h
12 
13 #include <vtkm/Range.h>
14 #include <vtkm/Types.h>
15 
16 #include <vtkm/cont/vtkm_cont_export.h>
17 
18 #include <vtkm/cont/ArrayHandle.h>
21 
22 #include <vtkm/exec/ColorTable.h>
23 
24 #include <set>
25 
26 namespace vtkm
27 {
28 namespace cont
29 {
30 
31 namespace detail
32 {
33 struct ColorTableInternals;
34 }
35 
37 {
38  static constexpr vtkm::ColorSpace RGB = vtkm::ColorSpace::RGB;
39  static constexpr vtkm::ColorSpace HSV = vtkm::ColorSpace::HSV;
40  static constexpr vtkm::ColorSpace HSV_WRAP = vtkm::ColorSpace::HSVWrap;
41  static constexpr vtkm::ColorSpace LAB = vtkm::ColorSpace::Lab;
42  static constexpr vtkm::ColorSpace DIVERGING = vtkm::ColorSpace::Diverging;
43 };
44 
98 class VTKM_CONT_EXPORT ColorTable : public vtkm::cont::ExecutionObjectBase
99 {
100  std::shared_ptr<detail::ColorTableInternals> Internals;
101 
102 public:
103  enum struct Preset
104  {
105  Default,
106  CoolToWarm,
107  CoolToWarmExtended,
108  Viridis,
109  Inferno,
110  Plasma,
111  BlackBodyRadiation,
112  XRay,
113  Green,
114  BlackBlueWhite,
115  BlueToOrange,
116  GrayToRed,
117  ColdAndHot,
118  BlueGreenOrange,
119  YellowGrayBlue,
120  RainbowUniform,
121  Jet,
122  RainbowDesaturated,
123 
124  DEFAULT VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::Default."),
125  COOL_TO_WARM VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::CoolToWarm."),
126  COOL_TO_WARM_EXTENDED VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::CoolToWarmExtended."),
127  VIRIDIS VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::Viridis."),
128  INFERNO VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::Inferno."),
129  PLASMA VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::Plasma."),
130  BLACK_BODY_RADIATION VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::BlackBodyRadiation."),
131  X_RAY VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::XRay."),
132  GREEN VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::Green."),
133  BLACK_BLUE_WHITE VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::BlackBlueWhite."),
134  BLUE_TO_ORANGE VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::BlueToOrange."),
135  GRAY_TO_RED VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::GrayToRed."),
136  COLD_AND_HOT VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::ColdAndHot."),
137  BLUE_GREEN_ORANGE VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::BlueGreenOrange."),
138  YELLOW_GRAY_BLUE VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::YellowGrayBlue."),
139  RAINBOW_UNIFORM VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::RainbowUniform."),
140  JET VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::Jet."),
141  RAINBOW_DESATURATED VTKM_DEPRECATED(1.6, "Use vtkm::ColorTable::Preset::RainbowDesaturated.")
142  };
143 
152 
180  explicit ColorTable(const std::string& name);
181 
186  explicit ColorTable(vtkm::ColorSpace space);
187 
194 
196  //
199  ColorTable(const vtkm::Range& range,
200  const vtkm::Vec3f_32& rgb1,
201  const vtkm::Vec3f_32& rgb2,
203 
207  ColorTable(const vtkm::Range& range,
208  const vtkm::Vec4f_32& rgba1,
209  const vtkm::Vec4f_32& rgba2,
211 
216  ColorTable(
217  const std::string& name,
218  vtkm::ColorSpace colorSpace,
219  const vtkm::Vec3f_64& nanColor,
220  const std::vector<vtkm::Float64>& rgbPoints,
221  const std::vector<vtkm::Float64>& alphaPoints = { 0.0, 1.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0 });
222 
223 
224  ~ColorTable();
225 
226  ColorTable& operator=(const ColorTable&) = default;
227  ColorTable(const ColorTable&) = default;
228 
229  const std::string& GetName() const;
230  void SetName(const std::string& name);
231 
232  bool LoadPreset(vtkm::cont::ColorTable::Preset preset);
233 
239  static std::set<std::string> GetPresets();
240 
269  bool LoadPreset(const std::string& name);
270 
276  ColorTable MakeDeepCopy();
277 
279  vtkm::ColorSpace GetColorSpace() const;
280  void SetColorSpace(vtkm::ColorSpace space);
281 
287  void SetClampingOn() { this->SetClamping(true); }
288  void SetClampingOff() { this->SetClamping(false); }
289  void SetClamping(bool state);
290  bool GetClamping() const;
291 
296  void SetBelowRangeColor(const vtkm::Vec3f_32& c);
297  const vtkm::Vec3f_32& GetBelowRangeColor() const;
298 
303  void SetAboveRangeColor(const vtkm::Vec3f_32& c);
304  const vtkm::Vec3f_32& GetAboveRangeColor() const;
305 
307  void SetNaNColor(const vtkm::Vec3f_32& c);
308  const vtkm::Vec3f_32& GetNaNColor() const;
309 
312  void Clear();
313 
315  void ClearColors();
316 
318  void ClearAlpha();
319 
321  void ReverseColors();
322 
327  void ReverseAlpha();
328 
330  const vtkm::Range& GetRange() const;
331 
334  void RescaleToRange(const vtkm::Range& range);
335 
336  // Functions for Colors
337 
343  vtkm::Int32 AddPoint(vtkm::Float64 x, const vtkm::Vec3f_32& rgb);
344 
350  vtkm::Int32 AddPointHSV(vtkm::Float64 x, const vtkm::Vec3f_32& hsv);
351 
357  vtkm::Int32 AddSegment(vtkm::Float64 x1,
358  const vtkm::Vec3f_32& rgb1,
359  vtkm::Float64 x2,
360  const vtkm::Vec3f_32& rgb2);
361 
367  vtkm::Int32 AddSegmentHSV(vtkm::Float64 x1,
368  const vtkm::Vec3f_32& hsv1,
369  vtkm::Float64 x2,
370  const vtkm::Vec3f_32& hsv2);
371 
376  bool GetPoint(vtkm::Int32 index, vtkm::Vec4f_64&) const;
377 
384  vtkm::Int32 UpdatePoint(vtkm::Int32 index, const vtkm::Vec4f_64&);
385 
389  bool RemovePoint(vtkm::Float64 x);
390 
394  bool RemovePoint(vtkm::Int32 index);
395 
397  vtkm::Int32 GetNumberOfPoints() const;
398 
399  // Functions for Opacity
400 
408  {
409  return AddPointAlpha(x, alpha, 0.5f, 0.0f);
410  }
411 
417  vtkm::Int32 AddPointAlpha(vtkm::Float64 x,
418  vtkm::Float32 alpha,
419  vtkm::Float32 midpoint,
420  vtkm::Float32 sharpness);
421 
429  vtkm::Float32 alpha1,
430  vtkm::Float64 x2,
431  vtkm::Float32 alpha2)
432  {
433  vtkm::Vec2f_32 mid_sharp(0.5f, 0.0f);
434  return AddSegmentAlpha(x1, alpha1, x2, alpha2, mid_sharp, mid_sharp);
435  }
436 
442  vtkm::Int32 AddSegmentAlpha(vtkm::Float64 x1,
443  vtkm::Float32 alpha1,
444  vtkm::Float64 x2,
445  vtkm::Float32 alpha2,
446  const vtkm::Vec2f_32& mid_sharp1,
447  const vtkm::Vec2f_32& mid_sharp2);
448 
454  bool GetPointAlpha(vtkm::Int32 index, vtkm::Vec4f_64&) const;
455 
463  vtkm::Int32 UpdatePointAlpha(vtkm::Int32 index, const vtkm::Vec4f_64&);
464 
468  bool RemovePointAlpha(vtkm::Float64 x);
469 
473  bool RemovePointAlpha(vtkm::Int32 index);
474 
476  vtkm::Int32 GetNumberOfPointsAlpha() const;
477 
489  bool FillColorTableFromDataPointer(vtkm::Int32 n, const vtkm::Float64* ptr);
490 
502  bool FillColorTableFromDataPointer(vtkm::Int32 n, const vtkm::Float32* ptr);
503 
517  bool FillOpacityTableFromDataPointer(vtkm::Int32 n, const vtkm::Float64* ptr);
518 
532  bool FillOpacityTableFromDataPointer(vtkm::Int32 n, const vtkm::Float32* ptr);
533 
534 
546  bool Sample(vtkm::Int32 numSamples,
548  vtkm::Float64 tolerance = 0.002) const;
549 
561  bool Sample(vtkm::Int32 numSamples,
563  vtkm::Float64 tolerance = 0.002) const;
564 
576  bool Sample(vtkm::Int32 numSamples,
578  vtkm::Float64 tolerance = 0.002) const;
579 
591  bool Sample(vtkm::Int32 numSamples,
593  vtkm::Float64 tolerance = 0.002) const;
594 
595 
599  vtkm::exec::ColorTable PrepareForExecution(vtkm::cont::DeviceAdapterId deviceId,
600  vtkm::cont::Token& token) const;
601 
602  VTKM_DEPRECATED(1.6, "PrepareForExecution now requires a vtkm::cont::Token object")
603  inline vtkm::exec::ColorTable PrepareForExecution(vtkm::cont::DeviceAdapterId deviceId) const;
604 
613  vtkm::Id GetModifiedCount() const;
614 
615 private:
616  void UpdateArrayHandles() const;
617 };
618 }
619 } //namespace vtkm::cont
620 #endif //vtk_m_cont_ColorTable_h
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:289
ArrayHandle.h
vtkm::cont::VTKM_DEPRECATED
struct VTKM_DEPRECATED(1.6, "Use vtkm::ColorSpace.") ColorSpace
Definition: cont/ColorTable.h:36
vtkm
VTKM_NO_DEPRECATED_VIRTUAL.
Definition: Algorithms.h:23
vtkm::cont::ColorTable
Color Table for coloring arbitrary fields.
Definition: cont/ColorTable.h:98
Types.h
vtkm::cont::ColorTable::AddPointAlpha
vtkm::Int32 AddPointAlpha(vtkm::Float64 x, vtkm::Float32 alpha)
Adds a point to the opacity function.
Definition: cont/ColorTable.h:407
ColorTable.h
vtkm::cont::ColorTable::SetClampingOff
void SetClampingOff()
Definition: cont/ColorTable.h:288
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
vtkm::cont::ColorTable::SetClampingOn
void SetClampingOn()
If clamping is disabled values that lay out side the color table range are colored based on Below and...
Definition: cont/ColorTable.h:287
vtkm::cont::ColorTable::AddSegmentAlpha
vtkm::Int32 AddSegmentAlpha(vtkm::Float64 x1, vtkm::Float32 alpha1, vtkm::Float64 x2, vtkm::Float32 alpha2)
Add a line segment to the opacity function.
Definition: cont/ColorTable.h:428
vtkm::cont::ColorTableSamplesRGBA
Color Sample Table used with vtkm::cont::ColorTable for fast coloring.
Definition: ColorTableSamples.h:32
vtkm::ColorSpace::Diverging
@ Diverging
Range.h
vtkm::ColorSpace::RGB
@ RGB
vtkm::ColorSpace::HSVWrap
@ HSVWrap
vtkm::exec::ColorTable
Definition: exec/ColorTable.h:35
vtkm::cont::ColorTable::Preset::Default
@ Default
vtkm::cont::ExecutionObjectBase
Base ExecutionObjectBase for execution objects to inherit from so that you can use an arbitrary objec...
Definition: ExecutionObjectBase.h:32
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
vtkm::Vec< vtkm::Float32, 3 >
vtkm::cont::ColorTableSamplesRGB
Color Sample Table used with vtkm::cont::ColorTable for fast coloring.
Definition: ColorTableSamples.h:51
vtkm::cont::ColorTable::Preset
Preset
Definition: cont/ColorTable.h:103
vtkm::Float32
float Float32
Definition: Types.h:154
vtkm::Int32
int32_t Int32
Definition: Types.h:160
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::ColorSpace::HSV
@ HSV
ColorTableSamples.h
vtkm::ColorSpace::Lab
@ Lab
ExecutionObjectBase.h
vtkm::cont::ColorTable::Internals
std::shared_ptr< detail::ColorTableInternals > Internals
Definition: cont/ColorTable.h:100
vtkm::ColorSpace
ColorSpace
Definition: exec/ColorTable.h:19
vtkm::Range
Represent a continuous scalar range of values.
Definition: Range.h:30