We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey Guys, I got one little problem that really blocks me from working on. To explain this: I created a script in Grasshopper (Graphical Programming Interface for Rhino 3D) that groups pictures based on some database. All data of the items are written into a .csv (things like position, size and index of the file). I then wrote some code in Processing to display pictures with the options provided in the csv-file (gh_data.csv). The filenames with the corresponding indices are written into a seperate csv-file.
All this works great until a certain time when the processing program seems to hang (colour-wheel of death) and I don't really know why.
Could this happen because I reload the table all the time? My thought was that I overwrite the data all the time and so there should not be any problem considering RAM, but maybe there is?
String filepath = "/Users/max/Desktop/collage_maker/png_small/";
Table filenames;
Table table_gh;
PImage[] images;
float factor = 1;
float factor_size = 1.2;
void setup()
{
imageMode(CENTER);
filenames = loadTable("gh_filenames.csv");
images = new PImage[filenames.getRowCount()];
load_images();
size(int(1000*factor),int(1000*factor));
}
void draw()
{
load_data();
background(255);
for(int i = 0; i<table_gh.getRowCount(); i++){
int _pos_x = int(factor*table_gh.getFloat(i,0));
int _pos_y = int(factor*table_gh.getFloat(i,1));
int _size = int(factor_size*table_gh.getFloat(i,2));
int _index = int(table_gh.getString(i,3));
image(images[_index],_pos_x,_pos_y,_size,_size);
}
}
void load_data(){
table_gh = loadTable("gh_data.csv");
}
void load_images(){
int image_counter = 0;
for(int i = 0; i<images.length; i++){
String filename = filenames.getString(i,0)+".png";
File f = new File(dataPath(filepath+filename));
// FILE EXISTS?
if (f.exists()){
println(filename);
image_counter ++;
images[i] = loadImage(filepath+filename);
} else {
println(filename+" nicht vorhanden");
images[i] = loadImage(filepath+"placeholder.png");
}
}
println(image_counter+" Bilder gefunden");
}
Answers
how big does the file get?
how many images?
maybe you can let it wait until all are loaded
(or go in a new thread?)
at first - thank you for your comment.
which file do you mean? the collages are just displayed and not saved in any specific file. there are 162 images in total. right now, they are all PNGs with a resolution of 100x100, but I would like to use bigger ones (probably 500x500).
Actually I do wait until all are loaded before starting since all pictures are loaded into the RAM while still in void setup(). There is also feedback on the process of loading all files and It prints a notification on how many pictures have been loaded in the end.
So I think he loading process itself works fine. My problem is that after a certain number of frames (its about 10 seconds) the program starts to hang itself up...
Is there any way to "clean" a variable like the Table table_gh? I had the idea that overwriting the Table might not delete the old data in the RAM...
you wrote
so the .csv gets deleted / recreated or appended?
appended would mean getting bigger.
Is this in Win? I don't know what happens when 2 programs access the same file at the time. Can Grasshopper lock the csv for writing and the open it again?
and can processing detect that?
I can't help.
;-)