59 #ifndef OPENMESH_KERNEL_OSG_BINDT_HH 60 #define OPENMESH_KERNEL_OSG_BINDT_HH 69 #include <OpenMesh/Core/Mesh/TriMeshT.hh> 70 #include <OpenMesh/Core/Utils/color_cast.hh> 71 #include <OpenMesh/Tools/Utils/GLConstAsString.hh> 72 #include <OpenSG/OSGGeometry.h> 74 #include "color_cast.hh" 79 namespace Kernel_OSG {
85 bool type_is_valid(
unsigned char _t )
87 return _t == GL_TRIANGLES
88 || _t == GL_TRIANGLE_STRIP
100 template <
typename Mesh >
inline 103 _geo = _mesh.createGeometryPtr();
114 template <
typename Mesh >
inline 125 GeoPTypesPtr types = _geo->getTypes();
127 if ( (
size_t)count_if( types->getData(), types->getData()+types->size(),
128 ptr_fun(type_is_valid) ) != (
size_t)types->size() )
133 if ( _geo->getIndexMapping().getSize() > 1 )
135 omerr <<
"OpenMesh::Kernel_OSG::bind(): Multi-indexed geometry is not supported!\n";
142 GeoPLengthsPtr lengths = _geo->getLengths();
143 GeoIndicesPtr indices = _geo->getIndices();
144 GeoPositionsPtr pos = _geo->getPositions();
145 GeoNormalsPtr normals = _geo->getNormals();
146 GeoColorsPtr colors = _geo->getColors();
152 vector< VertexHandle > vhandles;
160 bool bind_normal = (normals!=NullFC) && _mesh.has_vertex_normals();
161 bool bind_color = (colors !=NullFC) && _mesh.has_vertex_colors();
163 for (bidx=0; bidx < pos->size(); ++bidx)
167 _mesh.set_normal(vh, normals->getValue(bidx));
169 _mesh.set_color(vh, color_cast<color_t>(colors->getValue(bidx)));
177 size_t max_bidx = indices != NullFC ? indices->size() : pos->size();
179 for (bidx=tidx=0; ok && tidx<types->size() && bidx < max_bidx; ++tidx)
181 switch( types->getValue(tidx) )
185 for(
size_t lidx=0; lidx < lengths->getValue(tidx)-2; lidx+=3)
187 if (indices == NullFC ) {
193 vhandles[0] =
VertexHandle(indices->getValue(bidx+lidx ) );
194 vhandles[1] =
VertexHandle(indices->getValue(bidx+lidx+1) );
195 vhandles[2] =
VertexHandle(indices->getValue(bidx+lidx+2) );
198 if ( !(fh = _mesh.add_face( vhandles )).is_valid() )
201 swap(vhandles[2], vhandles[1]);
202 fh = _mesh.add_face( vhandles );
208 case GL_TRIANGLE_STRIP:
210 for (
size_t lidx=0; lidx < lengths->getValue(tidx)-2; ++lidx)
212 if (indices == NullFC ) {
218 vhandles[0] =
VertexHandle(indices->getValue(bidx+lidx ) );
219 vhandles[1] =
VertexHandle(indices->getValue(bidx+lidx+1) );
220 vhandles[2] =
VertexHandle(indices->getValue(bidx+lidx+2) );
223 if (vhandles[0]!=vhandles[2] &&
224 vhandles[0]!=vhandles[1] &&
225 vhandles[1]!=vhandles[2])
231 swap(vhandles[2], vhandles[1]);
233 if ( !(fh = _mesh.add_face( vhandles )).is_valid() )
235 omlog <<
"OpenMesh::Kernel_OSG::bind(): complex entity!\n";
237 swap(vhandles[2], vhandles[1]);
238 fh = _mesh.add_face( vhandles );
248 for(
size_t nf=_mesh.n_faces(), lidx=0;
249 lidx < lengths->getValue(tidx)-3; lidx+=4)
251 if (indices == NullFC ) {
258 vhandles[0] =
VertexHandle(indices->getValue(bidx+lidx ) );
259 vhandles[1] =
VertexHandle(indices->getValue(bidx+lidx+1) );
260 vhandles[2] =
VertexHandle(indices->getValue(bidx+lidx+2) );
261 vhandles[3] =
VertexHandle(indices->getValue(bidx+lidx+3) );
264 fh = _mesh.add_face( vhandles );
265 ok = ( Mesh::Face::is_triangle() && (_mesh.n_faces()==(nf+2)))
267 nf = _mesh.n_faces();
273 size_t ne = lengths->getValue(tidx);
274 size_t nf = _mesh.n_faces();
278 for(
size_t lidx=0; lidx < ne; ++lidx)
279 vhandles[lidx] = (indices == NullFC)
283 fh = _mesh.add_face( vhandles );
284 ok = ( Mesh::Face::is_triangle() && (_mesh.n_faces()==nf+ne-2) )
290 cerr <<
"Warning! Skipping unsupported type " 291 << types->getValue(tidx) <<
" '" 292 << Utils::GLenum_as_string( types->getValue(tidx) ) <<
"'\n";
296 bidx += lengths->getValue(tidx);
312 #endif // OPENMESH_KERNEL_OSG_BINDT_HH defined Handle for a face entity.
Kernel::Color Color
Color type.
Handle for a vertex entity.
bool is_valid() const
The handle is valid iff the index is not negative.
bool bind(osg::GeometryPtr &_geo, Mesh &_mesh)
SmartVertexHandle add_vertex(const Point &_p)