Monte Carlo eXtreme (MCX)
Macros | Functions | Variables
mcx_shapes.c File Reference

3D shape parsing and rasterization unit More...

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include "cjson/cJSON.h"
#include "mcx_shapes.h"
Include dependency graph for mcx_shapes.c:

Macros

#define MIN(a, b)   ((a)<(b)?(a):(b))
 
#define MAX(a, b)   ((a)>(b)?(a):(b))
 

Functions

int mcx_load_jsonshapes (Grid3D *g, char *fname)
 Load a JSON-formatted shape file and process. More...
 
int mcx_parse_shapestring (Grid3D *g, char *shapedata)
 Load JSON-formatted shape definitions from a string. More...
 
int mcx_parse_jsonshapes (cJSON *root, Grid3D *g)
 Parse a JSON-formatted shape file and rasterize the objects to the volume. More...
 
int mcx_raster_origin (cJSON *obj, Grid3D *g)
 Reset the origin of the domain, default is [0,0,0]. More...
 
int mcx_raster_sphere (cJSON *obj, Grid3D *g)
 Rasterize a 3D sphere and add to the volume. More...
 
int mcx_raster_subgrid (cJSON *obj, Grid3D *g)
 Rasterize a 3D rectangular region and add to the volume. More...
 
int mcx_raster_box (cJSON *obj, Grid3D *g)
 Rasterize a 3D rectangular region and add to the volume. More...
 
int mcx_raster_cylinder (cJSON *obj, Grid3D *g)
 Rasterize a finite 3D cylindrical region and add to the volume. More...
 
int mcx_raster_slabs (cJSON *obj, Grid3D *g)
 Rasterize a 3D layered-slab structure and add to the volume. More...
 
int mcx_raster_layers (cJSON *obj, Grid3D *g)
 Rasterize a 3D layer structure and add to the volume. More...
 
int mcx_raster_upperspace (cJSON *obj, Grid3D *g)
 Rasterize a 3D semi-space region and add to the volume. More...
 
int mcx_raster_grid (cJSON *obj, Grid3D *g)
 Recreate the background grid with a different dimension or medium. More...
 
int mcx_find_shapeid (char *shapename)
 Look up the JSON object tag and return the index to the processing function. More...
 
char * mcx_last_shapeerror ()
 return the last error message encountered in the processing
 

Variables

const char * ShapeTags []
 
int(* Rasterizers [])(cJSON *obj, Grid3D *g)
 
char ErrorMsg [MAX_SHAPE_ERR] = {'\0'}
 

Detailed Description

3D shape parsing and rasterization unit

In this unit, we load and parse a JSON-formatted shape file, rasterize the 3D objects and subsequently add to a voxelated volume.

Function Documentation

◆ mcx_find_shapeid()

int mcx_find_shapeid ( char *  shapename)

Look up the JSON object tag and return the index to the processing function.

Parameters
shapenameThe string of the JSON shape object

◆ mcx_load_jsonshapes()

int mcx_load_jsonshapes ( Grid3D g,
char *  fname 
)

Load a JSON-formatted shape file and process.

Parameters
gA structure pointing to the volume and dimension data
fnameThe file name string to the JSON shape file

◆ mcx_parse_jsonshapes()

int mcx_parse_jsonshapes ( cJSON *  root,
Grid3D g 
)

Parse a JSON-formatted shape file and rasterize the objects to the volume.

Parameters
rootA cJSON pointer points to the root obj of the shape block
gA structure pointing to the volume and dimension data
Here is the call graph for this function:

◆ mcx_parse_shapestring()

int mcx_parse_shapestring ( Grid3D g,
char *  shapedata 
)

Load JSON-formatted shape definitions from a string.

Parameters
gA structure pointing to the volume and dimension data
shapedataA string containg the JSON shape data
Here is the call graph for this function:

◆ mcx_raster_box()

int mcx_raster_box ( cJSON *  obj,
Grid3D g 
)

Rasterize a 3D rectangular region and add to the volume.

Parameters
objA cJSON pointer points to the rectangular obj block
gA structure pointing to the volume and dimension data

◆ mcx_raster_cylinder()

int mcx_raster_cylinder ( cJSON *  obj,
Grid3D g 
)

Rasterize a finite 3D cylindrical region and add to the volume.

Parameters
objA cJSON pointer points to the cylindrical obj block
gA structure pointing to the volume and dimension data

◆ mcx_raster_grid()

int mcx_raster_grid ( cJSON *  obj,
Grid3D g 
)

Recreate the background grid with a different dimension or medium.

Parameters
objA cJSON pointer points to the background grid block
gA structure pointing to the volume and dimension data

◆ mcx_raster_layers()

int mcx_raster_layers ( cJSON *  obj,
Grid3D g 
)

Rasterize a 3D layer structure and add to the volume.

Parameters
objA cJSON pointer points to the layer structure block
gA structure pointing to the volume and dimension data

◆ mcx_raster_origin()

int mcx_raster_origin ( cJSON *  obj,
Grid3D g 
)

Reset the origin of the domain, default is [0,0,0].

Parameters
objA cJSON pointer points to the Origin obj block
gA structure pointing to the volume and dimension data

◆ mcx_raster_slabs()

int mcx_raster_slabs ( cJSON *  obj,
Grid3D g 
)

Rasterize a 3D layered-slab structure and add to the volume.

Parameters
objA cJSON pointer points to the layered-slab structure block
gA structure pointing to the volume and dimension data

◆ mcx_raster_sphere()

int mcx_raster_sphere ( cJSON *  obj,
Grid3D g 
)

Rasterize a 3D sphere and add to the volume.

Parameters
objA cJSON pointer points to the sphere obj block
gA structure pointing to the volume and dimension data

◆ mcx_raster_subgrid()

int mcx_raster_subgrid ( cJSON *  obj,
Grid3D g 
)

Rasterize a 3D rectangular region and add to the volume.

Parameters
objA cJSON pointer points to the rectangular obj block
gA structure pointing to the volume and dimension data

◆ mcx_raster_upperspace()

int mcx_raster_upperspace ( cJSON *  obj,
Grid3D g 
)

Rasterize a 3D semi-space region and add to the volume.

Parameters
objA cJSON pointer points to the semi-space object block
gA structure pointing to the volume and dimension data

Variable Documentation

◆ Rasterizers

int(* Rasterizers[])(cJSON *obj, Grid3D *g)
Initial value:
}
int mcx_raster_grid(cJSON *obj, Grid3D *g)
Recreate the background grid with a different dimension or medium.
Definition: mcx_shapes.c:788
int mcx_raster_box(cJSON *obj, Grid3D *g)
Rasterize a 3D rectangular region and add to the volume.
Definition: mcx_shapes.c:360
int mcx_raster_cylinder(cJSON *obj, Grid3D *g)
Rasterize a finite 3D cylindrical region and add to the volume.
Definition: mcx_shapes.c:432
int mcx_raster_layers(cJSON *obj, Grid3D *g)
Rasterize a 3D layer structure and add to the volume.
Definition: mcx_shapes.c:634
int mcx_raster_subgrid(cJSON *obj, Grid3D *g)
Rasterize a 3D rectangular region and add to the volume.
Definition: mcx_shapes.c:294
int mcx_raster_origin(cJSON *obj, Grid3D *g)
Reset the origin of the domain, default is [0,0,0].
Definition: mcx_shapes.c:212
int mcx_raster_sphere(cJSON *obj, Grid3D *g)
Rasterize a 3D sphere and add to the volume.
Definition: mcx_shapes.c:233
int mcx_raster_slabs(cJSON *obj, Grid3D *g)
Rasterize a 3D layered-slab structure and add to the volume.
Definition: mcx_shapes.c:525
int mcx_raster_upperspace(cJSON *obj, Grid3D *g)
Rasterize a 3D semi-space region and add to the volume.
Definition: mcx_shapes.c:736

◆ ShapeTags

const char* ShapeTags[]
Initial value:
= {"Name", "Origin", "Grid", "Subgrid", "Sphere", "Box", "XSlabs",
"YSlabs", "ZSlabs", "XLayers", "YLayers", "ZLayers",
"Cylinder", "UpperSpace", NULL
}