From 49dbdd4940aa78021f4ba516f4edb632058262bf Mon Sep 17 00:00:00 2001 From: Samo Penic <samo.penic@fe.uni-lj.si> Date: Wed, 25 Jun 2014 09:44:48 +0000 Subject: [PATCH] Fixes bugs in creating IsakPrograms compatible image --- src/cross-section.h | 2 ++ src/tape | 2 +- src/cross-section.c | 52 +++++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/cross-section.c b/src/cross-section.c index d25f934..d4da81c 100644 --- a/src/cross-section.c +++ b/src/cross-section.c @@ -2,6 +2,7 @@ #include<cross-section.h> #include<coord.h> #include<cairo/cairo.h> +#include<stdint.h> /** @brief Calculates cross-section of vesicle with plane. * * Function returns points of cross-section of vesicle with plane. Plane is described with equation $ax+by+cz+d=0$. Algorithm extracts coordinates of each vertex of a vesicle and then: @@ -77,17 +78,17 @@ cairo_surface_t *surface; cairo_t *cr; ts_uint i; - surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 1800, 1800); + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 768, 576); cr = cairo_create (surface); - cairo_rectangle(cr, 0.0, 0.0, 1800,1800); - cairo_set_source_rgb(cr, 0.3, 0.3, 0.3); + cairo_rectangle(cr, 0.0, 0.0, 768,576); + cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); cairo_fill(cr); - cairo_set_line_width (cr, 5.0/30.0); + cairo_set_line_width (cr, 2.0/8.0); cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND); cairo_set_line_join(cr, CAIRO_LINE_JOIN_ROUND); - cairo_translate(cr, 900,900); - cairo_scale (cr, 30, 30); - cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); + cairo_translate(cr, 380,250); + cairo_scale (cr, 8.0, 8.0); + cairo_set_source_rgb (cr, 0.3, 0.3, 0.3); for(i=0;i<pts->n;i+=2){ cairo_move_to(cr, pts->coord[i]->e1, pts->coord[i]->e2); @@ -95,6 +96,7 @@ } cairo_stroke(cr); cairo_surface_write_to_png (surface,filename); + append_to_isak_program_raw(surface,"experimental.img"); cairo_surface_finish (surface); return TS_SUCCESS; } @@ -106,3 +108,39 @@ crossection_to_png(pts,filename); return TS_SUCCESS; } + +ts_bool append_to_isak_program_raw(cairo_surface_t *surface, char *filename){ + + unsigned char *d=cairo_image_surface_get_data(surface); + int w=cairo_image_surface_get_width(surface); + int h=cairo_image_surface_get_height(surface); + int s=cairo_image_surface_get_stride(surface); + int i,j; + FILE *fd=fopen(filename, "a+"); + + uint32_t *pixelptr; + uint32_t my_pixel; + uint8_t pixel_channel; +// red = (pixel[8] >> 16) & 0xFF; + + + + fwrite (&w,sizeof(uint32_t),1,fd); + fwrite (&h,sizeof(uint32_t),1,fd); + fwrite (&w,sizeof(uint32_t),1,fd);//time! + for(i=0;i<h;i++){ + for(j=0;j<w;j++){ + pixelptr=(uint32_t *)(d + i * s); + my_pixel = pixelptr[j]; + pixel_channel=(my_pixel>>16)&0xFF; + fwrite(&pixel_channel,sizeof(uint8_t), 1,fd); + } + } + fclose(fd); + return TS_SUCCESS; +} + +/*ts_bool init_isak_program_raw_output_file(ts_uint w, ts_uint h, char *filename){ + + +}*/ diff --git a/src/cross-section.h b/src/cross-section.h index 0021daa..a8e92de 100644 --- a/src/cross-section.h +++ b/src/cross-section.h @@ -1,8 +1,10 @@ #ifndef _H_CROSS_SECTION #define _H_CROSS_SECTION +#include<cairo/cairo.h> ts_coord_list *get_crossection_with_plane(ts_vesicle *vesicle,ts_double a,ts_double b,ts_double c, ts_double d); ts_bool add_crosssection_point(ts_coord_list *pts, ts_double a, ts_double b, ts_double c, ts_double d, ts_vertex *vtx1, ts_vertex *vtx2); ts_bool crossection_to_png(ts_coord_list *pts, char *filename); ts_bool save_crossection_snapshot(ts_coord_list *pts, ts_uint timestepno); +ts_bool append_to_isak_program_raw(cairo_surface_t *surface, char *filename); #endif diff --git a/src/tape b/src/tape index 7eae2ba..6a54093 100644 --- a/src/tape +++ b/src/tape @@ -49,7 +49,7 @@ ####### Program Control ############ #how many MC sweeps between subsequent records of states to disk -mcsweeps=2000 +mcsweeps=200 #how many initial mcsweeps*inititer MC sweeps before recording to disk? inititer=0 #how many records do you want on the disk iteration are there in a run? -- Gitblit v1.9.3