Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkVectorProperty.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkVectorProperty.h"
14 
15 namespace mitk
16 {
17  template <typename DATATYPE>
18  bool VectorProperty<DATATYPE>::IsEqual(const BaseProperty &property) const
19  {
20  return this->m_PropertyContent == static_cast<const Self &>(property).m_PropertyContent;
21  }
22 
23  template <typename DATATYPE>
24  bool VectorProperty<DATATYPE>::Assign(const BaseProperty &property)
25  {
26  this->m_PropertyContent = static_cast<const Self &>(property).m_PropertyContent;
27  return true;
28  }
29 
30  template <typename DATATYPE>
31  itk::LightObject::Pointer VectorProperty<DATATYPE>::InternalClone() const
32  {
33  itk::LightObject::Pointer result(new Self(*this));
34  return result;
35  }
36 
37  template <typename DATATYPE>
39  {
40  const size_t displayBlockLength = 3;
41  size_t beginningElementsCount = displayBlockLength;
42  size_t endElementsCount = displayBlockLength;
43 
44  if (m_PropertyContent.size() <= 2 * displayBlockLength)
45  {
46  beginningElementsCount = m_PropertyContent.size();
47  endElementsCount = 0;
48  }
49 
50  // return either a block of all items
51  // if the total number of maximum 2*displayBlockLength
52  //
53  // or return the first and last "displayBlockLength"
54  // number of items separated by "[...]";
55  std::stringstream string_collector;
56  for (size_t i = 0; i < beginningElementsCount; i++)
57  string_collector << m_PropertyContent[i] << "\n";
58  if (endElementsCount)
59  string_collector << "[... " << m_PropertyContent.size() - 2 * displayBlockLength << " more]\n";
60  for (size_t i = m_PropertyContent.size() - endElementsCount; i < m_PropertyContent.size(); ++i)
61  string_collector << m_PropertyContent[i] << "\n";
62 
63  std::string return_value = string_collector.str();
64 
65  // remove last '\n'
66  if (!return_value.empty())
67  return_value.erase(return_value.size() - 1);
68 
69  return return_value;
70  }
71 
72  template <typename DATATYPE>
74  {
75  m_PropertyContent = newValue;
76  }
77 
78  template <typename DATATYPE>
80  {
81  return m_PropertyContent;
82  }
83 
84  // Explicit instantiation for defined types.
87  MITK_DEFINE_VECTOR_PROPERTY(unsigned int)
88  MITK_DEFINE_VECTOR_PROPERTY(std::string)
89 
90 } // namespace mitk
virtual void SetValue(const VectorType &parameter_vector)
sets the content vector
DataCollection - Class to facilitate loading/accessing structured data.
std::string GetValueAsString() const override
virtual const VectorType & GetValue() const
returns a const reference to the contained vector
#define MITK_DEFINE_VECTOR_PROPERTY(TYPE)
This should be used in a .cpp file.
std::vector< DATATYPE > VectorType