ModQuadricT.hh
Go to the documentation of this file.
/* ========================================================================= *
* *
* OpenMesh *
* Copyright (c) 2001-2015, 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. *
* *
* ========================================================================= */
/*===========================================================================*\
* *
* $Revision$ *
* $Date$ *
* *
\*===========================================================================*/
//=============================================================================
//
// CLASS ModQuadricT
//
//=============================================================================
#ifndef OSG_MODQUADRIC_HH
#define OSG_MODQUADRIC_HH
//== INCLUDES =================================================================
#include <float.h>
#include <OpenMesh/Tools/Decimater/ModBaseT.hh>
#include <OpenMesh/Core/Utils/Property.hh>
#include <OpenMesh/Core/Utils/vector_cast.hh>
#include <OpenMesh/Core/Geometry/QuadricT.hh>
//== NAMESPACE ================================================================
namespace OpenMesh {
namespace Decimater {
//== CLASS DEFINITION =========================================================
template <class MeshT>
class ModQuadricT : public ModBaseT<MeshT>
{
public:
// Defines the types Self, Handle, Base, Mesh, and CollapseInfo
// and the memberfunction name()
DECIMATING_MODULE( ModQuadricT, MeshT, Quadric );
public:
ModQuadricT( MeshT &_mesh )
: Base(_mesh, false)
{
unset_max_err();
Base::mesh().add_property( quadrics_ );
}
virtual ~ModQuadricT()
{
Base::mesh().remove_property(quadrics_);
}
public: // inherited
virtual void initialize(void);
virtual float collapse_priority(const CollapseInfo& _ci)
{
using namespace OpenMesh;
typedef Geometry::QuadricT<double> Q;
Q q = Base::mesh().property(quadrics_, _ci.v0);
q += Base::mesh().property(quadrics_, _ci.v1);
double err = q(_ci.p1);
//min_ = std::min(err, min_);
//max_ = std::max(err, max_);
//double err = q( p );
return float( (err < max_err_) ? err : float( Base::ILLEGAL_COLLAPSE ) );
}
virtual void postprocess_collapse(const CollapseInfo& _ci)
{
Base::mesh().property(quadrics_, _ci.v1) +=
Base::mesh().property(quadrics_, _ci.v0);
}
void set_error_tolerance_factor(double _factor);
public: // specific methods
void set_max_err(double _err, bool _binary=true)
{
max_err_ = _err;
Base::set_binary(_binary);
}
void unset_max_err(void)
{
max_err_ = DBL_MAX;
Base::set_binary(false);
}
double max_err() const { return max_err_; }
private:
// maximum quadric error
double max_err_;
// this vertex property stores a quadric for each vertex
VPropHandleT< Geometry::QuadricT<double> > quadrics_;
};
//=============================================================================
} // END_NS_DECIMATER
} // END_NS_OPENMESH
//=============================================================================
#if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_DECIMATER_MODQUADRIC_CC)
#define OSG_MODQUADRIC_TEMPLATES
#include "ModQuadricT.cc"
#endif
//=============================================================================
#endif // OSG_MODQUADRIC_HH defined
//=============================================================================
DECIMATING_MODULE
#define DECIMATING_MODULE(Classname, MeshT, Name)
Convenience macro, to be used in derived modules The macro defines the types.
Definition: ModBaseT.hh:154
OpenMesh::Decimater::ModQuadricT::unset_max_err
void unset_max_err(void)
Unset maximum quadric error constraint and restore non-binary mode.
Definition: ModQuadricT.hh:169
OpenMesh::Decimater::ModQuadricT::initialize
virtual void initialize(void)
Initalize the module and prepare the mesh for decimation.
Definition: ModQuadricT.cc:78
OpenMesh::Decimater::ModQuadricT::set_error_tolerance_factor
void set_error_tolerance_factor(double _factor)
set the percentage of maximum quadric error
Definition: ModQuadricT.cc:141
QuadricT.hh
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:64
OpenMesh::Decimater::CollapseInfoT::v0
Mesh::VertexHandle v0
Vertex to be removed.
Definition: CollapseInfoT.hh:97
OpenMesh::Decimater::ModQuadricT::postprocess_collapse
virtual void postprocess_collapse(const CollapseInfo &_ci)
Post-process halfedge collapse (accumulate quadrics)
Definition: ModQuadricT.hh:142
OpenMesh::Decimater::ModQuadricT
Mesh decimation module computing collapse priority based on error quadrics.
Definition: ModQuadricT.hh:83
OpenMesh::Decimater::ModQuadricT::ModQuadricT
ModQuadricT(MeshT &_mesh)
Constructor.
Definition: ModQuadricT.hh:96
OpenMesh::Decimater::ModQuadricT::max_err
double max_err() const
Return value of max. allowed error.
Definition: ModQuadricT.hh:176
OpenMesh::Decimater::ModQuadricT::~ModQuadricT
virtual ~ModQuadricT()
Destructor.
Definition: ModQuadricT.hh:105
OpenMesh::Decimater::ModQuadricT::set_max_err
void set_max_err(double _err, bool _binary=true)
Set maximum quadric error constraint and enable binary mode.
Definition: ModQuadricT.hh:161
OpenMesh::VPropHandleT
Handle representing a vertex property.
Definition: Property.hh:487
OpenMesh::Decimater::CollapseInfoT
Stores information about a halfedge collapse.
Definition: CollapseInfoT.hh:80
OpenMesh::Decimater::ModQuadricT::collapse_priority
virtual float collapse_priority(const CollapseInfo &_ci)
Compute collapse priority based on error quadrics.
Definition: ModQuadricT.hh:121
ModQuadricT.cc
Bodies of template member function.
OpenMesh::Geometry::QuadricT
/class QuadricT Geometry/QuadricT.hh
Definition: QuadricT.hh:87
OpenMesh::Decimater::CollapseInfoT::v1
Mesh::VertexHandle v1
Remaining vertex.
Definition: CollapseInfoT.hh:98
OpenMesh::Decimater::CollapseInfoT::p1
Mesh::Point p1
Positions of remaining vertex.
Definition: CollapseInfoT.hh:100
OpenMesh::Decimater::ModBaseT
Base class for all decimation modules.
Definition: ModBaseT.hh:197
ModBaseT.hh
Base class for all decimation modules.