ITK  5.2.0
Insight Toolkit
itkSample.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 {
61 template <typename TMeasurementVector>
62 class Sample : public DataObject
63 {
64 public:
65  ITK_DISALLOW_COPY_AND_MOVE(Sample);
66 
68  using Self = Sample;
72 
74  itkTypeMacro(Sample, DataObject);
75 
77  using MeasurementVectorType = TMeasurementVector;
78 
82 
85 
88 
92 
94  using MeasurementVectorSizeType = unsigned int;
95 
97  virtual InstanceIdentifier
98  Size() const = 0;
99 
102  virtual const MeasurementVectorType &
104 
107  virtual AbsoluteFrequencyType
108  GetFrequency(InstanceIdentifier id) const = 0;
109 
112  GetTotalFrequency() const = 0;
113 
115  virtual void
117  {
118  // Test whether the vector type is resizable or not
120 
122  {
123  // then this is a resizable vector type
124  //
125  // if the new size is the same as the previou size, just return
126  if (s == this->m_MeasurementVectorSize)
127  {
128  return;
129  }
130  else
131  {
132  // If the new size is different from the current size, then
133  // only change the measurement vector size if the container is empty.
134  if (this->Size())
135  {
136  itkExceptionMacro("Attempting to change the measurement \
137  vector size of a non-empty Sample");
138  }
139  else
140  {
141  this->m_MeasurementVectorSize = s;
142  this->Modified();
143  }
144  }
145  }
146  else
147  {
148  // If this is a non-resizable vector type
151  // and the new length is different from the default one, then throw an
152  // exception
153  if (defaultLength != s)
154  {
155  itkExceptionMacro("Attempting to change the measurement \
156  vector size of a non-resizable vector type");
157  }
158  }
159  }
160 
162  itkGetConstMacro(MeasurementVectorSize, MeasurementVectorSizeType);
163 
165  void
166  Graft(const DataObject * thatObject) override
167  {
168  this->Superclass::Graft(thatObject);
169 
170  const auto * thatConst = dynamic_cast<const Self *>(thatObject);
171  if (thatConst)
172  {
173  this->SetMeasurementVectorSize(thatConst->GetMeasurementVectorSize());
174  }
175  }
176 
177 protected:
179 
180  ~Sample() override = default;
181 
182  void
183  PrintSelf(std::ostream & os, Indent indent) const override
184  {
185  Superclass::PrintSelf(os, indent);
186  os << indent << "Length of measurement vectors in the sample: " << m_MeasurementVectorSize << std::endl;
187  }
188 
189 private:
191 }; // end of class
192 } // end of namespace Statistics
193 } // end of namespace itk
194 
195 #endif
itk::DataObject::DataObject
DataObject()
itk::Statistics::MeasurementVectorTraits::InstanceIdentifier
IdentifierType InstanceIdentifier
Definition: itkMeasurementVectorTraits.h:50
itk::Statistics::Sample::GetFrequency
virtual AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const =0
itk::Statistics::Sample::MeasurementVectorType
TMeasurementVector MeasurementVectorType
Definition: itkSample.h:77
itk::Statistics::Sample::Graft
void Graft(const DataObject *thatObject) override
Definition: itkSample.h:166
itkPoint.h
itk::Statistics::Sample::Size
virtual InstanceIdentifier Size() const =0
itk::DataObject::Graft
virtual void Graft(const DataObject *)
Definition: itkDataObject.h:545
itk::NumericTraits::AccumulateType
double AccumulateType
Definition: itkNumericTraits.h:74
itk::Statistics::Sample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::TotalAbsoluteFrequencyType
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition: itkSample.h:87
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Statistics::Sample::GetTotalFrequency
virtual TotalAbsoluteFrequencyType GetTotalFrequency() const =0
itk::Statistics::Sample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::InstanceIdentifier
typename MeasurementVectorTraits::InstanceIdentifier InstanceIdentifier
Definition: itkSample.h:91
itkDataObject.h
itk::Statistics::Sample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::MeasurementType
typename MeasurementVectorTraitsTypes< MeasurementVectorType >::ValueType MeasurementType
Definition: itkSample.h:81
itk::Statistics::Sample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::MeasurementVectorSizeType
unsigned int MeasurementVectorSizeType
Definition: itkSample.h:94
itk::Statistics::MeasurementVectorTraits::AbsoluteFrequencyType
InstanceIdentifier AbsoluteFrequencyType
Definition: itkMeasurementVectorTraits.h:53
itk::Statistics::Sample::SetMeasurementVectorSize
virtual void SetMeasurementVectorSize(MeasurementVectorSizeType s)
Definition: itkSample.h:116
itk::Statistics::Sample::~Sample
~Sample() override=default
itk::DataObject::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
itk::Statistics::Sample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::AbsoluteFrequencyType
MeasurementVectorTraits::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkSample.h:84
itk::Statistics::Sample::m_MeasurementVectorSize
MeasurementVectorSizeType m_MeasurementVectorSize
Definition: itkSample.h:190
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:52
itk::Statistics::Sample::Sample
Sample()
Definition: itkSample.h:178
itkMeasurementVectorTraits.h
itk::Statistics::MeasurementVectorTraits::IsResizable
static bool IsResizable(const TVectorType &)
Definition: itkMeasurementVectorTraits.h:62
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::NumericTraits::GetLength
static unsigned int GetLength()
Definition: itkNumericTraits.h:208
itk::Statistics::MeasurementVectorTraitsTypes::ValueType
typename TMeasurementVector::ValueType ValueType
Definition: itkMeasurementVectorTraits.h:423
itk::Statistics::Sample
A collection of measurements for statistical analysis.
Definition: itkSample.h:62
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::Statistics::Sample::GetMeasurementVector
virtual const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const =0
itk::Statistics::Sample::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkSample.h:183
itk::Object::Modified
virtual void Modified() const
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293