This repository has been archived by the owner on Apr 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.cpp
168 lines (142 loc) · 4.21 KB
/
backend.cpp
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*********************************************************************
Hypersimplex Representer
Copyright (C) 2017 Roman Gilg
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#include "backend.h"
#include "hypersimplex.h"
#include "gimatrix.h"
#include <QtConcurrent/QtConcurrentRun>
BackEnd::BackEnd(QObject *parent) :
QObject(parent)
{}
BackEnd::~BackEnd()
{
if (::s_hypers) {
delete ::s_hypers;
::s_hypers = nullptr;
}
delete m_reprMatrix;
}
facet_pair BackEnd::getFacetPair(int index) const
{
if (::s_hypers = nullptr) {
return facet_pair(std::vector<Vertex>(), std::vector<Vertex>());
}
return ::s_hypers->getFacetPair(index);
}
void BackEnd::createHypersimplex(int d, int k)
{
m_ready = false;
emit readyChanged();
setVtxTrSubgroups(std::vector<std::string>());
setSelectedSubgroup(0);
QtConcurrent::run(::s_createHypersimplex, d, k);
m_checkReadyTimer = new QTimer(this);
connect(m_checkReadyTimer, SIGNAL(timeout()), this, SLOT(checkReady()));
m_checkReadyTimer->start(1000);
}
void BackEnd::setSelectedSubgroup(int set) {
if (m_selectedSubgroup != set) {
m_selectedSubgroup = set;
setGiMatrix(set);
setEecWraps();
emit selectedSubgroupChanged();
}
}
void BackEnd::setSelEigenvectMode(int mode)
{
if (m_selEigenvectMode != mode) {
m_selEigenvectMode = mode;
if(m_reprMatrix) {
m_reprMatrix->setSelEigenvectMode(mode);
m_reprMatrix->calcNullspaceRepr();
}
emit selEigenvectModeChanged();
emit geometryInitNeeded();
}
}
void BackEnd::setEecWraps() {
auto clear = [this]() {
for (auto eW : m_eecWraps) {
delete eW;
}
m_eecWraps.clear();
};
if (m_reprMatrix) {
clear();
auto vars = m_reprMatrix->getVars();
auto mults = m_reprMatrix->getMultiplicities();
for (int i = 0; i < vars.size(); i++) {
auto eecWrap = new EecWrap(this, vars[i], mults[i]);
m_eecWraps.append(eecWrap);
}
emit eecWrapsChanged();
} else if (!m_eecWraps.isEmpty()) {
clear();
emit eecWrapsChanged();
}
}
void BackEnd::setVars(QList<double > vars)
{
m_reprMatrix->setVars(vars.toVector().toStdVector());
emit geometryUpdateNeeded();
}
void BackEnd::setGiMatrix(int subgroup)
{
delete m_reprMatrix;
m_reprMatrix = new GiMatrix(::s_hypers->getGiMatrix(subgroup));
m_reprMatrix->setSelEigenvectMode(m_selEigenvectMode);
m_reprMatrix->init();
emit geometryInitNeeded();
}
void BackEnd::checkReady()
{
if (!::s_ready) {
return;
}
if (!m_ready) {
m_ready = ::s_ready;
emit readyChanged();
if (m_checkReadyTimer) {
delete m_checkReadyTimer;
m_checkReadyTimer = nullptr;
}
setVtxTrSubgroups(::s_hypers->getVtxTrSubgroupNames());
}
}
void BackEnd::setVtxTrSubgroups(std::vector<std::string> subNames)
{
bool changed = false;
if (subNames.size() != m_vtxTrSubgroups.size()) {
changed = true;
}
if (!changed) {
int index = 0;
for (auto s : m_vtxTrSubgroups) {
if (QString::compare(s, subNames[index].c_str()) != 0) {
changed = true;
break;
}
index++;
}
}
if (changed) {
m_vtxTrSubgroups.clear();
for (std::string sub : subNames) {
m_vtxTrSubgroups.append(QString(sub.c_str()));
}
setGiMatrix(0);
setEecWraps();
emit vtxTrSubgroupsChanged();
}
}