ITK  5.0.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:
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 Size() const = 0;
97 
100  virtual const MeasurementVectorType &
102 
106 
108  virtual TotalAbsoluteFrequencyType GetTotalFrequency() const = 0;
109 
112  {
113  // Test whether the vector type is resizable or not
115 
117  {
118  // then this is a resizable vector type
119  //
120  // if the new size is the same as the previou size, just return
121  if ( s == this->m_MeasurementVectorSize )
122  {
123  return;
124  }
125  else
126  {
127  // If the new size is different from the current size, then
128  // only change the measurement vector size if the container is empty.
129  if ( this->Size() )
130  {
131  itkExceptionMacro("Attempting to change the measurement \
132  vector size of a non-empty Sample");
133  }
134  else
135  {
136  this->m_MeasurementVectorSize = s;
137  this->Modified();
138  }
139  }
140  }
141  else
142  {
143  // If this is a non-resizable vector type
145  MeasurementVectorSizeType defaultLength =
147  // and the new length is different from the default one, then throw an
148  // exception
149  if ( defaultLength != s )
150  {
151  itkExceptionMacro(
152  "Attempting to change the measurement \
153  vector size of a non-resizable vector type" );
154  }
155  }
156  }
157 
159  itkGetConstMacro(MeasurementVectorSize, MeasurementVectorSizeType);
160 
162  void 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  {
178  }
179 
180  ~Sample() override = default;
181 
182  void PrintSelf(std::ostream & os, Indent indent) const override
183  {
184  Superclass::PrintSelf(os, indent);
185  os << indent << "Length of measurement vectors in the sample: "
186  << 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
typename MeasurementVectorTraits::InstanceIdentifier InstanceIdentifier
Definition: itkSample.h:90
virtual InstanceIdentifier Size() const =0
typename TMeasurementVector::ValueType ValueType
Define numeric traits for std::vector.
void Graft(const DataObject *thatObject) override
Definition: itkSample.h:162
virtual const MeasurementVectorType & GetMeasurementVector(InstanceIdentifier id) const =0
virtual AbsoluteFrequencyType GetFrequency(InstanceIdentifier id) const =0
virtual void Graft(const DataObject *)
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkSample.h:182
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:51
virtual void SetMeasurementVectorSize(MeasurementVectorSizeType s)
Definition: itkSample.h:111
static bool IsResizable(const TVectorType &)
void PrintSelf(std::ostream &os, Indent indent) const override
TMeasurementVector MeasurementVectorType
Definition: itkSample.h:76
virtual void Modified() const
NumericTraits< AbsoluteFrequencyType >::AccumulateType TotalAbsoluteFrequencyType
Definition: itkSample.h:86
A collection of measurements for statistical analysis.
Definition: itkSample.h:61
Control indentation during Print() invocation.
Definition: itkIndent.h:49
MeasurementVectorSizeType m_MeasurementVectorSize
Definition: itkSample.h:190
typename MeasurementVectorTraitsTypes< MeasurementVectorType >::ValueType MeasurementType
Definition: itkSample.h:80
Base class for most ITK classes.
Definition: itkObject.h:60
~Sample() override=default
Base class for all data objects in ITK.
virtual TotalAbsoluteFrequencyType GetTotalFrequency() const =0
MeasurementVectorTraits::AbsoluteFrequencyType AbsoluteFrequencyType
Definition: itkSample.h:83