Browse Source
Add Processing script for visualizing results Change camelCase strings to _underscore notationmaster
Apostolos Fanakis
7 years ago
6 changed files with 124 additions and 70 deletions
@ -0,0 +1,35 @@ |
|||||
|
int frame = 1; |
||||
|
PShape frameS; |
||||
|
|
||||
|
void setup() { |
||||
|
size(1280, 720); |
||||
|
frameRate(12); |
||||
|
} |
||||
|
|
||||
|
int scale = 40; |
||||
|
float radius = 2; |
||||
|
|
||||
|
void draw() { |
||||
|
background(255); |
||||
|
stroke(0); |
||||
|
translate(220, 0); |
||||
|
//scale(scale); |
||||
|
|
||||
|
fill(0); |
||||
|
String[] lines; |
||||
|
lines = loadStrings("../output_" + frame); |
||||
|
if (lines == null){ |
||||
|
delay(5000); |
||||
|
exit(); |
||||
|
} else { |
||||
|
for (int i = 0; i < lines.length; i++) { |
||||
|
String[] pieces = split(lines[i], ","); |
||||
|
frameS = createShape(ELLIPSE, Float.parseFloat(pieces[0])*scale,Float.parseFloat(pieces[1])*scale, radius, radius); |
||||
|
shape(frameS, 0, 0); |
||||
|
} |
||||
|
} |
||||
|
frame++; |
||||
|
//Uncomment to save each frame to a jpg file |
||||
|
//saveFrame("out-######.jpg"); |
||||
|
delay(600); |
||||
|
} |
@ -1,28 +0,0 @@ |
|||||
#ifndef SERIAL_DECLARATIONS_H /* Include guard */ |
|
||||
#define SERIAL_DECLARATIONS_H |
|
||||
|
|
||||
#include <stdbool.h> |
|
||||
|
|
||||
extern int NUMBER_OF_POINTS; |
|
||||
extern int DIMENSIONS; |
|
||||
extern char* POINTS_FILENAME; |
|
||||
extern char* LABELS_FILENAME; |
|
||||
|
|
||||
typedef struct parameters { |
|
||||
double epsilon; |
|
||||
bool verbose; |
|
||||
bool display; |
|
||||
} parameters; |
|
||||
|
|
||||
void get_args(int argc, char **argv, int *h); |
|
||||
int meanshift(double **originalPoints, double ***shiftedPoints, int h |
|
||||
, parameters *opt, int iteration); |
|
||||
double norm(double ** m, int rows, int cols); |
|
||||
void multiply(double ** matrix1, double ** matrix2, double ** output); |
|
||||
double calculateDistance(double *, double *); |
|
||||
double **alloc_2d_double(int rows, int cols); |
|
||||
double **duplicate(double **a, double **b, int rows, int cols); |
|
||||
void print_matrix(double ** array, int rows, int cols); |
|
||||
void save_matrix(double **matrix,int iteration); |
|
||||
|
|
||||
#endif //SERIAL_DECLARATIONS_H
|
|
@ -0,0 +1,50 @@ |
|||||
|
#ifndef SERIAL_DECLARATIONS_H /* Include guard */ |
||||
|
#define SERIAL_DECLARATIONS_H |
||||
|
|
||||
|
#include <stdbool.h> |
||||
|
|
||||
|
extern int NUMBER_OF_POINTS; |
||||
|
extern int DIMENSIONS; |
||||
|
extern char* POINTS_FILENAME; |
||||
|
extern char* LABELS_FILENAME; |
||||
|
|
||||
|
typedef struct parameters { |
||||
|
double epsilon; |
||||
|
bool verbose; |
||||
|
bool display; |
||||
|
} parameters; |
||||
|
|
||||
|
//Function get_args parses command line arguments.
|
||||
|
void get_args(int argc, char **argv, int *h); |
||||
|
|
||||
|
//Function meanshift recursively shifts original points according to th
|
||||
|
//mean-shift algorithm saving the result to shiftedPoints. Struct opt has user
|
||||
|
//options, h is the desirable deviation, iteration is this call's iteration
|
||||
|
//number.
|
||||
|
int meanshift(double **original_points, double ***shifted_points, int h |
||||
|
, parameters *opt, int iteration); |
||||
|
|
||||
|
//Function norm returns the second norm of matrix of dimensions rowsXcols.
|
||||
|
double norm(double **matrix, int rows, int cols); |
||||
|
|
||||
|
//Function multiply calculates the product of matrices 1 and 2 into output.
|
||||
|
void multiply(double **matrix1, double **matrix2, double **output); |
||||
|
|
||||
|
//Function calculateDistance returns the distance between x and y vectors.
|
||||
|
double calculateDistance(double *y, double *x); |
||||
|
|
||||
|
//Function alloc_2d_double allocates rows*cols bytes of continuous memory.
|
||||
|
double **alloc_2d_double(int rows, int cols); |
||||
|
|
||||
|
//Function duplicate copies the values of source array to dest array.
|
||||
|
void duplicate(double **source, int rows, int cols, double ***dest); |
||||
|
|
||||
|
//Function print_matrix prints array of dimensions rowsXcols to the console.
|
||||
|
void print_matrix(double **array, int rows, int cols); |
||||
|
|
||||
|
//Function save_matrix prints matrix in a csv file with path/filename
|
||||
|
//"output/output_iteration". If a file already exists new lines are concatenated.
|
||||
|
void save_matrix(double **matrix |
||||
|
, int iteration); |
||||
|
|
||||
|
#endif //SERIAL_DECLARATIONS_H
|
Loading…
Reference in new issue