MorphoGraphX  2.0-1-227
MeshProcessSelection.hpp
Go to the documentation of this file.
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_SELECTION_HPP
12 #define MESH_PROCESS_SELECTION_HPP
13 
14 #include <Process.hpp>
15 
16 namespace mgx
17 {
20 
25  class mgxBase_EXPORT MeshSelectAll : public Process
26  {
27  public:
28  MeshSelectAll(const Process& process) : Process(process)
29  {
30  setName("Mesh/Selection/Select All");
31  setDesc("Select all vertices of the current mesh");
32  }
33 
34  bool run()
35  {
36  if(!checkState().mesh(MESH_NON_EMPTY | MESH_SHOW_MESH))
37  return false;
38  return run(currentMesh());
39  }
40 
41  bool run(Mesh* m);
42 
43  };
44 
50  class mgxBase_EXPORT MeshSelectBadNormals : public Process
51  {
52  public:
53  MeshSelectBadNormals(const Process& process) : Process(process)
54  {
55  setName("Mesh/Selection/Select Bad Normals");
56  setDesc("Select all vertices of the current mesh with normals that cannot be calculated");
57  }
58 
59  bool run()
60  {
61  if(!checkState().mesh(MESH_NON_EMPTY | MESH_SHOW_MESH))
62  return false;
63  return run(currentMesh());
64  }
65 
66  bool run(Mesh* m);
67 
68  };
69 
75  class mgxBase_EXPORT MeshUnselect : public Process
76  {
77  public:
78  MeshUnselect(const Process& process) : Process(process)
79  {
80  setName("Mesh/Selection/Unselect");
81  setDesc("Unselect the vertices of the current mesh");
82  }
83 
84  bool run()
85  {
86  if(!checkState().mesh(MESH_NON_EMPTY | MESH_SHOW_MESH))
87  return false;
88  return run(currentMesh());
89  }
90 
91  bool run(Mesh* m);
92 
93  };
94 
100  class mgxBase_EXPORT MeshInvertSelection : public Process
101  {
102  public:
103  MeshInvertSelection(const Process& process) : Process(process)
104  {
105  setName("Mesh/Selection/Invert Selection");
106  setDesc("Invert the selection of the current mesh.");
107  }
108 
109  bool run()
110  {
111  if(!checkState().mesh(MESH_NON_EMPTY | MESH_SHOW_MESH))
112  return false;
113  return run(currentMesh());
114  }
115 
116  bool run(Mesh* m);
117 
118  };
119 
126  class mgxBase_EXPORT MeshSelectUnlabeled : public Process {
127  public:
128  MeshSelectUnlabeled(const Process& process) : Process(process)
129  {
130  setName("Mesh/Selection/Select Unlabeled");
131  setDesc("Add to or replace the selection with the unlabeled vertices.");
132 
133  addParm("Replace selection","Replace selection","No",booleanChoice());
134  }
135 
136  bool run()
137  {
138  if(!checkState().mesh(MESH_NON_EMPTY | MESH_SHOW_MESH))
139  return false;
140  bool replace = stringToBool(parm("Replace selection"));
141  return run(currentMesh(), replace);
142  }
143 
144  bool run(Mesh* m, bool replace);
145 
146  };
147 
153  class mgxBase_EXPORT MeshSelectLabeled : public Process
154  {
155  public:
156  MeshSelectLabeled(const Process& process) : Process(process)
157  {
158  setName("Mesh/Selection/Select Labeled");
159  setDesc("Add to or replace the selection with the labeled vertices.");
160 
161  addParm("Replace selection","Replace selection","No",booleanChoice());
162  }
163 
164  bool run()
165  {
166  if(!checkState().mesh(MESH_NON_EMPTY | MESH_SHOW_MESH))
167  return false;
168  bool replace = stringToBool(parm("Replace selection"));
169  return run(currentMesh(), replace);
170  }
171 
172  bool run(Mesh* m, bool replace);
173 
174  };
175 
179  class mgxBase_EXPORT MeshSelectLabels : public Process
180  {
181  public:
182  MeshSelectLabels(const Process& process) : Process(process)
183  {
184  setName("Mesh/Selection/Select Labels");
185  setDesc("Add to or replace the selection with the labeled vertices.");
186 
187  addParm("Labels","List of labels to select, 0 for current","0");
188  addParm("Replace Selection","Replace selection", "No", booleanChoice());
189  }
190 
191  bool run()
192  {
193  if(!checkState().mesh(MESH_NON_EMPTY | MESH_SHOW_MESH))
194  return false;
195  bool replaceSelection = stringToBool(parm("Replace Selection"));
196  Mesh *mesh = currentMesh();
197  if(!mesh)
198  throw QString("%1::run No current mesh:");
199 
200  IntSet labels;
201  for(auto s : parm("Labels").split(QRegExp("[ ,;:]"))) {
202  s = s.trimmed();
203  if(s.isEmpty())
204  continue;
205  int label = s.toInt();
206  if(s == "0")
207  label = mesh->viewLabel();
208  labels.insert(label);
209  }
210  return run(mesh, labels, replaceSelection);
211  }
212  bool run(Mesh* m, const IntSet &labels, bool replace = false);
213  };
214 
218  class mgxBase_EXPORT MeshSelectValence : public Process
219  {
220  public:
221  MeshSelectValence(const Process& process) : Process(process)
222  {
223  setName("Mesh/Selection/Select By Valence");
224  setDesc("Select vertices by Valence");
225 
226  addParm("Begin Valence","","1");
227  addParm("End Valence","","5");
228  }
229 
230  bool run()
231  {
232  if(!checkState().mesh(MESH_NON_EMPTY | MESH_SHOW_MESH))
233  return false;
234  return run(currentMesh(), parm("Begin Valence").toInt(), parm("End Valence").toInt());
235  }
236 
237  bool run(Mesh* m, int start, int end);
238 
239  };
240 
246  class mgxBase_EXPORT MeshUnselectLabel : public Process
247  {
248  public:
249  MeshUnselectLabel(const Process& process) : Process(process)
250  {
251  setName("Mesh/Selection/Unselect Label");
252  setDesc("Remove the vertices of a given label (0 for current label) from the selection.");
253 
254  addParm("Label (0 for current)","Label (0 for current)","0"); // 0
255  }
256 
257  bool run()
258  {
259  if(!checkState().mesh(MESH_NON_EMPTY | MESH_SHOW_MESH))
260  return false;
261  return run(currentMesh(), parm("Label (0 for current)").toInt());
262  }
263 
264  bool run(Mesh* m, int label);
265 
266  };
267 
273  class mgxBase_EXPORT MeshSelectClip : public Process
274  {
275  public:
276  MeshSelectClip(const Process& process) : Process(process)
277  {
278  setName("Mesh/Selection/Select Clip Region");
279  setDesc("Add vertices in clip region to selection.");
280  }
281 
282  bool run()
283  {
284  if(!checkState().mesh(MESH_NON_EMPTY | MESH_SHOW_MESH))
285  return false;
286  return run(currentMesh());
287  }
288 
289  bool run(Mesh* m);
290 
291  };
292 
299  class mgxBase_EXPORT MeshSelectWholeLabelExtend : public Process
300  {
301  public:
302  MeshSelectWholeLabelExtend(const Process& process) : Process(process)
303  {
304  setName("Mesh/Selection/Extend to Whole Cells");
305  setDesc("Extend Selection to Whole Cells");
306  }
307 
308  bool run()
309  {
310  if(!checkState().mesh(MESH_NON_EMPTY | MESH_SHOW_MESH))
311  return false;
312  return run(currentMesh());
313  }
314 
315  bool run(Mesh* m);
316 
317  };
318 
325  class mgxBase_EXPORT MeshSelectDuplicateCells : public Process
326  {
327  public:
328  MeshSelectDuplicateCells(const Process& process) : Process(process)
329  {
330  setName("Mesh/Selection/Select Duplicate Cells");
331  setDesc("Select cells with duplicate labels.");
332  }
333 
334  bool run()
335  {
336  if(!checkState().mesh(MESH_NON_EMPTY | MESH_SHOW_MESH))
337  return false;
338  return run(currentMesh());
339  }
340 
341  bool run(Mesh* m);
342 
343  };
344 
351  class mgxBase_EXPORT ExtendByConnectivity : public Process
352  {
353  public:
354  ExtendByConnectivity(const Process& process) : Process(process)
355  {
356  setName("Mesh/Selection/Extend by Connectivity");
357  setDesc("Extend the selection to connected regions");
358  setIcon(QIcon(":/images/SelectConnected.png"));
359  }
360 
361  bool run()
362  {
363  if(!checkState().mesh(MESH_NON_EMPTY))
364  return false;
365  return run(currentMesh());
366  }
367 
368  bool run(Mesh* m);
369 
370  };
372 
379 class mgxBase_EXPORT SelectByNormal : public Process
380  {
381  public:
382  SelectByNormal(const Process& process) : Process(process)
383  {
384  setName("Mesh/Selection/Extend Selection by Normal");
385  setDesc("Selects vertices according to how close their normal is compared to pre-selected reference vertices.");
386  setIcon(QIcon(":/images/SelectConnected.png"));
387 
388  addParm("Tolerance","Tolerance threshold of the scalar of the averaged normal of selected vertices and other vertices","0.01");
389  }
390 
391  bool run()
392  {
393  if(!checkState().mesh())
394  return false;
395  Mesh *m = currentMesh();
396  return run(m, parm("Tolerance").toDouble());
397  }
398 
399  bool run(Mesh *m, double tolerance);
400 
401  };
402 
409  class mgxBase_EXPORT SelectSharedTriangles : public Process
410  {
411  public:
412  SelectSharedTriangles(const Process& process) : Process(process)
413  {
414  setName("Mesh/Selection/Select Shared Triangles");
415  setDesc("Select triangles shared by several cells");
416  setIcon(QIcon(":/images/Triangle.png"));
417  }
418 
419  bool run()
420  {
421  if(!checkState().mesh(MESH_NON_EMPTY))
422  return false;
423  return run(currentMesh());
424  }
425 
426  bool run(Mesh* m);
427 
428  };
430 
436  class mgxBase_EXPORT AreaSelectedTris : public Process
437  {
438  public:
439  AreaSelectedTris(const Process& process) : Process(process)
440  {
441  setName("Mesh/Selection/Area of Selected Triangles");
442  setDesc("Returns the area of all selected triangles. Either triangles with all 3 vertices selected or triangles with at least one selected vertex");
443  setIcon(QIcon(":/images/Hex.png"));
444 
445  addParm("Mode","Mode","Tris inside Vtxs", QStringList() << "Tris inside Vtxs" << "Tris neighboring Vtxs");
446  }
447 
448  bool run()
449  {
450  if(!checkState().mesh(MESH_NON_EMPTY))
451  return false;
452  Mesh* m = currentMesh();
453  return run(m, parm("Mode"));
454  }
455 
456  bool run(Mesh* m, QString mode);
457 
458  };
459 
460 
466  class mgxBase_EXPORT CountSelectedCells : public Process
467  {
468  public:
469  CountSelectedCells(const Process& process) : Process(process)
470  {
471  setName("Mesh/Selection/Count Selected Cells");
472  setDesc("Counts how many cells are selected and prints information about selected labels in the console window");
473  setIcon(QIcon(":/images/Hex.png"));
474  }
475 
476  bool run()
477  {
478  Mesh* m = currentMesh();
479  return run(m);
480  }
481 
482  bool run(Mesh* m);
483 
484  };
485 
491  class mgxBase_EXPORT ExtendSelectionByNeighbors : public Process
492  {
493  public:
494  ExtendSelectionByNeighbors(const Process& process) : Process(process)
495  {
496  setName("Mesh/Selection/Extend Selection By Neighbors");
497  setDesc("Extend Selection By Neighbor Vertices");
498  setIcon(QIcon(":/images/Hex.png"));
499 
500  addParm("Shrink Selection","Shrink Selection instead of extending it","No",booleanChoice());
501  }
502 
503  bool run()
504  {
505  Mesh* m = currentMesh();
506  return run(m, stringToBool(parm("Shrink Selection")));
507  }
508 
509  bool run(Mesh* m, bool shrink);
510 
511  };
512 
513 
519  class mgxBase_EXPORT SelectSpecial : public Process
520  {
521  public:
522  SelectSpecial(const Process& process) : Process(process)
523  {
524 
525  setName("Mesh/Selection/Select Special");
526  setDesc("Selects vertices of a particular type");
527  setIcon(QIcon(":/images/LayerFiles.png"));
528 
529  addParm("Inner Border","Inner Border","Yes",booleanChoice());
530  addParm("Outer Border","Outer Border","No",booleanChoice());
531  addParm("Junctions","Junctions","No",booleanChoice());
532  addParm("Cell Vtxs","Cell Vtxs","No",booleanChoice());
533 
534 
535  }
536 
537  bool run()
538  {
539  if(!checkState().mesh())
540  return false;
541  Mesh *m = currentMesh();
542  return run(m, stringToBool(parm("Inner Border")), stringToBool(parm("Outer Border")), stringToBool(parm("Junctions")), stringToBool(parm("Cell Vtxs")));
543  }
544 
545  bool run(Mesh *m, bool borderIn, bool borderOut, bool junctions, bool cells);
546 
547  };
548 
554  class mgxBase_EXPORT SelectShortWalls : public Process {
555  public:
556  SelectShortWalls(const Process& proc) : Process(proc)
557  {
558  setName("Mesh/Selection/Select Short Walls");
559  setDesc("Selects cell walls shorter than a given threshold.");
560  setIcon(QIcon(":/images/open.png"));
561 
562  addParm("Junction Merging Threshold","Junction Merging Threshold","0.1");
563  addParm("Exclusive","never select two touching walls","Yes", booleanChoice());
564  }
565 
566  bool run()
567  {
568  Mesh* m = currentMesh();
569  return run(m, parm("Junction Merging Threshold").toDouble(), stringToBool(parm("Exclusive")));
570  }
571  bool run(Mesh* m, double threshold, bool exclusive);
572 
573  };
574 
580  class mgxBase_EXPORT DistanceCells : public Process {
581  public:
582  DistanceCells(const Process& proc) : Process(proc)
583  {
584  setName("Mesh/Selection/Distance Selected Cells");
585  setDesc("Outputs the distance of selected cells on the console");
586  setIcon(QIcon(":/images/open.png"));
587 
588  }
589 
590  bool run()
591  {
592  Mesh* m = currentMesh();
593  return run(m);
594  }
595  bool run(Mesh* m);
596 
597  };
598 
599 
600 }
601 
602 #endif
mgx::CountSelectedCells
Definition: MeshProcessSelection.hpp:466
mgx::MeshSelectDuplicateCells::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:334
mgx::MeshSelectBadNormals
Definition: MeshProcessSelection.hpp:50
mgx::MeshUnselectLabel::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:257
Process.hpp
mgx::Mesh::viewLabel
int viewLabel() const
Returns the current label, without modifying it.
Definition: Mesh.hpp:167
mgx::MeshSelectBadNormals::MeshSelectBadNormals
MeshSelectBadNormals(const Process &process)
Definition: MeshProcessSelection.hpp:53
mgx::MeshSelectUnlabeled::MeshSelectUnlabeled
MeshSelectUnlabeled(const Process &process)
Definition: MeshProcessSelection.hpp:128
mgx::SelectSpecial::SelectSpecial
SelectSpecial(const Process &process)
Definition: MeshProcessSelection.hpp:522
mgx::MeshSelectDuplicateCells
Definition: MeshProcessSelection.hpp:325
mgx::MeshSelectValence::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:230
mgx::MeshSelectWholeLabelExtend::MeshSelectWholeLabelExtend
MeshSelectWholeLabelExtend(const Process &process)
Definition: MeshProcessSelection.hpp:302
mgx::MeshUnselect::MeshUnselect
MeshUnselect(const Process &process)
Definition: MeshProcessSelection.hpp:78
mgx::SelectByNormal
Definition: MeshProcessSelection.hpp:379
mgx::MeshSelectLabeled
Definition: MeshProcessSelection.hpp:153
mgx::CountSelectedCells::CountSelectedCells
CountSelectedCells(const Process &process)
Definition: MeshProcessSelection.hpp:469
mgx::MeshUnselect
Definition: MeshProcessSelection.hpp:75
mgx::MeshUnselect::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:84
mgx::DistanceCells::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:590
mgx::SelectByNormal::SelectByNormal
SelectByNormal(const Process &process)
Definition: MeshProcessSelection.hpp:382
mgx::MeshSelectClip::MeshSelectClip
MeshSelectClip(const Process &process)
Definition: MeshProcessSelection.hpp:276
mgx::MeshSelectUnlabeled
Definition: MeshProcessSelection.hpp:126
mgx::MeshSelectLabels::MeshSelectLabels
MeshSelectLabels(const Process &process)
Definition: MeshProcessSelection.hpp:182
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::AreaSelectedTris::AreaSelectedTris
AreaSelectedTris(const Process &process)
Definition: MeshProcessSelection.hpp:439
mgx::CountSelectedCells::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:476
mgx::MeshSelectUnlabeled::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:136
mgx::SelectShortWalls::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:566
mgx::AreaSelectedTris::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:448
mgx::MeshSelectAll
Definition: MeshProcessSelection.hpp:25
mgx::MeshSelectLabeled::MeshSelectLabeled
MeshSelectLabeled(const Process &process)
Definition: MeshProcessSelection.hpp:156
mgx::DistanceCells
Definition: MeshProcessSelection.hpp:580
mgx::Process
Definition: Process.hpp:219
mgx::SelectSharedTriangles::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:419
mgx::stringToBool
mgx_EXPORT bool stringToBool(const QString &string)
Helper function converting a string into a boolean.
mgx::MeshSelectLabels::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:191
mgx::MeshSelectWholeLabelExtend::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:308
mgx::MeshInvertSelection::MeshInvertSelection
MeshInvertSelection(const Process &process)
Definition: MeshProcessSelection.hpp:103
mgx::IntSet
std::set< int > IntSet
Set of integers.
Definition: Types.hpp:78
mgx::SelectByNormal::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:391
mgx::MeshInvertSelection
Definition: MeshProcessSelection.hpp:100
mgx::ExtendByConnectivity
Definition: MeshProcessSelection.hpp:351
mgx::SelectSharedTriangles
Definition: MeshProcessSelection.hpp:409
mgx::ExtendSelectionByNeighbors
Definition: MeshProcessSelection.hpp:491
mgx::SelectSpecial
Definition: MeshProcessSelection.hpp:519
mgx::MeshSelectAll::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:34
mgx::MeshSelectBadNormals::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:59
mgx::ExtendSelectionByNeighbors::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:503
mgx::MeshSelectLabeled::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:164
mgx::SelectSpecial::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:537
mgx::Mesh
Definition: Mesh.hpp:54
mgx::MeshSelectClip
Definition: MeshProcessSelection.hpp:273
mgx::MeshInvertSelection::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:109
mgx::MeshUnselectLabel::MeshUnselectLabel
MeshUnselectLabel(const Process &process)
Definition: MeshProcessSelection.hpp:249
mgx::SelectShortWalls
Definition: MeshProcessSelection.hpp:554
mgx::SelectShortWalls::SelectShortWalls
SelectShortWalls(const Process &proc)
Definition: MeshProcessSelection.hpp:556
mgx::MeshSelectClip::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:282
mgx::MeshSelectLabels
Definition: MeshProcessSelection.hpp:179
mgx::ExtendByConnectivity::run
bool run()
Runs the process.
Definition: MeshProcessSelection.hpp:361
mgx::ExtendByConnectivity::ExtendByConnectivity
ExtendByConnectivity(const Process &process)
Definition: MeshProcessSelection.hpp:354
mgx::MeshUnselectLabel
Definition: MeshProcessSelection.hpp:246
mgx::MeshSelectValence::MeshSelectValence
MeshSelectValence(const Process &process)
Definition: MeshProcessSelection.hpp:221
mgx::ExtendSelectionByNeighbors::ExtendSelectionByNeighbors
ExtendSelectionByNeighbors(const Process &process)
Definition: MeshProcessSelection.hpp:494
mgx::MeshSelectDuplicateCells::MeshSelectDuplicateCells
MeshSelectDuplicateCells(const Process &process)
Definition: MeshProcessSelection.hpp:328
mgx::MeshSelectValence
Definition: MeshProcessSelection.hpp:218
mgx::MeshSelectAll::MeshSelectAll
MeshSelectAll(const Process &process)
Definition: MeshProcessSelection.hpp:28
mgx::MeshSelectWholeLabelExtend
Definition: MeshProcessSelection.hpp:299
mgx::SelectSharedTriangles::SelectSharedTriangles
SelectSharedTriangles(const Process &process)
Definition: MeshProcessSelection.hpp:412
mgx::AreaSelectedTris
Definition: MeshProcessSelection.hpp:436
mgx::DistanceCells::DistanceCells
DistanceCells(const Process &proc)
Definition: MeshProcessSelection.hpp:582