refactoredCPPNeuronMesher
callbacks.h File Reference

GLFW input handling callbacks for neuron visualization. More...

#include <GLFW/glfw3.h>
#include <iostream>
#include <vector>
#include "neurongraph.h"
#include "globals.h"
#include "opgl_utils.h"
Include dependency graph for callbacks.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void keyCallback (GLFWwindow *window, int key, int scancode, int action, int mods)
 Handles keyboard input events. More...
 
void mouseButtonCallback (GLFWwindow *window, int button, int action, int mods)
 Handles mouse button input events. More...
 
void cursorPosCallback (GLFWwindow *window, double xpos, double ypos)
 Handles mouse cursor movement. More...
 
void scrollCallback (GLFWwindow *window, double xoffset, double yoffset)
 Handles mouse scroll events. More...
 

Detailed Description

GLFW input handling callbacks for neuron visualization.

This header defines the callback functions that handle user input through GLFW, including keyboard, mouse, and scroll wheel interactions for the neuron viewer. These callbacks modify the global state in globals.h to control the visualization.

Author
CPPNeuronMesher Team
Date
2025-07-27
Version
1.0

Function Documentation

◆ cursorPosCallback()

void cursorPosCallback ( GLFWwindow *  window,
double  xpos,
double  ypos 
)

Handles mouse cursor movement.

Updates camera orientation or position based on mouse movement when:

  • Left button is held: Rotate view
  • Right button is held: Pan view
  • Middle button is held: Zoom view
Parameters
windowThe GLFW window that received the event
xposThe new cursor x-coordinate, relative to the left edge of the content area
yposThe new cursor y-coordinate, relative to the top edge of the content area

Handles mouse cursor movement.

Parameters
[in]windowThe GLFW window that received the event
[in]xposThe new x-coordinate of the cursor, in screen coordinates
[in]yposThe new y-coordinate of the cursor, in screen coordinates

This callback function processes mouse movement to implement interactive 3D view manipulation. It provides the following functionality:

  • Left-drag: Rotates the view around the X and Y axes
  • Right-drag: Pans the view in the X and Y directions

The function uses the difference between the current and last cursor positions to calculate the amount of rotation or panning to apply. The actual view transformation is applied in the main rendering loop using the global state variables modified by this function.

Note
The function updates the lastX and lastY variables to track cursor movement between frames
Rotation and panning speeds are scaled by constant factors (0.3f and 1.5f)
See also
mouseButtonCallback() for enabling/disabling rotation and panning
GLFW cursor position documentation: https://www.glfw.org/docs/latest/input_guide.html#cursor_pos
Here is the caller graph for this function:

◆ keyCallback()

void keyCallback ( GLFWwindow *  window,
int  key,
int  scancode,
int  action,
int  mods 
)

Handles keyboard input events.

Processes key presses and releases to control the visualization:

  • WASD: Move camera left/right/forward/backward
  • QE: Move camera up/down
  • Arrow keys: Rotate view
  • R: Reset view
  • Space: Toggle auto-rotation
  • 1-5: Switch between rendering modes
  • +/-: Adjust rendering parameters
  • ESC: Close window
  • H: Toggle help text
Parameters
windowThe GLFW window that received the event
keyThe keyboard key that was pressed or released
scancodeThe system-specific scancode of the key
actionGLFW_PRESS, GLFW_RELEASE or GLFW_REPEAT
modsBit field describing which modifier keys were held down

Handles keyboard input events.

Parameters
[in]windowThe GLFW window that received the event
[in]keyThe keyboard key that was pressed or released
[in]scancodeThe system-specific scancode of the key
[in]actionThe key action (GLFW_PRESS, GLFW_RELEASE, or GLFW_REPEAT)
[in]modsBit field describing which modifier keys were held down

This callback function processes keyboard input for controlling the neuron viewer. It implements the following keyboard shortcuts:

  • F: Refine neuron geometry (halve delta)
  • Ctrl+F: Coarsen neuron geometry (double delta)
  • 1-6: Switch between different render modes
  • O: Open a neuron file dialog
  • R: Reset camera view
  • H: Show/hide help window
  • S: Save the current neuron data to file

The function modifies global state for view parameters and triggers updates to the neuron visualization when geometry is refined or coarsened.

Note
The function only processes key press events (GLFW_PRESS)
Modifier keys (Ctrl, Shift, Alt) are checked using the mods parameter
See also
GLFW key documentation: https://www.glfw.org/docs/latest/input_guide.html#input_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mouseButtonCallback()

void mouseButtonCallback ( GLFWwindow *  window,
int  button,
int  action,
int  mods 
)

Handles mouse button input events.

Processes mouse button presses and releases for:

  • Left button: Start/end rotation
  • Right button: Start/end panning
  • Middle button: Start/end zooming
Parameters
windowThe GLFW window that received the event
buttonThe mouse button that was pressed or released
actionGLFW_PRESS or GLFW_RELEASE
modsBit field describing which modifier keys were held down

Handles mouse button input events.

Parameters
[in]windowThe GLFW window that received the event
[in]buttonThe mouse button that was pressed or released
[in]actionThe button action (GLFW_PRESS or GLFW_RELEASE)
[in]modsBit field describing which modifier keys were held down

This callback function processes mouse button events to enable interactive 3D view manipulation. It tracks the following interactions:

  • Left mouse button: Enables view rotation when dragged
  • Right mouse button: Enables view panning when dragged

The function updates global state variables (dragging, rightDragging) that are used by cursorPosCallback to implement the actual view transformations.

Note
The function tracks both press and release events for smooth interaction
The cursor position is captured on button press for relative movement
See also
cursorPosCallback() for the implementation of the actual view transformations
GLFW mouse button documentation: https://www.glfw.org/docs/latest/input_guide.html#input_mouse_button
Here is the caller graph for this function:

◆ scrollCallback()

void scrollCallback ( GLFWwindow *  window,
double  xoffset,
double  yoffset 
)

Handles mouse scroll events.

Zooms the view in/out based on vertical scroll input.

Parameters
windowThe GLFW window that received the event
xoffsetThe scroll offset along the x-axis (unused)
yoffsetThe scroll offset along the y-axis (positive = scroll up, negative = scroll down)

Handles mouse scroll events.

Parameters
[in]windowThe GLFW window that received the event
[in]xoffsetThe scroll offset along the x-axis (unused in this implementation)
[in]yoffsetThe scroll offset along the y-axis (positive for scroll up, negative for scroll down)

This callback function processes mouse scroll wheel input to implement smooth zooming of the 3D view. It modifies the global zoom factor based on the vertical scroll amount.

The zoom factor is adjusted using an exponential scale (1.1^yoffset) to provide natural-feeling zoom behavior. The zoom level is clamped between 0.05 and 10.0 to prevent extreme zoom levels that might cause rendering issues or numerical instability.

Note
The xoffset parameter is currently unused but included for future compatibility
Zooming is centered on the current view (no focal point adjustment)
The 1.1 base value provides a good balance between precision and responsiveness
See also
GLFW scroll documentation: https://www.glfw.org/docs/latest/input_guide.html#scrolling
Here is the caller graph for this function: