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 }
void setFaceIndices(indexArray indices, size_t n)
addFaceIndices Adds the face index array that references to the vertex array
Definition: MeshBuffer.cpp:91
void setFaceNormals(floatArr normals)
addFaceNormals Adds face normal information. The number of normals in the array are exspected to matc...
Definition: MeshBuffer.cpp:112
ucharArr getFaceColors(size_t &width)
getFaceColors Returns an array with wrgb colors
Definition: MeshBuffer.cpp:206
std::vector< Material > & getMaterials()
getTextures Returns a vector with materials
Definition: MeshBuffer.cpp:225
floatArr getTextureCoordinates()
getTextureCoordinates Returns an array with texture coordinates. Two normalized floats per vertex...
Definition: MeshBuffer.cpp:192
void setVertexColors(ucharArr colors, size_t w=3)
addVertexColors Adds vertex color information.
Definition: MeshBuffer.cpp:65
std::vector< Texture > & getTextures()
getTextures Returns a vector with textures
Definition: MeshBuffer.cpp:220
void setTextureCoordinates(floatArr coordinates)
addTextureCoordinates Adds texture coordinates for vertices
Definition: MeshBuffer.cpp:78
ucharArr getVertexColors(size_t &width)
getVertexColors Returns vertex color information or an empty array if vertex colors are not available...
Definition: MeshBuffer.cpp:171
indexArray getFaceIndices()
getFaceIndices Returns an array with face definitions, i.e., three vertex indices per face...
Definition: MeshBuffer.cpp:199
boost::shared_array< unsigned char > ucharArr
Definition: DataStruct.hpp:137
floatArr getVertices()
getVertices Return the vertex array.
Definition: MeshBuffer.cpp:164
bool hasFaceNormals() const
Definition: MeshBuffer.cpp:270
UCharChannel::Optional UCharChannelOptional
Definition: Channel.hpp:96
std::vector< Texture > m_textures
Vector containing all textures.
Definition: MeshBuffer.hpp:214
void addFloatChannel(FloatChannelPtr data, const std::string &name)
Adds a float channel pointer to the map.
Definition: BaseBuffer.hpp:159
bool hasVertices() const
Definition: MeshBuffer.cpp:230
void setFaceMaterialIndices(indexArray indices)
addFaceMaterialIndices Adds face material indices. The array references to material definitions in m_...
Definition: MeshBuffer.cpp:99
bool hasVertexNormals() const
Definition: MeshBuffer.cpp:280
floatArr getFloatArray(const std::string &name, size_t &n, size_t &w)
Gets a float channel as array.
Definition: BaseBuffer.hpp:528
boost::shared_array< unsigned int > indexArray
Definition: DataStruct.hpp:128
ucharArr getUCharArray(const std::string &name, size_t &n, size_t &w)
Gets an uchar channel as array.
Definition: BaseBuffer.hpp:541
void addIndexChannel(IndexChannelPtr data, const std::string &name)
Adds an index channel pointer to the map. cointer to add. cannel.
Definition: BaseBuffer.hpp:179
boost::shared_array< float > floatArr
Definition: DataStruct.hpp:133
void setFaceColors(ucharArr colors, size_t w=3)
addFaceColors Adds face colors the the buffer
Definition: MeshBuffer.cpp:125
MeshBuffer()
MeshBuffer Contructor. Builds an empty buffer. Fill elements with add-Methods.
Definition: MeshBuffer.cpp:38
void addUCharChannel(UCharChannelPtr data, const std::string &name)
Adds an uchar channel pointer to the map.
Definition: BaseBuffer.hpp:169
size_t numFaces() const
numFaces Number of faces in the mesh
Definition: MeshBuffer.cpp:151
FloatChannel::Optional FloatChannelOptional
Definition: Channel.hpp:88
void setVertexNormals(floatArr normals)
addVertexNormals Adds vertex normals.
Definition: MeshBuffer.cpp:52
boost::optional< Channel< T > > Optional
Definition: Channel.hpp:45
indexArray getFaceMaterialIndices()
getFaceMaterialIndices Returns an array with face material indices
Definition: MeshBuffer.cpp:213
IndexChannel::Optional IndexChannelOptional
Definition: Channel.hpp:100
std::vector< Material > m_materials
TODO: CHANNEL BASED SETTER / GETTER!
Definition: MeshBuffer.hpp:211
bool hasVertexColors() const
Definition: MeshBuffer.cpp:260
void setVertices(floatArr vertices, size_t n)
addVertices Adds the vertex array. Three floats per vertex
Definition: MeshBuffer.cpp:44
bool hasFaceColors() const
Definition: MeshBuffer.cpp:250
size_t numElements() const
floatArr getFaceNormals()
getFaceNormas Returns an array containing face normals, i.e., three float values per face...
Definition: MeshBuffer.cpp:185
size_t numVertices() const
numVertices Number of vertices in the mesh
Definition: MeshBuffer.cpp:138
ChannelManager class Store and access AttributeChannels. It expands the MultiChannelMap with downwoar...
Definition: BaseBuffer.hpp:54
floatArr getVertexNormals()
getVertexNormals Returns an array with vertex normals or an empty array if no normals are present...
Definition: MeshBuffer.cpp:178
bool hasFaces() const
Definition: MeshBuffer.cpp:240
indexArray getIndexArray(const std::string &name, size_t &n, size_t &w)
Gets an index channel as array.
Definition: BaseBuffer.hpp:554


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 Mon Feb 28 2022 22:46:08