Developer documentation | Axl-2.5.1

axlInspectorToolCreatorCircleArc.cpp
Go to the documentation of this file.
1 /* axlInspectorToolCreatorCircleArc.cpp ---
2  *
3  * Author: Valentin Michelet
4  * Copyright (C) 2008 - Valentin Michelet, Inria.
5  * Created: Tue Nov 9 16:58:59 2010 (+0100)
6  * Version: $Id$
7  * Last-Updated: Tue Nov 9 17:09:38 2010 (+0100)
8  * By: Valentin Michelet
9  * Update #: 19
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 
21 
24 
25 #include <axlCore/axlPoint.h>
26 #include <axlCore/axlCircleArc.h>
27 #include <axlCore/axlInteger.h>
28 #include <axlCore/axlDataDynamic.h>
30 #include <dtkCoreSupport/dtkAbstractProcessFactory.h>
31 #include <dtkCoreSupport/dtkAbstractProcess.h>
32 #include <dtkGuiSupport/dtkColorButton.h>
33 
34 #include <QtGui>
35 
36 class axlInspectorToolCreatorCircleArcPrivate {
37 public:
38  QSlider *sliderOpacity;
39  dtkColorButton *colorButton;
40  axlInspectorObjectController *controller;
41 
42  QDoubleSpinBox* coordinatePoint1_x;
43  QDoubleSpinBox* coordinatePoint1_y;
44  QDoubleSpinBox* coordinatePoint1_z;
45 
46  QDoubleSpinBox* coordinatePoint2_x;
47  QDoubleSpinBox* coordinatePoint2_y;
48  QDoubleSpinBox* coordinatePoint2_z;
49 
50  QDoubleSpinBox* coordinateCenter_x;
51  QDoubleSpinBox* coordinateCenter_y;
52  QDoubleSpinBox* coordinateCenter_z;
53 
54  QDoubleSpinBox* coordinateNormal_x;
55  QDoubleSpinBox* coordinateNormal_y;
56  QDoubleSpinBox* coordinateNormal_z;
57 
58  QLabel* coordinateNormalLabel_x;
59  QLabel* coordinateNormalLabel_y;
60  QLabel* coordinateNormalLabel_z;
61 
62  QCheckBox* counterClockWiseCheckBox;
63 
64  QLabel* radiusLabel;
65 
66  QLabel* linedUpMessage;
67  QLabel* centerModifiedMessage;
68 };
69 
71  axlInspectorToolCreator(parent), d(new axlInspectorToolCreatorCircleArcPrivate) {
72 
73  //Lined up points message
74  d->linedUpMessage = new QLabel("Point1, Point2 and Center are lined up.\nPlease provide the normal of the plane\ncontaining the circle arc.");
75  d->linedUpMessage->setStyleSheet("color: #0000FF;");
76  d->linedUpMessage->setVisible(false);
77 
78  //Center modified message
79  d->centerModifiedMessage = new QLabel("Warning: your center has been modified\nto be on the mediatory of [Point1;Point2].");
80  d->centerModifiedMessage->setStyleSheet("color: #FF6600;");
81  d->centerModifiedMessage->setVisible(false);
82 
83  //OPACITY//
84  d->sliderOpacity = new QSlider(Qt::Horizontal, this);
85 
86  QHBoxLayout *layoutOpacity = new QHBoxLayout;
87  layoutOpacity->addWidget(new QLabel("Opacity",this));
88  layoutOpacity->addWidget(d->sliderOpacity);
89  d->sliderOpacity->setMaximum(100);
90 
91  //COLOR//
92  d->colorButton = new dtkColorButton(this);
93 
94  QHBoxLayout *layoutColorButton = new QHBoxLayout;
95  layoutColorButton->addWidget(new QLabel("Color",this));
96  layoutColorButton->addWidget(d->colorButton);
97  d->colorButton->setColor(QColor("#a0a0a4"));
98 
99  //POINT1//
100  d->coordinatePoint1_x = new QDoubleSpinBox(this);
101  d->coordinatePoint1_x->setRange(-1000, 1000);
102  d->coordinatePoint1_x->setValue(1.0);
103  d->coordinatePoint1_x->setSingleStep(0.1);
104 
105  QHBoxLayout *layoutPoint1_x = new QHBoxLayout;
106  layoutPoint1_x->addWidget(new QLabel("X",this));
107  layoutPoint1_x->addWidget(d->coordinatePoint1_x);
108 
109  d->coordinatePoint1_y = new QDoubleSpinBox(this);
110  d->coordinatePoint1_y->setRange(-1000, 1000);
111  d->coordinatePoint1_y->setValue(0.0);
112  d->coordinatePoint1_y->setSingleStep(0.1);
113 
114  QHBoxLayout *layoutPoint1_y = new QHBoxLayout;
115  layoutPoint1_y->addWidget(new QLabel("Y",this));
116  layoutPoint1_y->addWidget(d->coordinatePoint1_y);
117 
118  d->coordinatePoint1_z = new QDoubleSpinBox(this);
119  d->coordinatePoint1_z->setRange(-1000, 1000);
120  d->coordinatePoint1_z->setValue(0.0);
121  d->coordinatePoint1_z->setSingleStep(0.1);
122 
123  QHBoxLayout *layoutPoint1_z = new QHBoxLayout;
124  layoutPoint1_z->addWidget(new QLabel("Z",this));
125  layoutPoint1_z->addWidget(d->coordinatePoint1_z);
126 
127  QVBoxLayout *layoutPoint1 = new QVBoxLayout;
128 
129  layoutPoint1->addWidget(new QLabel("Point1:", this));
130  layoutPoint1->addLayout(layoutPoint1_x);
131  layoutPoint1->addLayout(layoutPoint1_y);
132  layoutPoint1->addLayout(layoutPoint1_z);
133 
134  //POINT2//
135  d->coordinatePoint2_x = new QDoubleSpinBox(this);
136  d->coordinatePoint2_x->setRange(-1000, 1000);
137  d->coordinatePoint2_x->setValue(0.0);
138  d->coordinatePoint2_x->setSingleStep(0.1);
139 
140  QHBoxLayout *layoutPoint2_x = new QHBoxLayout;
141  layoutPoint2_x->addWidget(new QLabel("X",this));
142  layoutPoint2_x->addWidget(d->coordinatePoint2_x);
143 
144  d->coordinatePoint2_y = new QDoubleSpinBox(this);
145  d->coordinatePoint2_y->setRange(-1000, 1000);
146  d->coordinatePoint2_y->setValue(1.0);
147  d->coordinatePoint2_y->setSingleStep(0.1);
148 
149  QHBoxLayout *layoutPoint2_y = new QHBoxLayout;
150  layoutPoint2_y->addWidget(new QLabel("Y",this));
151  layoutPoint2_y->addWidget(d->coordinatePoint2_y);
152 
153  d->coordinatePoint2_z = new QDoubleSpinBox(this);
154  d->coordinatePoint2_z->setRange(-1000, 1000);
155  d->coordinatePoint2_z->setValue(0.0);
156  d->coordinatePoint2_z->setSingleStep(0.1);
157 
158  QHBoxLayout *layoutPoint2_z = new QHBoxLayout;
159  layoutPoint2_z->addWidget(new QLabel("Z",this));
160  layoutPoint2_z->addWidget(d->coordinatePoint2_z);
161 
162  QVBoxLayout *layoutPoint2 = new QVBoxLayout;
163 
164  layoutPoint2->addWidget(new QLabel("Point2:", this));
165  layoutPoint2->addLayout(layoutPoint2_x);
166  layoutPoint2->addLayout(layoutPoint2_y);
167  layoutPoint2->addLayout(layoutPoint2_z);
168 
169  //CENTER//
170  d->coordinateCenter_x = new QDoubleSpinBox(this);
171  d->coordinateCenter_x->setRange(-1000, 1000);
172  d->coordinateCenter_x->setValue(0.0);
173  d->coordinateCenter_x->setSingleStep(0.1);
174 
175  QHBoxLayout *layoutCenter_x = new QHBoxLayout;
176  layoutCenter_x->addWidget(new QLabel("X",this));
177  layoutCenter_x->addWidget(d->coordinateCenter_x);
178 
179  d->coordinateCenter_y = new QDoubleSpinBox(this);
180  d->coordinateCenter_y->setRange(-1000, 1000);
181  d->coordinateCenter_y->setValue(0.0);
182  d->coordinateCenter_y->setSingleStep(0.1);
183 
184  QHBoxLayout *layoutCenter_y = new QHBoxLayout;
185  layoutCenter_y->addWidget(new QLabel("Y",this));
186  layoutCenter_y->addWidget(d->coordinateCenter_y);
187 
188  d->coordinateCenter_z = new QDoubleSpinBox(this);
189  d->coordinateCenter_z->setRange(-1000, 1000);
190  d->coordinateCenter_z->setValue(0.0);
191  d->coordinateCenter_z->setSingleStep(0.1);
192 
193  QHBoxLayout *layoutCenter_z = new QHBoxLayout;
194  layoutCenter_z->addWidget(new QLabel("Z",this));
195  layoutCenter_z->addWidget(d->coordinateCenter_z);
196 
197  QVBoxLayout *layoutCenter = new QVBoxLayout;
198 
199  layoutCenter->addWidget(new QLabel("Center:", this));
200  layoutCenter->addLayout(layoutCenter_x);
201  layoutCenter->addLayout(layoutCenter_y);
202  layoutCenter->addLayout(layoutCenter_z);
203 
204  //RADIUS//
205  d->radiusLabel = new QLabel("1.0");
206 
207  QHBoxLayout *layoutRadius = new QHBoxLayout;
208  layoutRadius->addWidget(new QLabel("Radius",this));
209  layoutRadius->addWidget(d->radiusLabel);
210 
211  //NORMAL//
212  d->coordinateNormal_x = new QDoubleSpinBox(this);
213  d->coordinateNormal_x->setRange(-1000, 1000);
214  d->coordinateNormal_x->setValue(0.0);
215  d->coordinateNormal_x->setSingleStep(0.1);
216 
217  d->coordinateNormalLabel_x = new QLabel("0.0");
218 
219  QHBoxLayout *layoutNormal_x = new QHBoxLayout;
220  layoutNormal_x->addWidget(new QLabel("X",this));
221  layoutNormal_x->addWidget(d->coordinateNormalLabel_x);
222  layoutNormal_x->addWidget(d->coordinateNormal_x);
223 
224  d->coordinateNormal_y = new QDoubleSpinBox(this);
225  d->coordinateNormal_y->setRange(-1000, 1000);
226  d->coordinateNormal_y->setValue(0.0);
227  d->coordinateNormal_y->setSingleStep(0.1);
228 
229  d->coordinateNormalLabel_y = new QLabel("0.0");
230 
231  QHBoxLayout *layoutNormal_y = new QHBoxLayout;
232  layoutNormal_y->addWidget(new QLabel("Y",this));
233  layoutNormal_y->addWidget(d->coordinateNormalLabel_y);
234  layoutNormal_y->addWidget(d->coordinateNormal_y);
235 
236  d->coordinateNormal_z = new QDoubleSpinBox(this);
237  d->coordinateNormal_z->setRange(-1000, 1000);
238  d->coordinateNormal_z->setValue(1.0);
239  d->coordinateNormal_z->setSingleStep(0.1);
240 
241  d->coordinateNormalLabel_z = new QLabel("1.0");
242 
243  QHBoxLayout *layoutNormal_z = new QHBoxLayout;
244  layoutNormal_z->addWidget(new QLabel("Z",this));
245  layoutNormal_z->addWidget(d->coordinateNormalLabel_z);
246  layoutNormal_z->addWidget(d->coordinateNormal_z);
247 
248  QVBoxLayout *layoutNormal = new QVBoxLayout;
249 
250  layoutNormal->addWidget(new QLabel("Normal:", this));
251  layoutNormal->addWidget(d->linedUpMessage);
252  layoutNormal->addLayout(layoutNormal_x);
253  layoutNormal->addLayout(layoutNormal_y);
254  layoutNormal->addLayout(layoutNormal_z);
255 
256  d->coordinateNormal_x->setVisible(false);
257  d->coordinateNormal_y->setVisible(false);
258  d->coordinateNormal_z->setVisible(false);
259 
260  //COUNTER CLOCK WISE CHECK BOX
261  d->counterClockWiseCheckBox = new QCheckBox("Counter Clock Wise", this);
262  d->counterClockWiseCheckBox->setChecked(true);
263 
264  //BUTTON//
265  QPushButton *button = new QPushButton("Create", this);
266  connect(button, SIGNAL(clicked()), this, SLOT(run()));
267 
268  //LAYOUTS//
269  QVBoxLayout *layout = new QVBoxLayout(this);
270 
271  layout->addWidget(new QLabel("axlInspectorToolCreatorCircleArc", this));
272  layout->addLayout(layoutPoint1);
273  layout->addLayout(layoutPoint2);
274  layout->addLayout(layoutCenter);
275  layout->addLayout(layoutRadius);
276  layout->addLayout(layoutNormal);
277  layout->addWidget(d->counterClockWiseCheckBox);
278  layout->addLayout(layoutOpacity);
279  layout->addLayout(layoutColorButton);
280  layout->addWidget(d->centerModifiedMessage);
281  layout->addWidget(button);
282 
283  connect(d->coordinatePoint1_x, SIGNAL(valueChanged(double)), this, SLOT(manageNormal(double)));
284  connect(d->coordinatePoint1_y, SIGNAL(valueChanged(double)), this, SLOT(manageNormal(double)));
285  connect(d->coordinatePoint1_z, SIGNAL(valueChanged(double)), this, SLOT(manageNormal(double)));
286 
287  connect(d->coordinatePoint1_x, SIGNAL(valueChanged(double)), this, SLOT(manageCenter(double)));
288  connect(d->coordinatePoint1_y, SIGNAL(valueChanged(double)), this, SLOT(manageCenter(double)));
289  connect(d->coordinatePoint1_z, SIGNAL(valueChanged(double)), this, SLOT(manageCenter(double)));
290 
291  connect(d->coordinatePoint2_x, SIGNAL(valueChanged(double)), this, SLOT(manageNormal(double)));
292  connect(d->coordinatePoint2_y, SIGNAL(valueChanged(double)), this, SLOT(manageNormal(double)));
293  connect(d->coordinatePoint2_z, SIGNAL(valueChanged(double)), this, SLOT(manageNormal(double)));
294 
295  connect(d->coordinatePoint2_x, SIGNAL(valueChanged(double)), this, SLOT(manageCenter(double)));
296  connect(d->coordinatePoint2_y, SIGNAL(valueChanged(double)), this, SLOT(manageCenter(double)));
297  connect(d->coordinatePoint2_z, SIGNAL(valueChanged(double)), this, SLOT(manageCenter(double)));
298 
299  connect(d->coordinateCenter_x, SIGNAL(valueChanged(double)), this, SLOT(manageNormal(double)));
300  connect(d->coordinateCenter_y, SIGNAL(valueChanged(double)), this, SLOT(manageNormal(double)));
301  connect(d->coordinateCenter_z, SIGNAL(valueChanged(double)), this, SLOT(manageNormal(double)));
302 
303  connect(d->counterClockWiseCheckBox, SIGNAL(clicked()), this, SLOT(inverseNormal()));
304 }
305 
307  delete d;
308  d = NULL;
309 }
310 
312 
313 // d->controller = controller;
314 // if(d->controller->size() < 3){
315 // //d->coordinates->show();
316 // }else{
317 // bool hasRigthType = false;
318 // int nbRigthType = 0;
319 // foreach(axlInspectorObjectManagerTreeItem *item, d->controller->items()){
320 // if(dynamic_cast<axlPoint *>(d->controller->data(item)))
321 // nbRigthType++;
322 // else if(dynamic_cast<axlDataDynamic *>(d->controller->data(item)))
323 // if(dynamic_cast<axlDataDynamic *>(d->controller->data(item))->outputs())
324 // if(dynamic_cast<axlPoint *>(dynamic_cast<axlDataDynamic *>(d->controller->data(item))->outputs()))
325 // nbRigthType++;
326 // }
327 
328 // if(nbRigthType > 2)
329 // hasRigthType = true;
330 // //if(!hasRigthType)
331 // //d->coordinates->show();
332 // }
333 }
334 
336  QList<axlAbstractData *> list;
337  bool condition = true;
338  if(condition){
339  axlPoint *newCenter = new axlPoint(d->coordinateCenter_x->value(), d->coordinateCenter_y->value(), d->coordinateCenter_z->value());
340  axlPoint *point1 = new axlPoint(d->coordinatePoint1_x->value(), d->coordinatePoint1_y->value(), d->coordinatePoint1_z->value());
341  axlPoint *point2 = new axlPoint(d->coordinatePoint2_x->value(), d->coordinatePoint2_y->value(), d->coordinatePoint2_z->value());
342  axlPoint *normal = new axlPoint(d->coordinateNormal_x->value(), d->coordinateNormal_y->value(), d->coordinateNormal_z->value());
343  axlInteger *direct = new axlInteger(d->counterClockWiseCheckBox->isChecked());
344 
345  list << newCenter << point1 << point2 << normal << direct;
346 
347  }
348  return list;
349 
350 }
351 
353  axlPoint p1(d->coordinatePoint1_x->text().toDouble(), d->coordinatePoint1_y->text().toDouble(), d->coordinatePoint1_z->text().toDouble());
354  axlPoint p2(d->coordinatePoint2_x->text().toDouble(), d->coordinatePoint2_y->text().toDouble(), d->coordinatePoint2_z->text().toDouble());
355  axlPoint c(d->coordinateCenter_x->text().toDouble(), d->coordinateCenter_y->text().toDouble(), d->coordinateCenter_z->text().toDouble());
356 
357  d->radiusLabel->setText(QString("%1").arg(axlPoint::distance(p1, c)));
358 
359  axlPoint calculatedNormal = axlPoint::crossProduct((p1-c), (p2-c)).normalized();
360  bool linedUpPoints = calculatedNormal.norm() < 0.001;
361 
362  d->coordinateNormal_x->setVisible(linedUpPoints);
363 
364  d->coordinateNormalLabel_x->setVisible(!linedUpPoints);
365  d->coordinateNormalLabel_x->setText(QString("%1").arg(calculatedNormal.x()));
366 
367  d->coordinateNormal_y->setVisible(linedUpPoints);
368 
369  d->coordinateNormalLabel_y->setVisible(!linedUpPoints);
370  d->coordinateNormalLabel_y->setText(QString("%1").arg(calculatedNormal.y()));
371 
372  d->coordinateNormal_z->setVisible(linedUpPoints);
373 
374  d->coordinateNormalLabel_z->setVisible(!linedUpPoints);
375  d->coordinateNormalLabel_z->setText(QString("%1").arg(calculatedNormal.z()));
376 
377  d->linedUpMessage->setVisible(linedUpPoints);
378 }
379 
381  axlPoint p1(d->coordinatePoint1_x->text().toDouble(), d->coordinatePoint1_y->text().toDouble(), d->coordinatePoint1_z->text().toDouble());
382  axlPoint p2(d->coordinatePoint2_x->text().toDouble(), d->coordinatePoint2_y->text().toDouble(), d->coordinatePoint2_z->text().toDouble());
383  axlPoint c(d->coordinateCenter_x->text().toDouble(), d->coordinateCenter_y->text().toDouble(), d->coordinateCenter_z->text().toDouble());
384 
385  axlPoint calculatedNormal;
386  calculatedNormal = axlPoint(d->coordinateNormal_x->value(), d->coordinateNormal_y->value(), d->coordinateNormal_z->value());
387 
388  axlPoint p1p2(p2-p1);
389  axlPoint middle((p1+p2)/2);
390  axlPoint mediatory = axlPoint::crossProduct(p1p2, calculatedNormal).normalized();
391  double ps = axlPoint::dotProduct(mediatory, (c-middle));
392  axlPoint newCenter = middle+mediatory*ps;
393 
394  d->coordinateCenter_x->setValue(newCenter.x());
395  d->coordinateCenter_y->setValue(newCenter.y());
396  d->coordinateCenter_z->setValue(newCenter.z());
397 }
398 
400  d->coordinateNormal_x->setValue(-d->coordinateNormal_x->value());
401  d->coordinateNormal_y->setValue(-d->coordinateNormal_y->value());
402  d->coordinateNormal_z->setValue(-d->coordinateNormal_z->value());
403 
404  d->coordinateNormalLabel_x->setText(QString("%1").arg(-d->coordinateNormalLabel_x->text().toDouble()));
405  d->coordinateNormalLabel_y->setText(QString("%1").arg(-d->coordinateNormalLabel_y->text().toDouble()));
406  d->coordinateNormalLabel_z->setText(QString("%1").arg(-d->coordinateNormalLabel_z->text().toDouble()));
407 }
408 
410  axlPoint oldCenter(d->coordinateCenter_x->value(), d->coordinateCenter_y->value(), d->coordinateCenter_z->value());
411  manageCenter(0.0);
412  axlPoint newCenter(d->coordinateCenter_x->value(), d->coordinateCenter_y->value(), d->coordinateCenter_z->value());
413 
414  d->centerModifiedMessage->setVisible(axlPoint::distance(oldCenter, newCenter) > 0.01);
415 
416  axlPoint point1(d->coordinatePoint1_x->value(), d->coordinatePoint1_y->value(), d->coordinatePoint1_z->value());
417  axlPoint point2(d->coordinatePoint2_x->value(), d->coordinatePoint2_y->value(), d->coordinatePoint2_z->value());
418  axlPoint normal(d->coordinateNormal_x->value(), d->coordinateNormal_y->value(), d->coordinateNormal_z->value());
419 
420  axlCircleArc* newArc = new axlCircleArc(point1, point2, newCenter, normal, d->counterClockWiseCheckBox->isChecked());
421  newArc->setColor(d->colorButton->color());
422  double opacity = 1.0 - 0.01 * d->sliderOpacity->value();
423  newArc->setOpacity(opacity);
424  emit dataInserted(newArc);
425 }
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
double norm(void) const
Definition: axlPoint.cpp:450
axlPoint & normalized(void)
Definition: axlPoint.cpp:421
static double dotProduct(const axlPoint &lhs, const axlPoint &rhs)
Definition: axlPoint.cpp:508
double y
Definition: axlPoint.h:37
Class axlInteger defines an integer.
Definition: axlInteger.h:28
double z
Definition: axlPoint.h:38
void dataInserted(axlAbstractData *data)
static axlPoint crossProduct(const axlPoint &lhs, const axlPoint &rhs)
Returns the cross product between lhs (coords) and rhs (coords).
Definition: axlPoint.cpp:485
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.
Definition: axlPoint.cpp:459
double x
Definition: axlPoint.h:37
void setController(axlInspectorObjectController *controller)
QList< axlAbstractData * > returnInputsList(void)