Changeset 269


Ignore:
Timestamp:
12/16/14 01:51:06 (10 years ago)
Author:
Maciej Komosinski
Message:
  • Model validation checks part/joint shapes for consistency (old/new)
  • Model::getShape() returns new/old style
  • Model shape conversion (old to new) and sample usage in shapeconvert.cpp
Location:
cpp/frams
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/Makefile-GDK

    r247 r269  
    55include frams/Makefile-GDK-files
    66
    7 GDK_TESTS=genoconv_test gdk_test geno_test genooper_test genooper_test_fTest neuro_test loader_test serial_test multiline_f0_test f0_variants_test full_props part_shapes neuro_layout_test geometry_apices_test geometry_info_test geometry_surface_test geometry_volume_test
     7GDK_TESTS=genoconv_test gdk_test geno_test genooper_test genooper_test_fTest neuro_test loader_test serial_test multiline_f0_test f0_variants_test full_props shapeconvert part_shapes neuro_layout_test geometry_apices_test geometry_info_test geometry_surface_test geometry_volume_test
    88
    99gdk_tests: $(GDK_TESTS)
    1010
    1111GDK_BUILD_CONFIG= -include frams/config/gdk_build_config.h
    12 CXXFLAGS= -I$(CURDIR) -DLINUX $(GDK_BUILD_CONFIG) -Wno-parentheses -Wno-overloaded-virtual -Wno-format -g
     12CXXFLAGS= -I$(CURDIR) -std=gnu++11 -DLINUX $(GDK_BUILD_CONFIG) -Wno-parentheses -Wno-overloaded-virtual -Wno-format -g
    1313
    1414#############################################
     
    4747        $(CXX) $(FULL_PROPS_OBJS) $(LDFLAGS) -o $@
    4848
     49shapeconvert: $(SHAPECONVERT_OBJS)
     50        $(CXX) $(SHAPECONVERT_OBJS) $(LDFLAGS) -o $@
     51
    4952part_shapes: $(PART_SHAPES_OBJS)
    5053        $(CXX) $(PART_SHAPES_OBJS) $(LDFLAGS) -o $@
  • cpp/frams/Makefile-GDK-files

    r247 r269  
    4747FULL_PROPS_OBJS= frams/_demos/full_props.o frams/errmgr/stdouterr.o frams/virtfile/virtfile.o  frams/virtfile/stdiofile.o $(GDK_OBJS) $(GENOCONV_GDK_OBJS) $(GENMAN_GDK_OBJS)
    4848
     49SHAPECONVERT_OBJS= frams/_demos/shapeconvert.o frams/errmgr/stdouterr.o frams/virtfile/virtfile.o  frams/virtfile/stdiofile.o $(GDK_OBJS) $(GENOCONV_GDK_OBJS) $(GENMAN_GDK_OBJS)
     50
    4951SERIAL_TEST_OBJS= frams/_demos/serial_test.o frams/virtfile/virtfile.o  $(GDK_OBJS) $(GENOCONV_GDK_OBJS)
    5052
  • cpp/frams/model/model.cpp

    r247 r269  
    2929f0map=0;
    3030f0genoknown=1;
     31shape=SHAPE_UNKNOWN;
    3132}
    3233
     
    874875int i,k;
    875876int ret=1;
     877shape=SHAPE_UNKNOWN;
    876878if ((parts.size()==0)&&(neurons.size()==0)) return 0;
    877879if (parts.size()==0)
     
    903905        if (p->p.y+p->size > bbmax.y) bbmax.y=p->p.y+p->size;
    904906        if (p->p.z+p->size > bbmax.z) bbmax.z=p->p.z+p->size;
     907        if (shape==SHAPE_UNKNOWN)
     908                shape=(p->shape==Part::SHAPE_DEFAULT)?SHAPE_OLD:SHAPE_NEW;
     909        else if (shape!=SHAPE_ILLEGAL)
     910                {
     911                if ((p->shape==Part::SHAPE_DEFAULT) ^ (shape==SHAPE_OLD))
     912                        {
     913                        shape=SHAPE_ILLEGAL;
     914                        FMprintf("Model","internalCheck",FMLV_WARN,"Inconsistent part shapes (mixed old and new shapes)");
     915                        }
     916                }
    905917        }
    906918size=bbmax-bbmin;
     
    983995                         i,(const char*)geno.getName());
    984996                ret=0;
     997                }
     998        if (shape!=SHAPE_ILLEGAL)
     999                {
     1000                if ((j->shape==Joint::SHAPE_DEFAULT) ^ (shape==SHAPE_OLD))
     1001                        {
     1002                        shape==SHAPE_ILLEGAL;
     1003                        FMprintf("Model","internalCheck",FMLV_WARN,"Inconsistent joint shapes (mixed old and new shapes)");
     1004                        }
    9851005                }
    9861006        }
     
    10821102                }
    10831103        }
     1104if (shape==SHAPE_ILLEGAL)
     1105        ret=0;
    10841106return ret;
    10851107}
     
    12581280        tmpp-=j->part1->p;
    12591281        j->d=j->part2->o.revTransform(tmpp);
     1282        }
     1283}
     1284
     1285void Model::buildUsingNewShapes(const Model& old, Part::Shape default_shape, float thickness)
     1286{
     1287for(int i=0;i<old.getJointCount();i++)
     1288        {
     1289        Joint *oj=old.getJoint(i);
     1290        Part *p = addNewPart(default_shape);
     1291        p->p=(oj->part1->p+oj->part2->p)/2;
     1292        Orient o;
     1293        o.lookAt(oj->part1->p-oj->part2->p);
     1294        p->rot=o.getAngles();
     1295        p->scale.x=oj->part1->p.distanceTo(oj->part2->p)/2;
     1296        p->scale.y = thickness;
     1297        p->scale.z = thickness;
     1298        }
     1299for(int i=0;i<old.getPartCount();i++)
     1300        {
     1301        Part *op=old.getPart(i);
     1302        for(int j=0;j<old.getJointCount();j++)
     1303                {
     1304                Joint *oj=old.getJoint(j);
     1305                if ((oj->part1==op)||(oj->part2==op))
     1306                        {
     1307                        for(int j2=j+1;j2<old.getJointCount();j2++)
     1308                                {
     1309                                Joint *oj2=old.getJoint(j2);
     1310                                if ((oj2->part1==op)||(oj2->part2==op))
     1311                                        {
     1312                                        Joint *newj=addNewJoint(getPart(j),getPart(j2),Joint::SHAPE_SOLID);
     1313                                        }
     1314                                }
     1315                        break;
     1316                        }
     1317                }
    12601318        }
    12611319}
  • cpp/frams/model/model.h

    r258 r269  
    117117
    118118int checklevel;
     119
     120  public:
     121enum Shape {SHAPE_UNKNOWN,SHAPE_ILLEGAL,SHAPE_OLD,SHAPE_NEW};
     122  protected:
     123Shape shape;
    119124
    120125void updateNeuroRefno(); // set Neuro::refno for all neurons
     
    150155int isValid() const {return buildstatus==valid;}
    151156int getErrorPosition(bool includingwarnings=false);
     157Shape getShape() {return shape;}
    152158
    153159void updateRefno(); // set ::refno for all elements
     
    387393
    388394void disturb(double amount);
     395
     396void buildUsingNewShapes(const Model& src_old_shapes, Part::Shape default_shape = Part::SHAPE_CYLINDER, float thickness = 0.2);
    389397
    390398#ifdef EASYMAPDEBUG
  • cpp/frams/model/modelparts.h

    r247 r269  
    7070static SString getDefaultStyle();
    7171Part(double _mass,double _size,double _density,double _friction,double _ingest,double _assim)
    72         :PartBase(getDefaultStyle()),mass(_mass),size(_size),density(_density),friction(_friction),ingest(_ingest),assim(_assim)
     72          :PartBase(getDefaultStyle()),mass(_mass),size(_size),density(_density),friction(_friction),ingest(_ingest),assim(_assim)
    7373        {}
    7474void defassign();
     
    8686paInt shape;///default=old framsticks compatible, do not mix with shapes>0
    8787enum Shape {SHAPE_DEFAULT=0, SHAPE_ELLIPSOID=1, SHAPE_CUBOID=2, SHAPE_CYLINDER=3};
    88 double mass,size,density,friction,ingest,assim;
     88double mass,size,density,friction,ingest,assim,hollow;
    8989Pt3D scale;
    9090Pt3D food;
Note: See TracChangeset for help on using the changeset viewer.