| 1 |
|
/*========================================================================= |
| 2 |
|
|
| 3 |
|
Program: Insight Segmentation & Registration Toolkit |
| 4 |
|
Module: $RCSfile: itkCoreAtomImageToDistanceMatrixProcess.txx.html,v $ |
| 5 |
|
Language: C++ |
| 6 |
|
Date: $Date: 2006/01/17 19:15:34 $ |
| 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 |
|
|
| 18 |
|
#ifndef __itkCoreAtomImageToDistanceMatrixProcess_txx |
| 19 |
|
#define __itkCoreAtomImageToDistanceMatrixProcess_txx |
| 20 |
|
|
| 21 |
|
#include "itkCoreAtomImageToDistanceMatrixProcess.h" |
| 22 |
|
|
| 23 |
|
namespace itk |
| 24 |
|
{ |
| 25 |
|
|
| 26 |
|
/** |
| 27 |
IND |
* Default Constructor. Initializes outputs for the process object. |
| 28 |
IND |
*/ |
| 29 |
|
template< typename TSourceImage > |
| 30 |
|
CoreAtomImageToDistanceMatrixProcess< TSourceImage > |
| 31 |
|
::CoreAtomImageToDistanceMatrixProcess() |
| 32 |
|
{ |
| 33 |
LEN |
itkDebugMacro(<< "itkCoreAtomImageToDistanceMatrixProcess::itkCoreAtomImageToDistanceMatrixProcess() called"); |
| 34 |
|
|
| 35 |
|
// Setting the output. |
| 36 |
|
DistanceMatrixPointer output; |
| 37 |
LEN |
output = static_cast<typename CoreAtomImageToDistanceMatrixProcess::DistanceMatrixType*>(this->MakeOutput(0).GetPointer()); |
| 38 |
|
this->ProcessObject::SetNumberOfRequiredOutputs(1); |
| 39 |
|
this->ProcessObject::SetNthOutput(0, output.GetPointer()); |
| 40 |
|
} |
| 41 |
|
|
| 42 |
|
/** |
| 43 |
|
* Returns a pointer to the output cast as a Data Object. |
| 44 |
|
*/ |
| 45 |
|
template< typename TSourceImage > |
| 46 |
|
typename CoreAtomImageToDistanceMatrixProcess< TSourceImage >::DataObjectPointer |
| 47 |
|
CoreAtomImageToDistanceMatrixProcess< TSourceImage > |
| 48 |
|
::MakeOutput(unsigned int) |
| 49 |
|
{ |
| 50 |
|
return static_cast<DataObject*>(DistanceMatrixType::New().GetPointer()); |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
/** |
| 54 |
|
* Standard GetOutput |
| 55 |
|
*/ |
| 56 |
|
template< typename TSourceImage > |
| 57 |
LEN |
typename CoreAtomImageToDistanceMatrixProcess< TSourceImage >::DistanceMatrixType* |
| 58 |
|
CoreAtomImageToDistanceMatrixProcess< TSourceImage > |
| 59 |
|
::GetOutput() |
| 60 |
|
{ |
| 61 |
|
if (this->GetNumberOfOutputs() < 1) |
| 62 |
|
{ |
| 63 |
|
return 0; |
| 64 |
|
} |
| 65 |
|
return static_cast< DistanceMatrixType * > |
| 66 |
IND |
*********************(this->ProcessObject::GetOutput(0)); |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
/** |
| 70 |
|
* Sets the core atom image input. |
| 71 |
|
*/ |
| 72 |
|
template< typename TSourceImage > |
| 73 |
|
void |
| 74 |
|
CoreAtomImageToDistanceMatrixProcess< TSourceImage > |
| 75 |
|
::SetInput1(const TSourceImage * image1 ) |
| 76 |
|
{ |
| 77 |
LEN |
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 |
|
|
| 82 |
|
/** |
| 83 |
|
* Get the core atom image |
| 84 |
|
*/ |
| 85 |
|
template< typename TSourceImage > |
| 86 |
|
TSourceImage * |
| 87 |
|
CoreAtomImageToDistanceMatrixProcess< TSourceImage > |
| 88 |
|
::GetInput1() |
| 89 |
|
{ |
| 90 |
|
// Process object is not const-correct so the const casting is required. |
| 91 |
|
return const_cast<TSourceImage *>(this->GetNthInput(0)); |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
/** |
| 95 |
|
* |
| 96 |
|
*/ |
| 97 |
|
template< typename TSourceImage > |
| 98 |
|
void |
| 99 |
|
CoreAtomImageToDistanceMatrixProcess< TSourceImage > |
| 100 |
|
::GenerateData() |
| 101 |
|
{ |
| 102 |
LEN |
itkDebugMacro(<< "itkCoreAtomImageToDistanceMatrixProcess::GenerateData() called"); |
| 103 |
|
|
| 104 |
|
// Pointers to the core atom images, output matrix object. |
| 105 |
LEN |
m_CoreAtomImage = dynamic_cast<CoreAtomImageType*>(ProcessObject::GetInput(0)); |
| 106 |
LEN |
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 |
LEN |
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 |
IND |
******continue; |
| 151 |
|
|
| 152 |
|
for ( bloxIt2.GoToBegin(); !bloxIt2.IsAtEnd(); ++bloxIt2) |
| 153 |
|
{ |
| 154 |
|
pPixel2 = &bloxIt2.Value(); |
| 155 |
|
|
| 156 |
|
if( pPixel2->empty() ) |
| 157 |
IND |
********continue; |
| 158 |
|
|
| 159 |
|
// Get distance between pPixel1 and pPixel2. |
| 160 |
|
Location1 = pPixel1->GetVotedLocation(); |
| 161 |
|
Location2 = pPixel2->GetVotedLocation(); |
| 162 |
|
|
| 163 |
|
DistanceVector[0] = Location1[0] - Location2[0]; |
| 164 |
|
DistanceVector[1] = Location1[1] - Location2[1]; |
| 165 |
|
DistanceVector[2] = Location1[2] - Location2[2]; |
| 166 |
|
|
| 167 |
LEN |
distance = sqrt( pow((double)DistanceVector[0],2.0) + pow((double)DistanceVector[1],2.0) + pow((double)DistanceVector[2],2.0) ); |
| 168 |
|
|
| 169 |
|
m_DistanceMatrix->put(counter1,counter2,distance); |
| 170 |
|
|
| 171 |
|
counter2++; |
| 172 |
|
} |
| 173 |
|
counter2 = 0; |
| 174 |
|
counter1++; |
| 175 |
|
} |
| 176 |
|
itkDebugMacro(<< "Finished CoreAtomImageToDistanceMatrixProcess\n"); |
| 177 |
|
} |
| 178 |
|
|
| 179 |
|
/** |
| 180 |
|
* Print Self |
| 181 |
|
*/ |
| 182 |
|
template< typename TSourceImage > |
| 183 |
|
void |
| 184 |
|
CoreAtomImageToDistanceMatrixProcess< TSourceImage > |
| 185 |
|
::PrintSelf(std::ostream& os, Indent indent) const |
| 186 |
|
{ |
| 187 |
|
Superclass::PrintSelf(os,indent); |
| 188 |
|
} |
| 189 |
|
|
| 190 |
|
} // end namespace |
| 191 |
|
|
| 192 |
|
#endif |
| 193 |
|
|