Tidy up neural rendering
This commit is contained in:
parent
55448bf44a
commit
1241bca52f
3 changed files with 48 additions and 44 deletions
|
@ -21,6 +21,7 @@ typedef struct _neural_network {
|
|||
Neural_Network *neural_new(size_t, size_t, size_t);
|
||||
void neural_randomize(Neural_Network *);
|
||||
float *neural_process(Neural_Network *, float *);
|
||||
int neural_getMesh(ModelRegistry *, Neural_Network *);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
45
src/cx.c
45
src/cx.c
|
@ -135,59 +135,18 @@ cx_nnrun(Neural_Network *nn) {
|
|||
|
||||
int
|
||||
cx_run(GLFWwindow *window, Neural_Network *nn) {
|
||||
Model *model;
|
||||
ModelRegistry *mr;
|
||||
Model *neural_network_model;
|
||||
GLuint VertexArrayID;
|
||||
GLuint programID;
|
||||
|
||||
if (cx_loadShaders(&VertexArrayID, &programID)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
// Establish a model registry
|
||||
mr = modelRegistry_new();
|
||||
// Fill the model registry with mesh models
|
||||
for (int j = 0; j < nn->layer_count; j++) {
|
||||
Neural_Layer *nl = nn->layers[j];
|
||||
for (int i = 0; i < nl->layer_size; i++) {
|
||||
// Load model to render from file
|
||||
//Model *model = model_load("../3d_assets/triangle.obj");
|
||||
for (int k = 0; k < nl->layer_size_next; k++) {
|
||||
model = model_line((-.90)
|
||||
+ ((GLfloat)2 * i * .90/(nl->layer_size-1)),
|
||||
|
||||
.90 - ((GLfloat)2 * j *.90/(nn->layer_count)),
|
||||
|
||||
(-.90)
|
||||
+ ((GLfloat)2 * k * .90/(nl->layer_size_next-1)),
|
||||
|
||||
.90 - ((GLfloat)2 * (j+1) *.90/(nn->layer_count)),
|
||||
|
||||
.001 // girth
|
||||
);
|
||||
modelRegistry_register(mr, model);
|
||||
}
|
||||
|
||||
model = model_circle(0, (GLfloat)1/64);
|
||||
GLfloat *translation_matrix = matrix_new();
|
||||
GLfloat *aspectRatio_matrix = matrix_new();
|
||||
aspectRatio_matrix[0] = (GLfloat)9/16;
|
||||
|
||||
translation_matrix[3] = (((GLfloat)-1*16/9)*.90)
|
||||
+ ((GLfloat)1/(nl->layer_size-1)*2 * i * (((GLfloat)16/9))*.90);
|
||||
|
||||
translation_matrix[7] = .90 - ((GLfloat)1/(nn->layer_count)*2 * j *.90);
|
||||
|
||||
model->transformations[0] = translation_matrix;
|
||||
model->transformations[1] = aspectRatio_matrix;
|
||||
model->transformation_count = 2;
|
||||
model_colorWhite(model);
|
||||
|
||||
modelRegistry_register(mr, model);
|
||||
|
||||
}
|
||||
}
|
||||
neural_getMesh(mr, nn);
|
||||
|
||||
// Remainder from cursor experiments, might be useful later
|
||||
double xpos, ypos;
|
||||
|
|
46
src/neural.c
46
src/neural.c
|
@ -31,7 +31,6 @@ neural_new(size_t input_size, size_t output_size, size_t layer_count) {
|
|||
// The difference between layer sizes, hidden layers step between the two
|
||||
// sizes in linear fashion.
|
||||
ssize_t layer_diff;
|
||||
ssize_t layer_step;
|
||||
|
||||
self->layer_count = layer_count;
|
||||
self->layers = malloc(layer_count * sizeof(Neural_Layer *));
|
||||
|
@ -71,6 +70,8 @@ neural_process(Neural_Network *self, float *input) {
|
|||
float *retval = NULL;
|
||||
Neural_Layer *nl = self->layers[0];
|
||||
|
||||
retval = malloc(self->layers[self->layer_count-1]->layer_size * sizeof(float));
|
||||
|
||||
for (int i = 0; i < self->layers[0]->layer_size; i++) {
|
||||
nl->neurons[i].value = input[i];
|
||||
}
|
||||
|
@ -92,3 +93,46 @@ neural_process(Neural_Network *self, float *input) {
|
|||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
neural_getMesh(ModelRegistry *mr, Neural_Network *nn) {
|
||||
Model *model;
|
||||
for (int j = 0; j < nn->layer_count; j++) {
|
||||
Neural_Layer *nl = nn->layers[j];
|
||||
for (int i = 0; i < nl->layer_size; i++) {
|
||||
for (int k = 0; k < nl->layer_size_next; k++) {
|
||||
model = model_line((-.90)
|
||||
+ ((GLfloat)2 * i * .90/(nl->layer_size-1)),
|
||||
|
||||
.90 - ((GLfloat)2 * j *.90/(nn->layer_count)),
|
||||
|
||||
(-.90)
|
||||
+ ((GLfloat)2 * k * .90/(nl->layer_size_next-1)),
|
||||
|
||||
.90 - ((GLfloat)2 * (j+1) *.90/(nn->layer_count)),
|
||||
|
||||
.001 // girth
|
||||
);
|
||||
modelRegistry_register(mr, model);
|
||||
}
|
||||
|
||||
model = model_circle(0, (GLfloat)1/64);
|
||||
GLfloat *translation_matrix = matrix_new();
|
||||
GLfloat *aspectRatio_matrix = matrix_new();
|
||||
aspectRatio_matrix[0] = (GLfloat)9/16;
|
||||
|
||||
translation_matrix[3] = (((GLfloat)-1*16/9)*.90)
|
||||
+ ((GLfloat)1/(nl->layer_size-1)*2 * i * (((GLfloat)16/9))*.90);
|
||||
|
||||
translation_matrix[7] = .90 - ((GLfloat)1/(nn->layer_count)*2 * j *.90);
|
||||
|
||||
model->transformations[0] = translation_matrix;
|
||||
model->transformations[1] = aspectRatio_matrix;
|
||||
model->transformation_count = 2;
|
||||
model_colorWhite(model);
|
||||
|
||||
modelRegistry_register(mr, model);
|
||||
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue