MeshBuffer.cpp
Go to the documentation of this file.
1 
28 #include "lvr2/io/MeshBuffer.hpp"
29 #include "lvr2/io/Timestamp.hpp"
30 
31 #include <iostream>
32 using std::cout;
33 using std::endl;
34 
35 namespace lvr2
36 {
37 
39 :base()
40 {
41 
42 }
43 
44 void MeshBuffer::setVertices(floatArr vertices, size_t n)
45 {
46  if(n)
47  {
48  this->addFloatChannel(vertices, "vertices", n, 3);
49  }
50 }
51 
53 {
54  if(hasVertices())
55  {
56  this->addFloatChannel(normals, "vertex_normals", numVertices(), 3);
57  }
58  else
59  {
60  cout << "MeshBuffer::setVertexNormals(): "
61  << "Cannot add vertex normals without vertex definitions" << endl;
62  }
63 }
64 
66 {
67  if(hasVertices())
68  {
69  this->addUCharChannel(colors, "vertex_colors", numVertices(), w);
70  }
71  else
72  {
73  cout << "MeshBuffer::setVertexColors(): "
74  << "Cannot add vertex colors without vertex definitions" << endl;
75  }
76 }
77 
79 {
80  if(hasVertices())
81  {
82  this->addFloatChannel(coordinates, "texture_coordinates", numVertices(), 2);
83  }
84  else
85  {
86  cout << "MeshBuffer::setTextureCoordinates(): "
87  << "Cannot add vertex colors without vertex definitions" << endl;
88  }
89 }
90 
91 void MeshBuffer::setFaceIndices(indexArray indices, size_t n)
92 {
93  if(n)
94  {
95  this->addIndexChannel(indices, "face_indices", n, 3);
96  }
97 }
98 
100 {
101  if(hasFaces())
102  {
103  this->addIndexChannel(indices, "face_material_indices", numFaces(), 1);
104  }
105  else
106  {
107  cout << "MeshBuffer::setFaceMaterialIndices(): "
108  << "Cannot add material indices without face definitions" << endl;
109  }
110 }
111 
113 {
114  if(hasFaces())
115  {
116  this->addFloatChannel(normals, "face_normals", numFaces(), 3);
117  }
118  else
119  {
120  cout << "MeshBuffer::setFaceMaterialIndices(): "
121  << "Cannot add material indices without face definitions" << endl;
122  }
123 }
124 
126 {
127  if(hasFaces())
128  {
129  this->addUCharChannel(colors, "face_colors", numFaces(), w);
130  }
131  else
132  {
133  cout << "MeshBuffer::setFaceColors(): "
134  << "Cannot add face colors without face definitions" << endl;
135  }
136 }
137 
139 {
140  const typename Channel<float>::Optional opt = getChannel<float>("vertices");
141  if(opt)
142  {
143  return opt->numElements();
144  }
145  else
146  {
147  return 0;
148  }
149 }
150 
151 size_t MeshBuffer::numFaces() const
152 {
153  const typename Channel<unsigned int>::Optional opt = getChannel<unsigned int>("face_indices");
154  if(opt)
155  {
156  return opt->numElements();
157  }
158  else
159  {
160  return 0;
161  }
162 }
163 
165 {
166  size_t n;
167  size_t w;
168  return this->getFloatArray("vertices", n, w);
169 }
170 
172 {
173  size_t n;
174  return this->getUCharArray("vertex_colors", n, w);
175 
176 }
177 
179 {
180  size_t n;
181  size_t w;
182  return this->getFloatArray("vertex_normals", n, w);
183 }
184 
186 {
187  size_t n;
188  size_t w;
189  return this->getFloatArray("face_normals", n, w);
190 }
191 
193 {
194  size_t n;
195  size_t w;
196  return this->getFloatArray("texture_coordinates", n, w);
197 }
198 
200 {
201  size_t n;
202  size_t w;
203  return this->getIndexArray("face_indices", n, w);
204 }
205 
207 {
208  size_t n;
209  ucharArr arr = this->getUCharArray("face_colors", n, w);
210  return arr;
211 }
212 
214 {
215  size_t n;
216  size_t w;
217  return this->getIndexArray("face_material_indices", n, w);
218 }
219 
220 std::vector<Texture>& MeshBuffer::getTextures()
221 {
222  return m_textures;
223 }
224 
225 std::vector<Material>& MeshBuffer::getMaterials()
226 {
227  return m_materials;
228 }
229 
231 {
232  const FloatChannelOptional channel = this->getChannel<float>("vertices");
233  if(channel)
234  {
235  return true;
236  }
237  return false;
238 }
239 
240 bool MeshBuffer::hasFaces() const
241 {
242  const IndexChannelOptional channel = this->getChannel<unsigned int>("face_indices");
243  if(channel)
244  {
245  return true;
246  }
247  return false;
248 }
249 
251 {
252  const UCharChannelOptional channel = this->getChannel<unsigned char>("face_colors");
253  if(channel)
254  {
255  return true;
256  }
257  return false;
258 }
259 
261 {
262  const UCharChannelOptional channel = this->getChannel<unsigned char>("vertex_colors");
263  if(channel)
264  {
265  return true;
266  }
267  return false;
268 }
269 
271 {
272  FloatChannelOptional channel = this->getChannel<float>("face_normals");
273  if(channel)
274  {
275  return true;
276  }
277  return false;
278 }
279 
281 {
282  const FloatChannelOptional channel = this->getChannel<float>("vertex_normals");
283  if(channel)
284  {
285  return true;
286  }
287  return false;
288 }
289 
290 }
lvr2::floatArr
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
lvr2::IndexChannelOptional
IndexChannel::Optional IndexChannelOptional
Definition: Channel.hpp:100
lvr2::MeshBuffer::MeshBuffer
MeshBuffer()
MeshBuffer Contructor. Builds an empty buffer. Fill elements with add-Methods.
Definition: MeshBuffer.cpp:38
lvr2::UCharChannelOptional
UCharChannel::Optional UCharChannelOptional
Definition: Channel.hpp:96
lvr2::Channel::Optional
boost::optional< Channel< T > > Optional
Definition: Channel.hpp:45
lvr2::indexArray
boost::shared_array< unsigned int > indexArray
Definition: DataStruct.hpp:128
lvr2::MeshBuffer::getFaceColors
ucharArr getFaceColors(size_t &width)
getFaceColors Returns an array with wrgb colors
Definition: MeshBuffer.cpp:206
lvr2::MeshBuffer::setVertexNormals
void setVertexNormals(floatArr normals)
addVertexNormals Adds vertex normals.
Definition: MeshBuffer.cpp:52
lvr2::MeshBuffer::hasVertexNormals
bool hasVertexNormals() const
Definition: MeshBuffer.cpp:280
lvr2::MeshBuffer::setVertexColors
void setVertexColors(ucharArr colors, size_t w=3)
addVertexColors Adds vertex color information.
Definition: MeshBuffer.cpp:65
lvr2::MeshBuffer::hasVertices
bool hasVertices() const
Definition: MeshBuffer.cpp:230
lvr2::FloatChannelOptional
FloatChannel::Optional FloatChannelOptional
Definition: Channel.hpp:88
lvr2::MeshBuffer::setTextureCoordinates
void setTextureCoordinates(floatArr coordinates)
addTextureCoordinates Adds texture coordinates for vertices
Definition: MeshBuffer.cpp:78
lvr2::MeshBuffer::getVertices
floatArr getVertices()
getVertices Return the vertex array.
Definition: MeshBuffer.cpp:164
lvr2::MeshBuffer::hasFaceColors
bool hasFaceColors() const
Definition: MeshBuffer.cpp:250
lvr2::MeshBuffer::m_textures
std::vector< Texture > m_textures
Vector containing all textures.
Definition: MeshBuffer.hpp:214
lvr2::BaseBuffer::getIndexArray
indexArray getIndexArray(const std::string &name, size_t &n, size_t &w)
Gets an index channel as array.
Definition: BaseBuffer.hpp:554
lvr2::MeshBuffer::setFaceMaterialIndices
void setFaceMaterialIndices(indexArray indices)
addFaceMaterialIndices Adds face material indices. The array references to material definitions in m_...
Definition: MeshBuffer.cpp:99
lvr2::MeshBuffer::getFaceIndices
indexArray getFaceIndices()
getFaceIndices Returns an array with face definitions, i.e., three vertex indices per face.
Definition: MeshBuffer.cpp:199
lvr2::MeshBuffer::getTextureCoordinates
floatArr getTextureCoordinates()
getTextureCoordinates Returns an array with texture coordinates. Two normalized floats per vertex....
Definition: MeshBuffer.cpp:192
lvr2::BaseBuffer
ChannelManager class Store and access AttributeChannels. It expands the MultiChannelMap with downwoar...
Definition: BaseBuffer.hpp:54
lvr2::MeshBuffer::getVertexNormals
floatArr getVertexNormals()
getVertexNormals Returns an array with vertex normals or an empty array if no normals are present.
Definition: MeshBuffer.cpp:178
lvr2::MeshBuffer::setFaceColors
void setFaceColors(ucharArr colors, size_t w=3)
addFaceColors Adds face colors the the buffer
Definition: MeshBuffer.cpp:125
lvr2::MeshBuffer::setFaceIndices
void setFaceIndices(indexArray indices, size_t n)
addFaceIndices Adds the face index array that references to the vertex array
Definition: MeshBuffer.cpp:91
lvr2::BaseBuffer::addUCharChannel
void addUCharChannel(UCharChannelPtr data, const std::string &name)
Adds an uchar channel pointer to the map.
Definition: BaseBuffer.hpp:169
scripts.create_png.colors
colors
Definition: create_png.py:41
MeshBuffer.hpp
lvr2::MeshBuffer::getTextures
std::vector< Texture > & getTextures()
getTextures Returns a vector with textures
Definition: MeshBuffer.cpp:220
lvr2::MeshBuffer::setFaceNormals
void setFaceNormals(floatArr normals)
addFaceNormals Adds face normal information. The number of normals in the array are exspected to matc...
Definition: MeshBuffer.cpp:112
lvr2::MeshBuffer::getMaterials
std::vector< Material > & getMaterials()
getTextures Returns a vector with materials
Definition: MeshBuffer.cpp:225
lvr2::MeshBuffer::hasVertexColors
bool hasVertexColors() const
Definition: MeshBuffer.cpp:260
lvr2::Channel
Definition: Channel.hpp:42
lvr2::BaseBuffer::getUCharArray
ucharArr getUCharArray(const std::string &name, size_t &n, size_t &w)
Gets an uchar channel as array.
Definition: BaseBuffer.hpp:541
lvr2::MeshBuffer::getVertexColors
ucharArr getVertexColors(size_t &width)
getVertexColors Returns vertex color information or an empty array if vertex colors are not available
Definition: MeshBuffer.cpp:171
lvr2::ucharArr
boost::shared_array< unsigned char > ucharArr
Definition: DataStruct.hpp:137
lvr2
Definition: BaseBufferManipulators.hpp:39
lvr2::BaseBuffer::addIndexChannel
void addIndexChannel(IndexChannelPtr data, const std::string &name)
Adds an index channel pointer to the map. cointer to add. cannel.
Definition: BaseBuffer.hpp:179
lvr2::MeshBuffer::hasFaceNormals
bool hasFaceNormals() const
Definition: MeshBuffer.cpp:270
lvr2::MeshBuffer::numFaces
size_t numFaces() const
numFaces Number of faces in the mesh
Definition: MeshBuffer.cpp:151
Timestamp.hpp
lvr2::BaseBuffer::addFloatChannel
void addFloatChannel(FloatChannelPtr data, const std::string &name)
Adds a float channel pointer to the map.
Definition: BaseBuffer.hpp:159
lvr2::MeshBuffer::hasFaces
bool hasFaces() const
Definition: MeshBuffer.cpp:240
lvr2::MeshBuffer::setVertices
void setVertices(floatArr vertices, size_t n)
addVertices Adds the vertex array. Three floats per vertex
Definition: MeshBuffer.cpp:44
lvr2::MeshBuffer::getFaceMaterialIndices
indexArray getFaceMaterialIndices()
getFaceMaterialIndices Returns an array with face material indices
Definition: MeshBuffer.cpp:213
lvr2::MeshBuffer::numVertices
size_t numVertices() const
numVertices Number of vertices in the mesh
Definition: MeshBuffer.cpp:138
lvr2::MeshBuffer::m_materials
std::vector< Material > m_materials
TODO: CHANNEL BASED SETTER / GETTER!
Definition: MeshBuffer.hpp:211
lvr2::MeshBuffer::getFaceNormals
floatArr getFaceNormals()
getFaceNormas Returns an array containing face normals, i.e., three float values per face.
Definition: MeshBuffer.cpp:185
lvr2::Channel::numElements
size_t numElements() const
lvr2::BaseBuffer::getFloatArray
floatArr getFloatArray(const std::string &name, size_t &n, size_t &w)
Gets a float channel as array.
Definition: BaseBuffer.hpp:528


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:24