iMSTK
Interactive Medical Simulation Toolkit
SurfaceMeshCDBenchmark.cpp
1 /*
2 ** This file is part of the Interactive Medical Simulation Toolkit (iMSTK)
3 ** iMSTK is distributed under the Apache License, Version 2.0.
4 ** See accompanying NOTICE for details.
5 */
6 
7 #include "imstkCapsule.h"
8 #include "imstkCollisionHandling.h"
9 #include "imstkGeometry.h"
10 #include "imstkMath.h"
11 #include "imstkMeshIO.h"
12 #include "imstkPbdModel.h"
13 #include "imstkPbdModelConfig.h"
14 #include "imstkPbdObject.h"
15 #include "imstkPbdObjectCollision.h"
16 #include "imstkPointSetToCapsuleCD.h"
17 #include "imstkPointwiseMap.h"
18 #include "imstkRbdConstraint.h"
19 #include "imstkScene.h"
20 #include "imstkSphere.h"
21 #include "imstkSurfaceMesh.h"
22 #include "imstkSurfaceMeshToCapsuleCD.h"
23 #include "imstkTetrahedralMesh.h"
24 #include "imstkGeometryUtilities.h"
25 
26 #include <benchmark/benchmark.h>
27 
28 using namespace imstk;
29 
30 std::shared_ptr<SurfaceMesh>
31 makeSurfaceMesh(int dim)
32 {
33  return GeometryUtils::toTriangleGrid(Vec3d::Zero(), Vec2d{ 1, 1 }, Vec2i{ dim, dim });
34 }
35 
39 static void
40 BM_SurfaceMeshToCapsuleCD(benchmark::State& state)
41 {
42  auto mesh = makeSurfaceMesh(state.range(0));
43  //std::cout << "Range: " << state.range(0) << "Tris: " << mesh->getNumTriangles() << std::endl;
44  //std::cout << mesh->getNumVertices() << "/" << mesh->getNumTriangles() << std::endl;
45 
46  auto capsule = std::make_shared<Capsule>(Vec3d{ 0, 0, 0 }, 0.005, 0.01);
47 
49  cd.setInputGeometryA(mesh);
50  cd.setInputGeometryB(capsule);
51  cd.setGenerateCD(true, true);
52 
53  // Copy loop
54  for (auto _ : state)
55  {
56  cd.update();
57  }
58 }
59 
60 BENCHMARK(BM_SurfaceMeshToCapsuleCD)
61 ->Unit(benchmark::kMicrosecond)->Arg(4)->Arg(6)->Arg(8)->Arg(10)->Arg(12)->Arg(16)->Arg(24)->Arg(32)->Arg(48)->Arg(62)->Arg(78)->Arg(100);
62 
63 // Run the benchmark
64 BENCHMARK_MAIN();
std::shared_ptr< SurfaceMesh > toTriangleGrid(const Vec3d &center, const Vec2d &size, const Vec2i &dim, const Quatd orientation=Quatd::Identity(), const double uvScale=1.0)
Produces a triangle grid on a plane given the imstkPlane.
void setGenerateCD(const bool generateA, const bool generateB)
If generateA is false, CD data will not be generated for input0,A Similarly, if generateB is false...
Compound Geometry.
void update()
Do the actual algorithm.
SurfaceMesh to Capsule collision detection Generates vertex-triangle, point-edge, and point-point CD ...