Loading...
Searching...
No Matches
ModBaseT.hh
Go to the documentation of this file.
/* ========================================================================= *
* *
* OpenMesh *
* Copyright (c) 2001-2025, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openmesh.org *
* *
*---------------------------------------------------------------------------*
* 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. *
* *
* ========================================================================= */
//=============================================================================
//
// CLASS ModBaseT
//
//=============================================================================
#ifndef OPENMESH_DECIMATER_MODBASET_HH
#define OPENMESH_DECIMATER_MODBASET_HH
//== INCLUDES =================================================================
#include <OpenMesh/Core/Utils/Noncopyable.hh>
#include <OpenMesh/Tools/Decimater/CollapseInfoT.hh>
#include <string>
//== NAMESPACE ================================================================
namespace OpenMesh {
namespace Decimater {
//== FORWARD DECLARATIONS =====================================================
template <typename Mesh> class BaseDecimaterT;
//== CLASS DEFINITION =========================================================
template <typename Module>
class ModHandleT : private Utils::Noncopyable
{
public:
typedef ModHandleT<Module> Self;
typedef Module module_type;
public:
ModHandleT() : mod_(nullptr) {}
~ModHandleT() { /* don't delete mod_, since handle is not owner! */ }
bool is_valid() const { return mod_ != nullptr; }
private:
#if defined(OM_CC_MSVC)
friend class BaseDecimaterT;
#else
template <typename Mesh> friend class BaseDecimaterT;
#endif
void clear() { mod_ = nullptr; }
void init(Module* _m) { mod_ = _m; }
Module* module() { return mod_; }
private:
Module* mod_;
};
//== CLASS DEFINITION =========================================================
#define DECIMATER_MODNAME(_mod_name) \
virtual const std::string& name() const override { \
static std::string _s_modname_(#_mod_name); return _s_modname_; \
}
#define DECIMATING_MODULE(Classname, MeshT, Name) \
typedef Classname < MeshT > Self; \
typedef OpenMesh::Decimater::ModHandleT< Self > Handle; \
typedef OpenMesh::Decimater::ModBaseT< MeshT > Base; \
typedef typename Base::Mesh Mesh; \
typedef typename Base::CollapseInfo CollapseInfo; \
DECIMATER_MODNAME( Name )
//== CLASS DEFINITION =========================================================
template <typename MeshT>
class ModBaseT
{
public:
typedef MeshT Mesh;
typedef CollapseInfoT<MeshT> CollapseInfo;
enum {
ILLEGAL_COLLAPSE = -1,
LEGAL_COLLAPSE = 0
};
protected:
ModBaseT(MeshT& _mesh, bool _is_binary)
: error_tolerance_factor_(1.0), mesh_(_mesh), is_binary_(_is_binary) {}
public:
virtual ~ModBaseT() { }
virtual const std::string& name() const { static std::string _s_modname_("ModBase"); return _s_modname_; }
bool is_binary(void) const { return is_binary_; }
void set_binary(bool _b) { is_binary_ = _b; }
public: // common interface
virtual void initialize() { }
virtual float collapse_priority(const CollapseInfoT<MeshT>& /* _ci */)
{ return LEGAL_COLLAPSE; }
virtual void preprocess_collapse(const CollapseInfoT<MeshT>& /* _ci */)
{}
virtual void postprocess_collapse(const CollapseInfoT<MeshT>& /* _ci */)
{}
virtual void set_error_tolerance_factor(double _factor) {
if (_factor >= 0.0 && _factor <= 1.0)
error_tolerance_factor_ = _factor;
}
protected:
MeshT& mesh() { return mesh_; }
// current percentage of the original constraint
double error_tolerance_factor_;
private:
// hide copy constructor & assignemnt
ModBaseT(const ModBaseT& _cpy);
ModBaseT& operator=(const ModBaseT& );
MeshT& mesh_;
bool is_binary_;
};
//=============================================================================
} // namespace Decimater
} // namespace OpenMesh
//=============================================================================
#endif // OPENMESH_DECIMATER_MODBASE_HH defined
//=============================================================================
CollapseInfoT.hh
Provides data class CollapseInfoT for storing all information about a halfedge collapse.
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition MeshItems.hh:59
OpenMesh::Utils::Noncopyable
This class demonstrates the non copyable idiom.
Definition Noncopyable.hh:72
OpenMesh::Decimater::BaseDecimaterT
Definition BaseDecimaterT.hh:86
OpenMesh::Decimater::CollapseInfoT
Stores information about a halfedge collapse.
Definition CollapseInfoT.hh:74
OpenMesh::Decimater::ModHandleT
Handle for mesh decimation modules.
Definition ModBaseT.hh:84
OpenMesh::Decimater::ModHandleT::~ModHandleT
~ModHandleT()
Destructor.
Definition ModBaseT.hh:96
OpenMesh::Decimater::ModHandleT::is_valid
bool is_valid() const
Check handle status.
Definition ModBaseT.hh:100
OpenMesh::Decimater::ModHandleT::ModHandleT
ModHandleT()
Default constructor.
Definition ModBaseT.hh:93
OpenMesh::Decimater::ModBaseT
Base class for all decimation modules.
Definition ModBaseT.hh:193
OpenMesh::Decimater::ModBaseT::is_binary
bool is_binary(void) const
Returns true if criteria returns a binary value.
Definition ModBaseT.hh:220
OpenMesh::Decimater::ModBaseT::initialize
virtual void initialize()
Initialize module-internal stuff.
Definition ModBaseT.hh:229
OpenMesh::Decimater::ModBaseT::set_binary
void set_binary(bool _b)
Set whether module is binary or not.
Definition ModBaseT.hh:223
OpenMesh::Decimater::ModBaseT::set_error_tolerance_factor
virtual void set_error_tolerance_factor(double _factor)
This provides a function that allows the setting of a percentage of the original contraint.
Definition ModBaseT.hh:268
OpenMesh::Decimater::ModBaseT::LEGAL_COLLAPSE
@ LEGAL_COLLAPSE
indicates a legal collapse
Definition ModBaseT.hh:200
OpenMesh::Decimater::ModBaseT::ILLEGAL_COLLAPSE
@ ILLEGAL_COLLAPSE
indicates an illegal collapse
Definition ModBaseT.hh:199
OpenMesh::Decimater::ModBaseT::preprocess_collapse
virtual void preprocess_collapse(const CollapseInfoT< MeshT > &)
Before _from_vh has been collapsed into _to_vh, this method will be called.
Definition ModBaseT.hh:251
OpenMesh::Decimater::ModBaseT::mesh
MeshT & mesh()
Access the mesh associated with the decimater.
Definition ModBaseT.hh:277
OpenMesh::Decimater::ModBaseT::postprocess_collapse
virtual void postprocess_collapse(const CollapseInfoT< MeshT > &)
After _from_vh has been collapsed into _to_vh, this method will be called.
Definition ModBaseT.hh:257
OpenMesh::Decimater::ModBaseT::~ModBaseT
virtual ~ModBaseT()
Virtual desctructor.
Definition ModBaseT.hh:213
OpenMesh::Decimater::ModBaseT::name
virtual const std::string & name() const
Set module's name.
Definition ModBaseT.hh:216
OpenMesh::Decimater::ModBaseT::ModBaseT
ModBaseT(MeshT &_mesh, bool _is_binary)
Default constructor.
Definition ModBaseT.hh:207
OpenMesh::Decimater::ModBaseT::collapse_priority
virtual float collapse_priority(const CollapseInfoT< MeshT > &)
Return collapse priority.
Definition ModBaseT.hh:245