refactoredCPPNeuronMesher
python_package.scripts.neuronviewer Namespace Reference

Functions

def init_window (width=800, height=600)
 
def open_file_dialog ()
 
def load_neuron (path)
 
def draw_graph (graph)
 
def mouse_button_callback (window, button, action, mods)
 
def cursor_position_callback (window, xpos, ypos)
 
def scroll_callback (window, xoffset, yoffset)
 
def main ()
 

Variables

float angle_x = 0.0
 
float angle_y = 0.0
 
float distance = 300.0
 
 last_x
 
 last_y
 
bool mouse_pressed = False
 

Detailed Description

Neuron Viewer - A 3D visualization tool for neuron morphologies.

This module provides a simple OpenGL-based viewer for visualizing neuron structures
loaded from SWC or UGX files. It supports interactive 3D navigation and multiple
rendering modes for examining neuron morphologies.

Key Features:
- Supports SWC and UGX file formats
- Interactive 3D camera controls
- Multiple rendering modes (wireframe, solid, etc.)
- Cross-platform compatibility

Dependencies:
- PyOpenGL
- GLFW
- NumPy
- Tkinter (for file dialogs)

Example:
    viewer = NeuronViewer()
    viewer.run()

Function Documentation

◆ cursor_position_callback()

def python_package.scripts.neuronviewer.cursor_position_callback (   window,
  xpos,
  ypos 
)
Handles mouse cursor movement events for view rotation.
Tracks the last known position of the mouse cursor and updates the angle_x and angle_y variables
when the left mouse button is pressed.
Rotation speed is scaled by a constant factor (0.5) to provide a good balance between precision and responsiveness.
The actual view transformation is applied in the main rendering loop using the global state variables modified by this function.

See also
--------
GLFW cursor position documentation: https://www.glfw.org/docs/latest/input_guide.html#cursor_pos

◆ draw_graph()

def python_package.scripts.neuronviewer.draw_graph (   graph)
Draw a neuron as a set of lines connecting the nodes in the graph.

This function takes a NeuronGraph object as input and draws it as a set of
lines connecting the nodes in the graph. The lines are drawn by iterating
over the nodes and connecting each node to its parent node (if it exists).

Args:
    graph (NeuronGraph): The neuron graph to draw.
Here is the caller graph for this function:

◆ init_window()

def python_package.scripts.neuronviewer.init_window (   width = 800,
  height = 600 
)
Initialize a GLFW window with the given width and height.

This function initializes the GLFW library and creates a window
with the given size. The window is set as the current OpenGL context
and depth testing is enabled.

Args:
    width (int): The width of the window in pixels.
    height (int): The height of the window in pixels.

Returns:
    GLFWwindow: The initialized GLFW window.
Here is the caller graph for this function:

◆ load_neuron()

def python_package.scripts.neuronviewer.load_neuron (   path)
Load a neuron from a file.

This function takes a file path as input and loads a neuron from the file.
The neuron is loaded into a NeuronGraph object and returned.

The supported file formats are SWC and UGX. If the file format is not
recognized, a ValueError is raised.

Parameters
----------
path : str
    The path to the file containing the neuron data.

Returns
-------
NeuronGraph
    The loaded neuron graph.

Raises
------
ValueError
    If the file format is not recognized.
Here is the caller graph for this function:

◆ main()

def python_package.scripts.neuronviewer.main ( )
Main function to initialize the GLFW window and handle rendering loop.

This function sets up the GLFW window, assigns necessary callbacks for mouse
and keyboard interaction, and enters the main rendering loop. In each loop 
iteration, it processes events, clears the screen, sets up the camera 
perspective, and draws the neuron graph if loaded. It also handles the 
keyboard shortcut for opening a file dialog to load neuron data from a file.
Here is the call graph for this function:

◆ mouse_button_callback()

def python_package.scripts.neuronviewer.mouse_button_callback (   window,
  button,
  action,
  mods 
)
Handles mouse button events for view manipulation.
Tracks when the left mouse button is pressed or released to toggle the
mouse_pressed state, which is used for initiating and controlling 3D view
rotation in the neuron viewer.

Args:
    window: The GLFW window that received the event.
    button: The mouse button that was pressed or released.
    action: The mouse button action (GLFW_PRESS or GLFW_RELEASE).
    mods: Bit field describing which modifier keys were held down.

◆ open_file_dialog()

def python_package.scripts.neuronviewer.open_file_dialog ( )
Open a file dialog to select a neuron file.

This function uses a Tkinter file dialog to open a file selection window
for choosing neuron morphology files. The supported file types are SWC 
and UGX, but all file types can be selected.

Returns
-------
str
    The path to the selected file or an empty string if no file was selected.
Here is the caller graph for this function:

◆ scroll_callback()

def python_package.scripts.neuronviewer.scroll_callback (   window,
  xoffset,
  yoffset 
)
Handles mouse scroll events for zooming the view.
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

Variable Documentation

◆ angle_x

float python_package.scripts.neuronviewer.angle_x = 0.0

◆ angle_y

float python_package.scripts.neuronviewer.angle_y = 0.0

◆ distance

float python_package.scripts.neuronviewer.distance = 300.0

◆ last_x

python_package.scripts.neuronviewer.last_x

◆ last_y

python_package.scripts.neuronviewer.last_y

◆ mouse_pressed

bool python_package.scripts.neuronviewer.mouse_pressed = False