refactoredCPPNeuronMesher
opgl_utils.h File Reference

OpenGL utility functions for neuron visualization. More...

#include <vector>
#include <string>
#include "neurongraph.h"
#include "tinyfiledialogs.h"
Include dependency graph for opgl_utils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

std::vector< SWCNodeloadSWC (const std::string &filename)
 Loads neuron data from an SWC file. More...
 
void computeBounds (const std::vector< SWCNode > &nodes, double &minX, double &maxX, double &minY, double &maxY, double &minZ, double &maxZ, double &centerX, double &centerY, double &centerZ, double &radius)
 Computes the spatial bounds and center of a set of nodes. More...
 
void openNeuronFile (std::vector< SWCNode > &nodes, double &minX, double &maxX, double &minY, double &maxY, double &minZ, double &maxZ, double &centerX, double &centerY, double &centerZ, double &radius)
 Opens a file dialog to load a neuron file and updates the view. More...
 
void printHelpText ()
 Prints keyboard and mouse controls to the console. More...
 

Variables

std::string currentLoadedFile
 Path to the currently loaded SWC file. More...
 

Detailed Description

OpenGL utility functions for neuron visualization.

This header provides utility functions for OpenGL-based visualization of neuron morphologies, including file I/O, bounds computation, and help text display. These utilities handle the core functionality for loading and preparing neuron data for rendering.

Author
CPPNeuronMesher Team
Date
2025-07-27
Version
1.0

Function Documentation

◆ computeBounds()

void computeBounds ( const std::vector< SWCNode > &  nodes,
double &  minX,
double &  maxX,
double &  minY,
double &  maxY,
double &  minZ,
double &  maxZ,
double &  centerX,
double &  centerY,
double &  centerZ,
double &  radius 
)

Computes the spatial bounds and center of a set of nodes.

Calculates the axis-aligned bounding box, center point, and maximum radius of a collection of SWC nodes. This is used for camera positioning and scaling.

Parameters
[in]nodesVector of SWC nodes to analyze
[out]minXMinimum X coordinate of all nodes
[out]maxXMaximum X coordinate of all nodes
[out]minYMinimum Y coordinate of all nodes
[out]maxYMaximum Y coordinate of all nodes
[out]minZMinimum Z coordinate of all nodes
[out]maxZMaximum Z coordinate of all nodes
[out]centerXX coordinate of the center point
[out]centerYY coordinate of the center point
[out]centerZZ coordinate of the center point
[out]radiusMaximum distance from center to any node
Note
All output parameters are set to 0 if the input vector is empty

Computes the spatial bounds and center of a set of nodes.

Parameters
[in]nodesVector of SWC nodes to compute bounds for
[out]minXMinimum X coordinate of the bounding box
[out]maxXMaximum X coordinate of the bounding box
[out]minYMinimum Y coordinate of the bounding box
[out]maxYMaximum Y coordinate of the bounding box
[out]minZMinimum Z coordinate of the bounding box
[out]maxZMaximum Z coordinate of the bounding box
[out]centerXX coordinate of the bounding box center
[out]centerYY coordinate of the bounding box center
[out]centerZZ coordinate of the bounding box center
[out]radiusRadius of the bounding sphere (half the maximum dimension)

This function calculates the axis-aligned bounding box, center point, and bounding sphere radius for a set of 3D points represented by SWC nodes. The results are returned through reference parameters.

The function also prints the computed bounds and center to the console for debugging purposes.

Note
If the input vector is empty, the function returns immediately
The radius is defined as half the maximum dimension of the bounding box
See also
openNeuronFile() for a typical usage example
Here is the caller graph for this function:

◆ loadSWC()

std::vector<SWCNode> loadSWC ( const std::string &  filename)

Loads neuron data from an SWC file.

Parses an SWC (Standardized Waveform Container) file containing neuron morphology data and returns a vector of SWCNode objects.

Parameters
filenamePath to the SWC file to load
Returns
std::vector<SWCNode> Vector of nodes representing the neuron morphology
Exceptions
std::runtime_errorIf the file cannot be opened or is malformed
Note
The SWC format is a standard format for representing neuron morphologies. Each line in the file represents a point in the neuron structure.
See also
http://www.neuronland.org/NLMorphologyConverter/MorphologyFormats/SWC/Spec.html

Loads neuron data from an SWC file.

Parameters
[in]filenamePath to the SWC or UGX file to load
Returns
std::vector<SWCNode> Vector of SWC nodes representing the neuron

This function loads a neuron morphology from the specified file and returns its nodes as a vector of SWCNode objects. It supports both SWC and UGX file formats and performs preprocessing on the loaded data.

The function:

  1. Reads the neuron data using NeuronGraph's readFromFileUGXorSWC()
  2. Applies preprocessing to the loaded nodes
  3. Converts the node map to a vector for rendering
Note
The function modifies the global graph object
Preprocessing includes validation and cleanup of the neuron structure
Exceptions
std::runtime_errorif the file cannot be read or parsed
See also
NeuronGraph::readFromFileUGXorSWC()
NeuronGraph::preprocess()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ openNeuronFile()

void openNeuronFile ( std::vector< SWCNode > &  nodes,
double &  minX,
double &  maxX,
double &  minY,
double &  maxY,
double &  minZ,
double &  maxZ,
double &  centerX,
double &  centerY,
double &  centerZ,
double &  radius 
)

Opens a file dialog to load a neuron file and updates the view.

Displays a file open dialog to the user and loads the selected SWC file. Updates the provided node container and computes the new spatial bounds.

Parameters
[out]nodesVector to store the loaded nodes
[out]minXMinimum X coordinate (updated after loading)
[out]maxXMaximum X coordinate (updated after loading)
[out]minYMinimum Y coordinate (updated after loading)
[out]maxYMaximum Y coordinate (updated after loading)
[out]minZMinimum Z coordinate (updated after loading)
[out]maxZMaximum Z coordinate (updated after loading)
[out]centerXX coordinate of the center (updated after loading)
[out]centerYY coordinate of the center (updated after loading)
[out]centerZZ coordinate of the center (updated after loading)
[out]radiusMaximum radius from center (updated after loading)
Returns
True if a file was successfully loaded, false otherwise
Note
Uses tinyfiledialogs for cross-platform file dialog support
Updates currentLoadedFile on successful load

Opens a file dialog to load a neuron file and updates the view.

Parameters
[out]nodesVector to store the loaded SWC nodes
[out]minXMinimum X coordinate of the bounding box
[out]maxXMaximum X coordinate of the bounding box
[out]minYMinimum Y coordinate of the bounding box
[out]maxYMaximum Y coordinate of the bounding box
[out]minZMinimum Z coordinate of the bounding box
[out]maxZMaximum Z coordinate of the bounding box
[out]centerXX coordinate of the bounding box center
[out]centerYY coordinate of the bounding box center
[out]centerZZ coordinate of the bounding box center
[out]radiusRadius of the bounding sphere

This function opens a file dialog for the user to select an SWC or UGX file, loads the selected file, and computes the spatial bounds of the neuron. The function updates both the provided output parameters and the global state.

The function performs the following steps:

  1. Shows a file dialog for selecting SWC or UGX files
  2. Loads the selected file using loadSWC()
  3. Updates the global currentNodes and currentLoadedFile variables
  4. Computes the spatial bounds and center of the loaded neuron
  5. Resets the refinement delta to its default value
Note
Uses tinyfiledialogs for the file dialog
Prints diagnostic information to the console
See also
loadSWC() for the actual file loading implementation
computeBounds() for the bounds calculation
Here is the call graph for this function:
Here is the caller graph for this function:

◆ printHelpText()

void printHelpText ( )

Prints keyboard and mouse controls to the console.

Displays a help message listing all available keyboard shortcuts and mouse controls for the neuron viewer application.

Note
This function is typically called when the application starts or when the user presses the 'H' key.

Prints keyboard and mouse controls to the console.

Displays the application's keyboard and mouse controls to the console. The help text is defined as a global string constant in globals.h.

Note
The help text includes controls for view manipulation, file operations, and rendering modes.
See also
globals.h for the help text definition
Here is the caller graph for this function:

Variable Documentation

◆ currentLoadedFile

std::string currentLoadedFile
extern

Path to the currently loaded SWC file.

Stores the full path to the most recently loaded SWC file. Empty string if no file has been loaded yet.

Path to the currently loaded SWC file.