KWStyle - itkImageDuplicator.txx
 
Matrix View
Description

1 /*=========================================================================
2
3 Program:   Insight Segmentation & Registration Toolkit
4 Module:    $RCSfile: itkImageDuplicator.txx.html,v $
5 Language:  C++
6 Date:      $Date: 2006/01/17 19:15:37 $
7 Version:   $Revision: 1.4 $
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 DEF #ifndef _itkImageDuplicator_txx
18 DEF #define _itkImageDuplicator_txx
19
20 #include "itkImageDuplicator.h"
21
22
23 namespace itk
24
25     
26 /** Constructor */
27 template<class TInputImage>
28 ImageDuplicator<TInputImage>
29 ::ImageDuplicator()
30 {
31   m_InputImage = NULL;
32   m_Output = NULL;
33   m_InternalImageTime = 0;
34 }
35
36 /** */
37 template<class TInputImage>
38 void
39 ImageDuplicator<TInputImage>
40 ::Update(void)
41 {
42   if(!m_InputImage )
43     {
44     itkExceptionMacro(<<"Input image has not been connected");
45     return;
46     }
47
48   // Update only if the input image has been modified
49   unsigned long t, t1, t2;
50   t1 = m_InputImage->GetPipelineMTime();
51   t2 = m_InputImage->GetMTime();
52   t = (t1 > t2 ? t1 : t2);
53
54   if(t == m_InternalImageTime) 
55     {
56     return; // No need to update
57     }
58
59   // Cache the timestamp
60   m_InternalImageTime = t;
61
62   // Allocate the image
63   m_Output = ImageType::New();
64   m_Output->SetOrigin(m_InputImage->GetOrigin());
65   m_Output->SetSpacing(m_InputImage->GetSpacing());
66   m_Output->SetDirection(m_InputImage->GetDirection());
67   m_Output->SetLargestPossibleRegion(m_InputImage->GetLargestPossibleRegion());
68   m_Output->SetRequestedRegion(m_InputImage->GetRequestedRegion());
69   m_Output->SetBufferedRegion(m_InputImage->GetBufferedRegion());
70   m_Output->Allocate();
71
72   // Do the copy
73   unsigned long size = 1;
74   for(unsigned int i=0;i<itkGetStaticConstMacro(ImageDimension);i++)
75     {
76     size *= m_InputImage->GetBufferedRegion().GetSize()[i];
77     }
78
79 LEN   memcpy(m_Output->GetBufferPointer(),m_InputImage->GetBufferPointer(),size*sizeof(PixelType));
80
81 }
82
83 template<class TInputImage>
84 void
85 ImageDuplicator<TInputImage>
86 ::PrintSelf( std::ostream& os, Indent indent ) const
87 {
88   Superclass::PrintSelf(os,indent);
89   os << indent << "Input Image: " << m_InputImage << std::endl;
90   os << indent << "Output Image: " << m_Output << std::endl;
91   os << indent << "Internal Image Time: " << m_InternalImageTime << std::endl;
92 }
93
94 // end namespace itk
95
96 #endif
97

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:13PM
© Kitware Inc.