ITK  4.8.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< typename TMeasurementVector >
61 class 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 &
101 
105 
107  virtual TotalAbsoluteFrequencyType GetTotalFrequency() const = 0;
108 
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) ITK_OVERRIDE
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  {
177  }
178 
179  virtual ~Sample() {}
180 
181  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE
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
virtual void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkSample.h:181
virtual InstanceIdentifier Size() const =0
MeasurementVectorTraits::InstanceIdentifier InstanceIdentifier
Definition: itkSample.h:89
virtual const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const =0
virtual AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const =0
virtual void Graft(const DataObject *)
SmartPointer< const Self > ConstPointer
Definition: itkSample.h:68
virtual void Graft(const DataObject *thatObject) override
Definition: itkSample.h:161
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
void operator=(const Self &)
DataObject Superclass
Definition: itkSample.h:66
virtual void SetMeasurementVectorSize(MeasurementVectorSizeType s)
Definition: itkSample.h:110
static bool IsResizable(const TVectorType &)
SmartPointer< Self > Pointer
Definition: itkSample.h:67
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition: itkSample.h:85
MeasurementVectorTraitsTypes< MeasurementVectorType >::ValueType MeasurementType
Definition: itkSample.h:79
static unsigned int GetLength()
virtual void Modified() const
TMeasurementVector MeasurementVectorType
Definition: itkSample.h:71
unsigned int MeasurementVectorSizeType
Definition: itkSample.h:92
A collection of measurements for statistical analysis.
Definition: itkSample.h:61
Control indentation during Print() invocation.
Definition: itkIndent.h:49
MeasurementVectorTraits::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkSample.h:82
MeasurementVectorSizeType m_MeasurementVectorSize
Definition: itkSample.h:192
Base class for all data objects in ITK.
virtual void PrintSelf(std::ostream &os, Indent indent) const override
virtual TotalAbsoluteFrequencyType GetTotalFrequency() const =0