File: itkBloxCoreAtomPixel.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 (302 lines) | stat: -rw-r--r-- 7,838 bytes parent folder | download | duplicates (2)
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: itkBloxCoreAtomPixel.txx,v $
  Language:  C++
  Date:      $Date: 2006-03-18 20:10:36 $
  Version:   $Revision: 1.20 $

  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 __itkBloxCoreAtomPixel_txx
#define __itkBloxCoreAtomPixel_txx

#include "itkBloxCoreAtomPixel.h"

namespace itk
{

template <unsigned int NDimensions>
BloxCoreAtomPixel<NDimensions>
::BloxCoreAtomPixel()
{
  m_RawCMatrix.fill(0);
  m_Eigenvalues.fill(0.0);
  m_Eigenvectors.fill(0.0);

  m_VotedCMatrix.fill(0);
  m_VotedEigenvalues.fill(0.0);
  m_VotedEigenvectors.fill(0.0);
  
  m_MeanCoreAtomDiameter = 0;
  m_ConstituencySize = 0;

  m_WeightSum = 0;

  m_MeanCoreAtomIntensity = 0.0;

  m_LocationSums[0] = 0;
  m_LocationSums[1] = 0;
  m_LocationSums[2] = 0;
}

template <unsigned int NDimensions>
BloxCoreAtomPixel<NDimensions>
::~BloxCoreAtomPixel()
{
  // The default destructor walks the pixel and deletes all bloxitems
}


//REMOVED: Boundary points dont know their intensities...profiles do!
template <unsigned int NDimensions>
void 
BloxCoreAtomPixel<NDimensions>
::CalcMeanCoreAtomIntensity()
{
  /*
  double temp_intensity = 0.0;
  int num_core_atoms = 0;

  itk::BloxCoreAtomPixel<NDimensions>::iterator bpiterator;

  for (bpiterator = this->begin(); bpiterator != this->end(); ++bpiterator)
    {
    // Get the pointer of the core atom
    CoreAtomItemType* pCoreAtom = *bpiterator;

    //get mean intensity for this core atom
    temp_intensity = (pCoreAtom->GetBoundaryPointA()->GetValue() 
                      + pCoreAtom->GetBoundaryPointB()->GetValue())/2;

    m_MeanCoreAtomIntensity += temp_intensity;
    num_core_atoms++;
    }
  m_MeanCoreAtomIntensity /= num_core_atoms;
  */
}

template <unsigned int NDimensions>
void 
BloxCoreAtomPixel<NDimensions>
::CalcWeightedCoreAtomLocation(double weight_factor, Self * votingPixel)
{
  // The iterator for accessing linked list info
  typename itk::BloxCoreAtomPixel<NDimensions>::iterator bpiterator;
  
  PositionType center;

  // Walk through all of the items in the voting pixel
  for (bpiterator = votingPixel->begin(); bpiterator != votingPixel->end();
                                                                  ++bpiterator)
    {
    // Get the pointer of the core atom
    CoreAtomItemType* pCoreAtom = *bpiterator;

    // Get the center of the core atom
    center = pCoreAtom->GetCenterPosition();

    m_LocationSums[0] += (center[0]*weight_factor);
    m_LocationSums[1] += (center[1]*weight_factor);
    m_LocationSums[2] += (center[2]*weight_factor);

    m_WeightSum += weight_factor;
    }
}

template <unsigned int NDimensions>
double 
BloxCoreAtomPixel<NDimensions>
::CalcMeanCoreAtomDiameter()
{
  // Returns a mean of 0 if there are no core atoms present
  if( this->empty() )
    {
    return 0;
    }

  unsigned long int numCoreAtoms = 0;
  m_MeanCoreAtomDiameter = 0;

  // The iterator for accessing linked list info
  typename itk::BloxCoreAtomPixel<NDimensions>::iterator bpiterator;
  
  // Walk through all of the items at the pixel
  for (bpiterator = this->begin(); bpiterator != this->end(); ++bpiterator)
    {
    // Get the pointer of the core atom
    CoreAtomItemType* pCoreAtom = *bpiterator;

    m_MeanCoreAtomDiameter += pCoreAtom->GetDiameter();
    
    numCoreAtoms++;
    }

  if(numCoreAtoms>0) // Check for /0 to be safe
    {
    m_MeanCoreAtomDiameter /= numCoreAtoms;
    }
  else
    {
    m_MeanCoreAtomDiameter = 0;
    }
  return m_MeanCoreAtomDiameter;
}

template <unsigned int NDimensions>
bool
BloxCoreAtomPixel<NDimensions>
::DoCoreAtomEigenanalysis()
{
  // Don't attemp Eigenanalysis on an empty blox
  if( this->empty() )
    {
    return false;
    }

  // The iterator for accessing linked list info
  typename itk::BloxCoreAtomPixel<NDimensions>::iterator bpiterator;

  // The number of items stored in the pixel
  unsigned long int numItems = 0;

  // Walk through all of the items at the pixel
  for (bpiterator = this->begin(); bpiterator != this->end(); ++bpiterator)
    {
    // Get the pointer of the core atom
    CoreAtomItemType* pCoreAtom = *bpiterator;

    // Get the boundary points
    BPItemType* pBPOne = pCoreAtom->GetBoundaryPointA();
    BPItemType* pBPTwo = pCoreAtom->GetBoundaryPointB();
    
    // Get the physical positions of the two boundary points
    VectorType P1;
    P1 = pBPOne->GetPhysicalPosition().GetVnlVector();
    
    VectorType P2;
    P2 = pBPTwo->GetPhysicalPosition().GetVnlVector();

    // Figure out the "C" vector of the core atom
    VectorType cVector = P2 - P1;
    cVector.normalize();

    // Now, add to m_RawCMatrix
    for(unsigned int r = 0; r < NDimensions; r++) // row loop
      {
      for(unsigned int c = 0; c < NDimensions; c++) // column loop
        {
        m_RawCMatrix(r,c) += cVector[c]*cVector[r];
        } // end column loop
      } // end row loop

    numItems++;

    } // end walk all of the items in the pixel

  // Divide through by the number of items
  m_RawCMatrix /= numItems;

  // Create an identity matrix of size n
  vnl_matrix_fixed<double, NDimensions, NDimensions> identMatrix;
  identMatrix.fill(0);

  // Set the diagonal to 1
  for(unsigned int n = 0; n < NDimensions; n++) // row loop
    {
    identMatrix(n,n) = 1.0;
    } // end row loop

  // Do eigen analysis
  vnl_generalized_eigensystem* pEigenSys = 
                    new vnl_generalized_eigensystem(m_RawCMatrix, identMatrix);

  // Now, store the results
  
  // First the eigenvectors
  m_Eigenvectors = pEigenSys->V;

  // Now the eigenvalues (stored as a vector to save space)
  for(unsigned int i = 0; i < NDimensions; i++)
    {
    m_Eigenvalues[i] = pEigenSys->D(i,i);
    }

  delete pEigenSys;
  return true;
}

template <unsigned int NDimensions>
typename BloxCoreAtomPixel<NDimensions>::PositionType
BloxCoreAtomPixel<NDimensions>
::GetVotedLocation()
{
  m_VotedLocation[0] = m_LocationSums[0] / m_WeightSum;
  m_VotedLocation[1] = m_LocationSums[1] / m_WeightSum;
  m_VotedLocation[2] = m_LocationSums[2] / m_WeightSum;

  return m_VotedLocation;
}

template <unsigned int NDimensions>
void
BloxCoreAtomPixel<NDimensions>
::CollectVote(MatrixType* pMatrix, double strength, double count)
{
  m_VotedCMatrix += (*pMatrix)*strength;
  m_ConstituencySize += count;
}

template <unsigned int NDimensions>
void
BloxCoreAtomPixel<NDimensions>
::NormalizeVotedCMatrix()
{
  if(m_ConstituencySize != 0)
    {
    m_VotedCMatrix /= m_ConstituencySize;
    }
}

template <unsigned int NDimensions>
void
BloxCoreAtomPixel<NDimensions>
::DoVotedEigenanalysis()
{
  // Create an identity matrix of size n
  vnl_matrix_fixed<double, NDimensions, NDimensions> identMatrix;
  identMatrix.fill(0);

  // Set the diagonal to 1
  for(unsigned int n = 0; n < NDimensions; n++) // row loop
    {
    identMatrix(n,n) = 1.0;
    } // end row loop

  // Do eigen analysis
  vnl_generalized_eigensystem* pEigenSys = 
                new vnl_generalized_eigensystem(m_VotedCMatrix, identMatrix);

  // Now, store the results
  
  // First the eigenvectors
  m_VotedEigenvectors = pEigenSys->V;

  // Now the eigenvalues (stored as a vector to save space)
  for(unsigned int i = 0; i < NDimensions; i++)
    {
    m_VotedEigenvalues[i] = pEigenSys->D(i,i);
    }

  delete pEigenSys;
}

} // end namespace itk

#endif