ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkFEMPArray.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 
00019 #ifndef __itkFEMPArray_h
00020 #define __itkFEMPArray_h
00021 
00022 #include "itkFEMP.h"
00023 #include "itkFEMException.h"
00024 #include <vector>
00025 
00026 namespace itk
00027 {
00028 namespace fem
00029 {
00039 template <class T>
00040 class FEMPArray : public std::vector<FEMP<T> >
00041 {
00042 public:
00043 
00047   typedef FEMPArray Self;
00048 
00052   typedef std::vector<FEMP<T> > Superclass;
00053 
00057   typedef Self *     Pointer;
00058   typedef const Self *ConstPointer;
00059 
00063   typedef T                                ClassType;
00064   typedef typename ClassType::Pointer      ClassTypePointer;
00065   typedef typename ClassType::ConstPointer ClassTypeConstPointer;
00066 
00070   ClassTypePointer Find(int gn);
00071 
00072   ClassTypeConstPointer Find(int gn) const;
00073 
00077   ClassTypePointer operator()(int i)
00078   {
00079     return &( *this->operator[](i) );
00080   }
00081 
00086   ClassTypeConstPointer operator()(int i) const
00087   {
00088     return &( *this->operator[](i) );
00089   }
00090 
00096   int Renumber();
00097 
00098 };
00099 
00103 template <class T>
00104 typename FEMPArray<T>::ClassTypePointer
00105 FEMPArray<T>::Find(int gn)
00106 {
00107   typedef typename Superclass::iterator Iterator;
00108 
00109   Iterator it   = this->begin();
00110   Iterator iend = this->end();
00111   while( it != iend )
00112     {
00113     if( ( *it )->GetGlobalNumber() == gn )
00114       {
00115       break;
00116       }
00117     it++;
00118     }
00119 
00120   if( it == this->end() )
00121     {
00125     throw FEMExceptionObjectNotFound(__FILE__, __LINE__, "FEMPArray::Find() const", typeid( T ).name(), gn);
00126     }
00127 
00131   return &( *( *it ) );
00132 }
00133 
00137 template <class T>
00138 typename FEMPArray<T>::ClassTypeConstPointer
00139 FEMPArray<T>::Find(int gn) const
00140 {
00141   typedef typename Superclass::const_iterator ConstIterator;
00142 
00143   ConstIterator it   = this->begin();
00144   ConstIterator iend = this->end();
00145   while( it != iend )
00146     {
00147     if( ( *it )->GetGlobalNumber() == gn )
00148       {
00149       break;
00150       }
00151     it++;
00152     }
00153 
00154   if( it == this->end() )
00155     {
00159     throw FEMExceptionObjectNotFound(__FILE__, __LINE__, "FEMPArray::Find() const", typeid( T ).name(), gn);
00160     }
00161 
00165   return &( *( *it ) );
00166 }
00167 
00168 template <class T>
00169 int FEMPArray<T>::Renumber()
00170 {
00171   typename Superclass::iterator i;
00172   int j = 0;
00173   for( i = this->begin(); i != this->end(); i++ )
00174     {
00175     ( *i )->SetGlobalNumber(j);
00176     j++;
00177     }
00178 
00179   return j;
00180 }
00181 
00182 }
00183 }  // end namespace itk::fem
00184 
00185 #endif // #ifndef __itkFEMPArray_h
00186