Help: pure collision detection on large number of spheres

Post Reply
linksan
Posts: 13
Joined: Fri May 23, 2008 4:30 pm

Help: pure collision detection on large number of spheres

Post by linksan »

My program loads data for 30000 spheres (x_data, y_data, z_data, r_data) creates and adds the sphere objects into the btCollisionWorld and then performs collision. detection

Relevant Code:

Code: Select all

	btVector3	worldAabbMin(-1000,-1000,-1000);
	btVector3	worldAabbMax(1000,1000,1000);

	collisionConfiguration = new btDefaultCollisionConfiguration();
	dispatcher = new	btCollisionDispatcher(collisionConfiguration);
	broadphase = new bt32BitAxisSweep3(worldAabbMin,worldAabbMax,num_Bodies);

	collisionWorld = new btCollisionWorld(dispatcher,broadphase,collisionConfiguration);

	btMatrix3x3 basisTemp;
	basisTemp.setIdentity();

	for(int i=0; i<num_Bodies; ++i){
		btSphereShape *sphereTemp=new btSphereShape(r_data[i]);
		objects[i].getWorldTransform().setBasis(basisTemp);
		objects[i].setCollisionShape(sphereTemp);
		objects[i].getWorldTransform().setOrigin(btVector3(x_data[i],y_data[i],z_data[i]));
		collisionWorld->addCollisionObject(&objects[i]);
	}

if (collisionWorld){
		collisionWorld->performDiscreteCollisionDetection();}

Adding the objects takes ~150 mb of memory, once collisionWorld->performDiscreteCollisionDetection(); runs memory usage goes up to ~2GB and the program terminates automatically without an error message.

If I debug, the debugger says that it encountered an error at btCollisionDispatcher::getNewManifold(void * b0=0x00971390, void * b1=0x00000000)

Am I doing something wrong? I know that bullet can handle more spheres than this. I would like to move up to a million spheres.
Is there a better way to set up the simulation?

Thanks in advance.
linksan
Posts: 13
Joined: Fri May 23, 2008 4:30 pm

Re: Help: pure collision detection on large number of spheres

Post by linksan »

Any ideas?

I have tried increasing the m_defaultMaxCollisionAlgorithmPoolSize and m_defaultMaxPersistentManifoldPoolSize to 10 times the number of objects but it hasn't helped.

Any help would be appreciated.

Thanks.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Help: pure collision detection on large number of spheres

Post by Erwin Coumans »

Are you using the latest version of Bullet? Can you try the btDbvtBroadphase instead?

Otherwise, can you share the dataset/program so we can check it out? This forum supports zipped attachments.

Thanks,
Erwin
linksan
Posts: 13
Joined: Fri May 23, 2008 4:30 pm

Re: Help: pure collision detection on large number of spheres

Post by linksan »

I'm using Bullet 2.71

I tried btDbvtBroadphase and it added the collision objects to the collision world faster but still automatically terminated.

I attached a zip with the code, collision detection .exe and data generator .exe
The generated data, even zipped was too big to attach.

Run "DataGen.exe" type data.dat hit enter and type 30000 and hit enter. A file data.dat should appear with the data
Run "Collision.exe" and type "data.dat" and hit enter. This code uses btDbvtBroadphase.

let me know if it doesn't open or run.

Thank you.
Attachments
Collision.zip
(52.96 KiB) Downloaded 220 times
linksan
Posts: 13
Joined: Fri May 23, 2008 4:30 pm

Re: Help: pure collision detection on large number of spheres

Post by linksan »

To see what makes the program terminate I copied what collisionWorld does when performDiscreteCollisionDetection() is called
I changed:

Code: Select all

	if (collisionWorld)
	{
	collisionWorld->performDiscreteCollisionDetection();
	}
To:

Code: Select all

btDispatcher* dispatcher1;
btDispatcherInfo	dispatchInfo;
	if (collisionWorld)
	{
		
		collisionWorld->updateAabbs();
		collisionWorld->getBroadphase()->calculateOverlappingPairs(dispatcher);
		dispatcher->dispatchAllCollisionPairs(broadphase->getOverlappingPairCache(),dispatchInfo,dispatcher1);

		//collisionWorld->performDiscreteCollisionDetection();
	}
The first two commands:

collisionWorld->updateAabbs();
collisionWorld->getBroadphase()->calculateOverlappingPairs(dispatcher);
work fine but when dispatcher->dispatchAllCollisionPairs(broadphase->getOverlappingPairCache(),dispatchInfo,dispatcher1); is called the same behavior (program terminates after memory increases to >2gb) is experienced;

Hope this helps.

Thanks
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Help: pure collision detection on large number of spheres

Post by Erwin Coumans »

The generated spheres are overlapping a lot, for 30.000 spheres over 7 million overlapping pairs are generated. Only 300.000 are pre-allocated.
7 million pairs will consume a huge amount of memory (several gigabytes) right now.

Is something wrong with the generation of the positions/radii of the spheres?
Thanks,
Erwin
linksan
Posts: 13
Joined: Fri May 23, 2008 4:30 pm

Re: Help: pure collision detection on large number of spheres

Post by linksan »

Thank you very much :D .
After spacing the objects out more I was able to run 1000000 bodies with about 1.2 GB of memory.


Thanks for your help.
Post Reply