OMReader.cc 17.4 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
5
6
7
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department for Computer Graphics and Multimedia                 *
 *                          All rights reserved.                             *
 *                            www.openmesh.org                               *
Jan Möbius's avatar
Jan Möbius committed
8
 *                                                                           *
9
 *---------------------------------------------------------------------------*
Jan Möbius's avatar
Jan Möbius committed
10
11
 * This file is part of OpenMesh.                                            *
 *---------------------------------------------------------------------------*
12
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
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
 * 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

/*===========================================================================*\
43
 *                                                                           *
44
45
 *   $Revision$                                                         *
 *   $Date$                   *
Jan Möbius's avatar
Jan Möbius committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
 *                                                                           *
\*===========================================================================*/


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


//STL
#include <fstream>

// OpenMesh
#include <OpenMesh/Core/System/config.h>
#include <OpenMesh/Core/System/omstream.hh>
#include <OpenMesh/Core/Utils/Endian.hh>
#include <OpenMesh/Core/IO/OMFormat.hh>
#include <OpenMesh/Core/IO/reader/OMReader.hh>


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


namespace OpenMesh {
namespace IO {


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


// register the OMReader singleton with MeshReader
_OMReader_  __OMReaderInstance;
_OMReader_&  OMReader() { return __OMReaderInstance; }



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


_OMReader_::_OMReader_()
{
85
  IOManager().register_module(this);
Jan Möbius's avatar
Jan Möbius committed
86
87
88
89
90
91
}


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


92
bool _OMReader_::read(const std::string& _filename, BaseImporter& _bi, Options& _opt)
Jan Möbius's avatar
Jan Möbius committed
93
94
{
  // check whether importer can give us an OpenMesh BaseKernel
95
96
  if (!_bi.kernel())
    return false;
Jan Möbius's avatar
Jan Möbius committed
97
98

  _opt += Options::Binary; // only binary format supported!
99
  fileOptions_ = Options::Binary;
Jan Möbius's avatar
Jan Möbius committed
100
101

  // Open file
102
  std::ifstream ifs(_filename.c_str(), std::ios::binary);
103
104
105
106
107
108
109

  /* Clear formatting flag skipws (Skip whitespaces). If set, operator>> will
   * skip bytes set to whitespace chars (e.g. 0x20 bytes) in
   * Property<bool>::restore.
   */
  ifs.unsetf(std::ios::skipws);

110
111
  if (!ifs.is_open() || !ifs.good()) {
    omerr() << "[OMReader] : cannot not open file " << _filename << std::endl;
Jan Möbius's avatar
Jan Möbius committed
112
113
    return false;
  }
114

Jan Möbius's avatar
Jan Möbius committed
115
116
  // Pass stream to read method, remember result
  bool result = read(ifs, _bi, _opt);
117

Jan Möbius's avatar
Jan Möbius committed
118
119
  // close input stream
  ifs.close();
120

121
122
  _opt = _opt & fileOptions_;

Jan Möbius's avatar
Jan Möbius committed
123
124
125
126
127
128
  return result;
}

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


129
bool _OMReader_::read(std::istream& _is, BaseImporter& _bi, Options& _opt)
Jan Möbius's avatar
Jan Möbius committed
130
{
131
  // check whether importer can give us an OpenMesh BaseKernel
132
133
  if (!_bi.kernel())
    return false;
134
135

  _opt += Options::Binary; // only binary format supported!
136
  fileOptions_ = Options::Binary;
137

138
139
  if (!_is.good()) {
    omerr() << "[OMReader] : cannot read from stream " << std::endl;
140
141
142
143
144
145
    return false;
  }

  // Pass stream to read method, remember result
  bool result = read_binary(_is, _bi, _opt);

146
147
  if (result)
    _opt += Options::Binary;
Jan Möbius's avatar
Jan Möbius committed
148

149
150
  _opt = _opt & fileOptions_;

151
  return result;
Jan Möbius's avatar
Jan Möbius committed
152
153
154
155
156
157
}



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

158
bool _OMReader_::read_ascii(std::istream& /* _is */, BaseImporter& /* _bi */, Options& /* _opt */) const
Jan Möbius's avatar
Jan Möbius committed
159
160
161
162
163
164
165
166
{
  // not supported yet!
  return false;
}


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

167
bool _OMReader_::read_binary(std::istream& _is, BaseImporter& _bi, Options& _opt) const
Jan Möbius's avatar
Jan Möbius committed
168
169
170
{
  bool swap = _opt.check(Options::Swap) || (Endian::local() == Endian::MSB);

171
  // Initialize byte counter
172
  bytes_ = 0;
Jan Möbius's avatar
Jan Möbius committed
173

174
  bytes_ += restore(_is, header_, swap);
Jan Möbius's avatar
Jan Möbius committed
175
176


177
178
  while (!_is.eof()) {
    bytes_ += restore(_is, chunk_header_, swap);
Jan Möbius's avatar
Jan Möbius committed
179

180
    if (_is.eof())
Jan Möbius's avatar
Jan Möbius committed
181
182
183
      break;

    // Is this a named property restore the name
184
    if (chunk_header_.name_) {
Jan Möbius's avatar
Jan Möbius committed
185
      OMFormat::Chunk::PropertyName pn;
186
      bytes_ += restore(_is, property_name_, swap);
Jan Möbius's avatar
Jan Möbius committed
187
188
189
190
    }

    // Read in the property data. If it is an anonymous or unknown named
    // property, then skip data.
191
    switch (chunk_header_.entity_) {
192
      case OMFormat::Chunk::Entity_Vertex:
193
194
195
        if (!read_binary_vertex_chunk(_is, _bi, _opt, swap))
          return false;
        break;
Jan Möbius's avatar
Jan Möbius committed
196
      case OMFormat::Chunk::Entity_Face:
197
198
199
        if (!read_binary_face_chunk(_is, _bi, _opt, swap))
          return false;
        break;
Jan Möbius's avatar
Jan Möbius committed
200
      case OMFormat::Chunk::Entity_Edge:
201
202
203
        if (!read_binary_edge_chunk(_is, _bi, _opt, swap))
          return false;
        break;
Jan Möbius's avatar
Jan Möbius committed
204
      case OMFormat::Chunk::Entity_Halfedge:
205
206
207
        if (!read_binary_halfedge_chunk(_is, _bi, _opt, swap))
          return false;
        break;
Jan Möbius's avatar
Jan Möbius committed
208
      case OMFormat::Chunk::Entity_Mesh:
209
210
211
        if (!read_binary_mesh_chunk(_is, _bi, _opt, swap))
          return false;
        break;
Jan Möbius's avatar
Jan Möbius committed
212
      default:
213
        return false;
Jan Möbius's avatar
Jan Möbius committed
214
    }
Jan Möbius's avatar
Jan Möbius committed
215

Jan Möbius's avatar
Jan Möbius committed
216
217
218
219
220
221
222
223
224
  }

  // File was successfully parsed.
  return true;
}


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

225
bool _OMReader_::can_u_read(const std::string& _filename) const
Jan Möbius's avatar
Jan Möbius committed
226
227
228
{
  // !!! Assuming BaseReader::can_u_parse( std::string& )
  // does not call BaseReader::read_magic()!!!
229
230
231
  if (this->BaseReader::can_u_read(_filename)) {
    std::ifstream ifile(_filename.c_str());
    if (ifile && can_u_read(ifile))
232
      return true;
Jan Möbius's avatar
Jan Möbius committed
233
234
235
236
237
  }
  return false;
}

//-----------------------------------------------------------------------------
238

239
bool _OMReader_::can_u_read(std::istream& _is) const
Jan Möbius's avatar
Jan Möbius committed
240
241
242
243
244
{
  std::vector<char> evt;
  evt.reserve(20);

  // read first 4 characters into a buffer
245
246
  while (evt.size() < 4)
    evt.push_back(static_cast<char>(_is.get()));
Jan Möbius's avatar
Jan Möbius committed
247

248
  // put back all read characters
Jan Möbius's avatar
Jan Möbius committed
249
  std::vector<char>::reverse_iterator it = evt.rbegin();
250
251
  while (it != evt.rend())
    _is.putback(*it++);
Jan Möbius's avatar
Jan Möbius committed
252
253

  // evaluate header information
254
  OMFormat::Header *hdr = (OMFormat::Header*) &evt[0];
Jan Möbius's avatar
Jan Möbius committed
255
256
257
258
259
260

  // first two characters must be 'OM'
  if (hdr->magic_[0] != 'O' || hdr->magic_[1] != 'M')
    return false;

  // 3rd characters defines the mesh type:
261
  switch (hdr->mesh_) {
Jan Möbius's avatar
Jan Möbius committed
262
263
264
265
266
267
268
    case 'T': // Triangle Mesh
    case 'Q': // Quad Mesh
    case 'P': // Polygonal Mesh
      break;
    default:  // ?
      return false;
  }
269

Jan Möbius's avatar
Jan Möbius committed
270
  // 4th characters encodes the version
271
  return supports(hdr->version_);
Jan Möbius's avatar
Jan Möbius committed
272
273
274
275
}

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

276
bool _OMReader_::supports(const OMFormat::uint8 /* version */) const
Jan Möbius's avatar
Jan Möbius committed
277
278
279
280
281
282
283
{
  return true;
}


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

284
bool _OMReader_::read_binary_vertex_chunk(std::istream &_is, BaseImporter &_bi, Options &_opt, bool _swap) const
Jan Möbius's avatar
Jan Möbius committed
285
286
287
{
  using OMFormat::Chunk;

288
  assert( chunk_header_.entity_ == Chunk::Entity_Vertex);
289

290
291
  OpenMesh::Vec3f v3f;
  OpenMesh::Vec2f v2f;
Jan Möbius's avatar
Jan Möbius committed
292
293
294
295
  OpenMesh::Vec3uc v3uc; // rgb

  OMFormat::Chunk::PropertyName custom_prop;

296
297
  size_t vidx = 0;
  switch (chunk_header_.type_) {
Jan Möbius's avatar
Jan Möbius committed
298
    case Chunk::Type_Pos:
299
      assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
Jan Möbius's avatar
Jan Möbius committed
300

301
302
303
      for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
        bytes_ += vector_restore(_is, v3f, _swap);
        _bi.add_vertex(v3f);
Jan Möbius's avatar
Jan Möbius committed
304
305
306
307
      }
      break;

    case Chunk::Type_Normal:
308
      assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
Jan Möbius's avatar
Jan Möbius committed
309

310
      fileOptions_ += Options::VertexNormal;
311
312
      for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
        bytes_ += vector_restore(_is, v3f, _swap);
313
        if (fileOptions_.vertex_has_normal() && _opt.vertex_has_normal())
314
          _bi.set_normal(VertexHandle(int(vidx)), v3f);
Jan Möbius's avatar
Jan Möbius committed
315
316
317
318
      }
      break;

    case Chunk::Type_Texcoord:
319
      assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec2f::dim()));
Jan Möbius's avatar
Jan Möbius committed
320

321
      fileOptions_ += Options::VertexTexCoord;
322
323
      for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
        bytes_ += vector_restore(_is, v2f, _swap);
324
        if (fileOptions_.vertex_has_texcoord() && _opt.vertex_has_texcoord())
325
          _bi.set_texcoord(VertexHandle(int(vidx)), v2f);
Jan Möbius's avatar
Jan Möbius committed
326
      }
327
      break;
Jan Möbius's avatar
Jan Möbius committed
328
329
330

    case Chunk::Type_Color:

331
      assert( OMFormat::dimensions(chunk_header_) == 3);
Jan Möbius's avatar
Jan Möbius committed
332

333
      fileOptions_ += Options::VertexColor;
334

335
336
      for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
        bytes_ += vector_restore(_is, v3uc, _swap);
337
        if (fileOptions_.vertex_has_color() && _opt.vertex_has_color())
338
          _bi.set_color(VertexHandle(int(vidx)), v3uc);
Jan Möbius's avatar
Jan Möbius committed
339
340
341
342
      }
      break;

    case Chunk::Type_Custom:
343

344
      bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_vprop(property_name_), header_.n_vertices_, _swap);
Jan Möbius's avatar
Jan Möbius committed
345
346
347
348
349
350
351
352

      vidx = header_.n_vertices_;

      break;

    default: // skip unknown chunks
    {
      omerr() << "Unknown chunk type ignored!\n";
353
354
      size_t size_of = header_.n_vertices_ * OMFormat::vector_size(chunk_header_);
      _is.ignore(size_of);
Jan Möbius's avatar
Jan Möbius committed
355
356
357
358
359
360
361
362
363
364
365
      bytes_ += size_of;
    }
  }

  // all chunk data has been read..?!
  return vidx == header_.n_vertices_;
}


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

366
bool _OMReader_::read_binary_face_chunk(std::istream &_is, BaseImporter &_bi, Options &_opt, bool _swap) const
Jan Möbius's avatar
Jan Möbius committed
367
368
369
{
  using OMFormat::Chunk;

370
  assert( chunk_header_.entity_ == Chunk::Entity_Face);
Jan Möbius's avatar
Jan Möbius committed
371

372
373
  size_t fidx = 0;
  OpenMesh::Vec3f v3f;  // normal
Jan Möbius's avatar
Jan Möbius committed
374
375
  OpenMesh::Vec3uc v3uc; // rgb

376
377
378
379
380
381
382
383
384
385
386
387
388
  switch (chunk_header_.type_) {
    case Chunk::Type_Topology: {
      BaseImporter::VHandles vhandles;
      size_t nV = 0;
      size_t vidx = 0;

      switch (header_.mesh_) {
        case 'T':
          nV = 3;
          break;
        case 'Q':
          nV = 4;
          break;
Jan Möbius's avatar
Jan Möbius committed
389
      }
390

391
392
393
      for (; fidx < header_.n_faces_; ++fidx) {
        if (header_.mesh_ == 'P')
          bytes_ += restore(_is, nV, Chunk::Integer_16, _swap);
Jan Möbius's avatar
Jan Möbius committed
394

395
396
397
        vhandles.clear();
        for (size_t j = 0; j < nV; ++j) {
          bytes_ += restore(_is, vidx, Chunk::Integer_Size(chunk_header_.bits_), _swap);
Jan Möbius's avatar
Jan Möbius committed
398

399
          vhandles.push_back(VertexHandle(int(vidx)));
400
        }
Jan Möbius's avatar
Jan Möbius committed
401

402
        _bi.add_face(vhandles);
Jan Möbius's avatar
Jan Möbius committed
403
404
      }
    }
405
      break;
Jan Möbius's avatar
Jan Möbius committed
406
407

    case Chunk::Type_Normal:
408
      assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
Jan Möbius's avatar
Jan Möbius committed
409

410
      fileOptions_ += Options::FaceNormal;
411
412
      for (; fidx < header_.n_faces_ && !_is.eof(); ++fidx) {
        bytes_ += vector_restore(_is, v3f, _swap);
413
        if( fileOptions_.face_has_normal() && _opt.face_has_normal())
414
          _bi.set_normal(FaceHandle(int(fidx)), v3f);
Jan Möbius's avatar
Jan Möbius committed
415
416
417
418
419
      }
      break;

    case Chunk::Type_Color:

420
      assert( OMFormat::dimensions(chunk_header_) == 3);
Jan Möbius's avatar
Jan Möbius committed
421

422
      fileOptions_ += Options::FaceColor;
423
424
      for (; fidx < header_.n_faces_ && !_is.eof(); ++fidx) {
        bytes_ += vector_restore(_is, v3uc, _swap);
425
        if( fileOptions_.face_has_color() && _opt.face_has_color())
426
          _bi.set_color(FaceHandle(int(fidx)), v3uc);
Jan Möbius's avatar
Jan Möbius committed
427
428
429
430
      }
      break;

    case Chunk::Type_Custom:
431

432
      bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_fprop(property_name_), header_.n_faces_, _swap);
Jan Möbius's avatar
Jan Möbius committed
433
434
435
436

      fidx = header_.n_faces_;

      break;
437

Jan Möbius's avatar
Jan Möbius committed
438
439
440
441
    default: // skip unknown chunks
    {
      omerr() << "Unknown chunk type ignore!\n";
      size_t size_of = OMFormat::chunk_data_size(header_, chunk_header_);
442
      _is.ignore(size_of);
443
      bytes_ += size_of;
Jan Möbius's avatar
Jan Möbius committed
444
445
446
447
448
449
450
451
    }
  }
  return fidx == header_.n_faces_;
}


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

452
bool _OMReader_::read_binary_edge_chunk(std::istream &_is, BaseImporter &_bi, Options &/*_opt */, bool _swap) const
Jan Möbius's avatar
Jan Möbius committed
453
454
455
{
  using OMFormat::Chunk;

456
  assert( chunk_header_.entity_ == Chunk::Entity_Edge);
Jan Möbius's avatar
Jan Möbius committed
457

458
  size_t b = bytes_;
Jan Möbius's avatar
Jan Möbius committed
459

460
  switch (chunk_header_.type_) {
461
    case Chunk::Type_Custom:
Jan Möbius's avatar
Jan Möbius committed
462

463
      bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_eprop(property_name_), header_.n_edges_, _swap);
Jan Möbius's avatar
Jan Möbius committed
464
465
466
467
468
469

      break;

    default:
      // skip unknown type
      size_t size_of = OMFormat::chunk_data_size(header_, chunk_header_);
470
      _is.ignore(size_of);
Jan Möbius's avatar
Jan Möbius committed
471
472
473
474
475
476
477
478
479
      bytes_ += size_of;
  }

  return b < bytes_;
}


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

480
bool _OMReader_::read_binary_halfedge_chunk(std::istream &_is, BaseImporter &_bi, Options &/* _opt */, bool _swap) const
Jan Möbius's avatar
Jan Möbius committed
481
482
483
{
  using OMFormat::Chunk;

484
  assert( chunk_header_.entity_ == Chunk::Entity_Halfedge);
Jan Möbius's avatar
Jan Möbius committed
485
486
487

  size_t b = bytes_;

488
  switch (chunk_header_.type_) {
Jan Möbius's avatar
Jan Möbius committed
489
490
    case Chunk::Type_Custom:

491
      bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_hprop(property_name_), 2 * header_.n_edges_, _swap);
Jan Möbius's avatar
Jan Möbius committed
492
493
494
495
496
497
      break;

    default:
      // skip unknown chunk
      omerr() << "Unknown chunk type ignored!\n";
      size_t size_of = OMFormat::chunk_data_size(header_, chunk_header_);
498
      _is.ignore(size_of);
Jan Möbius's avatar
Jan Möbius committed
499
500
501
502
503
504
505
506
507
      bytes_ += size_of;
  }

  return b < bytes_;
}


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

508
bool _OMReader_::read_binary_mesh_chunk(std::istream &_is, BaseImporter &_bi, Options & /* _opt */, bool _swap) const
Jan Möbius's avatar
Jan Möbius committed
509
510
511
{
  using OMFormat::Chunk;

512
  assert( chunk_header_.entity_ == Chunk::Entity_Mesh);
Jan Möbius's avatar
Jan Möbius committed
513
514
515

  size_t b = bytes_;

516
  switch (chunk_header_.type_) {
Jan Möbius's avatar
Jan Möbius committed
517
    case Chunk::Type_Custom:
518

519
      bytes_ += restore_binary_custom_data(_is, _bi.kernel()->_get_mprop(property_name_), 1, _swap);
520

Jan Möbius's avatar
Jan Möbius committed
521
522
523
524
525
      break;

    default:
      // skip unknown chunk
      size_t size_of = OMFormat::chunk_data_size(header_, chunk_header_);
526
      _is.ignore(size_of);
Jan Möbius's avatar
Jan Möbius committed
527
528
529
530
531
532
533
534
535
536
      bytes_ += size_of;
  }

  return b < bytes_;
}


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


537
size_t _OMReader_::restore_binary_custom_data(std::istream& _is, BaseProperty* _bp, size_t _n_elem, bool _swap) const
538
{
539
  assert( !_bp || (_bp->name() == property_name_));
Jan Möbius's avatar
Jan Möbius committed
540
541
542

  using OMFormat::Chunk;

543
544
  size_t bytes = 0;
  Chunk::esize_t block_size;
Jan Möbius's avatar
Jan Möbius committed
545
546
  Chunk::PropertyName custom_prop;

547
  bytes += restore(_is, block_size, OMFormat::Chunk::Integer_32, _swap);
Jan Möbius's avatar
Jan Möbius committed
548

549
550
  if (_bp) {
    size_t n_bytes = _bp->size_of(_n_elem);
Jan Möbius's avatar
Jan Möbius committed
551

552
553
    if (((n_bytes == BaseProperty::UnknownSize) || (n_bytes == block_size))
        && (_bp->element_size() == BaseProperty::UnknownSize || (_n_elem * _bp->element_size() == block_size))) {
Jan Möbius's avatar
Jan Möbius committed
554
#if defined(OM_DEBUG)
Jan Möbius's avatar
Jan Möbius committed
555
      size_t b;
Jan Möbius's avatar
Jan Möbius committed
556
557
      bytes += (b=_bp->restore( _is, _swap ));
#else
558
      bytes += _bp->restore(_is, _swap);
Jan Möbius's avatar
Jan Möbius committed
559
#endif
560

Jan Möbius's avatar
Jan Möbius committed
561
562
563
#if defined(OM_DEBUG)
      assert( block_size == b );
#endif
564
565

      assert( block_size == _bp->size_of());
Jan Möbius's avatar
Jan Möbius committed
566
567

      block_size = 0;
568
569
    } else {
      omerr() << "Warning! Property " << _bp->name() << " not loaded: " << "Mismatching data sizes!n";
Jan Möbius's avatar
Jan Möbius committed
570
571
572
    }
  }

573
574
575
  if (block_size) {
    _is.ignore(block_size);
    bytes += block_size;
Jan Möbius's avatar
Jan Möbius committed
576
577
578
579
580
581
582
583
584
585
586
587
  }

  return bytes;
}


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

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