Viskores  1.0
cont/ColorTable.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_cont_ColorTable_h
19 #define viskores_cont_ColorTable_h
20 
21 #include <viskores/Range.h>
22 #include <viskores/Types.h>
23 
25 
29 
31 
32 #include <set>
33 
34 namespace viskores
35 {
36 namespace cont
37 {
38 
39 namespace detail
40 {
41 struct ColorTableInternals;
42 }
43 
97 class VISKORES_CONT_EXPORT ColorTable : public viskores::cont::ExecutionObjectBase
98 {
99  std::shared_ptr<detail::ColorTableInternals> Internals;
100 
101 public:
102  enum struct Preset
103  {
104  Default,
105  CoolToWarm,
106  CoolToWarmExtended,
107  Viridis,
108  Inferno,
109  Plasma,
110  BlackBodyRadiation,
111  XRay,
112  Green,
113  BlackBlueWhite,
114  BlueToOrange,
115  GrayToRed,
116  ColdAndHot,
117  BlueGreenOrange,
118  YellowGrayBlue,
119  RainbowUniform,
120  Jet,
121  RainbowDesaturated,
122  };
123 
131  ColorTable(
133 
161  explicit ColorTable(const std::string& name);
162 
167  explicit ColorTable(viskores::ColorSpace space);
168 
175 
177  //
180  ColorTable(const viskores::Range& range,
181  const viskores::Vec3f_32& rgb1,
182  const viskores::Vec3f_32& rgb2,
184 
188  ColorTable(const viskores::Range& range,
189  const viskores::Vec4f_32& rgba1,
190  const viskores::Vec4f_32& rgba2,
192 
197  ColorTable(
198  const std::string& name,
199  viskores::ColorSpace colorSpace,
200  const viskores::Vec3f_64& nanColor,
201  const std::vector<viskores::Float64>& rgbPoints,
202  const std::vector<viskores::Float64>& alphaPoints = { 0.0, 1.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0 });
203 
204 
205  ~ColorTable();
206 
207  ColorTable& operator=(const ColorTable&) = default;
208  ColorTable(const ColorTable&) = default;
209 
210  const std::string& GetName() const;
211  void SetName(const std::string& name);
212 
213  bool LoadPreset(viskores::cont::ColorTable::Preset preset);
214 
220  static std::set<std::string> GetPresets();
221 
250  bool LoadPreset(const std::string& name);
251 
257  ColorTable MakeDeepCopy();
258 
260  viskores::ColorSpace GetColorSpace() const;
261  void SetColorSpace(viskores::ColorSpace space);
262 
268  void SetClampingOn() { this->SetClamping(true); }
269  void SetClampingOff() { this->SetClamping(false); }
270  void SetClamping(bool state);
271  bool GetClamping() const;
272 
277  void SetBelowRangeColor(const viskores::Vec3f_32& c);
278  const viskores::Vec3f_32& GetBelowRangeColor() const;
279 
284  void SetAboveRangeColor(const viskores::Vec3f_32& c);
285  const viskores::Vec3f_32& GetAboveRangeColor() const;
286 
288  void SetNaNColor(const viskores::Vec3f_32& c);
289  const viskores::Vec3f_32& GetNaNColor() const;
290 
293  void Clear();
294 
296  void ClearColors();
297 
299  void ClearAlpha();
300 
302  void ReverseColors();
303 
308  void ReverseAlpha();
309 
311  const viskores::Range& GetRange() const;
312 
315  void RescaleToRange(const viskores::Range& range);
316 
317  // Functions for Colors
318 
324  viskores::Int32 AddPoint(viskores::Float64 x, const viskores::Vec3f_32& rgb);
325 
331  viskores::Int32 AddPointHSV(viskores::Float64 x, const viskores::Vec3f_32& hsv);
332 
338  viskores::Int32 AddSegment(viskores::Float64 x1,
339  const viskores::Vec3f_32& rgb1,
341  const viskores::Vec3f_32& rgb2);
342 
348  viskores::Int32 AddSegmentHSV(viskores::Float64 x1,
349  const viskores::Vec3f_32& hsv1,
351  const viskores::Vec3f_32& hsv2);
352 
357  bool GetPoint(viskores::Int32 index, viskores::Vec4f_64&) const;
358 
365  viskores::Int32 UpdatePoint(viskores::Int32 index, const viskores::Vec4f_64&);
366 
370  bool RemovePoint(viskores::Float64 x);
371 
375  bool RemovePoint(viskores::Int32 index);
376 
378  viskores::Int32 GetNumberOfPoints() const;
379 
380  // Functions for Opacity
381 
389  {
390  return AddPointAlpha(x, alpha, 0.5f, 0.0f);
391  }
392 
398  viskores::Int32 AddPointAlpha(viskores::Float64 x,
399  viskores::Float32 alpha,
400  viskores::Float32 midpoint,
401  viskores::Float32 sharpness);
402 
410  viskores::Float32 alpha1,
412  viskores::Float32 alpha2)
413  {
414  viskores::Vec2f_32 mid_sharp(0.5f, 0.0f);
415  return AddSegmentAlpha(x1, alpha1, x2, alpha2, mid_sharp, mid_sharp);
416  }
417 
423  viskores::Int32 AddSegmentAlpha(viskores::Float64 x1,
424  viskores::Float32 alpha1,
426  viskores::Float32 alpha2,
427  const viskores::Vec2f_32& mid_sharp1,
428  const viskores::Vec2f_32& mid_sharp2);
429 
435  bool GetPointAlpha(viskores::Int32 index, viskores::Vec4f_64&) const;
436 
444  viskores::Int32 UpdatePointAlpha(viskores::Int32 index, const viskores::Vec4f_64&);
445 
449  bool RemovePointAlpha(viskores::Float64 x);
450 
454  bool RemovePointAlpha(viskores::Int32 index);
455 
457  viskores::Int32 GetNumberOfPointsAlpha() const;
458 
470  bool FillColorTableFromDataPointer(viskores::Int32 n, const viskores::Float64* ptr);
471 
483  bool FillColorTableFromDataPointer(viskores::Int32 n, const viskores::Float32* ptr);
484 
498  bool FillOpacityTableFromDataPointer(viskores::Int32 n, const viskores::Float64* ptr);
499 
513  bool FillOpacityTableFromDataPointer(viskores::Int32 n, const viskores::Float32* ptr);
514 
515 
527  bool Sample(viskores::Int32 numSamples,
529  viskores::Float64 tolerance = 0.002) const;
530 
542  bool Sample(viskores::Int32 numSamples,
544  viskores::Float64 tolerance = 0.002) const;
545 
557  bool Sample(viskores::Int32 numSamples,
559  viskores::Float64 tolerance = 0.002) const;
560 
572  bool Sample(viskores::Int32 numSamples,
574  viskores::Float64 tolerance = 0.002) const;
575 
576 
580  viskores::exec::ColorTable PrepareForExecution(viskores::cont::DeviceAdapterId deviceId,
581  viskores::cont::Token& token) const;
582 
591  viskores::Id GetModifiedCount() const;
592 
593 private:
594  void UpdateArrayHandles() const;
595 };
596 }
597 } //namespace viskores::cont
598 #endif //viskores_cont_ColorTable_h
viskores::cont::ColorTable::SetClampingOff
void SetClampingOff()
Definition: cont/ColorTable.h:269
ArrayHandle.h
viskores::cont::ColorTable::Preset
Preset
Definition: cont/ColorTable.h:102
viskores::cont::ColorTable::AddPointAlpha
viskores::Int32 AddPointAlpha(viskores::Float64 x, viskores::Float32 alpha)
Adds a point to the opacity function.
Definition: cont/ColorTable.h:388
Types.h
ColorTable.h
viskores::cont::ColorTable::Preset::Default
@ Default
viskores::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:313
viskores::cont::ColorTable::Internals
std::shared_ptr< detail::ColorTableInternals > Internals
Definition: cont/ColorTable.h:99
viskores::ColorSpace
ColorSpace
Definition: exec/ColorTable.h:26
viskores::Id
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::cont::ColorTable
Color Table for coloring arbitrary fields.
Definition: cont/ColorTable.h:97
viskores::Float32
float Float32
Base type to use for 32-bit floating-point numbers.
Definition: Types.h:165
viskores::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:268
Range.h
viskores::cont::DeviceAdapterId
An object used to specify a device.
Definition: DeviceAdapterTag.h:66
viskores::Range
Represent a continuous scalar range of values.
Definition: Range.h:39
viskores::Int32
int32_t Int32
Base type to use for 32-bit signed integer numbers.
Definition: Types.h:189
viskores::ColorSpace::Lab
@ Lab
viskores::exec::ColorTable
Definition: exec/ColorTable.h:42
viskores::cont::ColorTableSamplesRGBA
Color Sample Table used with viskores::cont::ColorTable for fast coloring.
Definition: ColorTableSamples.h:40
ColorTableSamples.h
viskores::cont::ColorTable::AddSegmentAlpha
viskores::Int32 AddSegmentAlpha(viskores::Float64 x1, viskores::Float32 alpha1, viskores::Float64 x2, viskores::Float32 alpha2)
Add a line segment to the opacity function.
Definition: cont/ColorTable.h:409
viskores::Float64
double Float64
Base type to use for 64-bit floating-point numbers.
Definition: Types.h:169
ExecutionObjectBase.h
viskores::Vec< viskores::Float32, 3 >
viskores::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:43
viskores::cont::ExecutionObjectBase
Base ExecutionObjectBase for execution objects to inherit from so that you can use an arbitrary objec...
Definition: ExecutionObjectBase.h:39
viskores_cont_export.h
viskores::cont::ColorTableSamplesRGB
Color Sample Table used with viskores::cont::ColorTable for fast coloring.
Definition: ColorTableSamples.h:60