opensurgsim
ImageBase.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2016, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_DATASTRUCTURES_IMAGEBASE_H
17 #define SURGSIM_DATASTRUCTURES_IMAGEBASE_H
18 
19 #include <array>
20 #include <Eigen/Core>
21 
22 
23 namespace SurgSim
24 {
25 namespace DataStructures
26 {
27 
31 template<class T>
32 class ImageBase
33 {
34 public:
36  virtual ~ImageBase();
37 
40  size_t getWidth() const;
41 
44  size_t getHeight() const;
45 
48  std::array<size_t, 3> getSize() const;
49 
52  size_t getNumChannels() const;
53 
58  Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, 1>> operator()(size_t x, size_t y);
59 
64  Eigen::Map<const Eigen::Matrix<T, Eigen::Dynamic, 1>> operator()(size_t x, size_t y) const;
65 
67  typedef Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> ChannelType;
68 
72  Eigen::Map<ChannelType, Eigen::Unaligned, Eigen::Stride<-1, -1>> getChannel(size_t index);
73 
77  Eigen::Map<const ChannelType, Eigen::Unaligned, Eigen::Stride<-1, -1>> getChannel(size_t index) const;
78 
82  void setChannel(size_t index, const Eigen::Ref<const ChannelType>& data);
83 
85  typedef Eigen::Matrix<T, Eigen::Dynamic, 1> VectorType;
86 
89  Eigen::Map<VectorType, Eigen::Unaligned> getAsVector();
90 
93  Eigen::Map<const VectorType, Eigen::Unaligned> getAsVector() const;
94 
97  void setAsVector(const Eigen::Ref<const VectorType>& data);
98 
101  virtual T* const getData() = 0;
102 
105  virtual const T* const getData() const = 0;
106 
107 protected:
112  void setSize(size_t width, size_t height, size_t channels);
113 
114 private:
115  size_t m_width = 0;
116  size_t m_height = 0;
117  size_t m_channels = 0;
118 };
119 
120 };
121 };
122 
123 #include "SurgSim/DataStructures/ImageBase-inl.h"
124 
125 #endif //SURGSIM_DATASTRUCTURES_IMAGEBASE_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
std::array< size_t, 3 > getSize() const
Get the Image size.
Definition: ImageBase-inl.h:115
size_t getHeight() const
Get the Image height.
Definition: ImageBase-inl.h:109
void setChannel(size_t index, const Eigen::Ref< const ChannelType > &data)
Set the image data in the channel.
Definition: ImageBase-inl.h:71
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > ChannelType
2D Channel Type;
Definition: ImageBase.h:67
Eigen::Map< Eigen::Matrix< T, Eigen::Dynamic, 1 > > operator()(size_t x, size_t y)
Get the pixel value at (x, y)
Definition: ImageBase-inl.h:33
Eigen::Map< ChannelType, Eigen::Unaligned, Eigen::Stride<-1, -1 > > getChannel(size_t index)
Get the 2D image channel data.
Definition: ImageBase-inl.h:52
virtual T *const getData()=0
Get the pointer to the data.
Base class for Image-like classes.
Definition: ImageBase.h:32
Eigen::Matrix< T, Eigen::Dynamic, 1 > VectorType
1D Vector Type;
Definition: ImageBase.h:85
void setSize(size_t width, size_t height, size_t channels)
Set the Image size.
Definition: ImageBase-inl.h:128
size_t getWidth() const
Get the Image width.
Definition: ImageBase-inl.h:103
Eigen::Map< VectorType, Eigen::Unaligned > getAsVector()
Get the data as a 1D Vector.
Definition: ImageBase-inl.h:81
void setAsVector(const Eigen::Ref< const VectorType > &data)
Set the image data as a 1D Vector.
Definition: ImageBase-inl.h:93
virtual ~ImageBase()
Destructor.
Definition: ImageBase-inl.h:28
size_t getNumChannels() const
Get the number of channels in this Image.
Definition: ImageBase-inl.h:122