Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

CompositeT.hh

Go to the documentation of this file.
00001 //=============================================================================
00002 //                                                                            
00003 //                               OpenMesh                                     
00004 //        Copyright (C) 2003 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.7 $
00027 //   $Date: 2004/01/20 16:01:46 $
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 RuleInterfaceT<M>  Rule;
00125   typedef M                  Mesh;
00126   typedef std::vector<Rule*> RuleSequence;
00127 
00128   typedef typename M::VertexHandle   VH;
00129   typedef typename M::FaceHandle     FH;
00130   typedef typename M::EdgeHandle     EH;
00131   typedef typename M::HalfedgeHandle HH;
00132 
00133 public:
00134 
00136   CompositeT(Mesh& _mesh) 
00137     : subdiv_type_(0), 
00138       subdiv_rule_(NULL), /*first_rule_(NULL), last_rule_(NULL),*/ mesh_(_mesh)
00139   { }
00140 
00142   virtual ~CompositeT() 
00143   { cleanup(); }
00144 
00145 
00148   void cleanup(void)
00149   {
00150     subdiv_type_ = 0;
00151     subdiv_rule_ = NULL;
00152 
00153     std::for_each(rule_sequence_.begin(), 
00154                   rule_sequence_.end(), DeleteRule() );
00155     rule_sequence_.clear();
00156   }
00157 
00158 
00160   bool initialize(void);
00161 
00162   
00164   void refine(typename Mesh::FaceHandle& _fh);
00165 
00166 
00168   void refine(typename Mesh::VertexHandle& _vh);
00169 
00170 
00172   int subdiv_type() { return subdiv_type_; }
00173 
00174 
00175   // Return subdivision rule.
00176   const Rule& subdiv_rule() const { return *subdiv_rule_; }
00177 
00178 public:
00179 
00181   //*@
00182 
00187   template < typename R >
00188   RuleHandleT<R> add()
00189   {
00190     size_t idx = rule_sequence_.size();
00191     rule_sequence_.push_back( new R( mesh_ ) );
00192     return RuleHandleT<R>( (idx < rule_sequence_.size()) ? idx : -1 );
00193   }
00194 
00199   template < typename R >
00200   RuleHandleT<R>& add( RuleHandleT<R>& _rh )
00201   {
00202     return _rh = add< R >();
00203   }
00204 
00210   template < typename R >
00211   typename RuleHandleT<R>::Rule& rule( const RuleHandleT<R>& _rh )
00212   {
00213     typedef typename RuleHandleT<R>::Rule rule_t;
00214     assert( _rh.is_valid() );
00215     return *dynamic_cast<rule_t*>(rule_sequence_[ _rh.idx() ]);
00216   }
00217 
00218 
00224   RuleInterfaceT<M>& rule( size_t _idx )
00225   {
00226     assert( _idx < n_rules() );
00227     return *rule_sequence_[ _idx ];
00228   }
00229 
00231   size_t n_rules() const { return rule_sequence_.size(); }
00232 
00234   std::string rules_as_string(const std::string& _sep= " * ") const;
00235 
00237 
00238 protected:
00239 
00241   const RuleSequence& rules() const { return rule_sequence_; }
00242 
00243 protected: // helper
00244 
00245   // get current generation from state
00246   state_t generation(state_t _s) { return _s-(_s % n_rules()); }
00247   state_t generation( VH _vh ) { return generation(mesh_.deref(_vh).state()); }
00248   state_t generation( EH _eh ) { return generation(mesh_.deref(_eh).state()); }
00249   state_t generation( FH _fh ) { return generation(mesh_.deref(_fh).state()); }
00250 
00251 private:
00252 
00253   // short cuts
00254   Rule* t_rule() { return subdiv_rule_;           }
00255   Rule* f_rule() { return rule_sequence_.front(); }
00256   Rule* l_rule() { return rule_sequence_.back();  }
00257 
00258 private:
00259 
00260   // 
00261   RuleSequence rule_sequence_;
00262 
00263   // Split type
00264   int   subdiv_type_;
00265 
00266   Rule  *subdiv_rule_;
00267 //   Rule  *first_rule_; 
00268 //   Rule  *last_rule_;
00269 
00270   //
00271   Mesh  &mesh_;
00272 
00273 private: // helper
00274 
00275 #ifndef DOXY_IGNORE_THIS
00276   struct DeleteRule { void operator()( Rule* _r ) { delete _r; } };
00277 #endif
00278 
00279 private:
00280 
00281   CompositeT( const CompositeT& );
00282   CompositeT& operator = ( const CompositeT );
00283 
00284 };
00285 
00286    
00287 //=============================================================================
00288 } // END_NS_ADAPTIVE
00289 } // END_NS_SUBDIVIDER
00290 } // END_NS_OPENMESH
00291 //=============================================================================
00292 #if defined(OM_INCLUDE_TEMPLATES) && !defined(OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_CC)
00293 #  define OPENMESH_SUBDIVIDER_TEMPLATES
00294 #  include "CompositeT.cc"
00295 #endif
00296 //=============================================================================
00297 #endif // OPENMESH_SUBDIVIDER_ADAPTIVE_COMPOSITET_HH defined
00298 //=============================================================================

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .