ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkFEMPArray.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #ifndef __itkFEMPArray_h
20 #define __itkFEMPArray_h
21 
22 #include "itkFEMP.h"
23 #include "itkFEMException.h"
24 #include <vector>
25 
26 namespace itk
27 {
28 namespace fem
29 {
39 template <class T>
40 class FEMPArray : public std::vector<FEMP<T> >
41 {
42 public:
43 
47  typedef FEMPArray Self;
48 
52  typedef std::vector<FEMP<T> > Superclass;
53 
57  typedef Self * Pointer;
58  typedef const Self *ConstPointer;
59 
63  typedef T ClassType;
64  typedef typename ClassType::Pointer ClassTypePointer;
65  typedef typename ClassType::ConstPointer ClassTypeConstPointer;
66 
70  ClassTypePointer Find(int gn);
71 
72  ClassTypeConstPointer Find(int gn) const;
73 
78  {
79  return &( *this->operator[](i) );
80  }
81 
87  {
88  return &( *this->operator[](i) );
89  }
90 
96  int Renumber();
97 
98 };
99 
103 template <class T>
104 typename FEMPArray<T>::ClassTypePointer
106 {
107  typedef typename Superclass::iterator Iterator;
108 
109  Iterator it = this->begin();
110  Iterator iend = this->end();
111  while( it != iend )
112  {
113  if( ( *it )->GetGlobalNumber() == gn )
114  {
115  break;
116  }
117  it++;
118  }
119 
120  if( it == this->end() )
121  {
125  throw FEMExceptionObjectNotFound(__FILE__, __LINE__, "FEMPArray::Find() const", typeid( T ).name(), gn);
126  }
127 
131  return &( *( *it ) );
132 }
133 
137 template <class T>
139 FEMPArray<T>::Find(int gn) const
140 {
141  typedef typename Superclass::const_iterator ConstIterator;
142 
143  ConstIterator it = this->begin();
144  ConstIterator iend = this->end();
145  while( it != iend )
146  {
147  if( ( *it )->GetGlobalNumber() == gn )
148  {
149  break;
150  }
151  it++;
152  }
153 
154  if( it == this->end() )
155  {
159  throw FEMExceptionObjectNotFound(__FILE__, __LINE__, "FEMPArray::Find() const", typeid( T ).name(), gn);
160  }
161 
165  return &( *( *it ) );
166 }
167 
168 template <class T>
170 {
171  typename Superclass::iterator i;
172  int j = 0;
173  for( i = this->begin(); i != this->end(); i++ )
174  {
175  ( *i )->SetGlobalNumber(j);
176  j++;
177  }
178 
179  return j;
180 }
181 
182 }
183 } // end namespace itk::fem
184 
185 #endif // #ifndef __itkFEMPArray_h
186