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 "printconvmap.h" |
---|
6 | #include <stdio.h> |
---|
7 | #include <frams/util/multimap.h> |
---|
8 | |
---|
9 | #define GEN1MAX 15 |
---|
10 | |
---|
11 | void printN(const char* t,int maxlen) |
---|
12 | { |
---|
13 | while(maxlen-- > 0) |
---|
14 | if (*t) putchar(*(t++)); |
---|
15 | else putchar(' '); |
---|
16 | } |
---|
17 | |
---|
18 | void printN(char t,int maxlen) |
---|
19 | { |
---|
20 | while(maxlen-- > 0) putchar(t); |
---|
21 | } |
---|
22 | |
---|
23 | void printmapping(const char* gen1, int len1,const MultiRange &mr,const char* gen2,int len2) |
---|
24 | { |
---|
25 | printN(' ',GEN1MAX-len1); |
---|
26 | printN(gen1,len1); |
---|
27 | printf(" : "); |
---|
28 | int i; |
---|
29 | for(i=0;i<len2;i++) |
---|
30 | if (mr.contains(i)) |
---|
31 | putchar(gen2[i]); |
---|
32 | else |
---|
33 | putchar('.'); |
---|
34 | putchar('\n'); |
---|
35 | } |
---|
36 | |
---|
37 | void stripstring(SString &str) |
---|
38 | { |
---|
39 | char *t=str.directWrite(); |
---|
40 | for(;*t;t++) |
---|
41 | if (strchr("\n\r\t",*t)) *t=' '; |
---|
42 | } |
---|
43 | |
---|
44 | void printConvMap(const SString& gen1,const SString& gen2,const MultiMap& map) |
---|
45 | { |
---|
46 | int y,y2,len1; |
---|
47 | int id=0; |
---|
48 | if (map.isEmpty()) |
---|
49 | { |
---|
50 | printf("{ empty }\n"); |
---|
51 | return; |
---|
52 | } |
---|
53 | len1=gen1.len(); |
---|
54 | SString g1=gen1; |
---|
55 | stripstring(g1); |
---|
56 | SString g2=gen2; |
---|
57 | stripstring(g2); |
---|
58 | const char* g=g1; |
---|
59 | y=0; |
---|
60 | MultiRange *mr; |
---|
61 | MultiRange emptyrange; |
---|
62 | printN(' ',GEN1MAX); |
---|
63 | printf(" %s\n",(const char*)g2); |
---|
64 | int begin=map.getBegin(); |
---|
65 | int end=map.getEnd(); |
---|
66 | while(y<len1) |
---|
67 | { |
---|
68 | if (y<begin) |
---|
69 | { |
---|
70 | mr=&emptyrange; |
---|
71 | y2=begin; |
---|
72 | } |
---|
73 | else if (y>end) |
---|
74 | { |
---|
75 | mr=&emptyrange; |
---|
76 | y2=len1; |
---|
77 | } |
---|
78 | else { |
---|
79 | id=map.findMappingId(y); |
---|
80 | mr=&map.getMapping(id)->to; |
---|
81 | y2=map.getMapping(id+1)->begin; |
---|
82 | } |
---|
83 | if ((y2-y) > GEN1MAX) y2=y+GEN1MAX; |
---|
84 | if (y2>(y+len1)) y2=y+len1; |
---|
85 | printmapping(g+y,y2-y,*mr,g2,g2.len()); |
---|
86 | y=y2; |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | void printModelMap(const SString& gen1,const MultiMap& map) |
---|
91 | { |
---|
92 | SString g2("012345678901234567890123456789"); |
---|
93 | printN(' ',GEN1MAX); |
---|
94 | printf(" Parts Joints Neurons\n"); |
---|
95 | printConvMap(gen1,g2,map); |
---|
96 | } |
---|