-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheimapmodel.cpp
More file actions
136 lines (116 loc) · 2.97 KB
/
heimapmodel.cpp
File metadata and controls
136 lines (116 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include "heimapmodel.h"
#include "tiffreader.h"
HeiMapModel::HeiMapModel(QObject *parent)
: QAbstractListModel(parent)
{
}
QHash<int, QByteArray> HeiMapModel::roleNames() const
{
return { {Qt::DisplayRole, "display"}, {Qt::UserRole+1, "row"}, {Qt::UserRole+2, "column"}, {Qt::UserRole+3, "value"} };
}
QVariant HeiMapModel::headerData(int /*section*/, Qt::Orientation /*orientation*/, int /*role*/) const
{
return QVariant();
// FIXME: Implement me!
}
void HeiMapModel::loadImage(QString path)
{
if (reader)
{
delete reader;
reader = nullptr;
}
int type = 0;
switch (type)
{
default:
reader = new TiffReader();
break;
}
reader->open(path.toStdWString().c_str());
beginInsertRows(QModelIndex(), 0, reader->height() * reader->widght());
sdata = new float *[reader->height()];
for (int i = 0; i < reader->height(); ++i)
{
sdata[i] = reinterpret_cast<float*>(reader->getRowData(i));
}
endInsertRows();
}
//const int L= 1000;
int HeiMapModel::rowCount(const QModelIndex &parent) const
{
// For list models only the root node (an invalid parent) should return the list's size. For all
// other (valid) parents, rowCount() should return 0 so that it does not become a tree model.
if (parent.isValid() || reader==nullptr)
return 0;
return reader->height() * reader->widght();
// return L*L;
// FIXME: Implement me!
}
QVariant HeiMapModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()|| reader==nullptr)
return QVariant();
int row = getRow(index);
int col = getColumn(index);
switch (role)
{
case Qt::UserRole + 1: //row
return row;
case Qt::UserRole + 2: //col
return col;
case Qt::UserRole + 3: //value
return sdata[row][col];
void *data = reader->getRow(row);
switch (reader->getType())
{
case ImageType::float32:
float *fdata = reinterpret_cast<float *>(data);
// HeiValue val;
// val.row = row;
// val.col = col;
// val.value = fdata[index.column()];
// return val.value;
//QVariant::fromValue(val);
// qDebug() << "row:" << row << " col:" << col << " value:" << fdata[col];
return fdata[col];
}
return QVariant();
}
// FIXME: Implement me!
return QVariant();
}
QVariant HeiMapModel::getData(const QModelIndex &index) const
{
if (!index.isValid()|| reader==nullptr)
return QVariant ();
void *data = reader->getRow(index.row());
switch (reader->getType())
{
case ImageType::float32:
float *fdata = reinterpret_cast<float *>(data);
// HeiValue val;
// val.row = row;
// val.col = col;
// val.value = fdata[index.column()];
return fdata[index.column()];
//QVariant::fromValue(val);
break;
}
return QVariant();
}
qint32 HeiMapModel::getRow(const QModelIndex &index) const
{
return index.row() / reader->widght();
// return L;
//reader->widght();
}
qint32 HeiMapModel::getColumn(const QModelIndex &index) const
{
return index.row() % reader->widght();
// return index.row() % L;
}
//int HeiMapModel::columnCount(const QModelIndex &parent) const
//{
// return reader->widght();
//}