← Back to team overview

yade-dev team mailing list archive

[Branch ~yade-dev/yade/trunk] Rev 2020: 1. Add bin with 0 interactions to _utils.bodyNumInteractionsHistogram, hereby fixing utils.avgNum...

 

------------------------------------------------------------
revno: 2020
committer: Václav Šmilauer <eudoxos@xxxxxxxx>
branch nick: trunk
timestamp: Fri 2010-02-12 09:07:23 +0100
message:
  1. Add bin with 0 interactions to _utils.bodyNumInteractionsHistogram, hereby fixing utils.avgNumInteractions as well (thanks, Luc)
modified:
  py/_utils.cpp


--
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 'py/_utils.cpp'
--- py/_utils.cpp	2010-02-02 11:05:09 +0000
+++ py/_utils.cpp	2010-02-12 08:07:23 +0000
@@ -147,19 +147,24 @@
 python::tuple bodyNumInteractionsHistogram(python::tuple aabb=python::tuple()){
 	Vector3r bbMin(Vector3r::ZERO), bbMax(Vector3r::ZERO); bool useBB=python::len(aabb)>0; if(useBB){bbMin=extract<Vector3r>(aabb[0])();bbMax=extract<Vector3r>(aabb[1])();}
 	const shared_ptr<Scene>& rb=Omega::instance().getScene();
-	vector<int> bodyNumInta; bodyNumInta.resize(rb->bodies->size(),-1 /* uninitialized */);
-	int maxInta=0;
+	vector<int> bodyNumIntr; bodyNumIntr.resize(rb->bodies->size(),0);
+	int maxIntr=0;
 	FOREACH(const shared_ptr<Interaction>& i, *rb->interactions){
 		if(!i->isReal()) continue;
 		const body_id_t id1=i->getId1(), id2=i->getId2(); const shared_ptr<Body>& b1=Body::byId(id1,rb), b2=Body::byId(id2,rb);
-		if(useBB && isInBB(b1->state->pos,bbMin,bbMax)) bodyNumInta[id1]=bodyNumInta[id1]>0?bodyNumInta[id1]+1:1;
-		if(useBB && isInBB(b2->state->pos,bbMin,bbMax)) bodyNumInta[id2]=bodyNumInta[id2]>0?bodyNumInta[id2]+1:1;
-		maxInta=max(max(maxInta,bodyNumInta[b1->getId()]),bodyNumInta[b2->getId()]);
-	}
-	vector<int> bins; bins.resize(maxInta+1);
-	for(size_t id=0; id<bodyNumInta.size(); id++){ if(bodyNumInta[id]>=0) bins[bodyNumInta[id]]+=1; }
+		if((useBB && isInBB(b1->state->pos,bbMin,bbMax)) || !useBB) bodyNumIntr[id1]+=1;
+		if((useBB && isInBB(b2->state->pos,bbMin,bbMax)) || !useBB) bodyNumIntr[id2]+=1;
+		maxIntr=max(max(maxIntr,bodyNumIntr[b1->getId()]),bodyNumIntr[b2->getId()]);
+	}
+	vector<int> bins; bins.resize(maxIntr+1,0);
+	for(size_t id=0; id<bodyNumIntr.size(); id++){
+		if(bodyNumIntr[id]>0) bins[bodyNumIntr[id]]+=1;
+		// 0 is handled specially: add body to the 0 bin only if it is inside the bb requested (if applicable)
+		// otherwise don't do anything, since it is outside the volume of interest
+		else if((useBB && isInBB(Body::byId(id,rb)->state->pos,bbMin,bbMax)) || !useBB) bins[0]+=1;
+	}
 	python::list count,num;
-	for(size_t n=1; n<bins.size(); n++){
+	for(size_t n=0; n<bins.size(); n++){
 		if(bins[n]==0) continue;
 		num.append(n); count.append(bins[n]);
 	}