Skip to content

ethanlipson/DensityMap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DensityMap

DensityMap is a class that stores a 3D array of unsigned bytes between 0 and 255 (inclusive) and allows them to be displayed using OpenGL. It was developed for the Columbia Open Source Ultrasound Project, which aims to create affordable ultrasound for families across the globe. Specifically, this library was used to display ultrasound data collected in real time at a high resolution.

Methods

DensityMap(int dim)
Initializes the DensityMap with a cubic array of side length dim.

void clear(int value = 0)
Fills the whole array with a given value. Defaults to 0.

void writeLine(glm::vec3 p1, glm::vec3 p2, std::vector<unsigned char> vals, WriteMode writeMode = DensityMap::WriteMode::Avg)
Adds a line of data to the array along the line segment defined by p1 and p2. The more values there are in vals, the smoother the line will be.
The value written to the cell will be the weighted average of the new and old value. The coefficient used in this formula is determined by setUpdateCoefficient().

void writeCell(unsigned int x, unsigned int y, unsigned int z, unsigned char value)
Writes to one cell of the buffer on the graphics card.

Multiple data values can fall into the same cell (especially if there is a lot of data), so there are multiple ways to combine them.
If writeMode is equal to DensityMap::WriteMode::Avg, then all values in the same cell will be averaged, and that value will be written to the cell.
If writeMode is equal to DensityMap::WriteMode::Max, then the maximum of all the values in the cell will be written (this can be better if your data is sparse).

int getDim()
Returns the side length of the cube.

void draw(glm::mat4 projection, glm::mat4 view, glm::mat4 model)
Draws the density map and a white box around it to the screen.

void setThreshold(unsigned char value)
unsigned char getThreshold()
These set and get the minimum value needed to draw a cell. The fewer cells are drawn, the faster your program will run.

void setUpdateCoefficient(float value)
float getUpdateCoefficient()
These set and get the update coefficient used for the weighted average in writeLine().
If it is 1, then the new value completely overwrites the old value. If it is 0.5, then the mean of the new and old values is taken. If it is 0, then writing new values has no effect (not recommended for obvious reasons).

void setBrightness(float value)
float getBrightness()
void setContrast(float value)
float getContrast()

These set and get the image brightness and contrast.
After the cell shades are mapped onto the closed interval [0, 1], the following formula is applied:

shade = contrast * (shade - 0.5) + 0.5 + brightness

When the brightness is 1, all cells will be white, and when the brightness is -1, all cells will be invisible.
When the contrast is between 0 and 1, cells will appear less contrasted with their neighbors, and when it is more than 1, they will appear more contrasted with their neighbors.

unsigned char readCell(int x, int y, int z)
Gets the value at a specific index in the array. Blocks when drawing is happening.

unsigned char readCellInterpolated(float x, float y, float z)
Gets the interpolated value at a position in the cube. Blocks when drawing is happening.
x, y, and z must all be on the half-open range [0, 1)

void readLine(glm::vec3 p1, glm::vec3 p2, int numVals, unsigned char* vals)
Gets the interpolated values along the line between two points and writes them to a given array.
Make sure at least numVals bytes of memory are allocated for vals.

Movement

There are two movement options, controlled by setting ROTATE_GRID at the top of main.cpp to either true or false.

If ROTATE_GRID is false, then the camera can be moved around using WASD plus Q and E for upwards and downwards movement. C zooms in the camera.

If ROTATE_GRID is true, then the camera is stationary, and the grid can be rotated by clicking the left mouse button and dragging. Press R to reset the orientation.

The image is in the images folder

About

A class for representing a 3D array of values

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published