Developer documentation | Axl-2.5.1

axlFieldDiscrete.cpp
Go to the documentation of this file.
1 /* axlFieldDiscrete.cpp ---
2  *
3  * Author: Thibaud Kloczko
4  * Copyright (C) 2008 - Thibaud Kloczko, Inria.
5  * Created: Wed Jul 28 11:22:28 2010 (+0200)
6  * Version: $Id$
7  * Last-Updated: Tue Oct 25 09:55:32 2011 (+0200)
8  * By: Thibaud Kloczko
9  * Update #: 355
10  */
11 
12 /* Commentary:
13  *
14  */
15 
16 /* Change log:
17  *
18  */
19 #include <sstream>
20 
21 #include "axlFieldDiscrete.h"
22 
23 #include <dtkCoreSupport/dtkGlobal.h>
24 
25 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
26 
27 class axlFieldDiscretePrivate
28 {
29 public:
30 
31  QVector<int> arrayInt;
32  QVector<float> arrayFloat;
33  QVector<double> arrayDouble;
34 
35  int size;
36 };
37 
38 // /////////////////////////////////////////////////////////////////
39 // axlFieldDiscrete implementation
40 // /////////////////////////////////////////////////////////////////
41 
43 
46 axlFieldDiscrete::axlFieldDiscrete() : axlAbstractFieldDiscrete(), d(new axlFieldDiscretePrivate)
47 {
48  this->setObjectName(this->identifier());
49  d->size = 0;
50 }
51 
55 axlFieldDiscrete::axlFieldDiscrete(QString name, Type type, Kind kind, Support support, int size) : axlAbstractFieldDiscrete(name, type, kind, support, size), d(new axlFieldDiscretePrivate)
56 {
57  this->setType(type);
58  this->setKind(kind);
59  this->setObjectName(name);
60  d->size = size;
61  this->setSupport(support);
62 }
63 
65 
69 {
70  delete d;
71 
72  d = NULL;
73 }
74 
76 {
77  return dtkAbstractDataFactory::instance()->registerDataType("axlFieldDiscrete", createaxlFieldDiscrete);
78 }
79 
81 
84 void axlFieldDiscrete::setScalar(int index, double v1)
85 {
86  if(!(this->kind() == Scalar)) {
87  qDebug() << "Setting scalar value on non scalar field.";
88  return;
89  }
90 
91  if(this->type() == Int){
92  if(d->arrayInt.size() >= index+1 ){
93  d->arrayInt.replace(index, v1);
94  }else if(d->arrayInt.size() == index){
95  d->arrayInt.push_back(v1);
96  }else{
97  qDebug() << Q_FUNC_INFO << "The array vector is not well filled";
98  }
99  }else if(this->type() == Float){
100  if(d->arrayFloat.size() >= index+1 ){
101  d->arrayFloat.replace(index, v1);
102  }else if(d->arrayFloat.size() == index){
103  d->arrayFloat.push_back(v1);
104  }else{
105  qDebug() << Q_FUNC_INFO << "The array vector is not well filled";
106  }
107  }else if(this->type() == Double){
108  if(d->arrayDouble.size() >= index+1 ){
109  d->arrayDouble.replace(index, v1);
110  }else if(d->arrayDouble.size() == index){
111  d->arrayDouble.push_back(v1);
112  }else{
113  qDebug() << Q_FUNC_INFO << "The array vector is not well filled";
114  }
115  }else{
116  qDebug() << Q_FUNC_INFO << "This type doesn't exists";
117  }
118 }
119 
121 
124 void axlFieldDiscrete::setVector(int index, double v1, double v2, double v3)
125 {
126  if(!(this->kind() == Vector)) {
127  qDebug() << "Setting vector value on non vector field.";
128  return;
129  }
130 
131 // if(!(d->size%3 == 0) /*|| !(index%3==0)*/){
132 // qDebug() << Q_FUNC_INFO << "Error : cannot be divided by 3";
133 // return;
134 // }
135 
136  if(this->type() == Int){
137  if(d->arrayInt.size() >= 3*(index+1)){
138  d->arrayInt.replace(index, v1);
139  d->arrayInt.replace(index+1, v2);
140  d->arrayInt.replace(index+2, v3);
141  }else if(d->arrayInt.size() == 3*index){
142  d->arrayInt.push_back(v1);
143  d->arrayInt.push_back(v2);
144  d->arrayInt.push_back(v3);
145  }else{
146  qDebug() << Q_FUNC_INFO << "The array vector is not well filled";
147  return;
148  }
149  }else if(this->type() == Float){
150  if(d->arrayFloat.size() >= 3*(index+1) ){
151  d->arrayFloat.replace(index, v1);
152  d->arrayFloat.replace(index+1, v2);
153  d->arrayFloat.replace(index+2, v3);
154  }else if(d->arrayFloat.size() == 3*index){
155  d->arrayFloat.push_back(v1);
156  d->arrayFloat.push_back(v2);
157  d->arrayFloat.push_back(v3);
158  }else{
159  qDebug() << Q_FUNC_INFO << "The array vector is not well filled";
160  return;
161  }
162  }else if(this->type() == Double){
163  if(d->arrayDouble.size() >= 3*(index+1) ){
164  d->arrayDouble.replace(index, v1);
165  d->arrayDouble.replace(index+1, v2);
166  d->arrayDouble.replace(index+2, v3);
167  }else if(d->arrayDouble.size() == 3*index){
168  d->arrayDouble.push_back(v1);
169  d->arrayDouble.push_back(v2);
170  d->arrayDouble.push_back(v3);
171  }else{
172  qDebug() << Q_FUNC_INFO << "The array vector is not well filled";
173  return;
174  }
175  }else{
176  qDebug() << Q_FUNC_INFO << "This type doesn't exists";
177  return;
178  }
179 }
180 
182 
186 void axlFieldDiscrete::setTensor(int index, double v1, double v2, double v3, double v4, double v5, double v6, double v7, double v8, double v9)
187 {
188  if(!(this->kind() == Tensor)) {
189  qDebug() << "Setting tensor value on non tensor field.";
190  return;
191  }
192 
193  if(!(d->size%9 == 0) /*|| !(index%9 == 0)*/){
194  qDebug() << Q_FUNC_INFO << "Error : cannot be divided by 9";
195  return;
196  }
197 
198  if(this->type() == Int){
199  if(d->arrayInt.size() >= 9*(index+1)){
200  d->arrayInt.replace(index, v1);
201  d->arrayInt.replace(index+1, v2);
202  d->arrayInt.replace(index+2, v3);
203  d->arrayInt.replace(index+3, v4);
204  d->arrayInt.replace(index+4, v5);
205  d->arrayInt.replace(index+5, v6);
206  d->arrayInt.replace(index+6, v7);
207  d->arrayInt.replace(index+7, v8);
208  d->arrayInt.replace(index+8, v9);
209  }else if(d->arrayInt.size() == 9*index){
210  d->arrayInt.push_back(v1);
211  d->arrayInt.push_back(v2);
212  d->arrayInt.push_back(v3);
213  d->arrayInt.push_back(v4);
214  d->arrayInt.push_back(v5);
215  d->arrayInt.push_back(v6);
216  d->arrayInt.push_back(v7);
217  d->arrayInt.push_back(v8);
218  d->arrayInt.push_back(v9);
219 
220  }else{
221  qDebug() << Q_FUNC_INFO << "The array vector is not well filled";
222  return;
223  }
224  }else if(this->type() == Float){
225  if(d->arrayFloat.size() >= 9*(index+1) ){
226  d->arrayFloat.replace(index, v1);
227  d->arrayFloat.replace(index+1, v2);
228  d->arrayFloat.replace(index+2, v3);
229  d->arrayFloat.replace(index+3, v4);
230  d->arrayFloat.replace(index+4, v5);
231  d->arrayFloat.replace(index+5, v6);
232  d->arrayFloat.replace(index+6, v7);
233  d->arrayFloat.replace(index+7, v8);
234  d->arrayFloat.replace(index+8, v9);
235  }else if(d->arrayFloat.size() == 9*index){
236  d->arrayFloat.push_back(v1);
237  d->arrayFloat.push_back(v2);
238  d->arrayFloat.push_back(v3);
239  d->arrayFloat.push_back(v4);
240  d->arrayFloat.push_back(v5);
241  d->arrayFloat.push_back(v6);
242  d->arrayFloat.push_back(v7);
243  d->arrayFloat.push_back(v8);
244  d->arrayFloat.push_back(v9);
245  }else{
246  qDebug() << Q_FUNC_INFO << "The array vector is not well filled";
247  return;
248  }
249  }else if(this->type() == Double){
250  if(d->arrayDouble.size() >= 9*(index+1) ){
251  d->arrayDouble.replace(index, v1);
252  d->arrayDouble.replace(index+1, v2);
253  d->arrayDouble.replace(index+2, v3);
254  d->arrayDouble.replace(index+3, v4);
255  d->arrayDouble.replace(index+4, v5);
256  d->arrayDouble.replace(index+5, v6);
257  d->arrayDouble.replace(index+6, v7);
258  d->arrayDouble.replace(index+7, v8);
259  d->arrayDouble.replace(index+8, v9);
260  }else if(d->arrayDouble.size() == 9*index){
261  d->arrayDouble.push_back(v1);
262  d->arrayDouble.push_back(v2);
263  d->arrayDouble.push_back(v3);
264  d->arrayDouble.push_back(v4);
265  d->arrayDouble.push_back(v5);
266  d->arrayDouble.push_back(v6);
267  d->arrayDouble.push_back(v7);
268  d->arrayDouble.push_back(v8);
269  d->arrayDouble.push_back(v9);
270 
271  }else{
272  qDebug() << Q_FUNC_INFO << "The array vector is not well filled";
273  return;
274  }
275  }else{
276  qDebug() << Q_FUNC_INFO << "This type doesn't exists";
277  return;
278  }
279 }
280 
282 {
283  return d->size;
284 }
285 
287 {
288  d->size = size;
289 
290 }
291 
293 
296 double axlFieldDiscrete::scalar(int index)
297 {
298  if(!(this->kind() == Scalar)) {
299  qDebug() << "Getting scalar value on non scalar field.";
300  return 0;
301  }
302 
303  if(this->type() == Int){
304  return d->arrayInt.at(index);
305  }else if(this->type() == Float){
306  return d->arrayFloat.at(index);
307  }else if(this->type() == Double){
308  return d->arrayDouble.at(index);
309  }else{
310  qDebug() << "No return value.";
311  return 0;
312  }
313 }
314 
316 
319 double *axlFieldDiscrete::vector(int index)
320 {
321  if(!(this->kind() == Vector)) {
322  qDebug() << "Getting vector value on non vector field.";
323  return NULL;
324  }
325 
326  double* result = new double[3];
327 
328  if(this->type() == Int){
329  result[0] = d->arrayInt.at(index);
330  result[1] = d->arrayInt.at(index+1);
331  result[2] = d->arrayInt.at(index+2);
332  return result;
333  }else if(this->type() == Float){
334  result[0] = d->arrayFloat.at(index);
335  result[1] = d->arrayFloat.at(index+1);
336  result[2] = d->arrayFloat.at(index+2);
337  return result;
338  }else if(this->type() == Double){
339  result[0] = d->arrayDouble.at(index);
340  result[1] = d->arrayDouble.at(index+1);
341  result[2] = d->arrayDouble.at(index+2);
342  return result;
343  }else{
344  qDebug() << "No return value.";
345  return NULL;
346  }
347 }
348 
350 
353 double *axlFieldDiscrete::tensor(int index)
354 {
355  if(!(this->kind() == Tensor)) {
356  qDebug() << "Getting tensor value on non tensor field.";
357  return NULL;
358  }
359 
360  double* result = new double[9];
361 
362  if(this->type() == Int){
363  result[0] = d->arrayInt.at(index);
364  result[1] = d->arrayInt.at(index+1);
365  result[2] = d->arrayInt.at(index+2);
366  result[3] = d->arrayInt.at(index+3);
367  result[4] = d->arrayInt.at(index+4);
368  result[5] = d->arrayInt.at(index+5);
369  result[6] = d->arrayInt.at(index+6);
370  result[7] = d->arrayInt.at(index+7);
371  result[8] = d->arrayInt.at(index+8);
372  return result;
373  }else if(this->type() == Float){
374  result[0] = d->arrayFloat.at(index);
375  result[1] = d->arrayFloat.at(index+1);
376  result[2] = d->arrayFloat.at(index+2);
377  result[3] = d->arrayFloat.at(index+3);
378  result[4] = d->arrayFloat.at(index+4);
379  result[5] = d->arrayFloat.at(index+5);
380  result[6] = d->arrayFloat.at(index+6);
381  result[7] = d->arrayFloat.at(index+7);
382  result[8] = d->arrayFloat.at(index+8);
383  return result;
384  }else if(this->type() == Double){
385  result[0] = d->arrayDouble.at(index);
386  result[1] = d->arrayDouble.at(index+1);
387  result[2] = d->arrayDouble.at(index+2);
388  result[3] = d->arrayDouble.at(index+3);
389  result[4] = d->arrayDouble.at(index+4);
390  result[5] = d->arrayDouble.at(index+5);
391  result[6] = d->arrayDouble.at(index+6);
392  result[7] = d->arrayDouble.at(index+7);
393  result[8] = d->arrayDouble.at(index+8);
394  return result;
395  }else{
396  qDebug() << "No return value.";
397  return NULL;
398  }
399 }
400 
403 // *
404 // */
405 //QString axlFieldDiscrete::name(void)
406 //{
407 // if(d->array)
408 // return QString(d->array->GetName());
409 
410 // return QString() ;
411 //}
412 
415 // *
416 // */
417 //void axlFieldDiscrete::setName(QString name)
418 //{
419 // if(d->array)
420 // d->array->SetName(name.toAscii().constData());
421 
422 //}
423 
425 
428 QString axlFieldDiscrete::description(void) const
429 {
430  qDebug()<< "axlFieldDiscrete::description";
431 
432 
433  QString qstr;
434 
435  qstr.append("Name : ");
436  qstr.append(this->objectName());
437 
438  // switch(this->type()) {
439  // case axlFieldDiscrete::Int:
440  // qstr.append(";Type : integer");
441  // break;
442  // case axlFieldDiscrete::Float:
443  // qstr.append(";Type : Float");
444  // break;
445  // case axlFieldDiscrete::Double:
446  // qstr.append(";Type : Double");
447  // break;
448  // default:
449  // qDebug() << "Unsupported field type";
450  // }
451 
452 
453  // switch(this->kind()) {
454  // case axlFieldDiscrete::Scalar:
455  // qstr.append(";Kind : Scalar");
456  // break;
457  // case axlFieldDiscrete::Vector:
458  // qstr.append(";Kind : Vector");
459  // break;
460  // case axlFieldDiscrete::Tensor:
461  // qstr.append(";Kind : Tensor");
462  // break;
463  // default:
464  // qDebug() << ";Unsupported field kind";
465  // }
466 
467  // axlAbstractField::Support support; /*;= dynamic_cast<axlAbstractField *>(this)->support();*/
468  // switch(support) {
469  // case axlFieldDiscrete::Point:
470  // qstr.append(";Support : Point");
471  // break;
472  // case axlFieldDiscrete::Cell:
473  // qstr.append(";Support : Cell");
474  // break;
475  // case axlFieldDiscrete::Custom:
476  // qstr.append(";Support : Custom");
477  // break;
478  // default:
479  // qDebug() << ";No support";
480  // }
481 
482  // créer un flux de sortie
483  std::ostringstream oss;
484  // écrire un nombre dans le flux
485  // récupérer une chaîne de caractères
486  // qstr.append(";Size :"+this ->size());
487 
488 
489  qstr.append(";Size : ");
490  int s = d->size;
491  qstr.append(QString::number(s));
492 
493  return qstr;
494 
495 }
496 
498 
501 QString axlFieldDiscrete::identifier(void) const
502 {
503  return "axlFieldDiscrete";
504 }
505 
508 
512 {
513  //d->array->Modified();
514 
515  emit updated();
516 }
517 
520 // *
521 // */
522 //void *axlFieldDiscrete::array(void)
523 //{
524 // if(this->type == Int){
525 // return d->arrayInt;
526 // }else if(this->type == Float){
527 // return d->arrayFloat;
528 // }else{
529 // return d->arrayDouble;
530 // }
531 //}
532 
533 
534 
535 // /////////////////////////////////////////////////////////////////
536 // axlFieldDiscrete documentation
537 // /////////////////////////////////////////////////////////////////
538 
548 // /////////////////////////////////////////////////////////////////
549 // Type instanciation
550 // /////////////////////////////////////////////////////////////////
551 
552 dtkAbstractData *createaxlFieldDiscrete(void)
553 {
554  return new axlFieldDiscrete();
555 }
void updated(void)
dtkAbstractData * createaxlFieldDiscrete(void)
QString description(void) const
Returns the description of the field.
virtual int size(void)
virtual void update(void)
Class axlAbstractFieldDiscrete defines an API for arrays of numeric data.
QString identifier(void) const
Returns the identifier "axlFieldDiscrete".
virtual Kind kind(void)
virtual void setVector(int index, double v1, double v2, double v3)
virtual ~axlFieldDiscrete(void)
Destroys the discrete field.
virtual void setScalar(int index, double v1)
static bool registered(void)
virtual void setSize(int size)
Class axlFieldDiscrete defines an API for arrays of numeric data.
virtual void setType(Type type)
Sets the type of the field which can be either int, float or double.
virtual double scalar(int index)
Returns the value at index location of the scalar array.
virtual void setSupport(Support support)
virtual void setTensor(int index, double v1, double v2, double v3, double v4, double v5, double v6, double v7, double v8, double v9)
virtual Type type(void)
virtual void setKind(Kind kind)
Sets the kind of the field which can be either scalar, vector or tensor.
virtual double * vector(int index)
Returns the value at index location of the vector array.
virtual double * tensor(int index)
Returns the value at index location of the tensor array.