MorphoGraphX  2.0-1-227
SystemProcessLoad.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 SYSTEMPROCESSLOAD_HPP
12 #define SYSTEMPROCESSLOAD_HPP
13 
14 #include <Process.hpp>
15 #include <QFileDialog>
16 
22 class QDialog;
23 class Ui_LoadStackDialog;
24 class Ui_LoadMeshDialog;
25 class Ui_ImportMeshDialog;
26 class QFile;
27 class QIODevice;
28 
29 namespace mgx
30 {
31  mgx_EXPORT QList<int> extractVersion(QIODevice& file);
32 
40  class mgx_EXPORT StackSwapBytes : public Process {
41  public:
42  StackSwapBytes(const Process& process) : Process(process)
43  {
44  setName("Stack/Filters/Swap Bytes");
45  setDesc("Swap the bytes of the values in the stack.");
46  setIcon(QIcon(":/images/SwapBytes.png"));
47  }
48 
49  bool run()
50  {
51  if(!checkState().store(STORE_NON_EMPTY))
52  return false;
53  Store* input = currentStack()->currentStore();
54  Store* output = currentStack()->work();
55  bool res = run(input, output);
56  if(res) {
57  input->hide();
58  output->show();
59  }
60  return res;
61  }
62 
63  bool run(const Store* input, Store* output);
64  };
65 
73  class mgx_EXPORT StackImport : public Process {
74  Q_OBJECT
75  public:
76  StackImport(const Process& proc) : Process(proc)
77  {
78  setName("Stack/System/Import");
79  setDesc("Import stack from a series of images");
80  setIcon(QIcon(":/images/open.png"));
81 
82  addParm("Stack","Stack","-1"); // 0
83  addParm("Store","Store","Current", storeChoice() << "Current"); // 1
84  addParm("X Step","X Step","1.0"); // 2
85  addParm("Y Step","Y Step","1.0"); // 3
86  addParm("Z Step","Z Step","1.0"); // 4
87  addParm("Brightness","Brightness","1.0"); // 5
88  addParm("Profile File","Profile File",""); // 6
89  }
90 
91  bool initialize(QWidget* parent);
92 
93  bool run()
94  {
95  int stackId = parm("Stack").toInt();
96  QString storeName = parm("Store");
97  Point3f step(parm("X Step").toFloat(), parm("Y Step").toFloat(), parm("Z Step").toFloat());
98  float brightness(parm("Brightness").toFloat());
99  QString filename(parm("Profile File"));
100 
101  // Get stack and store
102  Stack* stk = currentStack();
103  if(stackId != -1)
104  stk = stack(parm("Stack").toInt());
105  if(!checkState().stack(STACK_ANY, stackId))
106  return false;
107 
108  Store* store = stk->currentStore();
109  if(storeName == "Main")
110  store = stk->main();
111  else if(storeName == "Work")
112  store = stk->work();
113 
114  return run(stk, store, step, brightness, filename);
115  }
116 
127  bool run(Stack* stack, Store* store, Point3f step, float brightness, QString filename);
128 
129  protected slots:
130  void SaveProfile();
131  void LoadProfile(QString filename = QString());
132  void AddFilesSlot();
133  void AddFilesSlot(const QStringList& files);
134  void RemoveFilesSlot();
135  void FilterFilesSlot();
136  void SortAscendingSlot(bool val = true);
137  void SortDescendingSlot();
138 
139  protected:
140  bool LoadProfile(QString filename, Point3u& size, Point3f& step, float& brightness, QStringList& files);
141  void setImageSize(Point3u size);
142  void setImageSize(uint x, uint y, uint z) {
143  setImageSize(Point3u(x, y, z));
144  }
145  void setImageResolution(Point3f step);
146  void setImageResolution(float x, float y, float z) {
147  setImageResolution(Point3f(x, y, z));
148  }
149  Point3f imageResolution();
150 
151  QString txtFile;
152  QDialog* dlg;
153  Ui_LoadStackDialog* ui;
154  QString loadedFile;
156  QStringList imageFiles;
157  };
158 
166  class mgx_EXPORT StackOpen : public Process {
167  public:
168  StackOpen(const Process& proc) : Process(proc)
169  {
170  setName("Stack/System/Open");
171  setDesc("Open a stack from a known 3D image format");
172  setIcon(QIcon(":/images/open.png"));
173 
174  addParm("Filename","Filename",""); // 0
175  addParm("Store","Store","Main", storeChoice()); // 1
176  addParm("Stack Number","Stack number","0"); // 2
177  addParm("HDF5 DataSetName","HDF5 DataSetName","/label"); // 2
178  }
179 
180  bool run();
181 
188  bool run(Stack* stack, Store* store, QString filename);
189 
190  bool initialize(QWidget* parent);
191 
192  bool loadMGXS_1_3(QIODevice& file, Stack* stack, Store* store);
193  bool loadMGXS_1_2(QIODevice& file, Stack* stack, Store* store);
194  bool loadMGXS_1_1(QIODevice& file, Stack* stack, Store* store);
195  bool loadMGXS_1_0(QIODevice& file, Stack* stack, Store* store);
196  bool loadMGXS_0(QIODevice& file, Stack* stack, Store* store);
197  void centerImage();
198  };
199 
200 
208  class mgx_EXPORT MeshLoad : public Process {
209  Q_OBJECT
210  public:
211  MeshLoad(const Process& proc) : Process(proc)
212  {
213  setName("Mesh/System/Load");
214  setDesc("Load a mesh from one of the known formats.");
215  setIcon(QIcon(":/images/open.png"));
216 
217  addParm("Filename","Filename",""); // 0
218  addParm("Transform","Transform","no",booleanChoice()); // 1
219  addParm("Add","Add","no",booleanChoice()); // 2
220  addParm("Stack Number","Stack number","0"); // 3
221  }
222 
223  bool run();
235  bool run(Mesh* mesh, QString filename, bool transform, bool add);
236  bool initialize(QWidget* parent);
237 
238  bool loadMGXM_0(QIODevice& file, Mesh* mesh, bool scale, bool transform, bool has_color = true);
239  bool loadMGXM_1_0(QIODevice& file, Mesh* mesh, bool& scale, bool& transform, bool has_color = true);
240  bool loadMGXM_1_1(QIODevice& file, Mesh* mesh, bool& scale, bool& transform, bool has_color = true);
241  bool loadMGXM_1_2(QIODevice& file, Mesh* mesh, bool& scale, bool& transform, bool has_color = true);
242  bool loadMGXM_1_3(QIODevice& file, Mesh* mesh, bool& scale, bool& transform);
243  bool loadMGXM_2_0(QIODevice& file, const QList<int> &version, Mesh* mesh, bool& scale, bool& transform);
244  bool loadMGXM_2_1(QIODevice& file, const QList<int> &version, Mesh* mesh, bool& scale, bool& transform);
245 
246  void findSignalBounds(Mesh* mesh);
247 
248  protected slots:
249  void selectMeshFile();
250 
251  protected:
252  void setMeshFile(const QString& filename);
253 
254  QDialog* dlg;
255  Ui_LoadMeshDialog* ui;
256  };
257 
265  class mgx_EXPORT MeshImport : public Process {
266  Q_OBJECT
267 
268  public:
269  MeshImport(const Process& proc) : Process(proc)
270  {
271  setName("Mesh/System/Import");
272  setDesc("Import a mesh from one of the known formats.");
273  setIcon(QIcon(":/images/open.png"));
274 
275  addParm("Filename","Filename",""); // 0
276  addParm("Kind","Kind","PLY",
277  QStringList() << "VTK Mesh" << "Text" << "Cells" << "Keyence" << "MeshEdit"); // 1
278  addParm("Scale","Scale","yes", booleanChoice()); // 2
279  addParm("Transform","Transform","no", booleanChoice()); // 3
280  addParm("Add","Add","no", booleanChoice()); // 4
281  addParm("Stack Number","Stack number","0"); // 5
282  }
283 
284  bool run();
297  bool initialize(QWidget* parent);
298 
299  bool run(Mesh* mesh, QString filename, QString type, bool scale, bool transform, bool add);
300 
301  protected slots:
302  void selectMeshFile();
303  void selectMeshType(const QString& type);
304 
305  protected:
306  void setMeshFile(const QString& filename, const QString& type = QString());
307  QString properFile(QString filename, const QString& type) const;
308 
309  bool loadText(Mesh* mesh, const QString& filename, bool scale, bool transform, bool add);
310  bool loadCells(Mesh* mesh, const QString& filename, bool scale, bool transform, bool add);
311  bool loadKeyence(Mesh* mesh, const QString& filename, bool scale, bool transform, bool add);
312  bool loadMeshEdit(Mesh* mesh, const QString& filename, bool scale, bool transform, bool add);
313  bool loadMeshVTK(Mesh* mesh, const QString& filename, bool& scale, bool transform, bool add);
314  bool loadMeshOBJ(Mesh* mesh, const QString& filename, bool scale, bool transform, bool add);
315  bool loadMeshPLY(Mesh* mesh, const QString& filename, bool scale, bool transform, bool add);
316 
317  QDialog* dlg;
318  Ui_ImportMeshDialog* ui;
319  };
320 
331  class mgx_EXPORT LoadAllData : public Process
332  {
333  public:
334  LoadAllData(const Process& proc) : Process(proc)
335  {
336  setName("Misc/System/Load All");
337  setDesc("Load the data for all existing objects, using the filename and properties set in them.");
338  setIcon(QIcon(":/images/open.png"));
339  }
340 
341  bool run();
342 
343  protected:
344  bool loadStore(Stack* stack, Store* store, QStringList& errors);
345  };
346 
353  class mgx_EXPORT LoadViewFile : public Process {
354  public:
355  LoadViewFile(const Process& proc) : Process(proc)
356  {
357  setName("Misc/System/Load View");
358  setDesc("Load a view file and set all the fields and interface. Does not load the data though.");
359  setIcon(QIcon(":/images/open.png"));
360 
361  addParm("Filename","Filename",""); // 0
362  }
363 
364  bool run();
368  bool run(QString filename);
369 
370  bool initialize(QWidget* parent);
371 
372  };
373 
381  class mgx_EXPORT ResetMeshProcess : public Process {
382  public:
383  ResetMeshProcess(const Process& proc) : Process(proc)
384  {
385  setName("Mesh/System/Reset");
386  setDesc("Reset a mesh, -1 for current.");
387  setIcon(QIcon(":/images/ClearStack.png"));
388 
389  addParm("Mesh","Mesh","-1"); // 0
390  }
391 
392  bool run();
393  bool run(Mesh* m);
394 
395  };
396 
404  class mgx_EXPORT SaveParents : public Process {
405  public:
406  SaveParents(const Process& process) : Process(process)
407  {
408  setName("Mesh/Lineage Tracking/Save Parents");
409  setDesc("Save map of labels to parents labels to a file");
410  setIcon(QIcon(":/images/ParentsSave.png"));
411 
412  addParm("Filename","Path to spreadsheet file.",""); // 0
413  addParm("Existing Labels Only","Save only labels that currently exist.","Yes", booleanChoice());
414  }
415 
416  bool initialize(QWidget* parent);
417 
418  bool run()
419  {
420  if(!checkState().mesh(MESH_ANY))
421  return false;
422  Mesh* m = currentMesh();
423  return run(m, parm("Filename"), stringToBool(parm("Existing Labels Only")));
424  }
425 
426  bool run(Mesh* mesh, const QString& filename, bool saveOnlyExisting);
427 
428  };
429 
435  class mgx_EXPORT LoadParents : public Process
436  {
437  public:
438  LoadParents(const Process& process) : Process(process)
439  {
440  setName("Mesh/Lineage Tracking/Load Parents");
441  setDesc("Load map of labels to parents from a file");
442  setIcon(QIcon(":/images/Parents.png"));
443 
444  addParm("Filename","Path to label parents file.",""); // 0
445  addParm("FileType","File type, CSV(label, parent) or TXT(parent: label, label ...)","CSV",
446  QStringList() << "CSV" << "TXT"); // 1
447  addParm("Keep","Keep existing parents","No", booleanChoice()); // 2
448 
449  }
450 
451  bool initialize(QWidget* parent);
452 
453  bool run()
454  {
455  if(!checkState().mesh(MESH_ANY))
456  return false;
457  Mesh* m = currentMesh();
458  return run(m, parm("Filename"), parm("FileType"), stringToBool(parm("Keep")));
459  }
460 
461  bool run(Mesh* mesh, const QString& filename, const QString &fileType, bool keep);
462 
463  };
464 
472  class mgx_EXPORT ResetParents : public Process {
473  public:
474  ResetParents(const Process& process) : Process(process)
475  {
476  setName("Mesh/Lineage Tracking/Reset Parents");
477  setDesc("Clear mapping from parents to labels");
478  setIcon(QIcon(":/images/ParentsClear.png"));
479  }
480 
481  bool run()
482  {
483  if(!checkState().mesh(MESH_ANY))
484  return false;
485  Mesh* m = currentMesh();
486  return run(m);
487  }
488 
489  bool run(Mesh* mesh);
490  };
491 }
492 
493 #endif
mgx::StackSwapBytes::StackSwapBytes
StackSwapBytes(const Process &process)
Definition: SystemProcessLoad.hpp:42
mgx::uint
unsigned int uint
Definition: Geometry.hpp:41
Process.hpp
mgx::StackImport::ui
Ui_LoadStackDialog * ui
Definition: SystemProcessLoad.hpp:153
mgx::LoadAllData
Definition: SystemProcessLoad.hpp:331
mgx::StackImport::setImageSize
void setImageSize(uint x, uint y, uint z)
Definition: SystemProcessLoad.hpp:142
mgx::MeshLoad::MeshLoad
MeshLoad(const Process &proc)
Definition: SystemProcessLoad.hpp:211
mgx::StackImport::setImageResolution
void setImageResolution(float x, float y, float z)
Definition: SystemProcessLoad.hpp:146
mgx::Stack::work
const Store * work() const
Access the work store.
Definition: Stack.hpp:101
mgx::StackOpen
Definition: SystemProcessLoad.hpp:166
mgx::StackImport::loadedFile
QString loadedFile
Definition: SystemProcessLoad.hpp:154
mgx::ResetParents::ResetParents
ResetParents(const Process &process)
Definition: SystemProcessLoad.hpp:474
mgx::StackImport::dlg
QDialog * dlg
Definition: SystemProcessLoad.hpp:152
mgx::LoadViewFile::LoadViewFile
LoadViewFile(const Process &proc)
Definition: SystemProcessLoad.hpp:355
mgx::Stack::currentStore
const Store * currentStore() const
Returns the current store.
Definition: Stack.hpp:120
mgx::Stack::main
const Store * main() const
Access the main store.
Definition: Stack.hpp:82
mgx::StackImport::run
bool run()
Runs the process.
Definition: SystemProcessLoad.hpp:93
mgx::StackOpen::StackOpen
StackOpen(const Process &proc)
Definition: SystemProcessLoad.hpp:168
mgx::LoadAllData::LoadAllData
LoadAllData(const Process &proc)
Definition: SystemProcessLoad.hpp:334
mgx::Stack
Definition: Stack.hpp:33
mgx::SaveParents::run
bool run()
Runs the process.
Definition: SystemProcessLoad.hpp:418
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::Store::hide
void hide()
Ask the user interface to hide this store.
Definition: Store.hpp:167
mgx::MeshLoad::ui
Ui_LoadMeshDialog * ui
Definition: SystemProcessLoad.hpp:255
mgx::LoadParents
Definition: SystemProcessLoad.hpp:435
mgx::Process
Definition: Process.hpp:219
mgx::Point3f
Vector< 3, float > Point3f
Definition: CuttingSurface.hpp:25
mgx::MeshImport::MeshImport
MeshImport(const Process &proc)
Definition: SystemProcessLoad.hpp:269
mgx::stringToBool
mgx_EXPORT bool stringToBool(const QString &string)
Helper function converting a string into a boolean.
mgx::MeshLoad
Definition: SystemProcessLoad.hpp:208
mgx::LoadParents::run
bool run()
Runs the process.
Definition: SystemProcessLoad.hpp:453
mgx::ResetParents
Definition: SystemProcessLoad.hpp:472
mgx::StackImport::imageSize
Point3u imageSize
Definition: SystemProcessLoad.hpp:155
mgx::MeshImport
Definition: SystemProcessLoad.hpp:265
mgx::StackImport::StackImport
StackImport(const Process &proc)
Definition: SystemProcessLoad.hpp:76
mgx::MeshImport::ui
Ui_ImportMeshDialog * ui
Definition: SystemProcessLoad.hpp:318
mgx::SaveParents::SaveParents
SaveParents(const Process &process)
Definition: SystemProcessLoad.hpp:406
mgx::extractVersion
mgx_EXPORT QList< int > extractVersion(QIODevice &file)
mgx::MeshLoad::dlg
QDialog * dlg
Definition: SystemProcessLoad.hpp:254
mgx::Store::show
void show()
Ask the user interface to show this store.
Definition: Store.hpp:162
mgx::LoadParents::LoadParents
LoadParents(const Process &process)
Definition: SystemProcessLoad.hpp:438
mgx::Mesh
Definition: Mesh.hpp:54
mgx::StackImport::txtFile
QString txtFile
Definition: SystemProcessLoad.hpp:151
mgx::ResetParents::run
bool run()
Runs the process.
Definition: SystemProcessLoad.hpp:481
mgx::StackImport
Definition: SystemProcessLoad.hpp:73
mgx::LoadViewFile
Definition: SystemProcessLoad.hpp:353
mgx::Vector< 3, float >
mgx::StackSwapBytes::run
bool run()
Runs the process.
Definition: SystemProcessLoad.hpp:49
mgx::Point3u
Vector< 3, uint > Point3u
Definition: Geometry.hpp:75
mgx::StackSwapBytes
Definition: SystemProcessLoad.hpp:40
mgx::ResetMeshProcess::ResetMeshProcess
ResetMeshProcess(const Process &proc)
Definition: SystemProcessLoad.hpp:383
mgx::StackImport::imageFiles
QStringList imageFiles
Definition: SystemProcessLoad.hpp:156
mgx::ResetMeshProcess
Definition: SystemProcessLoad.hpp:381
mgx::MeshImport::dlg
QDialog * dlg
Definition: SystemProcessLoad.hpp:317
mgx::SaveParents
Definition: SystemProcessLoad.hpp:404
mgx::Store
Definition: Store.hpp:33