vtf-logo

ComplexWithFreeVertex.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00008 #if !defined(__geom_ComplexWithFreeVertex_h__)
00009 #define __geom_ComplexWithFreeVertex_h__
00010 
00011 #if defined(DEBUG_geom) && !defined(DEBUG_ComplexWithFreeVertex)
00012 #define DEBUG_ComplexWithFreeVertex
00013 #endif
00014 
00015 #include "SimplexWithFreeVertex.h"
00016 #include "SimplexModDet.h"
00017 
00018 #include <vector>
00019 #include <iostream>
00020 
00021 #include <cassert>
00022 
00023 BEGIN_NAMESPACE_GEOM
00024 
00025 
00027 
00054 template<template<int,typename> class QF,
00055          int N,
00056          typename T = double>
00057 class ComplexWithFreeVertex {
00058 private:
00059 
00060   //
00061   // Private types.
00062   //
00063 
00064   typedef SimplexWithFreeVertex<QF,N,T> SWFV;
00065   typedef std::vector<SWFV> SimplexContainer;
00066   typedef typename SimplexContainer::iterator SimplexIterator;
00067   typedef typename SimplexContainer::const_iterator SimplexConstIterator;
00068 
00069 public:
00070 
00071   //
00072   // Public types.
00073   //
00074 
00076   typedef T Number;
00077 
00079   typedef typename SWFV::Vertex Vertex;
00080 
00082   typedef typename SWFV::Face Face;
00083 
00084 private:
00085 
00086   //
00087   // Data
00088   //
00089 
00090   SimplexContainer _simplices;
00091 
00092   //
00093   // Not implemented.
00094   //
00095 
00096   // Copy constructor not implemented.
00097   ComplexWithFreeVertex(const ComplexWithFreeVertex&);
00098 
00099   // Assignment operator not implemented.
00100   ComplexWithFreeVertex& 
00101   operator=(const ComplexWithFreeVertex&);
00102   
00103 public:
00104 
00105   //--------------------------------------------------------------------------
00108 
00110   ComplexWithFreeVertex()
00111   {}
00112 
00114   template<typename FaceIterator>
00115   ComplexWithFreeVertex(FaceIterator beginning, FaceIterator end) {
00116     set(beginning, end);
00117   }
00118 
00120   ~ComplexWithFreeVertex()
00121   {}
00122 
00124   //--------------------------------------------------------------------------
00127 
00129   Vertex
00130   getFreeVertex() const {
00131     assert(! _simplices.empty());
00132     return _simplices[0].getFreeVertex();
00133   }
00134 
00136   //--------------------------------------------------------------------------
00139 
00141   template<typename FaceIterator>
00142   void
00143   set(FaceIterator begin, FaceIterator end);
00144 
00146   //--------------------------------------------------------------------------
00149 
00151   void
00152   computeBBox(const Vertex& v, BBox<N,T>* bb) {
00153     set(v);
00154     computeBBox(bb);
00155   }
00156 
00158   Number
00159   computeContent(const Vertex& v);
00160 
00162   void
00163   computeGradientOfContent(const Vertex& v, Vertex* gradient);
00164 
00166   Number
00167   computeNorm2(const Vertex& v);
00168 
00170   void
00171   computeGradientOfNorm2(const Vertex& v, Vertex* gradient);
00172 
00174   Number
00175   computeNorm2Modified(const Vertex& v);
00176 
00178   void
00179   computeGradientOfNorm2Modified(const Vertex& v, Vertex* gradient);
00180 
00182 
00183 protected:
00184 
00186 
00189   void
00190   set(const Vertex& v);
00191 
00192 private:
00193 
00194   // Return the minimum Jacobian determinant.
00195   Number
00196   computeMinDeterminant() const;
00197 
00198   // Calculate the bounding box for the complex.
00199   void
00200   computeBBox(BBox<N,T>* bb) const;
00201 
00202   // Return the content.
00203   // The free vertex must be set before calling this function.
00204   Number
00205   computeContent() const;
00206 
00207   // Calculate the gradient of the content.
00208   // The free vertex must be set before calling this function.
00209   void
00210   computeGradientOfContent(Vertex* gradient) const;
00211 
00212   // Return the 2-norm of the quality metric.
00213   // The free vertex must be set before calling this function.
00214   Number
00215   computeNorm2() const;
00216 
00217   // Calculate the gradient of the 2-norm of the quality metric.
00218   // The free vertex must be set before calling this function.
00219   void
00220   computeGradientOfNorm2(Vertex* gradient) const;
00221 
00222   // Return the 2-norm of the modified quality metric.
00223   // The free vertex must be set before calling this function.
00224   Number
00225   computeNorm2Modified(Number minDetermintant) const;
00226 
00227   // Calculate the gradient of the 2-norm of the modified quality metric.
00228   // The free vertex must be set before calling this function.
00229   void
00230   computeGradientOfNorm2Modified(Number minDetermintant, Vertex* gradient) 
00231     const;
00232 };
00233 
00234 
00236 
00240 template<class Complex>
00241 class ComplexContentConstraint :
00242   public std::unary_function<typename Complex::Vertex, 
00243                              typename Complex::Number>
00244 {
00245 private:
00246 
00247   typedef std::unary_function<typename Complex::Vertex, 
00248                               typename Complex::Number> base_type;
00249 
00250 public:
00251 
00253   typedef typename base_type::argument_type argument_type;
00255   typedef typename base_type::result_type result_type;
00256 
00257 private:
00258 
00259   mutable Complex& _sc;
00260 
00261   // The content of the complex for the initial position of the free vertex.
00262   result_type _initialContent;
00263 
00264   // Default constructor not implemented.
00265   ComplexContentConstraint();
00266 
00267   // Assignment operator not implemented.
00268   ComplexContentConstraint&
00269   operator=(const ComplexContentConstraint&);
00270 
00271 public:
00272 
00274   ComplexContentConstraint(Complex& sc) :
00275     _sc(sc)
00276   {}
00277 
00279   ComplexContentConstraint(const ComplexContentConstraint& other) :
00280     _sc(other._sc)
00281   {}
00282 
00284   void
00285   initialize(const argument_type& x) {
00286     _initialContent = _sc.computeContent(x);
00287   }
00288 
00290   result_type
00291   operator()(const argument_type& x) const {
00292 #ifdef DEBUG_ComplexWithFreeVertex
00293     assert(_initialContent != 0);
00294 #endif
00295     return (_sc.computeContent(x) - _initialContent) / _initialContent;
00296   }
00297 
00299   void
00300   gradient(const argument_type& x, argument_type& grad) const {
00301 #ifdef DEBUG_ComplexWithFreeVertex
00302     assert(_initialContent != 0);
00303 #endif
00304     _sc.computeGradientOfContent(x, &grad);
00305     grad /= _initialContent;
00306   }
00307 };
00308 
00309 
00311 template<class Complex>
00312 class ComplexNorm2 :
00313   public std::unary_function<typename Complex::Vertex, 
00314                              typename Complex::Number>
00315 {
00316 private:
00317 
00318   typedef std::unary_function<typename Complex::Vertex, 
00319                               typename Complex::Number> Base;
00320 
00321 public:
00322 
00324   typedef typename Base::argument_type argument_type;
00326   typedef typename Base::result_type result_type;
00327 
00328 private:
00329 
00330   mutable Complex& _sc;
00331 
00332   // Default constructor not implemented.
00333   ComplexNorm2();
00334 
00335   // Assignment operator not implemented.
00336   ComplexNorm2&
00337   operator=(const ComplexNorm2&);
00338 
00339 public:
00340 
00342   ComplexNorm2(Complex& sc) :
00343     _sc(sc)
00344   {}
00345 
00347   ComplexNorm2(const ComplexNorm2& other) :
00348     _sc(other._sc)
00349   {}
00350 
00352   result_type
00353   operator()(const argument_type& x) const {
00354     return _sc.computeNorm2(x);
00355   }
00356 
00358   void
00359   gradient(const argument_type& x, argument_type& grad) const {
00360     _sc.computeGradientOfNorm2(x, &grad);
00361   }
00362 };
00363 
00364 
00365 
00367 template<class Complex>
00368 class ComplexNorm2Mod :
00369   public std::unary_function<typename Complex::Vertex, 
00370                              typename Complex::Number>
00371 {
00372 private:
00373 
00374   typedef std::unary_function<typename Complex::Vertex, 
00375                               typename Complex::Number> Base;
00376 
00377 public:
00378 
00380   typedef typename Base::argument_type argument_type;
00382   typedef typename Base::result_type result_type;
00383 
00384 private:
00385 
00386   mutable Complex& _sc;
00387 
00388   // Default constructor not implemented.
00389   ComplexNorm2Mod();
00390 
00391   // Assignment operator not implemented.
00392   ComplexNorm2Mod&
00393   operator=(const ComplexNorm2Mod&);
00394 
00395 public:
00396 
00398   ComplexNorm2Mod(Complex& sc) :
00399     _sc(sc)
00400   {}
00401 
00403   ComplexNorm2Mod(const ComplexNorm2Mod& x) :
00404     _sc(x._sc)
00405   {}
00406 
00408   result_type
00409   operator()(const argument_type& x) const {
00410     return _sc.computeNorm2Modified(x);
00411   }
00412 
00414   void
00415   gradient(const argument_type& x, argument_type& grad) const {
00416     _sc.computeGradientOfNorm2Modified(x, &grad);
00417   }
00418 };
00419 
00420 
00421 END_NAMESPACE_GEOM
00422 
00423 #define __geom_ComplexWithFreeVertex_ipp__
00424 #include "ComplexWithFreeVertex.ipp"
00425 #undef __geom_ComplexWithFreeVertex_ipp__
00426 
00427 #endif

Generated on Fri Aug 24 12:55:51 2007 for Computational Geometry Package by  doxygen 1.4.7