BaseRemesherT.hh 6.53 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1 2 3
/*===========================================================================*\
*                                                                            *
*                              OpenFlipper                                   *
Martin Schultz's avatar
Martin Schultz committed
4 5 6 7 8 9 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
 *           Copyright (c) 2001-2015, RWTH-Aachen University                 *
 *           Department of Computer Graphics and Multimedia                  *
 *                          All rights reserved.                             *
 *                            www.openflipper.org                            *
 *                                                                           *
 *---------------------------------------------------------------------------*
 * This file is part of OpenFlipper.                                         *
 *---------------------------------------------------------------------------*
 *                                                                           *
 * 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 46 47 48 49 50 51 52
*                                                                            *
\*===========================================================================*/


//=============================================================================
//
//  CLASS BaseRemesherT
//
//=============================================================================


#ifndef BASE_REMESHERT_HH
#define BASE_REMESHERT_HH

Matthias Möller's avatar
Matthias Möller committed
53 54 55 56 57 58
/**
 *  BaseRemesher implements a modified version of a remesher approach presented by Mario Botsch and Leif Kobbelt in
 *  "A Remeshing Approach to Multiresolution Modeling" published at Symposium on Geometry Processing 2004 p. 189-196
 *  Paper can found at: http://www.graphics.rwth-aachen.de/publications/0000/37/
 */

Jan Möbius's avatar
Jan Möbius committed
59 60 61 62

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

#include <OpenMesh/Core/Utils/Property.hh>
63
#include <ACG/Geometry/bsp/TriangleBSPT.hh>
Jan Möbius's avatar
Jan Möbius committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

#include "../ProgressEmitter.hh"

//== FORWARDDECLARATIONS ======================================================


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

namespace Remeshing {


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


template <class Mesh>
class BaseRemesherT
{
public:

Matthias Möller's avatar
Matthias Möller committed
83 84 85 86 87 88
  enum Selection
  {
    VERTEX_SELECTION,
    FACE_SELECTION
  };

89 90 91 92 93
  typedef typename Mesh::Scalar         Scalar;
  typedef typename Mesh::Point          Point;
  typedef typename Mesh::EdgeHandle     EdgeHandle;
  typedef typename Mesh::HalfedgeHandle HalfedgeHandle;
  typedef typename Mesh::VertexHandle   VertexHandle;
Jan Möbius's avatar
Jan Möbius committed
94 95 96 97 98 99 100


  BaseRemesherT(Mesh& _mesh, ProgressEmitter* _progress = NULL);
  virtual ~BaseRemesherT();

  void remesh(unsigned int  _iters,
              unsigned int  _area_iters,
Matthias Möller's avatar
Matthias Möller committed
101 102
              bool          _use_projection = true,
              Selection     _selection=VERTEX_SELECTION);
Jan Möbius's avatar
Jan Möbius committed
103 104 105 106 107



protected:

Matthias Möller's avatar
Matthias Möller committed
108 109 110 111
  /// prepare for remeshing only selected vertices (if no vertex was selected, remesh whole mesh)
  void prepare_vertex_selection();
  /// prepare for remeshing only vertices which are fully surrounded by selected faces (if no face was selected, remesh whole mesh)
  void prepare_face_selection();
Jan Möbius's avatar
Jan Möbius committed
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
  void remeshh(unsigned int _iters, unsigned int _aiters, bool _proj);
  void cleanup();

  virtual void init_reference();
  virtual void delete_reference();
  virtual void project_to_reference(VertexHandle _vh) const;

  void split_long_edges();
  void collapse_short_edges();
  void flip_edges();
  void tangential_smoothing(bool _use_projection);
  void balanace_area(unsigned int _iters, bool _use_projection);
  void remove_caps();

  virtual bool is_too_long  (VertexHandle _v0, VertexHandle _v1) const = 0;
  virtual bool is_too_short (VertexHandle _v0, VertexHandle _v1) const = 0;

129 130
  bool edge_flip_flips_normal(EdgeHandle _eh);
  bool collapse_flips_normal(HalfedgeHandle _heh);
Jan Möbius's avatar
Jan Möbius committed
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154

  
protected:

  typedef OpenMeshTriangleBSPT<Mesh>  BSP;

  Mesh&  mesh_;
  Mesh*  refmesh_;
  BSP*   bsp_;
  bool   nothing_selected_;

  OpenMesh::VPropHandleT<int>     valences_;
  OpenMesh::VPropHandleT<Point>   update_;
  OpenMesh::VPropHandleT<Scalar>  area_;

  ProgressEmitter* progress_;
};


//=============================================================================
} // namespace Remeshing
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(BASE_REMESHERT_C)
#define BASE_REMESHERT_TEMPLATES
155
#include "BaseRemesherT_impl.hh"
Jan Möbius's avatar
Jan Möbius committed
156 157 158 159 160
#endif
//=============================================================================
#endif // BASE_REMESHERT_HH defined
//=============================================================================