Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkFEMPArray.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkFEMPArray.h,v $
00005   Language:  C++
00006   Date:      $Date: 2003/08/06 17:15:47 $
00007   Version:   $Revision: 1.10.8.1 $
00008 
00009   Copyright (c) 2002 Insight Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 
00018 #ifndef __itkFEMPArray_h
00019 #define __itkFEMPArray_h
00020 
00021 #include "itkFEMP.h"
00022 #include "itkFEMException.h"
00023 #include <vector>
00024 
00025 namespace itk {
00026 namespace fem {
00027 
00028 
00029 
00030 
00039 template<class T>
00040 class FEMPArray : public std::vector<FEMP<T> >
00041 {
00042 public:
00046   typedef FEMPArray Self;
00047 
00051   typedef std::vector<FEMP<T> > Superclass;
00052 
00056   typedef Self* Pointer;
00057   typedef const Self* ConstPointer;
00058 
00062   typedef T ClassType;
00063   typedef typename ClassType::Pointer ClassTypePointer;
00064   typedef typename ClassType::ConstPointer ClassTypeConstPointer;
00065 
00069   ClassTypePointer Find(int gn);
00070   ClassTypeConstPointer Find(int gn) const;
00071 
00075   ClassTypePointer operator() (int i) 
00076   {
00077     return &(*operator[](i));
00078   }
00079 
00084   ClassTypeConstPointer operator() (int i) const 
00085   {  
00086     return &(*operator[](i));
00087   }
00088 
00089 
00095   int Renumber();
00096 
00097 };
00098 
00099 
00100 
00104 template<class T>
00105 typename FEMPArray<T>::ClassTypePointer 
00106 FEMPArray<T>::Find(int gn)
00107 {
00108 
00110   if( gn < 0 || gn >= (int)this->size() )
00111     {
00112     throw FEMExceptionObjectNotFound(__FILE__,__LINE__,"FEMPArray::Find() const",typeid(T).name(),gn);
00113     }
00114       
00119   typedef typename Superclass::value_type     ValueType;
00120   const ValueType & value = this->operator[](gn);
00121 
00122   if( value->GN == gn )
00123     {
00124     return &(*(value));
00125     }
00126       
00130   typedef typename Superclass::iterator Iterator;
00131   Iterator it   = this->begin(); 
00132   Iterator iend = this->end();
00133   while( it != iend )
00134     {
00135     if( (*it)->GN == gn )
00136       {
00137       break;
00138       }
00139     it++;
00140     }  
00141 
00142   if( it == this->end() )
00143     {
00147     throw FEMExceptionObjectNotFound(__FILE__,__LINE__,"FEMPArray::Find() const",typeid(T).name(),gn);
00148     }
00149 
00153   return &(*(*it));
00154 
00155 }
00156 
00157 
00158 
00159 
00163 template<class T>
00164 typename FEMPArray<T>::ClassTypeConstPointer 
00165 FEMPArray<T>::Find( int gn ) const
00166 {
00167 
00169   if( gn < 0 || gn >= (int)this->size() )
00170     {
00171     throw FEMExceptionObjectNotFound(__FILE__,__LINE__,"FEMPArray::Find() const",typeid(T).name(),gn);
00172     }
00173       
00178   typedef typename Superclass::value_type     ValueType;
00179   const ValueType & value = this->operator[](gn);
00180 
00181   if( value->GN == gn )
00182     {
00183     return &(*(value));
00184     }
00185       
00189   typedef typename Superclass::const_iterator ConstIterator;
00190   ConstIterator it   = this->begin(); 
00191   ConstIterator iend = this->end();
00192   while( it != iend )
00193     {
00194     if( (*it)->GN == gn )
00195       {
00196       break;
00197       }
00198     it++;
00199     }  
00200 
00201   if( it == this->end() )
00202     {
00206     throw FEMExceptionObjectNotFound(__FILE__,__LINE__,"FEMPArray::Find() const",typeid(T).name(),gn);
00207     }
00208 
00212   return &(*(*it));
00213 
00214 }
00215 
00216 
00217 
00218 
00219 template<class T>
00220 int FEMPArray<T>::Renumber() 
00221 {
00222 
00223   typename Superclass::iterator i;
00224   int j=0;
00225 
00226   for(i=begin(); i!=end(); i++)
00227   {
00228     (*i)->GN=j;
00229     j++;
00230   }
00231 
00232   return j;
00233 
00234 }
00235 
00236 
00237 
00238 
00239 }} // end namespace itk::fem
00240 
00241 #endif // #ifndef __itkFEMPArray_h

Generated at Fri May 21 01:14:46 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000