Last change
on this file since 135 was
135,
checked in by sz, 10 years ago
|
neuron layout algorithm (for schematic drawing), usage example in frams/_demos/neuro_layout_test.cpp
|
-
Property svn:eol-style set to
native
|
File size:
847 bytes
|
Rev | Line | |
---|
[135] | 1 | #include "nn_layout.h" |
---|
| 2 | #include "common/nonstd_math.h" |
---|
| 3 | #include <stdlib.h> |
---|
| 4 | |
---|
| 5 | static void randomlayout(NNLayoutState*); |
---|
| 6 | static void arraylayout(NNLayoutState*); |
---|
| 7 | |
---|
| 8 | extern void smartlayout(NNLayoutState*); |
---|
| 9 | |
---|
| 10 | struct NNLayoutFunction nn_layout_functions[] = |
---|
| 11 | { |
---|
| 12 | { "Random", randomlayout, }, |
---|
| 13 | { "Dumb array", arraylayout, }, |
---|
| 14 | { "Smart", smartlayout, }, |
---|
| 15 | { 0, } |
---|
| 16 | }; |
---|
| 17 | |
---|
| 18 | static void randomlayout(NNLayoutState*nn) |
---|
| 19 | { |
---|
| 20 | int i; |
---|
| 21 | int N = nn->GetElements(); |
---|
| 22 | for (i = 0; i < N; i++) |
---|
| 23 | { |
---|
| 24 | nn->SetXYWH(i, (int)rnd0N(300), (int)rnd0N(300), 50, 50); |
---|
| 25 | } |
---|
| 26 | } |
---|
| 27 | |
---|
| 28 | static void arraylayout(NNLayoutState*nn) |
---|
| 29 | { |
---|
| 30 | int e = 0, i, j; |
---|
| 31 | int N = nn->GetElements(); |
---|
| 32 | int a = ((int)(sqrt(double(N)) - 0.0001)) + 1; |
---|
| 33 | for (j = 0; j < a; j++) |
---|
| 34 | for (i = 0; i < a; i++) |
---|
| 35 | { |
---|
| 36 | if (e >= N) return; |
---|
| 37 | nn->SetXYWH(e, 70 * i + ((i + j) & 3) * 4, 70 * j + ((2 + i + j) & 3) * 4, 50, 50); |
---|
| 38 | e++; |
---|
| 39 | } |
---|
| 40 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.