KWStyle - itkBloxCoreAtomPixel.txx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkBloxCoreAtomPixel.txx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:33 $
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 #ifndef __itkBloxCoreAtomPixel_txx
18 #define __itkBloxCoreAtomPixel_txx
19
20 #include "itkBloxCoreAtomPixel.h"
21
22 namespace itk
23 {
24
25 template <unsigned int NDimensions>
26 BloxCoreAtomPixel<NDimensions>
27 ::BloxCoreAtomPixel()
28 {
29   m_RawCMatrix.fill(0);
30   m_Eigenvalues.fill(0.0);
31   m_Eigenvectors.fill(0.0);
32
33   m_VotedCMatrix.fill(0);
34   m_VotedEigenvalues.fill(0.0);
35   m_VotedEigenvectors.fill(0.0);
36   
37   m_MeanCoreAtomDiameter = 0;
38   m_ConstituencySize = 0;
39
40   m_WeightSum = 0;
41
42   m_MeanCoreAtomIntensity = 0.0;
43
44   m_LocationSums[0] = 0;
45   m_LocationSums[1] = 0;
46   m_LocationSums[2] = 0;
47 }
48
49 template <unsigned int NDimensions>
50 BloxCoreAtomPixel<NDimensions>
51 ::~BloxCoreAtomPixel()
52 {
53   // The default destructor walks the pixel and deletes all bloxitems
54 }
55
56
57 //REMOVED: Boundary points dont know their intensities...profiles do!
58 template <unsigned int NDimensions>
59 void 
60 BloxCoreAtomPixel<NDimensions>
61 ::CalcMeanCoreAtomIntensity()
62 {
63
64 IND /*
65   double temp_intensity = 0.0;
66   int num_core_atoms = 0;
67
68   itk::BloxCoreAtomPixel<NDimensions>::iterator bpiterator;
69
70   for (bpiterator = this->begin(); bpiterator != this->end(); ++bpiterator)
71     {
72     // Get the pointer of the core atom
73     CoreAtomItemType* pCoreAtom = *bpiterator;
74
75     //get mean intensity for this core atom
76 LEN     temp_intensity = (pCoreAtom->GetBoundaryPointA()->GetValue() + pCoreAtom->GetBoundaryPointB()->GetValue())/2
77
78     m_MeanCoreAtomIntensity += temp_intensity;
79     num_core_atoms++;
80     }
81   m_MeanCoreAtomIntensity /= num_core_atoms;
82 IND */
83 }
84
85 template <unsigned int NDimensions>
86 void 
87 BloxCoreAtomPixel<NDimensions>
88 ::CalcWeightedCoreAtomLocation(double weight_factor, Self * votingPixel)
89 {
90   // The iterator for accessing linked list info
91   typename itk::BloxCoreAtomPixel<NDimensions>::iterator bpiterator;
92   
93   PositionType center;
94
95   // Walk through all of the items in the voting pixel
96 LEN   for (bpiterator = votingPixel->begin(); bpiterator != votingPixel->end(); ++bpiterator)
97     {
98     // Get the pointer of the core atom
99     CoreAtomItemType* pCoreAtom = *bpiterator;
100
101     // Get the center of the core atom
102     center = pCoreAtom->GetCenterPosition();
103
104     m_LocationSums[0] += (center[0]*weight_factor);
105     m_LocationSums[1] += (center[1]*weight_factor);
106     m_LocationSums[2] += (center[2]*weight_factor);
107
108     m_WeightSum += weight_factor;
109     }
110 }
111
112 template <unsigned int NDimensions>
113 double 
114 BloxCoreAtomPixel<NDimensions>
115 ::CalcMeanCoreAtomDiameter()
116 {
117   // Returns a mean of 0 if there are no core atoms present
118   if( this->empty() )
119     {
120     return 0;
121     }
122
123   unsigned long int numCoreAtoms = 0;
124   m_MeanCoreAtomDiameter = 0;
125
126   // The iterator for accessing linked list info
127   typename itk::BloxCoreAtomPixel<NDimensions>::iterator bpiterator;
128   
129   // Walk through all of the items at the pixel
130   for (bpiterator = this->begin(); bpiterator != this->end(); ++bpiterator)
131     {
132     // Get the pointer of the core atom
133     CoreAtomItemType* pCoreAtom = *bpiterator;
134
135     m_MeanCoreAtomDiameter += pCoreAtom->GetDiameter();
136     
137     numCoreAtoms++;
138     }
139
140   if(numCoreAtoms>0) // Check for /0 to be safe
141 IND ****m_MeanCoreAtomDiameter /= numCoreAtoms;
142   else
143 IND ****m_MeanCoreAtomDiameter = 0;
144
145   return m_MeanCoreAtomDiameter;
146 }
147
148 template <unsigned int NDimensions>
149 bool
150 BloxCoreAtomPixel<NDimensions>
151 ::DoCoreAtomEigenanalysis()
152 {
153   // Don't attemp Eigenanalysis on an empty blox
154   if( this->empty() )
155     {
156     return false;
157     }
158
159   // The iterator for accessing linked list info
160   typename itk::BloxCoreAtomPixel<NDimensions>::iterator bpiterator;
161
162   // The number of items stored in the pixel
163   unsigned long int numItems = 0;
164
165   // Walk through all of the items at the pixel
166   for (bpiterator = this->begin(); bpiterator != this->end(); ++bpiterator)
167     {
168     // Get the pointer of the core atom
169     CoreAtomItemType* pCoreAtom = *bpiterator;
170
171     // Get the boundary points
172     BPItemType* pBPOne = pCoreAtom->GetBoundaryPointA();
173     BPItemType* pBPTwo = pCoreAtom->GetBoundaryPointB();
174     
175     // Get the physical positions of the two boundary points
176     VectorType P1;
177     P1 = pBPOne->GetPhysicalPosition().GetVnlVector();
178     
179     VectorType P2;
180     P2 = pBPTwo->GetPhysicalPosition().GetVnlVector();
181
182     // Figure out the "C" vector of the core atom
183     VectorType cVector = P2 - P1;
184     cVector.normalize();
185
186     // Now, add to m_RawCMatrix
187     for(unsigned int r = 0; r < NDimensions; r++) // row loop
188       {
189       for(unsigned int c = 0; c < NDimensions; c++) // column loop
190         {
191         m_RawCMatrix(r,c) += cVector[c]*cVector[r];
192         } // end column loop
193       } // end row loop
194
195     numItems++;
196
197     } // end walk all of the items in the pixel
198
199   // Divide through by the number of items
200   m_RawCMatrix /= numItems;
201
202   // Create an identity matrix of size n
203   vnl_matrix_fixed<double, NDimensions, NDimensions> identMatrix;
204   identMatrix.fill(0);
205
206   // Set the diagonal to 1
207   for(unsigned int n = 0; n < NDimensions; n++) // row loop
208     {
209     identMatrix(n,n) = 1.0;
210     } // end row loop
211
212   // Do eigen analysis
213 LEN   vnl_generalized_eigensystem* pEigenSys = new vnl_generalized_eigensystem(m_RawCMatrix, identMatrix);
214
215   // Now, store the results
216   
217   // First the eigenvectors
218   m_Eigenvectors = pEigenSys->V;
219
220   // Now the eigenvalues (stored as a vector to save space)
221   for(unsigned int i = 0; i < NDimensions; i++)
222     {
223     m_Eigenvalues[i] = pEigenSys->D(i,i);
224     }
225
226   delete pEigenSys;
227   return true;
228 }
229
230 template <unsigned int NDimensions>
231 typename BloxCoreAtomPixel<NDimensions>::PositionType
232 BloxCoreAtomPixel<NDimensions>
233 ::GetVotedLocation()
234 {
235   m_VotedLocation[0] = m_LocationSums[0] / m_WeightSum;
236   m_VotedLocation[1] = m_LocationSums[1] / m_WeightSum;
237   m_VotedLocation[2] = m_LocationSums[2] / m_WeightSum;
238
239   return m_VotedLocation;
240 }
241
242 template <unsigned int NDimensions>
243 void
244 BloxCoreAtomPixel<NDimensions>
245 ::CollectVote(MatrixType* pMatrix, double strength, double count)
246 {
247   m_VotedCMatrix += (*pMatrix)*strength;
248   m_ConstituencySize += count;
249 }
250
251 template <unsigned int NDimensions>
252 void
253 BloxCoreAtomPixel<NDimensions>
254 ::NormalizeVotedCMatrix()
255 {
256   if(m_ConstituencySize != 0)
257 IND ****m_VotedCMatrix /= m_ConstituencySize;
258 }
259
260 template <unsigned int NDimensions>
261 void
262 BloxCoreAtomPixel<NDimensions>
263 ::DoVotedEigenanalysis()
264 {
265   // Create an identity matrix of size n
266   vnl_matrix_fixed<double, NDimensions, NDimensions> identMatrix;
267   identMatrix.fill(0);
268
269   // Set the diagonal to 1
270   for(unsigned int n = 0; n < NDimensions; n++) // row loop
271     {
272     identMatrix(n,n) = 1.0;
273     } // end row loop
274
275   // Do eigen analysis
276 LEN   vnl_generalized_eigensystem* pEigenSys = new vnl_generalized_eigensystem(m_VotedCMatrix, identMatrix);
277
278   // Now, store the results
279   
280   // First the eigenvectors
281   m_VotedEigenvectors = pEigenSys->V;
282
283   // Now the eigenvalues (stored as a vector to save space)
284   for(unsigned int i = 0; i < NDimensions; i++)
285     {
286     m_VotedEigenvalues[i] = pEigenSys->D(i,i);
287     }
288
289   delete pEigenSys;
290
291   //printf("VotedCMatrix\n");
292   for(int i = 0; i < 3; i++)
293     {
294 LEN     //printf("%f %f %f\n", m_VotedCMatrix(i,0), m_VotedCMatrix(i,1), m_VotedCMatrix(i,2) );
295     }
296   //printf("\n");
297
298   //printf("Voted eigenvectors\n");
299   for(int i = 0; i < 3; i++)
300     {
301 LEN     //printf("%f %f %f\n", m_VotedEigenvectors(i,0), m_VotedEigenvectors(i,1), m_VotedEigenvectors(i,2) );
302     }
303   //printf("\n");
304 }
305
306 // end namespace itk
307
308 #endif
309

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