ITK  6.0.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  }
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  else
143  {
144  // If this is a non-resizable vector type
146  // and the new length is different from the default one, then throw an
147  // exception
148  if (defaultLength != s)
149  {
150  itkExceptionMacro("Attempting to change the measurement vector size of a non-resizable vector type");
151  }
152  }
153  }
154 
156  itkGetConstMacro(MeasurementVectorSize, MeasurementVectorSizeType);
157 
159  void
160  Graft(const DataObject * thatObject) override
161  {
162  this->Superclass::Graft(thatObject);
163 
164  const auto * thatConst = dynamic_cast<const Self *>(thatObject);
165  if (thatConst)
166  {
167  this->SetMeasurementVectorSize(thatConst->GetMeasurementVectorSize());
168  }
169  }
170 
171 protected:
173 
174  ~Sample() override = default;
175 
176  void
177  PrintSelf(std::ostream & os, Indent indent) const override
178  {
179  Superclass::PrintSelf(os, indent);
180  os << indent << "Length of measurement vectors in the sample: " << m_MeasurementVectorSize << std::endl;
181  }
182 
183 private:
185 }; // end of class
186 } // end of namespace Statistics
187 } // end of namespace itk
188 
189 #endif
itk::DataObject::DataObject
DataObject()
itk::Statistics::MeasurementVectorTraits::InstanceIdentifier
IdentifierType InstanceIdentifier
Definition: itkMeasurementVectorTraits.h:49
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:160
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:76
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:52
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:184
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:53
itk::Statistics::Sample::Sample
Sample()
Definition: itkSample.h:172
itkMeasurementVectorTraits.h
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::NumericTraits::GetLength
static unsigned int GetLength()
Definition: itkNumericTraits.h:210
itk::Statistics::MeasurementVectorTraitsTypes::ValueType
typename TMeasurementVector::ValueType ValueType
Definition: itkMeasurementVectorTraits.h:414
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:177
itk::Object::Modified
virtual void Modified() const
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293