source: cpp/frams/_demos/printconvmap.cpp @ 292

Last change on this file since 292 was 286, checked in by Maciej Komosinski, 10 years ago

Updated headers

  • Property svn:eol-style set to native
File size: 1.7 KB
Line 
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
11void printN(const char* t,int maxlen)
12{
13while(maxlen-- > 0)
14        if (*t) putchar(*(t++));
15        else putchar(' ');
16}
17
18void printN(char t,int maxlen)
19{
20while(maxlen-- > 0) putchar(t);
21}
22
23void printmapping(const char* gen1, int len1,const MultiRange &mr,const char* gen2,int len2)
24{
25printN(' ',GEN1MAX-len1);
26printN(gen1,len1);
27printf(" : ");
28int i;
29for(i=0;i<len2;i++)
30        if (mr.contains(i))
31                putchar(gen2[i]);
32        else
33                putchar('.');
34putchar('\n');
35}
36
37void stripstring(SString &str)
38{
39char *t=str.directWrite();
40for(;*t;t++)
41        if (strchr("\n\r\t",*t)) *t=' ';
42}
43
44void printConvMap(const SString& gen1,const SString& gen2,const MultiMap& map)
45{
46int y,y2,len1;
47int id=0;
48if (map.isEmpty())
49        {
50        printf("{ empty }\n");
51        return;
52        }
53len1=gen1.len();
54SString g1=gen1;
55stripstring(g1);
56SString g2=gen2;
57stripstring(g2);
58const char* g=g1;
59y=0;
60MultiRange *mr;
61MultiRange emptyrange;
62printN(' ',GEN1MAX);
63printf("   %s\n",(const char*)g2);
64int begin=map.getBegin();
65int end=map.getEnd();
66while(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
90void printModelMap(const SString& gen1,const MultiMap& map)
91{
92SString g2("012345678901234567890123456789");
93printN(' ',GEN1MAX);
94printf("   Parts     Joints    Neurons\n");
95printConvMap(gen1,g2,map);
96}
Note: See TracBrowser for help on using the repository browser.