AlgorithmPattern.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef ALGORITHMPATTERN_H
00011 #define ALGORITHMPATTERN_H
00012
00013 #include "AlgorithmShell.h"
00014 #include "ApplicationServices.h"
00015 #include "DesktopServices.h"
00016 #include "Location.h"
00017 #include "ModelServices.h"
00018 #include "PlugInManagerServices.h"
00019 #include "Progress.h"
00020 #include "Resource.h"
00021 #include "TypesFile.h"
00022 #include "UtilityServices.h"
00023
00024 class BitMask;
00025 class QDialog;
00026 class RasterElement;
00027 class SpatialDataView;
00028 class Step;
00029
00030 #include <boost/any.hpp>
00031 #include <vector>
00032 #include <string>
00033 #include <functional>
00034 #include <memory>
00035
00036 class AlgorithmReporter
00037 {
00038 public:
00039 AlgorithmReporter(Progress* pProgress);
00040 virtual ~AlgorithmReporter();
00041
00042 void reportProgress(ReportingLevel rptLevel, int progress, std::string message) const;
00043 int getProgressPercent() const;
00044 void addStage(std::string stageMessage, int weight);
00045 void nextStage();
00046 void clearStages();
00047
00048 protected:
00049 Progress* getProgress() const;
00050 Step* mpStep;
00051
00052 private:
00053 AlgorithmReporter(const AlgorithmReporter& reporter) {}
00054
00055 virtual void updateProgress(ReportingLevel rptLevel, int progress, std::string message) const;
00056 Progress* mpProgress;
00057 class Stage
00058 {
00059 public:
00060 std::string mMessage;
00061 int mWeight;
00062 int mWeightSum;
00063 Stage(std::string message, int weight, int weightSum = 0);
00064 Stage(const Stage& stage);
00065 };
00066 std::vector<Stage> mStages;
00067 size_t mCurrentStage;
00068 int mWeightSum;
00069 };
00070
00071 class AlgorithmPattern : public AlgorithmReporter
00072 {
00073 public:
00074 AlgorithmPattern(RasterElement* pRasterElement, Progress* pProgress, bool interactive, const BitMask* pRoi);
00075 virtual ~AlgorithmPattern();
00076
00077 bool runPreprocess();
00078 bool runProcess();
00079 bool runPostprocess();
00080 bool hasAbort() const;
00081 bool abort();
00082
00083 void elementDeleted(Subject& subject, const std::string& signal, const boost::any& v);
00084
00085 RasterElement* getRasterElement() const;
00086 int getRowOffset() const;
00087 bool setGuiData(void* pAlgorithmData);
00088 bool isInteractive() const;
00089
00090 protected:
00091 bool determinePixelsToProcess() const;
00092 const BitMask* getPixelsToProcess() const;
00093 void setRoi(const BitMask* pRoi);
00094 void displayThresholdResults(RasterElement* pRasterElement, ColorType color, PassArea passArea,
00095 double firstThreshold, double secondThreshold, Opticks::PixelOffset offset = Opticks::PixelOffset());
00096 void displayPseudocolorResults(RasterElement* pRasterElement, std::vector<std::string>& sigNames,
00097 Opticks::PixelOffset offset = Opticks::PixelOffset());
00098
00099 Service<ApplicationServices> mpApplicationServices;
00100 Service<DesktopServices> mpDesktopServices;
00101 Service<PlugInManagerServices> mpPlugInManagerServices;
00102 Service<ModelServices> mpModelServices;
00103 Service<UtilityServices> mpUtilityServices;
00104 ObjectFactory* mpObjFact;
00105
00106 private:
00107 AlgorithmPattern(const AlgorithmPattern& rhs);
00108 virtual bool preprocess() = 0;
00109 virtual bool processAll() = 0;
00110 virtual bool postprocess() = 0;
00111 virtual bool initialize(void* pAlgorithmData) = 0;
00112 virtual bool canAbort() const = 0;
00113 virtual bool doAbort() = 0;
00114
00115 int getSubCube(int startRow, int numRows);
00116
00117 RasterElement* mpRasterElement;
00118 RasterElement* mpSubCube;
00119 const BitMask* mpRoi;
00120 mutable BitMask* mpPixelsToProcess;
00121 int mRowOffset;
00122 bool mInteractive;
00123 };
00124
00125 class AlgorithmRunner
00126 {
00127 public:
00128 bool runAlgorithmFromGuiInputs();
00129
00130 private:
00131 virtual bool extractFromGui() = 0;
00132 virtual bool setupAndRunAlgorithm() = 0;
00133 virtual bool needToRunAlgorithm()
00134 {
00135 return true;
00136 }
00137 };
00138
00139
00140
00141
00142 class AlgorithmPlugIn : public AlgorithmShell, public AlgorithmRunner
00143 {
00144 public:
00145
00146 ~AlgorithmPlugIn();
00147 bool setBatch();
00148 bool setInteractive();
00149 bool getInputSpecification(PlugInArgList*& pArgList);
00150 bool getOutputSpecification(PlugInArgList*& pArgList);
00151 bool execute(PlugInArgList* pInArgList, PlugInArgList* pOutArgList);
00152 bool abort();
00153
00154 protected:
00155 AlgorithmPlugIn(void* pAlgData);
00156 void setAlgorithmPattern(Resource<AlgorithmPattern> pAlgorithm);
00157 bool isInteractive() const;
00158 bool setupAndRunAlgorithm();
00159
00160 Service<ApplicationServices> mpApplicationServices;
00161 Service<DesktopServices> mpDesktopServices;
00162 Service<PlugInManagerServices> mpPlugInManagerServices;
00163 Service<ModelServices> mpModelServices;
00164 Service<UtilityServices> mpUtilityServices;
00165 ObjectFactory* mpObjFact;
00166
00167 private:
00168 virtual bool canRunBatch() const = 0;
00169 virtual bool canRunInteractive() const = 0;
00170 virtual bool populateBatchInputArgList(PlugInArgList*) = 0;
00171 virtual bool populateInteractiveInputArgList(PlugInArgList*) = 0;
00172 virtual bool populateDefaultOutputArgList(PlugInArgList*) = 0;
00173 virtual bool setActualValuesInOutputArgList(PlugInArgList*) = 0;
00174 virtual bool parseInputArgList(PlugInArgList*) = 0;
00175 virtual void propagateAbort() = 0;
00176 virtual QDialog* getGui(void* pAlgorithmData) = 0;
00177 bool runDialog(QDialog* pDialog);
00178
00179 Resource<AlgorithmPattern> mpAlgorithm;
00180 bool mInteractive;
00181 void* mpAlgorithmData;
00182 };
00183
00184 #endif