Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ plugins {
}

group = "io.github.codegrits"
version = "0.3.2"
version = "0.3.2-dev1"

repositories {
mavenCentral()
Expand Down
27 changes: 24 additions & 3 deletions src/main/java/trackers/EyeTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import utils.AvailabilityChecker;
import utils.RelativePathGetter;
import utils.XMLWriter;

Expand Down Expand Up @@ -61,6 +62,12 @@ public class EyeTracker implements Disposable {
String pythonScriptTobii;
String pythonScriptMouse;
int deviceIndex = 0;
/**
* This variable indicates whether the gaze coordinates are normalized to the screen size,
* that is returned as values between (0, 0) for the upper left corner and (1, 1) for the lower right corner.
* See, for example, <a href="https://developer.tobiipro.com/commonconcepts/coordinatesystems.html">'Coordinate system' page in Tobii Pro SDK documentation</a>
*/
boolean isGazeNormalized = true;

/**
* This variable indicates whether the real-time data is transmitting.
Expand Down Expand Up @@ -157,6 +164,14 @@ public void startTracking(Project project) throws IOException {
setting.setAttribute("eye_tracker", "Mouse");
} else {
setting.setAttribute("eye_tracker", "Tobii Pro Fusion");
try {
String trackerName = AvailabilityChecker.getEyeTrackerName(pythonInterpreter);
if (trackerName != null && !trackerName.equals("Not Found")) {
setting.setAttribute("tracker_name", trackerName);
}
} catch (InterruptedException | IOException e) {
// just don't add the "tracker_name" attribute
}
}
setting.setAttribute("sample_frequency", String.valueOf(sampleFrequency));
track();
Expand Down Expand Up @@ -216,15 +231,21 @@ public void processRawData(String message) {
return;
}

int eyeX = (int) ((Double.parseDouble(leftGazePointX) + Double.parseDouble(rightGazePointX)) / 2 * screenWidth);
int eyeY = (int) ((Double.parseDouble(leftGazePointY) + Double.parseDouble(rightGazePointY)) / 2 * screenHeight);
int eyeX, eyeY;
if (isGazeNormalized) {
eyeX = (int) ((Double.parseDouble(leftGazePointX) + Double.parseDouble(rightGazePointX)) / 2 * screenWidth);
eyeY = (int) ((Double.parseDouble(leftGazePointY) + Double.parseDouble(rightGazePointY)) / 2 * screenHeight);
} else {
eyeX = (int) ((Double.parseDouble(leftGazePointX) + Double.parseDouble(rightGazePointX)) / 2);
eyeY = (int) ((Double.parseDouble(leftGazePointY) + Double.parseDouble(rightGazePointY)) / 2);
}

int editorX, editorY;
try {
editorX = editor.getContentComponent().getLocationOnScreen().x;
editorY = editor.getContentComponent().getLocationOnScreen().y;
} catch (IllegalComponentStateException e) {
gaze.setAttribute("remark", "Fail | No Editor");
gaze.setAttribute("remark", "Fail | IllegalComponentStateException in Editor");
return;
}
int relativeX = eyeX - editorX;
Expand Down
29 changes: 18 additions & 11 deletions src/main/java/utils/AvailabilityChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class AvailabilityChecker {
*/
public static boolean checkPythonEnvironment(String pythonInterpreter) throws IOException, InterruptedException {
String pythonScript = """
import tobii_research as tr
from screeninfo import get_monitors
import pyautogui
import time
Expand All @@ -41,13 +40,17 @@ public static boolean checkPythonEnvironment(String pythonInterpreter) throws IO
*/
public static boolean checkEyeTracker(String pythonInterpreter) throws IOException, InterruptedException {
String pythonScript = """
import tobii_research as tr
try:
import tobii_research as tr

found_eyetrackers = tr.find_all_eyetrackers()
if found_eyetrackers == ():
found_eyetrackers = tr.find_all_eyetrackers()
if found_eyetrackers == ():
print('Not Found')
else:
print('Found')

except ImportError:
print('Not Found')
else:
print('Found')
""";

String line = runPythonScript(pythonInterpreter, pythonScript);
Expand All @@ -62,13 +65,17 @@ public static boolean checkEyeTracker(String pythonInterpreter) throws IOExcepti
*/
public static String getEyeTrackerName(String pythonInterpreter) throws IOException, InterruptedException {
String pythonScript = """
import tobii_research as tr
try:
import tobii_research as tr

found_eyetrackers = tr.find_all_eyetrackers()
if found_eyetrackers == ():
found_eyetrackers = tr.find_all_eyetrackers()
if found_eyetrackers == ():
print('Not Found')
else:
print(found_eyetrackers[0].device_name)

except ImportError:
print('Not Found')
else:
print(found_eyetrackers[0].device_name)
""";

return runPythonScript(pythonInterpreter, pythonScript);
Expand Down