1 //============================================================================
2 //  Copyright (c) Kitware, Inc.
3 //  All rights reserved.
4 //  See LICENSE.txt for details.
5 //  This software is distributed WITHOUT ANY WARRANTY; without even
6 //  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7 //  PURPOSE.  See the above copyright notice for more information.
8 //
9 //  Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 //  Copyright 2014 UT-Battelle, LLC.
11 //  Copyright 2014 Los Alamos National Security.
12 //
13 //  Under the terms of Contract DE-NA0003525 with NTESS,
14 //  the U.S. Government retains certain rights in this software.
15 //
16 //  Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
17 //  Laboratory (LANL), the U.S. Government retains certain rights in
18 //  this software.
19 //============================================================================
20 
21 #ifndef vtk_m_filter_FieldToColors_h
22 #define vtk_m_filter_FieldToColors_h
23 
24 #include <vtkm/cont/ColorTable.h>
25 #include <vtkm/filter/FilterField.h>
26 
27 namespace vtkm
28 {
29 namespace filter
30 {
31 
32 /// \brief  Convert an arbitrary field to an RGB or RGBA field
33 ///
34 class FieldToColors : public vtkm::filter::FilterField<FieldToColors>
35 {
36 public:
37   VTKM_CONT
38   FieldToColors(const vtkm::cont::ColorTable& table = vtkm::cont::ColorTable());
39 
40   enum FieldToColorsInputMode
41   {
42     SCALAR,
43     MAGNITUDE,
44     COMPONENT
45   };
46 
47   enum FieldToColorsOutputMode
48   {
49     RGB,
50     RGBA
51   };
52 
SetColorTable(const vtkm::cont::ColorTable & table)53   void SetColorTable(const vtkm::cont::ColorTable& table)
54   {
55     this->Table = table;
56     this->ModifiedCount = -1;
57   }
GetColorTable()58   const vtkm::cont::ColorTable& GetColorTable() const { return this->Table; }
59 
SetMappingMode(FieldToColorsInputMode mode)60   void SetMappingMode(FieldToColorsInputMode mode) { this->InputMode = mode; }
SetMappingToScalar()61   void SetMappingToScalar() { this->InputMode = FieldToColorsInputMode::SCALAR; }
SetMappingToMagnitude()62   void SetMappingToMagnitude() { this->InputMode = FieldToColorsInputMode::MAGNITUDE; }
SetMappingToComponent()63   void SetMappingToComponent() { this->InputMode = FieldToColorsInputMode::COMPONENT; }
GetMappingMode()64   FieldToColorsInputMode GetMappingMode() const { return this->InputMode; }
IsMappingScalar()65   bool IsMappingScalar() const { return this->InputMode == FieldToColorsInputMode::SCALAR; }
IsMappingMagnitude()66   bool IsMappingMagnitude() const { return this->InputMode == FieldToColorsInputMode::MAGNITUDE; }
IsMappingComponent()67   bool IsMappingComponent() const { return this->InputMode == FieldToColorsInputMode::COMPONENT; }
68 
SetMappingComponent(vtkm::IdComponent comp)69   void SetMappingComponent(vtkm::IdComponent comp) { this->Component = comp; }
GetMappingComponent()70   vtkm::IdComponent GetMappingComponent() const { return this->Component; }
71 
SetOutputMode(FieldToColorsOutputMode mode)72   void SetOutputMode(FieldToColorsOutputMode mode) { this->OutputMode = mode; }
SetOutputToRGB()73   void SetOutputToRGB() { this->OutputMode = FieldToColorsOutputMode::RGB; }
SetOutputToRGBA()74   void SetOutputToRGBA() { this->OutputMode = FieldToColorsOutputMode::RGBA; }
GetOutputMode()75   FieldToColorsOutputMode GetOutputMode() const { return this->OutputMode; }
IsOutputRGB()76   bool IsOutputRGB() const { return this->OutputMode == FieldToColorsOutputMode::RGB; }
IsOutputRGBA()77   bool IsOutputRGBA() const { return this->OutputMode == FieldToColorsOutputMode::RGBA; }
78 
79 
80   void SetNumberOfSamplingPoints(vtkm::Int32 count);
GetNumberOfSamplingPoints()81   vtkm::Int32 GetNumberOfSamplingPoints() const { return this->SampleCount; }
82 
83   template <typename T, typename StorageType, typename DerivedPolicy, typename DeviceAdapter>
84   VTKM_CONT vtkm::cont::DataSet DoExecute(const vtkm::cont::DataSet& input,
85                                           const vtkm::cont::ArrayHandle<T, StorageType>& field,
86                                           const vtkm::filter::FieldMetadata& fieldMeta,
87                                           const vtkm::filter::PolicyBase<DerivedPolicy>& policy,
88                                           const DeviceAdapter& tag);
89 
90 private:
91   vtkm::cont::ColorTable Table;
92   FieldToColorsInputMode InputMode;
93   FieldToColorsOutputMode OutputMode;
94   vtkm::cont::ColorTableSamplesRGB SamplesRGB;
95   vtkm::cont::ColorTableSamplesRGBA SamplesRGBA;
96   vtkm::IdComponent Component;
97   vtkm::Int32 SampleCount;
98   vtkm::Id ModifiedCount;
99 };
100 }
101 } // namespace vtkm::filter
102 
103 #include <vtkm/filter/FieldToColors.hxx>
104 
105 #endif // vtk_m_filter_FieldToColors_h
106