diff --git a/Makefile b/Makefile index 8264514..90aa13f 100755 --- a/Makefile +++ b/Makefile @@ -6,8 +6,8 @@ SHELL := /bin/bash CC = gcc RM = rm -f CFLAGS=-lm -O3 -Wall -I. -OBJ=serial.o serialDeclarations.o -DEPS=serialDeclarations.h +OBJ=serial.o serial_declarations.o +DEPS=serial_declarations.h # ========================================== # TARGETS diff --git a/output/visualization/visualization.pde b/output/visualization/visualization.pde new file mode 100644 index 0000000..325f21f --- /dev/null +++ b/output/visualization/visualization.pde @@ -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); +} \ No newline at end of file diff --git a/serial.c b/serial.c index 67b263a..3b8ec33 100755 --- a/serial.c +++ b/serial.c @@ -2,7 +2,7 @@ #include #include -#include "serialDeclarations.h" +#include "serial_declarations.h" int NUMBER_OF_POINTS = 600; int DIMENSIONS = 2; @@ -56,11 +56,11 @@ int main(int argc, char **argv){ parameters *opt; opt = ¶ms; - double **shiftedPoints; + double **shifted_points; // tic gettimeofday (&startwtime, NULL); - int iterations = meanshift(vectors, &shiftedPoints, h, opt, 1); + int iterations = meanshift(vectors, &shifted_points, h, opt, 1); // toc gettimeofday (&endwtime, NULL); diff --git a/serialDeclarations.h b/serialDeclarations.h deleted file mode 100644 index b70ad47..0000000 --- a/serialDeclarations.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef SERIAL_DECLARATIONS_H /* Include guard */ -#define SERIAL_DECLARATIONS_H - -#include - -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 \ No newline at end of file diff --git a/serialDeclarations.c b/serial_declarations.c similarity index 66% rename from serialDeclarations.c rename to serial_declarations.c index 7cfe344..3bd388a 100644 --- a/serialDeclarations.c +++ b/serial_declarations.c @@ -4,7 +4,7 @@ #include #include -#include "serialDeclarations.h" +#include "serial_declarations.h" void get_args(int argc, char **argv, int *h){ if (argc != 6) { @@ -24,47 +24,47 @@ void get_args(int argc, char **argv, int *h){ LABELS_FILENAME = argv[5]; } -int meanshift(double **originalPoints, double ***shiftedPoints, int h +int meanshift(double **original_points, double ***shifted_points, int h , parameters *opt, int iteration){ // allocates space and copies original points on first iteration if (iteration == 1){ - (*shiftedPoints) = alloc_2d_double(NUMBER_OF_POINTS, DIMENSIONS); - (*shiftedPoints) = duplicate(originalPoints, (*shiftedPoints) - , NUMBER_OF_POINTS, DIMENSIONS); + (*shifted_points) = alloc_2d_double(NUMBER_OF_POINTS, DIMENSIONS); + duplicate(original_points, NUMBER_OF_POINTS, DIMENSIONS, shifted_points); } // mean shift vector - double **meanShiftVector; - meanShiftVector = alloc_2d_double(NUMBER_OF_POINTS, DIMENSIONS); - // initialize elements of meanShiftVector to inf + double **mean_shift_vector; + mean_shift_vector = alloc_2d_double(NUMBER_OF_POINTS, DIMENSIONS); + // initialize elements of mean_shift_vector to inf for (int i=0;i opt->epsilon) { - return meanshift(originalPoints, shiftedPoints, h, opt, ++iteration); + return meanshift(original_points, shifted_points, h, opt, ++iteration); } return iteration; @@ -98,11 +98,11 @@ int meanshift(double **originalPoints, double ***shiftedPoints, int h // TODO check why there's is a difference in the norm calculate in matlab double norm(double **matrix, int rows, int cols){ - double sum=0, tempMul=0; + double sum=0, temp_mul=0; for (int i=0; i + +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 \ No newline at end of file