00001 #ifndef QUICKTRIMRANGETEST_H
00002 #define QUICKTRIMRANGETEST_H
00003
00004 #include "../ipc/TestRequest.h"
00005 #include "../ipc/CalibrationController.h"
00006 #include "../ipc/ScanLibrary.h"
00007 #include "../ipc/CalibrationController.hh"
00008 #include "../CalibrationControllerImpl.h"
00009
00010 #include "../SctApiAccessException.h"
00011 #include "Sct/LogicErrors.h"
00012 #include "../SctApiCall.h"
00013
00014 #include <Sct/AbcdScans.h>
00015 #include <iostream>
00016 #include <vector>
00017
00018 using namespace std;
00019 using namespace SctCalibrationController::Ipc;
00020 using namespace SctCalibrationController;
00021 using namespace Sct;
00022
00023 namespace SctCalibrationController {
00024 namespace Scripts {
00025
00026 class QuickTrimRangeTest : public TestRequestImpl {
00027 private:
00028 static const bool registeredInTestLibrary;
00029
00030 public:
00031 static Sct_CalibrationController::TestRequest_ptr instance() {
00032 static QuickTrimRangeTest tr;
00033 tr.setFitAlgorithm("Threshold");
00034 tr.setAnalysisAlgorithm("TrimRangeTest");
00035 return tr._this();
00036 }
00037
00038 virtual void startTestRealImpl(Sct_SctApi::SctApiIPC_ptr inapi, string& name, unsigned short& testVariable, unsigned long& nScans, vector<double>& testPoints) {
00039 this->api = Sct_SctApi::SctApiIPC::_duplicate(inapi);
00040
00041
00042 APICALL(api, modifyABCDVar(ST_COMPRESSION, 1), "QuickTrimRangeTest::startTest can't set compression")
00043
00044
00045 APICALL(api, modifyABCDVar(ST_EDGE_DETECT, 0), "QuickTrimRangeTest::startTest can't set edge detect")
00046
00047
00048 APICALL(api, modifyABCDVar(ST_SEND_MASK, 0), "QuickTrimRangeTest::startTest can't set send mask")
00049
00050
00051 APICALL(api, modifyABCDVar(ST_QCAL, 1), "QuickTrimRangeTest::startTest can't set qcal")
00052
00053 name = "TrimRangeTest";
00054 testVariable=ST_TRIM_RANGE;
00055 for (unsigned int i=0; i<6; ++i) {
00056 testPoints.push_back(getValue(i));
00057 }
00058 nScans = testPoints.size();
00059 }
00060
00061 virtual Sct_CalibrationController::ScanRequest_ptr getNextScanRealImpl(unsigned long index) {
00062 if (isFirstPoint(index)) {
00063
00064 APICALL(api, modifyABCDVar(ST_TRIM_RANGE, getRange(index)), "QuickTrimRangeTest::getNextScan")
00065 }
00066
00067 APICALL(api, modifyABCDVar(ST_TRIM, getValue(index)), "QuickTrimRangeTest::getNextScan")
00068
00069 Sct_CalibrationController::ScanLibrary_var sl = CalibrationControllerImpl::instance()->getScanLibrary();
00070 double offset = ranges[getRange(index)] * getValue(index);
00071 return sl->thresholdScanfCOffset(200, 1.0, offset);
00072 }
00073
00074 unsigned int getRange(unsigned int index) {
00075 return index<3 ? 0 : 1;
00076 }
00077
00078 bool isFirstPoint(unsigned int index) {
00079 return index%3 == 0;
00080 }
00081
00082 unsigned int getValue(unsigned int index) {
00083 switch (index%3) {
00084 case 0: return 1;
00085 case 1: return 6;
00086 case 2: return 15;
00087 }
00088 }
00089
00090 virtual bool canFeedbackRealImpl() {
00091 return true;
00092 }
00093
00094 virtual void endTestRealImpl() {
00095 api = Sct_SctApi::SctApiIPC::_nil();
00096 }
00097
00098 private:
00099 QuickTrimRangeTest() {}
00100 Sct_SctApi::SctApiIPC_var api;
00101 static double ranges[4];
00102 };
00103 }
00104 }
00105 #endif //TRIMRANGETEST_H