PLYReader.cc 39.1 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
/* ========================================================================= *
Jan Möbius's avatar
Jan Möbius committed
2 3
 *                                                                           *
 *                               OpenMesh                                    *
Jan Möbius's avatar
Jan Möbius committed
4
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
Jan Möbius's avatar
Typo  
Jan Möbius committed
5
 *           Department of Computer Graphics and Multimedia                  *
Jan Möbius's avatar
Jan Möbius committed
6 7
 *                          All rights reserved.                             *
 *                            www.openmesh.org                               *
Jan Möbius's avatar
Jan Möbius committed
8
 *                                                                           *
Mike Kremer's avatar
Mike Kremer committed
9
 *---------------------------------------------------------------------------*
Jan Möbius's avatar
Jan Möbius committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 * This file is part of OpenMesh.                                            *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
 *                                                                           *
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
 *                                                                           *
 * 2. Redistributions in binary form must reproduce the above copyright      *
 *    notice, this list of conditions and the following disclaimer in the    *
 *    documentation and/or other materials provided with the distribution.   *
 *                                                                           *
 * 3. Neither the name of the copyright holder nor the names of its          *
 *    contributors may be used to endorse or promote products derived from   *
 *    this software without specific prior written permission.               *
 *                                                                           *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS       *
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A           *
 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,  *
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,       *
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR        *
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF    *
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING      *
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS        *
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.              *
Jan Möbius's avatar
Jan Möbius committed
39 40
 *                                                                           *
 * ========================================================================= */
41 42

/*===========================================================================*\
Mike Kremer's avatar
Mike Kremer committed
43
 *                                                                           *
44 45
 *   $Revision$                                                         *
 *   $Date$                   *
Jan Möbius's avatar
Jan Möbius committed
46
 *                                                                           *
Mike Kremer's avatar
Mike Kremer committed
47
 \*===========================================================================*/
Jan Möbius's avatar
Jan Möbius committed
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

#define LINE_LEN 4096

//== INCLUDES =================================================================

// OpenMesh
#include <OpenMesh/Core/System/config.h>
#include <OpenMesh/Core/System/omstream.hh>
#include <OpenMesh/Core/IO/reader/PLYReader.hh>
#include <OpenMesh/Core/IO/importer/BaseImporter.hh>
#include <OpenMesh/Core/IO/IOManager.hh>
#include <OpenMesh/Core/Utils/color_cast.hh>
#include <OpenMesh/Core/IO/SR_store.hh>

//STL
#include <fstream>
64
#include <iostream>
Jan Möbius's avatar
Jan Möbius committed
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
#include <memory>

#ifndef WIN32
#include <string.h>
#endif

//=== NAMESPACES ==============================================================


namespace OpenMesh {
namespace IO {

//=============================================================================

//=== INSTANCIATE =============================================================


Mike Kremer's avatar
Mike Kremer committed
82 83
_PLYReader_ __PLYReaderInstance;
_PLYReader_& PLYReader() {
84
    return __PLYReaderInstance;
Mike Kremer's avatar
Mike Kremer committed
85
}
Jan Möbius's avatar
Jan Möbius committed
86 87 88 89

//=== IMPLEMENTATION ==========================================================


Mike Kremer's avatar
Mike Kremer committed
90
_PLYReader_::_PLYReader_() {
91
    IOManager().register_module(this);
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110

    // Store sizes in byte of each property type
    scalar_size_[ValueTypeINT8] = 1;
    scalar_size_[ValueTypeUINT8] = 1;
    scalar_size_[ValueTypeINT16] = 2;
    scalar_size_[ValueTypeUINT16] = 2;
    scalar_size_[ValueTypeINT32] = 4;
    scalar_size_[ValueTypeUINT32] = 4;
    scalar_size_[ValueTypeFLOAT32] = 4;
    scalar_size_[ValueTypeFLOAT64] = 8;

    scalar_size_[ValueTypeCHAR] = 1;
    scalar_size_[ValueTypeUCHAR] = 1;
    scalar_size_[ValueTypeSHORT] = 2;
    scalar_size_[ValueTypeUSHORT] = 2;
    scalar_size_[ValueTypeINT] = 4;
    scalar_size_[ValueTypeUINT] = 4;
    scalar_size_[ValueTypeFLOAT] = 4;
    scalar_size_[ValueTypeDOUBLE] = 8;
Jan Möbius's avatar
Jan Möbius committed
111 112 113 114 115
}

//-----------------------------------------------------------------------------


Mike Kremer's avatar
Mike Kremer committed
116
bool _PLYReader_::read(const std::string& _filename, BaseImporter& _bi, Options& _opt) {
117

118
    std::fstream in(_filename.c_str(), (std::ios_base::binary | std::ios_base::in) );
Jan Möbius's avatar
Jan Möbius committed
119

120 121 122 123
    if (!in.is_open() || !in.good()) {
        omerr() << "[PLYReader] : cannot not open file " << _filename << std::endl;
        return false;
    }
Jan Möbius's avatar
Jan Möbius committed
124

125
    bool result = read(in, _bi, _opt);
Jan Möbius's avatar
Jan Möbius committed
126

127 128
    in.close();
    return result;
Jan Möbius's avatar
Jan Möbius committed
129 130 131 132 133
}

//-----------------------------------------------------------------------------


134 135 136 137 138 139 140
bool _PLYReader_::read(std::istream& _in, BaseImporter& _bi, Options& _opt) {

    if (!_in.good()) {
        omerr() << "[PLYReader] : cannot not use stream" << std::endl;
        return false;
    }

141 142
    // filter relevant options for reading
    bool swap = _opt.check(Options::Swap);
Jan Möbius's avatar
Jan Möbius committed
143

144
    userOptions_ = _opt;
Jan Möbius's avatar
Jan Möbius committed
145

146 147
    // build options to be returned
    _opt.clear();
Jan Möbius's avatar
Jan Möbius committed
148

149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
    if (options_.vertex_has_normal() && userOptions_.vertex_has_normal()) {
        _opt += Options::VertexNormal;
    }
    if (options_.vertex_has_texcoord() && userOptions_.vertex_has_texcoord()) {
        _opt += Options::VertexTexCoord;
    }
    if (options_.vertex_has_color() && userOptions_.vertex_has_color()) {
        _opt += Options::VertexColor;
    }
    if (options_.face_has_color() && userOptions_.face_has_color()) {
        _opt += Options::FaceColor;
    }
    if (options_.is_binary()) {
        _opt += Options::Binary;
    }
164 165 166
    if (options_.color_is_float()) {
        _opt += Options::ColorFloat;
    }
167 168 169
    if (options_.check(Options::Custom) && userOptions_.check(Options::Custom)) {
        _opt += Options::Custom;
    }
Jan Möbius's avatar
Jan Möbius committed
170

171 172 173
    //    //force user-choice for the alpha value when reading binary
    //    if ( options_.is_binary() && userOptions_.color_has_alpha() )
    //      options_ += Options::ColorAlpha;
Jan Möbius's avatar
Jan Möbius committed
174

175
    return (options_.is_binary() ? read_binary(_in, _bi, swap, _opt) : read_ascii(_in, _bi, _opt));
Jan Möbius's avatar
Jan Möbius committed
176 177 178

}

Matthias Möller's avatar
Matthias Möller committed
179 180 181
template<typename T, typename Handle>
struct Handle2Prop;

182
template<typename T>
Matthias Möller's avatar
Matthias Möller committed
183
struct Handle2Prop<T,VertexHandle>
184
{
Matthias Möller's avatar
Matthias Möller committed
185 186
  typedef OpenMesh::VPropHandleT<T> PropT;
};
187

Matthias Möller's avatar
Matthias Möller committed
188 189 190 191 192
template<typename T>
struct Handle2Prop<T,FaceHandle>
{
  typedef OpenMesh::FPropHandleT<T> PropT;
};
193

Matthias Möller's avatar
Matthias Möller committed
194 195
template<typename T, typename Handle>
void assignCustomProperty(std::istream& _in, BaseImporter& _bi, Handle _h, const std::string& _propName, bool isList)
196
{
Matthias Möller's avatar
Matthias Möller committed
197 198 199 200 201
  if (!isList)
  {
    //get/add property
    typename Handle2Prop<T,Handle>::PropT prop;
    if (!_bi.kernel()->get_property_handle(prop,_propName))
202
    {
Matthias Möller's avatar
Matthias Möller committed
203
      _bi.kernel()->add_property(prop,_propName);
204 205
      _bi.kernel()->property(prop).set_persistent(true);
    }
Matthias Möller's avatar
Matthias Möller committed
206 207 208 209 210 211 212 213 214 215 216

    //read and assign
    T in;
    _in >> in;
    _bi.kernel()->property(prop,_h) = in;
  }
  else
  {
    //get/add property
    typename Handle2Prop<std::vector<T>,Handle>::PropT prop;
    if (!_bi.kernel()->get_property_handle(prop,_propName))
217
    {
Matthias Möller's avatar
Matthias Möller committed
218
      _bi.kernel()->add_property(prop,_propName);
219 220
      _bi.kernel()->property(prop).set_persistent(true);
    }
Matthias Möller's avatar
Matthias Möller committed
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241

    //init vector
    int numberOfValues;
    _in >> numberOfValues;
    std::vector<T> vec;
    vec.reserve(numberOfValues);
    //read and assign
    for (int i = 0; i < numberOfValues; ++i)
    {
      T in;
      _in >> in;
      vec.push_back(in);
    }
    _bi.kernel()->property(prop,_h) = vec;
  }
}

template<typename Handle>
void _PLYReader_::readCustomProperty(std::istream& _in, BaseImporter& _bi, Handle _h, const std::string& _propName, const ValueType _valueType, const ValueType _listIndexType) const
{
  const bool isList = _listIndexType != Unsupported;
242 243 244 245
  switch (_valueType)
  {
  case ValueTypeINT8:
  case ValueTypeCHAR:
246
      assignCustomProperty<signed char>(_in,_bi,_h,_propName,isList);
247
      break;
248 249 250 251
  case ValueTypeUINT8:
  case ValueTypeUCHAR:
      assignCustomProperty<unsigned char>(_in,_bi,_h,_propName,isList);
      break;
252 253
  case ValueTypeINT16:
  case ValueTypeSHORT:
Matthias Möller's avatar
Matthias Möller committed
254
      assignCustomProperty<short>(_in,_bi,_h,_propName,isList);
255 256 257
      break;
  case ValueTypeUINT16:
  case ValueTypeUSHORT:
Matthias Möller's avatar
Matthias Möller committed
258
      assignCustomProperty<unsigned short>(_in,_bi,_h,_propName,isList);
259 260 261
      break;
  case ValueTypeINT32:
  case ValueTypeINT:
Matthias Möller's avatar
Matthias Möller committed
262
      assignCustomProperty<int>(_in,_bi,_h,_propName,isList);
263 264 265
      break;
  case ValueTypeUINT32:
  case ValueTypeUINT:
Matthias Möller's avatar
Matthias Möller committed
266
      assignCustomProperty<unsigned int>(_in,_bi,_h,_propName,isList);
267 268 269
      break;
  case ValueTypeFLOAT32:
  case ValueTypeFLOAT:
Matthias Möller's avatar
Matthias Möller committed
270
      assignCustomProperty<float>(_in,_bi,_h,_propName,isList);
271 272 273
      break;
  case ValueTypeFLOAT64:
  case ValueTypeDOUBLE:
Matthias Möller's avatar
Matthias Möller committed
274
      assignCustomProperty<double>(_in,_bi,_h,_propName,isList);
275 276 277 278 279 280
      break;
  default:
      std::cerr << "unsupported type" << std::endl;
      break;
  }
}
281 282


Jan Möbius's avatar
Jan Möbius committed
283 284
//-----------------------------------------------------------------------------

285
bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi, const Options& _opt) const {
Mike Kremer's avatar
Mike Kremer committed
286

287 288 289 290 291 292 293 294
    // Reparse the header
    if (!can_u_read(_in)) {
        omerr() << "[PLYReader] : Unable to parse header\n";
        return false;
    }

    unsigned int i, j, k, l, idx;
    unsigned int nV;
Jan Möbius's avatar
Jan Möbius committed
295
    OpenMesh::Vec3f v, n;
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
    std::string trash;
    OpenMesh::Vec2f t;
    OpenMesh::Vec4i c;
    float tmp;
    BaseImporter::VHandles vhandles;
    VertexHandle vh;

    _bi.reserve(vertexCount_, 3* vertexCount_ , faceCount_);

    if (vertexDimension_ != 3) {
        omerr() << "[PLYReader] : Only vertex dimension 3 is supported." << std::endl;
        return false;
    }

    // read vertices:
    for (i = 0; i < vertexCount_ && !_in.eof(); ++i) {
312 313
        vh = _bi.add_vertex();

314 315 316 317
        v[0] = 0.0;
        v[1] = 0.0;
        v[2] = 0.0;

Jan Möbius's avatar
Jan Möbius committed
318 319 320 321
        n[0] = 0.0;
        n[1] = 0.0;
        n[2] = 0.0;

322 323 324 325 326 327 328 329
        t[0] = 0.0;
        t[1] = 0.0;

        c[0] = 0;
        c[1] = 0;
        c[2] = 0;
        c[3] = 255;

Matthias Möller's avatar
Matthias Möller committed
330 331
        for (size_t propertyIndex = 0; propertyIndex < vertexProperties_.size(); ++propertyIndex) {
            switch (vertexProperties_[propertyIndex].property) {
332 333 334 335 336 337 338 339 340
            case XCOORD:
                _in >> v[0];
                break;
            case YCOORD:
                _in >> v[1];
                break;
            case ZCOORD:
                _in >> v[2];
                break;
Jan Möbius's avatar
Jan Möbius committed
341 342 343 344 345 346 347 348 349
            case XNORM:
                _in >> n[0];
                break;
            case YNORM:
                _in >> n[1];
                break;
            case ZNORM:
                _in >> n[2];
                break;
350 351 352 353 354 355 356
            case TEXX:
                _in >> t[0];
                break;
            case TEXY:
                _in >> t[1];
                break;
            case COLORRED:
Matthias Möller's avatar
Matthias Möller committed
357 358
                if (vertexProperties_[propertyIndex].value == ValueTypeFLOAT32 ||
                    vertexProperties_[propertyIndex].value == ValueTypeFLOAT) {
359 360 361 362 363 364
                    _in >> tmp;
                    c[0] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
                } else
                    _in >> c[0];
                break;
            case COLORGREEN:
Matthias Möller's avatar
Matthias Möller committed
365 366
                if (vertexProperties_[propertyIndex].value == ValueTypeFLOAT32 ||
                    vertexProperties_[propertyIndex].value == ValueTypeFLOAT) {
367 368 369 370 371 372
                    _in >> tmp;
                    c[1] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
                } else
                    _in >> c[1];
                break;
            case COLORBLUE:
Matthias Möller's avatar
Matthias Möller committed
373 374
                if (vertexProperties_[propertyIndex].value == ValueTypeFLOAT32 ||
                    vertexProperties_[propertyIndex].value == ValueTypeFLOAT) {
375 376 377 378 379 380
                    _in >> tmp;
                    c[2] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
                } else
                    _in >> c[2];
                break;
            case COLORALPHA:
Matthias Möller's avatar
Matthias Möller committed
381 382
                if (vertexProperties_[propertyIndex].value == ValueTypeFLOAT32 ||
                    vertexProperties_[propertyIndex].value == ValueTypeFLOAT) {
383 384 385 386 387
                    _in >> tmp;
                    c[3] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
                } else
                    _in >> c[3];
                break;
388 389
            case CUSTOM_PROP:
                if (_opt.check(Options::Custom))
Matthias Möller's avatar
Matthias Möller committed
390
                  readCustomProperty(_in, _bi, vh, vertexProperties_[propertyIndex].name, vertexProperties_[propertyIndex].value, vertexProperties_[propertyIndex].listIndexType);
391 392 393
                else
                  _in >> trash;
                break;
394 395 396 397 398 399
            default:
                _in >> trash;
                break;
            }
        }

400
        _bi.set_point(vh, v);
401 402 403 404 405 406
        if (_opt.vertex_has_normal())
          _bi.set_normal(vh, n);
        if (_opt.vertex_has_texcoord())
          _bi.set_texcoord(vh, t);
        if (_opt.vertex_has_color())
          _bi.set_color(vh, Vec4uc(c));
407 408 409 410
    }

    // faces
    for (i = 0; i < faceCount_; ++i) {
Matthias Möller's avatar
Matthias Möller committed
411 412 413 414
      FaceHandle fh;
      for (size_t propertyIndex = 0; propertyIndex < faceProperties_.size(); ++propertyIndex) {
        PropertyInfo prop = faceProperties_[propertyIndex];
        switch (prop.property) {
415

Matthias Möller's avatar
Matthias Möller committed
416 417 418 419 420
        case VERTEX_INDICES:
          // nV = number of Vertices for current face
          _in >> nV;

          if (nV == 3) {
421 422 423 424 425 426 427 428
            vhandles.resize(3);
            _in >> j;
            _in >> k;
            _in >> l;

            vhandles[0] = VertexHandle(j);
            vhandles[1] = VertexHandle(k);
            vhandles[2] = VertexHandle(l);
Matthias Möller's avatar
Matthias Möller committed
429
          } else {
430 431
            vhandles.clear();
            for (j = 0; j < nV; ++j) {
Matthias Möller's avatar
Matthias Möller committed
432 433
              _in >> idx;
              vhandles.push_back(VertexHandle(idx));
434
            }
Matthias Möller's avatar
Matthias Möller committed
435
          }
436

Matthias Möller's avatar
Matthias Möller committed
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
          fh = _bi.add_face(vhandles);
          break;

        case CUSTOM_PROP:
          if (_opt.check(Options::Custom) && fh.is_valid())
            readCustomProperty(_in, _bi, fh, prop.name, prop.value, prop.listIndexType);
          else
            _in >> trash;
          break;

        default:
          _in >> trash;
          break;
        }
      }
452 453 454 455 456

    }

    // File was successfully parsed.
    return true;
Jan Möbius's avatar
Jan Möbius committed
457 458 459 460
}

//-----------------------------------------------------------------------------

461
bool _PLYReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap*/, const Options& _opt) const {
Mike Kremer's avatar
Mike Kremer committed
462

463 464 465 466 467 468
    // Reparse the header
    if (!can_u_read(_in)) {
        omerr() << "[PLYReader] : Unable to parse header\n";
        return false;
    }

469 470
    OpenMesh::Vec3f        v, n;  // Vertex
    OpenMesh::Vec2f        t;  // TexCoords
471
    BaseImporter::VHandles vhandles;
472 473 474
    VertexHandle           vh;
    OpenMesh::Vec4i        c;  // Color
    float                  tmp;
475 476 477 478

    _bi.reserve(vertexCount_, 3* vertexCount_ , faceCount_);

    // read vertices:
Matthias Möller's avatar
Matthias Möller committed
479
    for (unsigned int i = 0; i < vertexCount_ && !_in.eof(); ++i) {
480 481 482 483
        v[0] = 0.0;
        v[1] = 0.0;
        v[2] = 0.0;

Jan Möbius's avatar
Jan Möbius committed
484 485 486 487
        n[0] = 0.0;
        n[1] = 0.0;
        n[2] = 0.0;

488 489 490 491 492 493 494 495
        t[0] = 0.0;
        t[1] = 0.0;

        c[0] = 0;
        c[1] = 0;
        c[2] = 0;
        c[3] = 255;

Matthias Möller's avatar
Matthias Möller committed
496 497
        for (size_t propertyIndex = 0; propertyIndex < vertexProperties_.size(); ++propertyIndex) {
            switch (vertexProperties_[propertyIndex].property) {
498
            case XCOORD:
Matthias Möller's avatar
Matthias Möller committed
499
                readValue(vertexProperties_[propertyIndex].value, _in, v[0]);
500 501
                break;
            case YCOORD:
Matthias Möller's avatar
Matthias Möller committed
502
                readValue(vertexProperties_[propertyIndex].value, _in, v[1]);
503 504
                break;
            case ZCOORD:
Matthias Möller's avatar
Matthias Möller committed
505
                readValue(vertexProperties_[propertyIndex].value, _in, v[2]);
506
                break;
Jan Möbius's avatar
Jan Möbius committed
507
            case XNORM:
Matthias Möller's avatar
Matthias Möller committed
508
                readValue(vertexProperties_[propertyIndex].value, _in, n[0]);
Jan Möbius's avatar
Jan Möbius committed
509 510
                break;
            case YNORM:
Matthias Möller's avatar
Matthias Möller committed
511
                readValue(vertexProperties_[propertyIndex].value, _in, n[1]);
Jan Möbius's avatar
Jan Möbius committed
512 513
                break;
            case ZNORM:
Matthias Möller's avatar
Matthias Möller committed
514
                readValue(vertexProperties_[propertyIndex].value, _in, n[2]);
Jan Möbius's avatar
Jan Möbius committed
515
                break;
516
            case TEXX:
Matthias Möller's avatar
Matthias Möller committed
517
                readValue(vertexProperties_[propertyIndex].value, _in, t[0]);
518 519
                break;
            case TEXY:
Matthias Möller's avatar
Matthias Möller committed
520
                readValue(vertexProperties_[propertyIndex].value, _in, t[1]);
521 522
                break;
            case COLORRED:
Matthias Möller's avatar
Matthias Möller committed
523 524 525
                if (vertexProperties_[propertyIndex].value == ValueTypeFLOAT32 ||
                    vertexProperties_[propertyIndex].value == ValueTypeFLOAT) {
                    readValue(vertexProperties_[propertyIndex].value, _in, tmp);
526 527 528

                    c[0] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
                } else
Matthias Möller's avatar
Matthias Möller committed
529
                    readInteger(vertexProperties_[propertyIndex].value, _in, c[0]);
530

531 532
                break;
            case COLORGREEN:
Matthias Möller's avatar
Matthias Möller committed
533 534 535
                if (vertexProperties_[propertyIndex].value == ValueTypeFLOAT32 ||
                    vertexProperties_[propertyIndex].value == ValueTypeFLOAT) {
                    readValue(vertexProperties_[propertyIndex].value, _in, tmp);
536 537
                    c[1] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
                } else
Matthias Möller's avatar
Matthias Möller committed
538
                    readInteger(vertexProperties_[propertyIndex].value, _in, c[1]);
539

540 541
                break;
            case COLORBLUE:
Matthias Möller's avatar
Matthias Möller committed
542 543 544
                if (vertexProperties_[propertyIndex].value == ValueTypeFLOAT32 ||
                    vertexProperties_[propertyIndex].value == ValueTypeFLOAT) {
                    readValue(vertexProperties_[propertyIndex].value, _in, tmp);
545 546
                    c[2] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
                } else
Matthias Möller's avatar
Matthias Möller committed
547
                    readInteger(vertexProperties_[propertyIndex].value, _in, c[2]);
548

549 550
                break;
            case COLORALPHA:
Matthias Möller's avatar
Matthias Möller committed
551 552 553
                if (vertexProperties_[propertyIndex].value == ValueTypeFLOAT32 ||
                    vertexProperties_[propertyIndex].value == ValueTypeFLOAT) {
                    readValue(vertexProperties_[propertyIndex].value, _in, tmp);
554 555
                    c[3] = static_cast<OpenMesh::Vec4i::value_type> (tmp * 255.0f);
                } else
Matthias Möller's avatar
Matthias Möller committed
556
                    readInteger(vertexProperties_[propertyIndex].value, _in, c[3]);
557

558 559
                break;
            default:
560
                // Read unsupported property
Matthias Möller's avatar
Matthias Möller committed
561
                consume_input(_in, scalar_size_[vertexProperties_[propertyIndex].value]);
562 563 564 565 566 567
                break;
            }

        }

        vh = _bi.add_vertex(v);
568 569 570 571 572 573
        if (_opt.vertex_has_normal())
          _bi.set_normal(vh, n);
        if (_opt.vertex_has_texcoord())
          _bi.set_texcoord(vh, t);
        if (_opt.vertex_has_color())
          _bi.set_color(vh, Vec4uc(c));
574 575
    }

Matthias Möller's avatar
Matthias Möller committed
576 577
    if(!faceProperties_.empty())
    {
Matthias Möller's avatar
Matthias Möller committed
578
      for (unsigned int i = 0; i < faceCount_; ++i) {
579
        // Read number of vertices for the current face
Matthias Möller's avatar
Matthias Möller committed
580
        unsigned int nV;
Matthias Möller's avatar
Matthias Möller committed
581
        readValue(faceProperties_[0].listIndexType, _in, nV);
582 583

        if (nV == 3) {
Matthias Möller's avatar
Matthias Möller committed
584
          vhandles.resize(3);
Matthias Möller's avatar
Matthias Möller committed
585
          unsigned int j,k,l;
Matthias Möller's avatar
Matthias Möller committed
586 587 588 589 590 591 592
          readInteger(faceProperties_[0].value, _in, j);
          readInteger(faceProperties_[0].value, _in, k);
          readInteger(faceProperties_[0].value, _in, l);

          vhandles[0] = VertexHandle(j);
          vhandles[1] = VertexHandle(k);
          vhandles[2] = VertexHandle(l);
593
        } else {
Matthias Möller's avatar
Matthias Möller committed
594
          vhandles.clear();
Matthias Möller's avatar
Matthias Möller committed
595 596
          for (unsigned int j = 0; j < nV; ++j) {
            unsigned int idx;
Matthias Möller's avatar
Matthias Möller committed
597 598 599
            readInteger(faceProperties_[0].value, _in, idx);
            vhandles.push_back(VertexHandle(idx));
          }
600 601
        }

Jan Möbius's avatar
Jan Möbius committed
602
        _bi.add_face(vhandles);
Matthias Möller's avatar
Matthias Möller committed
603
      }
604 605 606
    }

    return true;
Jan Möbius's avatar
Jan Möbius committed
607 608 609
}


610 611 612
//-----------------------------------------------------------------------------


613
void _PLYReader_::readValue(ValueType _type, std::istream& _in, float& _value) const {
614

615 616 617 618 619 620 621 622 623 624 625 626
    switch (_type) {
    case ValueTypeFLOAT32:
    case ValueTypeFLOAT:
        float32_t tmp;
        restore(_in, tmp, options_.check(Options::MSB));
        _value = tmp;
        break;
    default:
        _value = 0.0;
        std::cerr << "unsupported conversion type to float: " << _type << std::endl;
        break;
    }
627 628
}

629 630 631 632 633 634 635

//-----------------------------------------------------------------------------


void _PLYReader_::readValue(ValueType _type, std::istream& _in, double& _value) const {

    switch (_type) {
636

637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
        case ValueTypeFLOAT64:

        case ValueTypeDOUBLE:

            float64_t tmp;
            restore(_in, tmp, options_.check(Options::MSB));
            _value = tmp;

            break;

    default:

        _value = 0.0;
        std::cerr << "unsupported conversion type to double: " << _type << std::endl;

        break;
    }
}


//-----------------------------------------------------------------------------


660
void _PLYReader_::readValue(ValueType _type, std::istream& _in, unsigned int& _value) const {
661

662 663
    uint32_t tmp_uint32_t;
    uint16_t tmp_uint16_t;
664 665 666
    uint8_t tmp_uchar;

    switch (_type) {
667 668 669 670

        case ValueTypeUINT:

        case ValueTypeUINT32:
671

672 673 674
            restore(_in, tmp_uint32_t, options_.check(Options::MSB));
            _value = tmp_uint32_t;

675
        break;
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700

        case ValueTypeUSHORT:

        case ValueTypeUINT16:

            restore(_in, tmp_uint16_t, options_.check(Options::MSB));
            _value = tmp_uint16_t;

            break;

        case ValueTypeUCHAR:

        case ValueTypeUINT8:

            restore(_in, tmp_uchar, options_.check(Options::MSB));
            _value = tmp_uchar;

            break;

        default:

            _value = 0;
            std::cerr << "unsupported conversion type to unsigned int: " << _type << std::endl;

            break;
701
    }
702 703
}

704 705 706 707

//-----------------------------------------------------------------------------


708
void _PLYReader_::readValue(ValueType _type, std::istream& _in, int& _value) const {
709

710
    int32_t tmp_int32_t;
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760
    int16_t tmp_int16_t;
    int8_t tmp_char;

    switch (_type) {

        case ValueTypeINT:

        case ValueTypeINT32:

            restore(_in, tmp_int32_t, options_.check(Options::MSB));
            _value = tmp_int32_t;

            break;

        case ValueTypeSHORT:

        case ValueTypeINT16:

            restore(_in, tmp_int16_t, options_.check(Options::MSB));
            _value = tmp_int16_t;

            break;

        case ValueTypeCHAR:

        case ValueTypeINT8:

            restore(_in, tmp_char, options_.check(Options::MSB));
            _value = tmp_char;

            break;

        default:

            _value = 0;
            std::cerr << "unsupported conversion type to int: " << _type << std::endl;

            break;
    }
}


//-----------------------------------------------------------------------------


void _PLYReader_::readInteger(ValueType _type, std::istream& _in, int& _value) const {

    int32_t tmp_int32_t;
    uint32_t tmp_uint32_t;
    int8_t tmp_char;
761 762 763
    uint8_t tmp_uchar;

    switch (_type) {
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779

        case ValueTypeINT:

        case ValueTypeINT32:

            restore(_in, tmp_int32_t, options_.check(Options::MSB));
            _value = tmp_int32_t;

            break;

        case ValueTypeUINT:

        case ValueTypeUINT32:

            restore(_in, tmp_uint32_t, options_.check(Options::MSB));
            _value = tmp_uint32_t;
780

781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806
            break;

        case ValueTypeCHAR:

        case ValueTypeINT8:

            restore(_in, tmp_char, options_.check(Options::MSB));
            _value = tmp_char;

            break;

        case ValueTypeUCHAR:

        case ValueTypeUINT8:

            restore(_in, tmp_uchar, options_.check(Options::MSB));
            _value = tmp_uchar;

            break;

        default:

            _value = 0;
            std::cerr << "unsupported conversion type to int: " << _type << std::endl;

            break;
807
    }
808 809
}

810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868

//-----------------------------------------------------------------------------


void _PLYReader_::readInteger(ValueType _type, std::istream& _in, unsigned int& _value) const {

    int32_t tmp_int32_t;
    uint32_t tmp_uint32_t;
    int8_t tmp_char;
    uint8_t tmp_uchar;

    switch (_type) {

        case ValueTypeUINT:

        case ValueTypeUINT32:

            restore(_in, tmp_uint32_t, options_.check(Options::MSB));
            _value = tmp_uint32_t;

            break;

        case ValueTypeINT:

        case ValueTypeINT32:

            restore(_in, tmp_int32_t, options_.check(Options::MSB));
            _value = tmp_int32_t;

            break;

        case ValueTypeUCHAR:

        case ValueTypeUINT8:

            restore(_in, tmp_uchar, options_.check(Options::MSB));
            _value = tmp_uchar;

            break;

        case ValueTypeCHAR:

        case ValueTypeINT8:

            restore(_in, tmp_char, options_.check(Options::MSB));
            _value = tmp_char;

            break;

        default:

            _value = 0;
            std::cerr << "unsupported conversion type to unsigned int: " << _type << std::endl;

            break;
    }
}


869 870
//------------------------------------------------------------------------------

871

Mike Kremer's avatar
Mike Kremer committed
872
bool _PLYReader_::can_u_read(const std::string& _filename) const {
873

874 875 876 877 878 879 880 881 882 883 884
    // !!! Assuming BaseReader::can_u_parse( std::string& )
    // does not call BaseReader::read_magic()!!!

    if (BaseReader::can_u_read(_filename)) {
        std::ifstream ifs(_filename.c_str());
        if (ifs.is_open() && can_u_read(ifs)) {
            ifs.close();
            return true;
        }
    }
    return false;
Jan Möbius's avatar
Jan Möbius committed
885 886
}

887 888


Jan Möbius's avatar
Jan Möbius committed
889 890
//-----------------------------------------------------------------------------

Mike Kremer's avatar
Mike Kremer committed
891
std::string get_property_name(std::string _string1, std::string _string2) {
892

893 894 895 896
    if (_string1 == "float32" || _string1 == "float64" || _string1 == "float" || _string1 == "double" ||
        _string1 == "int8" || _string1 == "uint8" || _string1 == "char" || _string1 == "uchar" ||
        _string1 == "int32" || _string1 == "uint32" || _string1 == "int" || _string1 == "uint" ||
        _string1 == "int16" || _string1 == "uint16" || _string1 == "short" || _string1 == "ushort")
897
        return _string2;
Mike Kremer's avatar
Mike Kremer committed
898

899 900 901 902
    if (_string2 == "float32" || _string2 == "float64" || _string2 == "float" || _string2 == "double" ||
        _string2 == "int8" || _string2 == "uint8" || _string2 == "char" || _string2 == "uchar" ||
        _string2 == "int32" || _string2 == "uint32" || _string2 == "int" || _string2 == "uint" ||
        _string2 == "int16" || _string2 == "uint16" || _string2 == "short" || _string2 == "ushort")
903
        return _string1;
Mike Kremer's avatar
Mike Kremer committed
904

905

906 907
    std::cerr << "Unsupported entry type" << std::endl;
    return "Unsupported";
Jan Möbius's avatar
Jan Möbius committed
908 909 910 911
}

//-----------------------------------------------------------------------------

Mike Kremer's avatar
Mike Kremer committed
912
_PLYReader_::ValueType get_property_type(std::string _string1, std::string _string2) {
913

914
    if (_string1 == "float32" || _string2 == "float32")
915

916
        return _PLYReader_::ValueTypeFLOAT32;
917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935

    else if (_string1 == "float64" || _string2 == "float64")

        return _PLYReader_::ValueTypeFLOAT64;

    else if (_string1 == "float" || _string2 == "float")

        return _PLYReader_::ValueTypeFLOAT;

    else if (_string1 == "double" || _string2 == "double")

        return _PLYReader_::ValueTypeDOUBLE;

    else if (_string1 == "int8" || _string2 == "int8")

        return _PLYReader_::ValueTypeINT8;

    else if (_string1 == "uint8" || _string2 == "uint8")

936
        return _PLYReader_::ValueTypeUINT8;
937 938 939 940 941

    else if (_string1 == "char" || _string2 == "char")

        return _PLYReader_::ValueTypeCHAR;

942
    else if (_string1 == "uchar" || _string2 == "uchar")
943

944
        return _PLYReader_::ValueTypeUCHAR;
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976

    else if (_string1 == "int32" || _string2 == "int32")

        return _PLYReader_::ValueTypeINT32;

    else if (_string1 == "uint32" || _string2 == "uint32")

        return _PLYReader_::ValueTypeUINT32;

    else if (_string1 == "int" || _string2 == "int")

        return _PLYReader_::ValueTypeINT;

    else if (_string1 == "uint" || _string2 == "uint")

        return _PLYReader_::ValueTypeUINT;

    else if (_string1 == "int16" || _string2 == "int16")

        return _PLYReader_::ValueTypeINT16;

    else if (_string1 == "uint16" || _string2 == "uint16")

        return _PLYReader_::ValueTypeUINT16;

    else if (_string1 == "short" || _string2 == "short")

        return _PLYReader_::ValueTypeSHORT;

    else if (_string1 == "ushort" || _string2 == "ushort")

        return _PLYReader_::ValueTypeUSHORT;
977 978

    return _PLYReader_::Unsupported;
Jan Möbius's avatar
Jan Möbius committed
979 980
}

981

Jan Möbius's avatar
Jan Möbius committed
982 983
//-----------------------------------------------------------------------------

Mike Kremer's avatar
Mike Kremer committed
984
bool _PLYReader_::can_u_read(std::istream& _is) const {
985

986 987 988
    // Clear per file options
    options_.cleanup();

Matthias Möller's avatar
Matthias Möller committed
989 990 991
    // clear property maps, will be recreated
    vertexProperties_.clear();
    faceProperties_.clear();
992 993 994 995

    // read 1st line
    std::string line;
    std::getline(_is, line);
996
    trim(line);
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027

    //Check if this file is really a ply format
    if (line != "PLY" && line != "ply")
        return false;

    vertexCount_ = 0;
    faceCount_ = 0;
    vertexDimension_ = 0;

    std::string keyword;
    std::string fileType;
    std::string elementName = "";
    std::string propertyName;
    std::string listIndexType;
    std::string listEntryType;
    float version;

    _is >> keyword;
    _is >> fileType;
    _is >> version;

    if (_is.bad()) {
        omerr() << "Defect PLY header detected" << std::endl;
        return false;
    }

    if (fileType == "ascii") {
        options_ -= Options::Binary;
    } else if (fileType == "binary_little_endian") {
        options_ += Options::Binary;
        options_ += Options::LSB;
1028 1029 1030
        //if (Endian::local() == Endian::MSB)

        //  options_ += Options::Swap;
1031 1032 1033
    } else if (fileType == "binary_big_endian") {
        options_ += Options::Binary;
        options_ += Options::MSB;
1034 1035 1036
        //if (Endian::local() == Endian::LSB)

        //  options_ += Options::Swap;
1037 1038 1039 1040 1041
    } else {
        omerr() << "Unsupported PLY format: " << fileType << std::endl;
        return false;
    }

Matthias Möller's avatar
Matthias Möller committed
1042
    std::streamoff streamPos = _is.tellg();
1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
    _is >> keyword;
    while (keyword != "end_header") {

        if (keyword == "comment") {
            std::getline(_is, line);
        } else if (keyword == "element") {
            _is >> elementName;
            if (elementName == "vertex") {
                _is >> vertexCount_;
            } else if (elementName == "face") {
                _is >> faceCount_;
            } else {
                omerr() << "PLY header unsupported element type: " << elementName << std::endl;
            }
        } else if (keyword == "property") {
            std::string tmp1;
            std::string tmp2;

            // Read first keyword, as it might be a list
            _is >> tmp1;

            if (tmp1 == "list") {
Matthias Möller's avatar
Matthias Möller committed
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
              _is >> listIndexType;
              _is >> listEntryType;
              _is >> propertyName;

              ValueType indexType = Unsupported;
              ValueType entryType = Unsupported;

              if (listIndexType == "uint8") {
                indexType = ValueTypeUINT8;
              } else if (listIndexType == "uchar") {
                indexType = ValueTypeUCHAR;
              } else {
                omerr() << "Unsupported Index type for property list: " << listIndexType << std::endl;
                continue;
              }

              entryType = get_property_type(listEntryType, listEntryType);

              if (entryType == Unsupported) {
                omerr() << "Unsupported Entry type for property list: " << listEntryType << std::endl;
              }

                PropertyInfo property(CUSTOM_PROP, entryType, propertyName);
                property.listIndexType = indexType;

                // just 2 elements supported by now
                if (elementName == "vertex" && !options_.is_binary())
                {
                  vertexProperties_.push_back(property);
1094
                }
Matthias Möller's avatar
Matthias Möller committed
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104
                else if (elementName == "face")
                {
                  // special case for vertex indices, also needed by the binary version
                  if (propertyName == "vertex_index" || propertyName == "vertex_indices")
                  {
                    property.property = VERTEX_INDICES;
                    if (!faceProperties_.empty())
                    {
                      omerr() << "Custom face Properties defined, before 'vertex_indices' property was defined. They will be skipped" << std::endl;
                      faceProperties_.clear();
1105
                    }
Matthias Möller's avatar
Matthias Möller committed
1106 1107 1108 1109 1110 1111 1112 1113
                    faceProperties_.push_back(property);
                  }else
                  {
                    if (!options_.is_binary())
                      faceProperties_.push_back(property);
                    else
                      omerr() << "Custom list properties per face not supported with binary files" << std::endl;
                  }
1114

Matthias Möller's avatar
Matthias Möller committed
1115 1116 1117
                }
                else
                  omerr() << "property " << propertyName << " belongs to unsupported element " << elementName << std::endl;
1118

Matthias Möller's avatar
Matthias Möller committed
1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
            } else {
              // as this is not a list property, read second value of property
              _is >> tmp2;


              // Extract name and type of property
              // As the order seems to be different in some files, autodetect it.
              ValueType valueType = get_property_type(tmp1, tmp2);
              propertyName = get_property_name(tmp1, tmp2);

              PropertyInfo entry;

              //special treatment for some vertex properties.
              if (elementName == "vertex") {
                if (propertyName == "x") {
                  entry = PropertyInfo(XCOORD, valueType);
                  vertexDimension_++;
                } else if (propertyName == "y") {
                  entry = PropertyInfo(YCOORD, valueType);
                  vertexDimension_++;
                } else if (propertyName == "z") {
                  entry = PropertyInfo(ZCOORD, valueType);
                  vertexDimension_++;
                } else if (propertyName == "nx") {
                  entry = PropertyInfo(XNORM, valueType);
                  options_ += Options::VertexNormal;
                } else if (propertyName == "ny") {
                  entry = PropertyInfo(YNORM, valueType);
                  options_ += Options::VertexNormal;
                } else if (propertyName == "nz") {
                  entry = PropertyInfo(ZNORM, valueType);
                  options_ += Options::VertexNormal;
                } else if (propertyName == "u" || propertyName == "s") {
                  entry = PropertyInfo(TEXX, valueType);
                  options_ += Options::VertexTexCoord;
                } else if (propertyName == "v" || propertyName == "t") {
                  entry = PropertyInfo(TEXY, valueType);
                  options_ += Options::VertexTexCoord;
                } else if (propertyName == "red") {
                  entry = PropertyInfo(COLORRED, valueType);
                  options_ += Options::VertexColor;
                  if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32)
                    options_ += Options::ColorFloat;
                } else if (propertyName == "green") {
                  entry = PropertyInfo(COLORGREEN, valueType);
                  options_ += Options::VertexColor;
                  if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32)
                    options_ += Options::ColorFloat;
                } else if (propertyName == "blue") {
                  entry = PropertyInfo(COLORBLUE, valueType);
                  options_ += Options::VertexColor;
                  if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32)
                    options_ += Options::ColorFloat;
                } else if (propertyName == "diffuse_red") {
                  entry = PropertyInfo(COLORRED, valueType);
                  options_ += Options::VertexColor;
                  if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32)
                    options_ += Options::ColorFloat;
                } else if (propertyName == "diffuse_green") {
                  entry = PropertyInfo(COLORGREEN, valueType);
                  options_ += Options::VertexColor;
                  if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32)
                    options_ += Options::ColorFloat;
                } else if (propertyName == "diffuse_blue") {
                  entry = PropertyInfo(COLORBLUE, valueType);
                  options_ += Options::VertexColor;
                  if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32)
                    options_ += Options::ColorFloat;
                } else if (propertyName == "alpha") {
                  entry = PropertyInfo(COLORALPHA, valueType);
                  options_ += Options::VertexColor;
                  options_ += Options::ColorAlpha;
                  if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32)
                    options_ += Options::ColorFloat;
1193
                }
Matthias Möller's avatar
Matthias Möller committed
1194 1195 1196 1197 1198 1199 1200 1201 1202
              }

              //not a special property, load as custom
              if (entry.value == Unsupported){
                Property prop = (!options_.is_binary()) ? CUSTOM_PROP : UNSUPPORTED; // loading vertex properties is not yet supported by the binary loader
                if (prop != UNSUPPORTED)
                  options_ += Options::Custom;
                else
                  omerr() << "Custom Properties not supported in binary files. Skipping" << std::endl;
1203
                entry  = PropertyInfo(prop, valueType, propertyName);
Matthias Möller's avatar
Matthias Möller committed
1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214
              }

              if (entry.property != UNSUPPORTED)
              {
                if (elementName == "vertex")
                  vertexProperties_.push_back(entry);
                else if (elementName == "face")
                  faceProperties_.push_back(entry);
                else
                  omerr() << "Properties not supported in element " << elementName << std::endl;
              }
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236

            }

        } else {
            omlog() << "Unsupported keyword : " << keyword << std::endl;
        }

        streamPos = _is.tellg();
        _is >> keyword;
        if (_is.bad()) {
            omerr() << "Error while reading PLY file header" << std::endl;
            return false;
        }
    }

    // As the binary data is directy after the end_header keyword
    // and the stream removes too many bytes, seek back to the right position
    if (options_.is_binary()) {
        _is.seekg(streamPos + 12);
    }

    return true;
Jan Möbius's avatar
Jan Möbius committed
1237 1238 1239 1240 1241 1242
}

//=============================================================================
} // namespace IO
} // namespace OpenMesh
//=============================================================================