BaseKernel.hh 27.9 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
/* ========================================================================= *
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                               *
8
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
9 10 11
 *---------------------------------------------------------------------------*
 * This file is part of OpenMesh.                                            *
 *---------------------------------------------------------------------------*
12
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
13 14 15
 * Redistribution and use in source and binary forms, with or without        *
 * modification, are permitted provided that the following conditions        *
 * are met:                                                                  *
16
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
17 18
 * 1. Redistributions of source code must retain the above copyright notice, *
 *    this list of conditions and the following disclaimer.                  *
19
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
20 21 22
 * 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.   *
23
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
24 25 26
 * 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.               *
27
 *                                                                           *
Jan Möbius's avatar
Jan Möbius committed
28 29 30 31 32 33 34 35 36 37 38
 * 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 46 47

/*===========================================================================*\
 *                                                                           *             
 *   $Revision$                                                         *
 *   $Date$                   *
 *                                                                           *
\*===========================================================================*/
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 64 65 66 67 68


//=============================================================================
//
//  CLASS BaseKernel
//
//=============================================================================


#ifndef OPENMESH_BASE_KERNEL_HH
#define OPENMESH_BASE_KERNEL_HH


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


#include <OpenMesh/Core/System/config.h>
// --------------------
#include <vector>
#include <string>
#include <algorithm>
69
#include <iosfwd>
Jan Möbius's avatar
Jan Möbius committed
70 71 72 73 74 75 76 77 78 79 80 81
// --------------------
#include <OpenMesh/Core/Utils/PropertyContainer.hh>


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


namespace OpenMesh {


//== CLASS DEFINITION =========================================================

82 83 84 85 86
/// This class provides low-level property management like adding/removing
/// properties and access to properties. Under most circumstances, it is
/// advisable to use the high-level property management provided by
/// PropertyManager, instead.
///
Jan Möbius's avatar
Jan Möbius committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
/// All operations provided by %BaseKernel need at least a property handle
/// (VPropHandleT, EPropHandleT, HPropHandleT, FPropHandleT, MPropHandleT).
/// which keeps the data type of the property, too.
///
/// There are two types of properties:
/// -# Standard properties - mesh data (e.g. vertex normal or face color)
/// -# Custom properties - user defined data
///
/// The differentiation is only semantically, technically both are
/// equally handled. Therefore the methods provided by the %BaseKernel
/// are applicable to both property types.
///
/// \attention Since the class PolyMeshT derives from a kernel, hence all public
/// elements of %BaseKernel are usable.

102
class OPENMESHDLLEXPORT BaseKernel
Jan Möbius's avatar
Jan Möbius committed
103 104 105 106
{
public: //-------------------------------------------- constructor / destructor

  BaseKernel() {}
107 108 109 110 111 112
  virtual ~BaseKernel() {
	vprops_.clear();
	eprops_.clear();
	hprops_.clear();
	fprops_.clear();
  }
Jan Möbius's avatar
Jan Möbius committed
113 114 115 116 117 118 119 120


public: //-------------------------------------------------- add new properties

  /// \name Add a property to a mesh item

  //@{

121 122 123 124 125 126
  /** You should not use this function directly. Instead, use the convenient
   *  PropertyManager wrapper and/or one of its helper functions such as
   *  makePropertyManagerFromNew, makePropertyManagerFromExisting, or
   *  makePropertyManagerFromExistingOrNew.
   *
   *  Adds a property
Jan Möbius's avatar
Jan Möbius committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
   *
   *  Depending on the property handle type a vertex, (half-)edge, face or
   *  mesh property is added to the mesh. If the action fails the handle
   *  is invalid.
   *  On success the handle must be used to access the property data with
   *  property().
   *
   *  \param  _ph   A property handle defining the data type to bind to mesh.
   *                On success the handle is valid else invalid.
   *  \param  _name Optional name of property. Following restrictions apply
   *                to the name:
   *                -# Maximum length of name is 256 characters
   *                -# The prefixes matching "^[vhefm]:" are reserved for
   *                   internal usage.
   *                -# The expression "^<.*>$" is reserved for internal usage.
   *
   */

  template <class T>
  void add_property( VPropHandleT<T>& _ph, const std::string& _name="<vprop>")
  {
    _ph = VPropHandleT<T>( vprops_.add(T(), _name) );
    vprops_.resize(n_vertices());
  }

  template <class T>
  void add_property( HPropHandleT<T>& _ph, const std::string& _name="<hprop>")
  {
    _ph = HPropHandleT<T>( hprops_.add(T(), _name) );
    hprops_.resize(n_halfedges());
  }

  template <class T>
  void add_property( EPropHandleT<T>& _ph, const std::string& _name="<eprop>")
  {
    _ph = EPropHandleT<T>( eprops_.add(T(), _name) );
    eprops_.resize(n_edges());
  }

  template <class T>
  void add_property( FPropHandleT<T>& _ph, const std::string& _name="<fprop>")
  {
    _ph = FPropHandleT<T>( fprops_.add(T(), _name) );
    fprops_.resize(n_faces());
  }

  template <class T>
  void add_property( MPropHandleT<T>& _ph, const std::string& _name="<mprop>")
  {
    _ph = MPropHandleT<T>( mprops_.add(T(), _name) );
    mprops_.resize(1);
  }

  //@}


public: //--------------------------------------------------- remove properties

  /// \name Removing a property from a mesh tiem
  //@{

188 189 190 191
  /** You should not use this function directly. Instead, use the convenient
   *  PropertyManager wrapper to manage (and remove) properties.
   *
   *  Remove a property.
Jan Möbius's avatar
Jan Möbius committed
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
   *
   *  Removes the property represented by the handle from the apropriate
   *  mesh item.
   *  \param _ph Property to be removed. The handle is invalid afterwords.
   */

  template <typename T>
  void remove_property(VPropHandleT<T>& _ph)
  {
    if (_ph.is_valid())
      vprops_.remove(_ph);
    _ph.reset();
  }

  template <typename T>
  void remove_property(HPropHandleT<T>& _ph)
  {
    if (_ph.is_valid())
      hprops_.remove(_ph);
    _ph.reset();
  }

  template <typename T>
  void remove_property(EPropHandleT<T>& _ph)
  {
    if (_ph.is_valid())
      eprops_.remove(_ph);
    _ph.reset();
  }

  template <typename T>
  void remove_property(FPropHandleT<T>& _ph)
  {
    if (_ph.is_valid())
      fprops_.remove(_ph);
    _ph.reset();
  }

  template <typename T>
  void remove_property(MPropHandleT<T>& _ph)
  {
    if (_ph.is_valid())
      mprops_.remove(_ph);
    _ph.reset();
  }

  //@}
239
  
Jan Möbius's avatar
Jan Möbius committed
240 241 242 243 244
public: //------------------------------------------------ get handle from name

  /// \name Get property handle by name
  //@{

245 246 247 248 249 250
  /** You should not use this function directly. Instead, use the convenient
   *  PropertyManager wrapper (e.g. PropertyManager::propertyExists) or one of
   *  its higher level helper functions such as
   *  makePropertyManagerFromExisting, or makePropertyManagerFromExistingOrNew.
   *
   *  Retrieves the handle to a named property by it's name.
Jan Möbius's avatar
Jan Möbius committed
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
   *
   *  \param _ph    A property handle. On success the handle is valid else
   *                invalid.
   *  \param _name  Name of wanted property.
   *  \return \c true if such a named property is available, else \c false.
   */

  template <class T>
  bool get_property_handle(VPropHandleT<T>& _ph,
         const std::string& _name) const
  {
    return (_ph = VPropHandleT<T>(vprops_.handle(T(), _name))).is_valid();
  }

  template <class T>
  bool get_property_handle(HPropHandleT<T>& _ph,
         const std::string& _name) const
  {
    return (_ph = HPropHandleT<T>(hprops_.handle(T(), _name))).is_valid();
  }

  template <class T>
  bool get_property_handle(EPropHandleT<T>& _ph,
         const std::string& _name) const
  {
    return (_ph = EPropHandleT<T>(eprops_.handle(T(), _name))).is_valid();
  }

  template <class T>
  bool get_property_handle(FPropHandleT<T>& _ph,
         const std::string& _name) const
  {
    return (_ph = FPropHandleT<T>(fprops_.handle(T(), _name))).is_valid();
  }

  template <class T>
  bool get_property_handle(MPropHandleT<T>& _ph,
         const std::string& _name) const
  {
    return (_ph = MPropHandleT<T>(mprops_.handle(T(), _name))).is_valid();
  }

  //@}

public: //--------------------------------------------------- access properties

  /// \name Access a property
  //@{

300 301 302 303 304 305
  /** In most cases you should use the convenient PropertyManager wrapper
   *  and use of this function should not be necessary. Under some
   *  circumstances, however (i.e. making a property persistent), it might be
   *  necessary to use this function.
   *
   *  Access a property
Jan Möbius's avatar
Jan Möbius committed
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
   *
   *  This method returns a reference to property. The property handle
   *  must be valid! The result is unpredictable if the handle is invalid!
   *
   *  \param  _ph     A \em valid (!) property handle.
   *  \return The wanted property if the handle is valid.
   */

  template <class T>
  PropertyT<T>& property(VPropHandleT<T> _ph) {
    return vprops_.property(_ph);
  }
  template <class T>
  const PropertyT<T>& property(VPropHandleT<T> _ph) const {
    return vprops_.property(_ph);
  }

  template <class T>
  PropertyT<T>& property(HPropHandleT<T> _ph) {
    return hprops_.property(_ph);
  }
  template <class T>
  const PropertyT<T>& property(HPropHandleT<T> _ph) const {
    return hprops_.property(_ph);
  }

  template <class T>
  PropertyT<T>& property(EPropHandleT<T> _ph) {
    return eprops_.property(_ph);
  }
  template <class T>
  const PropertyT<T>& property(EPropHandleT<T> _ph) const {
    return eprops_.property(_ph);
  }

  template <class T>
  PropertyT<T>& property(FPropHandleT<T> _ph) {
    return fprops_.property(_ph);
  }
  template <class T>
  const PropertyT<T>& property(FPropHandleT<T> _ph) const {
    return fprops_.property(_ph);
  }

  template <class T>
  PropertyT<T>& mproperty(MPropHandleT<T> _ph) {
    return mprops_.property(_ph);
  }
  template <class T>
  const PropertyT<T>& mproperty(MPropHandleT<T> _ph) const {
    return mprops_.property(_ph);
  }

  //@}

public: //-------------------------------------------- access property elements

  /// \name Access a property element using a handle to a mesh item
  //@{

366 367 368 369
  /** You should not use this function directly. Instead, use the convenient
   *  PropertyManager wrapper.
   *
   *  Return value of property for an item
Jan Möbius's avatar
Jan Möbius committed
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
   */

  template <class T>
  typename VPropHandleT<T>::reference
  property(VPropHandleT<T> _ph, VertexHandle _vh) {
    return vprops_.property(_ph)[_vh.idx()];
  }

  template <class T>
  typename VPropHandleT<T>::const_reference
  property(VPropHandleT<T> _ph, VertexHandle _vh) const {
    return vprops_.property(_ph)[_vh.idx()];
  }


  template <class T>
  typename HPropHandleT<T>::reference
  property(HPropHandleT<T> _ph, HalfedgeHandle _hh) {
    return hprops_.property(_ph)[_hh.idx()];
  }

  template <class T>
  typename HPropHandleT<T>::const_reference
  property(HPropHandleT<T> _ph, HalfedgeHandle _hh) const {
    return hprops_.property(_ph)[_hh.idx()];
  }


  template <class T>
  typename EPropHandleT<T>::reference
  property(EPropHandleT<T> _ph, EdgeHandle _eh) {
    return eprops_.property(_ph)[_eh.idx()];
  }

  template <class T>
  typename EPropHandleT<T>::const_reference
  property(EPropHandleT<T> _ph, EdgeHandle _eh) const {
    return eprops_.property(_ph)[_eh.idx()];
  }


  template <class T>
  typename FPropHandleT<T>::reference
  property(FPropHandleT<T> _ph, FaceHandle _fh) {
    return fprops_.property(_ph)[_fh.idx()];
  }

  template <class T>
  typename FPropHandleT<T>::const_reference
  property(FPropHandleT<T> _ph, FaceHandle _fh) const {
    return fprops_.property(_ph)[_fh.idx()];
  }


  template <class T>
  typename MPropHandleT<T>::reference
  property(MPropHandleT<T> _ph) {
    return mprops_.property(_ph)[0];
  }

  template <class T>
  typename MPropHandleT<T>::const_reference
  property(MPropHandleT<T> _ph) const {
    return mprops_.property(_ph)[0];
  }

  //@}

438 439 440

public: //------------------------------------------------ copy property

441 442 443 444 445
  /** You should not use this function directly. Instead, use the convenient
   *  PropertyManager wrapper (e.g. PropertyManager::copy_to or
   *  PropertyManager::copy).
   *
   * Copies a single property from one mesh element to another (of the same type)
446
   *
Jan Möbius's avatar
Jan Möbius committed
447 448 449
   * @param _ph       A vertex property handle
   * @param _vh_from  From vertex handle
   * @param _vh_to    To vertex handle
450 451 452 453
   */
  template <class T>
  void copy_property(VPropHandleT<T>& _ph, VertexHandle _vh_from, VertexHandle _vh_to) {
    if(_vh_from.is_valid() && _vh_to.is_valid())
454
      vprops_.property(_ph)[_vh_to.idx()] = vprops_.property(_ph)[_vh_from.idx()];
455 456
  }

457 458 459 460 461
  /** You should not use this function directly. Instead, use the convenient
    * PropertyManager wrapper (e.g. PropertyManager::copy_to or
    * PropertyManager::copy).
    *
    * Copies a single property from one mesh element to another (of the same type)
Jan Möbius's avatar
Jan Möbius committed
462 463 464 465 466
    *
    * @param _ph       A halfedge property handle
    * @param _hh_from  From halfedge handle
    * @param _hh_to    To halfedge handle
    */
467 468 469
  template <class T>
  void copy_property(HPropHandleT<T> _ph, HalfedgeHandle _hh_from, HalfedgeHandle _hh_to) {
    if(_hh_from.is_valid() && _hh_to.is_valid())
470
      hprops_.property(_ph)[_hh_to.idx()] = hprops_.property(_ph)[_hh_from.idx()];
471 472
  }

473 474 475 476 477
  /** You should not use this function directly. Instead, use the convenient
    * PropertyManager wrapper (e.g. PropertyManager::copy_to or
    * PropertyManager::copy).
    *
    * Copies a single property from one mesh element to another (of the same type)
Jan Möbius's avatar
Jan Möbius committed
478 479 480 481 482
    *
    * @param _ph       An edge property handle
    * @param _eh_from  From edge handle
    * @param _eh_to    To edge handle
    */
483 484 485
  template <class T>
  void copy_property(EPropHandleT<T> _ph, EdgeHandle _eh_from, EdgeHandle _eh_to) {
    if(_eh_from.is_valid() && _eh_to.is_valid())
486
      eprops_.property(_ph)[_eh_to.idx()] = eprops_.property(_ph)[_eh_from.idx()];
487 488
  }

489 490 491 492 493
  /** You should not use this function directly. Instead, use the convenient
    * PropertyManager wrapper (e.g. PropertyManager::copy_to or
    * PropertyManager::copy).
    *
    * Copies a single property from one mesh element to another (of the same type)
Jan Möbius's avatar
Jan Möbius committed
494 495 496 497 498
    *
    * @param _ph       A face property handle
    * @param _fh_from  From face handle
    * @param _fh_to    To face handle
    */
499 500 501
  template <class T>
  void copy_property(FPropHandleT<T> _ph, FaceHandle _fh_from, FaceHandle _fh_to) {
    if(_fh_from.is_valid() && _fh_to.is_valid())
502
      fprops_.property(_ph)[_fh_to.idx()] = fprops_.property(_ph)[_fh_from.idx()];
503 504
  }

505 506 507 508 509 510 511

public:
  //------------------------------------------------ copy all properties

  /** Copies all properties from one mesh element to another (of the same type)
   *
   *
512 513 514
   * @param _vh_from A vertex handle - source
   * @param _vh_to   A vertex handle - target
   * @param _copyBuildIn Should the internal properties (position, normal, texture coordinate,..) be copied?
515
   */
516 517
  void copy_all_properties(VertexHandle _vh_from, VertexHandle _vh_to, bool _copyBuildIn = false) {

518
    for( PropertyContainer::iterator p_it = vprops_.begin();
519 520 521 522
        p_it != vprops_.end(); ++p_it) {

      // Copy all properties, if build in is true
      // Otherwise, copy only properties without build in specifier
523
      if ( *p_it && ( _copyBuildIn || (*p_it)->name().substr(0,2) != "v:" ) )
524 525
        (*p_it)->copy(_vh_from.idx(), _vh_to.idx());

526 527 528
    }
  }

Jan Möbius's avatar
Jan Möbius committed
529 530
  /** Copies all properties from one mesh element to another (of the same type)
   *
531 532 533
   * @param _hh_from A halfedge handle - source
   * @param _hh_to   A halfedge handle - target
   * @param _copyBuildIn Should the internal properties (position, normal, texture coordinate,..) be copied?
Jan Möbius's avatar
Jan Möbius committed
534
   */
535 536
  void copy_all_properties(HalfedgeHandle _hh_from, HalfedgeHandle _hh_to, bool _copyBuildIn = false) {

537
    for( PropertyContainer::iterator p_it = hprops_.begin();
538 539 540 541
        p_it != hprops_.end(); ++p_it) {

      // Copy all properties, if build in is true
      // Otherwise, copy only properties without build in specifier
542
      if ( *p_it && ( _copyBuildIn || (*p_it)->name().substr(0,2) != "h:") )
543 544
        (*p_it)->copy(_hh_from.idx(), _hh_to.idx());

545 546 547
    }
  }

Jan Möbius's avatar
Jan Möbius committed
548 549
  /** Copies all properties from one mesh element to another (of the same type)
   *
550 551 552
   * @param _eh_from An edge handle - source
   * @param _eh_to   An edge handle - target
   * @param _copyBuildIn Should the internal properties (position, normal, texture coordinate,..) be copied?
Jan Möbius's avatar
Jan Möbius committed
553
   */
554
  void copy_all_properties(EdgeHandle _eh_from, EdgeHandle _eh_to, bool _copyBuildIn = false) {
555
    for( PropertyContainer::iterator p_it = eprops_.begin();
556 557 558 559
        p_it != eprops_.end(); ++p_it) {

      // Copy all properties, if build in is true
      // Otherwise, copy only properties without build in specifier
560
      if ( *p_it && ( _copyBuildIn || (*p_it)->name().substr(0,2) != "e:") )
561 562
        (*p_it)->copy(_eh_from.idx(), _eh_to.idx());

563 564 565
    }
  }

Jan Möbius's avatar
Jan Möbius committed
566 567
  /** Copies all properties from one mesh element to another (of the same type)
    *
568 569 570
    * @param _fh_from A face handle - source
    * @param _fh_to   A face handle - target
    * @param _copyBuildIn Should the internal properties (position, normal, texture coordinate,..) be copied?
Jan Möbius's avatar
Jan Möbius committed
571 572
    *
    */
573 574
  void copy_all_properties(FaceHandle _fh_from, FaceHandle _fh_to, bool _copyBuildIn = false) {

575
    for( PropertyContainer::iterator p_it = fprops_.begin();
576 577 578 579
        p_it != fprops_.end(); ++p_it) {

      // Copy all properties, if build in is true
      // Otherwise, copy only properties without build in specifier
580
      if ( *p_it && ( _copyBuildIn || (*p_it)->name().substr(0,2) != "f:") )
581
        (*p_it)->copy(_fh_from.idx(), _fh_to.idx());
582
    }
583

584
  }
Jan Möbius's avatar
Jan Möbius committed
585

Jan Möbius's avatar
Jan Möbius committed
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680
protected: //------------------------------------------------- low-level access

public: // used by non-native kernel and MeshIO, should be protected

  size_t n_vprops(void) const { return vprops_.size(); }

  size_t n_eprops(void) const { return eprops_.size(); }

  size_t n_hprops(void) const { return hprops_.size(); }

  size_t n_fprops(void) const { return fprops_.size(); }

  size_t n_mprops(void) const { return mprops_.size(); }

  BaseProperty* _get_vprop( const std::string& _name)
  { return vprops_.property(_name); }

  BaseProperty* _get_eprop( const std::string& _name)
  { return eprops_.property(_name); }

  BaseProperty* _get_hprop( const std::string& _name)
  { return hprops_.property(_name); }

  BaseProperty* _get_fprop( const std::string& _name)
  { return fprops_.property(_name); }

  BaseProperty* _get_mprop( const std::string& _name)
  { return mprops_.property(_name); }

  const BaseProperty* _get_vprop( const std::string& _name) const
  { return vprops_.property(_name); }

  const BaseProperty* _get_eprop( const std::string& _name) const
  { return eprops_.property(_name); }

  const BaseProperty* _get_hprop( const std::string& _name) const
  { return hprops_.property(_name); }

  const BaseProperty* _get_fprop( const std::string& _name) const
  { return fprops_.property(_name); }

  const BaseProperty* _get_mprop( const std::string& _name) const
  { return mprops_.property(_name); }

  BaseProperty& _vprop( size_t _idx ) { return vprops_._property( _idx ); }
  BaseProperty& _eprop( size_t _idx ) { return eprops_._property( _idx ); }
  BaseProperty& _hprop( size_t _idx ) { return hprops_._property( _idx ); }
  BaseProperty& _fprop( size_t _idx ) { return fprops_._property( _idx ); }
  BaseProperty& _mprop( size_t _idx ) { return mprops_._property( _idx ); }

  const BaseProperty& _vprop( size_t _idx ) const
  { return vprops_._property( _idx ); }
  const BaseProperty& _eprop( size_t _idx ) const
  { return eprops_._property( _idx ); }
  const BaseProperty& _hprop( size_t _idx ) const
  { return hprops_._property( _idx ); }
  const BaseProperty& _fprop( size_t _idx ) const
  { return fprops_._property( _idx ); }
  const BaseProperty& _mprop( size_t _idx ) const
  { return mprops_._property( _idx ); }

  size_t _add_vprop( BaseProperty* _bp ) { return vprops_._add( _bp ); }
  size_t _add_eprop( BaseProperty* _bp ) { return eprops_._add( _bp ); }
  size_t _add_hprop( BaseProperty* _bp ) { return hprops_._add( _bp ); }
  size_t _add_fprop( BaseProperty* _bp ) { return fprops_._add( _bp ); }
  size_t _add_mprop( BaseProperty* _bp ) { return mprops_._add( _bp ); }

protected: // low-level access non-public

  BaseProperty& _vprop( BaseHandle _h )
  { return vprops_._property( _h.idx() ); }
  BaseProperty& _eprop( BaseHandle _h )
  { return eprops_._property( _h.idx() ); }
  BaseProperty& _hprop( BaseHandle _h )
  { return hprops_._property( _h.idx() ); }
  BaseProperty& _fprop( BaseHandle _h )
  { return fprops_._property( _h.idx() ); }
  BaseProperty& _mprop( BaseHandle _h )
  { return mprops_._property( _h.idx() ); }

  const BaseProperty& _vprop( BaseHandle _h ) const
  { return vprops_._property( _h.idx() ); }
  const BaseProperty& _eprop( BaseHandle _h ) const
  { return eprops_._property( _h.idx() ); }
  const BaseProperty& _hprop( BaseHandle _h ) const
  { return hprops_._property( _h.idx() ); }
  const BaseProperty& _fprop( BaseHandle _h ) const
  { return fprops_._property( _h.idx() ); }
  const BaseProperty& _mprop( BaseHandle _h ) const
  { return mprops_._property( _h.idx() ); }


public: //----------------------------------------------------- element numbers


681 682 683 684
  virtual size_t n_vertices()  const { return 0; }
  virtual size_t n_halfedges() const { return 0; }
  virtual size_t n_edges()     const { return 0; }
  virtual size_t n_faces()     const { return 0; }
Jan Möbius's avatar
Jan Möbius committed
685 686 687 688


protected: //------------------------------------------- synchronize properties

689
  /// Reserves space for \p _n elements in all vertex property vectors.
690
  void vprops_reserve(size_t _n) const { vprops_.reserve(_n); }
691 692

  /// Resizes all vertex property vectors to the specified size.
693
  void vprops_resize(size_t _n) const { vprops_.resize(_n); }
694 695 696 697 698 699 700 701 702

  /**
   * Same as vprops_resize() but ignores vertex property vectors that have
   * a size larger than \p _n.
   *
   * Use this method instead of vprops_resize() if you plan to frequently reduce
   * and enlarge the property container and you don't want to waste time
   * reallocating the property vectors every time.
   */
Hans-Christian Ebke's avatar
Hans-Christian Ebke committed
703
  void vprops_resize_if_smaller(size_t _n) const { vprops_.resize_if_smaller(_n); }
704

705 706 707
  void vprops_clear() {
    vprops_.clear();
  }
708

Jan Möbius's avatar
Jan Möbius committed
709 710 711 712
  void vprops_swap(unsigned int _i0, unsigned int _i1) const {
    vprops_.swap(_i0, _i1);
  }

713 714
  void hprops_reserve(size_t _n) const { hprops_.reserve(_n); }
  void hprops_resize(size_t _n) const { hprops_.resize(_n); }
715 716 717
  void hprops_clear() {
    hprops_.clear();
  }
Jan Möbius's avatar
Jan Möbius committed
718 719 720 721
  void hprops_swap(unsigned int _i0, unsigned int _i1) const {
    hprops_.swap(_i0, _i1);
  }

722 723
  void eprops_reserve(size_t _n) const { eprops_.reserve(_n); }
  void eprops_resize(size_t _n) const { eprops_.resize(_n); }
724 725 726
  void eprops_clear() {
    eprops_.clear();
  }
Jan Möbius's avatar
Jan Möbius committed
727 728 729 730
  void eprops_swap(unsigned int _i0, unsigned int _i1) const {
    eprops_.swap(_i0, _i1);
  }

731 732
  void fprops_reserve(size_t _n) const { fprops_.reserve(_n); }
  void fprops_resize(size_t _n) const { fprops_.resize(_n); }
733 734 735
  void fprops_clear() {
    fprops_.clear();
  }
Jan Möbius's avatar
Jan Möbius committed
736 737 738 739
  void fprops_swap(unsigned int _i0, unsigned int _i1) const {
    fprops_.swap(_i0, _i1);
  }

740
  void mprops_resize(size_t _n) const { mprops_.resize(_n); }
741 742 743
  void mprops_clear() {
    mprops_.clear();
  }
Jan Möbius's avatar
Jan Möbius committed
744 745 746

public:

747 748 749
  // uses std::clog as output stream
  void property_stats() const;
  void property_stats(std::ostream& _ostr) const;
Jan Möbius's avatar
Jan Möbius committed
750

751 752 753 754 755 756
  void vprop_stats( std::string& _string ) const;
  void hprop_stats( std::string& _string ) const;
  void eprop_stats( std::string& _string ) const;
  void fprop_stats( std::string& _string ) const;
  void mprop_stats( std::string& _string ) const;

757 758 759 760 761 762 763 764 765 766 767 768
  // uses std::clog as output stream
  void vprop_stats() const;
  void hprop_stats() const;
  void eprop_stats() const;
  void fprop_stats() const;
  void mprop_stats() const;

  void vprop_stats(std::ostream& _ostr) const;
  void hprop_stats(std::ostream& _ostr) const;
  void eprop_stats(std::ostream& _ostr) const;
  void fprop_stats(std::ostream& _ostr) const;
  void mprop_stats(std::ostream& _ostr) const;
769

Jan Möbius's avatar
Jan Möbius committed
770 771 772 773 774 775 776 777 778 779 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 807 808 809 810 811 812 813 814
public:

  typedef PropertyContainer::iterator prop_iterator;
  typedef PropertyContainer::const_iterator const_prop_iterator;

  prop_iterator vprops_begin() { return vprops_.begin(); }
  prop_iterator vprops_end()   { return vprops_.end(); }
  const_prop_iterator vprops_begin() const { return vprops_.begin(); }
  const_prop_iterator vprops_end()   const { return vprops_.end(); }

  prop_iterator eprops_begin() { return eprops_.begin(); }
  prop_iterator eprops_end()   { return eprops_.end(); }
  const_prop_iterator eprops_begin() const { return eprops_.begin(); }
  const_prop_iterator eprops_end()   const { return eprops_.end(); }

  prop_iterator hprops_begin() { return hprops_.begin(); }
  prop_iterator hprops_end()   { return hprops_.end(); }
  const_prop_iterator hprops_begin() const { return hprops_.begin(); }
  const_prop_iterator hprops_end()   const { return hprops_.end(); }

  prop_iterator fprops_begin() { return fprops_.begin(); }
  prop_iterator fprops_end()   { return fprops_.end(); }
  const_prop_iterator fprops_begin() const { return fprops_.begin(); }
  const_prop_iterator fprops_end()   const { return fprops_.end(); }

  prop_iterator mprops_begin() { return mprops_.begin(); }
  prop_iterator mprops_end()   { return mprops_.end(); }
  const_prop_iterator mprops_begin() const { return mprops_.begin(); }
  const_prop_iterator mprops_end()   const { return mprops_.end(); }

private:

  PropertyContainer  vprops_;
  PropertyContainer  hprops_;
  PropertyContainer  eprops_;
  PropertyContainer  fprops_;
  PropertyContainer  mprops_;
};


//=============================================================================
} // namespace OpenMesh
//=============================================================================
#endif // OPENMESH_BASE_KERNEL_HH defined
//=============================================================================