larchi_header.patch
ctlibio.pro (working copy) | ||
---|---|---|
42 | 42 |
readers/ct_reader_points_ascii_def_models.h \ |
43 | 43 |
readers/ct_reader_idxyz.h \ |
44 | 44 |
readers/ct_reader_idxyz_def_models.h \ |
45 |
readers/headers/ct_xybheader.h |
|
45 |
readers/headers/ct_xybheader.h \ |
|
46 |
readers/headers/ct_larchiheader.h |
|
46 | 47 |
|
47 | 48 |
SOURCES += \ |
48 | 49 |
readers/ct_reader_ascrgb.cpp \ |
... | ... | |
57 | 58 |
readers/ct_reader_pbm.cpp \ |
58 | 59 |
readers/ct_reader_points_ascii.cpp \ |
59 | 60 |
readers/ct_reader_idxyz.cpp \ |
60 |
readers/headers/ct_xybheader.cpp |
|
61 |
readers/headers/ct_xybheader.cpp \ |
|
62 |
readers/headers/ct_larchiheader.cpp |
readers/ct_reader_larchitect_grid.cpp (working copy) | ||
---|---|---|
29 | 29 |
CT_Reader_LArchitect_Grid::CT_Reader_LArchitect_Grid() : CT_AbstractReader() |
30 | 30 |
{ |
31 | 31 |
setToolTip(tr("Charge des grilles 3D depuis un fichier au format LArchitect")); |
32 |
_LarchiHeader = new CT_LARCHIHEADER(); |
|
32 | 33 |
} |
33 | 34 | |
34 | 35 | |
... | ... | |
53 | 54 |
{ |
54 | 55 |
QTextStream stream(&f); |
55 | 56 | |
56 |
Eigen::Vector3d min; |
|
57 |
Eigen::Vector3d max; |
|
58 |
Eigen::Vector3d res; |
|
59 |
EigenVector3ui64 dim; |
|
60 |
int nMat; |
|
61 |
QMap<QString, int> matNames; |
|
57 |
QString err; |
|
58 |
_LarchiHeader = (CT_LARCHIHEADER*)protectedReadHeader(stream,err); |
|
62 | 59 | |
63 |
if(readHeader(stream, min, max, res, dim, nMat, matNames)) {
|
|
60 |
if(_LarchiHeader!=NULL) {
|
|
64 | 61 |
f.close(); |
65 | 62 |
return CT_AbstractReader::setFilePath(filepath); |
66 | 63 |
} else { |
... | ... | |
107 | 104 |
{ |
108 | 105 |
QTextStream stream(&f); |
109 | 106 | |
110 |
Eigen::Vector3d min; |
|
111 |
Eigen::Vector3d max; |
|
112 |
Eigen::Vector3d res; |
|
113 |
EigenVector3ui64 dim; |
|
114 |
int nMat; |
|
115 |
QMap<QString, int> matNames; |
|
107 |
QString err; |
|
108 |
_LarchiHeader = (CT_LARCHIHEADER*)protectedReadHeader(stream,err); |
|
116 | 109 | |
117 |
if(readHeader(stream, min, max, res, dim, nMat, matNames)) {
|
|
110 |
if(_LarchiHeader!=NULL) {
|
|
118 | 111 | |
112 |
Eigen::Vector3d min = _LarchiHeader->get_Min(); |
|
113 |
Eigen::Vector3d res = _LarchiHeader->get_Res(); |
|
114 |
EigenVector3ui64 dim = _LarchiHeader->get_Dim(); |
|
115 |
int nMat = _LarchiHeader->get_nMat(); |
|
116 |
QMap<QString, int> matNames = _LarchiHeader->get_matNames(); |
|
117 | ||
119 | 118 |
CT_Grid3D<float> *wood_surface = NULL; |
120 | 119 |
CT_Grid3D<float> *leaf_surface = NULL; |
121 | 120 |
CT_Grid3D<float> *wood_volume = NULL; |
... | ... | |
264 | 263 |
return false; |
265 | 264 |
} |
266 | 265 | |
267 |
bool CT_Reader_LArchitect_Grid::readHeader(QTextStream &stream, Eigen::Vector3d &min, Eigen::Vector3d &max, Eigen::Vector3d &res, EigenVector3ui64 &dim, int &nMat, QMap<QString, int> &matNames) const
|
|
266 |
CT_FileHeader* CT_Reader_LArchitect_Grid::protectedReadHeader(QTextStream &stream, QString &error) const
|
|
268 | 267 |
{ |
268 | ||
269 |
Q_UNUSED(error) |
|
270 | ||
271 |
CT_LARCHIHEADER *header = new CT_LARCHIHEADER(); |
|
272 |
header->setFile(filepath()); |
|
273 | ||
269 | 274 |
if(stream.atEnd()) |
270 |
return false;
|
|
275 |
return header;
|
|
271 | 276 | |
272 | 277 |
// Read (x,y,z) min and max limits of the grid |
273 | 278 |
QString line = stream.readLine(); |
... | ... | |
278 | 283 |
return false; |
279 | 284 | |
280 | 285 |
bool ok[6]; |
281 |
min[0] = values.at(0).toDouble(&ok[0]);
|
|
282 |
min[1] = values.at(1).toDouble(&ok[1]);
|
|
283 |
min[2] = values.at(2).toDouble(&ok[2]);
|
|
284 |
max[0] = values.at(3).toDouble(&ok[3]);
|
|
285 |
max[1] = values.at(4).toDouble(&ok[4]);
|
|
286 |
max[2] = values.at(5).toDouble(&ok[5]);
|
|
286 |
header->set_xMin(values.at(0).toDouble(&ok[0]));
|
|
287 |
header->set_yMin(values.at(1).toDouble(&ok[1]));
|
|
288 |
header->set_zMin(values.at(2).toDouble(&ok[2]));
|
|
289 |
header->set_xMax(values.at(3).toDouble(&ok[3]));
|
|
290 |
header->set_yMax(values.at(4).toDouble(&ok[4]));
|
|
291 |
header->set_zMax(values.at(5).toDouble(&ok[5]));
|
|
287 | 292 | |
288 | 293 |
if (!ok[0] || !ok[1] || !ok[2] || !ok[3] || !ok[4] || !ok[5]) |
289 | 294 |
return false; |
... | ... | |
296 | 301 |
if (values.size() < 3) |
297 | 302 |
return false; |
298 | 303 | |
299 |
res[0] = values.at(0).toDouble(&ok[0]);
|
|
300 |
res[1] = values.at(1).toDouble(&ok[1]);
|
|
301 |
res[2] = values.at(2).toDouble(&ok[2]);
|
|
304 |
header->set_Res(values.at(0).toDouble(&ok[0]),0);
|
|
305 |
header->set_Res(values.at(1).toDouble(&ok[1]),1);
|
|
306 |
header->set_Res(values.at(2).toDouble(&ok[2]),2);
|
|
302 | 307 | |
303 | 308 |
if (!ok[0] || !ok[1] || !ok[2]) |
304 | 309 |
return false; |
305 | 310 | |
306 |
if ((res[0] != res[1]) || (res[0] != res[2]))
|
|
311 |
if ((header->get_Res(0) != header->get_Res(1)) || (header->get_Res(0) != header->get_Res(2)))
|
|
307 | 312 |
return false; |
308 | 313 | |
309 | 314 |
// read dimensions of the grid |
... | ... | |
314 | 319 |
if (values.size() < 3) |
315 | 320 |
return false; |
316 | 321 | |
317 |
dim[0] = values.at(0).toUInt(&ok[0]);
|
|
318 |
dim[1] = values.at(1).toUInt(&ok[1]);
|
|
319 |
dim[2] = values.at(2).toUInt(&ok[2]);
|
|
322 |
header->set_xDim(values.at(0).toUInt(&ok[0]));
|
|
323 |
header->set_yDim(values.at(1).toUInt(&ok[1]));
|
|
324 |
header->set_zDim(values.at(2).toUInt(&ok[2]));
|
|
320 | 325 | |
321 | 326 |
if (!ok[0] || !ok[1] || !ok[2]) |
322 | 327 |
return false; |
... | ... | |
330 | 335 | |
331 | 336 |
if(size > 0) |
332 | 337 |
{ |
333 |
nMat = values.at(0).toInt(&ok[0]);
|
|
338 |
header->set_nMat(values.at(0).toInt(&ok[0]));
|
|
334 | 339 | |
335 |
if (!ok[0] || (nMat <= 0) || (size < (2*nMat+1)))
|
|
340 |
if (!ok[0] || (header->get_nMat() <= 0) || (size < (2*header->get_nMat()+1)))
|
|
336 | 341 |
return false; |
337 | 342 | |
338 | 343 |
int matid; |
339 | 344 |
QString matName; |
340 | 345 | |
341 | 346 |
// read materials ids and names |
342 |
for (int i = 0 ; i < nMat; ++i)
|
|
347 |
for (int i = 0 ; i < header->get_nMat(); ++i)
|
|
343 | 348 |
{ |
344 | 349 |
matid = values.at(2*i+1).toInt(&ok[0]); |
345 | 350 |
matName = values.at(2*i+2); |
... | ... | |
347 | 352 |
if (!ok[0] || matName.size() <= 0) |
348 | 353 |
return false; |
349 | 354 | |
350 |
matNames.insert(matName.toUpper(), matid);
|
|
355 |
header->set_matNames(matName.toUpper(), matid);
|
|
351 | 356 |
} |
352 | 357 |
} |
353 |
return true;
|
|
358 |
return header;
|
|
354 | 359 |
} |
355 | 360 | |
356 | 361 |
CT_Grid3D<float>* CT_Reader_LArchitect_Grid::createGrid(Eigen::Vector3d &min, Eigen::Vector3d &res, CT_Reader_LArchitect_Grid::EigenVector3ui64 &dim) const |
readers/ct_reader_larchitect_grid.h (working copy) | ||
---|---|---|
7 | 7 | |
8 | 8 |
#include "ctlibio/ctlibio_global.h" |
9 | 9 |
#include "ct_reader_larchitect_grid_def_models.h" |
10 |
#include "headers/ct_larchiheader.h" |
|
10 | 11 | |
11 | 12 |
class CTLIBIO_EXPORT CT_Reader_LArchitect_Grid : public CT_AbstractReader |
12 | 13 |
{ |
... | ... | |
23 | 24 |
CT_AbstractReader* copy() const; |
24 | 25 |
READER_COPY_FULL_IMP(CT_Reader_LArchitect_Grid) |
25 | 26 | |
27 |
CT_LARCHIHEADER* getHeader(){return _LarchiHeader;} |
|
28 | ||
26 | 29 |
protected: |
27 | 30 |
typedef Eigen::Matrix<size_t, 3, 1> EigenVector3ui64; |
31 |
CT_LARCHIHEADER* _LarchiHeader; |
|
28 | 32 | |
29 | 33 |
void protectedInit(); |
30 | 34 |
void protectedCreateOutItemDrawableModelList(); |
31 | 35 |
bool protectedReadFile(); |
32 | ||
33 |
bool readHeader(QTextStream &stream, Eigen::Vector3d &min, Eigen::Vector3d &max, Eigen::Vector3d &res, EigenVector3ui64 &dim, int &nMat, QMap<QString, int> &matNames) const; |
|
36 |
CT_FileHeader* protectedReadHeader(QTextStream &stream, QString &error) const; |
|
34 | 37 |
CT_Grid3D<float>* createGrid(Eigen::Vector3d &min, Eigen::Vector3d &res, EigenVector3ui64 &dim) const; |
35 | 38 |
}; |
36 | 39 |
readers/headers/ct_larchiheader.cpp (working copy) | ||
---|---|---|
1 |
#include "ct_larchiheader.h" |
|
2 |
|
|
3 |
CT_DEFAULT_IA_INIT(CT_LARCHIHEADER) |
|
4 |
|
|
5 |
CT_LARCHIHEADER::CT_LARCHIHEADER() : CT_FileHeader() |
|
6 |
{ |
|
7 |
_min[0] = 0.0; |
|
8 |
_min[1] = 0.0; |
|
9 |
_min[2] = 0.0; |
|
10 |
|
|
11 |
_max[0] = 0.0; |
|
12 |
_max[1] = 0.0; |
|
13 |
_max[2] = 0.0; |
|
14 |
|
|
15 |
_res[0]=0.0; |
|
16 |
_res[1]=0.0; |
|
17 |
_res[2]=0.0; |
|
18 |
|
|
19 |
_dim[0]=0; |
|
20 |
_dim[1]=0; |
|
21 |
_dim[2]=0; |
|
22 |
|
|
23 |
_nMat = 0; |
|
24 |
_matNames["none"] = 0; |
|
25 |
|
|
26 |
} |
|
27 |
|
|
28 |
CT_LARCHIHEADER::CT_LARCHIHEADER(const CT_OutAbstractSingularItemModel *model, const CT_AbstractResult *result) : CT_FileHeader(model, result) |
|
29 |
{ |
|
30 |
CT_LARCHIHEADER(); |
|
31 |
} |
|
32 |
|
|
33 |
CT_LARCHIHEADER::CT_LARCHIHEADER(const QString &modelName, const CT_AbstractResult *result) : CT_FileHeader(modelName, result) |
|
34 |
{ |
|
35 |
CT_LARCHIHEADER(); |
|
36 |
} |
|
37 |
|
|
38 |
CT_AbstractItemDrawable *CT_LARCHIHEADER::copy(const CT_OutAbstractItemModel *model, const CT_AbstractResult *result, CT_ResultCopyModeList copyModeList) |
|
39 |
{ |
|
40 |
Q_UNUSED(copyModeList); |
|
41 |
|
|
42 |
CT_LARCHIHEADER *cpy = new CT_LARCHIHEADER((CT_OutAbstractSingularItemModel*) model, result); |
|
43 |
cpy->setFile(_fileInfo.filePath()); |
|
44 |
cpy->set_Min(_min); |
|
45 |
cpy->set_Max(_max); |
|
46 |
cpy->set_Res(_res); |
|
47 |
cpy->set_Dim(_dim); |
|
48 |
cpy->set_nMat(_nMat); |
|
49 |
cpy->set_matNames(_matNames); |
|
50 |
|
|
51 |
return cpy; |
|
52 |
} |
readers/headers/ct_larchiheader.h (working copy) | ||
---|---|---|
1 |
#ifndef CT_LARCHIHEADER_H |
|
2 |
#define CT_LARCHIHEADER_H |
|
3 |
|
|
4 |
|
|
5 |
#include "ctlibio/ctlibio_global.h" |
|
6 |
#include "ct_itemdrawable/ct_fileheader.h" |
|
7 |
|
|
8 |
class CTLIBIO_EXPORT CT_LARCHIHEADER : public CT_FileHeader |
|
9 |
{ |
|
10 |
Q_OBJECT |
|
11 |
CT_TYPE_IMPL_MACRO(CT_LARCHIHEADER, CT_FileHeader, XYB Header) |
|
12 |
|
|
13 |
|
|
14 |
protected : |
|
15 |
typedef Eigen::Matrix<size_t, 3, 1> EigenVector3ui64; |
|
16 |
|
|
17 |
|
|
18 |
public: |
|
19 |
CT_LARCHIHEADER(); |
|
20 |
|
|
21 |
CT_LARCHIHEADER(const CT_OutAbstractSingularItemModel *model, |
|
22 |
const CT_AbstractResult *result); |
|
23 |
|
|
24 |
CT_LARCHIHEADER(const QString &modelName, |
|
25 |
const CT_AbstractResult *result); |
|
26 |
|
|
27 |
virtual bool hasBoundingBox() const {return false;} |
|
28 |
|
|
29 |
virtual CT_AbstractItemDrawable* copy(const CT_OutAbstractItemModel *model, const CT_AbstractResult *result, CT_ResultCopyModeList copyModeList); |
|
30 |
|
|
31 |
// Global getters |
|
32 |
inline Eigen::Vector3d get_Min() const {return _min;} |
|
33 |
inline Eigen::Vector3d get_Max() const {return _max;} |
|
34 |
inline Eigen::Vector3d get_Res() const {return _res;} |
|
35 |
inline EigenVector3ui64 get_Dim() const {return _dim;} |
|
36 |
inline int get_nMat() const {return _nMat;} |
|
37 |
inline QMap<QString, int> get_matNames() const {return _matNames;} |
|
38 |
|
|
39 |
// Getters |
|
40 |
inline double get_xMin() const {return _min[0];} |
|
41 |
inline double get_yMin() const {return _min[1];} |
|
42 |
inline double get_zMin() const {return _min[2];} |
|
43 |
|
|
44 |
inline double get_xMax() const {return _max[0];} |
|
45 |
inline double get_yMax() const {return _max[1];} |
|
46 |
inline double get_zMax() const {return _max[2];} |
|
47 |
|
|
48 |
inline double get_Res(int i) const {return _res[i];} |
|
49 |
|
|
50 |
inline size_t get_xDim() const {return _dim[0];} |
|
51 |
inline size_t get_yDim() const {return _dim[1];} |
|
52 |
inline size_t get_zDim() const {return _dim[2];} |
|
53 |
|
|
54 |
// Global setters |
|
55 |
inline void set_Min(Eigen::Vector3d min){_min = min;} |
|
56 |
inline void set_Max(Eigen::Vector3d max){_max = max;} |
|
57 |
inline void set_Res(Eigen::Vector3d res){_res = res;} |
|
58 |
inline void set_Dim(EigenVector3ui64 dim){_dim = dim;} |
|
59 |
|
|
60 |
// Setters |
|
61 |
inline void set_xMin(double x) {_min[0]=x;} |
|
62 |
inline void set_yMin(double y) {_min[1]=y;} |
|
63 |
inline void set_zMin(double z) {_min[2]=z;} |
|
64 |
|
|
65 |
inline void set_xMax(double x) {_max[0]=x;} |
|
66 |
inline void set_yMax(double y) {_max[1]=y;} |
|
67 |
inline void set_zMax(double z) {_max[2]=z;} |
|
68 |
|
|
69 |
inline void set_Res(double res, short n) {_res[n]=res;} |
|
70 |
|
|
71 |
inline void set_xDim(size_t xDim) {_dim[0]=xDim;} |
|
72 |
inline void set_yDim(size_t yDim) {_dim[1]=yDim;} |
|
73 |
inline void set_zDim(size_t zDim) {_dim[2]=zDim;} |
|
74 |
|
|
75 |
inline void set_nMat(int nMat){_nMat = nMat;} |
|
76 |
inline void set_matNames(QMap<QString, int> matNames){_matNames = matNames ;} |
|
77 |
inline void set_matNames(QString key, int value){_matNames.insert(key,value);} |
|
78 |
|
|
79 |
|
|
80 |
private: |
|
81 |
|
|
82 |
|
|
83 |
Eigen::Vector3d _min; |
|
84 |
Eigen::Vector3d _max; |
|
85 |
Eigen::Vector3d _res; |
|
86 |
EigenVector3ui64 _dim; |
|
87 |
int _nMat; |
|
88 |
QMap<QString, int> _matNames; |
|
89 |
|
|
90 |
|
|
91 |
CT_DEFAULT_IA_BEGIN(CT_LARCHIHEADER) |
|
92 |
CT_DEFAULT_IA_V3(CT_LARCHIHEADER, CT_AbstractCategory::staticInitDataValue(), &CT_LARCHIHEADER::get_Min, QObject::tr("Grid minimum coordinates"), "Minxyz") |
|
93 |
CT_DEFAULT_IA_V3(CT_LARCHIHEADER, CT_AbstractCategory::staticInitDataValue(), &CT_LARCHIHEADER::get_Max, QObject::tr("Grid maximum coordinates"), "Maxxyz") |
|
94 |
CT_DEFAULT_IA_V3(CT_LARCHIHEADER, CT_AbstractCategory::staticInitDataValue(), &CT_LARCHIHEADER::get_Res, QObject::tr("Grid resolution"), "Gres") |
|
95 |
CT_DEFAULT_IA_V3(CT_LARCHIHEADER, CT_AbstractCategory::staticInitDataValue(), &CT_LARCHIHEADER::get_Dim, QObject::tr("Grid dimension"), "Gdim") |
|
96 |
CT_DEFAULT_IA_V3(CT_LARCHIHEADER, CT_AbstractCategory::staticInitDataValue(), &CT_LARCHIHEADER::get_nMat, QObject::tr("Number of matrix"), "Nmat") |
|
97 |
//CT_DEFAULT_IA_V3(CT_LARCHIHEADER, CT_AbstractCategory::staticInitDataValue(), &CT_LARCHIHEADER::get_matNames, QObject::tr("Matrix names"), "Mnames") // To-fix : QMap toString() error in "numerictostringconversion.h" |
|
98 |
CT_DEFAULT_IA_END(CT_LARCHIHEADER) |
|
99 |
|
|
100 |
}; |
|
101 |
|
|
102 |
#endif // CT_LARCHIHEADER_H |