ITK  5.4.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  * https://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  itkOverrideGetNameOfClassMacro(Sample);
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
119  if (MeasurementVectorTraits::IsResizable<MeasurementVectorType>({}))
120  {
121  // then this is a resizable vector type
122  //
123  // if the new size is the same as the previous size, just return
124  if (s == this->m_MeasurementVectorSize)
125  {
126  return;
127  }
128  else
129  {
130  // If the new size is different from the current size, then
131  // only change the measurement vector size if the container is empty.
132  if (this->Size())
133  {
134  itkExceptionMacro("Attempting to change the measurement vector size of a non-empty Sample");
135  }
136  else
137  {
138  this->m_MeasurementVectorSize = s;
139  this->Modified();
140  }
141  }
142  }
143  else
144  {
145  // If this is a non-resizable vector type
147  // and the new length is different from the default one, then throw an
148  // exception
149  if (defaultLength != s)
150  {
151  itkExceptionMacro("Attempting to change the measurement vector size of a non-resizable vector type");
152  }
153  }
154  }
158  itkGetConstMacro(MeasurementVectorSize, MeasurementVectorSizeType);
159 
161  void
162  Graft(const DataObject * thatObject) override
163  {
164  this->Superclass::Graft(thatObject);
165 
166  const auto * thatConst = dynamic_cast<const Self *>(thatObject);
167  if (thatConst)
168  {
169  this->SetMeasurementVectorSize(thatConst->GetMeasurementVectorSize());
170  }
171  }
172 
173 protected:
175 
176  ~Sample() override = default;
177 
178  void
179  PrintSelf(std::ostream & os, Indent indent) const override
180  {
181  Superclass::PrintSelf(os, indent);
182  os << indent << "Length of measurement vectors in the sample: " << m_MeasurementVectorSize << std::endl;
183  }
184 
185 private:
187 }; // end of class
188 } // end of namespace Statistics
189 } // end of namespace itk
190 
191 #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:162
itkPoint.h
itk::Statistics::Sample::Size
virtual InstanceIdentifier Size() const =0
itk::DataObject::Graft
virtual void Graft(const DataObject *)
Definition: itkDataObject.h:549
itk::NumericTraits::AccumulateType
double AccumulateType
Definition: itkNumericTraits.h:75
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:186
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:53
itk::Statistics::Sample::Sample
Sample()
Definition: itkSample.h:174
itkMeasurementVectorTraits.h
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:209
itk::Statistics::MeasurementVectorTraitsTypes::ValueType
typename TMeasurementVector::ValueType ValueType
Definition: itkMeasurementVectorTraits.h:422
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:61
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:179
itk::Object::Modified
virtual void Modified() const
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293