00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00030 #include "quality.h"
00031
00032 #include <QGridLayout>
00033 #include <QBoxLayout>
00034 #include <QHBoxLayout>
00035 #include <QWidget>
00036 #include <q3groupbox.h>
00037 #include <QLayout>
00038 #include <QLabel>
00039 #include <QLineEdit>
00040 #include <QComboBox>
00041
00042 #include "grasp.h"
00043 #include "gws.h"
00044
00045 #ifdef USE_DMALLOC
00046 #include "dmalloc.h"
00047 #endif
00048
00049
00050
00052 const char *QualityMeasure::TYPE_LIST[] = {"Epsilon","Volume",NULL};
00053
00054 const char *QualEpsilon::type = "Epsilon";
00055 const char *QualVolume::type = "Volume";
00056
00061 QualityMeasure::QualityMeasure(qmDlgDataT *qmData)
00062 {
00063 name = qmData->qmName->text();
00064 grasp = qmData->grasp;
00065 }
00066
00067 QualityMeasure::QualityMeasure(Grasp *g, QString n)
00068 {
00069 grasp = g;
00070 name = n;
00071 }
00072
00076 QualityMeasure::~QualityMeasure()
00077 {
00078 #ifdef GRASPITDBG
00079 std::cout << "deleting QualityMeasure" << std::endl;
00080 #endif
00081 }
00082
00083
00089 void
00090 QualityMeasure::buildParamArea(qmDlgDataT *qmData)
00091 {
00092 if (!strcmp(qmData->qmType,QualEpsilon::getClassType()))
00093 QualEpsilon::buildParamArea(qmData);
00094
00095 else if (!strcmp(qmData->qmType,QualVolume::getClassType()))
00096 QualVolume::buildParamArea(qmData);
00097 }
00098
00103 QualityMeasure *
00104 QualityMeasure::createInstance(qmDlgDataT *qmData)
00105 {
00106 if (!strcmp(qmData->qmType,QualEpsilon::getClassType()))
00107 return new QualEpsilon(qmData);
00108
00109 else if (!strcmp(qmData->qmType,QualVolume::getClassType()))
00110 return new QualVolume(qmData);
00111
00112 return NULL;
00113 }
00114
00115
00117
00118
00119
00121
00123
00127 struct QualEpsilonParamT {
00128 QComboBox *gwsTypeComboBox,*twsTypeComboBox;
00129 };
00130
00136 QualEpsilon::QualEpsilon(qmDlgDataT *data) : QualityMeasure(data)
00137 {
00138 QualEpsilonParamT *params = (QualEpsilonParamT *)data->paramPtr;
00139 gws = grasp->addGWS(params->gwsTypeComboBox->currentText().latin1());
00140 }
00141
00142 QualEpsilon::QualEpsilon(Grasp *g, QString n, const char *gwsType) : QualityMeasure(g,n)
00143 {
00144 gws = grasp->addGWS( gwsType );
00145 }
00150 QualEpsilon::~QualEpsilon()
00151 {
00152 #ifdef GRASPITDBG
00153 std::cout << "deleting QualEpsilon" << std::endl;
00154 #endif
00155 grasp->removeGWS(gws);
00156 }
00157
00162 double
00163 QualEpsilon::evaluate()
00164 {
00165 double minOffset;
00166
00167 if (!gws->hyperPlanes) {
00168 #ifdef GRASPITDBG
00169 std::cout << "hyperplanes is NULL"<<std::endl;
00170 #endif
00171 return -1.0;
00172 }
00173
00174 #ifdef GRASPITDBG
00175 std::cout << "numHyperPlanes"<<gws->numHyperPlanes<<std::endl;
00176 #endif
00177
00178 for (int i=0;i<gws->numHyperPlanes;i++) {
00179 if (i==0 || -(gws->hyperPlanes[i][6])<minOffset) {
00180 minOffset = -(gws->hyperPlanes[i][6]);
00181 if (minOffset < 0) return -1.0;
00182 }
00183 }
00184
00185 val = minOffset;
00186 return val;
00187 }
00188
00189 double
00190 QualEpsilon::evaluate3D()
00191 {
00192 if (!gws->hyperPlanes) {
00193 #ifdef GRASPITDBG
00194 std::cout << "hyperplanes is NULL"<<std::endl;
00195 #endif
00196 return -1.0e3;
00197 }
00198
00199 #ifdef GRASPITDBG
00200 std::cout << "numHyperPlanes"<<gws->numHyperPlanes<<std::endl;
00201 #endif
00202
00203 double minOffset = -1.0e3;
00204 for (int i=0;i<gws->numHyperPlanes;i++) {
00205 if ( gws->hyperPlanes[i][6] > minOffset) {
00206 minOffset = gws->hyperPlanes[i][6];
00207 }
00208 }
00209 val = - minOffset;
00210 return val;
00211 }
00212
00219 void
00220 QualEpsilon::buildParamArea(qmDlgDataT *qmData)
00221 {
00222 int i;
00223 static QualEpsilonParamT params;
00224
00225 QualEpsilon *currQM = (QualEpsilon *)qmData->currQM;
00226
00227 #ifdef GRASPITDBG
00228 std::cout << "building qualepsilon" << std::endl;
00229 #endif
00230
00231 QLayout *l = new QGridLayout(qmData->settingsArea,2,2,1);
00232 l->setAutoAdd(true);
00233
00234
00235 new QLabel(QString("Limit unit GWS using:"),qmData->settingsArea);
00236 params.gwsTypeComboBox = new QComboBox(qmData->settingsArea,"gwsComboBox");
00237
00238 new QLabel(QString("Task Wrench Space (TWS):"),qmData->settingsArea);
00239 params.twsTypeComboBox = new QComboBox(qmData->settingsArea,"twsComboBox");
00240
00241
00242 for (i=0;GWS::TYPE_LIST[i];i++) {
00243 params.gwsTypeComboBox->insertItem(QString(GWS::TYPE_LIST[i]));
00244 if (currQM && !strcmp(currQM->gws->getType(),GWS::TYPE_LIST[i]))
00245 params.gwsTypeComboBox->setCurrentItem(i);
00246 }
00247
00248 params.twsTypeComboBox->insertItem(QString("Unit Ball"));
00249
00250 qmData->paramPtr = ¶ms;
00251 }
00252
00254
00255
00256
00258
00260
00264 struct QualVolumeParamT {
00265 QWidget *gwsTypeComboBox;
00266 };
00267
00273 QualVolume::QualVolume(qmDlgDataT *data) : QualityMeasure(data)
00274 {
00275 QComboBox *gwsType = (QComboBox *)data->paramPtr;
00276 gws = grasp->addGWS(gwsType->currentText().latin1());
00277 }
00278
00279 QualVolume::QualVolume(Grasp *g, QString n, const char *gwsType) : QualityMeasure(g,n)
00280 {
00281 gws = grasp->addGWS( gwsType );
00282 }
00283
00284
00289 QualVolume::~QualVolume()
00290 {
00291 #ifdef GRASPITDBG
00292 std::cout << "deleting QualVolume" << std::endl;
00293 #endif
00294 grasp->removeGWS(gws);
00295 }
00296
00301 double
00302 QualVolume::evaluate()
00303 {
00304 val = gws->hullVolume;
00305 return val;
00306 }
00307
00308 double
00309 QualVolume::evaluate3D()
00310 {
00311 val = gws->hullVolume;
00312 return val;
00313 }
00314
00319 void
00320 QualVolume::buildParamArea(qmDlgDataT *qmData)
00321 {
00322 int i;
00323 QualVolume *currQM = (QualVolume *)qmData->currQM;
00324
00325 #ifdef GRASPITDBG
00326 std::cout << "building qualvolume" << std::endl;
00327 #endif
00328
00329 QBoxLayout *l = new QHBoxLayout(qmData->settingsArea);
00330 l->setAutoAdd(true);
00331
00332
00333 new QLabel(QString("Limit unit GWS using:"),qmData->settingsArea);
00334 QComboBox *gwsComboBox = new QComboBox(qmData->settingsArea,"gwsComboBox");
00335
00336
00337 for (i=0;GWS::TYPE_LIST[i];i++) {
00338 gwsComboBox->insertItem(QString(GWS::TYPE_LIST[i]));
00339 if (currQM && !strcmp(currQM->gws->getType(),GWS::TYPE_LIST[i]))
00340 gwsComboBox->setCurrentItem(i);
00341 }
00342
00343 qmData->paramPtr = gwsComboBox;
00344 }
00345
00347
00348
00349