VTK-m  2.0
ChannelBuffer.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 vtkm_rendering_raytracing_ChannelBuffer_h
11 #define vtkm_rendering_raytracing_ChannelBuffer_h
12 
13 #include <vtkm/cont/ArrayHandle.h>
14 
15 #include <vtkm/rendering/vtkm_rendering_export.h>
16 
18 
19 #include <string>
20 
21 namespace vtkm
22 {
23 namespace rendering
24 {
25 namespace raytracing
26 {
43 
44 template <typename Precision>
45 class VTKM_RENDERING_EXPORT ChannelBuffer
46 {
47 protected:
50  std::string Name;
52 
53 public:
55 
59  VTKM_CONT
60  ChannelBuffer();
61 
62  VTKM_CONT
63  ChannelBuffer(const vtkm::Int32 numChannels, const vtkm::Id size);
64 
65  VTKM_CONT
66  ChannelBuffer<Precision> GetChannel(const vtkm::Int32 channel);
67 
69  const vtkm::Id outputSize,
71 
73  const vtkm::Id outputSize,
74  Precision initValue = 1.f);
75 
77 
78  void InitConst(const Precision value);
79  void InitChannels(const vtkm::cont::ArrayHandle<Precision>& signature);
80  void Normalize(bool invert);
81  void SetName(const std::string name);
82  void Resize(const vtkm::Id newSize);
83  void SetNumChannels(const vtkm::Int32 numChannels);
84  vtkm::Int32 GetNumChannels() const;
85  vtkm::Id GetSize() const;
86  vtkm::Id GetBufferLength() const;
87  std::string GetName() const;
88  void AddBuffer(const ChannelBuffer<Precision>& other);
89  void MultiplyBuffer(const ChannelBuffer<Precision>& other);
92  template <typename Device>
93  VTKM_CONT ChannelBuffer(const vtkm::Int32 size, const vtkm::Int32 numChannels, Device)
94  {
95  if (size < 1)
96  throw vtkm::cont::ErrorBadValue("ChannelBuffer: Size must be greater that 0");
97  if (numChannels < 1)
98  throw vtkm::cont::ErrorBadValue("ChannelBuffer: NumChannels must be greater that 0");
99 
100  this->NumChannels = numChannels;
101  this->Size = size;
102 
103  vtkm::cont::Token token;
104  this->Buffer.PrepareForOutput(this->Size * this->NumChannels, Device(), token);
105  }
106 
107 
108 
109  template <typename Device>
110  VTKM_CONT void SetNumChannels(const vtkm::Int32 numChannels, Device)
111  {
112  if (numChannels < 1)
113  {
114  std::string msg = "ChannelBuffer SetNumChannels: numBins must be greater that 0";
115  throw vtkm::cont::ErrorBadValue(msg);
116  }
117  if (this->NumChannels == numChannels)
118  return;
119 
120  this->NumChannels = numChannels;
121  vtkm::cont::Token token;
122  this->Buffer.PrepareForOutput(this->Size * this->NumChannels, Device(), token);
123  }
124 
125  template <typename Device>
126  VTKM_CONT void Resize(const vtkm::Id newSize, Device device)
127  {
128  if (newSize < 0)
129  throw vtkm::cont::ErrorBadValue("ChannelBuffer resize: Size must be greater than -1 ");
130  this->Size = newSize;
131  vtkm::cont::Token token;
132  this->Buffer.PrepareForOutput(this->Size * static_cast<vtkm::Id>(NumChannels), device, token);
133  }
134 };
135 }
136 }
137 } // namespace vtkm::rendering::raytracing
138 
139 #endif
vtkm::rendering::raytracing::ChannelBuffer::Resize
VTKM_CONT void Resize(const vtkm::Id newSize, Device device)
Definition: ChannelBuffer.h:126
vtkm::cont::ArrayHandle< Precision >
ArrayHandle.h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::rendering::raytracing::ChannelBuffer::Name
std::string Name
Definition: ChannelBuffer.h:50
vtkm::Normalize
VTKM_EXEC_CONT void Normalize(T &x)
Changes a vector to be normal.
Definition: VectorAnalysis.h:168
vtkm::rendering::raytracing::ChannelBuffer::Size
vtkm::Id Size
Definition: ChannelBuffer.h:49
vtkm::rendering::raytracing::ChannelBuffer
Mananges a buffer that contains many channels per value (e.g., RGBA values).
Definition: ChannelBuffer.h:45
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
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::rendering::raytracing::ChannelBuffer::Buffer
vtkm::cont::ArrayHandle< Precision > Buffer
Definition: ChannelBuffer.h:54
vtkm::cont::ErrorBadValue
This class is thrown when a VTKm function or method encounters an invalid value that inhibits progres...
Definition: ErrorBadValue.h:25
vtkm::cont::ArrayHandle::PrepareForOutput
VTKM_CONT WritePortalType PrepareForOutput(vtkm::Id numberOfValues, vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Prepares (allocates) this array to be used as an output from an operation in the execution environmen...
Definition: ArrayHandle.h:613
vtkm::Int32
int32_t Int32
Definition: Types.h:160
RayTracingTypeDefs.h
vtkm::rendering::raytracing::ChannelBuffer::ChannelBuffer
VTKM_CONT ChannelBuffer(const vtkm::Int32 size, const vtkm::Int32 numChannels, Device)
Functions that are calleble within vtkm where the device is already known.
Definition: ChannelBuffer.h:93
vtkm::rendering::raytracing::ChannelBuffer::SetNumChannels
VTKM_CONT void SetNumChannels(const vtkm::Int32 numChannels, Device)
Definition: ChannelBuffer.h:110
vtkm::rendering::raytracing::ChannelBuffer::NumChannels
vtkm::Int32 NumChannels
Definition: ChannelBuffer.h:48
vtkm::rendering::raytracing::ChannelBufferOperations
Definition: ChannelBufferOperations.h:93