MorphoGraphX  2.0-1-227
StackProcessMerge.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 STACK_PROCESS_MERGE_HPP
12 #define STACK_PROCESS_MERGE_HPP
13 
14 #include <Process.hpp>
15 
16 namespace mgx
17 {
18 
21 
31  class mgxBase_EXPORT AlignCanvas : public Process
32  {
33  public:
34  AlignCanvas(const Process& process) : Process(process)
35  {
36  setName("Stack/MultiStack/Align Canvas");
37  setDesc("Align two stacks' canvas. Expand the canvas of the first stack so the\n"
38  "second one can be drawn onto it. If the 'change both stack' option is\n"
39  "selected, then all the stacks are extended and made aligned with the\n"
40  "axis of the reference system. Otherwise, the work store of the current\n"
41  "stack is replaced with the projection of the other stack onto the\n"
42  "extended canvas, keeping the resolution of the current stack.");
43  setIcon(QIcon(":/images/AlignCanvas.png"));
44 
45  addParm("Change both stacks","Extend the non-active stacks canvas as well","True",booleanChoice());
46  addParm("Interpolation","How to resample data points","Linear", QStringList() << "Linear" << "Nearest");
47  }
48 
49  bool run()
50  {
51  if(not checkState().store(STORE_NON_EMPTY | STORE_VISIBLE, 0)
52  .store(STORE_NON_EMPTY | STORE_VISIBLE, 1))
53  return false;
54  Stack* current = currentStack();
55  Stack* other = stack(1 - current->id());
56  if(current->currentStore()->labels() != other->currentStore()->labels())
57  return setErrorMessage("Error, one stack is labeled and the other is not.");
58  bool change_both = stringToBool(parm("Change both stacks"));
59  bool result = run(current, other, change_both, parm("Interpolation"));
60  if(not change_both and result)
61  current->work()->show();
62  return result;
63  }
64 
65  bool run(Stack* target, Stack* other, bool change_both, QString interp = "Linear");
66  bool projectGlobal(Stack* s1, Stack* s2, QString interp = "Linear");
67  bool projectOnStack(Stack* target, const Stack* to_project, QString interp = "Linear");
68  };
69 
75  class mgxBase_EXPORT CombineStacks : public Process
76  {
77  public:
78  CombineStacks(const Process& process) : Process(process)
79  {
80  setName("Stack/MultiStack/Combine Stacks");
81  setDesc("Combine the values of the main and work store onto the work store.");
82  setIcon(QIcon(":/images/CombineStacks.png"));
83 
84  addParm("Method","Method","Average", QStringList() << "Max" << "Min" << "Average" << "Product" << "Add" << "Subtract");
85  }
86 
87  bool run()
88  {
89  if(not checkState().store(STORE_NON_EMPTY | STORE_VISIBLE | STORE_MAIN)
90  .store(STORE_NON_EMPTY | STORE_VISIBLE | STORE_WORK))
91  return false;
92  Stack* current = currentStack();
93  if(current->main()->labels() != current->work()->labels())
94  return setErrorMessage("Error, one store is labeled and the other is not.");
95  return run(current, parm("Method"));
96  }
97 
98  bool run(Stack* target, QString method);
99 
100  };
101 
109  class mgxBase_EXPORT MergeStacks : public Process
110  {
111  public:
112  MergeStacks(const Process& process) : Process(process)
113  {
114  setName("Stack/MultiStack/Merge Stacks");
115  setDesc("Merge the main store of the current stack with the current store of the other one.\n"
116  "The current stack will be resampled if required.");
117  setIcon(QIcon(":/images/MergeStacks.png"));
118 
119  addParm("Method","Method","max", QStringList() << "max" << "min" << "average" << "product");
120  addParm("Interpolation","Interpolation","Linear", QStringList() << "Linear" << "Nearest");
121  }
122 
123  bool run()
124  {
125  if(not checkState().store(STORE_NON_EMPTY | STORE_VISIBLE, 0)
126  .store(STORE_NON_EMPTY | STORE_VISIBLE, 1))
127  return false;
128  Stack* current = currentStack();
129  Stack* other = stack(1 - current->id());
130  if(current->currentStore() != current->main())
131  return setErrorMessage("Error, the current stack must have its main store active.");
132  if(current->currentStore()->labels() != other->currentStore()->labels())
133  return setErrorMessage("Error, one stack is labeled and the other is not.");
134  bool result = run(current, other, parm("Method"), parm("Interpolation"));
135  if(result)
136  current->work()->show();
137  return result;
138  }
139 
140  bool run(Stack* target, const Stack* other, QString method, QString interp = "Linear");
141 
142  };
144 }
145 #endif
mgx::CombineStacks
Definition: StackProcessMerge.hpp:75
mgx::MergeStacks
Definition: StackProcessMerge.hpp:109
Process.hpp
mgx::Stack::work
const Store * work() const
Access the work store.
Definition: Stack.hpp:101
mgx::Store::labels
bool labels() const
Returns true if the data is to be interpreted as labels rather than intensities.
Definition: Store.hpp:70
mgx::Stack::currentStore
const Store * currentStore() const
Returns the current store.
Definition: Stack.hpp:120
mgx::AlignCanvas
Definition: StackProcessMerge.hpp:31
mgx::Stack::main
const Store * main() const
Access the main store.
Definition: Stack.hpp:82
mgx::Stack
Definition: Stack.hpp:33
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::CombineStacks::run
bool run()
Runs the process.
Definition: StackProcessMerge.hpp:87
mgx::Process
Definition: Process.hpp:219
mgx::stringToBool
mgx_EXPORT bool stringToBool(const QString &string)
Helper function converting a string into a boolean.
mgx::AlignCanvas::AlignCanvas
AlignCanvas(const Process &process)
Definition: StackProcessMerge.hpp:34
mgx::AlignCanvas::run
bool run()
Runs the process.
Definition: StackProcessMerge.hpp:49
mgx::CombineStacks::CombineStacks
CombineStacks(const Process &process)
Definition: StackProcessMerge.hpp:78
mgx::Store::show
void show()
Ask the user interface to show this store.
Definition: Store.hpp:162
mgx::MergeStacks::run
bool run()
Runs the process.
Definition: StackProcessMerge.hpp:123
mgx::MergeStacks::MergeStacks
MergeStacks(const Process &process)
Definition: StackProcessMerge.hpp:112
mgx::Stack::id
int id() const
Id of a stack.
Definition: Stack.hpp:57