- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# Tools/Subdivider/Adaptive/Composite/CompositeT.hh

Go to the documentation of this file.

    00001 //=============================================================================
    00002 //
    00003 //                               OpenMesh
    00004 //      Copyright (C) 2001-2005 by Computer Graphics Group, RWTH Aachen
    00005 //                           www.openmesh.org
    00006 //
    00007 //-----------------------------------------------------------------------------
    00008 //
    00009 //                                License
    00010 //
    00011 //   This library is free software; you can redistribute it and/or modify it
    00012 //   under the terms of the GNU Library General Public License as published
    00013 //   by the Free Software Foundation, version 2.
    00014 //
    00015 //   This library is distributed in the hope that it will be useful, but
    00016 //   WITHOUT ANY WARRANTY; without even the implied warranty of
    00017 //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00018 //   Library General Public License for more details.
    00019 //
    00020 //   You should have received a copy of the GNU Library General Public
    00021 //   License along with this library; if not, write to the Free Software
    00022 //   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00023 //
    00024 //-----------------------------------------------------------------------------
    00025 //
    00026 //   $Revision: 1.3 $
    00027 //   $Date: 2005-12-21 13:58:54 $
    00028 //
    00029 //=============================================================================
    00030
    00035 //=============================================================================
    00036 //
    00037 //  CLASS CompositeT
    00038 //
    00039 //=============================================================================
    00040
    00041 #ifndef OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_HH
    00042 #define OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_HH
    00043
    00044
    00045 //== INCLUDES =================================================================
    00046
    00047 #include <OpenMesh/Core/System/config.hh>
    00048 #include <OpenMesh/Tools/Subdivider/Adaptive/Composite/CompositeTraits.hh>
    00049 // --------------------
    00050 #include <vector>
    00051 #include <memory>
    00052 #include <string>
    00053
    00054
    00055 //== NAMESPACE ================================================================
    00056
    00057 namespace OpenMesh   { // BEGIN_NS_OPENMESH
    00058 namespace Subdivider { // BEGIN_NS_SUBDIVIDER
    00059 namespace Adaptive   { // BEGIN_NS_ADAPTIVE
    00060
    00061
    00062 //== CLASS DEFINITION =========================================================
    00063
    00064
    00065 template <typename R> struct RuleHandleT;
    00066 template <typename M> class  RuleInterfaceT;
    00067
    00068
    00069 //== CLASS DEFINITION =========================================================
    00070
    00120 template <typename M> class CompositeT
    00121 {
    00122 public:
    00123
    00124   typedef CompositeT< M >    Self;
    00125   typedef RuleInterfaceT<M>  Rule;
    00126   typedef M                  Mesh;
    00127   typedef std::vector<Rule*> RuleSequence;
    00128
    00129   typedef typename M::VertexHandle   VH;
    00130   typedef typename M::FaceHandle     FH;
    00131   typedef typename M::EdgeHandle     EH;
    00132   typedef typename M::HalfedgeHandle HH;
    00133
    00134 public:
    00135
    00137   CompositeT(Mesh& _mesh)
    00138     : subdiv_type_(0),
    00139       subdiv_rule_(NULL), /*first_rule_(NULL), last_rule_(NULL),*/ mesh_(_mesh)
    00140   { }
    00141
    00143   virtual ~CompositeT()
    00144   { cleanup(); }
    00145
    00146
    00149   void cleanup(void)
    00150   {
    00151     subdiv_type_ = 0;
    00152     subdiv_rule_ = NULL;
    00153
    00154     std::for_each(rule_sequence_.begin(),
    00155                   rule_sequence_.end(), DeleteRule() );
    00156     rule_sequence_.clear();
    00157   }
    00158
    00159
    00161   bool initialize(void);
    00162
    00163
    00165   void refine(typename Mesh::FaceHandle& _fh);
    00166
    00167
    00169   void refine(typename Mesh::VertexHandle& _vh);
    00170
    00171
    00173   int subdiv_type() { return subdiv_type_; }
    00174
    00175
    00176   // Return subdivision rule.
    00177   const Rule& subdiv_rule() const { return *subdiv_rule_; }
    00178
    00179 public:
    00180
    00182   //*@
    00183
    00188   template < typename R >
    00189   RuleHandleT<R> add()
    00190   {
    00191     size_t idx = rule_sequence_.size();
    00192     rule_sequence_.push_back( new R( mesh_ ) );
    00193     return RuleHandleT<R>( (idx < rule_sequence_.size()) ? idx : -1 );
    00194   }
    00195
    00200   template < typename R >
    00201   RuleHandleT<R>& add( RuleHandleT<R>& _rh )
    00202   {
    00203     return _rh = add< R >();
    00204   }
    00205
    00211   template < typename R >
    00212   typename RuleHandleT<R>::Rule& rule( const RuleHandleT<R>& _rh )
    00213   {
    00214     typedef typename RuleHandleT<R>::Rule rule_t;
    00215     assert( _rh.is_valid() );
    00216     return *dynamic_cast<rule_t*>(rule_sequence_[ _rh.idx() ]);
    00217   }
    00218
    00219
    00225   RuleInterfaceT<M>& rule( size_t _idx )
    00226   {
    00227     assert( _idx < n_rules() );
    00228     return *rule_sequence_[ _idx ];
    00229   }
    00230
    00232   size_t n_rules() const { return rule_sequence_.size(); }
    00233
    00235   std::string rules_as_string(const std::string& _sep= " * ") const;
    00236
    00238
    00239 protected:
    00240
    00242   const RuleSequence& rules() const { return rule_sequence_; }
    00243
    00244 protected: // helper
    00245
    00246   // get current generation from state
    00247   state_t generation(state_t _s) { return _s-(_s % n_rules()); }
    00248   state_t generation( VH _vh ) { return generation(mesh_.deref(_vh).state()); }
    00249   state_t generation( EH _eh ) { return generation(mesh_.deref(_eh).state()); }
    00250   state_t generation( FH _fh ) { return generation(mesh_.deref(_fh).state()); }
    00251
    00252 private:
    00253
    00254   // short cuts
    00255   Rule* t_rule() { return subdiv_rule_;           }
    00256   Rule* f_rule() { return rule_sequence_.front(); }
    00257   Rule* l_rule() { return rule_sequence_.back();  }
    00258
    00259 private:
    00260
    00261   //
    00262   RuleSequence rule_sequence_;
    00263
    00264   // Split type
    00265   int   subdiv_type_;
    00266
    00267   Rule  *subdiv_rule_;
    00268 //   Rule  *first_rule_;
    00269 //   Rule  *last_rule_;
    00270
    00271   //
    00272   Mesh  &mesh_;
    00273
    00274 private: // helper
    00275
    00276 #ifndef DOXY_IGNORE_THIS
    00277   struct DeleteRule { void operator()( Rule* _r ) { delete _r; } };
    00278 #endif
    00279
    00280 private:
    00281
    00282   CompositeT( const CompositeT& );
    00283   CompositeT& operator = ( const CompositeT );
    00284
    00285 };
    00286
    00287
    00288 //=============================================================================
    00289 } // END_NS_ADAPTIVE
    00290 } // END_NS_SUBDIVIDER
    00291 } // END_NS_OPENMESH
    00292 //=============================================================================
    00293 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_CC)
    00294 #  define OPENMESH_SUBDIVIDER_TEMPLATES
    00295 #  include "CompositeT.cc"
    00296 #endif
    00297 //=============================================================================
    00298 #endif // OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_HH defined
    00299 //=============================================================================