MorphoGraphX
MergeStacks.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 MergeStacks_HPP
12 #define MergeStacks_HPP
13 
14 #include <Process.hpp>
15 
16 namespace mgx {
17 namespace process {
18 
21 
31 class AlignCanvas : public StackProcess {
32 public:
34  : Process(process)
35  , StackProcess(process)
36  {
37  }
38 
39  bool operator()(const QStringList& parms)
40  {
41  if(not checkState().store(STORE_NON_EMPTY | STORE_VISIBLE, 0).store(STORE_NON_EMPTY | STORE_VISIBLE, 1))
42  return false;
43  Stack* current = currentStack();
44  Stack* other = stack(1 - current->id());
45  if(current->currentStore()->labels() != other->currentStore()->labels())
46  return setErrorMessage("Error, one stack is labeled and the other is not.");
47  bool change_both = stringToBool(parms[0]);
48  bool result = operator()(current, other, change_both);
49  if(not change_both and result)
50  current->work()->show();
51  return result;
52  }
53 
54  bool operator()(Stack* target, Stack* other, bool change_both);
55 
56  QString folder() const {
57  return "Multi-stack";
58  }
59  QString name() const {
60  return "Align Canvas";
61  }
63  {
64  return "Align two stacks' canvas. Expand the canvas of the first stack so the\n"
65  "second one can be drawn onto it. If the 'change both stack' option is \n"
66  "selected, then all the stacks are extended and made aligned with the \n"
67  "axis of the reference system. Otherwise, the work store of the current\n"
68  "stack is replaced with the projection of the other stack onto the\n"
69  "extended canvas, keeping the resolution of the current stack.\n";
70  }
72  return QStringList() << "Change both stacks";
73  }
75  return QStringList() << "Extend the non-active stacks canvas as well";
76  }
78  return QStringList() << "True";
79  }
81  {
82  ParmChoiceMap map;
83  map[0] = booleanChoice();
84  return map;
85  }
86  QIcon icon() const {
87  return QIcon(":/images/AlignCanvas.png");
88  }
89 
90  bool projectGlobal(Stack* s1, Stack* s2);
91  bool projectOnStack(Stack* target, const Stack* to_project);
92 };
93 
99 class CombineStacks : public StackProcess {
100 public:
102  : Process(process)
103  , StackProcess(process)
104  {
105  }
106 
107  bool operator()(const QStringList& parms)
108  {
110  | STORE_WORK))
111  return false;
112  Stack* current = currentStack();
113  if(current->main()->labels() != current->work()->labels())
114  return setErrorMessage("Error, one store is labeled and the other is not.");
115  return operator()(current, parms[0]);
116  }
117 
118  bool operator()(Stack* target, QString method);
119 
120  QString folder() const {
121  return "Multi-stack";
122  }
123  QString name() const {
124  return "Combine Stacks";
125  }
127  return "Combine the values of the main and work store onto the work store.";
128  }
130  return QStringList() << "Method";
131  }
133  return QStringList() << "Method";
134  }
136  return QStringList() << "Max";
137  }
139  {
140  ParmChoiceMap map;
141  map[0] = QStringList() << "Max"
142  << "Min"
143  << "Average"
144  << "Product"
145  << "Add"
146  << "Subtract";
147  return map;
148  }
149  QIcon icon() const {
150  return QIcon(":/images/CombineStacks.png");
151  }
152 };
153 
161 class MergeStacks : public StackProcess {
162 public:
164  : Process(process)
165  , StackProcess(process)
166  {
167  }
168 
169  bool operator()(const QStringList& parms)
170  {
171  if(not checkState().store(STORE_NON_EMPTY | STORE_VISIBLE, 0).store(STORE_NON_EMPTY | STORE_VISIBLE, 1))
172  return false;
173  Stack* current = currentStack();
174  Stack* other = stack(1 - current->id());
175  if(current->currentStore() != current->main())
176  return setErrorMessage("Error, the current stack must have its main store active.");
177  if(current->currentStore()->labels() != other->currentStore()->labels())
178  return setErrorMessage("Error, one stack is labeled and the other is not.");
179  bool result = operator()(current, other, parms[0]);
180  if(result)
181  current->work()->show();
182  return result;
183  }
184 
185  bool operator()(Stack* target, const Stack* other, QString method);
186 
187  QString folder() const {
188  return "Multi-stack";
189  }
190  QString name() const {
191  return "Merge Stacks";
192  }
194  {
195  return "Merge the main store of the current stack with the current store of the other one.\n"
196  "The current stack will be aligned with the other before the stores being combines.\n"
197  "The method argument is simply passed to the Combine_Stacks process.";
198  }
200  return QStringList() << "Method";
201  }
203  return QStringList() << "Method";
204  }
206  return QStringList() << "max";
207  }
209  {
210  ParmChoiceMap map;
211  map[0] = QStringList() << "max"
212  << "min"
213  << "average"
214  << "product";
215  return map;
216  }
217  QIcon icon() const {
218  return QIcon(":/images/MergeStacks.png");
219  }
220 };
222 } // namespace process
223 } // namespace mgx
224 #endif
void show()
Ask the user interface to show this store.
Definition: Store.hpp:177
QStringList parmNames() const
List of named parameters.
Definition: MergeStacks.hpp:199
ParmChoiceMap parmChoice() const
Purely for GUI purposes, provides for some of the parms parameter a choice.
Definition: MergeStacks.hpp:80
QString description() const
Returns a description of the process for the GUI.
Definition: MergeStacks.hpp:126
Stack * currentStack()
Returns the current stack (i.e.
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: MergeStacks.hpp:39
QString folder() const
Folder in which to place the process.
Definition: MergeStacks.hpp:120
int id() const
Id of a stack.
Definition: Stack.hpp:59
QStringList parmDefaults() const
List of default parms.
Definition: MergeStacks.hpp:205
QString name() const
Returns the name of the process.
Definition: MergeStacks.hpp:59
const Store * currentStore() const
Returns the current store.
Definition: Stack.hpp:122
QStringList parmNames() const
List of named parameters.
Definition: MergeStacks.hpp:129
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: MergeStacks.hpp:169
QString description() const
Returns a description of the process for the GUI.
Definition: MergeStacks.hpp:62
QStringList parmDefaults() const
List of default parms.
Definition: MergeStacks.hpp:135
Process()
Default constructor.
QStringList parmDescs() const
List of parameters descriptions.
Definition: MergeStacks.hpp:74
QStringList parmDefaults() const
List of default parms.
Definition: MergeStacks.hpp:77
Align two stacks&#39; canvas.
Definition: MergeStacks.hpp:31
QStringList parmNames() const
List of named parameters.
Definition: MergeStacks.hpp:71
CheckState checkState()
Call this function and convert the result to a boolean.
ParmChoiceMap parmChoice() const
Purely for GUI purposes, provides for some of the parms parameter a choice.
Definition: MergeStacks.hpp:138
Visible store.
Definition: Process.hpp:654
Merge the main store of the current stack with the current store of the other one.
Definition: MergeStacks.hpp:161
Stack * stack(int i)
Returns the ith stack, or 0 if there is no such stack.
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MergeStacks.hpp:149
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26
QString folder() const
Folder in which to place the process.
Definition: MergeStacks.hpp:187
bool setErrorMessage(const QString &str)
Set an error message that will be displayed if the process returns false.
Non-Empty store.
Definition: Process.hpp:653
QString name() const
Returns the name of the process.
Definition: MergeStacks.hpp:190
bool labels() const
Returns true if the data is to be interpreted as labels rather than intensities.
Definition: Store.hpp:73
File containing the definition of a Process.
ParmChoiceMap parmChoice() const
Purely for GUI purposes, provides for some of the parms parameter a choice.
Definition: MergeStacks.hpp:208
The Stack class represent the dimensions of the 3D data, and the frames transformations.
Definition: Stack.hpp:35
bool operator()(const QStringList &parms)
Implementation of the process with generic arguments.
Definition: MergeStacks.hpp:107
QStringList parmDescs() const
List of parameters descriptions.
Definition: MergeStacks.hpp:132
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MergeStacks.hpp:86
mgx_EXPORT bool stringToBool(const QString &string)
Helper function converting a string into a boolean.
Main store.
Definition: Process.hpp:666
This namespace contains all the classes needed to define processes.
const Store * work() const
Access the work store.
Definition: Stack.hpp:103
QString name() const
Returns the name of the process.
Definition: MergeStacks.hpp:123
Combine the values of the main and work store onto the work store.
Definition: MergeStacks.hpp:99
const Store * main() const
Access the main store.
Definition: Stack.hpp:84
QString description() const
Returns a description of the process for the GUI.
Definition: MergeStacks.hpp:193
QIcon icon() const
Icon to use to represent the process in the GUI.
Definition: MergeStacks.hpp:217
Stack processes have non-mutable access to meshes and mutable access to stacks.
Definition: Process.hpp:829
QStringList booleanChoice() const
Helper function that provides a list of choices for a boolean argument.
Definition: Process.hpp:609
QString folder() const
Folder in which to place the process.
Definition: MergeStacks.hpp:56
QStringList parmDescs() const
List of parameters descriptions.
Definition: MergeStacks.hpp:202
Work store.
Definition: Process.hpp:665