ITK  5.1.0
Insight 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:
64  ITK_DISALLOW_COPY_AND_ASSIGN(Sample);
65 
67  using Self = Sample;
71 
73  itkTypeMacro(Sample, DataObject);
74 
76  using MeasurementVectorType = TMeasurementVector;
77 
81 
84 
87 
91 
93  using MeasurementVectorSizeType = unsigned int;
94 
96  virtual InstanceIdentifier
97  Size() const = 0;
98 
101  virtual const MeasurementVectorType &
103 
106  virtual AbsoluteFrequencyType
107  GetFrequency(InstanceIdentifier id) const = 0;
108 
111  GetTotalFrequency() const = 0;
112 
114  virtual void
116  {
117  // Test whether the vector type is resizable or not
119 
121  {
122  // then this is a resizable vector type
123  //
124  // if the new size is the same as the previou size, just return
125  if (s == this->m_MeasurementVectorSize)
126  {
127  return;
128  }
129  else
130  {
131  // If the new size is different from the current size, then
132  // only change the measurement vector size if the container is empty.
133  if (this->Size())
134  {
135  itkExceptionMacro("Attempting to change the measurement \
136  vector size of a non-empty Sample");
137  }
138  else
139  {
140  this->m_MeasurementVectorSize = s;
141  this->Modified();
142  }
143  }
144  }
145  else
146  {
147  // If this is a non-resizable vector type
150  // and the new length is different from the default one, then throw an
151  // exception
152  if (defaultLength != s)
153  {
154  itkExceptionMacro("Attempting to change the measurement \
155  vector size of a non-resizable vector type");
156  }
157  }
158  }
159 
161  itkGetConstMacro(MeasurementVectorSize, MeasurementVectorSizeType);
162 
164  void
165  Graft(const DataObject * thatObject) override
166  {
167  this->Superclass::Graft(thatObject);
168 
169  const auto * thatConst = dynamic_cast<const Self *>(thatObject);
170  if (thatConst)
171  {
172  this->SetMeasurementVectorSize(thatConst->GetMeasurementVectorSize());
173  }
174  }
175 
176 protected:
178 
179  ~Sample() override = default;
180 
181  void
182  PrintSelf(std::ostream & os, Indent indent) const override
183  {
184  Superclass::PrintSelf(os, indent);
185  os << indent << "Length of measurement vectors in the sample: " << m_MeasurementVectorSize << std::endl;
186  }
187 
188 private:
190 }; // end of class
191 } // end of namespace Statistics
192 } // end of namespace itk
193 
194 #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:76
itk::Statistics::Sample::Graft
void Graft(const DataObject *thatObject) override
Definition: itkSample.h:165
itkPoint.h
itk::Statistics::Sample::Size
virtual InstanceIdentifier Size() const =0
itk::DataObject::Graft
virtual void Graft(const DataObject *)
Definition: itkDataObject.h:540
itk::NumericTraits::AccumulateType
double AccumulateType
Definition: itkNumericTraits.h:74
itk::Statistics::Sample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::TotalAbsoluteFrequencyType
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition: itkSample.h:86
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:90
itkDataObject.h
itk::Statistics::Sample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::MeasurementType
typename MeasurementVectorTraitsTypes< MeasurementVectorType >::ValueType MeasurementType
Definition: itkSample.h:80
itk::Statistics::Sample< ImageJointDomainTraits< TImage >::MeasurementVectorType >::MeasurementVectorSizeType
unsigned int MeasurementVectorSizeType
Definition: itkSample.h:93
itk::Statistics::MeasurementVectorTraits::AbsoluteFrequencyType
InstanceIdentifier AbsoluteFrequencyType
Definition: itkMeasurementVectorTraits.h:53
itk::Statistics::Sample::SetMeasurementVectorSize
virtual void SetMeasurementVectorSize(MeasurementVectorSizeType s)
Definition: itkSample.h:115
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:83
itk::Statistics::Sample::m_MeasurementVectorSize
MeasurementVectorSizeType m_MeasurementVectorSize
Definition: itkSample.h:189
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:52
itk::Statistics::Sample::Sample
Sample()
Definition: itkSample.h:177
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: itkArray.h:26
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:61
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:60
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:182
itk::Object::Modified
virtual void Modified() const
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:288