Texture.cpp
Go to the documentation of this file.
1 
28 /*
29  * Texture.cpp
30  *
31  * @date 19.07.2017
32  * @author Kim Rinnewitz (krinnewitz@uos.de)
33  * @author Sven Schalk (sschalk@uos.de)
34  * @author Kristin Schmidt (krschmidt@uos.de)
35  * @author Jan Philipp Vogtherr (jvogtherr@uos.de)
36  */
37 
38 #include "lvr2/texture/Texture.hpp"
40 
41 namespace lvr2 {
42 
44 {
45  this->m_data = 0;
46  this->m_width = 0;
47  this->m_height = 0;
48  this->m_numChannels = 0;
49  this->m_numBytesPerChan = 0;
50  this->m_texelSize = 1.0;
51 }
52 
53 // Texture::Texture(unsigned short int width, unsigned short int height, unsigned char numChannels,
54 // unsigned char numBytesPerChan, unsigned short int textureClass, unsigned short int numFeatures,
55 // unsigned char numFeatureComponents, float* features, float* keyPoints, float* stats, bool isPattern,
56 // unsigned char numCCVColors, unsigned long* CCV)
57 // {
58 // this->m_width = width;
59 // this->m_height = height;
60 // this->m_numChannels = numChannels;
61 // this->m_numBytesPerChan = numBytesPerChan;
62 // this->m_data = new unsigned char[width * height * numChannels * numBytesPerChan];
63 // this->m_textureClass = textureClass;
64 // this->m_numFeatures = numFeatures;
65 // this->m_numFeatureComponents = numFeatureComponents;
66 // this->m_featureDescriptors = features;
67 // this->m_stats = stats;
68 // this->m_isPattern = isPattern;
69 // this->m_numCCVColors = numCCVColors;
70 // this->m_CCV = CCV;
71 // this->m_keyPoints = keyPoints;
72 // this->m_distance = 0;
73 // }
74 
76  int index,
77  unsigned short int width,
78  unsigned short int height,
79  unsigned char numChannels,
80  unsigned char numBytesPerChan,
81  float texelSize,
82  unsigned char* data
83 ) :
84  m_index(index),
85  m_width(width),
86  m_height(height),
87  m_numChannels(numChannels),
88  m_numBytesPerChan(numBytesPerChan),
89  m_texelSize(texelSize),
90  m_data(new unsigned char[width * height * numChannels * numBytesPerChan])
91 {
92  if(data)
93  {
94  memcpy(m_data, data, width * height * numChannels * numBytesPerChan);
95  }
96 }
97 
99  this->m_index = other.m_index;
100  this->m_width = other.m_width;
101  this->m_height = other.m_height;
102  this->m_data = other.m_data;
103  this->m_numChannels = other.m_numChannels;
104  this->m_numBytesPerChan = other.m_numBytesPerChan;
105  this->m_texelSize = other.m_texelSize;
106 
107  other.m_data = nullptr;
108  other.m_width = 0;
109  other.m_height = 0;
110  other.m_numChannels = 0;
111  other.m_numBytesPerChan = 0;
112 }
113 
115 {
116  this->m_index = other.m_index;
117  this->m_width = other.m_width;
118  this->m_height = other.m_height;
119  //this->m_data = other.m_data;
120  this->m_numChannels = other.m_numChannels;
121  this->m_numBytesPerChan = other.m_numBytesPerChan;
122  this->m_texelSize = other.m_texelSize;
123 
124  size_t data_size = m_width * m_height * m_numChannels * m_numBytesPerChan;
125  m_data = new unsigned char[data_size];
126  std::copy(other.m_data, other.m_data + data_size, m_data);
127 
128 }
129 
131 {
132  if (this != &other)
133  {
134 
135  if (m_data)
136  {
137  delete[] m_data;
138  }
139  this->m_index = other.m_index;
140  this->m_width = other.m_width;
141  this->m_height = other.m_height;
142  //this->m_data = other.m_data;
143  this->m_numChannels = other.m_numChannels;
144  this->m_numBytesPerChan = other.m_numBytesPerChan;
145  this->m_texelSize = other.m_texelSize;
146 
147  size_t data_size = m_width * m_height * m_numChannels * m_numBytesPerChan;
148  m_data = new unsigned char[data_size];
149  std::copy(other.m_data, other.m_data + data_size, m_data);
150  }
151 
152  return *this;
153 }
154 
155 
157  int index,
158  GlTexture* oldTexture
159 ) :
160  m_index(index),
161  m_width(oldTexture->m_width),
162  m_height(oldTexture->m_height),
163  m_numChannels(3),
164  m_numBytesPerChan(sizeof(unsigned char)),
165  m_texelSize(1),
166  m_data(new unsigned char[oldTexture->m_width
167  * oldTexture->m_height
168  * 3
169  * sizeof(unsigned char)])
170 {
171  size_t copy_len = m_width * m_height * m_numChannels * m_numBytesPerChan;
172  std::copy(oldTexture->m_pixels, oldTexture->m_pixels + copy_len, m_data);
173 }
174 
176 {
177  //write image file
178  char fn[255];
179  sprintf(fn, "texture_%d.ppm", m_index);
180  PPMIO* pio = new PPMIO;
181  pio->setDataArray(this->m_data, m_width, m_height);
182  pio->write(string(fn));
183  delete pio;
184 }
185 
187  if (m_data)
188  {
189  delete[] m_data;
190  }
191  // delete[] m_featureDescriptors;
192  // delete[] m_stats;
193  // delete[] m_CCV;
194  // delete[] m_keyPoints;
195 }
196 
197 }
lvr2::Texture::m_data
unsigned char * m_data
The texture data.
Definition: Texture.hpp:114
lvr2::GlTexture
Definition: GlTexture.hpp:56
lvr2::Texture::m_numChannels
unsigned char m_numChannels
The number of color channels.
Definition: Texture.hpp:117
lvr2::Texture::~Texture
virtual ~Texture()
Destructor.
Definition: Texture.cpp:186
lvr2::Texture::Texture
Texture()
Constructor.
Definition: Texture.cpp:43
lvr2::Texture::m_height
unsigned short int m_height
Definition: Texture.hpp:111
Texture.hpp
lvr2::PPMIO::setDataArray
void setDataArray(unsigned char *array, int width, int height)
Definition: PPMIO.cpp:143
lvr2::Texture::m_texelSize
float m_texelSize
The size of a texture pixel.
Definition: Texture.hpp:123
lvr2::GlTexture::m_pixels
unsigned char * m_pixels
The aligned pixel data. Three bytes per pixel (r,g,b)
Definition: GlTexture.hpp:109
lvr2::Texture::save
void save()
Writes the texture to an image file.
Definition: Texture.cpp:175
lvr2::Texture::operator=
Texture & operator=(const Texture &other)
Definition: Texture.cpp:130
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::Texture
This class represents a texture.
Definition: Texture.hpp:54
lvr2::PPMIO::write
void write(string filename)
Definition: PPMIO.cpp:129
lvr2::Texture::m_width
unsigned short int m_width
The dimensions of the texture.
Definition: Texture.hpp:111
lvr2::PPMIO
An implementation of the PPM file format.
Definition: PPMIO.hpp:59
lvr2::Texture::m_index
int m_index
Texture index.
Definition: Texture.hpp:108
GlTexture.hpp
lvr2::Texture::m_numBytesPerChan
unsigned char m_numBytesPerChan
The number of bytes per channel.
Definition: Texture.hpp:120


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:25