-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathstateList.h
106 lines (86 loc) · 3.41 KB
/
stateList.h
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
/*
Copyright (c) 2013, Timothy Gerstner, All rights reserved.
This code is part of the prototype C++ implementation of our paper/ my thesis.
Public repository: https://github.com/timgerst/pix
Project Webpage: http://www.research.rutgers.edu/~timgerst/
This code 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 code 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 code. If not, see <http://www.gnu.org/licenses/>.
Author: Timothy Gerstner, [email protected]
Description: Used to store the states of the algorithm for undo/redo operations.
This is techinically not necessary for the algorithm to run, but greately reduces
the overhead of undo/redo operations with the accompanying UI.
*/
#pragma once
#include <opencv2/opencv.hpp>
#include <vector>
#include <list>
struct pixState
{
cv::Mat superpixel_pos;
cv::Mat superpixel_color;
cv::Mat palette_assign;
std::vector<cv::Vec3f> palette;
std::vector<float> prob_c;
std::vector<bool> locked_colors;
std::vector<std::list<int> > pixel_constraints;
std::vector<std::pair<int,int> > sub_superpixel_pairs;
int iteration;
float saturation;
pixState(){};
pixState(const pixState& other)
{
other.superpixel_pos.copyTo(superpixel_pos);
other.superpixel_color.copyTo(superpixel_color);
superpixel_color = cv::Mat(other.superpixel_color);
palette_assign = cv::Mat(other.palette_assign);
palette = std::vector<cv::Vec3f>(other.palette);
prob_c = std::vector<float>(other.prob_c);
locked_colors = std::vector<bool>(other.locked_colors);
pixel_constraints = std::vector<std::list<int> >(other.pixel_constraints);
sub_superpixel_pairs = std::vector<std::pair<int,int> >(other.sub_superpixel_pairs);
iteration = other.iteration;
saturation = other.saturation;
}
};
class stateList
{
struct stateNode
{
pixState * val;
stateNode * prev;
stateNode * next;
stateNode(pixState * n): val(n), prev(NULL), next(NULL){}
~stateNode(){ delete val;}
};
public:
//constructs a statelist with a single state
stateList(int maxSize);
~stateList(){}
//pushes a copy of the current state onto the list and makes it the current
//state If the current state had any children, they are deleted. If the
//total number of states exceeds the maximum specified at construction,
//states are removed from the front of the list until this bound is met.
void push_copy();
//moves the current state to the previous state, while retaining
//the current state in memory. Does not change the state if no previous
//state exists.
void stepBack();
//moves the current state to the next state, while retaining the
//current state in memory. Does not change the state if no next state exists.
void stepForward();
//returns the current state
pixState * getCur() {return current_->val;}
private:
stateNode* head_;
stateNode* current_;
int max_size_;
int current_size_;
};