1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/ |
---|
2 | // Copyright (C) 1999-2015 Maciej Komosinski and Szymon Ulatowski. |
---|
3 | // See LICENSE.txt for details. |
---|
4 | |
---|
5 | #include "nn_layout.h" |
---|
6 | #include "common/nonstd_math.h" |
---|
7 | #include <stdlib.h> |
---|
8 | |
---|
9 | static void randomlayout(NNLayoutState*); |
---|
10 | static void arraylayout(NNLayoutState*); |
---|
11 | |
---|
12 | extern void smartlayout(NNLayoutState*); |
---|
13 | |
---|
14 | struct NNLayoutFunction nn_layout_functions[] = |
---|
15 | { |
---|
16 | { "Random", randomlayout, }, |
---|
17 | { "Dumb array", arraylayout, }, |
---|
18 | { "Smart", smartlayout, }, |
---|
19 | { 0, } |
---|
20 | }; |
---|
21 | |
---|
22 | static void randomlayout(NNLayoutState*nn) |
---|
23 | { |
---|
24 | int i; |
---|
25 | int N = nn->GetElements(); |
---|
26 | for (i = 0; i < N; i++) |
---|
27 | { |
---|
28 | nn->SetXYWH(i, (int)rnd0N(300), (int)rnd0N(300), 50, 50); |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | static void arraylayout(NNLayoutState*nn) |
---|
33 | { |
---|
34 | int e = 0, i, j; |
---|
35 | int N = nn->GetElements(); |
---|
36 | int a = ((int)(sqrt(double(N)) - 0.0001)) + 1; |
---|
37 | for (j = 0; j < a; j++) |
---|
38 | for (i = 0; i < a; i++) |
---|
39 | { |
---|
40 | if (e >= N) return; |
---|
41 | nn->SetXYWH(e, 70 * i + ((i + j) & 3) * 4, 70 * j + ((2 + i + j) & 3) * 4, 50, 50); |
---|
42 | e++; |
---|
43 | } |
---|
44 | } |
---|