27 #include <dtkCoreSupport/dtkAbstractProcessFactory.h>
28 #include <dtkCoreSupport/dtkAbstractProcess.h>
29 #include <dtkGuiSupport/dtkColorButton.h>
36 class axlInspectorToolCreatorEllipsoidPrivate {
38 QSlider *sliderOpacity;
39 dtkColorButton *colorButton;
42 QDoubleSpinBox *center_x;
43 QDoubleSpinBox *center_y;
44 QDoubleSpinBox *center_z;
45 QDoubleSpinBox *semix;
46 QDoubleSpinBox *semix_x;
47 QDoubleSpinBox *semix_y;
48 QDoubleSpinBox *semix_z;
49 QDoubleSpinBox *semiy;
50 QDoubleSpinBox *semiy_x;
51 QDoubleSpinBox *semiy_y;
52 QDoubleSpinBox *semiy_z;
53 QDoubleSpinBox *semiz;
54 QDoubleSpinBox *semiz_x;
55 QDoubleSpinBox *semiz_y;
56 QDoubleSpinBox *semiz_z;
58 QLabel *warningMessage;
61 QGroupBox *centerGroupBox;
62 QGroupBox *semiXGroupBox;
63 QGroupBox *semiYGroupBox;
64 QGroupBox *semiZGroupBox;
66 QLabel *messageToDisplay;
70 QVBoxLayout *layout =
new QVBoxLayout(
this);
73 d->warningMessage =
new QLabel(
"Warning: your axis have been orthogonalized.");
74 d->warningMessage->setStyleSheet(
"color: #FF6600;");
75 d->warningMessage->setVisible(
false);
79 d->errorMessage =
new QLabel(
"Error: axis are parallele or nul.\nPlease check out your data and run again.");
80 d->errorMessage->setStyleSheet(
"color: #FF0000;");
81 d->errorMessage->setVisible(
false);
85 d->sliderOpacity =
new QSlider(Qt::Horizontal,
this);
87 QHBoxLayout *layoutOpacity =
new QHBoxLayout;
88 layoutOpacity->addWidget(
new QLabel(
"Opacity",
this));
89 layoutOpacity->addWidget(d->sliderOpacity);
90 d->sliderOpacity->setMaximum(100);
94 d->colorButton =
new dtkColorButton(
this);
96 QHBoxLayout *layoutColorButton =
new QHBoxLayout;
97 layoutColorButton->addWidget(
new QLabel(
"Color",
this));
98 layoutColorButton->addWidget(d->colorButton);
99 d->colorButton->setColor(QColor(
"#a0a0a4"));
102 d->center_x =
new QDoubleSpinBox(
this);
103 d->center_x->setRange(-1000, 1000);
104 d->center_x->setValue(0.0);
105 d->center_x->setSingleStep(0.1);
107 d->center_y =
new QDoubleSpinBox(
this);
108 d->center_y->setRange(-1000, 1000);
109 d->center_y->setValue(0.0);
110 d->center_y->setSingleStep(0.1);
112 d->center_z =
new QDoubleSpinBox(
this);
113 d->center_z->setRange(-1000, 1000);
114 d->center_z->setValue(0.0);
115 d->center_z->setSingleStep(0.1);
117 QHBoxLayout *layoutCenter_x =
new QHBoxLayout;
118 layoutCenter_x->addWidget(
new QLabel(
"X",
this));
119 layoutCenter_x->addWidget(d->center_x);
121 QHBoxLayout *layoutCenter_y =
new QHBoxLayout;
122 layoutCenter_y->addWidget(
new QLabel(
"Y",
this));
123 layoutCenter_y->addWidget(d->center_y);
125 QHBoxLayout *layoutCenter_z =
new QHBoxLayout;
126 layoutCenter_z->addWidget(
new QLabel(
"Z",
this));
127 layoutCenter_z->addWidget(d->center_z);
129 QVBoxLayout* layoutCenter =
new QVBoxLayout;
130 layoutCenter->addLayout(layoutCenter_x);
131 layoutCenter->addLayout(layoutCenter_y);
132 layoutCenter->addLayout(layoutCenter_z);
134 d->centerGroupBox =
new QGroupBox(
"Center");
135 d->centerGroupBox->setLayout(layoutCenter);
139 d->semix =
new QDoubleSpinBox(
this);
140 d->semix->setRange(-1000, 1000);
141 d->semix->setValue(1.00);
142 d->semix->setSingleStep(0.1);
144 d->semix_x =
new QDoubleSpinBox(
this);
145 d->semix_x->setRange(-1000, 1000);
146 d->semix_x->setValue(1.0);
147 d->semix_x->setSingleStep(0.1);
149 d->semix_y =
new QDoubleSpinBox(
this);
150 d->semix_y->setRange(-1000, 1000);
151 d->semix_y->setValue(0.0);
152 d->semix_y->setSingleStep(0.1);
154 d->semix_z =
new QDoubleSpinBox(
this);
155 d->semix_z->setRange(-1000, 1000);
156 d->semix_z->setValue(0.0);
157 d->semix_z->setSingleStep(0.1);
159 QHBoxLayout *layoutSemixRadius =
new QHBoxLayout;
160 layoutSemixRadius->addWidget(
new QLabel(
"X radius",
this));
161 layoutSemixRadius->addWidget(d->semix);
163 QHBoxLayout *layoutSemix_x =
new QHBoxLayout;
164 layoutSemix_x->addWidget(
new QLabel(
"X",
this));
165 layoutSemix_x->addWidget(d->semix_x);
167 QHBoxLayout *layoutSemix_y =
new QHBoxLayout;
168 layoutSemix_y->addWidget(
new QLabel(
"Y",
this));
169 layoutSemix_y->addWidget(d->semix_y);
171 QHBoxLayout *layoutSemix_z =
new QHBoxLayout;
172 layoutSemix_z->addWidget(
new QLabel(
"Z",
this));
173 layoutSemix_z->addWidget(d->semix_z);
175 QVBoxLayout* layoutSemiX =
new QVBoxLayout;
176 layoutSemiX->addLayout(layoutSemixRadius);
177 layoutSemiX->addLayout(layoutSemix_x);
178 layoutSemiX->addLayout(layoutSemix_y);
179 layoutSemiX->addLayout(layoutSemix_z);
181 d->semiXGroupBox =
new QGroupBox(
"Semi Axis X");
182 d->semiXGroupBox->setLayout(layoutSemiX);
186 d->semiy =
new QDoubleSpinBox(
this);
187 d->semiy->setRange(-1000, 1000);
188 d->semiy->setValue(1.00);
189 d->semiy->setSingleStep(0.1);
191 d->semiy_x =
new QDoubleSpinBox(
this);
192 d->semiy_x->setRange(-1000, 1000);
193 d->semiy_x->setValue(0.0);
194 d->semiy_x->setSingleStep(0.1);
196 d->semiy_y =
new QDoubleSpinBox(
this);
197 d->semiy_y->setRange(-1000, 1000);
198 d->semiy_y->setValue(1.0);
199 d->semiy_y->setSingleStep(0.1);
201 d->semiy_z =
new QDoubleSpinBox(
this);
202 d->semiy_z->setRange(-1000, 1000);
203 d->semiy_z->setValue(0.0);
204 d->semiy_z->setSingleStep(0.1);
206 QHBoxLayout *layoutSemiyRadius =
new QHBoxLayout;
207 layoutSemiyRadius->addWidget(
new QLabel(
"Y radius",
this));
208 layoutSemiyRadius->addWidget(d->semiy);
210 QHBoxLayout *layoutSemiy_x =
new QHBoxLayout;
211 layoutSemiy_x->addWidget(
new QLabel(
"X",
this));
212 layoutSemiy_x->addWidget(d->semiy_x);
214 QHBoxLayout *layoutSemiy_y =
new QHBoxLayout;
215 layoutSemiy_y->addWidget(
new QLabel(
"Y",
this));
216 layoutSemiy_y->addWidget(d->semiy_y);
218 QHBoxLayout *layoutSemiy_z =
new QHBoxLayout;
219 layoutSemiy_z->addWidget(
new QLabel(
"Z",
this));
220 layoutSemiy_z->addWidget(d->semiy_z);
222 QVBoxLayout* layoutSemiY =
new QVBoxLayout;
223 layoutSemiY->addLayout(layoutSemiyRadius);
224 layoutSemiY->addLayout(layoutSemiy_x);
225 layoutSemiY->addLayout(layoutSemiy_y);
226 layoutSemiY->addLayout(layoutSemiy_z);
228 d->semiYGroupBox =
new QGroupBox(
"Semi Axis Y");
229 d->semiYGroupBox->setLayout(layoutSemiY);
233 d->semiz =
new QDoubleSpinBox(
this);
234 d->semiz->setRange(-1000, 1000);
235 d->semiz->setValue(1.00);
236 d->semiz->setSingleStep(0.1);
238 d->semiz_x =
new QDoubleSpinBox(
this);
239 d->semiz_x->setRange(-1000, 1000);
240 d->semiz_x->setValue(0.0);
241 d->semiz_x->setSingleStep(0.1);
243 d->semiz_y =
new QDoubleSpinBox(
this);
244 d->semiz_y->setRange(-1000, 1000);
245 d->semiz_y->setValue(0.0);
246 d->semiz_y->setSingleStep(0.1);
248 d->semiz_z =
new QDoubleSpinBox(
this);
249 d->semiz_z->setRange(-1000, 1000);
250 d->semiz_z->setValue(1.0);
251 d->semiz_z->setSingleStep(0.1);
253 QHBoxLayout *layoutSemizRadius =
new QHBoxLayout;
254 layoutSemizRadius->addWidget(
new QLabel(
"Z radius",
this));
255 layoutSemizRadius->addWidget(d->semiz);
257 QHBoxLayout *layoutSemiz_x =
new QHBoxLayout;
258 layoutSemiz_x->addWidget(
new QLabel(
"X",
this));
259 layoutSemiz_x->addWidget(d->semiz_x);
261 QHBoxLayout *layoutSemiz_y =
new QHBoxLayout;
262 layoutSemiz_y->addWidget(
new QLabel(
"Y",
this));
263 layoutSemiz_y->addWidget(d->semiz_y);
265 QHBoxLayout *layoutSemiz_z =
new QHBoxLayout;
266 layoutSemiz_z->addWidget(
new QLabel(
"Z",
this));
267 layoutSemiz_z->addWidget(d->semiz_z);
269 QVBoxLayout* layoutSemiZ =
new QVBoxLayout;
270 layoutSemiZ->addLayout(layoutSemizRadius);
271 layoutSemiZ->addLayout(layoutSemiz_x);
272 layoutSemiZ->addLayout(layoutSemiz_y);
273 layoutSemiZ->addLayout(layoutSemiz_z);
275 d->semiZGroupBox =
new QGroupBox(
"Semi Axis Z");
276 d->semiZGroupBox->setLayout(layoutSemiZ);
279 d->messageToDisplay =
new QLabel(
"",
this);
281 d->messageToDisplay->setText(creator->
description());
283 d->messageToDisplay->setStyleSheet(
"color: #ff0000;");
286 QPushButton *button =
new QPushButton(
"Create",
this);
287 connect(button, SIGNAL(clicked()),
this, SLOT(
run()));
291 layout->addWidget(
new QLabel(
"axlInspectorToolCreatorEllipsoid",
this));
292 layout->addWidget(d->messageToDisplay);
293 layout->addWidget(d->centerGroupBox);
294 layout->addWidget(d->semiXGroupBox);
295 layout->addWidget(d->semiYGroupBox);
296 layout->addWidget(d->semiZGroupBox);
298 layout->addLayout(layoutOpacity);
299 layout->addLayout(layoutColorButton);
300 layout->addWidget(d->warningMessage);
301 layout->addWidget(d->errorMessage);
302 layout->addWidget(button);
306 connect(d->semix_x, SIGNAL(valueChanged(
double)),
this, SLOT(
onUpdateRadiusX(
double)));
307 connect(d->semix_y, SIGNAL(valueChanged(
double)),
this, SLOT(
onUpdateRadiusX(
double)));
308 connect(d->semix_z, SIGNAL(valueChanged(
double)),
this, SLOT(
onUpdateRadiusX(
double)));
310 connect(
this, SIGNAL(
radiusXUpdated(
double)), d->semix, SLOT(setValue(
double)));
311 connect(d->semix, SIGNAL(valueChanged(
double)),
this, SLOT(
onUpdateSemix(
double)));
313 connect(d->semiy_x, SIGNAL(valueChanged(
double)),
this, SLOT(
onUpdateRadiusY(
double)));
314 connect(d->semiy_y, SIGNAL(valueChanged(
double)),
this, SLOT(
onUpdateRadiusY(
double)));
315 connect(d->semiy_z, SIGNAL(valueChanged(
double)),
this, SLOT(
onUpdateRadiusY(
double)));
317 connect(
this, SIGNAL(
radiusYUpdated(
double)), d->semiy, SLOT(setValue(
double)));
318 connect(d->semiy, SIGNAL(valueChanged(
double)),
this, SLOT(
onUpdateSemiy(
double)));
320 connect(d->semiz_x, SIGNAL(valueChanged(
double)),
this, SLOT(
onUpdateRadiusZ(
double)));
321 connect(d->semiz_y, SIGNAL(valueChanged(
double)),
this, SLOT(
onUpdateRadiusZ(
double)));
322 connect(d->semiz_z, SIGNAL(valueChanged(
double)),
this, SLOT(
onUpdateRadiusZ(
double)));
324 connect(
this, SIGNAL(
radiusZUpdated(
double)), d->semiz, SLOT(setValue(
double)));
325 connect(d->semiz, SIGNAL(valueChanged(
double)),
this, SLOT(
onUpdateSemiz(
double)));
327 d->centerGroupBox->hide();
328 d->semiXGroupBox->hide();
329 d->semiYGroupBox->hide();
330 d->semiZGroupBox->hide();
340 d->controller = controller;
341 if(d->controller->size() < 4){
342 d->messageToDisplay->hide();
343 d->centerGroupBox->show();
344 d->semiXGroupBox->show();
345 d->semiYGroupBox->show();
346 d->semiZGroupBox->show();
348 d->centerGroupBox->hide();
349 d->semiXGroupBox->hide();
350 d->semiYGroupBox->hide();
351 d->semiZGroupBox->hide();
352 bool hasRigthType =
false;
355 if(dynamic_cast<axlPoint *>(d->controller->data(item)))
357 else if(dynamic_cast<axlDataDynamic *>(d->controller->data(item)))
358 if(dynamic_cast<axlDataDynamic *>(d->controller->data(item))->outputs())
359 if(dynamic_cast<axlPoint *>(dynamic_cast<axlDataDynamic *>(d->controller->data(item))->outputs()))
366 d->messageToDisplay->hide();
367 d->centerGroupBox->show();
368 d->semiXGroupBox->show();
369 d->semiYGroupBox->show();
370 d->semiZGroupBox->show();
377 QList<axlAbstractData *> list;
378 if(d->centerGroupBox->isVisible()){
379 axlPoint *center =
new axlPoint(d->center_x->value(), d->center_y->value(), d->center_z->value());
380 axlPoint *semiX =
new axlPoint(d->semix_x->value(), d->semix_y->value(), d->semix_z->value());
381 axlPoint *semiY =
new axlPoint(d->semiy_x->value(), d->semiy_y->value(), d->semiy_z->value());
382 axlPoint *semiZ =
new axlPoint(d->semiz_x->value(), d->semiz_y->value(), d->semiz_z->value());
384 list << center << semiX << semiY << semiZ;
392 axlPoint semix(d->semix_x->value(), d->semix_y->value(), d->semix_z->value());
394 double semixRadius = semix.norm();
397 axlPoint semiy(d->semiy_x->value(), d->semiy_y->value(), d->semiy_z->value());
399 double semiyRadius = semiy.norm();
402 axlPoint semiz(d->semiz_x->value(), d->semiz_y->value(), d->semiz_z->value());
404 double semizRadius = semiz.norm();
407 if (semix.norm() < 0.001) {
409 if (pv.
norm() < 0.001) {
420 if (pv.
norm() < 0.001) {
422 if (pv.
norm() < 0.001) {
439 semix *= semixRadius;
440 d->semix_x->setValue(semix.x());
441 d->semix_y->setValue(semix.y());
442 d->semix_z->setValue(semix.z());
443 semiy *= semiyRadius;
444 d->semiy_x->setValue(semiy.x());
445 d->semiy_y->setValue(semiy.y());
446 d->semiy_z->setValue(semiy.z());
447 semiz *= semizRadius;
448 d->semiz_x->setValue(semiz.x());
449 d->semiz_y->setValue(semiz.y());
450 d->semiz_z->setValue(semiz.z());
464 d->semix_x->value()*d->semix_x->value()
465 + d->semix_y->value()*d->semix_y->value()
466 + d->semix_z->value()*d->semix_z->value()
474 d->semiy_x->value()*d->semiy_x->value()
475 + d->semiy_y->value()*d->semiy_y->value()
476 + d->semiy_z->value()*d->semiy_z->value()
484 d->semiz_x->value()*d->semiz_x->value()
485 + d->semiz_y->value()*d->semiz_y->value()
486 + d->semiz_z->value()*d->semiz_z->value()
492 axlPoint semix(d->semix_x->value(), d->semix_y->value(), d->semix_z->value());
497 d->semix_x->setValue(semix.x());
498 d->semix_y->setValue(semix.y());
499 d->semix_z->setValue(semix.z());
503 axlPoint semiy(d->semiy_x->value(), d->semiy_y->value(), d->semiy_z->value());
508 d->semiy_x->setValue(semiy.x());
509 d->semiy_y->setValue(semiy.y());
510 d->semiy_z->setValue(semiy.z());
514 axlPoint semiz(d->semiz_x->value(), d->semiz_y->value(), d->semiz_z->value());
519 d->semiz_x->setValue(semiz.x());
520 d->semiz_y->setValue(semiz.y());
521 d->semiz_z->setValue(semiz.z());
528 d->warningMessage->setVisible(status == 1);
529 d->errorMessage->setVisible(status == 2);
536 if(!d->centerGroupBox->isVisible()){
538 d->messageToDisplay->show();
541 if(!(d->controller->size()==0)) {
544 if(item->text(2) ==
"Selected"|| item->text(2) ==
"Editable")
547 if(dynamic_cast<axlPoint *>(d->controller->data(item))) {
553 qDebug() <<
"To many inputs selected, only the two first points were used";
562 ellipse->
setColor(d->colorButton->color());
563 double opacity = 1.0 - 0.01 * d->sliderOpacity->value();
569 d->messageToDisplay->hide();
570 d->centerGroupBox->show();
571 d->semiXGroupBox->show();
572 d->semiYGroupBox->show();
573 d->semiZGroupBox->show();
578 d->messageToDisplay->hide();
580 axlPoint *center =
new axlPoint(d->center_x->value(), d->center_y->value(), d->center_z->value());
582 axlPoint *semiX =
new axlPoint(d->semix_x->value(), d->semix_y->value(), d->semix_z->value());
583 axlPoint *semiY =
new axlPoint(d->semiy_x->value(), d->semiy_y->value(), d->semiy_z->value());
584 axlPoint *semiZ =
new axlPoint(d->semiz_x->value(), d->semiz_y->value(), d->semiz_z->value());
588 double opacity = 1.0 - 0.01 * d->sliderOpacity->value();
590 ellipsoid->setColor(d->colorButton->color());
591 ellipsoid->setOpacity(opacity);
593 d->centerGroupBox->hide();
594 d->semiXGroupBox->hide();
595 d->semiYGroupBox->hide();
596 d->semiZGroupBox->hide();
Class axlPoint defines 3D points.
virtual QString description(void) const
virtual dtkAbstractData * output(void)
virtual void setInput(dtkAbstractData *newData, int channel)
void setOpacity(const double &opacity)
static axlPoint crossProduct(const axlPoint &lhs, const axlPoint &rhs)
Returns the cross product between lhs (coords) and rhs (coords).
void setColor(double r, double g, double b)
static double distance(const axlPoint &lhs, const axlPoint &rhs)
Returns the distance between lhs point and rhs point.
Class axlEllipsoid defines 3D ellipsoids.