[526] | 1 | // This file is a part of Framsticks SDK. http://www.framsticks.com/
|
---|
[972] | 2 | // Copyright (C) 1999-2020 Maciej Komosinski and Szymon Ulatowski.
|
---|
[526] | 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 |
|
---|
| 33 | int 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])
|
---|
[972] | 48 | {
|
---|
[526] | 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;
|
---|
[972] | 58 | }
|
---|
[526] | 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);
|
---|
[972] | 69 | Model m(g, Model::SHAPE_UNKNOWN);
|
---|
[526] | 70 |
|
---|
| 71 | if (!m.isValid())
|
---|
| 72 | {
|
---|
| 73 | logPrintf("", "shapeconvert", LOG_ERROR, "Cannot build Model from the supplied genotype");
|
---|
| 74 | return 2;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[544] | 77 | if (m.getShapeType() != Model::SHAPE_BALL_AND_STICK)
|
---|
[526] | 78 | {
|
---|
[544] | 79 | logPrintf("", "shapeconvert", LOG_ERROR, "Only ball-and-stick models can be converted");
|
---|
[526] | 80 | return 3;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | Model newmodel;
|
---|
| 84 | newmodel.open();
|
---|
[546] | 85 | newmodel.buildUsingSolidShapeTypes(m, shape, thickness);
|
---|
[526] | 86 | newmodel.close();
|
---|
| 87 |
|
---|
| 88 | Geno f0_g = newmodel.getF0Geno();
|
---|
[534] | 89 | puts(f0_g.getGenesAndFormat().c_str());
|
---|
[526] | 90 |
|
---|
| 91 | return 0;
|
---|
| 92 | }
|
---|