Loading...
Searching...
No Matches
CompositeT.hh
Go to the documentation of this file.
/* ========================================================================= *
* *
* OpenMesh *
* Copyright (c) 2001-2022, 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 CompositeT
//
//=============================================================================
#ifndef OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_HH
#define OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_HH
//== INCLUDES =================================================================
#include <OpenMesh/Core/System/config.hh>
#include <OpenMesh/Tools/Subdivider/Adaptive/Composite/CompositeTraits.hh>
// --------------------
#include <vector>
#include <memory>
#include <string>
//== NAMESPACE ================================================================
namespace OpenMesh { // BEGIN_NS_OPENMESH
namespace Subdivider { // BEGIN_NS_SUBDIVIDER
namespace Adaptive { // BEGIN_NS_ADAPTIVE
//== CLASS DEFINITION =========================================================
template <typename R> struct RuleHandleT;
template <typename M> class RuleInterfaceT;
//== CLASS DEFINITION =========================================================
template <typename M> class CompositeT
{
public:
typedef RuleInterfaceT<M> Rule;
typedef M Mesh;
typedef std::vector<Rule*> RuleSequence;
typedef typename M::VertexHandle VH;
typedef typename M::FaceHandle FH;
typedef typename M::EdgeHandle EH;
typedef typename M::HalfedgeHandle HH;
public:
explicit CompositeT(Mesh& _mesh)
: subdiv_type_(0),
subdiv_rule_(nullptr), /*first_rule_(nullptr), last_rule_(nullptr),*/ mesh_(_mesh)
{ }
virtual ~CompositeT()
{ cleanup(); }
void cleanup(void)
{
subdiv_type_ = 0;
subdiv_rule_ = nullptr;
std::for_each(rule_sequence_.begin(),
rule_sequence_.end(), DeleteRule() );
rule_sequence_.clear();
}
bool initialize(void);
void refine(typename M::FaceHandle& _fh);
void refine(typename M::VertexHandle& _vh);
int subdiv_type() { return subdiv_type_; }
// Return subdivision rule.
const Rule& subdiv_rule() const { return *subdiv_rule_; }
public:
//*@
template < typename R >
RuleHandleT<R> add()
{
size_t idx = rule_sequence_.size();
rule_sequence_.push_back( new R( mesh_ ) );
return RuleHandleT<R>( (idx < rule_sequence_.size()) ? idx : -1 );
}
template < typename R >
RuleHandleT<R>& add( RuleHandleT<R>& _rh )
{
return _rh = add< R >();
}
template < typename R >
typename RuleHandleT<R>::Rule& rule( const RuleHandleT<R>& _rh )
{
typedef typename RuleHandleT<R>::Rule rule_t;
assert( _rh.is_valid() );
return *dynamic_cast<rule_t*>(rule_sequence_[ _rh.idx() ]);
}
RuleInterfaceT<M>& rule( size_t _idx )
{
assert( _idx < n_rules() );
return *rule_sequence_[ _idx ];
}
size_t n_rules() const { return rule_sequence_.size(); }
std::string rules_as_string(const std::string& _sep= " * ") const;
protected:
const RuleSequence& rules() const { return rule_sequence_; }
protected: // helper
// get current generation from state
state_t generation(state_t _s) const { return _s-(_s % n_rules()); }
state_t generation( VH _vh ) const { return generation(mesh_.data(_vh).state()); }
state_t generation( EH _eh ) const { return generation(mesh_.data(_eh).state()); }
state_t generation( FH _fh ) const { return generation(mesh_.data(_fh).state()); }
private:
// short cuts
Rule* t_rule() const { return subdiv_rule_; }
Rule* f_rule() { return rule_sequence_.front(); }
Rule* l_rule() { return rule_sequence_.back(); }
private:
//
RuleSequence rule_sequence_;
// Split type
int subdiv_type_;
Rule *subdiv_rule_;
// Rule *first_rule_;
// Rule *last_rule_;
//
Mesh &mesh_;
private: // helper
#ifndef DOXY_IGNORE_THIS
struct DeleteRule { void operator()( Rule* _r ) { delete _r; } };
#endif
private:
CompositeT( const CompositeT& );
CompositeT& operator = ( const CompositeT );
};
//=============================================================================
} // END_NS_ADAPTIVE
} // END_NS_SUBDIVIDER
} // END_NS_OPENMESH
//=============================================================================
#if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_CC)
# define OPENMESH_SUBDIVIDER_TEMPLATES
# include "CompositeT_impl.hh"
#endif
//=============================================================================
#endif // OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_HH defined
//=============================================================================
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition MeshItems.hh:59
OpenMesh::Subdivider::Adaptive::state_t
CompositeTraits::state_t state_t
Adaptive Composite Subdivision framework.
Definition CompositeTraits.hh:250
OpenMesh::BaseHandle::is_valid
bool is_valid() const
The handle is valid iff the index is not negative.
Definition Handles.hh:72
OpenMesh::BaseHandle::idx
int idx() const
Get the underlying index of this handle.
Definition Handles.hh:69
OpenMesh::Subdivider::Adaptive::RuleHandleT
Handle template for adaptive composite subdividion rules.
Definition RuleInterfaceT.hh:84
OpenMesh::Subdivider::Adaptive::RuleInterfaceT
Base class for adaptive composite subdivision rules.
Definition RuleInterfaceT.hh:109
OpenMesh::Subdivider::Adaptive::CompositeT
Adaptive Composite Subdivision framework.
Definition CompositeT.hh:134
OpenMesh::Subdivider::Adaptive::CompositeT::add
RuleHandleT< R > add()
Add new rule to rule sequence by passing the type of the wanted rule as template argument to the meth...
Definition CompositeT.hh:201
OpenMesh::Subdivider::Adaptive::CompositeT::CompositeT
CompositeT(Mesh &_mesh)
Constructor.
Definition CompositeT.hh:149
OpenMesh::Subdivider::Adaptive::CompositeT::generation
state_t generation(VH _vh) const
Add new rule to rule sequence by passing the type of the wanted rule as template argument to the meth...
Definition CompositeT.hh:260
OpenMesh::Subdivider::Adaptive::CompositeT::rule
RuleInterfaceT< M > & rule(size_t _idx)
Get rule (interface) by index.
Definition CompositeT.hh:237
OpenMesh::Subdivider::Adaptive::CompositeT::n_rules
size_t n_rules() const
Number of rules in the rule sequence.
Definition CompositeT.hh:244
OpenMesh::Subdivider::Adaptive::CompositeT::add
RuleHandleT< R > & add(RuleHandleT< R > &_rh)
Add new rule to rule sequence by passing an appropriate handle to the method.
Definition CompositeT.hh:213
OpenMesh::Subdivider::Adaptive::CompositeT::generation
state_t generation(FH _fh) const
Add new rule to rule sequence by passing the type of the wanted rule as template argument to the meth...
Definition CompositeT.hh:262
OpenMesh::Subdivider::Adaptive::CompositeT::generation
state_t generation(state_t _s) const
Add new rule to rule sequence by passing the type of the wanted rule as template argument to the meth...
Definition CompositeT.hh:259
OpenMesh::Subdivider::Adaptive::CompositeT::rules
const RuleSequence & rules() const
The rule sequence.
Definition CompositeT.hh:254
OpenMesh::Subdivider::Adaptive::CompositeT::generation
state_t generation(EH _eh) const
Add new rule to rule sequence by passing the type of the wanted rule as template argument to the meth...
Definition CompositeT.hh:261
OpenMesh::Subdivider::Adaptive::CompositeT::cleanup
void cleanup(void)
Reset self to state after the default constructor except of the mesh.
Definition CompositeT.hh:161
OpenMesh::Subdivider::Adaptive::CompositeT::rule
RuleHandleT< R >::Rule & rule(const RuleHandleT< R > &_rh)
Get rule in the rule sequence by a handle.
Definition CompositeT.hh:224
OpenMesh::Subdivider::Adaptive::CompositeT::subdiv_type
int subdiv_type()
Return subdivision split type (3 for 1-to-3 split, 4 for 1-to-4 split).
Definition CompositeT.hh:185
CompositeTraits.hh
Mesh traits for adaptive composite subdivider.