CustusX  2023.01.05-dev+develop.0da12
An IGT application
cxGenericScriptFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 #ifndef CXGENERICSCRIPTFILTER_H
12 #define CXGENERICSCRIPTFILTER_H
13 
14 #include "cxFilterImpl.h"
15 //#include <QProcess>
16 #include "cxSettings.h"
17 #include "cxProcessWrapper.h"
18 #include <QColor>
20 
21 
22 namespace cx
23 {
24 
25 struct cxResourceFilter_EXPORT CommandStringVariables
26 {
27  QString inputFilePath;
28  QString outputFilePath;
29  QString envPath;
30  QString scriptFilePath;
31  QString cArguments;
32  QString scriptEngine;
33  QString model;
34 
35  CommandStringVariables(QString parameterFilePath, ImagePtr input);
36 };
37 
38 struct cxResourceFilter_EXPORT OutputVariables
39 {
42  QStringList mOutputColorList;
43  QStringList mOutputClasses;
44 
45  OutputVariables(QString parameterFilePath);
46 };
47 
56 class cxResourceFilter_EXPORT GenericScriptFilter : public FilterImpl
57 {
58  Q_OBJECT
59 
60 public:
62  virtual ~GenericScriptFilter();
63 
64  virtual QString getType() const;
65  virtual QString getName() const;
66  virtual QString getHelp() const;
67 
68  virtual bool execute();
69  virtual bool postProcess();
70 
71  // extensions:
72  FilePathPropertyPtr getParameterFile(QDomElement root);
73  void setParameterFilePath(QString path);
74  FilePreviewPropertyPtr getIniFileOption(QDomElement root);
76 
77 protected:
78  virtual void createOptions();
79  virtual void createInputTypes();
80  virtual void createOutputTypes();
81  QString createCommandString(ImagePtr input);
82  bool runCommandStringAndWait(QString command);
83  QString getCustomPath();
84  void setupOutputColors(QStringList colorList);
85  QColor createColor(QStringList color);
86  QColor getDefaultColor();
87  void createOutputMesh(QColor color);
88  bool readGeneratedSegmentationFiles(bool createOutputVolume, bool createOutputMesh);
89  QString createImageName(QString parentName, QString filePath);
90  void createOutputVolume();
91  void deleteNotUsedFiles(QString fileNameMhd, bool createOutputVolume);
92  QString getScriptPath();
93  QString getInputFilePath(ImagePtr input);
94  QString getOutputFilePath(ImagePtr input);
95 
96  CommandStringVariables createCommandStringVariables(ImagePtr input);
97  QString standardCommandString(CommandStringVariables variables);
98  bool isUsingDeepSintefEngine(CommandStringVariables variables);
99  QString deepSintefCommandString(CommandStringVariables variables);
100 
101  bool environmentExist(QString path);
102  QString getEnvironmentPath(CommandStringVariables variables);
103  QString getEnvironmentBasePath(QString environmentPath);
104  QString findRequirementsFileLocation(QString path);
105  bool createVirtualPythonEnvironment(QString environmentPath, QString requirementsPath);
106  bool isVirtualEnvironment(QString path);
107  QString getFixedEnvironmentSubdir();
108 
111 
117  QStringList mOutoutOrgans;
119  QList<QColor> mOutputColors;
120  QStringList mOutputClasses;
121 
125 
126 protected slots:
127  void scriptFileChanged();
128  void processStateChanged();
129  void processFinished(int code, QProcess::ExitStatus status);
130  void processError(QProcess::ProcessError error);
131  void processReadyRead();
132  void processReadyReadError();
133  bool createProcess();
134  bool deleteProcess();
135  bool disconnectProcess();
136 
137 };
138 typedef boost::shared_ptr<class GenericScriptFilter> GenericScriptFilterPtr;
139 
140 
141 } // namespace cx
142 
143 
144 
145 #endif // CXGENERICSCRIPTFILTER_H
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:27
boost::shared_ptr< class FilePreviewProperty > FilePreviewPropertyPtr
SelectDataStringPropertyBasePtr mOutputImageSelectDataPtr
FilePreviewPropertyPtr mScriptFilePreview
StringPropertySelectMeshPtr mOutputMeshSelectMeshPtr
boost::shared_ptr< class SelectDataStringPropertyBase > SelectDataStringPropertyBasePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
boost::shared_ptr< class GenericScriptFilter > GenericScriptFilterPtr
PatientModelServicePtr mPatientModelService
FilePathPropertyPtr mScriptFile
boost::shared_ptr< class ProcessWrapper > ProcessWrapperPtr
Definition: cxMainWindow.h:41
boost::shared_ptr< class FilePathProperty > FilePathPropertyPtr
boost::shared_ptr< class BoolProperty > BoolPropertyPtr
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
boost::shared_ptr< class StringPropertySelectMesh > StringPropertySelectMeshPtr
Namespace for all CustusX production code.