h o m e d o c u m e n t a t i o n c l a s s h i e r a r c h y

Interface1D.h

Go to the documentation of this file.
00001 //
00002 //  Filename         : Interface1D.h
00003 //  Author(s)        : Emmanuel Turquin
00004 //  Purpose          : Interface to 1D elts
00005 //  Date of creation : 01/07/2003
00006 //
00008 
00009 
00010 //
00011 //  Copyright (C) : Please refer to the COPYRIGHT file distributed 
00012 //   with this source distribution. 
00013 //
00014 //  This program is free software; you can redistribute it and/or
00015 //  modify it under the terms of the GNU General Public License
00016 //  as published by the Free Software Foundation; either version 2
00017 //  of the License, or (at your option) any later version.
00018 //
00019 //  This program is distributed in the hope that it will be useful,
00020 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022 //  GNU General Public License for more details.
00023 //
00024 //  You should have received a copy of the GNU General Public License
00025 //  along with this program; if not, write to the Free Software
00026 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00027 //
00029 
00030 #ifndef  INTERFACE1D_H
00031 # define INTERFACE1D_H
00032 
00033 # include <string>
00034 # include <iostream>
00035 # include <float.h>
00036 # include "../system/Id.h"
00037 # include "../system/Precision.h"
00038 # include "../winged_edge/Nature.h"
00039 # include "Functions0D.h"
00040 
00041 using namespace std;
00045 // Integration method
00051 typedef enum {
00052   MEAN,
00053   MIN,
00054   MAX,
00055   FIRST,
00056   LAST
00057 } IntegrationType;
00058 
00076 template <class T>
00077 T integrate(UnaryFunction0D<T>& fun,
00078             Interface0DIterator it,
00079             Interface0DIterator it_end,
00080             IntegrationType integration_type = MEAN) {
00081   T res;
00082   T res_tmp;
00083   unsigned size;
00084   switch (integration_type) {
00085   case MIN:
00086     res = fun(it);++it;
00087     for (; !it.isEnd(); ++it) {
00088       res_tmp = fun(it);
00089       if (res_tmp < res)
00090         res = res_tmp;
00091     }
00092     break;
00093   case MAX:
00094     res = fun(it);++it;
00095     for (; !it.isEnd(); ++it) {
00096       res_tmp = fun(it);
00097       if (res_tmp > res)
00098         res = res_tmp;
00099     }
00100     break;
00101   case FIRST:
00102     res = fun(it);
00103     break;
00104   case LAST:
00105     res = fun(--it_end);
00106     break;
00107   case MEAN:
00108   default:
00109     res = fun(it);++it;
00110     for (size = 1; !it.isEnd(); ++it, ++size)
00111       res += fun(it);
00112     res /= (size ? size : 1);
00113     break;
00114   }
00115   return res;
00116 }
00117 
00118 //
00119 // Interface1D
00120 //
00122 
00124 class Interface1D
00125 {
00126 public:
00127 
00129   Interface1D() {_timeStamp=0;}
00130 
00132   virtual string getExactTypeName() const {
00133     return "Interface1D";
00134   }
00135 
00136   // Iterator access
00137 
00141   virtual Interface0DIterator verticesBegin() = 0;
00145   virtual Interface0DIterator verticesEnd() = 0;
00155   virtual Interface0DIterator pointsBegin(float t=0.f) = 0;
00165   virtual Interface0DIterator pointsEnd(float t=0.f) = 0;
00166 
00167   // Data access methods
00168 
00170   virtual real getLength2D() const {
00171     cerr << "Warning: method getLength2D() not implemented" << endl;
00172     return 0;
00173   }
00174 
00176   virtual Id getId() const {
00177     cerr << "Warning: method getId() not implemented" << endl;
00178     return Id(0, 0);
00179   }
00180 
00181   // FIXME: ce truc n'a rien a faire la...(c une requete complexe qui doit etre ds les Function1D)
00183   virtual Nature::EdgeNature getNature() const {
00184     cerr << "Warning: method getNature() not implemented" << endl;
00185     return Nature::NO_FEATURE;
00186   }
00187   
00189   virtual unsigned getTimeStamp() const {
00190     return _timeStamp;
00191   }
00192   
00194   inline void setTimeStamp(unsigned iTimeStamp){
00195     _timeStamp = iTimeStamp;
00196   }
00197 
00198 protected:
00199   unsigned _timeStamp;
00200 };
00201 
00202 #endif // INTERFACE1D_H