[Yade-dev] [svn] r1641 - in trunk: core examples examples/SpheresFactory gui/py lib/import pkg/common pkg/common/Engine/MetaEngine pkg/common/Engine/StandAloneEngine
Author: sega Date: 2009-01-25 15:28:37 +0100 (Sun, 25 Jan 2009) New Revision: 1641 Added: trunk/core/BroadInteractor.cpp trunk/examples/SpheresFactory/ trunk/examples/SpheresFactory/circle.stl trunk/examples/SpheresFactory/model.py trunk/examples/SpheresFactory/plane.stl trunk/examples/SpheresFactory/square.stl trunk/examples/SpheresFactory/yade.stl Modified: trunk/core/BroadInteractor.hpp trunk/core/SConscript trunk/examples/STLImporterTest.py trunk/gui/py/utils.py trunk/gui/py/yadeControl.cpp trunk/lib/import/STLImporter.cpp trunk/lib/import/STLImporter.hpp trunk/pkg/common/Engine/MetaEngine/InteractionGeometryMetaEngine.cpp trunk/pkg/common/Engine/MetaEngine/InteractionGeometryMetaEngine.hpp trunk/pkg/common/Engine/StandAloneEngine/PersistentSAPCollider.cpp trunk/pkg/common/Engine/StandAloneEngine/PersistentSAPCollider.hpp trunk/pkg/common/Engine/StandAloneEngine/SpheresFactory.cpp trunk/pkg/common/Engine/StandAloneEngine/SpheresFactory.hpp trunk/pkg/common/SConscript Log: 1.First worked version of SpheresFactory engine. Example in examples/SpheresFactory 2.Added PersistentSAPCollider::probeBoundingVolume function (for using with SpheresFactory) 3.InteractionGeometryMetaEngine::explicitAction has been modified to remove artifical (as me seems) asserts. 4.python import_stl_geometry now return list of body ids instead only their number. 5.import stl geometry now allows import facets without BoundingVolume and InteractingGeometry. 6.Fixed dynamic_cast for BroadInteractor. Added: trunk/core/BroadInteractor.cpp === --- trunk/core/BroadInteractor.cpp 2009-01-25 04:38:29 UTC (rev 1640) +++ trunk/core/BroadInteractor.cpp 2009-01-25 14:28:37 UTC (rev 1641) @@ -0,0 +1,20 @@ +/* +* Copyright (C) 2004 by Janek Kozicki * +* cosu...@berlios.de* +** +* This program is free software; it is licensed under the terms of the * +* GNU General Public License v2 or later. See file LICENSE for details. * +*/ + +#include BroadInteractor.hpp + +BroadInteractor::BroadInteractor() +{ + +} + +BroadInteractor::~BroadInteractor() +{ + +} + Modified: trunk/core/BroadInteractor.hpp === --- trunk/core/BroadInteractor.hpp 2009-01-25 04:38:29 UTC (rev 1640) +++ trunk/core/BroadInteractor.hpp 2009-01-25 14:28:37 UTC (rev 1641) @@ -15,9 +15,9 @@ class BroadInteractor : public StandAloneEngine { public : - BroadInteractor() {}; - virtual ~BroadInteractor() {}; - virtual bool probeBoundingVolume(const shared_ptrBoundingVolume bv, const Vector3r center){throw;} + BroadInteractor(); + virtual ~BroadInteractor(); + virtual bool probeBoundingVolume(const BoundingVolume){throw;} vectorbody_id_t probedBodies; protected: Modified: trunk/core/SConscript === --- trunk/core/SConscript 2009-01-25 04:38:29 UTC (rev 1640) +++ trunk/core/SConscript 2009-01-25 14:28:37 UTC (rev 1641) @@ -4,6 +4,7 @@ ['Body.cpp', 'BodyContainer.cpp', 'BoundingVolume.cpp', + 'BroadInteractor.cpp', 'DeusExMachina.cpp', 'FileGenerator.cpp', 'FrontEnd.cpp', Modified: trunk/examples/STLImporterTest.py === --- trunk/examples/STLImporterTest.py 2009-01-25 04:38:29 UTC (rev 1640) +++ trunk/examples/STLImporterTest.py 2009-01-25 14:28:37 UTC (rev 1641) @@ -74,7 +74,7 @@ ## Angular acceleration changes angular velocity, resulting in position and/or orientation change of the body. MetaEngine('PhysicalParametersMetaEngine',[EngineUnit('LeapFrogOrientationIntegrator')]), ## Apply kinematics to walls - DeusExMachina('RotationEngine',{'subscribedBodies':range(imported),'rotationAxis':[0,0,1],'rotateAroundZero':True,'angularVelocity':0.5}), + DeusExMachina('RotationEngine',{'subscribedBodies':imported,'rotationAxis':[0,0,1],'rotateAroundZero':True,'angularVelocity':0.5}), ] ## Save the scene to file, so that it can be loaded later. Supported extension are: .xml, .xml.gz, .xml.bz2. Added: trunk/examples/SpheresFactory/circle.stl === (Binary files differ) Property changes on: trunk/examples/SpheresFactory/circle.stl
[Yade-dev] [svn] r1642 - in trunk/pkg/snow: DataClass RenderingEngine
Author: cosurgi Date: 2009-01-25 23:32:18 +0100 (Sun, 25 Jan 2009) New Revision: 1642 Modified: trunk/pkg/snow/DataClass/BshSnowGrain.cpp trunk/pkg/snow/DataClass/BshSnowGrain.hpp trunk/pkg/snow/RenderingEngine/Ef1_BshSnowGrain_glDraw.cpp Log: - added extensive comments to the polyhedron code which will be used for collisions Modified: trunk/pkg/snow/DataClass/BshSnowGrain.cpp === --- trunk/pkg/snow/DataClass/BshSnowGrain.cpp 2009-01-25 14:28:37 UTC (rev 1641) +++ trunk/pkg/snow/DataClass/BshSnowGrain.cpp 2009-01-25 22:32:18 UTC (rev 1642) @@ -183,16 +183,16 @@ // now check if the point (when projected on a plane) is within triangle a,b,c // it could be faster with methods from http://softsurfer.com/Archive/algorithm_0105/algorithm_0105.htm // but I don't understand them, so I prefer to use the method which I derived myself - Vector3r c1((a - b).Cross(d - a)); - Vector3r c2((c - a).Cross(d - c)); - Vector3r c3((b - c).Cross(d - b)); - if(c1.Dot(N) 0 c2.Dot(N) 0 c3.Dot(N) 0) + Vector3r c1((a - b).Cross(d - a)); // since points a,b,c are all clockwise, + Vector3r c2((c - a).Cross(d - c)); // then if I put a point 'd' inside a triangle it will be clockwise + Vector3r c3((b - c).Cross(d - b)); // with each pair of other points, but will be counterclockwise if it's outside + if(c1.Dot(N) 0 c2.Dot(N) 0 c3.Dot(N) 0) // therefore if any of them is counterclockwise, the dot product will be negative return true; } return false; }; -bool BshSnowGrain::is_inside(Vector3r P) +bool BshSnowGrain::is_point_inside_polyhedron(Vector3r P) { const std::vectorboost::tupleVector3r,Vector3r,Vector3r,Vector3r f(get_faces_const_ref()); // loop on all faces @@ -203,24 +203,67 @@ Vector3r b(get1(f[i])); Vector3r c(get2(f[i])); Vector3r N(get3(f[i])); + Real depth = m_depths[i]; Real point_plane_distance = N.Dot(P - c); if( point_plane_distance 0 // point has to be inside - on negative side of the plane - point_plane_distance m_depths[i] ) // and has to be within the depth of this face + point_plane_distance depth ) // and has to be within the depth of this face { if(is_point_orthogonally_projected_on_triangle(a,b,c,N,P,point_plane_distance)) { - // so a point orthogonally projected on triangle is crossing it - // now check if this point is inside a tetrahedron made by this triangle and a point Z at m_depths[i] - Vector3r Z((a+b+c)/3.0 + N*m_depths[i]); - Vector3r N1(-1.0*((a - b).Cross(Z - a))); - Vector3r N2(-1.0*((c - a).Cross(Z - c))); - Vector3r N3(-1.0*((b - c).Cross(Z - b))); - if( - is_point_orthogonally_projected_on_triangle(b,a,Z,N1,P) - is_point_orthogonally_projected_on_triangle(a,c,Z,N2,P) - is_point_orthogonally_projected_on_triangle(c,b,Z,N3,P) - ) + if( point_plane_distance depth*0.5 ) // (1-parallelepiped) + { // that's close enough. We can speed up the computation by returning true at this point + +// therefore in fact, we are checking if point is inside a volume of parallelepiped (1) the height of 1/2 depth +// within the polyhedron PLUS (that's the code below - the (2)) a polyhedron the height given by depth +// like this: +// this weird shape is WHOLE polyhedron +// / Z. \ -- +/// ' ` \ | +// / '2-tetrahedron with the height equal to depth of THIS trangle | +// / ' ` \ | +// / ' ` \ |d +/// ' ` \__ XX face (see description) |e - search below for +// / ' ` / |p 'arbitrary safety coefficient' +// / '.`.. / |t +// \ ' ' 1-parallelepiped
Re: [Yade-dev] polyhedron collisions
Václav S(milauer said: (by the date of Sun, 25 Jan 2009 08:40:40 +0100) Great to hear that. I hope you will also commit a very simple example, like 2 of those bumping into each other. when I get it to work - yes. Something like SDECSpherePlane, but with random polyhedrons. AFAIK the common solution is to cut the shape into parts that are convex, since convex shapes are mathematically easier to handle. I'm not doing that. In fact it also won't work correctly if two polyhedrons have multiple surfaces of contact But I don't care about it now. I used a quite stupid approach of simplifying polyhedron into a list of parallelepipeds made out of each surface-triangle (and a tetrahedron, for more precise collision detection). This allows for quick collision checking - just one dot product and few cross products. See the comments that I have just committed, if you want... There are sophisticated algorithms for detecting triangular surface collisions (see httpo://gts.sf.net for some references). For such complicated shapes, I'm not going this way, it's too complex for me, to understand. And probably slower too. OTOH my solution is not volume-perfect in mathematical sense. though, what folks in Glasgow do (and what I tried with tetraheda) is to treat the intersection as volume, i.e. compute volume and direction in which this volume is the thinnest (that is the direction of repulsive force); I used exact code for that (which is - who knows - maybe incorrect: extra/tetra), Bicanic co in Glasgow get the direction from some averages over normals of planar elements involved in the collision. First I'll try a plane directed directly between centers of both polyhedrons in contact. If it gives stupid results, then I'll try least-squares fitting a plane into a cloud of 3D points, using algorithm directly copied from wildmagic library (LGPL). And is much slower than spheres, so you can forget about simulations with 5000 polyhedrons, anyway. I bet you can forget simulations with 500 polyhedra as well ;-) Do you have some benchmarks on that, BTW? doesn't work yet. So no benchmarks :) -- Janek Kozicki | ___ Mailing list: https://launchpad.net/~yade-dev Post to : yade-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~yade-dev More help : https://help.launchpad.net/ListHelp
[Yade-dev] [svn] r1643 - in trunk/pkg/snow: . DataClass Engine PreProcessor RenderingEngine
Author: cosurgi Date: 2009-01-26 04:34:03 +0100 (Mon, 26 Jan 2009) New Revision: 1643 Added: trunk/pkg/snow/DataClass/IstSnowLayersContact.cpp trunk/pkg/snow/DataClass/IstSnowLayersContact.hpp trunk/pkg/snow/Engine/Ef2_BssSnowGrain_BssSnowGrain_makeIstSnowLayersContact.cpp trunk/pkg/snow/Engine/Ef2_BssSnowGrain_BssSnowGrain_makeIstSnowLayersContact.hpp trunk/pkg/snow/Engine/Ef2_InteractingBox_BssSnowGrain_makeIstSnowLayersContact.cpp trunk/pkg/snow/Engine/Ef2_InteractingBox_BssSnowGrain_makeIstSnowLayersContact.hpp Modified: trunk/pkg/snow/DataClass/BshSnowGrain.cpp trunk/pkg/snow/PreProcessor/SnowVoxelsLoader.cpp trunk/pkg/snow/RenderingEngine/Ef1_BshSnowGrain_glDraw.cpp trunk/pkg/snow/RenderingEngine/Ef1_BssSnowGrain_glDraw.cpp trunk/pkg/snow/RenderingEngine/Ef1_BssSnowGrain_glDraw.hpp trunk/pkg/snow/SConscript Log: small snow update Modified: trunk/pkg/snow/DataClass/BshSnowGrain.cpp === --- trunk/pkg/snow/DataClass/BshSnowGrain.cpp 2009-01-25 22:32:18 UTC (rev 1642) +++ trunk/pkg/snow/DataClass/BshSnowGrain.cpp 2009-01-26 03:34:03 UTC (rev 1643) @@ -213,8 +213,8 @@ if( point_plane_distance depth*0.5 ) // (1-parallelepiped) { // that's close enough. We can speed up the computation by returning true at this point -// therefore in fact, we are checking if point is inside a volume of parallelepiped (1) the height of 1/2 depth -// within the polyhedron PLUS (that's the code below - the (2)) a polyhedron the height given by depth +// therefore in fact, we are checking if point is inside a volume of parallelepiped (1-) the height of 1/2 depth +// within the polyhedron PLUS (that's the code below - the (2-)) a polyhedron the height given by depth // like this: // this weird shape is WHOLE polyhedron // / Z. \ -- @@ -225,9 +225,9 @@ /// ' ` \__ XX face (see description) |e - search below for // / ' ` / |p 'arbitrary safety coefficient' // / '.`.. / |t -// \ ' ' 1-parallelepiped with height equal to 1/2 of depth |h -// \' ' ` '/ | -//\ ' ' ` ' / | +// \ ' ' 1-parallelepiped with height equal to 1/2 of depth |h ('Z' is orthogonal to triangle with +// \' ' ` '/ | 'depth' distance from the +//\ ' ' ` ' / | triangle's center point ) // \ '' ` ' / | // \ ' `' / | // \__/ -- Added: trunk/pkg/snow/DataClass/IstSnowLayersContact.cpp === --- trunk/pkg/snow/DataClass/IstSnowLayersContact.cpp 2009-01-25 22:32:18 UTC (rev 1642) +++ trunk/pkg/snow/DataClass/IstSnowLayersContact.cpp 2009-01-26 03:34:03 UTC (rev 1643) @@ -0,0 +1,15 @@ +#includeyade/pkg-snow/IstSnowLayersContact.hpp + +IstSnowLayersContact::IstSnowLayersContact() +{ + createIndex(); +} + +IstSnowLayersContact::~IstSnowLayersContact() +{} + +void IstSnowLayersContact::registerAttributes() +{ + SpheresContactGeometry::registerAttributes(); +} + Added: trunk/pkg/snow/DataClass/IstSnowLayersContact.hpp === --- trunk/pkg/snow/DataClass/IstSnowLayersContact.hpp 2009-01-25 22:32:18 UTC (rev 1642) +++ trunk/pkg/snow/DataClass/IstSnowLayersContact.hpp 2009-01-26 03:34:03 UTC (rev 1643) @@ -0,0 +1,23 @@ +// 2009 Janek Kozicki cosu...@berlios.de + +#pragma once + +#includeyade/core/InteractionGeometry.hpp +#includeyade/pkg-dem/SpheresContactGeometry.hpp + +class IstSnowLayersContact : public SpheresContactGeometry +{ + public: + IstSnowLayersContact(); + virtual ~IstSnowLayersContact(); + + protected : + virtual void registerAttributes(); + + REGISTER_CLASS_NAME(IstSnowLayersContact); + REGISTER_BASE_CLASS_NAME(SpheresContactGeometry); + REGISTER_CLASS_INDEX(IstSnowLayersContact,SpheresContactGeometry); +}; + +REGISTER_SERIALIZABLE(IstSnowLayersContact); + Added: