处理Class/object变量堆叠
Processing Class/object variable stacking
所以我有一个问题,我以前在更简单的程序中设法(侥幸地)解决了这个问题,但仍然不知道实际问题是什么。
我创建了一个包含以下变量的 class g1.display(tableHr, hrMeasure, 37, 10, 20,160, 0);
。问题是,当我 运行 class 的一个对象时,一切都很好,并且创建了一个漂亮的图形。虽然当我 运行 class 的两个对象时,程序中的第一个图形 运行 很好,而第二个变得不成比例。几乎就像变量在相互堆叠或相乘。
有人熟悉这个问题吗?
主草图的代码:
Graph g1 = new Graph();
Button b1 = new Button();
TableRow hrMeasure;
TableRow spoMeasure;
TableRow tempMeasure;
Table tableHr;
Table tableSpo;
Table tableAbp;
Table tableResp;
Table tableTemp;
int i;
int border;
float p;
PFont font;
PFont font2;
String alarmColor;
void setup(){
font = loadFont("data/OpenSans-36.vlw");
textFont(font,36);
frameRate(15);
smooth(8);
size(1024,768);
tableHr = loadTable("testfile.csv", "header");
tableSpo = loadTable("testfile2.csv", "header");
tableAbp = loadTable("testfile3.csv", "header");
tableResp = loadTable("testfile4.csv", "header");
tableTemp = loadTable("testfile5.csv", "header");
}
void draw(){
retrieveData();
GUI();
relativeGraph();
buttons();
g1.display(tableHr, hrMeasure, 40, 15, 25,200,100);
// g1.display(tableSpo, spoMeasure, 37, 1, 3,160,2);
// g1.display(tableTemp, tempMeasure, 37, 1, 3,160,3);
// g1.display(tableHr, hrMeasure, 37, 13, 18,160,4);
// g1.display(tableHr, hrMeasure, 37, 13, 18,160,5);
}
//retrieving data from the csv file
void retrieveData(){
i++;
hrMeasure = tableHr.getRow(i);
spoMeasure = tableSpo.getRow(i);
tempMeasure = tableTemp.getRow(i);
}
Class:
class Graph {
int adjustment;
float p;
int greenRelative, yellowRelative, redRelative;
float[] measure = new float[1500000];
String alarmColor;
int timer, counter;
int greenTimer, yellowTimer, redTimer;
int graphHeight = 80;
int graphLength = 800;
void display(Table table, TableRow measurement, int average, int bound1, int bound2,int x, int y){
p = measurement.getFloat("value");
pushMatrix();
translate(width,0);
scale(-1,1);
for (int i = 0; i < table.getRowCount(); i++){
adjustment = width-table.getRowCount()-x; // adjustment to the x-coordinate, so every graph will start at 0
//if statement for green readings
if(measure[i] > average-bound1 && measure[i] < average+bound1){
stroke(0, 255, 0);
strokeWeight(1);
alarmColor = "green";
}else{
//if statement for yellow readings
if(measure[i] <= average-bound1 && measure[i] > average-bound2|| measure[i] >= average+bound1 && measure[i] < average+bound2){
stroke(255, 255, 0);
strokeWeight(1);
alarmColor = "yellow";
//else red
}else{stroke(255, 0, 0);
strokeWeight(1);
alarmColor = "red";
}}
line(i+adjustment, graphHeight-map(measure[i], average-bound1-bound2, 37, 0,graphHeight/2)+y, (i+1)+adjustment, graphHeight-map(measure[i+1], average-bound1-bound2, 37, 0,graphHeight/2)+y);
}
popMatrix();
for(int i=0; i < table.getRowCount(); i++){
measure[i] = measure[i+1];
measure[i+1] = p;
println(measure[i]);
}
确保您使用的是独立实例,例如:
Graph g1 = new Graph();
Graph g2 = new Graph();
然后在 draw()
:
g1.display(tableHr, hrMeasure, 40, 15, 25,200,100);
g2.display(tableSpo, spoMeasure, 37, 1, 3,160,2);
完整列表:
Graph g1 = new Graph();
Graph g2 = new Graph();
Graph g3 = new Graph();
Graph g4 = new Graph();
Graph g5 = new Graph();
Button b1 = new Button();
TableRow hrMeasure;
TableRow spoMeasure;
TableRow tempMeasure;
Table tableHr;
Table tableSpo;
Table tableAbp;
Table tableResp;
Table tableTemp;
int i;
int border;
float p;
PFont font;
PFont font2;
String alarmColor;
void setup(){
font = loadFont("data/OpenSans-36.vlw");
textFont(font,36);
frameRate(15);
smooth(8);
size(1024,768);
tableHr = loadTable("testfile.csv", "header");
tableSpo = loadTable("testfile2.csv", "header");
tableAbp = loadTable("testfile3.csv", "header");
tableResp = loadTable("testfile4.csv", "header");
tableTemp = loadTable("testfile5.csv", "header");
}
void draw(){
retrieveData();
GUI();
relativeGraph();
buttons();
g1.display(tableHr, hrMeasure, 40, 15, 25,200,100);
g2.display(tableSpo, spoMeasure, 37, 1, 3,160,2);
g3.display(tableTemp, tempMeasure, 37, 1, 3,160,3);
g4.display(tableHr, hrMeasure, 37, 13, 18,160,4);
g5.display(tableHr, hrMeasure, 37, 13, 18,160,5);
}
//retrieving data from the csv file
void retrieveData(){
i++;
hrMeasure = tableHr.getRow(i);
spoMeasure = tableSpo.getRow(i);
tempMeasure = tableTemp.getRow(i);
}
class Graph {
int adjustment;
float p;
int greenRelative, yellowRelative, redRelative;
float[] measure = new float[1500000];
String alarmColor;
int timer, counter;
int greenTimer, yellowTimer, redTimer;
int graphHeight = 80;
int graphLength = 800;
void display(Table table, TableRow measurement, int average, int bound1, int bound2,int x, int y){
p = measurement.getFloat("value");
pushMatrix();
translate(width,0);
scale(-1,1);
for (int i = 0; i < table.getRowCount(); i++){
adjustment = width-table.getRowCount()-x; // adjustment to the x-coordinate, so every graph will start at 0
//if statement for green readings
if(measure[i] > average-bound1 && measure[i] < average+bound1){
stroke(0, 255, 0);
strokeWeight(1);
alarmColor = "green";
}else{
//if statement for yellow readings
if(measure[i] <= average-bound1 && measure[i] > average-bound2|| measure[i] >= average+bound1 && measure[i] < average+bound2){
stroke(255, 255, 0);
strokeWeight(1);
alarmColor = "yellow";
//else red
}else{stroke(255, 0, 0);
strokeWeight(1);
alarmColor = "red";
}}
line(i+adjustment, graphHeight-map(measure[i], average-bound1-bound2, 37, 0,graphHeight/2)+y, (i+1)+adjustment, graphHeight-map(measure[i+1], average-bound1-bound2, 37, 0,graphHeight/2)+y);
}
popMatrix();
for(int i=0; i < table.getRowCount(); i++){
measure[i] = measure[i+1];
measure[i+1] = p;
println(measure[i]);
}
所以我有一个问题,我以前在更简单的程序中设法(侥幸地)解决了这个问题,但仍然不知道实际问题是什么。
我创建了一个包含以下变量的 class g1.display(tableHr, hrMeasure, 37, 10, 20,160, 0);
。问题是,当我 运行 class 的一个对象时,一切都很好,并且创建了一个漂亮的图形。虽然当我 运行 class 的两个对象时,程序中的第一个图形 运行 很好,而第二个变得不成比例。几乎就像变量在相互堆叠或相乘。
有人熟悉这个问题吗?
主草图的代码:
Graph g1 = new Graph();
Button b1 = new Button();
TableRow hrMeasure;
TableRow spoMeasure;
TableRow tempMeasure;
Table tableHr;
Table tableSpo;
Table tableAbp;
Table tableResp;
Table tableTemp;
int i;
int border;
float p;
PFont font;
PFont font2;
String alarmColor;
void setup(){
font = loadFont("data/OpenSans-36.vlw");
textFont(font,36);
frameRate(15);
smooth(8);
size(1024,768);
tableHr = loadTable("testfile.csv", "header");
tableSpo = loadTable("testfile2.csv", "header");
tableAbp = loadTable("testfile3.csv", "header");
tableResp = loadTable("testfile4.csv", "header");
tableTemp = loadTable("testfile5.csv", "header");
}
void draw(){
retrieveData();
GUI();
relativeGraph();
buttons();
g1.display(tableHr, hrMeasure, 40, 15, 25,200,100);
// g1.display(tableSpo, spoMeasure, 37, 1, 3,160,2);
// g1.display(tableTemp, tempMeasure, 37, 1, 3,160,3);
// g1.display(tableHr, hrMeasure, 37, 13, 18,160,4);
// g1.display(tableHr, hrMeasure, 37, 13, 18,160,5);
}
//retrieving data from the csv file
void retrieveData(){
i++;
hrMeasure = tableHr.getRow(i);
spoMeasure = tableSpo.getRow(i);
tempMeasure = tableTemp.getRow(i);
}
Class:
class Graph {
int adjustment;
float p;
int greenRelative, yellowRelative, redRelative;
float[] measure = new float[1500000];
String alarmColor;
int timer, counter;
int greenTimer, yellowTimer, redTimer;
int graphHeight = 80;
int graphLength = 800;
void display(Table table, TableRow measurement, int average, int bound1, int bound2,int x, int y){
p = measurement.getFloat("value");
pushMatrix();
translate(width,0);
scale(-1,1);
for (int i = 0; i < table.getRowCount(); i++){
adjustment = width-table.getRowCount()-x; // adjustment to the x-coordinate, so every graph will start at 0
//if statement for green readings
if(measure[i] > average-bound1 && measure[i] < average+bound1){
stroke(0, 255, 0);
strokeWeight(1);
alarmColor = "green";
}else{
//if statement for yellow readings
if(measure[i] <= average-bound1 && measure[i] > average-bound2|| measure[i] >= average+bound1 && measure[i] < average+bound2){
stroke(255, 255, 0);
strokeWeight(1);
alarmColor = "yellow";
//else red
}else{stroke(255, 0, 0);
strokeWeight(1);
alarmColor = "red";
}}
line(i+adjustment, graphHeight-map(measure[i], average-bound1-bound2, 37, 0,graphHeight/2)+y, (i+1)+adjustment, graphHeight-map(measure[i+1], average-bound1-bound2, 37, 0,graphHeight/2)+y);
}
popMatrix();
for(int i=0; i < table.getRowCount(); i++){
measure[i] = measure[i+1];
measure[i+1] = p;
println(measure[i]);
}
确保您使用的是独立实例,例如:
Graph g1 = new Graph();
Graph g2 = new Graph();
然后在 draw()
:
g1.display(tableHr, hrMeasure, 40, 15, 25,200,100);
g2.display(tableSpo, spoMeasure, 37, 1, 3,160,2);
完整列表:
Graph g1 = new Graph();
Graph g2 = new Graph();
Graph g3 = new Graph();
Graph g4 = new Graph();
Graph g5 = new Graph();
Button b1 = new Button();
TableRow hrMeasure;
TableRow spoMeasure;
TableRow tempMeasure;
Table tableHr;
Table tableSpo;
Table tableAbp;
Table tableResp;
Table tableTemp;
int i;
int border;
float p;
PFont font;
PFont font2;
String alarmColor;
void setup(){
font = loadFont("data/OpenSans-36.vlw");
textFont(font,36);
frameRate(15);
smooth(8);
size(1024,768);
tableHr = loadTable("testfile.csv", "header");
tableSpo = loadTable("testfile2.csv", "header");
tableAbp = loadTable("testfile3.csv", "header");
tableResp = loadTable("testfile4.csv", "header");
tableTemp = loadTable("testfile5.csv", "header");
}
void draw(){
retrieveData();
GUI();
relativeGraph();
buttons();
g1.display(tableHr, hrMeasure, 40, 15, 25,200,100);
g2.display(tableSpo, spoMeasure, 37, 1, 3,160,2);
g3.display(tableTemp, tempMeasure, 37, 1, 3,160,3);
g4.display(tableHr, hrMeasure, 37, 13, 18,160,4);
g5.display(tableHr, hrMeasure, 37, 13, 18,160,5);
}
//retrieving data from the csv file
void retrieveData(){
i++;
hrMeasure = tableHr.getRow(i);
spoMeasure = tableSpo.getRow(i);
tempMeasure = tableTemp.getRow(i);
}
class Graph {
int adjustment;
float p;
int greenRelative, yellowRelative, redRelative;
float[] measure = new float[1500000];
String alarmColor;
int timer, counter;
int greenTimer, yellowTimer, redTimer;
int graphHeight = 80;
int graphLength = 800;
void display(Table table, TableRow measurement, int average, int bound1, int bound2,int x, int y){
p = measurement.getFloat("value");
pushMatrix();
translate(width,0);
scale(-1,1);
for (int i = 0; i < table.getRowCount(); i++){
adjustment = width-table.getRowCount()-x; // adjustment to the x-coordinate, so every graph will start at 0
//if statement for green readings
if(measure[i] > average-bound1 && measure[i] < average+bound1){
stroke(0, 255, 0);
strokeWeight(1);
alarmColor = "green";
}else{
//if statement for yellow readings
if(measure[i] <= average-bound1 && measure[i] > average-bound2|| measure[i] >= average+bound1 && measure[i] < average+bound2){
stroke(255, 255, 0);
strokeWeight(1);
alarmColor = "yellow";
//else red
}else{stroke(255, 0, 0);
strokeWeight(1);
alarmColor = "red";
}}
line(i+adjustment, graphHeight-map(measure[i], average-bound1-bound2, 37, 0,graphHeight/2)+y, (i+1)+adjustment, graphHeight-map(measure[i+1], average-bound1-bound2, 37, 0,graphHeight/2)+y);
}
popMatrix();
for(int i=0; i < table.getRowCount(); i++){
measure[i] = measure[i+1];
measure[i+1] = p;
println(measure[i]);
}