refactoredCPPNeuronMesher
callbacks.cpp File Reference

Implementation of GLFW callback functions for the neuron viewer. More...

#include "globals.h"
#include "callbacks.h"
Include dependency graph for callbacks.cpp:

Functions

void keyCallback (GLFWwindow *window, int key, int scancode, int action, int mods)
 Handles keyboard input events for the neuron viewer. More...
 
void mouseButtonCallback (GLFWwindow *window, int button, int action, int mods)
 Handles mouse button events for 3D view manipulation. More...
 
void cursorPosCallback (GLFWwindow *window, double xpos, double ypos)
 Handles mouse cursor movement for view manipulation. More...
 
void scrollCallback (GLFWwindow *window, double xoffset, double yoffset)
 Handles mouse scroll wheel events for zooming the view. More...
 

Detailed Description

Implementation of GLFW callback functions for the neuron viewer.

This file contains the implementation of various GLFW callback functions that handle user input and interaction with the neuron visualization window. It includes keyboard, mouse, and scroll wheel event handling for controlling the 3D view and interacting with neuron data.

Key features:

  • Keyboard shortcuts for view manipulation (rotation, zoom, pan)
  • Mouse interaction for 3D view control
  • File I/O operations (open/save)
  • Interactive refinement of neuron geometry
  • Help system display

The implementation uses GLFW for window management and input handling, and integrates with the NeuronGraph class for neuron data manipulation.

Author
CPPNeuronMesher Team
Date
2025-07-27
Version
1.0
See also
https://github.com/yourusername/refactoredCPPNeuronMesher

Function Documentation

◆ cursorPosCallback()

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

Handles mouse cursor movement for view manipulation.

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 for the neuron viewer.

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 events for 3D view manipulation.

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 wheel events for zooming the view.

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: