Orfeo Toolbox  3.16
itkCoreAtomImageToDistanceMatrixProcess.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkCoreAtomImageToDistanceMatrixProcess.txx,v $
5  Language: C++
6  Date: $Date: 2008-10-07 12:04:18 $
7  Version: $Revision: 1.7 $
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 
18 #ifndef __itkCoreAtomImageToDistanceMatrixProcess_txx
19 #define __itkCoreAtomImageToDistanceMatrixProcess_txx
20 
22 
23 namespace itk
24 {
25 
29 template< typename TSourceImage >
32 {
33  itkDebugMacro(<< "itkCoreAtomImageToDistanceMatrixProcess::itkCoreAtomImageToDistanceMatrixProcess() called");
34 
36  DistanceMatrixPointer output;
37  output = static_cast<typename CoreAtomImageToDistanceMatrixProcess::DistanceMatrixType*>(this->MakeOutput(0).GetPointer());
39  this->ProcessObject::SetNthOutput(0, output.GetPointer());
40 }
41 
45 template< typename TSourceImage >
48 ::MakeOutput(unsigned int)
49 {
50  return static_cast<DataObject*>(DistanceMatrixType::New().GetPointer());
51 }
52 
56 template< typename TSourceImage >
60 {
61  if (this->GetNumberOfOutputs() < 1)
62  {
63  return 0;
64  }
65  return static_cast< DistanceMatrixType * >
66  (this->ProcessObject::GetOutput(0));
67 }
68 
72 template< typename TSourceImage >
73 void
75 ::SetInput1(const TSourceImage * image1 )
76 {
77  itkDebugMacro(<< "itkCoreAtomImageToDistanceMatrixProcess: Setting core atom image");
78  // Process object is not const-correct so the const casting is required.
79  SetNthInput(0, const_cast<TSourceImage *>( image1 ) );
80 }
81 
85 template< typename TSourceImage >
86 TSourceImage *
89 {
90  // Process object is not const-correct so the const casting is required.
91  return const_cast<TSourceImage *>(this->GetNthInput(0));
92 }
93 
97 template< typename TSourceImage >
98 void
101 {
102  itkDebugMacro(<< "itkCoreAtomImageToDistanceMatrixProcess::GenerateData() called");
103 
104  // Pointers to the core atom images, output matrix object.
105  m_CoreAtomImage = dynamic_cast<CoreAtomImageType*>(ProcessObject::GetInput(0));
106  m_DistanceMatrix = dynamic_cast<DistanceMatrixType*>(ProcessObject::GetOutput(0));
107 
108  // Get the number of medial nodes in the core atom image.
109  m_NumberOfNodes = m_CoreAtomImage->GetMedialNodeCount();
110 
111  // Resize the distance matrix
112  if(m_DistanceMatrix->set_size(m_NumberOfNodes,m_NumberOfNodes))
113  {
114  itkDebugMacro(<< "m_DistanceMatrix resized successfully");
115  }
116  else
117  {
118  itkDebugMacro(<< "m_DistanceMatrix resize failed");
119  assert(0);
120  }
121  itkDebugMacro(<< "CoreAtomImageToDistanceMatrixProcess::GenerateData(): Matrix Size: " << m_NumberOfNodes << " x " << m_NumberOfNodes);
122 
123  // Create iterator that will walk the blox core atom image.
124  typedef itk::ImageRegionIterator<CoreAtomImageType> BloxIterator;
125 
126  BloxIterator bloxIt = BloxIterator(m_CoreAtomImage,
127  m_CoreAtomImage->GetRequestedRegion() );
128 
129  BloxIterator bloxIt2 = BloxIterator(m_CoreAtomImage,
130  m_CoreAtomImage->GetRequestedRegion() );
131 
132  // Pointer for accessing pixel.
133  MedialNodeType* pPixel1;
134  MedialNodeType* pPixel2;
135 
136  // Local variables.
137  PositionType DistanceVector;
138  PositionType Location1;
139  PositionType Location2;
140  double distance;
141  int counter1 = 0;
142  int counter2 = 0;
143 
144  // Iterate through nodes in the core atom image.
145  for ( bloxIt.GoToBegin(); !bloxIt.IsAtEnd(); ++bloxIt)
146  {
147  pPixel1 = &bloxIt.Value();
148 
149  if( pPixel1->empty() )
150  {
151  continue;
152  }
153  for ( bloxIt2.GoToBegin(); !bloxIt2.IsAtEnd(); ++bloxIt2)
154  {
155  pPixel2 = &bloxIt2.Value();
156 
157  if( pPixel2->empty() )
158  {
159  continue;
160  }
161  // Get distance between pPixel1 and pPixel2.
162  Location1 = pPixel1->GetVotedLocation();
163  Location2 = pPixel2->GetVotedLocation();
164 
165  DistanceVector[0] = Location1[0] - Location2[0];
166  DistanceVector[1] = Location1[1] - Location2[1];
167  DistanceVector[2] = Location1[2] - Location2[2];
168 
169  distance = vcl_sqrt(vcl_pow((double)DistanceVector[0],2.0) + vcl_pow((double)DistanceVector[1],2.0) + vcl_pow((double)DistanceVector[2],2.0) );
170 
171  m_DistanceMatrix->put(counter1,counter2,distance);
172 
173  counter2++;
174  }
175  counter2 = 0;
176  counter1++;
177  }
178  itkDebugMacro(<< "Finished CoreAtomImageToDistanceMatrixProcess\n");
179 }
180 
184 template< typename TSourceImage >
185 void
187 ::PrintSelf(std::ostream& os, Indent indent) const
188 {
189  Superclass::PrintSelf(os,indent);
190 }
191 
192 } // end namespace
193 
194 #endif

Generated at Sat Feb 2 2013 23:33:44 for Orfeo Toolbox with doxygen 1.8.1.1