VTK-m  2.0
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 
89 class VTKM_CONT_EXPORT ColorTable : public vtkm::cont::ExecutionObjectBase
90 {
91  std::shared_ptr<detail::ColorTableInternals> Internals;
92 
93 public:
94  enum struct Preset
95  {
96  Default,
97  CoolToWarm,
98  CoolToWarmExtended,
99  Viridis,
100  Inferno,
101  Plasma,
102  BlackBodyRadiation,
103  XRay,
104  Green,
105  BlackBlueWhite,
106  BlueToOrange,
107  GrayToRed,
108  ColdAndHot,
109  BlueGreenOrange,
110  YellowGrayBlue,
111  RainbowUniform,
112  Jet,
113  RainbowDesaturated,
114  };
115 
124 
152  explicit ColorTable(const std::string& name);
153 
158  explicit ColorTable(vtkm::ColorSpace space);
159 
166 
168  //
171  ColorTable(const vtkm::Range& range,
172  const vtkm::Vec3f_32& rgb1,
173  const vtkm::Vec3f_32& rgb2,
175 
179  ColorTable(const vtkm::Range& range,
180  const vtkm::Vec4f_32& rgba1,
181  const vtkm::Vec4f_32& rgba2,
183 
188  ColorTable(
189  const std::string& name,
190  vtkm::ColorSpace colorSpace,
191  const vtkm::Vec3f_64& nanColor,
192  const std::vector<vtkm::Float64>& rgbPoints,
193  const std::vector<vtkm::Float64>& alphaPoints = { 0.0, 1.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0 });
194 
195 
196  ~ColorTable();
197 
198  ColorTable& operator=(const ColorTable&) = default;
199  ColorTable(const ColorTable&) = default;
200 
201  const std::string& GetName() const;
202  void SetName(const std::string& name);
203 
204  bool LoadPreset(vtkm::cont::ColorTable::Preset preset);
205 
211  static std::set<std::string> GetPresets();
212 
241  bool LoadPreset(const std::string& name);
242 
248  ColorTable MakeDeepCopy();
249 
251  vtkm::ColorSpace GetColorSpace() const;
252  void SetColorSpace(vtkm::ColorSpace space);
253 
259  void SetClampingOn() { this->SetClamping(true); }
260  void SetClampingOff() { this->SetClamping(false); }
261  void SetClamping(bool state);
262  bool GetClamping() const;
263 
268  void SetBelowRangeColor(const vtkm::Vec3f_32& c);
269  const vtkm::Vec3f_32& GetBelowRangeColor() const;
270 
275  void SetAboveRangeColor(const vtkm::Vec3f_32& c);
276  const vtkm::Vec3f_32& GetAboveRangeColor() const;
277 
279  void SetNaNColor(const vtkm::Vec3f_32& c);
280  const vtkm::Vec3f_32& GetNaNColor() const;
281 
284  void Clear();
285 
287  void ClearColors();
288 
290  void ClearAlpha();
291 
293  void ReverseColors();
294 
299  void ReverseAlpha();
300 
302  const vtkm::Range& GetRange() const;
303 
306  void RescaleToRange(const vtkm::Range& range);
307 
308  // Functions for Colors
309 
315  vtkm::Int32 AddPoint(vtkm::Float64 x, const vtkm::Vec3f_32& rgb);
316 
322  vtkm::Int32 AddPointHSV(vtkm::Float64 x, const vtkm::Vec3f_32& hsv);
323 
329  vtkm::Int32 AddSegment(vtkm::Float64 x1,
330  const vtkm::Vec3f_32& rgb1,
331  vtkm::Float64 x2,
332  const vtkm::Vec3f_32& rgb2);
333 
339  vtkm::Int32 AddSegmentHSV(vtkm::Float64 x1,
340  const vtkm::Vec3f_32& hsv1,
341  vtkm::Float64 x2,
342  const vtkm::Vec3f_32& hsv2);
343 
348  bool GetPoint(vtkm::Int32 index, vtkm::Vec4f_64&) const;
349 
356  vtkm::Int32 UpdatePoint(vtkm::Int32 index, const vtkm::Vec4f_64&);
357 
361  bool RemovePoint(vtkm::Float64 x);
362 
366  bool RemovePoint(vtkm::Int32 index);
367 
369  vtkm::Int32 GetNumberOfPoints() const;
370 
371  // Functions for Opacity
372 
380  {
381  return AddPointAlpha(x, alpha, 0.5f, 0.0f);
382  }
383 
389  vtkm::Int32 AddPointAlpha(vtkm::Float64 x,
390  vtkm::Float32 alpha,
391  vtkm::Float32 midpoint,
392  vtkm::Float32 sharpness);
393 
401  vtkm::Float32 alpha1,
402  vtkm::Float64 x2,
403  vtkm::Float32 alpha2)
404  {
405  vtkm::Vec2f_32 mid_sharp(0.5f, 0.0f);
406  return AddSegmentAlpha(x1, alpha1, x2, alpha2, mid_sharp, mid_sharp);
407  }
408 
414  vtkm::Int32 AddSegmentAlpha(vtkm::Float64 x1,
415  vtkm::Float32 alpha1,
416  vtkm::Float64 x2,
417  vtkm::Float32 alpha2,
418  const vtkm::Vec2f_32& mid_sharp1,
419  const vtkm::Vec2f_32& mid_sharp2);
420 
426  bool GetPointAlpha(vtkm::Int32 index, vtkm::Vec4f_64&) const;
427 
435  vtkm::Int32 UpdatePointAlpha(vtkm::Int32 index, const vtkm::Vec4f_64&);
436 
440  bool RemovePointAlpha(vtkm::Float64 x);
441 
445  bool RemovePointAlpha(vtkm::Int32 index);
446 
448  vtkm::Int32 GetNumberOfPointsAlpha() const;
449 
461  bool FillColorTableFromDataPointer(vtkm::Int32 n, const vtkm::Float64* ptr);
462 
474  bool FillColorTableFromDataPointer(vtkm::Int32 n, const vtkm::Float32* ptr);
475 
489  bool FillOpacityTableFromDataPointer(vtkm::Int32 n, const vtkm::Float64* ptr);
490 
504  bool FillOpacityTableFromDataPointer(vtkm::Int32 n, const vtkm::Float32* ptr);
505 
506 
518  bool Sample(vtkm::Int32 numSamples,
520  vtkm::Float64 tolerance = 0.002) const;
521 
533  bool Sample(vtkm::Int32 numSamples,
535  vtkm::Float64 tolerance = 0.002) const;
536 
548  bool Sample(vtkm::Int32 numSamples,
550  vtkm::Float64 tolerance = 0.002) const;
551 
563  bool Sample(vtkm::Int32 numSamples,
565  vtkm::Float64 tolerance = 0.002) const;
566 
567 
571  vtkm::exec::ColorTable PrepareForExecution(vtkm::cont::DeviceAdapterId deviceId,
572  vtkm::cont::Token& token) const;
573 
582  vtkm::Id GetModifiedCount() const;
583 
584 private:
585  void UpdateArrayHandles() const;
586 };
587 }
588 } //namespace vtkm::cont
589 #endif //vtk_m_cont_ColorTable_h
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
ArrayHandle.h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::cont::ColorTable
Color Table for coloring arbitrary fields.
Definition: cont/ColorTable.h:89
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:379
ColorTable.h
vtkm::cont::ColorTable::SetClampingOff
void SetClampingOff()
Definition: cont/ColorTable.h:260
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:259
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:400
vtkm::cont::ColorTableSamplesRGBA
Color Sample Table used with vtkm::cont::ColorTable for fast coloring.
Definition: ColorTableSamples.h:32
Range.h
vtkm::exec::ColorTable
Definition: exec/ColorTable.h:34
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:31
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:94
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
ColorTableSamples.h
vtkm::ColorSpace::Lab
@ Lab
ExecutionObjectBase.h
vtkm::cont::ColorTable::Internals
std::shared_ptr< detail::ColorTableInternals > Internals
Definition: cont/ColorTable.h:91
vtkm::ColorSpace
ColorSpace
Definition: exec/ColorTable.h:18
vtkm::Range
Represent a continuous scalar range of values.
Definition: Range.h:31