source: cpp/frams/model/geometry/modelgeoclass.cpp @ 239

Last change on this file since 239 was 235, checked in by sz, 10 years ago

Framscript interface class for Model geometry calculation

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1#include "modelgeoclass.h"
2#include "modelgeometryinfo.h"
3#include <frams/vm/classes/collectionobj.h>
4#include <frams/vm/classes/3dobject.h>
5
6#define FIELDSTRUCT ModelGeometry
7static ParamEntry modelgeo_paramtab[]=
8{
9 {"Creature: Geometry",1,5,"ModelGeometry",
10  "Example usage:\n"
11  "Simulator.print(ModelGeometry.forModel(Model.newFromString(\"//0\\np:sh=1\\n\")).area());\n"
12  "ModelGeometry.geodensity refers to the global simulator parameter (also available in GUI).\n"
13  "Local geodensity of individual ModelGeometry objects can also be changed, like this:\n"
14  "var mg=ModelGeometry.forModel(GenePools[0][0].getModel()); mg.geodensity=2; GenePools[0][0].user1=mg.area();\n"},
15 {"geodensity",0,0,"Density","f 0.01 100.0 1.0",FIELD(density),"Affects the geometry calculation precision"}, //note: geodensity instead of density to make the name more unique - because of the unfortunate sim_params merging all configuration fields in a single namespace
16{"forModel",0,PARAM_USERHIDDEN,"","p oModelGeometry(oModel)",PROCEDURE(p_formodel),"The returned ModelGeometry object can be used to calculate geometric properties of the associated model (volume, area, sizes). The density is copied from the current global ModelGeometry.geodensity on object creation."},
17{"volume",0,PARAM_NOSTATIC|PARAM_USERHIDDEN,"volume","p f()",PROCEDURE(p_volume),},
18{"area",0,PARAM_NOSTATIC|PARAM_USERHIDDEN,"area","p f()",PROCEDURE(p_area),},
19{"sizesAndAxes",0,PARAM_NOSTATIC|PARAM_USERHIDDEN,"sizesAndAxes","p oVector()",PROCEDURE(p_sizesandaxes),"The returned vector contains XYZ (sizes) and Orient (axes) objects."},
20
21{0,0,0,},
22};
23#undef FIELDSTRUCT
24
25ExtObject ModelGeometry::makeDynamicObject(ModelGeometry* mg)
26{return ExtObject(&mg->par,mg);}
27
28ModelGeometry::ModelGeometry(ModelObj *mo)
29        :par(modelgeo_paramtab,this)
30{
31model=mo;
32if (model!=NULL)
33        model->incref();
34}
35
36ModelGeometry::~ModelGeometry()
37{
38if (model!=NULL)
39        model->decref();
40}
41
42void ModelGeometry::p_formodel(ExtValue *args,ExtValue *ret)
43{
44Model *m=ModelObj::fromObject(*args);
45if (m!=NULL)
46        {
47        ModelGeometry *mg=new ModelGeometry((ModelObj*)m);
48        mg->density=density;
49        ret->setObject(ModelGeometry::makeDynamicObject(mg));
50        }
51else
52        ret->setEmpty();
53}
54
55void ModelGeometry::p_volume(ExtValue *args,ExtValue *ret)
56{
57ret->setDouble(ModelGeometryInfo::volume(*model,density));
58}
59
60void ModelGeometry::p_area(ExtValue *args,ExtValue *ret)
61{
62ret->setDouble(ModelGeometryInfo::area(*model,density));
63}
64
65void ModelGeometry::p_sizesandaxes(ExtValue *args,ExtValue *ret)
66{
67Pt3D sizes; Orient axes;
68ModelGeometryInfo::findSizesAndAxesOfModel(*model,density,sizes,axes);
69VectorObject* n=new VectorObject;
70n->data+=new ExtValue(Pt3D_Ext::makeDynamicObject(sizes));
71n->data+=new ExtValue(Orient_Ext::makeDynamicObject(new Orient_Ext(axes)));
72ret->setObject(n->makeObject());
73}
Note: See TracBrowser for help on using the repository browser.