Brainsimulation
Simulation of the human brain.
Macros | Functions
brainsetup.h File Reference

Setup all node arrays to be passed to the brainsimulation. More...

#include "definitions.h"
Include dependency graph for brainsetup.h:

Go to the source code of this file.

Macros

#define FLAG_TICKS   "--ticks"
 Command line flag for number of ticks (single integer paramter). More...
 
#define FLAG_X_OBSERVATIONNODES   "--xobs"
 Command line flag for x indices of observation nodes (multiple integer paramters). More...
 
#define FLAG_Y_OBSERVATIONNODES   "--yobs"
 Command line flag for y indices of observation nodes (multiple integer paramters). More...
 
#define FLAG_X_NODES   "-x"
 Command line flag for node grid size on the x axis (single integer paramter). More...
 
#define FLAG_Y_NODES   "-y"
 Command line flag for node grid size on the y axis (single integer paramter). More...
 
#define FLAG_START_LEVELS   "--startlevels"
 Command line flag for starting energy levels of start nodes (multiple double paramters). More...
 
#define FLAG_START_NODES_X   "--startx"
 Command line flag for x indices of start nodes (multiple integer paramters). More...
 
#define FLAG_START_NODES_Y   "--starty"
 Command line flag for y indices of start nodes (multiple integer paramters). More...
 
#define FLAG_FREQUENCIES   "--freqs"
 Command line flag for frequencies of frequency generating nodes (multiple intger paramters). More...
 
#define FLAG_FREQ_NODES_X   "--freqx"
 Command line flag for x indices of frequency generating nodes (multiple integer paramters). More...
 
#define FLAG_FREQ_NODES_Y   "--freqy"
 Command line flag for y indices of frequency generating nodes (multiple integer paramters). More...
 
#define FLAG_FREQ_BITMAPS   "--freqbitmaps"
 Command line flag for bitmap image paths, interpreted as frequencies (multiple string paramters). More...
 
#define FLAG_MIN_BITMAP_FREQ   "--minbitmapfreq"
 Command line flag for the frequency to be used for the min non-0 bitmap value (1) (single integer paramter). More...
 
#define FLAG_MAX_BITMAP_FREQ   "--maxbitmapfreq"
 Command line flag for the frequency to be used for the max bitmap value (assumes 24-bit: 765) (single integer paramter). More...
 
#define FLAG_BITMAP_DURATION   "--bitmapduration"
 Command line flag for the duration (in ticks) a bitmap is to be used for input before it is followed by the next bitmap (single integer paramter).
 

Functions

unsigned int contains_flag (const int argc, const char *argv[], const char *flag)
 Checks if the command line contains a flag. More...
 
int parse_int_arg (const int argc, const char *argv[], const char *flag)
 Parses an integer argument from the command line for a specified flag. More...
 
nodetimeseries_tinit_observation_timeseries_from_sh (const int argc, const char *argv[], int *num_observationnodes)
 Initializes num_oberservationnodes timeseries structs and returns them in an array using settings from the command line. More...
 
nodetimeseries_tinit_observation_timeseries_default (int *num_observationnodes, int num_ticks)
 Initializes num_oberservationnodes timeseries structs with default values and returns them in an array. More...
 
nodetimeseries_tinit_observation_timeseries (const int num_oberservationnodes, const int *x_indices, const int *y_indices, const int num_timeseries_elements)
 Initializes num_oberservationnodes timeseries structs and returns them in an array. More...
 
void init_start_time_state_from_sh (const int argc, const char *argv[], const int number_nodes_x, const int number_nodes_y, nodeval_t **nodes)
 Sets a start time energy state for the node field. More...
 
nodeval_t ** init_nodegrid_default (int *number_nodes_x, int *number_nodes_y)
 Initializes a nodegrid with a default size and initializes it with zero. More...
 
void init_start_time_state (const int number_nodes_x, const int number_nodes_y, nodeval_t **nodes, const int num_start_levels, const nodeval_t *start_levels, const int *start_nodes_x, const int *start_nodes_y)
 Sets a start time energy state for the node field. More...
 
nodeinputseries_tread_input_behavior (const int number_of_inputnodes, const int *x_indices, const int *y_indices, const char **inputnodefilenames, const int *number_of_elements)
 Reads and parses the inputs defined as csv files to be added to the given nodes during the simulation. More...
 
double * generate_sin_time_series (int hz, const double tick_ms, int number_of_samples)
 Generates a specified number of samples of a discretized sinoidal timeseries with the specified frequency and returns it. More...
 
double * generate_sin_frequency (int hz, const double tick_ms)
 Generates a discretized sinoidal timeseries with the specified frequency and returns it. More...
 
int calculate_period_length (int hz, const double tick_ms)
 Calcuated the period length of the given frequency at the specified resolution, i.e., the number of samples to generate, until the period is reached. More...
 
nodeinputseries_tgenerate_input_frequencies_from_sh (const int argc, const char *argv[], int *num_inputnodes, const double tick_ms)
 Generates input timeseries for the given nodes with the specified frequency. More...
 
nodeinputseries_tgenerate_input_frequencies_default (int *num_inputnodes, const double tick_ms)
 Generates input timeseries for a set of default given nodes with default frequencies. More...
 
nodeinputseries_tgenerate_input_frequencies (const int number_of_inputnodes, const int *x_indices, const int *y_indices, const int *frequencies, const double tick_ms)
 Generates input timeseries for the given nodes with the specified frequency. More...
 
unsigned int * read_bitmap_contents (const char *bitmap_path, unsigned int *bitmap_size_x, unsigned int *bitmap_size_y)
 Reads a bitmap image file and returns the sum color values for each pixel in a array. More...
 
nodeinputseries_tgenerate_input_frequencies_from_bitmap (const char *filenames[], const unsigned int num_filenames, const int min_freq, const int max_freq, const int bitmap_duration_ticks, int *num_inputnodes, const double tick_ms)
 Generates input timeseries for all non-zero (non-black) nodes from the specified 24-bit bitmap images. More...
 
nodeinputseries_tgenerate_input_frequencies_from_sh_bitmap (const int argc, const char *argv[], int *num_inputnodes, const double tick_ms)
 Generates input timeseries for all non-zero (non-black) nodes from the specified 24-bit bitmap images. More...
 

Detailed Description

Setup all node arrays to be passed to the brainsimulation.

Macro Definition Documentation

#define FLAG_FREQ_BITMAPS   "--freqbitmaps"

Command line flag for bitmap image paths, interpreted as frequencies (multiple string paramters).

#define FLAG_FREQ_NODES_X   "--freqx"

Command line flag for x indices of frequency generating nodes (multiple integer paramters).

#define FLAG_FREQ_NODES_Y   "--freqy"

Command line flag for y indices of frequency generating nodes (multiple integer paramters).

#define FLAG_FREQUENCIES   "--freqs"

Command line flag for frequencies of frequency generating nodes (multiple intger paramters).

#define FLAG_MAX_BITMAP_FREQ   "--maxbitmapfreq"

Command line flag for the frequency to be used for the max bitmap value (assumes 24-bit: 765) (single integer paramter).

#define FLAG_MIN_BITMAP_FREQ   "--minbitmapfreq"

Command line flag for the frequency to be used for the min non-0 bitmap value (1) (single integer paramter).

#define FLAG_START_LEVELS   "--startlevels"

Command line flag for starting energy levels of start nodes (multiple double paramters).

#define FLAG_START_NODES_X   "--startx"

Command line flag for x indices of start nodes (multiple integer paramters).

#define FLAG_START_NODES_Y   "--starty"

Command line flag for y indices of start nodes (multiple integer paramters).

#define FLAG_TICKS   "--ticks"

Command line flag for number of ticks (single integer paramter).

#define FLAG_X_NODES   "-x"

Command line flag for node grid size on the x axis (single integer paramter).

#define FLAG_X_OBSERVATIONNODES   "--xobs"

Command line flag for x indices of observation nodes (multiple integer paramters).

#define FLAG_Y_NODES   "-y"

Command line flag for node grid size on the y axis (single integer paramter).

#define FLAG_Y_OBSERVATIONNODES   "--yobs"

Command line flag for y indices of observation nodes (multiple integer paramters).

Function Documentation

int calculate_period_length ( int  hz,
const double  tick_ms 
)

Calcuated the period length of the given frequency at the specified resolution, i.e., the number of samples to generate, until the period is reached.

Parameters
hzThe desired frequency in Hz.
tick_msThe milliseconds in between each simulation tick, i.e., the required resolution in milliseconds.
Returns
The number of samples required for one period.
unsigned int contains_flag ( const int  argc,
const char *  argv[],
const char *  flag 
)

Checks if the command line contains a flag.

Parameters
argcNumber of command line arguments.
argvCommand line arguments.
flagThe command line flag.
Returns
1 if it contains, 0 if not.
nodeinputseries_t* generate_input_frequencies ( const int  number_of_inputnodes,
const int *  x_indices,
const int *  y_indices,
const int *  frequencies,
const double  tick_ms 
)

Generates input timeseries for the given nodes with the specified frequency.

The different time-series may vary as the minimal period length is detected.

Parameters
number_of_inputnodesThe number of input nodes and frequencies to generate.
x_indicesAn array of x-coordinates of the nodes. Defines which node will be modified with the defined frequency. Length: number_of_inputnodes.
y_indicesAn array of y-coordinates of the nodes. Defines which node will be modified with the defined frequency. Length: number_of_inputnodes.
frequenciesAn array describing the desired frequencies in periods/second (Hz) to generate for each node. Length: number_of_inputnodes.
tick_msThe milliseconds in between each simulation tick, i.e., the required resolution in milliseconds. This parameter influences the number of generated samples, as frequency is defined in periods/second (Hz).
Returns
The array of input nodes initialized with the specified frequencies. Length: number_of_inputnodes.
nodeinputseries_t* generate_input_frequencies_default ( int *  num_inputnodes,
const double  tick_ms 
)

Generates input timeseries for a set of default given nodes with default frequencies.

The different time-series may vary as the minimal period length is different.

Parameters
num_inputnodesThe number of frequency generating nodes is written to this pointer.
tick_msThe milliseconds in between each simulation tick, i.e., the required resolution in milliseconds. This parameter influences the number of generated samples, as frequency is defined in periods/second (Hz).
Returns
The array of input nodes initialized with the frequencies. Length: num_inputnodes.
nodeinputseries_t* generate_input_frequencies_from_bitmap ( const char *  filenames[],
const unsigned int  num_filenames,
const int  min_freq,
const int  max_freq,
const int  bitmap_duration_ticks,
int *  num_inputnodes,
const double  tick_ms 
)

Generates input timeseries for all non-zero (non-black) nodes from the specified 24-bit bitmap images.

Bitmaps must have the same dimensions and be encoded using uncompressed, 24-bit bitmap files. Bitmap color values are summed (R+G+B) and translated to frequencies. The minimum non-0 color (1) is mapped to min_freq and the maximum color (765) is mapped to max_freq. Other frequencies are determined using linear interpolation.

Parameters
filenamesFile names of the .bmp files to read.
num_filenamesThe number of .bmp files to read.
min_freqThe minimum frequency to generate. The minimum non-0 color (1) is mapped to min_freq.
max_freqThe maximum frequency to generate. The maximum color (765) is mapped to max_freq.
bitmap_duration_ticksThe number of ticks for which to generate a signal for a bitmap before moving on to the next bitmap (analogous to a frame's duration in a movie).
num_inputnodesThe number of frequency generating nodes is written to this pointer.
tick_msThe milliseconds in between each simulation tick, i.e., the required resolution in milliseconds. This parameter influences the number of generated samples, as frequency is defined in periods/second (Hz).
Returns
The array of input nodes initialized with the specified frequencies. Length: num_inputnodes.
nodeinputseries_t* generate_input_frequencies_from_sh ( const int  argc,
const char *  argv[],
int *  num_inputnodes,
const double  tick_ms 
)

Generates input timeseries for the given nodes with the specified frequency.

The different time-series may vary as the minimal period length is detected. Uses command line arguments.

Parameters
argcNumber of command line arguments.
argvCommand line arguments.
num_inputnodesThe number of frequency generating nodes is written to this pointer.
tick_msThe milliseconds in between each simulation tick, i.e., the required resolution in milliseconds. This parameter influences the number of generated samples, as frequency is defined in periods/second (Hz).
Returns
The array of input nodes initialized with the specified frequencies. Length: num_inputnodes.
nodeinputseries_t* generate_input_frequencies_from_sh_bitmap ( const int  argc,
const char *  argv[],
int *  num_inputnodes,
const double  tick_ms 
)

Generates input timeseries for all non-zero (non-black) nodes from the specified 24-bit bitmap images.

Bitmaps must have the same dimensions and be encoded using uncompressed, 24-bit bitmap files. Uses command line arguments.

Parameters
argcNumber of command line arguments.
argvCommand line arguments.
num_inputnodesThe number of frequency generating nodes is written to this pointer.
tick_msThe milliseconds in between each simulation tick, i.e., the required resolution in milliseconds. This parameter influences the number of generated samples, as frequency is defined in periods/second (Hz).
Returns
The array of input nodes initialized with the specified frequencies. Length: num_inputnodes.
double* generate_sin_frequency ( int  hz,
const double  tick_ms 
)

Generates a discretized sinoidal timeseries with the specified frequency and returns it.

Automatically detects the period, and returns exactly only period. Should be preferred way to generate the time-series.

Parameters
hzThe desired frequency in Hz.
tick_msThe milliseconds in between each simulation tick, i.e., the required resolution in milliseconds.
Returns
A series of doubles. Length: Period of the frequency.
double* generate_sin_time_series ( int  hz,
const double  tick_ms,
int  number_of_samples 
)

Generates a specified number of samples of a discretized sinoidal timeseries with the specified frequency and returns it.

Parameters
hzThe desired frequency in Hz.
tick_msThe milliseconds in between each simulation tick, i.e., the required resolution in milliseconds.
number_of_samplesThe number of samples to generate.
Returns
A series of doubles. Length: number_of_samples.
nodeval_t** init_nodegrid_default ( int *  number_nodes_x,
int *  number_nodes_y 
)

Initializes a nodegrid with a default size and initializes it with zero.

Parameters
number_nodes_xWrites the number of nodes in the x-axis to this pointer.
number_nodes_yWrites the number of nodes in the y-axis to this pointer.
Returns
The initialized 2D node field. Size: number_nodes_x * number_nodes_y.
nodetimeseries_t* init_observation_timeseries ( const int  num_oberservationnodes,
const int *  x_indices,
const int *  y_indices,
const int  num_timeseries_elements 
)

Initializes num_oberservationnodes timeseries structs and returns them in an array.

Parameters
num_oberservationnodesThe number of timeseries to create.
x_indicesThe x indices of the nodes to observe. Must have num_obervationnodes as length.
y_indicesThe y indices of the nodes to observe. Must have num_obervationnodes as length.
num_timeseries_elementsThe number of elements for the timeseries to hold. Timeseries memory is allocated as part of initialization.
Returns
Array of newly initialized timeseries structs. Array has num_oberservationnodes as length.
nodetimeseries_t* init_observation_timeseries_default ( int *  num_observationnodes,
int  num_ticks 
)

Initializes num_oberservationnodes timeseries structs with default values and returns them in an array.

Parameters
num_observationnodesWrites the number of timeseries to this pointer.
num_ticksThe number of ticks to simulate, as memory is reserved beforehand.
Returns
Array of newly initialized timeseries structs. Array has num_oberservationnodes as length.
nodetimeseries_t* init_observation_timeseries_from_sh ( const int  argc,
const char *  argv[],
int *  num_observationnodes 
)

Initializes num_oberservationnodes timeseries structs and returns them in an array using settings from the command line.

Parameters
argcNumber of command line arguments.
argvCommand line arguments.
num_observationnodesWrites the number of timeseries to this pointer.
Returns
Array of newly initialized timeseries structs. Array has num_oberservationnodes as length.
void init_start_time_state ( const int  number_nodes_x,
const int  number_nodes_y,
nodeval_t **  nodes,
const int  num_start_levels,
const nodeval_t start_levels,
const int *  start_nodes_x,
const int *  start_nodes_y 
)

Sets a start time energy state for the node field.

All unspecified nodes start with 0.

Parameters
number_nodes_xThe x dimension of the node field.
number_nodes_yThe y dimension of the node field.
nodesThe 2D node field to initialize.
num_start_levelsThe number of nodes in the field to initialize with non-zero values.
start_levelsThe energy levels of the starting non-zero nodes. Must have num_start_levels length.
start_nodes_xThe x indices of the starting non-zero nodes. Must have num_start_levels length.
start_nodes_yThe y indices of the starting non-zero nodes. Must have num_start_levels length.
void init_start_time_state_from_sh ( const int  argc,
const char *  argv[],
const int  number_nodes_x,
const int  number_nodes_y,
nodeval_t **  nodes 
)

Sets a start time energy state for the node field.

All unspecified nodes start with 0 using settings from the command line.

Parameters
argcNumber of command line arguments.
argvCommand line arguments.
number_nodes_xThe x dimension of the node field.
number_nodes_yThe y dimension of the node field.
nodesThe 2D node field to initialize.
int parse_int_arg ( const int  argc,
const char *  argv[],
const char *  flag 
)

Parses an integer argument from the command line for a specified flag.

Parameters
argcNumber of command line arguments.
argvCommand line arguments.
flagThe command line flag.
Returns
The parsed integer argument for the flag.
unsigned int* read_bitmap_contents ( const char *  bitmap_path,
unsigned int *  bitmap_size_x,
unsigned int *  bitmap_size_y 
)

Reads a bitmap image file and returns the sum color values for each pixel in a array.

Array length is width * height. Get pixel using array[y * width + x]. Allocates the new array on the heap (do not forget to free it after use).

Parameters
bitmap_pathPath of the bitmap file to read.
bitmap_size_xThe x dimension of the read bitmap is written to this pointer.
bitmap_size_yThe y dimension of the read bitmap is written to this pointer.
Returns
The array of the sum of the bitmap's color values.
nodeinputseries_t* read_input_behavior ( const int  number_of_inputnodes,
const int *  x_indices,
const int *  y_indices,
const char **  inputnodefilenames,
const int *  number_of_elements 
)

Reads and parses the inputs defined as csv files to be added to the given nodes during the simulation.

Parameters
number_of_inputnodesThe number of input nodes and files.
x_indicesAn array of x-coordinates of the nodes. Defines, which node will be added the values written in the corresponding csv file. Length: number_of_inputnodes.
y_indicesAn array of y-coordinates of the nodes. Defines, which node will be added the values written in the corresponding csv file. Length: number_of_inputnodes.
inputnodefilenamesThe .csv filenames to read. Order must match the order of x_coordinates and y_coordinates. Length: number_of_inputnodes.
number_of_elementsElements assigning each node the number of input elements in the corresponding file. Length: number_of_inputnodes.
Returns
The array of input nodes as read from the given filepaths. Length: number_of_inputnodes.