Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkVectorProperty.h"
18 
19 namespace mitk
20 {
21  template <typename DATATYPE>
22  bool VectorProperty<DATATYPE>::IsEqual(const BaseProperty &property) const
23  {
24  return this->m_PropertyContent == static_cast<const Self &>(property).m_PropertyContent;
25  }
26 
27  template <typename DATATYPE>
28  bool VectorProperty<DATATYPE>::Assign(const BaseProperty &property)
29  {
30  this->m_PropertyContent = static_cast<const Self &>(property).m_PropertyContent;
31  return true;
32  }
33 
34  template <typename DATATYPE>
35  itk::LightObject::Pointer VectorProperty<DATATYPE>::InternalClone() const
36  {
37  itk::LightObject::Pointer result(new Self(*this));
38  return result;
39  }
40 
41  template <typename DATATYPE>
43  {
44  const size_t displayBlockLength = 3;
45  size_t beginningElementsCount = displayBlockLength;
46  size_t endElementsCount = displayBlockLength;
47 
48  if (m_PropertyContent.size() <= 2 * displayBlockLength)
49  {
50  beginningElementsCount = m_PropertyContent.size();
51  endElementsCount = 0;
52  }
53 
54  // return either a block of all items
55  // if the total number of maximum 2*displayBlockLength
56  //
57  // or return the first and last "displayBlockLength"
58  // number of items separated by "[...]";
59  std::stringstream string_collector;
60  for (size_t i = 0; i < beginningElementsCount; i++)
61  string_collector << m_PropertyContent[i] << "\n";
62  if (endElementsCount)
63  string_collector << "[... " << m_PropertyContent.size() - 2 * displayBlockLength << " more]\n";
64  for (size_t i = m_PropertyContent.size() - endElementsCount; i < m_PropertyContent.size(); ++i)
65  string_collector << m_PropertyContent[i] << "\n";
66 
67  std::string return_value = string_collector.str();
68 
69  // remove last '\n'
70  if (!return_value.empty())
71  return_value.erase(return_value.size() - 1);
72 
73  return return_value;
74  }
75 
76  template <typename DATATYPE>
78  {
79  m_PropertyContent = newValue;
80  }
81 
82  template <typename DATATYPE>
84  {
85  return m_PropertyContent;
86  }
87 
88  // Explicit instantiation for defined types.
91 
92 } // namespace mitk
itk::SmartPointer< Self > Pointer
virtual void SetValue(const VectorType &parameter_vector)
sets the content vector
DataCollection - Class to facilitate loading/accessing structured data.
virtual 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