Skip to content

Commit 7043cee

Browse files
committed
getting up to date
1 parent 46bb372 commit 7043cee

File tree

2 files changed

+58
-31
lines changed

2 files changed

+58
-31
lines changed

main.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@ int main( int argc, char* args[] ) {
4545
IMG_Init(IMG_INIT_PNG);
4646

4747
std::vector<SrcImage> src_images;
48-
load_images(20000, "hemtai", src_images);
49-
int recInd = src_images.size()-2;
48+
load_images(20000, "Qats_reduced", src_images);
49+
int recInd = src_images.size()-1;
5050
SrcImage reconstructed = src_images[recInd];
5151
std::cout << "RECONSTRUCTING " << reconstructed.path << std::endl;
52+
std::cout << "p1 p2 p3 p4 " << (int)reconstructed.data[0] << " " << (int)reconstructed.data[1]
53+
<< " " << (int)reconstructed.data[2] << " " << (int)reconstructed.data[3] << " " << std::endl;
5254
src_images.erase(src_images.begin() + recInd);
5355
Habitat hbsim = Habitat(&reconstructed, &src_images);
5456

@@ -58,16 +60,24 @@ int main( int argc, char* args[] ) {
5860
for (int i = 0; i < 100000000; i++) {
5961
hbsim.step();
6062

63+
if (i == 80000) {
64+
src_images.clear(); // TODO: free .data of underlying images
65+
load_images(30000, "Qats_reduced", src_images);
66+
reconstructed = src_images[recInd];
67+
src_images.erase(src_images.begin() + recInd);
68+
hbsim.reload_indiv_pointers();
69+
}
70+
6171
if (i == 300000) {
6272
src_images.clear(); // TODO: free .data of underlying images
63-
load_images(60000, "hemtai", src_images);
73+
load_images(60000, "Qats_reduced", src_images);
6474
reconstructed = src_images[recInd];
6575
src_images.erase(src_images.begin() + recInd);
6676
hbsim.reload_indiv_pointers();
6777
}
6878
if (i == 420000) {
6979
src_images.clear(); // TODO: free .data of underlying images
70-
load_images(100000000000, "hemtai", src_images);
80+
load_images(100000000000, "Qats_reduced", src_images);
7181
reconstructed = src_images[recInd];
7282
src_images.erase(src_images.begin() + recInd);
7383
hbsim.reload_indiv_pointers();

main_pure_random.cpp

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include "opencv2/opencv.hpp"
2121
#include <opencv2/imgcodecs.hpp>
2222

23+
#include <tbb/parallel_for.h>
24+
#include <tbb/mutex.h>
25+
2326
#include "utils.h"
2427

2528
bool init_sdl(SDL_Window** window_ptr, SDL_Surface** surface_ptr, SDL_Renderer** renderer_ptr,
@@ -35,14 +38,22 @@ int main( int argc, char* args[] ) {
3538
IMG_Init(IMG_INIT_PNG);
3639

3740
std::vector<SrcImage> src_images;
38-
load_images("imgsimple", src_images);
41+
load_images("hemtaiClean", src_images);
3942
int recInd = src_images.size()-1;
4043
SrcImage reconstructed = src_images[recInd];
4144
reconstructed.data = new uint8_t[reconstructed.width * reconstructed.height * 4];
4245
memset(reconstructed.data, 0xFFFFFF00, reconstructed.width * reconstructed.height*4);
4346
RotatePixel_t *pPstBase = static_cast<RotatePixel_t*>((void*)reconstructed.data);
4447
RotatePixel_t *pDstBase = static_cast<RotatePixel_t*>((void*)src_images[recInd].data);
4548

49+
int best_sad;
50+
int bestX;
51+
int bestY;
52+
float bestA;
53+
float bestS;
54+
55+
tbb::mutex best_mutex;
56+
4657
Timer t;
4758
t.start();
4859
for (int i = 0; i < 100000000; i++) {
@@ -51,31 +62,37 @@ int main( int argc, char* args[] ) {
5162
continue;
5263
}
5364
RotatePixel_t *pSrcBase = static_cast<RotatePixel_t*>((void*)src_images[index].data);
54-
int best_sad = INT_MAX;
55-
int bestX;
56-
int bestY;
57-
float bestA;
58-
float bestS;
59-
for (int j = 0; j < 100; j++) {
60-
int fDstCX = rand()%(src_images[recInd].width);
61-
int fDstCY = rand()%(src_images[recInd].height);
62-
float fAngle = rand()%(314) / 100.0;
63-
float fScale = (rand()%(1500) + 1) / 1000.0;
64-
sadPair genQuality = RotateDrawClipSad(
65-
pDstBase, src_images[recInd].width, src_images[recInd].height, src_images[recInd].pitch,
66-
pSrcBase, src_images[index].width, src_images[index].height, src_images[index].pitch,
67-
pPstBase,
68-
fDstCX, fDstCY,
69-
0, 0,
70-
fAngle, fScale );
71-
if (genQuality.sad1 < genQuality.sad2 && genQuality.sad1 < best_sad) {
72-
best_sad = genQuality.sad1;
73-
bestX = fDstCX;
74-
bestY = fDstCY;
75-
bestA = fAngle;
76-
bestS = fScale;
65+
66+
best_sad = INT_MAX;
67+
tbb::parallel_for( tbb::blocked_range<int>(0, 100, 1),
68+
[&](tbb::blocked_range<int> r) {
69+
for (int j = r.begin(); j < r.end(); j++) {
70+
int fDstCX = rand()%(src_images[recInd].width);
71+
int fDstCY = rand()%(src_images[recInd].height);
72+
float fAngle = rand()%(314) / 100.0;
73+
float fScale = (rand()%(1500) + 1) / 1000.0;
74+
sadPair genQuality = RotateDrawClipSad(
75+
pDstBase, src_images[recInd].width, src_images[recInd].height, src_images[recInd].pitch,
76+
pSrcBase, src_images[index].width, src_images[index].height, src_images[index].pitch,
77+
pPstBase,
78+
fDstCX, fDstCY,
79+
0, 0,
80+
fAngle, fScale );
81+
82+
83+
tbb::mutex::scoped_lock lock;
84+
lock.acquire(best_mutex);
85+
if (genQuality.sad1 < genQuality.sad2 && genQuality.sad1 < best_sad) {
86+
best_sad = genQuality.sad1;
87+
bestX = fDstCX;
88+
bestY = fDstCY;
89+
bestA = fAngle;
90+
bestS = fScale;
91+
}
92+
93+
lock.release();
7794
}
78-
}
95+
});
7996

8097
if (best_sad != INT_MAX) {
8198
RotateDrawClip(
@@ -85,11 +102,11 @@ int main( int argc, char* args[] ) {
85102
0, 0,
86103
bestA, bestS );
87104
}
88-
if (i % 100 == 0) {
105+
if (i % 500 == 0) {
89106
while (SDL_PollEvent(&event)) {
90107
}
91108
sdl_draw(renderer, reconstructed);
92-
std::cout << "currently at " << i << " 100 gens took " << t.get() <<
109+
std::cout << "currently at " << i << " 500 gens took " << t.get() <<
93110
"\n" << "sad is " << compute_sad(src_images[0].data,
94111
reconstructed.data,
95112
reconstructed.width * reconstructed.height * 4) << "\n";

0 commit comments

Comments
 (0)