Commit c97ba63f authored by Gaurav Arora (gaa721)'s avatar Gaurav Arora (gaa721)
Browse files

Updated the Without trail stuff

parent d39bd399
import g4p_controls.*;
import com.sun.jna.platform.win32.*;
import gab.opencv.*;
import processing.video.*;
......@@ -184,7 +183,6 @@ void setupInside()
try {
out = new ObjectOutputStream(fileOut);
outE = new ObjectOutputStream(fileOutE);
outQ = new ObjectOutputStream(fileOutQ);
}
catch (IOException e) {
System.err.println(e);
......
import g4p_controls.*;
import com.sun.jna.platform.win32.*;
import gab.opencv.*;
import processing.video.*;
......@@ -15,6 +14,8 @@ import org.jnativehook.keyboard.NativeKeyEvent;
import com.sun.jna.platform.win32.WinUser.WINDOWINFO;
private static final int WS_ICONIC = 0x20000000; //for check minimized
import java.util.ArrayList;
import java.util.Scanner;
import shiffman.box2d.*;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.joints.*;
......@@ -24,9 +25,13 @@ import org.jbox2d.common.*;
import org.jbox2d.dynamics.*;
import org.jbox2d.dynamics.contacts.*;
import java.io.*;
import java.util.Date;
Box2DProcessing box2d;
boolean question;
String user = "gaa721";
float afterAttentionTime;
String participationID;
Capture video;
......@@ -61,53 +66,115 @@ int drawdelay;
boolean eof=false;
float rx, ry;
float rx1, ry1, m, c;
FileInputStream fileIn, fileInE;
FileInputStream fileIn, fileInE, fileInQ;
String currShape;
float cx, cy;
FileOutputStream fileOut, fileOutE;
FileOutputStream fileOut, fileOutE, fileOutQ;
float cradius;
ObjectOutputStream out, outE;
ObjectInputStream in, inE;
ObjectOutputStream out, outE, outQ;
ObjectInputStream in, inE, inQ;
OutputStream os;
int t;
boolean complete;
int Stime, timer;
boolean questionMouse;
float questionBoxX, questionBoxY;
boolean changingFile = false;
Date date = new Date();
//File logfile ;// new File("c:/Users/gaa721/Desktop/" + date.toString() + "-" + participationID );
PrintWriter writer;
FileWriter fw ;
BufferedWriter bw;
String folderName ;
// D)
//String[] Questions = {
// "Select the most recent portion","was line drawn first or circle was moved first? Select that ", "Select the most recent portion", "Select the new portion drawn after the black screen "
//};
// C)
//String[] Questions = {
// "Select the portion drwan immediately after the black screen","where was the deleted circle? ", "What was the initial position of the smaller circle", "In which circle something was drawn? ","was anything deleted, select that"
//};
// B)
//String[] Questions = {
// "What is starting point of the botommost line","What was the position of the circle before moving? ", "Select the most recent line drawn?", "Where was the deleted object before deletion? "
//};
// A)
//String[] Questions = {
// "What is most recent drawing","Which portion has stayed for least amount of time? ", "Which circle travlelled more distance", "What was drawn immediately after the black screen? "
//};
// "E")
String[] Questions = {
"Select the portion which was drawn after the black screen", "Select the portion which was drawn IMMEDIATELY after the black screen", "Select the portion which had stayed longest after the black Screen", "Select the portion which was drawn RECENTLY", "Select The portion which was drawn recently ", "Select The portion where circle was drawn before moving", "Select The portion which was drawn recently", "Thnaks"
"Select the portion which was drawn after the black screen", "Select the portion which was drawn IMMEDIATELY after the black screen", "Select the portion which had stayed longest after the black Screen", "Select the portion which was drawn RECENTLY", "Select The portion which was drawn recently ", "Select The starting position of new line created"
}
;
int QuestionCounter;
int frameCounter;
boolean startMenu ;
Rectangle[] r = { new Rectangle(111.0 , 65.0,347.0 , 258.0), new Rectangle(1467.0 , 265.0,1570.0 , 382.0), new Rectangle(447.0 , 209.0,529.0 , 343.0),new Rectangle(1103.0 , 185.0,1202.0 , 291.0),new Rectangle(915.0 , 208.0,958.0 , 258.0), new Rectangle(1231.0 , 660.0 , 1385.0 , 803.0),new Rectangle(1340.0 , 839.0, 1434.0 , 911.0)};
int totalShapesandTrailCount = 0;
Rectangle[] r = {
new Rectangle(111.0, 65.0, 347.0, 258.0), new Rectangle(1467.0, 265.0, 1570.0, 382.0), new Rectangle(447.0, 209.0, 529.0, 343.0), new Rectangle(1103.0, 185.0, 1202.0, 291.0), new Rectangle(915.0, 208.0, 958.0, 258.0), new Rectangle(1231.0, 660.0, 1385.0, 803.0), new Rectangle(1340.0, 839.0, 1434.0, 911.0)
};
float totalShapesandTrailCount = 0;
boolean questionSaving;
ArrayList<Question> questions ;
char tempFiler = 'E';
void setup()
{
createGUI();
startMenu = true;
setupInside();
}
void setup()
void setupInside()
{
QuestionCounter = 0;
createGUI();
button1.setVisible(false);
// createGUI1();
frameCounter = 0;
afterAttentionTime=1.2;
complete= true;
frameCounter = 0;
startMenu = true;
Stime = 0;//millis();
question = false;
timer=0;
saveornot = false;
t=0;
mover=10;
questionSaving = false;
questions = new ArrayList<Question>();
changingFile = false;
if (questionSaving)
{
try {
fileOutQ = new FileOutputStream("c:/Users/"+user+"/Desktop/" +"DrawingData/"+ tempFiler + "Quest.ser");
}
catch (FileNotFoundException ex) {
// Do something with mistake or ignore
print( ex.toString());
}
try {
outQ = new ObjectOutputStream(fileOutQ);
}
catch (IOException e) {
System.err.println(e);
}
}
if (saveornot)
{
try {
fileOut = new FileOutputStream("c:/Users/gaa721/Desktop/shapes.ser");
fileOutE = new FileOutputStream("c:/Users/gaa721/Desktop/Events.ser");
fileOut = new FileOutputStream("c:/Users/"+user+"/Desktop/" +"DrawingData/"+ tempFiler + "shapes.ser");
fileOutE = new FileOutputStream("c:/Users/"+user+"/Desktop/" +"DrawingData/"+ tempFiler + "Events.ser");
}
catch (FileNotFoundException ex) {
// Do something with mistake or ignore
......@@ -158,11 +225,10 @@ void setup()
// Turn on collision listening!
box2d.listenForCollisions();
//
rx=random(10, 490);
ry=random(10, 490);
rx1=random(10, 490);
ry1=random(10, 490);
rx = random(10, 490);
ry = random(10, 490);
rx1= random(10, 490);
ry1= random(10, 490);
//rx=20;
//ry=20;
//rx1=60;
......@@ -175,10 +241,12 @@ void setup()
currShape = "b";
try {
fileIn = new FileInputStream("c:/Users/gaa721/Desktop/shapes.ser");
fileInE = new FileInputStream("c:/Users/gaa721/Desktop/Events.ser");
fileIn = new FileInputStream("c:/Users/"+user+"/Desktop/" + "DrawingData/"+tempFiler + "shapes.ser");
fileInE = new FileInputStream("c:/Users/"+user+"/Desktop/" + "DrawingData/"+tempFiler + "Events.ser");
fileInQ = new FileInputStream("c:/Users/"+user+"/Desktop/" + "DrawingData/"+tempFiler + "Quest.ser");
in = new ObjectInputStream(fileIn);
inE = new ObjectInputStream(fileInE);
inQ = new ObjectInputStream(fileInQ);
}
catch(FileNotFoundException o)
{
......@@ -216,82 +284,117 @@ void setup()
return;
}
}
//print(p.shapes.size());
for (Shape s: p.shapes)
eof = false;
if (!questionSaving)
{
//print(s.data.shape);
try {
while (!eof)
{
Question tempQuest = (Question) inQ.readObject();
questions.add(tempQuest);
}
}
catch(ClassNotFoundException i) {
}
catch(java.io.EOFException ex1)
{
eof=true;
}
catch(IOException i)
{
i.printStackTrace();
return;
}
}
//print(p.shapes.size());
// for (Shape s: p.shapes)
// {
// //print(s.data.shape);
// }
}
void draw()
{
if (!saveornot)
if (!changingFile)
{
if (!startMenu)
if (!saveornot)
{
// attention = true;
timer = totalShapesandTrailCount - Stime;
// print(timer + " ") ;
if (!question )
if (!startMenu)
{
if (timer<=100 )
{
attention = true;
drawing();
}
else
// attention = true;
timer = (int)totalShapesandTrailCount - Stime;
// print(timer + " ") ;
if (!question )
{
attention = true;
drawing();
background(0, 0, 0);
if(p.Ecounter>=p.e.e.size()-3 )
timer= 250;
if (timer>=250 )
if (timer<=100 )
{
timer = 0;
Stime = totalShapesandTrailCount;
question = true;
attention = true;
drawing();
fill(0, 0, 0);
text(Questions[QuestionCounter], 600, 600);
}
else
{
attention = true;
drawing();
background(0, 0, 0);
if (p.Ecounter>=p.e.e.size()-3 )
timer= 200;
if (timer>=200 )
{
timer = 0;
Stime = (int)totalShapesandTrailCount;
question = true;
drawing();
textSize(20);
fill(0, 0, 0);
if (!questionSaving)
text(questions.get(QuestionCounter).getQuestion(), 600, 600);
else
text(Questions[QuestionCounter], 600, 600);
}
}
}
}
if (question)
{
if (question)
{
if (!questionMouse)
{
if (mousePressed)
if (!questionMouse)
{
pushMatrix();
background(255);
p.drawAll();
pushMatrix();
rectMode(CORNERS);
// rect((float)r[QuestionCounter].p1.x,(float)r[QuestionCounter].p1.y,(float)r[QuestionCounter].p2.x,(float)r[QuestionCounter].p2.y);
popMatrix();
text(Questions[QuestionCounter], 600, 600);
rectMode(CORNERS);
fill(0, 0, 0, 80);
// rect(questionBoxX, questionBoxY, sqrt(sq(mouseX-questionBoxX) + sq(mouseY - questionBoxY)), sqrt(sq(mouseX-questionBoxX) + sq(mouseY - questionBoxY)));
rect(questionBoxX, questionBoxY, mouseX,mouseY);
popMatrix();
if (mousePressed)
{
pushMatrix();
background(255);
p.drawAll();
pushMatrix();
rectMode(CORNERS);
textSize(20);
// if(!questionSaving)
// rect((float)questions.get(QuestionCounter).answer.p1.x, (float)questions.get(QuestionCounter).answer.p1.y, (float)questions.get(QuestionCounter).answer.p2.x, (float)questions.get(QuestionCounter).answer.p2.y);
popMatrix();
if (!questionSaving)
text(questions.get(QuestionCounter).getQuestion(), 600, 600);
else
text(Questions[QuestionCounter], 600, 600);
rectMode(CORNERS);
fill(0, 0, 0, 80);
// rect(questionBoxX, questionBoxY, sqrt(sq(mouseX-questionBoxX) + sq(mouseY - questionBoxY)), sqrt(sq(mouseX-questionBoxX) + sq(mouseY - questionBoxY)));
rect(questionBoxX, questionBoxY, mouseX, mouseY);
popMatrix();
}
}
}
}
} //drawing();
} //drawing();
}
else
drawing();
}
else
drawing();
}
......@@ -320,7 +423,10 @@ void mousePressed()
// }
if (question && questionMouse)
{
text("Select the portion which was drawn first after the black screen", 600, 600);
if (!questionSaving)
text(questions.get(QuestionCounter).getQuestion(), 600, 600);
else
text(Questions[QuestionCounter], 600, 600);
questionBoxX=mouseX;
questionBoxY=mouseY;
// ellipse(questionBoxX, questionBoxY, 10, 10);
......@@ -335,6 +441,7 @@ void mouseReleased()
mp=false;
p.e.addEvent('d', p.shapes.size());
print(totalShapesandTrailCount++ + " ");
p.addShape(currShape, cx, cy, cradius);
}
if (question)
......@@ -345,89 +452,73 @@ void mouseReleased()
// rect(questionBoxX,questionBoxX,mouseX,mouseY);
questionMouse = true;
question = false;
Rectangle r1 = new Rectangle(questionBoxX,questionBoxY , mouseX ,mouseY);
// print(questionBoxX + " " +questionBoxY + " " +mouseX + " " +mouseY);
r[QuestionCounter].show();
r1.show();
double intersection = r1.getIntersectionPercent(r[QuestionCounter],r1);
print(intersection);
if( intersection > 75.0 && (r1.getArea()/r[QuestionCounter].getArea()) <2.00)
{
print("yes");
}
save("/"+participationID+ "/" + ++frameCounter + ".png");
// Box tempBox = new Box((int)questionBoxX, (int)questionBoxY, (int)sqrt(sq(mouseX-questionBoxX) + sq(mouseY - questionBoxY)), (int)sqrt(sq(mouseX-questionBoxX) + sq(mouseY - questionBoxY)));
//
// ArrayList<Float> fxL = new ArrayList<Float>();
// ArrayList<Float> fyL = new ArrayList<Float>();
// ArrayList<Point> tempPoints
// for (Shape p1 : p.nshapes)
// {
//
//
//
// // print(p.x +"\n");
// if (tempBox.contains(p1.data.x, p1.data.y))
// {
// //print(p.x);
// fxL.add( p1.data.x);
// fyL.add( p1.data.y);
//
// // printPoint.add(p1,);
// }
// }
// Float[] fx = new Float[fxL.size()];
// Float[] fy = new Float[fyL.size()];
//
// fx = fxL.toArray(fx);
// fy = fyL.toArray(fy);
// println("\nx:");
// for (int i=0;i<fx.length;i++)
// print(fx[i] + ",");
//
// println("\ny:");
//
// for (int i=0;i<fy.length;i++)
// print(fy[i] + ",");
// // printPoint.clear();
// if (similarityQuestiont(fx, correctX[QuestionCounter]) && similarityQuestiont(fy, correctY[QuestionCounter]))
// print("yipppeee");
// else
// print("no");
QuestionCounter++;
if (QuestionCounter>=Questions.length)
Rectangle r1 = new Rectangle(questionBoxX, questionBoxY, mouseX, mouseY);
// print(questionBoxX + " " +questionBoxY + " " +mouseX + " " +mouseY);
r1.show();
if (!questionSaving)
{
questions.get(QuestionCounter).answer.show();
double intersection = r1.getIntersectionPercent(questions.get(QuestionCounter).answer, r1);
double bigRecRatio = (r1.getArea()/questions.get(QuestionCounter).answer.getArea());
print(intersection);
String rightorwronng = "";
if ( intersection > 70.0 && bigRecRatio <2.00)
{
rightorwronng = "Correct";
}
else if ( intersection > 40.0 && bigRecRatio <2.00)
{
rightorwronng = "Maybe";
}
else if (intersection > 70.0)
rightorwronng = "overFlow Correct";
else if ( intersection > 40.0)
rightorwronng = "overFlow maybe";
else rightorwronng = "Incorrect";
writer.println("Date " + date.toString() + " Timestamp: " + millis() + " Partipation ID: " + participationID +" Trial number: " + tempFiler + (QuestionCounter+1) + " Correct Answer: " + RectoString(questions.get(QuestionCounter).answer) + " Answer Given: " + RectoString(r1) +" Intersection Percentage: " + intersection + " Answer Given/ Answer Ratio: "+ bigRecRatio +" Comment: " + rightorwronng );
pushMatrix();
textSize(20);
fill(0, 0, 0);
text( "participationID: " + participationID, 200, 200);
popMatrix();
save(folderName + "/" + day()+"-"+month()+"-"+year()+"-"+ hour()+"-"+minute() +"-"+second()+ "-" +millis() +"-"+ participationID +"-" + tempFiler + (QuestionCounter+1)+ ".png");
QuestionCounter++;
if (QuestionCounter>=questions.size())
{
noLoop();
background(255, 255, 255);
textSize(20);
text("Thanks", 200, 200);
// createGUI1();
button1.setVisible(true);
changingFile = true;
// noLoop();
}
}
else
{
try {
outQ.writeObject(new Question(Questions[QuestionCounter++], r1));
}
catch(IOException i) {
}
}
timer = 0;
Stime = totalShapesandTrailCount;
Stime = (int)totalShapesandTrailCount;
}
moving=false;
for ( Shape s : p.shapes)
s.data.mving=false;
//p.nshapes.clear();
//p.nshapes.clear();
}
void keyPressed()
{
......@@ -508,6 +599,30 @@ void drawing()
box2d.step();
background(255, 255, 255);
if (saveornot)
{
timer = (int)totalShapesandTrailCount - Stime;
// print(timer + " ") ;
if (timer<=100 )
{
}
else if (timer>=200 )
{
timer = 0;
Stime = (int)totalShapesandTrailCount;
}
else
background(0, 0, 0);
}
/*
opencv.loadImage(video);
faces = opencv.detect();
......@@ -543,7 +658,10 @@ void drawing()
cy=mouseY;
// print(p.e);
if (saveornot)
{
p.e.addEvent('d', p.shapes.size());
print(totalShapesandTrailCount++ + " ");
}
p.addShape("b", cx, cy, 10);
}
......@@ -559,7 +677,7 @@ void drawing()
{