Developer documentation | Axl-2.5.1

axlVolumeDiscreteReader.cpp
Go to the documentation of this file.
1 /* axlVolumeDiscreteReader.cpp ---
2  *
3  * Author: Anais Ducoffe
4  * Copyright (C) 2013 - Anais Ducoffe, Inria.
5  */
6 
7 /* Commentary:
8  *
9  */
10 
11 /* Change log:
12  *
13  */
14 
16 
17 #include "axlVolumeDiscrete.h"
18 
19 #include <dtkCoreSupport/dtkAbstractData.h>
20 #include <dtkCoreSupport/dtkAbstractDataFactory.h>
22 #include "axlVtkViewPlugin.h"
23 
24 // /////////////////////////////////////////////////////////////////
25 // axlVolumeDiscreteReader
26 // /////////////////////////////////////////////////////////////////
27 
29 {
30  this->setObjectName(this->identifier());
31 }
32 
34 {
35 
36 }
37 
39 {
40  return "axlVolumeDiscreteReader";
41 }
42 
44 {
45  return "axlVolumeDiscreteReader";
46 }
47 
48 QStringList axlVolumeDiscreteReader::handled(void) const
49 {
50  return QStringList() << "axlVolumeDiscrete";
51 }
52 
54 {
55  return axlVtkViewPlugin::dataFactSingleton->registerDataReaderType("axlVolumeDiscreteReader", QStringList(), createaxlVolumeDiscreteReader);
56 }
57 
58 bool axlVolumeDiscreteReader::accept(const QDomNode& node)
59 {
60  QDomElement element = node.toElement();
61 
62  if(element.tagName() != "volume")
63  return false;
64 
65  if(element.attribute("type") != "discrete")
66  return false;
67 
68  if(!hasChildNode(element, "dimension"))
69  return false;
70 
71  if(!hasChildNode(element, "values"))
72  return false;
73 
74  return true;
75 }
76 
77 bool axlVolumeDiscreteReader::reject(const QDomNode& node)
78 {
79  return !this->accept(node);
80 }
81 
83 {
84  QDomElement element = node.toElement();
85 
86  axlVolumeDiscrete *currentVolume = new axlVolumeDiscrete();
87 
88  QString name = element.attribute("name");
89  if(!name.isEmpty())
90  {
91  currentVolume->setObjectName(name);
92  }
93 
94  //Set the 3 dimensions.
95  QDomNodeList dimension = element.elementsByTagName("dimension");
96  if(!dimension.isEmpty()){
97  QDomElement dimensionElement = dimension.at(0).toElement();
98 
99  QStringList dimensions = dimensionElement.text().simplified().split(QRegExp("\\s+"));
100 
101  if(dimensions.size() == 3)
102  {
103  currentVolume->setDimensions(dimensions[0].toInt(),dimensions[1].toInt(),dimensions[2].toInt());
104  }
105 
106  }
107 
108  //Set the scalar values.
109  QDomNodeList values = element.elementsByTagName("values");
110  QStringList scalar;
111  if(!values.isEmpty()){
112  QDomElement scalarElement = values.at(0).toElement();
113  scalar = scalarElement.text().simplified().split(QRegExp("\\s+"));
114  }
115 
116  int nx = currentVolume->xDimension();
117  int ny = currentVolume->yDimension();
118  int nz = currentVolume->zDimension();
119  double number = 0;
120  for(int i = 0;i < nx;i++){
121  for(int j = 0;j < ny;j++){
122  for(int k = 0;k < nz;k++){
123  number = scalar[nx*ny*k+ nx*j + i].toDouble();
124  currentVolume->setValue(number,i,j,k);
125  }
126  }
127  }
128 
129  return currentVolume;
130 
131 }
132 
133 
135 {
136  if(!axl_reader)
137  return NULL;
138 
139  if(!axl_reader->accept(node))
140  return NULL;
141 
142  axl_reader->dtkAbstractDataReader::read(this->file());
143 
144  if(axlAbstractData *data = axl_reader->read(node))
145  return data;
146 
147 
148  return NULL;
149 }
150 
151 
152 
153 dtkAbstractDataReader *createaxlVolumeDiscreteReader(void)
154 {
155  return new axlVolumeDiscreteReader;
156 }
157 
QStringList handled(void) const
axlAbstractData * read(const QDomNode &node)
bool reject(const QDomNode &node)
int yDimension(void) const
void setValue(double value, int i, int j, int k)
virtual axlAbstractData * read(const QDomNode &node)=0
int xDimension(void) const
QString description(void) const
dtkAbstractDataReader * createaxlVolumeDiscreteReader(void)
int zDimension(void) const
void setDimensions(unsigned int x, unsigned int y, unsigned int z)
bool hasChildNode(QDomElement element, const QString &tag)
Definition: axlFormat.h:20
virtual bool accept(const QDomNode &node)=0
bool accept(const QDomNode &node)
axlAbstractData * dataByReader(axlAbstractDataReader *axl_reader, const QDomNode &node)
Class axlAbstractData defines an API for all type of axel data.
static dtkAbstractDataFactory * dataFactSingleton