MorphoGraphX
MeshProcessHeatMap.hpp
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef MESH_PROCESS_HEAT_MAP_HPP
12 #define MESH_PROCESS_HEAT_MAP_HPP
13 
14 #include <Process.hpp>
15 
16 #include <limits>
17 
18 class Ui_LoadHeatMap;
19 
20 namespace mgx { namespace process {
21 
22  mgxBase_EXPORT void getBBox(const HVec3F& pts, Point3f* bBox);
23 
26 
32  class mgxBase_EXPORT ComputeHeatMap : public QObject, public MeshProcess {
33  Q_OBJECT
34  public:
35  ComputeHeatMap(const MeshProcess& process) : Process(process), QObject(), MeshProcess(process) {}
36 
37  bool operator()(const QStringList& parms);
38 
39  enum MapType { AREA, VOLUME, WALL };
40 
41  enum SignalType {
42  GEOMETRY = 0x1,
43  BORDER = 0x2,
44  INTERIOR = 0x4,
45  TOTAL = 0x8,
46  BORDER_TOTAL = 0x10,
47  INTERIOR_TOTAL = 0x20
48  };
49 
50  enum PolarityType { NONE, CELL_AVERAGE, WALL_MIN };
51 
52  enum MultiMapType {
53  SINGLE,
54  INCREASING_RATIO,
55  INCREASING_DIFF,
56  DECREASING_RATIO,
57  DECREASING_DIFF,
58  INCREASING_GROWTH,
59  DECREASING_GROWTH
60  };
61 
62  struct ImageHeatMaps {
63  IntFloatMap LabelGeom; // Label Areas
64  IntFloatMap LabelBordGeom; // Area of label borders
65  IntFloatMap LabelIntGeom; // Area of label interiors
66  IntFloatMap LabelTotalSig; // Label total signal
67  IntFloatMap LabelBordSig; // Label border signal
68  IntFloatMap LabelIntSig; // Label interior signal
69  IntFloatMap LabelHeatAmt; // Label HeatMap temp for change map
70  IntHVec3uMap LabelTris; // Label triangle lists
71  IntVIdSetMap LabelPts; // Label triangle list points
72 
73  IntIntFloatMap WallBordGeom; // Wall border areas
74  IntIntFloatMap WallBordSig; // Wall border signal
75  IntIntFloatMap WallHeatAmt; // Wall border signal amt for change map
76  };
77 
78  bool operator()(Mesh* mesh1, Mesh* mesh2, MapType map, SignalType signal, const QString& reportFile, int report,
79  bool manualRange, float rangeMin, float rangeMax, bool signalAverage, bool globalCoordinates,
80  PolarityType polarity, MultiMapType multiMapType, float growthTime, float borderSize);
81 
82  bool initialize(QStringList& parms, QWidget* parent);
83 
84  QString folder() const { return "Heat Map"; }
85  QString name() const { return "Heat Map"; }
86  QString description() const { return "Generate heat map for the current mesh"; }
88  {
89  return QStringList()
90  << "Type" << "Visualize" << "FileName" << "ReportFields" << "Man. Range" << "Range Min"
91  << "Range Max" << "Signal Avg" << "Global Coord" << "Polarity Type" << "Change Map"
92  << "Increasing" << "Diff Type" << "Growth Time" << QString("Border Size(%1)").arg(UM);
93  }
95  {
96  return QStringList()
97  << "Area: signal/geometry on curved surfaces,\n"
98  "Volume: for 3D only,\n"
99  "Walls: quantify signal or geometry at cell borders."
100  << "Geometry: cell areas or volume,\n"
101  "Border signal: signal associated with cell borders, within a given distance (Border Size)\n"
102  "Interior signal: total signal of a cell - border signal.\n"
103  << "Path to output file."
104  << "Options to report the following fields in spreadsheet: Geometry, Signal, Border-Interior"
105  << "Manually define the range of the color map."
106  << "Color map lower bound."
107  << "Color map upper bound."
108  << "Option to normalize the signal by cell area or volume"
109  << "Apply the rotation/translation of the stack to the cell center coordinates."
110  << "Experimental option, attempt to determine cell signal polarity based on strength of signal on "
111  "different walls.\n"
112  "Cell Average: compare each wall signal to signal average,\n"
113  "Wall/Min: compare wall signal to the weakest wall signal in the cell."
114  << "Compare two meshes with each other (deformation or change in signal) .\n"
115  << "Increasing: the current mesh is the reference (T0), the other mesh is the changed state (T1),\n"
116  "Decreasing: the other mesh is the reference (T0), the current mesh is the changed state (T1)."
117  << "Ratio: area or signal in changed state(T1) / area or signal in reference (T0),\n"
118  "Difference: area or signal in changed state(T1) - area or signal in reference (T0),\n"
119  "Growth: (Ratio -1) / growth time.\n"
120  << "Time interval between the two samples." << QString("Border Size(%1)").arg(UM);
121  }
123  {
124  return QStringList()
125  << "Area" << "Geometry" << "" << "Geometry" << "No" << "0" << "65535" << "Yes"
126  << "No" << "None" << "No" << "Yes" << "Ratio" << ".001" << "1.0";
127  }
128  QIcon icon() const { return QIcon(":/images/MakeHeatMap.png"); }
129 
130  QDialog* dlg;
131 
132  protected slots:
133  void changeMapType(const QString& type);
134  void selectSpreadsheetFile();
135 
136  protected:
137  bool getLabelMaps(ImageHeatMaps& map, Mesh* mesh);
138  MapType mapType;
139  SignalType signal;
140  int report;
141  bool manualRange;
142  float rangeMin;
143  float rangeMax;
144  bool signalAverage;
145  bool globalCoordinates;
146  PolarityType polarity;
147  bool changeMap;
148  MultiMapType multiMapType;
149  float growthTime;
150  float borderSize;
151  };
152 
158  class mgxBase_EXPORT DeleteHeatRangeLabels : public MeshProcess {
159  public:
160  DeleteHeatRangeLabels(const MeshProcess& process) : Process(process), MeshProcess(process) {}
161 
162  bool operator()(const QStringList& parms)
163  {
164  if(!checkState().mesh(MESH_NON_EMPTY))
165  return false;
166  float min, max;
167  bool ok = true;
168  if(parms[2].isEmpty())
169  min = std::numeric_limits<float>::quiet_NaN();
170  else
171  min = parms[2].toFloat(&ok);
172  if(not ok)
173  return setErrorMessage("Error, parameter 'Min Heat' must be either empty, or a number");
174  if(parms[3].isEmpty())
175  max = std::numeric_limits<float>::quiet_NaN();
176  else
177  max = parms[3].toFloat(&ok);
178  if(not ok)
179  return setErrorMessage("Error, parameter 'Min Heat' must be either empty, or a number");
180  return (*this)(currentMesh(), stringToBool(parms[0]), stringToBool(parms[1]), min, max);
181  }
182 
183  bool operator()(Mesh* mesh, bool rescale, bool deleteCells, float min, float max);
184 
185  QString folder() const { return "Heat Map"; }
186  QString name() const { return "Delete Heat Range Labels"; }
187  QString description() const { return
188  "Delete labels with heat within a given range. The heat is given relative to the total range."; }
189  QStringList parmNames() const { return QStringList()
190  << "Rescale" << "Delete cells" << "Min Heat" << "Max Heat"; }
191  QStringList parmDescs() const { return QStringList()
192  << "Redefine the lower/upper bounds of colormap to fit the range of values."
193  << "Delete vertices within a given range of the color map (Min Heat-Max Heat)."
194  << "Lower bound of color value for which the cells will be deleted (empty for current min)."
195  << "Upper bound of color value for which the cells will be deleted (empty for current max)."; }
196  QStringList parmDefaults() const { return QStringList() << "Yes" << "No" << "" << ""; }
198  {
199  ParmChoiceMap map;
200  map[0] = booleanChoice();
201  map[1] = booleanChoice();
202  return map;
203  }
204  QIcon icon() const { return QIcon(":/images/ClearStack.png"); }
205  };
206 
212  class mgxBase_EXPORT RescaleHeatMap : public MeshProcess {
213  public:
214  RescaleHeatMap(const MeshProcess& process) : Process(process), MeshProcess(process) {}
215 
216  bool operator()(const QStringList& parms)
217  {
218  if(!checkState().mesh(MESH_HEAT))
219  return false;
220  Mesh* m = currentMesh();
221  bool ok = true;
222  float min, max;
223  if(parms[0].isEmpty())
224  min = std::numeric_limits<float>::quiet_NaN();
225  else
226  min = parms[0].toFloat(&ok);
227  if(not ok)
228  return setErrorMessage("Error, parameter 'Min' must be either empty, or a number");
229  if(parms[1].isEmpty())
230  max = std::numeric_limits<float>::quiet_NaN();
231  else
232  max = parms[1].toFloat(&ok);
233  if(not ok)
234  return setErrorMessage("Error, parameter 'Max' must be either empty, or a number");
235  return (*this)(m, min, max);
236  }
237 
238  bool operator()(Mesh* m, float min, float max);
239 
240  QString folder() const { return "Heat Map"; }
241  QString name() const { return "Rescale Heat Map"; }
242  QString description() const { return "Change the range of the current heat map for display."; }
243  QStringList parmNames() const { return QStringList() << "Min" << "Max"; }
244  QStringList parmDescs() const { return QStringList()
245  << "Lower bound (empty for current)" << "Upper bound (empty for current)"; }
246  QStringList parmDefaults() const { return QStringList() << "" << ""; }
247  QIcon icon() const { return QIcon(":/images/MakeHeatMap.png"); }
248  };
249 
255  class mgxBase_EXPORT SaveHeatMap : public QObject, public MeshProcess {
256  Q_OBJECT
257  public:
258  SaveHeatMap(const MeshProcess& process) : Process(process), QObject(), MeshProcess(process) {}
259 
260  bool initialize(QStringList& parms, QWidget* parent);
261 
262  bool operator()(const QStringList& parms)
263  {
264  if(!checkState().mesh(MESH_ANY))
265  return false;
266  Mesh* m = currentMesh();
267  return (*this)(m, parms[0]);
268  }
269 
270  bool operator()(Mesh* mesh, const QString& filename);
271 
272  QString folder() const { return "Heat Map"; }
273  QString name() const { return "Save Heat Map"; }
274  QString description() const { return "Save heat map to a file"; }
275  QStringList parmNames() const { return QStringList() << "Filename"; }
276  QStringList parmDescs() const { return QStringList() << "Path to spreadsheat file."; }
277  QStringList parmDefaults() const { return QStringList() << ""; }
278  QIcon icon() const { return QIcon(":/images/MakeHeatMap.png"); }
279  };
280 
292  class mgxBase_EXPORT LoadHeatMap : public QObject, public MeshProcess {
293  Q_OBJECT
294  public:
295  LoadHeatMap(const MeshProcess& process) : Process(process) , QObject() , MeshProcess(process) {}
296 
297  bool initialize(QStringList& parms, QWidget* parent);
298 
299  bool operator()(const QStringList& parms)
300  {
301  if(!checkState().mesh(MESH_ANY))
302  return false;
303  Mesh* m = currentMesh();
304  return (*this)(m, parms[0], parms[1].toInt(), parms[2].toFloat());
305  }
306 
307  bool operator()(Mesh* mesh, const QString& filename, int column, float border_size);
308 
309  QString folder() const { return "Heat Map"; }
310  QString name() const { return "Load Heat Map"; }
311  QString description() const { return "Load a heat map file and set the corresponding heat for each label"; }
312  QStringList parmNames() const { return QStringList()
313  << "Filename" << "Column" << QString("Border size (%1)").arg(UM); }
314  QStringList parmDescs() const { return QStringList()
315  << "Path to spreadsheet file."
316  << "Column of the csv file to load for display.\n"
317  "Label: cell labels, Value: original computed values (e.g. growth or signal), Heat: "
318  "values scaled for visualization (always between 0-1)."
319  << "Width of cell outline used for vizualization of 'wall' colormaps"; }
320  QStringList parmDefaults() const { return QStringList() << "" << "2" << "1.0"; }
321  QIcon icon() const { return QIcon(":/images/MakeHeatMap.png"); }
322 
323  public slots:
324  void selectFile(const QString& filename);
325  void selectFile();
326  void selectColumn(int c);
327 
328  protected:
329  QDialog* dlg;
330  Ui_LoadHeatMap* ui;
331  QList<QString> column_unit;
332  };
333 
339  class mgxBase_EXPORT SaveParents : public MeshProcess {
340  public:
341  SaveParents(const MeshProcess& process) : Process(process), MeshProcess(process) {}
342 
343  bool initialize(QStringList& parms, QWidget* parent);
344 
345  bool operator()(const QStringList& parms)
346  {
347  if(!checkState().mesh(MESH_ANY))
348  return false;
349  Mesh* m = currentMesh();
350  return (*this)(m, parms[0]);
351  }
352 
353  bool operator()(Mesh* mesh, const QString& filename);
354 
355  QString folder() const { return "Lineage Tracking"; }
356  QString name() const { return "Save Parents"; }
357  QString description() const { return "Save map of labels to parents labels to a file"; }
358  QStringList parmNames() const { return QStringList() << "Filename"; }
359  QStringList parmDescs() const { return QStringList() << "Path to label parents file."; }
360  QStringList parmDefaults() const { return QStringList() << ""; }
361  QIcon icon() const { return QIcon(":/images/Parents.png"); }
362  };
363 
369  class mgxBase_EXPORT LoadParents : public MeshProcess {
370  public:
371  LoadParents(const MeshProcess& process) : Process(process), MeshProcess(process) {}
372 
373  bool initialize(QStringList& parms, QWidget* parent);
374 
375  bool operator()(const QStringList& parms)
376  {
377  if(!checkState().mesh(MESH_ANY))
378  return false;
379  Mesh* m = currentMesh();
380  return (*this)(m, parms[0]);
381  }
382 
383  bool operator()(Mesh* mesh, const QString& filename);
384 
385  QString folder() const { return "Lineage Tracking"; }
386  QString name() const { return "Load Parents"; }
387  QString description() const { return "Load map of labels to parents from a file"; }
388  QStringList parmNames() const { return QStringList() << "Filename"; }
389  QStringList parmDescs() const { return QStringList() << "Path to label parents file."; }
390  QStringList parmDefaults() const { return QStringList() << ""; }
391  QIcon icon() const { return QIcon(":/images/Parents.png"); }
392  };
393 
397  class mgxBase_EXPORT ResetParents : public MeshProcess {
398  public:
399  ResetParents(const MeshProcess& process) : Process(process), MeshProcess(process) {}
400 
401  bool operator()(const QStringList&)
402  {
403  if(!checkState().mesh(MESH_ANY))
404  return false;
405  Mesh* m = currentMesh();
406  return (*this)(m);
407  }
408 
409  bool operator()(Mesh* mesh);
410 
411  QString folder() const { return "Lineage Tracking"; }
412  QString name() const { return "Clear Parents"; }
413  QString description() const { return "Clear mapping from parents to labels"; }
414  QStringList parmNames() const { return QStringList(); }
415  QStringList parmDescs() const { return QStringList(); }
416  QIcon icon() const { return QIcon(":/images/Parents.png"); }
417  };
419 }}
420 
421 #endif
Definition: MeshProcessHeatMap.hpp:62
QString name() const
Returns the name of the process.
Definition: MeshProcessHeatMap.hpp:412
QString folder() const
Folder in which to place the process.
Definition: MeshProcessHeatMap.hpp:411
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MeshProcessHeatMap.hpp:278
std::map< int, HVec3U > IntHVec3uMap
Map of an integer to a host vector of 3 unsigned integers.
Definition: Mesh.hpp:78
QString description() const
Returns a description of the process for the GUI.
Definition: MeshProcessHeatMap.hpp:387
QString folder() const
Folder in which to place the process.
Definition: MeshProcessHeatMap.hpp:84
QStringList parmNames() const
List of named parameters.
Definition: MeshProcessHeatMap.hpp:414
QString description() const
Returns a description of the process for the GUI.
Definition: MeshProcessHeatMap.hpp:413
QStringList parmNames() const
List of named parameters.
Definition: MeshProcessHeatMap.hpp:243
QStringList parmDescs() const
List of parameters descriptions.
Definition: MeshProcessHeatMap.hpp:191
std::map< IntIntPair, float > IntIntFloatMap
Map of a pair of integers to a float.
Definition: Mesh.hpp:122
arg(const QString &a, int fieldWidth=0, const QChar &fillChar=QLatin1Char( ' ')
std::map< int, float > IntFloatMap
Map of an integer to a float.
Definition: Mesh.hpp:68
QStringList parmDescs() const
List of parameters descriptions.
Definition: MeshProcessHeatMap.hpp:389
QStringList parmDefaults() const
List of default parms.
Definition: MeshProcessHeatMap.hpp:196
Rescale the heat map, specifying new lower and upper bound.
Definition: MeshProcessHeatMap.hpp:212
QString description() const
Returns a description of the process for the GUI.
Definition: MeshProcessHeatMap.hpp:357
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: MeshProcessHeatMap.hpp:299
QString description() const
Returns a description of the process for the GUI.
Definition: MeshProcessHeatMap.hpp:311
Save the current heat map in a CSV file.
Definition: MeshProcessHeatMap.hpp:255
QString name() const
Returns the name of the process.
Definition: MeshProcessHeatMap.hpp:386
Store mapping from each label to a label in a different mesh (parent).
Definition: MeshProcessHeatMap.hpp:339
Compute heat map on the current mesh.
Definition: MeshProcessHeatMap.hpp:32
QString folder() const
Folder in which to place the process.
Definition: MeshProcessHeatMap.hpp:240
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MeshProcessHeatMap.hpp:361
QStringList parmDescs() const
List of parameters descriptions.
Definition: MeshProcessHeatMap.hpp:359
QString folder() const
Folder in which to place the process.
Definition: MeshProcessHeatMap.hpp:272
QString name() const
Returns the name of the process.
Definition: MeshProcessHeatMap.hpp:310
QString name() const
Returns the name of the process.
Definition: MeshProcessHeatMap.hpp:273
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MeshProcessHeatMap.hpp:204
QStringList parmNames() const
List of named parameters.
Definition: MeshProcessHeatMap.hpp:312
QStringList parmNames() const
List of named parameters.
Definition: MeshProcessHeatMap.hpp:189
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MeshProcessHeatMap.hpp:247
QString folder() const
Folder in which to place the process.
Definition: MeshProcessHeatMap.hpp:355
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: MeshProcessHeatMap.hpp:345
QString description() const
Returns a description of the process for the GUI.
Definition: MeshProcessHeatMap.hpp:86
QStringList parmDefaults() const
List of default parms.
Definition: MeshProcessHeatMap.hpp:277
QStringList parmDescs() const
List of parameters descriptions.
Definition: MeshProcessHeatMap.hpp:276
QString name() const
Returns the name of the process.
Definition: MeshProcessHeatMap.hpp:356
std::map< int, VIdSet > IntVIdSetMap
Map of an integer to a set of vertex ids.
Definition: Mesh.hpp:98
This class holds the actual mesh as a VV Graph and all sort of properties for it, including visualiza...
Definition: Mesh.hpp:177
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MeshProcessHeatMap.hpp:128
QString folder() const
Folder in which to place the process.
Definition: MeshProcessHeatMap.hpp:185
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MeshProcessHeatMap.hpp:391
QStringList parmDescs() const
List of parameters descriptions.
Definition: MeshProcessHeatMap.hpp:94
Load the heat map from a CSV file.
Definition: MeshProcessHeatMap.hpp:292
QString folder() const
Folder in which to place the process.
Definition: MeshProcessHeatMap.hpp:385
Load mapping from each label to a label in a different mesh (parent).
Definition: MeshProcessHeatMap.hpp:369
QStringList parmDefaults() const
List of default parms.
Definition: MeshProcessHeatMap.hpp:320
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26
QStringList parmDescs() const
List of parameters descriptions.
Definition: MeshProcessHeatMap.hpp:244
QString name() const
Returns the name of the process.
Definition: MeshProcessHeatMap.hpp:186
QStringList parmNames() const
List of named parameters.
Definition: MeshProcessHeatMap.hpp:388
File containing the definition of a Process.
ParmChoiceMap parmChoice() const
Purely for GUI purposes, provides for some of the parms parameter a choice.
Definition: MeshProcessHeatMap.hpp:197
QStringList parmDefaults() const
List of default parms.
Definition: MeshProcessHeatMap.hpp:390
QStringList parmNames() const
List of named parameters.
Definition: MeshProcessHeatMap.hpp:87
This is the main process class, the one all process inherit from.
Definition: Process.hpp:258
QString name() const
Returns the name of the process.
Definition: MeshProcessHeatMap.hpp:85
mgx_EXPORT bool stringToBool(const QString &string)
Helper function converting a string into a boolean.
This namespace contains all the classes needed to define processes.
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MeshProcessHeatMap.hpp:416
QStringList parmDescs() const
List of parameters descriptions.
Definition: MeshProcessHeatMap.hpp:314
bool operator()(const QStringList &)
Implementation of the process with generic arguments.
Definition: MeshProcessHeatMap.hpp:401
QStringList parmNames() const
List of named parameters.
Definition: MeshProcessHeatMap.hpp:275
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: MeshProcessHeatMap.hpp:262
QStringList parmNames() const
List of named parameters.
Definition: MeshProcessHeatMap.hpp:358
QStringList parmDefaults() const
List of default parms.
Definition: MeshProcessHeatMap.hpp:360
QStringList parmDefaults() const
List of default parms.
Definition: MeshProcessHeatMap.hpp:122
QString description() const
Returns a description of the process for the GUI.
Definition: MeshProcessHeatMap.hpp:187
QString description() const
Returns a description of the process for the GUI.
Definition: MeshProcessHeatMap.hpp:242
QString folder() const
Folder in which to place the process.
Definition: MeshProcessHeatMap.hpp:309
QStringList parmDefaults() const
List of default parms.
Definition: MeshProcessHeatMap.hpp:246
QString name() const
Returns the name of the process.
Definition: MeshProcessHeatMap.hpp:241
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MeshProcessHeatMap.hpp:321
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: MeshProcessHeatMap.hpp:216
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: MeshProcessHeatMap.hpp:162
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: MeshProcessHeatMap.hpp:375
QString description() const
Returns a description of the process for the GUI.
Definition: MeshProcessHeatMap.hpp:274
Clear label to parent mapping.
Definition: MeshProcessHeatMap.hpp:397
QStringList parmDescs() const
List of parameters descriptions.
Definition: MeshProcessHeatMap.hpp:415
Mesh processes have mutable access to meshes and non-mutable access to stacks.
Definition: Process.hpp:865
Delete labeling, and possibly cells, if their heat falls within a defined range.
Definition: MeshProcessHeatMap.hpp:158