source: cpp/frams/_demos/shapeconvert.cpp @ 411

Last change on this file since 411 was 391, checked in by sz, 10 years ago

Moved frams/loggers to common/loggers

File size: 2.4 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 <stdlib.h>
6#include <stdio.h>
7#include <time.h>
8#include <common/virtfile/stdiofile.h>
9
10#include <frams/model/model.h>
11#include <common/loggers/loggertostdout.h>
12#include <frams/genetics/preconfigured.h>
13
14/**
15 @file
16 Sample code: Convert old-style shapes (sticks are Joints) to new style (sticks are Parts)
17 Usage: shapeconvert [-sSHAPE] [-tTHICKNESS] [genotype_or_stdin]
18
19 Calling examples:
20
21 # convert any genotype to f0 using new-style shapes:
22 shapeconvert "X"
23
24 //0
25 m:
26 p:0.5, sh=3, sx=0.5, sy=0.200000002980232, sz=0.200000002980232, rx=-1.5707963267949, rz=3.14159265358979
27
28 # load a genotype from file, convert to new shapes, display:
29 loader_test data/other.gen "Bird" | shapeconvert -s1 - | theater.exe -g -
30
31 */
32
33int main(int argc, char*argv[])
34{
35        StdioFILE::setStdio();//setup VirtFILE::Vstdin/out/err
36        LoggerToStdout messages_to_stderr(LoggerBase::Enable | LoggerBase::DontBlock, VirtFILE::Vstderr); //errors -> stderr, don't interfere with stdout
37
38        PreconfiguredGenetics genetics;
39        Part::Shape shape = Part::SHAPE_CYLINDER;
40        float thickness = 0.2;
41
42        char* gen_arg = 0;
43        for (int i = 1; i < argc; i++)
44        {
45                char* ar = argv[i];
46                if (ar[0] == '-')
47                        switch (ar[1])
48                {
49                        case 's': shape = (Part::Shape)atol(ar + 2);
50                                if ((shape != Part::SHAPE_ELLIPSOID) && (shape != Part::SHAPE_CUBOID) && (shape != Part::SHAPE_CYLINDER))
51                                {
52                                        logPrintf("", "shapeconvert", LOG_ERROR, "Invalid shape");
53                                        return 4;
54                                }
55                                break;
56                        case 't': thickness = atof(ar + 2); break;
57                        case 'h': puts("Usage: shapeconvert [-sSHAPE] [-tTHICKNESS] [genotype_or_stdin]\n\tSHAPE: 1=ellipsoid, 2=cuboid, 3(default)=cylinder\n\tTHICKNESS: used for Part.sy/sz (default=0.2)"); break;
58                }
59                else
60                        if (!gen_arg)
61                                gen_arg = ar;
62        }
63        SString gen;
64        if (gen_arg)
65                gen = gen_arg;
66        else
67                loadSString(VirtFILE::Vstdin, gen);
68        Geno g(gen);
69        Model m(g);
70
71        if (!m.isValid())
72        {
73                logPrintf("", "shapeconvert", LOG_ERROR, "Cannot build Model from the supplied genotype");
74                return 2;
75        }
76
77        if (m.getShape() != Model::SHAPE_OLD)
78        {
79                logPrintf("", "shapeconvert", LOG_ERROR, "Only old style shapes can be converted");
80                return 3;
81        }
82
83        Model newmodel;
84        newmodel.open();
85        newmodel.buildUsingNewShapes(m, shape, thickness);
86        newmodel.close();
87
88        Geno f0_g = newmodel.getF0Geno();
89        puts(f0_g.toString().c_str());
90
91        return 0;
92}
Note: See TracBrowser for help on using the repository browser.