MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PCAnalysis.hpp
1 #ifndef PCAnalysis_HPP
2 #define PCAnalysis_HPP
3 
4 #include <Process.hpp>
5 
6 #include <Information.hpp>
7 
8 #include <QRegExp>
9 #include <QString>
10 #include <QStringList>
11 
12 namespace mgx {
13 namespace process {
14 
23 class PCAnalysis : public GlobalProcess {
24 public:
25  PCAnalysis(const GlobalProcess& process)
26  : Process(process)
27  , GlobalProcess(process)
28  {
29  }
30 
31  bool operator()(const QStringList& parms)
32  {
33  if(!checkState().stack())
34  return false;
35  Stack* stk = currentStack();
36  Store* store = stk->currentStore();
37  QString fn = parms[0];
38  QString correction = parms[1].trimmed();
39  Point3f correcting_factor;
40  if(correction == "Ellipsoid")
41  correcting_factor = sqrt(5);
42  else if(correction == "Cuboid")
43  correcting_factor = sqrt(3);
44  else if(correction == "Elliptical Cylinder")
45  correcting_factor = Point3f(sqrt(3), sqrt(4), sqrt(4));
46  else if(correction == "Maximum Span")
47  correcting_factor = 0;
48  else if(correction.endsWith('%')) {
49  QString cor = correction.left(correction.size() - 1);
50  bool ok;
51  float cr = cor.toFloat(&ok);
52  if(ok) {
53  correcting_factor = -cr / 100.f;
54  } else {
55  setErrorMessage(QString("Error, percentage value is not valid: '%1'").arg(cor));
56  return false;
57  }
58  } else {
59  bool ok;
60  float cr = correction.toFloat(&ok);
61  if(ok)
62  correcting_factor = cr;
63  else {
64  QStringList vs = correction.split(QRegExp("[ ,-;:-]"));
65  if(vs.size() == 3) {
66  correcting_factor.x() = vs[0].toFloat(&ok);
67  if(!ok) {
68  setErrorMessage(QString("Invalid x value for correction factor: '%1'.").arg(vs[0]));
69  return false;
70  }
71  correcting_factor.y() = vs[1].toFloat(&ok);
72  if(!ok) {
73  setErrorMessage(QString("Invalid y value for correction factor: '%1'.").arg(vs[1]));
74  return false;
75  }
76  correcting_factor.z() = vs[2].toFloat(&ok);
77  if(!ok) {
78  setErrorMessage(QString("Invalid z value for correction factor: '%1'.").arg(vs[2]));
79  return false;
80  }
81  } else {
82  setErrorMessage(QString("Invalid correction string '%1', expected one of 'Ellipsoid'"
83  ", 'Cuboid', 'Elliptical Cylinder', Maximum Span', a percentage, a single "
84  "value or three values"));
85  return false;
86  }
87  }
88  }
89  bool draw_result = false;
90  bool res
91  = operator()(stk, store, fn, parms[3].toInt(), parms[2], correcting_factor, parms[4].toInt(), draw_result);
92  if(res and draw_result) {
93  Mesh* m = mesh(stk->id());
94  m->showSurface();
95  m->showLabel();
96  }
97  return res;
98  }
99 
114  bool operator()(Stack* stack, Store* store, QString filename, int treshold, QString shape,
115  Point3f correcting_factor, int slices, bool& draw_result);
116 
117  QString folder() const {
118  return "Shape Analysis";
119  }
120  QString name() const {
121  return "PCAnalysis";
122  }
124  {
125  return "Compute the principle components of the image. If the threshold is -1, then all the values are used, \n"
126  "as is. If 'Draw Result' is set to true, the current mesh will be erased and replaced with shapes \n"
127  "representing the cells fit. 'Splan Correction' can be either a shape, a single value of a vector \n"
128  "of 3 values, corresponding to the correction to apply for the eigen-values on all three directions.";
129  }
131  {
132  return QStringList() << "Output"
133  << "Span Correction"
134  << "Draw Result"
135  << "Threshold"
136  << "Shape Details";
137  }
139  {
140  return QStringList() << "File to write the output to"
141  << "Span correction can be made using pre-computed formula for regular shapes, or a "
142  "percentage of the PC."
143  << "Shape used to display the result"
144  << "If the stack is not labeled, a single volume is considered with all voxels of "
145  "intensity greater than this threshold."
146  << "How finely to draw the shape (for cylinders or ellipsoids)";
147  }
149  {
150  return QStringList() << "output.csv"
151  << "Ellipsoid"
152  << "No"
153  << "100"
154  << "3";
155  }
157  {
158  ParmChoiceMap map;
159  map[1] = QStringList() << "Ellipsoid"
160  << "Cuboid"
161  << "Elliptical Cylinder"
162  << "Maximum Span";
163  map[2] = QStringList() << "No"
164  << "Ellipsoids"
165  << "Cuboids"
166  << "Cylinder";
167  return map;
168  }
169  QIcon icon() const {
170  return QIcon(":/images/PCAnalysis.png");
171  }
172 };
173 } // namespace process
174 } // namespace mgx
175 
176 #endif // PCAnalysis_HPP
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: PCAnalysis.hpp:169
void showSurface()
Show the surface to the user.
Definition: Mesh.hpp:791
QString folder() const
Folder in which to place the process.
Definition: PCAnalysis.hpp:117
int id() const
Id of a stack.
Definition: Stack.hpp:49
split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive)
const Store * currentStore() const
Returns the current store.
Definition: Stack.hpp:112
CU_HOST_DEVICE void x(const T &v)
Short access to the first element.
Definition: Vector.hpp:651
Process()
Default constructor.
QStringList parmDescs() const
List of parameters descriptions.
Definition: PCAnalysis.hpp:138
CheckState checkState()
Call this function and convert the result to a boolean.
The Store class holds the actual 3D data and properties specific to it.
Definition: Store.hpp:25
This class holds the actual mesh as a VV Graph and all sort of properties for it, including visualiza...
Definition: Mesh.hpp:167
endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive)
CU_HOST_DEVICE void y(const T &v)
Short access to the second element.
Definition: Vector.hpp:660
bool setErrorMessage(const QString &str)
Set an error message that will be displayed if the process returns false.
QStringList parmDefaults() const
List of default parms.
Definition: PCAnalysis.hpp:148
void showLabel()
Show the labels of the surface triangles.
Definition: Mesh.hpp:810
QString name() const
Returns the name of the process.
Definition: PCAnalysis.hpp:120
File containing the definition of a Process.
The Stack class represent the dimensions of the 3D data, and the frames transformations.
Definition: Stack.hpp:25
QStringList parmNames() const
List of named parameters.
Definition: PCAnalysis.hpp:130
Global processes have full mutable access to all properties of the process.
Definition: Process.hpp:894
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: PCAnalysis.hpp:31
CU_HOST_DEVICE void z(const T &v)
Short access to the third element.
Definition: Vector.hpp:669
ParmChoiceMap parmChoice() const
Purely for GUI purposes, provides for some of the parms parameter a choice.
Definition: PCAnalysis.hpp:156
toFloat(bool *ok=0)
left(int n)
QString description() const
Returns a description of the process for the GUI.
Definition: PCAnalysis.hpp:123
Perform a PCA on each labeled regions of the segmented stack, and create shapes in the mesh reflectin...
Definition: PCAnalysis.hpp:23