Orfeo Toolbox  3.16
itkSpatialObjectDuplicator.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3 Program: Insight Segmentation & Registration Toolkit
4 Module: $RCSfile: itkSpatialObjectDuplicator.txx,v $
5 Language: C++
6 Date: $Date: 2007-01-28 19:24:57 $
7 Version: $Revision: 1.2 $
8 
9 Copyright (c) Insight Software Consortium. All rights reserved.
10 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkSpatialObjectDuplicator_txx
18 #define __itkSpatialObjectDuplicator_txx
19 
22 
23 namespace itk
24 {
25 
27 template<class TInputSpatialObject>
30 {
31  m_Input = NULL;
32  m_Output = NULL;
33  m_InternalSpatialObjectTime = 0;
35 }
36 
38 template<class TInputSpatialObject>
39 void
42  InternalSpatialObjectType* destination)
43 {
44  // Create the new Spatial Object using the SpatialObjectFactory
46  std::string value = source->GetSpatialObjectTypeAsString();
47  i = ObjectFactoryBase::CreateInstance ( value.c_str() );
48 
50 
51  SOType* newSO = dynamic_cast<SOType*> ( i.GetPointer() );
52  if ( newSO == NULL )
53  {
54  std::cout << "Could not create an instance of " << value << std::endl
55  << "The usual cause of this error is not registering the "
56  << "SpatialObject with SpatialFactory" << std::endl;
57  std::cout << "Currently registered Transforms: " << std::endl;
58  std::list<std::string> names =
60  std::list<std::string>::iterator it;
61  for ( it = names.begin(); it != names.end(); it++ )
62  {
63  std::cout << "\t\"" << *it << "\"" << std::endl;
64  }
65  return;
66  }
67 
68  // We make the copy
69  newSO->CopyInformation(source);
70  destination->AddSpatialObject(newSO);
71 
72  typedef typename TInputSpatialObject::ChildrenListType ChildrenListType;
73  ChildrenListType* children = source->GetChildren(0);
74  typename ChildrenListType::const_iterator it = children->begin();
75  while(it != children->end())
76  {
77  this->CopyObject(*it,newSO);
78  it++;
79  }
80  delete children;
81 
82 }
83 
85 template<class TInputSpatialObject>
86 void
88 ::Update(void)
89 {
90  if(!m_Input)
91  {
92  itkExceptionMacro(<<"Input SpatialObject has not been connected");
93  return;
94  }
95 
96  // Update only if the input SpatialObject has been modified
97  unsigned long t, t1, t2;
98  t1 = m_Input->GetPipelineMTime();
99  t2 = m_Input->GetMTime();
100  t = (t1 > t2 ? t1 : t2);
101 
102  if(t == m_InternalSpatialObjectTime)
103  {
104  return; // No need to update
105  }
106 
107  // Cache the timestamp
108  m_InternalSpatialObjectTime = t;
109 
110  //Copy the object first
111  // Create the new Spatial Object using the SpatialObjectFactory
113  std::string value = m_Input->GetSpatialObjectTypeAsString();
114  i = ObjectFactoryBase::CreateInstance ( value.c_str() );
115 
116  m_Output = dynamic_cast<SpatialObjectType*> ( i.GetPointer() );
117  if ( m_Output.IsNull() )
118  {
119  std::cout << "Could not create an instance of " << value << std::endl
120  << "The usual cause of this error is not registering the "
121  << "SpatialObject with SpatialFactory" << std::endl;
122  std::cout << "Currently registered Transforms: " << std::endl;
123  std::list<std::string> names =
125  std::list<std::string>::iterator it;
126  for ( it = names.begin(); it != names.end(); it++ )
127  {
128  std::cout << "\t\"" << *it << "\"" << std::endl;
129  }
130  return;
131  }
132 
133  m_Output->CopyInformation(m_Input);
134 
135 
136  // Create the children
137  typedef typename TInputSpatialObject::ChildrenListType ChildrenListType;
138  ChildrenListType* children = m_Input->GetChildren(0);
139  typename ChildrenListType::const_iterator it = children->begin();
140  while(it != children->end())
141  {
142  this->CopyObject(*it,m_Output);
143  it++;
144  }
145  delete children;
146 }
147 
148 template<class TInputSpatialObject>
149 void
151 ::PrintSelf( std::ostream& os, Indent indent ) const
152 {
153  Superclass::PrintSelf(os,indent);
154  os << indent << "Input SpatialObject: " << m_Input << std::endl;
155  os << indent << "Output SpatialObject: " << m_Output << std::endl;
156  os << indent << "Internal SpatialObject Time: "
157  << m_InternalSpatialObjectTime << std::endl;
158 }
159 
160 } // end namespace itk
161 
162 #endif

Generated at Sun Feb 3 2013 00:08:13 for Orfeo Toolbox with doxygen 1.8.1.1