ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkSample.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 #ifndef __itkSample_h
19 #define __itkSample_h
20 
21 #include "itkPoint.h"
22 #include "itkDataObject.h"
24 #include <vector> // for the size_type declaration
25 
26 namespace itk
27 {
28 namespace Statistics
29 {
60 template< class TMeasurementVector >
61 class ITK_EXPORT Sample:public DataObject
62 {
63 public:
65  typedef Sample Self;
69 
71  itkTypeMacro(Sample, DataObject);
72 
74  typedef TMeasurementVector MeasurementVectorType;
75 
78  typedef typename MeasurementVectorTraitsTypes<
80 
83 
86 
90 
92  typedef unsigned int MeasurementVectorSizeType;
93 
95  virtual InstanceIdentifier Size() const = 0;
96 
99  virtual const MeasurementVectorType &
100  GetMeasurementVector(InstanceIdentifier id) const = 0;
101 
104  virtual AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const = 0;
105 
107  virtual TotalAbsoluteFrequencyType GetTotalFrequency() const = 0;
108 
110  virtual void SetMeasurementVectorSize(MeasurementVectorSizeType s)
111  {
112  // Test whether the vector type is resizable or not
114 
116  {
117  // then this is a resizable vector type
118  //
119  // if the new size is the same as the previou size, just return
120  if ( s == this->m_MeasurementVectorSize )
121  {
122  return;
123  }
124  else
125  {
126  // If the new size is different from the current size, then
127  // only change the measurement vector size if the container is empty.
128  if ( this->Size() )
129  {
130  itkExceptionMacro("Attempting to change the measurement \
131  vector size of a non-empty Sample");
132  }
133  else
134  {
135  this->m_MeasurementVectorSize = s;
136  this->Modified();
137  }
138  }
139  }
140  else
141  {
142  // If this is a non-resizable vector type
144  MeasurementVectorSizeType defaultLength =
146  // and the new length is different from the default one, then throw an
147  // exception
148  if ( defaultLength != s )
149  {
150  itkExceptionMacro(
151  "Attempting to change the measurement \
152  vector size of a non-resizable vector type" );
153  }
154  }
155  }
156 
158  itkGetConstMacro(MeasurementVectorSize, MeasurementVectorSizeType);
159 
161  virtual void Graft(const DataObject *thatObject)
162  {
163  this->Superclass::Graft(thatObject);
164 
165  const Self *thatConst = dynamic_cast< const Self * >( thatObject );
166  if ( thatConst )
167  {
168  this->SetMeasurementVectorSize( thatConst->GetMeasurementVectorSize() );
169  }
170  }
171 
172 protected:
174  {
175  m_MeasurementVectorSize = NumericTraits<MeasurementVectorType>::GetLength(
177  }
178 
179  virtual ~Sample() {}
180 
181  void PrintSelf(std::ostream & os, Indent indent) const
182  {
183  Superclass::PrintSelf(os, indent);
184  os << indent << "Length of measurement vectors in the sample: "
185  << m_MeasurementVectorSize << std::endl;
186  }
187 
188 private:
189  Sample(const Self &); //purposely not implemented
190  void operator=(const Self &); //purposely not implemented
191 
193 }; // end of class
194 } // end of namespace Statistics
195 } // end of namespace itk
196 
197 #endif
198