refactoredCPPNeuronMesher
draw_utils.cpp File Reference

Implementation of OpenGL rendering utilities for neuron visualization. More...

#include <array>
#include "neurongraph.h"
#include "globals.h"
#include "draw_utils.h"
Include dependency graph for draw_utils.cpp:

Functions

void drawSimpleSphere (const SWCNode &node, double size)
 Renders a low-detail sphere at the specified node's position. More...
 
void drawSimpleLine (const SWCNode &a, const SWCNode &b)
 Draws a straight line between two nodes. More...
 
void drawSphere (const SWCNode &node, int slices, int stacks)
 Renders a detailed sphere at the specified node's position. More...
 
void drawCylinder (const SWCNode &a, const SWCNode &b, int segments)
 Renders a tapered cylinder between two nodes. More...
 
void drawBoundingBox (double minX, double maxX, double minY, double maxY, double minZ, double maxZ)
 Renders a wireframe bounding box in 3D space. More...
 
void setColorByType (int type)
 Sets the OpenGL color based on SWC node type. More...
 
void renderSWC (const std::vector< SWCNode > &nodes)
 Renders a collection of SWC nodes as a 3D neuron morphology. More...
 

Detailed Description

Implementation of OpenGL rendering utilities for neuron visualization.

This file contains utility functions for rendering 3D neuron structures using OpenGL. It provides various primitives for drawing spheres, cylinders, and other geometric shapes used to represent neuron morphologies in 3D space.

Key features:

  • Sphere and cylinder rendering for soma and neurites
  • Bounding box visualization
  • Color mapping for different neuron components
  • Multiple rendering modes (wireframe, solid, etc.)
  • Support for different levels of detail

The implementation uses legacy OpenGL immediate mode (glBegin/glEnd) for simplicity and compatibility with the existing visualization pipeline.

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

Function Documentation

◆ drawBoundingBox()

void drawBoundingBox ( double  minX,
double  maxX,
double  minY,
double  maxY,
double  minZ,
double  maxZ 
)

Renders a wireframe bounding box in 3D space.

Draws an axis-aligned bounding box.

Parameters
[in]minXThe minimum X coordinate of the bounding box
[in]maxXThe maximum X coordinate of the bounding box
[in]minYThe minimum Y coordinate of the bounding box
[in]maxYThe maximum Y coordinate of the bounding box
[in]minZThe minimum Z coordinate of the bounding box
[in]maxZThe maximum Z coordinate of the bounding box

This function draws a white wireframe box representing the spatial bounds of the neuron morphology. The box is drawn using OpenGL line primitives, with each edge of the box represented by a single line segment.

The function sets the current OpenGL color to white before rendering and uses immediate mode rendering (glBegin/glEnd). The box is axis-aligned and defined by the provided min/max coordinates in each dimension.

Note
The function sets the color to white (1.0, 1.0, 1.0)
Uses legacy OpenGL immediate mode rendering
The box is drawn with GL_LINES primitive type
See also
glBegin() for details on immediate mode rendering
glVertex3f() for vertex specification
Here is the caller graph for this function:

◆ drawCylinder()

void drawCylinder ( const SWCNode a,
const SWCNode b,
int  segments 
)

Renders a tapered cylinder between two nodes.

Draws a cylinder connecting two nodes.

Parameters
[in]aThe starting node of the cylinder
[in]bThe ending node of the cylinder
[in]segmentsThe number of sides around the cylinder

This function draws a tapered cylinder connecting two nodes in 3D space. The cylinder's radius at each end is determined by the radius property of the corresponding node, allowing for smooth tapering of neurites.

The function handles the necessary coordinate system transformations to orient the cylinder correctly between the two points in 3D space. It uses OpenGL's matrix stack to ensure the transformations don't affect subsequent rendering operations.

Note
The cylinder is drawn with smooth normals for proper lighting
If the nodes are coincident (distance = 0), the function returns early
The 57.2957795f constant converts radians to degrees (180/π)
Uses legacy OpenGL immediate mode rendering
See also
gluCylinder() for details on the underlying GLU primitive
Here is the caller graph for this function:

◆ drawSimpleLine()

void drawSimpleLine ( const SWCNode a,
const SWCNode b 
)

Draws a straight line between two nodes.

Draws a simple line between two nodes.

Parameters
[in]aThe starting node of the line
[in]bThe ending node of the line

This function renders a simple line segment between two nodes in 3D space using OpenGL's immediate mode line rendering. The line is drawn with the current OpenGL color and line width settings.

The function is typically used for wireframe representations of neuron morphologies or for debug visualization.

Note
The line is drawn with the current OpenGL color
Uses legacy OpenGL immediate mode rendering (glBegin/glEnd)
For more complex line rendering (e.g., with thickness), consider using geometry shaders or other modern OpenGL techniques
Here is the caller graph for this function:

◆ drawSimpleSphere()

void drawSimpleSphere ( const SWCNode node,
double  size 
)

Renders a low-detail sphere at the specified node's position.

Draws a simple low-polygon sphere at a node's position.

Parameters
[in]nodeThe SWCNode containing the position for the sphere
[in]sizeThe radius of the sphere

This function draws a simple sphere using OpenGL's GLU quadric primitives. It's optimized for speed rather than visual quality, using a low number of slices and stacks (8x8) for the sphere approximation.

The function handles the OpenGL matrix stack appropriately, pushing the current matrix before translation and popping it afterward to avoid affecting subsequent rendering operations.

Note
The sphere is drawn with the current OpenGL color
Uses legacy OpenGL immediate mode rendering
See also
drawSphere() for a higher-quality sphere rendering alternative
gluSphere() for details on the underlying GLU primitive
Here is the caller graph for this function:

◆ drawSphere()

void drawSphere ( const SWCNode node,
int  slices,
int  stacks 
)

Renders a detailed sphere at the specified node's position.

Draws a sphere with specified geometric detail.

Parameters
[in]nodeThe SWCNode containing the position and radius for the sphere
[in]slicesThe number of subdivisions around the Z axis (longitude)
[in]stacksThe number of subdivisions along the Z axis (latitude)

This function draws a sphere using OpenGL's GLU quadric primitives with smooth normal vectors for proper lighting calculations. The sphere's radius is taken from the node's radius property, and its position is set to the node's coordinates.

The function handles the OpenGL matrix stack appropriately and uses the current OpenGL color for rendering. The resolution of the sphere can be controlled through the slices and stacks parameters.

Note
The sphere is drawn with smooth shading (GLU_SMOOTH)
Uses legacy OpenGL immediate mode rendering
For high-quality rendering, use at least 16 slices and stacks
See also
drawSimpleSphere() for a faster, lower-quality alternative
gluQuadricNormals() for details on normal generation
Here is the caller graph for this function:

◆ renderSWC()

void renderSWC ( const std::vector< SWCNode > &  nodes)

Renders a collection of SWC nodes as a 3D neuron morphology.

Renders a complete SWC neuron morphology.

Parameters
[in]nodesA vector of SWCNode objects representing the neuron morphology

This function renders a complete neuron morphology from SWC node data using different rendering modes controlled by the global renderMode variable. The function handles both the rendering of nodes (soma, branch points, etc.) and the connections between them (dendrites, axons).

Supported render modes:

  • Mode 1: White wireframe lines between nodes
  • Mode 2: Colored spheres at nodes with white wireframe connections
  • Mode 3: Yellow simple spheres at node positions
  • Mode 4: Purple detailed spheres at node positions
  • Mode 5: Colored tapered cylinders between nodes (no spheres)
  • Mode 6: Colored detailed spheres with colored tapered cylinders

The function first renders all nodes according to the current render mode, then renders the connections between nodes. Node colors are determined by their SWC type using the setColorByType() function.

Note
The function uses the global renderMode variable to determine rendering style
Parent-child relationships are determined by the node.pid field
The function skips rendering of invalid parent references (pid = -1)
See also
setColorByType() for information about color mapping
drawSphere(), drawCylinder() for the actual rendering primitives
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setColorByType()

void setColorByType ( int  type)

Sets the OpenGL color based on SWC node type.

Parameters
[in]typeThe SWC node type identifier

This function maps standard SWC node types to specific colors for visualization. The color mapping is as follows:

  • Type 1: Red (soma)
  • Type 2: Green (axon)
  • Type 3: Blue (basal dendrite)
  • Type 4: Yellow (apical dendrite)
  • Type 5: Magenta
  • Type 6: Cyan
  • Type 7: Orange
  • Default: White (for any other type)

The function uses a static map for efficient type-to-color lookup and modifies the current OpenGL color state.

Note
The function modifies the OpenGL current color state
The color map is static and shared across all instances
For custom color schemes, modify the colorMap variable
See also
http://www.neuronland.org/NLMorphologyConverter/MorphologyFormats/SWC/Spec.html for SWC format specification
Here is the caller graph for this function: