MorphoGraphX
MeshProcessSegmentation.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_SEGMENTATION_HPP
12 #define MESH_PROCESS_SEGMENTATION_HPP
13 
14 #include <Process.hpp>
15 
16 class Ui_LoadHeatMap;
17 
18 namespace mgx {
19 namespace process {
22 
30 class mgxBase_EXPORT SegmentMesh : public MeshProcess {
31 public:
33  : Process(process)
34  , MeshProcess(process)
35  {
36  }
37 
38  bool operator()(const QStringList& parms)
39  {
40  if(!checkState().mesh())
41  return false;
42  return (*this)(currentMesh(), parms[0].toUInt(), currentMesh()->activeVertices());
43  }
44 
45  bool operator()(Mesh* mesh, uint maxsteps, const std::vector<vertex>& to_segment);
46 
47  QString folder() const {
48  return "Segmentation";
49  }
50  QString name() const {
51  return "Watershed Segmentation";
52  }
53  QString description() const {
54  return "Propagate labels on mesh using the watershed algorithm.";
55  }
57  return QStringList() << "Steps";
58  }
60  {
61  return QStringList() << "Number of propagation steps performed before updating display. "
62  "Increase value to run faster.";
63  }
65  return QStringList() << "20000";
66  }
67  QIcon icon() const {
68  return QIcon(":/images/SegmentMesh.png");
69  }
70 };
71 
77 class mgxBase_EXPORT SegmentClear : public MeshProcess {
78 public:
80  : Process(process)
81  , MeshProcess(process)
82  {
83  }
84 
85  bool operator()(const QStringList&)
86  {
87  if(!checkState().mesh())
88  return false;
89  return (*this)(currentMesh());
90  }
91 
92  bool operator()(Mesh* mesh);
93 
94  QString folder() const {
95  return "Segmentation";
96  }
97  QString name() const {
98  return "Segmentation Clear";
99  }
101  return "Clean all mesh labels.";
102  }
104  return QStringList();
105  }
107  return QStringList();
108  }
109  QIcon icon() const {
110  return QIcon(":/images/SegmentClear.png");
111  }
112 };
113 
122 class mgxBase_EXPORT MeshRelabel : public MeshProcess {
123 public:
125  : Process(process)
126  , MeshProcess(process)
127  {
128  }
129 
130  bool operator()(const QStringList& parms)
131  {
132  if(!checkState().mesh(MESH_NON_EMPTY | MESH_LABEL))
133  return false;
134  Mesh* m = currentMesh();
135  int start = parms[0].toInt();
136  int step = parms[1].toInt();
137  return (*this)(m, start, step);
138  }
139 
140  bool operator()(Mesh* m, int start, int step);
141 
142  QString folder() const {
143  return "Segmentation";
144  }
145  QString name() const {
146  return "Relabel";
147  }
149  return "Relabel a mesh randomly to use consecutive labels.";
150  }
152  {
153  return QStringList() << "Label Start"
154  << "Label Step";
155  }
157  {
158  return QStringList() << "Starting label."
159  << "Increment step.";
160  }
162  {
163  return QStringList() << "1"
164  << "1";
165  }
166  QIcon icon() const {
167  return QIcon(":/images/Relabel.png");
168  }
169 };
170 
176 class mgxBase_EXPORT GrabLabelsSegment : public MeshProcess {
177 public:
179  : Process(process)
180  , MeshProcess(process)
181  {
182  }
183 
184  bool operator()(const QStringList& parms)
185  {
186  if(!checkState().mesh(MESH_NON_EMPTY, 0).mesh(MESH_NON_EMPTY, 1))
187  return false;
188 
189  Mesh* mesh1, *mesh2;
190  if(currentMesh() == mesh(0)) {
191  mesh1 = mesh(0);
192  mesh2 = mesh(1);
193  } else if(currentMesh() == mesh(1)) {
194  mesh2 = mesh(0);
195  mesh1 = mesh(1);
196  } else
197  return false;
198 
199  bool res = (*this)(mesh1, mesh2, parms[0].toFloat());
200  return res;
201  }
202 
203  bool operator()(Mesh* mesh1, Mesh* mesh2, float tolerance);
204 
205  QString name() const {
206  return "3D Grab Labels";
207  }
209  return "Grab labels from other mesh (3D meshes).";
210  }
211  QString folder() const {
212  return "Segmentation";
213  }
215  return QStringList() << QString("Tolerance (%1)").arg(UM);
216  }
218  return QStringList() << "Maximal distance between matching cells. ";
219  }
221  return QStringList() << "5.0";
222  }
223  QIcon icon() const {
224  return QIcon(":/images/GrabLabels.png");
225  }
226 };
227 
233 class mgxBase_EXPORT LabelSelected : public MeshProcess {
234 public:
236  : Process(process)
237  , MeshProcess(process)
238  {
239  }
240 
241  bool operator()(const QStringList& parms)
242  {
243  if(!checkState().mesh(MESH_LABEL))
244  return false;
245  return (*this)(currentMesh(), parms[0].toInt());
246  }
247 
248  bool operator()(Mesh* mesh, int label);
249 
250  QString folder() const {
251  return "Segmentation";
252  }
253  QString name() const {
254  return "Label Selected Vertices";
255  }
257  return "Label selected vertices with the same value, which can be a new label";
258  }
260  return QStringList() << "Label";
261  }
263  return QStringList() << "Asign this label to all selected vertices.";
264  }
266  return QStringList() << "0";
267  }
268  QIcon icon() const {
269  return QIcon(":/images/LabelSelected.png");
270  }
271 };
272 
278 class mgxBase_EXPORT RelabelCells3D : public MeshProcess {
279 public:
281  : Process(process)
282  , MeshProcess(process)
283  {
284  }
285 
286  bool operator()(const QStringList& parms)
287  {
288  if(!checkState().mesh(MESH_NON_EMPTY))
289  return false;
290  Mesh* mesh = currentMesh();
291  bool res = (*this)(mesh, parms[0].toInt(), parms[1].toInt());
292  if(res)
293  mesh->showLabel();
294  return res;
295  }
296 
297  bool operator()(Mesh* mesh, int label_start, int label_step);
298 
299  QString folder() const {
300  return "Segmentation";
301  }
302  QString name() const {
303  return "Relabel 3D Cells";
304  }
306  {
307  return "Relabel 3D cells (connected regions)."
308  " A start label of -1 is used to indicate continuing using current labels.";
309  }
311  {
312  return QStringList() << "Label start"
313  << "Label step";
314  }
316  {
317  return QStringList() << "Starting label. Use -1 to continue from last current label."
318  << "Increment step.";
319  }
321  {
322  return QStringList() << "-1"
323  << "1";
324  }
325  QIcon icon() const {
326  return QIcon(":/images/CellFiles3D.png");
327  }
328 };
329 
336 public:
338  : Process(process)
339  , MeshProcess(process)
340  {
341  }
342 
343  bool operator()(const QStringList& parms)
344  {
345  if(!checkState().mesh(MESH_NON_EMPTY))
346  return false;
347  return (*this)(currentMesh(), parms[0].toFloat(), parms[1].toFloat());
348  }
349 
350  bool operator()(Mesh* mesh, float borderDist, float Difference);
351 
352  QString folder() const {
353  return "Segmentation";
354  }
355  QString name() const {
356  return "Combine Labels";
357  }
359  return "Combine over-segmented regions, based on mesh signal.";
360  }
362  return QStringList() << QString("Border Distance (%1)").arg(UM) << "Threshold";
363  }
365  {
366  return QStringList() << "Half of the cell border width on the mesh."
367  << "Ratio of border signal over internal signal. If a border between 2 cells "
368  "has a ratio below the threshold, the cells are fused.";
369  }
371  {
372  return QStringList() << "1"
373  << "1.5";
374  }
375  QIcon icon() const {
376  return QIcon(":/images/Merge.png");
377  }
378 };
379 
386 class MeshAutoSegment : public MeshProcess {
387 public:
389  : Process(process)
390  , MeshProcess(process)
391  {
392  }
393 
394  bool operator()(const QStringList& parms)
395  {
396  if(!checkState().mesh(MESH_NON_EMPTY))
397  return false;
398  return (*this)(currentMesh(), stringToBool(parms[0]), stringToBool(parms[1]), parms[2].toFloat(),
399  parms[3].toFloat(), parms[4].toFloat(), parms[5].toFloat(), parms[6].toFloat(),
400  parms[7].toFloat());
401  }
402 
403  bool operator()(Mesh* mesh, bool updateView, bool normalize, float gaussianRadiusCell, float localMinimaRadius,
404  float gaussianRadiusWall, float normalizeRadius, float borderDist, float threshold);
405 
406  QString folder() const {
407  return "Segmentation";
408  }
409  QString name() const {
410  return "Auto-Segmentation";
411  }
413  {
414  return "Auto-Segmentation of the mesh surface based on signal. Combines blurring, auto-seeding, "
415  "label propagation by watershed and fusion of over-segmented cells.";
416  }
418  {
419  return QStringList() << "Update"
420  << "Normalize" << QString("Blur Cell Radius (%1)").arg(UM)
421  << QString("Auto-Seed Radius (%1)").arg(UM) << QString("Blur Borders Radius (%1)").arg(UM)
422  << QString("Normalization Radius (%1)").arg(UM) << QString("Border Distance (%1)").arg(UM)
423  << "Combine Threshold";
424  }
426  {
427  return QStringList()
428  << "Option to update mesh drawing while running processes."
429  << "Option to normalize mesh signal before merging the cells. Most usefull in case of low contrast mesh "
430  "signal."
431  << "Radius used for gaussian blur of mesh signal. In normal cases, should be equal to auto-seed radius."
432  << "Radius used for auto-seeding the mesh, based on local minima of signal. Should be equal to radius "
433  "of smallest cells."
434  << "Radius used for gaussian blur of signal on cell borders before watershed segmentation. Use small "
435  "values (roughly, half the border width) to avoid border signal distortion."
436  << "Radius used for local normalization of signal. Roughly, radius of largest cells."
437  << "Half of the cell border width after blurring. Used for fusion of over-segmented cells."
438  << "Ratio of border signal over internal signal. If a borders between 2 cells have a ratio below the "
439  "threshold, the cells are fused.";
440  }
442  {
443  return QStringList() << "Yes"
444  << "Yes"
445  << "2.0"
446  << "2.0"
447  << "1"
448  << "5.0"
449  << "1.0"
450  << "1.8";
451  }
453  {
454  ParmChoiceMap map;
455  map[0] = booleanChoice();
456  map[1] = booleanChoice();
457  return map;
458  }
459  QIcon icon() const {
460  return QIcon(":/images/SegmentMesh.png");
461  }
462 };
464 } // namespace process
465 } // namespace mgx
466 
467 #endif
QStringList parmDefaults() const
List of default parms.
Definition: MeshProcessSegmentation.hpp:220
QStringList parmNames() const
List of named parameters.
Definition: MeshProcessSegmentation.hpp:310
QString folder() const
Folder in which to place the process.
Definition: MeshProcessSegmentation.hpp:211
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: MeshProcessSegmentation.hpp:38
Relabel 3D cells.
Definition: MeshProcessSegmentation.hpp:278
QStringList parmDefaults() const
List of default parms.
Definition: MeshProcessSegmentation.hpp:64
QString folder() const
Folder in which to place the process.
Definition: MeshProcessSegmentation.hpp:406
QString folder() const
Folder in which to place the process.
Definition: MeshProcessSegmentation.hpp:299
QString name() const
Returns the name of the process.
Definition: MeshProcessSegmentation.hpp:50
arg(const QString &a, int fieldWidth=0, const QChar &fillChar=QLatin1Char( ' ')
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MeshProcessSegmentation.hpp:67
QString name() const
Returns the name of the process.
Definition: MeshProcessSegmentation.hpp:355
QStringList parmNames() const
List of named parameters.
Definition: MeshProcessSegmentation.hpp:361
QStringList parmDefaults() const
List of default parms.
Definition: MeshProcessSegmentation.hpp:161
QString folder() const
Folder in which to place the process.
Definition: MeshProcessSegmentation.hpp:142
ParmChoiceMap parmChoice() const
Purely for GUI purposes, provides for some of the parms parameter a choice.
Definition: MeshProcessSegmentation.hpp:452
QString description() const
Returns a description of the process for the GUI.
Definition: MeshProcessSegmentation.hpp:100
QString folder() const
Folder in which to place the process.
Definition: MeshProcessSegmentation.hpp:352
QStringList parmDescs() const
List of parameters descriptions.
Definition: MeshProcessSegmentation.hpp:217
QString description() const
Returns a description of the process for the GUI.
Definition: MeshProcessSegmentation.hpp:148
QStringList parmDefaults() const
List of default parms.
Definition: MeshProcessSegmentation.hpp:441
bool operator()(const QStringList &)
Implementation of the process with generic arguments.
Definition: MeshProcessSegmentation.hpp:85
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: MeshProcessSegmentation.hpp:130
Combine over-segmented regions, based on mesh signal.
Definition: MeshProcessSegmentation.hpp:335
QString folder() const
Folder in which to place the process.
Definition: MeshProcessSegmentation.hpp:250
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: MeshProcessSegmentation.hpp:343
QStringList parmDescs() const
List of parameters descriptions.
Definition: MeshProcessSegmentation.hpp:106
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: MeshProcessSegmentation.hpp:184
QString description() const
Returns a description of the process for the GUI.
Definition: MeshProcessSegmentation.hpp:305
QString description() const
Returns a description of the process for the GUI.
Definition: MeshProcessSegmentation.hpp:412
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MeshProcessSegmentation.hpp:166
QString description() const
Returns a description of the process for the GUI.
Definition: MeshProcessSegmentation.hpp:256
This class holds the actual mesh as a VV Graph and all sort of properties for it, including visualiza...
Definition: Mesh.hpp:177
QString name() const
Returns the name of the process.
Definition: MeshProcessSegmentation.hpp:253
QString description() const
Returns a description of the process for the GUI.
Definition: MeshProcessSegmentation.hpp:208
QStringList parmNames() const
List of named parameters.
Definition: MeshProcessSegmentation.hpp:417
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MeshProcessSegmentation.hpp:268
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MeshProcessSegmentation.hpp:325
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26
Segment the mesh using a seeded watershed algorithm.
Definition: MeshProcessSegmentation.hpp:30
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: MeshProcessSegmentation.hpp:394
QStringList parmDescs() const
List of parameters descriptions.
Definition: MeshProcessSegmentation.hpp:364
QStringList parmDescs() const
List of parameters descriptions.
Definition: MeshProcessSegmentation.hpp:59
Change the label of the selected vertices.
Definition: MeshProcessSegmentation.hpp:233
QString name() const
Returns the name of the process.
Definition: MeshProcessSegmentation.hpp:145
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MeshProcessSegmentation.hpp:223
QStringList parmNames() const
List of named parameters.
Definition: MeshProcessSegmentation.hpp:56
File containing the definition of a Process.
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MeshProcessSegmentation.hpp:375
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: MeshProcessSegmentation.hpp:241
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: MeshProcessSegmentation.hpp:286
Remove any segmentation from the current mesh.
Definition: MeshProcessSegmentation.hpp:77
QStringList parmDescs() const
List of parameters descriptions.
Definition: MeshProcessSegmentation.hpp:315
This is the main process class, the one all process inherit from.
Definition: Process.hpp:258
QStringList parmNames() const
List of named parameters.
Definition: MeshProcessSegmentation.hpp:259
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MeshProcessSegmentation.hpp:109
QStringList parmDefaults() const
List of default parms.
Definition: MeshProcessSegmentation.hpp:370
Grab labels from other mesh (3D meshes).
Definition: MeshProcessSegmentation.hpp:176
QStringList parmNames() const
List of named parameters.
Definition: MeshProcessSegmentation.hpp:103
mgx_EXPORT bool stringToBool(const QString &string)
Helper function converting a string into a boolean.
Auto-Segmentation of the mesh surface based on signal.
Definition: MeshProcessSegmentation.hpp:386
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MeshProcessSegmentation.hpp:459
This namespace contains all the classes needed to define processes.
QString folder() const
Folder in which to place the process.
Definition: MeshProcessSegmentation.hpp:47
QStringList parmDefaults() const
List of default parms.
Definition: MeshProcessSegmentation.hpp:320
QStringList parmDefaults() const
List of default parms.
Definition: MeshProcessSegmentation.hpp:265
QStringList parmDescs() const
List of parameters descriptions.
Definition: MeshProcessSegmentation.hpp:156
QString description() const
Returns a description of the process for the GUI.
Definition: MeshProcessSegmentation.hpp:53
QString description() const
Returns a description of the process for the GUI.
Definition: MeshProcessSegmentation.hpp:358
QStringList parmNames() const
List of named parameters.
Definition: MeshProcessSegmentation.hpp:151
QString folder() const
Folder in which to place the process.
Definition: MeshProcessSegmentation.hpp:94
Relabel a segmented mesh.
Definition: MeshProcessSegmentation.hpp:122
QString name() const
Returns the name of the process.
Definition: MeshProcessSegmentation.hpp:409
QString name() const
Returns the name of the process.
Definition: MeshProcessSegmentation.hpp:205
QStringList parmDescs() const
List of parameters descriptions.
Definition: MeshProcessSegmentation.hpp:425
QStringList parmNames() const
List of named parameters.
Definition: MeshProcessSegmentation.hpp:214
QString name() const
Returns the name of the process.
Definition: MeshProcessSegmentation.hpp:302
QStringList parmDescs() const
List of parameters descriptions.
Definition: MeshProcessSegmentation.hpp:262
Mesh processes have mutable access to meshes and non-mutable access to stacks.
Definition: Process.hpp:865
QString name() const
Returns the name of the process.
Definition: MeshProcessSegmentation.hpp:97