yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #02624
[Branch ~yade-dev/yade/trunk] Rev 1885: STLImporter returns a vector imported facets instead of adding them directly
------------------------------------------------------------
revno: 1885
committer: Sergei D. <sega@think>
branch nick: trunk
timestamp: Thu 2009-12-10 18:13:23 +0300
message:
STLImporter returns a vector imported facets instead of adding them directly
utils._commonBodySetup does not reset body id.
modified:
examples/STLImporterTest.py
pkg/dem/PreProcessor/STLImporter.cpp
pkg/dem/PreProcessor/STLImporter.hpp
py/utils.py
py/yadeWrapper/yadeWrapper.cpp
py/ymport.py
--
lp:yade
https://code.launchpad.net/~yade-dev/yade/trunk
Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription.
=== modified file 'examples/STLImporterTest.py'
--- examples/STLImporterTest.py 2009-12-09 17:11:51 +0000
+++ examples/STLImporterTest.py 2009-12-10 15:13:23 +0000
@@ -10,11 +10,10 @@
## Import wall's geometry
params=utils.getViscoelasticFromSpheresInteraction(10e3,tc,en,es)
-print params
facetMat=O.materials.append(SimpleViscoelasticMat(frictionAngle=frictionAngle,**params)) # **params sets kn, cn, ks, cs
sphereMat=O.materials.append(SimpleViscoelasticMat(density=Density,frictionAngle=frictionAngle,**params))
from yade import ymport
-imported = ymport.stl('baraban.stl',material=facetMat)
+fctIds=O.bodies.append(ymport.stl('baraban.stl',color=(1,0,0),material=facetMat))
## Spheres
sphereRadius = 0.2
nbSpheres = (10,10,10)
@@ -57,7 +56,7 @@
## Cundall damping must been disabled!
NewtonIntegrator(damping=0),
## Apply kinematics to walls
- RotationEngine(subscribedBodies=imported,rotationAxis=[0,0,1],rotateAroundZero=True,angularVelocity=0.5)
+ RotationEngine(subscribedBodies=fctIds,rotationAxis=[0,0,1],rotateAroundZero=True,angularVelocity=0.5)
]
from yade import qt
=== modified file 'pkg/dem/PreProcessor/STLImporter.cpp'
--- pkg/dem/PreProcessor/STLImporter.cpp 2009-12-04 23:46:45 +0000
+++ pkg/dem/PreProcessor/STLImporter.cpp 2009-12-10 15:13:23 +0000
@@ -11,42 +11,29 @@
CREATE_LOGGER(STLImporter);
-STLImporter::STLImporter(): number_of_facets(0)
-{
-
-}
-
-bool STLImporter::open(const char* filename)
-{
- vector<double> vtmp, ntmp;
- vector<int> etmp, ftmp;
- STLReader reader;
- reader.tolerance=Math<Real>::ZERO_TOLERANCE;
-
+vector<shared_ptr<Body> > STLImporter::import(const char* filename)
+{
+ vector<Vector3r> tr;
+ vector<shared_ptr<Body> > imported;
+
+ // Load geometry
+ vector<double> vtmp, ntmp; vector<int> etmp, ftmp;
+ STLReader reader; reader.tolerance=Math<Real>::ZERO_TOLERANCE;
if(!reader.open(filename, back_inserter(vtmp), back_inserter(etmp), back_inserter(ftmp), back_inserter(ntmp)))
{
LOG_ERROR("Can't open file: " << filename);
- return false;
+ return imported; // zero size
}
-
for(int i=0,e=ftmp.size(); i<e; ++i)
tr.push_back(Vector3r(vtmp[3*ftmp[i]],vtmp[3*ftmp[i]+1],vtmp[3*ftmp[i]+2]));
- number_of_facets = tr.size()/3;
- LOG_INFO("Open file: " << filename << ": Number of facets: " << number_of_facets);
- return true;
-}
-void STLImporter::import(shared_ptr<BodyContainer> bodies)
-{
+ // Create facets
for(int i=0,e=tr.size(); i<e; i+=3)
{
Vector3r v[3]={tr[i],tr[i+1],tr[i+2]};
-
Vector3r icc = Shop::inscribedCircleCenter(v[0],v[1],v[2]);
-
shared_ptr<InteractingFacet> iFacet(new InteractingFacet);
iFacet->diffuseColor = Vector3r(0.8,0.3,0.3);
-
#ifdef YADE_GEOMETRICALMODEL
shared_ptr<Facet> gFacet(new Facet);
gFacet->diffuseColor = Vector3r(0.5,0.5,0.5);
@@ -54,7 +41,6 @@
gFacet->shadowCaster = true;
(*bodies)[b_id]->geometricalModel = gFacet;
#endif
-
for (int j=0; j<3; ++j)
{
iFacet->vertices.push_back(v[j]-icc);
@@ -62,13 +48,13 @@
gFacet->vertices.push_back(v[j]-icc);
#endif
}
- //iFacet->postProcessAttributes(true);
- //postProcessAttributes is protected
-
+ //iFacet->postProcessAttributes(true); //postProcessAttributes is protected
shared_ptr<Body> b(new Body());
- b->state->pos=icc;
- b->state->ori=Quaternionr::IDENTITY;
+ b->state->pos=b->state->refPos=icc;
+ b->state->ori=b->state->refOri=Quaternionr::IDENTITY;
b->shape = iFacet;
- bodies->insert(b);
+ imported.push_back(b);
}
+ return imported;
}
+
=== modified file 'pkg/dem/PreProcessor/STLImporter.hpp'
--- pkg/dem/PreProcessor/STLImporter.hpp 2009-12-04 23:07:34 +0000
+++ pkg/dem/PreProcessor/STLImporter.hpp 2009-12-10 15:13:23 +0000
@@ -16,19 +16,7 @@
class STLImporter {
public:
- STLImporter();
-
- /// open file
- bool open(const char* filename);
-
- /// number of facets
- unsigned int number_of_facets;
-
- /// import geometry
- void import(shared_ptr<BodyContainer> bodies);
-
+ vector<shared_ptr<Body> > import(const char*);
DECLARE_LOGGER;
-protected:
- vector<Vector3r> tr;
};
=== modified file 'py/utils.py'
--- py/utils.py 2009-12-09 15:38:28 +0000
+++ py/utils.py 2009-12-10 15:13:23 +0000
@@ -88,7 +88,6 @@
if resetState: b.state=b.mat.newAssocState()
mass=volume*b.mat['density']
b.state['mass'],b.state['inertia']=mass,geomInertia*b.mat['density']
- b['id']=-1
if not noBound: b.bound=Bound('AABB',diffuseColor=[0,1,0])
def sphere(center,radius,dynamic=True,wire=False,color=None,highlight=False,material=0):
=== modified file 'py/yadeWrapper/yadeWrapper.cpp'
--- py/yadeWrapper/yadeWrapper.cpp 2009-12-09 17:11:51 +0000
+++ py/yadeWrapper/yadeWrapper.cpp 2009-12-10 15:13:23 +0000
@@ -548,10 +548,7 @@
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(omega_loadTmp_overloads,loadTmp,0,1);
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(omega_exitNoBacktrace_overloads,exitNoBacktrace,0,1);
-class pySTLImporter : public STLImporter {
- public:
- void py_import(pyBodyContainer bc) { import(bc.proxee); }
-};
+class pySTLImporter : public STLImporter {};
/*****************************************************************************
@@ -793,9 +790,7 @@
.def("__len__",&pyMaterialContainer::len);
python::class_<pySTLImporter>("STLImporter")
- .def("open",&pySTLImporter::open)
- .add_property("number_of_facets",&pySTLImporter::number_of_facets)
- .def("import_geometry",&pySTLImporter::py_import);
+ .def("ymport",&pySTLImporter::import);
//////////////////////////////////////////////////////////////
///////////// proxyless wrappers
=== modified file 'py/ymport.py'
--- py/ymport.py 2009-12-10 12:02:39 +0000
+++ py/ymport.py 2009-12-10 15:13:23 +0000
@@ -30,19 +30,15 @@
def stl(file, dynamic=False,wire=True,color=None,highlight=False,noBound=False,material=0):
""" Import geometry from stl file, create facets and return list of their ids."""
imp = STLImporter()
- imp.open(file)
- begin=len(O.bodies)
- imp.import_geometry(O.bodies)
- imported=range(begin,begin+imp.number_of_facets)
- for i in imported:
- b=O.bodies[i]
+ facets=imp.ymport(file)
+ for b in facets:
b['isDynamic']=dynamic
- b.mold.postProcessAttributes(True)
- b.mold['diffuseColor']=color if color else utils.randomColor()
- b.mold['wire']=wire
- b.mold['highlight']=highlight
+ b.shape.postProcessAttributes(True)
+ b.shape['diffuseColor']=color if color else utils.randomColor()
+ b.shape['wire']=wire
+ b.shape['highlight']=highlight
utils._commonBodySetup(b,0,Vector3(0,0,0),noBound=noBound,material=material,resetState=False)
- return imported
+ return facets
def gmsh(meshfile="file.mesh",shift=[0.0,0.0,0.0],scale=1.0,**kw):
""" Imports geometry from mesh file and creates facets.