File: PotentialBlock2AABB.cpp

package info (click to toggle)
yade 2026.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,448 kB
  • sloc: cpp: 97,645; python: 52,173; sh: 677; makefile: 162
file content (43 lines) | stat: -rw-r--r-- 1,377 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

/*CWBoon 2015 */
#ifdef YADE_POTENTIAL_BLOCKS
#include "PotentialBlock2AABB.hpp"
#include <core/Aabb.hpp>
#include <pkg/potential/PotentialBlock.hpp>

namespace yade { // Cannot have #include directive inside.

void PotentialBlock2AABB::go(const shared_ptr<Shape>& cm, shared_ptr<Bound>& bv, const Se3r& se3, const Body*)
{
	PotentialBlock* pp = static_cast<PotentialBlock*>(cm.get());
	if (!bv) { bv = shared_ptr<Bound>(new Aabb); }
	Aabb* aabb = static_cast<Aabb*>(bv.get());

	if (pp->AabbMinMax == false) {
		Real     distFromCentre = 1.0 * pp->R;
		Vector3r halfSize       = (aabbEnlargeFactor > 0 ? aabbEnlargeFactor : 1.) * Vector3r(distFromCentre, distFromCentre, distFromCentre);
		aabb->min               = se3.position - halfSize;
		aabb->max               = se3.position + halfSize;
		return;
	} else {
		Vector3r vertex, aabbMin(0, 0, 0), aabbMax(0, 0, 0);
		for (unsigned int i = 0; i < pp->vertices.size(); i++) {
			vertex  = se3.orientation * pp->vertices[i]; // vertices in global coordinates
			aabbMin = aabbMin.cwiseMin(vertex);
			aabbMax = aabbMax.cwiseMax(vertex);
		}
		if (aabbEnlargeFactor > 0) {
			aabbMin *= aabbEnlargeFactor;
			aabbMax *= aabbEnlargeFactor;
		}
		aabb->min = se3.position + aabbMin;
		aabb->max = se3.position + aabbMax;
		return;
	}
}

YADE_PLUGIN((PotentialBlock2AABB));

} // namespace yade

#endif // YADE_POTENTIAL_BLOCKS