# dcnieho/glassesviewer architecture

> Architecture diagram of the GitHub repository dcnieho/glassesviewer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dcnieho/glassesviewer
- Repository: https://github.com/dcnieho/glassesviewer

## Overview

##### Main Components
- Main GUI & Entry Point: At the core is the “glassesViewer.m” script that launches the user interface. This component drives the overall workflow from file selection to displaying parsed data.
- Data Parsers: Under “function_library”, you have dedicated parser functions for the two types of recording data:
– TobiiG2DataReader (for Glasses 2 recordings)
– TobiiG3DataReader (for Glasses 3 recordings)
- Data Quality and Signal Processing: Multiple utility functions (e.g., in “function_library/DataQuality” and related functions like “computeDataQuality.m”, “computeRMSnoise.m”, etc.) help process and evaluate the data streams.
- User Functions & Classifiers: In “user_functions”, there are custom implementations and classifiers (like “HesselsEtAl2020” and “HoogeCamps2013”) which process specific aspects of the data (e.g., event detection like fixations, saccades).
- Configuration & Settings: The “defaults.json” file holds default settings that configure how data is read (channels, time windows, plot limits) and how the GUI behaves. This directly maps into the runtime settings structure.
- Demo / Sample Data: The “demo_data” folder holds example projects and recordings that can be loaded to test and demonstrate the application’s functionality.
- Miscellaneous Modules: Other files (e.g., “SDparser”, “extractAllAndGetDataQuality.m”, “user_functions/detPitchRoll”, etc.) contribute supporting functionality such as file parsing, indicator extraction, and video overlay processing for scene videos with gaze data.

##### Relationships and Interactions
- Initialization and Configuration: The main GUI file (“glassesViewer.m”) reads “defaults.json” and may adjust settings. It then uses the file picker to allow the user to select a particular recording (or project folder from the demo_data structure).
- Data Ingestion: Depending on whether a Glasses 2 or 3 recording is chosen, the viewer invokes either the “readG2DataFiles.m” or “readG3DataFiles.m” function from the function_library. These functions traverse the recording structure (as seen in “demo_data/projects/…”) to read various data files (like calibration, recording, segments, and participant files). Parsed data is then stored in MATLAB files (“livedata.mat” or “gazedata.mat”).
- Signal Processing & Quality Assessments: Once the data is loaded, additional processing happens via the DataQuality functions and various helper utilities (e.g., smoothing filters, timestamp alignment) to prepare a clean dataset for visualization.
- Annotation & Classification: The project supports multiple annotation streams (sync streams, hand-coded events, file-based events, APIevents, and classifier-based events). These are configured through settings (as described extensively in the README) and are implemented via a mix of built-in functions and user functions in “user_functions”. The relationships here include toggling between manual inputs and automated classifier outputs.
- And Export: The GUI displays the parsed data (with separate panels indicated by “settings.plot” for different streams such as azimuth, elevation, velocity, etc.). Export functions allow saving data streams, quality reports, and even scene videos with gaze overlays.

##### Architectural Patterns and Design Principles
- Modular Design: The project is structured in clear modules (parsers, utility functions, user extensions, GUI script) which follow a flat hierarchy – facilitating maintenance and ease of extension.
- Separation of Concerns: There is a distinct separation between data ingestion (parsing functions), data processing (filtering, quality computations, and user streams), and presentation (GUI functions in “glassesViewer.m” and associated annotation procedures).
- Configurability and Extensibility: The use of an external “defaults.json” and customizable “userStreams” (with both direct script references and classifier functions) ensures that the tool can be tailored to different experiments or analysis pipelines.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Configuration Management
    subgraph "Configuration Management"
        A["Configuration & Settings (defaults.json)"] 
    end

    %% GUI / Interface Layer
    subgraph "GUI / Interface Layer"
        B["Main GUI (glassesViewer.m)"]
    end

    %% Data Ingestion & Parsing
    subgraph "Data Ingestion & Parsing"
        C1["Glasses 2 Parser: TobiiG2DataReader"]
        C2["Glasses 3 Parser: TobiiG3DataReader"]
        C3["SD Card Parser: SDparser"]
    end

    %% Data Processing & Analysis
    subgraph "Data Processing & Analysis"
        D1["Data Quality & Signal Processing (function_library/DataQuality)"]
        subgraph "User Functions & Classifiers"
            D2a["HesselsEtAl2020"]
            D2b["HoogeCamps2013"]
            D2c["Pitch/Roll Detection"]
        end
    end

    %% Data Storage & Export
    subgraph "Data Storage & Export"
        E["Data Export Functions (function_library)"]
    end

    %% Demo & Sample Data
    subgraph "Demo & Sample Data"
        F["demo_data folder"]
    end

    %% Relationships
    A -->|"reads"| B
    B -->|"initiates"| C1
    B -->|"initiates"| C2
    B -->|"initiates"| C3
    F -->|"providesRawData"| C1
    F -->|"providesRawData"| C2
    F -->|"providesRawData"| C3
    C1 -->|"outputsParsedData"| D1
    C2 -->|"outputsParsedData"| D1
    C3 -->|"outputsParsedData"| D1
    D1 -->|"updatesGUI"| B
    D1 -->|"exportsData"| E
    D2a ---|"classifiesEvents"| D1
    D2b ---|"classifiesEvents"| D1
    D2c ---|"detectsOrientation"| D1

    %% Styles
    classDef config fill:#FFA500,stroke:#333,stroke-width:2px;
    classDef gui fill:#87CEEB,stroke:#333,stroke-width:2px;
    classDef parsing fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef analysis fill:#DDA0DD,stroke:#333,stroke-width:2px;
    classDef export fill:#FF6347,stroke:#333,stroke-width:2px;
    classDef demo fill:#C0C0C0,stroke:#333,stroke-width:2px;

    class A config;
    class B gui;
    class C1,C2,C3 parsing;
    class D1,D2a,D2b,D2c analysis;
    class E export;
    class F demo;

    %% Click Events
    click A "https://github.com/dcnieho/glassesviewer/blob/master/defaults.json"
    click B "https://github.com/dcnieho/glassesviewer/blob/master/glassesViewer.m"
    click C1 "https://github.com/dcnieho/glassesviewer/blob/master/function_library/TobiiG2DataReader/readG2DataFiles.m"
    click C2 "https://github.com/dcnieho/glassesviewer/blob/master/function_library/TobiiG3DataReader/readG3DataFiles.m"
    click C3 "https://github.com/dcnieho/glassesviewer/tree/master/SDparser"
    click D1 "https://github.com/dcnieho/glassesviewer/tree/master/function_library/DataQuality"
    click D2a "https://github.com/dcnieho/glassesviewer/tree/master/user_functions/HesselsEtAl2020"
    click D2b "https://github.com/dcnieho/glassesviewer/tree/master/user_functions/HoogeCamps2013"
    click D2c "https://github.com/dcnieho/glassesviewer/tree/master/user_functions/detPitchRoll"
    click E "https://github.com/dcnieho/glassesviewer/tree/master/function_library"
    click F "https://github.com/dcnieho/glassesviewer/tree/master/demo_data"
```
