Shapeworks Studio  2.1
Shape analysis software suite
itkParticleShapeStatistics.h
1 /*=========================================================================
2  Program: ShapeWorks: Particle-based Shape Correspondence & Visualization
3  Module: $RCSfile: itkParticleShapeStatistics.h,v $
4  Date: $Date: 2011/03/24 01:17:41 $
5  Version: $Revision: 1.3 $
6  Author: $Author: wmartin $
7 
8  Copyright (c) 2009 Scientific Computing and Imaging Institute.
9  See ShapeWorksLicense.txt for details.
10 
11  This software is distributed WITHOUT ANY WARRANTY; without even
12  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13  PURPOSE. See the above copyright notices for more information.
14  =========================================================================*/
15 #ifndef _ParticleShapeStatistics_h
16 #define _ParticleShapeStatistics_h
17 
18 #include <iostream>
19 #include <vector>
20 #include "vnl/vnl_vector.h"
21 #include "vnl/algo/vnl_symmetric_eigensystem.h"
22 #include "vnl/vnl_matrix.h"
23 #include "itkParticlePositionReader.h"
24 #include "vnl/vnl_vector_fixed.h"
25 #include "vnl/algo/vnl_matrix_inverse.h"
26 #include <iostream>
27 #include <fstream>
28 #include <string>
29 #include <cstdio>
30 #include "itkParticlePositionWriter.h"
31 
37 template <unsigned int VDimension = 3>
38 class ITK_EXPORT ParticleShapeStatistics
39 {
40 public:
43 
45  itkStaticConstMacro( Dimension, unsigned int, VDimension );
46 
48  int ImportPoints( std::vector<vnl_vector<double> > points );
49 
51  int ReadPointFiles( const char* fname );
52 
54  int ReloadPointFiles();
55 
58  int WriteCSVFile( const char* s );
59  int WriteCSVFile( const std::string &s )
60  { return this->WriteCSVFile( s.c_str() ); }
61  int WriteCSVFile2( const char* s );
62  int WriteCSVFile2( const std::string &s )
63  { return this->WriteCSVFile2( s.c_str() ); }
64 
67  int ComputeModes();
68 
72  int PrincipalComponentProjections();
73 
75  int FisherLinearDiscriminant( unsigned int );
76 
78  inline int SampleSize() const
79  { return m_numSamples; }
80  inline int Group1SampleSize() const
81  { return m_numSamples1; }
82  inline int Group2SampleSize() const
83  { return m_numSamples2; }
84 
86  inline int NumberOfDimensions() const
87  { return m_numDimensions; }
88 
90  inline int GroupID( unsigned int i ) const
91  { return m_groupIDs[i]; }
92  const std::vector<int> &GroupID() const
93  { return m_groupIDs; }
94 
96  const vnl_matrix<double> &Eigenvectors() const
97  { return m_eigenvectors; }
98  const vnl_vector<double> &Eigenvalues() const
99  { return m_eigenvalues; }
100 
102  const vnl_vector<double> &Mean() const
103  { return m_mean; }
104  const vnl_vector<double> &Group1Mean() const
105  { return m_mean1; }
106  const vnl_vector<double> &Group2Mean() const
107  { return m_mean2; }
108 
109  // Returns group2 - group1 mean
110  const vnl_vector<double> &NormalizedGroupDifference() const
111  { return m_groupdiffnorm; }
112  const vnl_vector<double> &GroupDifference() const
113  { return m_groupdiff; }
114 
122  int ComputeMedianShape( const int );
123 
125  double L1Norm( unsigned int a, unsigned int b );
126 
128  const vnl_matrix<double> &PCALoadings() const
129  { return m_principals; }
130 
132  const vnl_vector<double> &FishersLDA() const
133  { return m_fishersLD; }
134 
136  const vnl_matrix<double> &ShapeMatrix() const
137  {return m_shapes; }
138 
139  const vnl_vector<double> &Shape( unsigned int i ) const
140  { return m_shapes.get_column( i ); }
141 
145  int SimpleLinearRegression( const std::vector<double> &y,
146  const std::vector<double> &x,
147  double &a, double &b ) const;
148 
149 protected:
150  unsigned int m_numSamples1;
151  unsigned int m_numSamples2;
152  unsigned int m_numSamples;
153  unsigned int m_domainsPerShape;
154  unsigned int m_numDimensions;
155  std::vector<int> m_groupIDs;
156 
157  vnl_matrix<double> m_pooled_covariance;
158  vnl_matrix<double> m_eigenvectors;
159  vnl_vector<double> m_eigenvalues;
160  vnl_vector<double> m_mean;
161  vnl_vector<double> m_mean1;
162  vnl_vector<double> m_mean2;
163  vnl_matrix<double> m_pointsMinusMean;
164  vnl_matrix<double> m_shapes;
165  vnl_matrix<double> m_projectedPMM1;
166  vnl_matrix<double> m_projectedPMM2;
167  vnl_vector<double> m_projectedMean1;
168  vnl_vector<double> m_projectedMean2;
169  std::vector<double> m_fishersProjection;
170  std::vector<double> m_percentVarByMode;
171  vnl_vector<double> m_fishersLD;
172  int m_top95;
173  vnl_matrix<double> m_principals;
174 
175  vnl_vector<double> m_groupdiff;
176  vnl_vector<double> m_groupdiffnorm;
177 
178  // used to keep the points' files that needs to be reloaded when new updates come in.
179  std::vector< std::string > m_pointsfiles;
180 };
181 
182 #if ITK_TEMPLATE_EXPLICIT
183 # include "Templates/itkParticleShapeStatistics+-.h"
184 #endif
185 
186 #if ITK_TEMPLATE_TXX
187 # include "itkParticleShapeStatistics.txx"
188 #endif
189 
190 #endif // ifndef _ParticleShapeStatistics_h
const vnl_matrix< double > & ShapeMatrix() const
const vnl_matrix< double > & PCALoadings() const
const vnl_vector< double > & Mean() const
int GroupID(unsigned int i) const
Representation of a single shape/patient.
Definition: Shape.h:21
const vnl_matrix< double > & Eigenvectors() const
const vnl_vector< double > & FishersLDA() const