Developer documentation | Axl-2.5.1

axlInspectorToolCreatorTorus.cpp
Go to the documentation of this file.
1 /* axlInspectorToolCreatorTorus.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/axlTorus.h>
28 #include <dtkCoreSupport/dtkAbstractProcessFactory.h>
29 #include <dtkCoreSupport/dtkAbstractProcess.h>
30 #include <dtkGuiSupport/dtkColorButton.h>
31 
32 #include <axlCore/axlDouble.h>
33 #include <axlCore/axlDataDynamic.h>
35 
36 #include <QtGui>
37 
38 class axlInspectorToolCreatorTorusPrivate {
39 public:
40  QSlider *sliderOpacity;
41  dtkColorButton *colorButton;
42  axlInspectorObjectController *controller;
43 
44  QDoubleSpinBox* coordinateCenter_x;
45  QDoubleSpinBox* coordinateCenter_y;
46  QDoubleSpinBox* coordinateCenter_z;
47 
48  QDoubleSpinBox* coordinateDirection_x;
49  QDoubleSpinBox* coordinateDirection_y;
50  QDoubleSpinBox* coordinateDirection_z;
51 
52  QDoubleSpinBox* ringRadius;
53 
54  QDoubleSpinBox* crossSectionRadius;
55 
56  QGroupBox *coordinates;
57  QLabel *messageToDisplay;
58 
59 };
60 
62  axlInspectorToolCreator(parent), d(new axlInspectorToolCreatorTorusPrivate) {
63 
64  //OPACITY//
65  d->sliderOpacity = new QSlider(Qt::Horizontal, this);
66 
67  QHBoxLayout *layoutOpacity = new QHBoxLayout;
68  layoutOpacity->addWidget(new QLabel("Opacity",this));
69  layoutOpacity->addWidget(d->sliderOpacity);
70  d->sliderOpacity->setMaximum(100);
71 
72  //COLOR//
73  d->colorButton = new dtkColorButton(this);
74 
75  QHBoxLayout *layoutColorButton = new QHBoxLayout;
76  layoutColorButton->addWidget(new QLabel("Color",this));
77  layoutColorButton->addWidget(d->colorButton);
78  d->colorButton->setColor(QColor("#a0a0a4"));
79 
80  //CENTER//
81  d->coordinateCenter_x = new QDoubleSpinBox(this);
82  d->coordinateCenter_x->setValue(0.0);
83  d->coordinateCenter_x->setRange(-1000, 1000);
84  d->coordinateCenter_x->setSingleStep(0.1);
85  d->coordinateCenter_y = new QDoubleSpinBox(this);
86  d->coordinateCenter_y->setValue(0.0);
87  d->coordinateCenter_y->setRange(-1000, 1000);
88  d->coordinateCenter_y->setSingleStep(0.1);
89  d->coordinateCenter_z = new QDoubleSpinBox(this);
90  d->coordinateCenter_z->setValue(0.0);
91  d->coordinateCenter_z->setRange(-1000, 1000);
92  d->coordinateCenter_z->setSingleStep(0.1);
93 
94  QVBoxLayout *layoutCenter = new QVBoxLayout;
95 
96  QHBoxLayout *layoutCenter_x = new QHBoxLayout;
97  QLabel *labelCenter_x = new QLabel("x",this);
98  QHBoxLayout *layoutCenter_y = new QHBoxLayout;
99  QLabel *labelCenter_y = new QLabel("y",this);
100  QHBoxLayout *layoutCenter_z = new QHBoxLayout;
101  QLabel *labelCenter_z = new QLabel("z",this);
102 
103  layoutCenter_x->addWidget(labelCenter_x);
104  layoutCenter_x->addWidget(d->coordinateCenter_x);
105  layoutCenter_y->addWidget(labelCenter_y);
106  layoutCenter_y->addWidget(d->coordinateCenter_y);
107  layoutCenter_z->addWidget(labelCenter_z);
108  layoutCenter_z->addWidget(d->coordinateCenter_z);
109 
110  layoutCenter->addWidget(new QLabel("Center:", this));
111  layoutCenter->addLayout(layoutCenter_x);
112  layoutCenter->addLayout(layoutCenter_y);
113  layoutCenter->addLayout(layoutCenter_z);
114 
115  //DIRECTION//
116  d->coordinateDirection_x = new QDoubleSpinBox(this);
117  d->coordinateDirection_x->setValue(0.0);
118  d->coordinateDirection_x->setRange(-1000, 1000);
119  d->coordinateDirection_x->setSingleStep(0.1);
120  d->coordinateDirection_y = new QDoubleSpinBox(this);
121  d->coordinateDirection_y->setValue(0.0);
122  d->coordinateDirection_y->setRange(-1000, 1000);
123  d->coordinateDirection_y->setSingleStep(0.1);
124  d->coordinateDirection_z = new QDoubleSpinBox(this);
125  d->coordinateDirection_z->setValue(1.0);
126  d->coordinateDirection_z->setRange(-1000, 1000);
127  d->coordinateDirection_z->setSingleStep(0.1);
128 
129  QVBoxLayout *layoutDirection = new QVBoxLayout;
130 
131  QHBoxLayout *layoutDirection_x = new QHBoxLayout;
132  QLabel *labelDirection_x = new QLabel("x",this);
133  QHBoxLayout *layoutDirection_y = new QHBoxLayout;
134  QLabel *labelDirection_y = new QLabel("y",this);
135  QHBoxLayout *layoutDirection_z = new QHBoxLayout;
136  QLabel *labelDirection_z = new QLabel("z",this);
137 
138  layoutDirection_x->addWidget(labelDirection_x);
139  layoutDirection_x->addWidget(d->coordinateDirection_x);
140  layoutDirection_y->addWidget(labelDirection_y);
141  layoutDirection_y->addWidget(d->coordinateDirection_y);
142  layoutDirection_z->addWidget(labelDirection_z);
143  layoutDirection_z->addWidget(d->coordinateDirection_z);
144 
145  layoutDirection->addWidget(new QLabel("Second point to create direction:", this));
146  layoutDirection->addLayout(layoutDirection_x);
147  layoutDirection->addLayout(layoutDirection_y);
148  layoutDirection->addLayout(layoutDirection_z);
149 
150  //RING RADIUS//
151  d->ringRadius = new QDoubleSpinBox(this);
152  d->ringRadius->setValue(1.0);
153  d->ringRadius->setSingleStep(0.1);
154 
155  QHBoxLayout *layoutRingRadius = new QHBoxLayout;
156  QLabel *labelRingRadius = new QLabel("Ring Radius:",this);
157 
158  layoutRingRadius->addWidget(labelRingRadius);
159  layoutRingRadius->addWidget(d->ringRadius);
160 
161  //CROSS SECTION RADIUS//
162  d->crossSectionRadius = new QDoubleSpinBox(this);
163  d->crossSectionRadius->setValue(0.2);
164  d->crossSectionRadius->setSingleStep(0.1);
165 
166  QHBoxLayout *layoutCrossSectionRadius = new QHBoxLayout;
167  QLabel *labelCrossSectionRadius = new QLabel("Cross Section Radius:",this);
168 
169  layoutCrossSectionRadius->addWidget(labelCrossSectionRadius);
170  layoutCrossSectionRadius->addWidget(d->crossSectionRadius);
171 
172  d->coordinates = new QGroupBox(tr("Enter coordinates"),this);
173  QVBoxLayout *layoutCoordonate = new QVBoxLayout(this);
174  layoutCoordonate->addLayout(layoutCenter);
175  layoutCoordonate->addLayout(layoutDirection);
176  d->coordinates->setLayout(layoutCoordonate);
177 
178  d->messageToDisplay = new QLabel("Select two points : the torus center \n and the other one to determine its orientation", this);
179  d->messageToDisplay->setStyleSheet("color: #ff0000;");
180 
181 
182  QPushButton *button = new QPushButton("Create", this);
183  connect(button, SIGNAL(clicked()), this, SLOT(run()));
184 
185  QVBoxLayout *layout = new QVBoxLayout(this);
186 
187  layout->addWidget(new QLabel("axlInspectorToolCreatorTorus", this));
188  // layout->addLayout(layoutCenter);
189  // layout->addLayout(layoutDirection);
190  layout->addWidget(d->messageToDisplay);
191  layout->addWidget(d->coordinates);
192  layout->addLayout(layoutRingRadius);
193  layout->addLayout(layoutCrossSectionRadius);
194  layout->addLayout(layoutOpacity);
195  layout->addLayout(layoutColorButton);
196  layout->addWidget(button);
197  d->coordinates->hide();
198  d->messageToDisplay->show();
199 }
200 
202  delete d;
203  d = NULL;
204 }
205 
207  d->controller = controller;
208  if(d->controller->size() < 2){
209  d->messageToDisplay->hide();
210  d->coordinates->show();
211  }else{
212  d->coordinates->hide();
213  bool hasRigthType = false;
214  int nbRigthType = 0;
215  foreach(axlInspectorObjectManagerTreeItem *item, d->controller->items()){
216  if(dynamic_cast<axlPoint *>(d->controller->data(item)))
217  nbRigthType++;
218  else if(dynamic_cast<axlDataDynamic *>(d->controller->data(item)))
219  if(dynamic_cast<axlDataDynamic *>(d->controller->data(item))->outputs())
220  if(dynamic_cast<axlPoint *>(dynamic_cast<axlDataDynamic *>(d->controller->data(item))->outputs()))
221  nbRigthType++;
222  }
223 
224  if(nbRigthType > 1)
225  hasRigthType = true;
226  if(!hasRigthType){
227  d->messageToDisplay->hide();
228  d->coordinates->show();
229  }
230  }
231 }
232 
233 QList<axlAbstractData *> axlInspectorToolCreatorTorus::returnInputsList(void){
234  QList<axlAbstractData *>list;
235  if(d->coordinates->isVisible()){
236  axlPoint *center = new axlPoint(d->coordinateCenter_x->value(), d->coordinateCenter_y->value(), d->coordinateCenter_z->value());
237  axlPoint *direction = new axlPoint(d->coordinateDirection_x->value(), d->coordinateDirection_y->value(), d->coordinateDirection_z->value());
238 
239  //parameters
240  axlDouble *ringRadius = new axlDouble(d->ringRadius->value());
241  axlDouble *crossSectionRadius = new axlDouble(d->crossSectionRadius->value());
242 
243  list << center << direction << ringRadius << crossSectionRadius;
244  }
245  return list;
246 
247 }
248 
250 
251  if(!d->coordinates->isVisible()){
252  d->messageToDisplay->show();
253  axlTorusCreator *creator = new axlTorusCreator();
254  int nbPoints = 0;
255  if(d->controller->size() > 0){
256  foreach(axlInspectorObjectManagerTreeItem *item, d->controller->items()){
257 
258  if(item->text(2) == "Selected"|| item->text(2) == "Editable")
259  {
260  if(nbPoints < 2){
261  if(dynamic_cast<axlPoint *>(d->controller->data(item))) {
262  axlPoint *point = dynamic_cast<axlPoint *>(d->controller->data(item));
263  creator->setInput(point,nbPoints);
264  nbPoints++;
265  }
266  }else{
267  qDebug() << "To many inputs selected, only the two first points were used";
268  }
269  }
270 
271  }
272  }
273 
274  if(nbPoints == 2){
275  creator->setParameter(d->ringRadius->value(),0);
276  creator->setParameter(d->crossSectionRadius->value(),1);
277  creator->update();
278  axlTorus *torus = dynamic_cast<axlTorus *>(creator->output());
279  torus->setColor(d->colorButton->color());
280  double opacity = 1.0 - 0.01 * d->sliderOpacity->value();
281  torus->setOpacity(opacity);
282  emit dataInserted(torus);
283  d->coordinates->hide();
284 
285  }else {
286  //display the coordinates to be chosen for the extremal points
287  d->messageToDisplay->hide();
288  d->coordinates->show();
289  }
290  delete creator;
291  }else{
292  d->messageToDisplay->hide();
293  axlPoint *center = new axlPoint(d->coordinateCenter_x->value(), d->coordinateCenter_y->value(), d->coordinateCenter_z->value());
294  axlPoint *direction = new axlPoint(d->coordinateDirection_x->value(), d->coordinateDirection_y->value(), d->coordinateDirection_z->value());
295 
296  axlTorus* newTorus = new axlTorus(center, direction, d->ringRadius->value(), d->crossSectionRadius->value());
297 
298  newTorus->setColor(d->colorButton->color());
299  double opacity = 1.0 - 0.01 * d->sliderOpacity->value();
300  newTorus->setOpacity(opacity);
301  emit dataInserted(newTorus);
302  }
303 }
304 
306 {
307  return new axlInspectorToolCreatorTorus;
308 }
virtual void setInput(dtkAbstractData *newData, int channel)
Class axlPoint defines 3D points.
Definition: axlPoint.h:34
virtual int update(void)
void setController(axlInspectorObjectController *controller)
Class axlDouble defines a double.
Definition: axlDouble.h:29
axlInspectorToolInterface * createaxlInspectorToolCreatorTorus(void)
QList< axlAbstractData * > returnInputsList(void)
virtual void setParameter(double data, int channel)
void setOpacity(const double &opacity)
void dataInserted(axlAbstractData *data)
void setColor(double r, double g, double b)
virtual dtkAbstractData * output(void)