Skip to content

Commit db841a2

Browse files
committed
- added new namespace for utilities
1 parent 4632886 commit db841a2

50 files changed

Lines changed: 646 additions & 150 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,19 @@ else()
1717
endif()
1818

1919
include(ExternalProject)
20-
set(ExternalInstallDir "${CMAKE_SOURCE_DIR}/extern/install")
20+
if (DEFINED PBD_EXTERNALINSTALLDIR)
21+
set(ExternalInstallDir "${PBD_EXTERNALINSTALLDIR}")
22+
else()
23+
set(ExternalInstallDir "${CMAKE_SOURCE_DIR}/extern/install")
24+
endif()
2125
set(EigenDir "${CMAKE_SOURCE_DIR}/extern/eigen")
2226

2327
## Discregrid
2428
ExternalProject_Add(
2529
ExternalProject_Discregrid
2630
PREFIX "${CMAKE_SOURCE_DIR}/extern/Discregrid"
2731
GIT_REPOSITORY https://github.com/InteractiveComputerGraphics/Discregrid.git
28-
GIT_TAG "573c2f51f433c74de832454272e47f590140e80b"
32+
GIT_TAG "f16a29afebf7a7f43139d5832bbfc7124c5d98db"
2933
INSTALL_DIR ${ExternalInstallDir}/Discregrid
3034
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${ExternalInstallDir}/Discregrid -DBUILD_CMD_EXECUTABLE:BOOL=0 -DEIGEN3_INCLUDE_DIR:PATH=${EigenDir}
3135
)

Changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
- added new namespace for utilities
2+
13
1.6.0
24
- added collision detection for arbitrary meshes based on cubic signed distance fields
35
- added DiscreGrid library as external project to generate cubic signed distance fields

Common/Common.h

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,28 @@ typedef float Real;
1919
#define REAL_MIN FLT_MIN
2020
#endif
2121

22-
namespace PBD
23-
{
24-
using Vector2r = Eigen::Matrix<Real, 2, 1>;
25-
using Vector3r = Eigen::Matrix<Real, 3, 1>;
26-
using Vector4r = Eigen::Matrix<Real, 4, 1>;
27-
using Matrix2r = Eigen::Matrix<Real, 2, 2>;
28-
using Matrix3r = Eigen::Matrix<Real, 3, 3>;
29-
using Matrix4r = Eigen::Matrix<Real, 4, 4>;
30-
using AlignedBox2r = Eigen::AlignedBox<Real, 2>;
31-
using AlignedBox3r = Eigen::AlignedBox<Real, 3>;
32-
using AngleAxisr = Eigen::AngleAxis<Real>;
33-
using Quaternionr = Eigen::Quaternion<Real>;
34-
35-
//allocators to be used in STL collections containing Eigen structures
36-
using Alloc_Vector2r = Eigen::aligned_allocator<Vector2r>;
37-
using Alloc_Vector3r = Eigen::aligned_allocator<Vector3r>;
38-
using Alloc_Vector4r = Eigen::aligned_allocator<Vector4r>;
39-
using Alloc_Matrix2r = Eigen::aligned_allocator<Matrix2r>;
40-
using Alloc_Matrix3r = Eigen::aligned_allocator<Matrix3r>;
41-
using Alloc_Matrix4r = Eigen::aligned_allocator<Matrix4r>;
42-
using Alloc_AlignedBox2r = Eigen::aligned_allocator<AlignedBox2r>;
43-
using Alloc_AlignedBox3r = Eigen::aligned_allocator<AlignedBox3r>;
44-
using Alloc_AngleAxisr = Eigen::aligned_allocator<AngleAxisr>;
45-
using Alloc_Quaternionr = Eigen::aligned_allocator<Quaternionr>;
22+
using Vector2r = Eigen::Matrix<Real, 2, 1>;
23+
using Vector3r = Eigen::Matrix<Real, 3, 1>;
24+
using Vector4r = Eigen::Matrix<Real, 4, 1>;
25+
using Matrix2r = Eigen::Matrix<Real, 2, 2>;
26+
using Matrix3r = Eigen::Matrix<Real, 3, 3>;
27+
using Matrix4r = Eigen::Matrix<Real, 4, 4>;
28+
using AlignedBox2r = Eigen::AlignedBox<Real, 2>;
29+
using AlignedBox3r = Eigen::AlignedBox<Real, 3>;
30+
using AngleAxisr = Eigen::AngleAxis<Real>;
31+
using Quaternionr = Eigen::Quaternion<Real>;
32+
33+
//allocators to be used in STL collections containing Eigen structures
34+
using Alloc_Vector2r = Eigen::aligned_allocator<Vector2r>;
35+
using Alloc_Vector3r = Eigen::aligned_allocator<Vector3r>;
36+
using Alloc_Vector4r = Eigen::aligned_allocator<Vector4r>;
37+
using Alloc_Matrix2r = Eigen::aligned_allocator<Matrix2r>;
38+
using Alloc_Matrix3r = Eigen::aligned_allocator<Matrix3r>;
39+
using Alloc_Matrix4r = Eigen::aligned_allocator<Matrix4r>;
40+
using Alloc_AlignedBox2r = Eigen::aligned_allocator<AlignedBox2r>;
41+
using Alloc_AlignedBox3r = Eigen::aligned_allocator<AlignedBox3r>;
42+
using Alloc_AngleAxisr = Eigen::aligned_allocator<AngleAxisr>;
43+
using Alloc_Quaternionr = Eigen::aligned_allocator<Quaternionr>;
4644

4745
#if EIGEN_ALIGN
4846
#define PDB_MAKE_ALIGNED_OPERATOR_NEW EIGEN_MAKE_ALIGNED_OPERATOR_NEW
@@ -89,7 +87,7 @@ namespace PBD
8987
#endif
9088

9189
#endif
92-
}
90+
9391

9492
#endif
9593

Demos/BarDemo/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ INIT_LOGGING
2323
using namespace PBD;
2424
using namespace Eigen;
2525
using namespace std;
26+
using namespace Utilities;
2627

2728
void timeStep ();
2829
void buildModel ();

Demos/ClothDemo/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ INIT_LOGGING
2323
using namespace PBD;
2424
using namespace Eigen;
2525
using namespace std;
26+
using namespace Utilities;
2627

2728
void timeStep ();
2829
void buildModel ();

Demos/CosseratRodsDemo/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ INIT_LOGGING
2323
using namespace PBD;
2424
using namespace Eigen;
2525
using namespace std;
26+
using namespace Utilities;
2627

2728
void timeStep ();
2829
void buildModel ();

Demos/CouplingDemos/RigidBodyClothCouplingDemo.cpp

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ INIT_LOGGING
2828
using namespace PBD;
2929
using namespace Eigen;
3030
using namespace std;
31+
using namespace Utilities;
3132

3233
void timeStep ();
3334
void buildModel ();
@@ -406,6 +407,55 @@ Vector3r computeInertiaTensorBox(const Real mass, const Real width, const Real h
406407
return Vector3r(Ix, Iy, Iz);
407408
}
408409

410+
void loadObj(const std::string &filename, VertexData &vd, IndexedFaceMesh &mesh, const Vector3r &scale)
411+
{
412+
std::vector<OBJLoader::Vec3f> x;
413+
std::vector<OBJLoader::Vec3f> normals;
414+
std::vector<OBJLoader::Vec2f> texCoords;
415+
std::vector<MeshFaceIndices> faces;
416+
OBJLoader::Vec3f s = { (float)scale[0], (float)scale[1], (float)scale[2] };
417+
OBJLoader::loadObj(filename, &x, &faces, &normals, &texCoords, s);
418+
419+
mesh.release();
420+
const unsigned int nPoints = (unsigned int)x.size();
421+
const unsigned int nFaces = (unsigned int)faces.size();
422+
const unsigned int nTexCoords = (unsigned int)texCoords.size();
423+
mesh.initMesh(nPoints, nFaces * 2, nFaces);
424+
vd.reserve(nPoints);
425+
for (unsigned int i = 0; i < nPoints; i++)
426+
{
427+
vd.addVertex(Vector3r(x[i][0], x[i][1], x[i][2]));
428+
}
429+
for (unsigned int i = 0; i < nTexCoords; i++)
430+
{
431+
mesh.addUV(texCoords[i][0], texCoords[i][1]);
432+
}
433+
for (unsigned int i = 0; i < nFaces; i++)
434+
{
435+
// Reduce the indices by one
436+
int posIndices[3];
437+
int texIndices[3];
438+
for (int j = 0; j < 3; j++)
439+
{
440+
posIndices[j] = faces[i].posIndices[j] - 1;
441+
if (nTexCoords > 0)
442+
{
443+
texIndices[j] = faces[i].texIndices[j] - 1;
444+
mesh.addUVIndex(texIndices[j]);
445+
}
446+
}
447+
448+
mesh.addFace(&posIndices[0]);
449+
}
450+
mesh.buildNeighbors();
451+
452+
mesh.updateNormals(vd, 0);
453+
mesh.updateVertexNormals(vd);
454+
455+
LOG_INFO << "Number of triangles: " << nFaces;
456+
LOG_INFO << "Number of vertices: " << nPoints;
457+
}
458+
409459
/** Create the model
410460
*/
411461
void createRigidBodyModel()
@@ -416,7 +466,7 @@ void createRigidBodyModel()
416466
string fileName = FileSystem::normalizePath(dataPath + "/models/cube.obj");
417467
IndexedFaceMesh mesh;
418468
VertexData vd;
419-
OBJLoader::loadObj(fileName, vd, mesh, Vector3r(width, height, depth));
469+
loadObj(fileName, vd, mesh, Vector3r(width, height, depth));
420470

421471
rb.resize(12);
422472

Demos/DistanceFieldDemos/ClothCollisionDemo.cpp

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ INIT_LOGGING
2626
using namespace PBD;
2727
using namespace Eigen;
2828
using namespace std;
29+
using namespace Utilities;
2930

3031
void timeStep ();
3132
void buildModel ();
@@ -254,6 +255,55 @@ void timeStep ()
254255
model.getTriangleModels()[i]->updateMeshNormals(model.getParticles());
255256
}
256257

258+
void loadObj(const std::string &filename, VertexData &vd, IndexedFaceMesh &mesh, const Vector3r &scale)
259+
{
260+
std::vector<OBJLoader::Vec3f> x;
261+
std::vector<OBJLoader::Vec3f> normals;
262+
std::vector<OBJLoader::Vec2f> texCoords;
263+
std::vector<MeshFaceIndices> faces;
264+
OBJLoader::Vec3f s = { (float)scale[0], (float)scale[1], (float)scale[2] };
265+
OBJLoader::loadObj(filename, &x, &faces, &normals, &texCoords, s);
266+
267+
mesh.release();
268+
const unsigned int nPoints = (unsigned int)x.size();
269+
const unsigned int nFaces = (unsigned int)faces.size();
270+
const unsigned int nTexCoords = (unsigned int)texCoords.size();
271+
mesh.initMesh(nPoints, nFaces * 2, nFaces);
272+
vd.reserve(nPoints);
273+
for (unsigned int i = 0; i < nPoints; i++)
274+
{
275+
vd.addVertex(Vector3r(x[i][0], x[i][1], x[i][2]));
276+
}
277+
for (unsigned int i = 0; i < nTexCoords; i++)
278+
{
279+
mesh.addUV(texCoords[i][0], texCoords[i][1]);
280+
}
281+
for (unsigned int i = 0; i < nFaces; i++)
282+
{
283+
// Reduce the indices by one
284+
int posIndices[3];
285+
int texIndices[3];
286+
for (int j = 0; j < 3; j++)
287+
{
288+
posIndices[j] = faces[i].posIndices[j] - 1;
289+
if (nTexCoords > 0)
290+
{
291+
texIndices[j] = faces[i].texIndices[j] - 1;
292+
mesh.addUVIndex(texIndices[j]);
293+
}
294+
}
295+
296+
mesh.addFace(&posIndices[0]);
297+
}
298+
mesh.buildNeighbors();
299+
300+
mesh.updateNormals(vd, 0);
301+
mesh.updateVertexNormals(vd);
302+
303+
LOG_INFO << "Number of triangles: " << nFaces;
304+
LOG_INFO << "Number of vertices: " << nPoints;
305+
}
306+
257307
void buildModel ()
258308
{
259309
TimeManager::getCurrent ()->setTimeStepSize (0.005);
@@ -264,12 +314,12 @@ void buildModel ()
264314
string fileName = FileSystem::normalizePath(dataPath + "/models/cube.obj");
265315
IndexedFaceMesh mesh;
266316
VertexData vd;
267-
OBJLoader::loadObj(fileName, vd, mesh);
317+
loadObj(fileName, vd, mesh, Vector3r::Ones());
268318

269319
string fileNameTorus = FileSystem::normalizePath(dataPath + "/models/torus.obj");
270320
IndexedFaceMesh meshTorus;
271321
VertexData vdTorus;
272-
OBJLoader::loadObj(fileNameTorus, vdTorus, meshTorus);
322+
loadObj(fileNameTorus, vdTorus, meshTorus, Vector3r::Ones());
273323

274324
SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
275325
rb.resize(2);

Demos/DistanceFieldDemos/DeformableCollisionDemo.cpp

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ INIT_LOGGING
2525
using namespace PBD;
2626
using namespace Eigen;
2727
using namespace std;
28+
using namespace Utilities;
2829

2930
void timeStep ();
3031
void buildModel ();
@@ -212,6 +213,55 @@ void timeStep ()
212213
model.getTetModels()[i]->updateMeshNormals(model.getParticles());
213214
}
214215

216+
void loadObj(const std::string &filename, VertexData &vd, IndexedFaceMesh &mesh, const Vector3r &scale)
217+
{
218+
std::vector<OBJLoader::Vec3f> x;
219+
std::vector<OBJLoader::Vec3f> normals;
220+
std::vector<OBJLoader::Vec2f> texCoords;
221+
std::vector<MeshFaceIndices> faces;
222+
OBJLoader::Vec3f s = { (float)scale[0], (float)scale[1], (float)scale[2] };
223+
OBJLoader::loadObj(filename, &x, &faces, &normals, &texCoords, s);
224+
225+
mesh.release();
226+
const unsigned int nPoints = (unsigned int)x.size();
227+
const unsigned int nFaces = (unsigned int)faces.size();
228+
const unsigned int nTexCoords = (unsigned int)texCoords.size();
229+
mesh.initMesh(nPoints, nFaces * 2, nFaces);
230+
vd.reserve(nPoints);
231+
for (unsigned int i = 0; i < nPoints; i++)
232+
{
233+
vd.addVertex(Vector3r(x[i][0], x[i][1], x[i][2]));
234+
}
235+
for (unsigned int i = 0; i < nTexCoords; i++)
236+
{
237+
mesh.addUV(texCoords[i][0], texCoords[i][1]);
238+
}
239+
for (unsigned int i = 0; i < nFaces; i++)
240+
{
241+
// Reduce the indices by one
242+
int posIndices[3];
243+
int texIndices[3];
244+
for (int j = 0; j < 3; j++)
245+
{
246+
posIndices[j] = faces[i].posIndices[j] - 1;
247+
if (nTexCoords > 0)
248+
{
249+
texIndices[j] = faces[i].texIndices[j] - 1;
250+
mesh.addUVIndex(texIndices[j]);
251+
}
252+
}
253+
254+
mesh.addFace(&posIndices[0]);
255+
}
256+
mesh.buildNeighbors();
257+
258+
mesh.updateNormals(vd, 0);
259+
mesh.updateVertexNormals(vd);
260+
261+
LOG_INFO << "Number of triangles: " << nFaces;
262+
LOG_INFO << "Number of vertices: " << nPoints;
263+
}
264+
215265
void buildModel ()
216266
{
217267
TimeManager::getCurrent ()->setTimeStepSize (0.005);
@@ -222,12 +272,12 @@ void buildModel ()
222272
string fileName = FileSystem::normalizePath(dataPath + "/models/cube.obj");
223273
IndexedFaceMesh mesh;
224274
VertexData vd;
225-
OBJLoader::loadObj(fileName, vd, mesh);
275+
loadObj(fileName, vd, mesh, Vector3r::Ones());
226276

227277
string fileNameTorus = FileSystem::normalizePath(dataPath + "/models/torus.obj");
228278
IndexedFaceMesh meshTorus;
229279
VertexData vdTorus;
230-
OBJLoader::loadObj(fileNameTorus, vdTorus, meshTorus);
280+
loadObj(fileNameTorus, vdTorus, meshTorus, Vector3r::Ones());
231281

232282
SimulationModel::RigidBodyVector &rb = model.getRigidBodies();
233283
rb.resize(2);

0 commit comments

Comments
 (0)