File: itkCoreAtomImageToDistanceMatrixProcess.txx

package info (click to toggle)
insighttoolkit 3.6.0-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 94,956 kB
  • ctags: 74,981
  • sloc: cpp: 355,621; ansic: 195,070; fortran: 28,713; python: 3,802; tcl: 1,996; sh: 1,175; java: 583; makefile: 415; csh: 184; perl: 175
file content (192 lines) | stat: -rw-r--r-- 5,808 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: itkCoreAtomImageToDistanceMatrixProcess.txx,v $
  Language:  C++
  Date:      $Date: 2006-03-19 04:36:58 $
  Version:   $Revision: 1.6 $

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#ifndef __itkCoreAtomImageToDistanceMatrixProcess_txx
#define __itkCoreAtomImageToDistanceMatrixProcess_txx

#include "itkCoreAtomImageToDistanceMatrixProcess.h"

namespace itk
{

/**
* Default Constructor.  Initializes outputs for the process object.
*/
template< typename TSourceImage >
CoreAtomImageToDistanceMatrixProcess< TSourceImage >
::CoreAtomImageToDistanceMatrixProcess()
{
  itkDebugMacro(<< "itkCoreAtomImageToDistanceMatrixProcess::itkCoreAtomImageToDistanceMatrixProcess() called");

  // Setting the output.
  DistanceMatrixPointer output;
  output = static_cast<typename CoreAtomImageToDistanceMatrixProcess::DistanceMatrixType*>(this->MakeOutput(0).GetPointer()); 
  this->ProcessObject::SetNumberOfRequiredOutputs(1);
  this->ProcessObject::SetNthOutput(0, output.GetPointer());
}

/**
 * Returns a pointer to the output cast as a Data Object.
 */
template< typename TSourceImage >
typename CoreAtomImageToDistanceMatrixProcess< TSourceImage >::DataObjectPointer
CoreAtomImageToDistanceMatrixProcess< TSourceImage >
::MakeOutput(unsigned int)
{
  return static_cast<DataObject*>(DistanceMatrixType::New().GetPointer());
}

/**
 * Standard GetOutput
 */
template< typename TSourceImage >
typename CoreAtomImageToDistanceMatrixProcess< TSourceImage >::DistanceMatrixType*
CoreAtomImageToDistanceMatrixProcess< TSourceImage >
::GetOutput()
{
  if (this->GetNumberOfOutputs() < 1)
    {
    return 0;
    }
  return static_cast< DistanceMatrixType * >
                     (this->ProcessObject::GetOutput(0));
}

/**
 * Sets the core atom image input.
 */
template< typename TSourceImage >
void
CoreAtomImageToDistanceMatrixProcess< TSourceImage > 
::SetInput1(const TSourceImage * image1 ) 
{
  itkDebugMacro(<< "itkCoreAtomImageToDistanceMatrixProcess: Setting core atom image");
  // Process object is not const-correct so the const casting is required.
  SetNthInput(0,  const_cast<TSourceImage *>( image1 ) );
}

/**
 * Get the core atom image
 */
template< typename TSourceImage >
TSourceImage *
CoreAtomImageToDistanceMatrixProcess< TSourceImage >
::GetInput1() 
{
  // Process object is not const-correct so the const casting is required.
  return const_cast<TSourceImage *>(this->GetNthInput(0));
}

/**
 * 
 */
template< typename TSourceImage >
void
CoreAtomImageToDistanceMatrixProcess< TSourceImage >
::GenerateData()
{
  itkDebugMacro(<< "itkCoreAtomImageToDistanceMatrixProcess::GenerateData() called");

  // Pointers to the core atom images, output matrix object.
  m_CoreAtomImage = dynamic_cast<CoreAtomImageType*>(ProcessObject::GetInput(0));
  m_DistanceMatrix = dynamic_cast<DistanceMatrixType*>(ProcessObject::GetOutput(0));

  // Get the number of medial nodes in the core atom image.
  m_NumberOfNodes = m_CoreAtomImage->GetMedialNodeCount();

  // Resize the distance matrix
  if(m_DistanceMatrix->set_size(m_NumberOfNodes,m_NumberOfNodes))
    {
    itkDebugMacro(<< "m_DistanceMatrix resized successfully");
    }
  else
    {
    itkDebugMacro(<< "m_DistanceMatrix resize failed");
    assert(0);
    }
  itkDebugMacro(<< "CoreAtomImageToDistanceMatrixProcess::GenerateData(): Matrix Size: " << m_NumberOfNodes << " x " << m_NumberOfNodes);

  // Create iterator that will walk the blox core atom image.
  typedef itk::ImageRegionIterator<CoreAtomImageType> BloxIterator;

  BloxIterator bloxIt = BloxIterator(m_CoreAtomImage,
                                      m_CoreAtomImage->GetRequestedRegion() );

  BloxIterator bloxIt2 = BloxIterator(m_CoreAtomImage,
                                      m_CoreAtomImage->GetRequestedRegion() );

  // Pointer for accessing pixel.
  MedialNodeType* pPixel1;
  MedialNodeType* pPixel2;

  // Local variables.
  PositionType DistanceVector;
  PositionType Location1;
  PositionType Location2;
  double distance;
  int counter1 = 0;
  int counter2 = 0;

  // Iterate through nodes in the core atom image.
  for ( bloxIt.GoToBegin(); !bloxIt.IsAtEnd(); ++bloxIt)
    {
    pPixel1 = &bloxIt.Value();

    if( pPixel1->empty() )
      continue;

    for ( bloxIt2.GoToBegin(); !bloxIt2.IsAtEnd(); ++bloxIt2)
      {
      pPixel2 = &bloxIt2.Value();

      if( pPixel2->empty() )
        continue;

      // Get distance between pPixel1 and pPixel2.
      Location1 = pPixel1->GetVotedLocation();
      Location2 = pPixel2->GetVotedLocation();

      DistanceVector[0] = Location1[0] - Location2[0];
      DistanceVector[1] = Location1[1] - Location2[1];
      DistanceVector[2] = Location1[2] - Location2[2];

      distance = vcl_sqrt(vcl_pow((double)DistanceVector[0],2.0) + vcl_pow((double)DistanceVector[1],2.0) + vcl_pow((double)DistanceVector[2],2.0) );

      m_DistanceMatrix->put(counter1,counter2,distance);
  
      counter2++;
      }
    counter2 = 0;
    counter1++;
    }
  itkDebugMacro(<< "Finished CoreAtomImageToDistanceMatrixProcess\n");
}

/**
 * Print Self
 */
template< typename TSourceImage >
void
CoreAtomImageToDistanceMatrixProcess< TSourceImage >
::PrintSelf(std::ostream& os, Indent indent) const
{
  Superclass::PrintSelf(os,indent);
}

} // end namespace

#endif