diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2022-09-13 23:43:54 +0200 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2022-09-13 23:43:54 +0200 |
commit | 42c2ccd11ba20a1ae396b6d64caaef68d8506ca0 (patch) | |
tree | e726d484010ec9edd4aad7016b04b8db8260428c | |
parent | 4ed15ffe73f83dfaaddd796021740864dbff4def (diff) | |
download | code-42c2ccd11ba20a1ae396b6d64caaef68d8506ca0.tar.gz code-42c2ccd11ba20a1ae396b6d64caaef68d8506ca0.tar.bz2 code-42c2ccd11ba20a1ae396b6d64caaef68d8506ca0.zip |
Some code simplification.
-rw-r--r-- | rbmp.cpp | 45 |
1 files changed, 19 insertions, 26 deletions
@@ -29,31 +29,28 @@ public: class HalfEdge { private: - unsigned index; Vertex* tail; Vertex* head; public: double oldX; double X; - double w; - void setIndex(unsigned i) {index = i;} - unsigned getIndex() const {return index;} + double weight; void setVertices(Vertex& vt, Vertex& vh) { tail = &vt; head = &vh; } - Vertex* getHead() { - return head; + Vertex& getHead() { + return *head; } - Vertex* getTail() { - return tail; + Vertex& getTail() { + return *tail; } - const Vertex* getHead() const { - return head; + const Vertex& getHead() const { + return *head; } - const Vertex* getTail() const { - return tail; + const Vertex& getTail() const { + return *tail; } }; @@ -70,8 +67,6 @@ public: blueVertices[i].setIndex(i); } for (unsigned i = 0; i < redEdges.size(); i++) { - redEdges[i].setIndex(i); - blueEdges[i].setIndex(i); Vertex& blueVertex = blueVertices[(i % (2 * n)) / 2 + n * (((i + 2*n) / 4) / n)]; Vertex& redVertex = redVertices[(1+(i % (2 * n))) / 2 + (n + 1) * ((i / 4) / (n))]; redEdges[i].setVertices(redVertex, blueVertex); @@ -83,28 +78,26 @@ public: redEdges[i].oldX = 0; blueEdges[i].oldX = 0; double w = r.variate<double, std::exponential_distribution>(1); - redEdges[i].w = w; - blueEdges[i].w = w; + redEdges[i].weight = w; + blueEdges[i].weight = w; } } void propagateBeliefs() { for (HalfEdge& e : redEdges) { double Xt = std::numeric_limits<double>::infinity(); - const Vertex* head = e.getHead(); - for (const HalfEdge* en : head->neighbors) { - if (e.getTail()->getIndex() != en->getHead()->getIndex()) { - Xt = std::min(en->w - en->oldX, Xt); + for (const HalfEdge* en : e.getHead().neighbors) { + if (e.getTail().getIndex() != en->getHead().getIndex()) { + Xt = std::min(en->weight - en->oldX, Xt); } } e.X = Xt; } for (HalfEdge& e : blueEdges) { double Xt = std::numeric_limits<double>::infinity(); - const Vertex* head = e.getHead(); - for (const HalfEdge* en : head->neighbors) { - if (e.getTail()->getIndex() != en->getHead()->getIndex()) { - Xt = std::min(en->w - en->oldX, Xt); + for (const HalfEdge* en : e.getHead().neighbors) { + if (e.getTail().getIndex() != en->getHead().getIndex()) { + Xt = std::min(en->weight - en->oldX, Xt); } } e.X = Xt; @@ -128,11 +121,11 @@ int main() { } for (unsigned i = 0; i < G.blueEdges.size(); i++) { - std::cout << G.blueEdges[i].getTail()->getIndex() << " " << G.blueEdges[i].getHead()->getIndex() + G.blueVertices.size() << std::endl; + std::cout << G.blueEdges[i].getTail().getIndex() << " " << G.blueEdges[i].getHead().getIndex() + G.blueVertices.size() << std::endl; } for (unsigned i = 0; i < G.blueEdges.size(); i++) { if (G.blueEdges[i].X + G.redEdges[i].X >= 0) { - std::cout << G.blueEdges[i].getTail()->getIndex() << " " << G.blueEdges[i].getHead()->getIndex() + G.blueVertices.size() << std::endl; + std::cout << G.blueEdges[i].getTail().getIndex() << " " << G.blueEdges[i].getHead().getIndex() + G.blueVertices.size() << std::endl; } } |