Skip to content
Snippets Groups Projects
Commit 14cfbb80 authored by Andrew Wilson's avatar Andrew Wilson :elephant:
Browse files

Merge branch 'AssimpBugFix' into 'master'

BUG: Ignore segments in triangle mesh reading

See merge request iMSTK/iMSTK!685
parents c11d712c 20edefe5
No related branches found
No related tags found
No related merge requests found
/*=========================================================================
Library: iMSTK
Copyright (c) Kitware, Inc. & Center for Modeling, Simulation,
& Imaging in Medicine, Rensselaer Polytechnic Institute.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0.txt
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=========================================================================*/
#include "gtest/gtest.h"
#include "imstkCollisionData.h"
using namespace imstk;
namespace {
namespace
{
}
struct imstkCollisionElementTest : public ::testing::Test
{
imstkCollisionElementTest()
{
cv.pts[0] = Vec3d{ 1,2,3 };
cv.pts[1] = Vec3d{ 2,3,4 };
cv.pts[2] = Vec3d{ 3,4,5 };
cv.pts[3] = Vec3d{ 4,5,6 };
cv.size = 10;
ci.ids[0] = 7;
ci.ids[1] = 8;
ci.ids[2] = 9;
ci.ids[3] = 10;
ci.idCount = 11;
cv.pts[0] = Vec3d{ 1, 2, 3 };
cv.pts[1] = Vec3d{ 2, 3, 4 };
cv.pts[2] = Vec3d{ 3, 4, 5 };
cv.pts[3] = Vec3d{ 4, 5, 6 };
cv.size = 10;
ci.ids[0] = 7;
ci.ids[1] = 8;
ci.ids[2] = 9;
ci.ids[3] = 10;
ci.idCount = 11;
ci.cellType = IMSTK_VERTEX;
pd.pt = Vec3d{ 2,3,4 };
pd.dir = Vec3d{ 4,5,6 };
pd.pt = Vec3d{ 2, 3, 4 };
pd.dir = Vec3d{ 4, 5, 6 };
pd.penetrationDepth = 12.0;
pi.ptIndex = 13;
pi.dir = Vec3d{ 3,4,5 };
pi.dir = Vec3d{ 3, 4, 5 };
pi.penetrationDepth = 2.0;
};
......@@ -62,7 +84,7 @@ TEST_F(imstkCollisionElementTest, Constructor)
EXPECT_EQ(CollisionElementType::PointDirection, e.m_type);
EXPECT_EQ(pd.dir, e.m_element.m_PointDirectionElement.dir);
EXPECT_EQ(pd.penetrationDepth, e.m_element.m_PointDirectionElement.penetrationDepth);
}
}
{
CollisionElement e(pi);
EXPECT_EQ(CollisionElementType::PointIndexDirection, e.m_type);
......
......@@ -109,7 +109,7 @@ using Mat3d = Eigen::Matrix<double, 3, 3>;
using StdVectorOfMat3d = std::vector<Mat3d, Eigen::aligned_allocator<Mat3d>>;
// 4x4 Matrix
using Mat4f = Eigen::Matrix<float, 4, 4> ;
using Mat4f = Eigen::Matrix<float, 4, 4>;
using Mat4d = Eigen::Matrix<double, 4, 4>;
/// A dynamic size matrix of floats
......
......@@ -79,7 +79,7 @@ private:
/// \brief Phantom omni device api callback
///
#ifndef HDCALLBACK
#define HDCALLBACK
#define HDCALLBACK
#endif
typedef unsigned int HDCallbackCode;
static HDCallbackCode HDCALLBACK hapticCallback(void* pData);
......
......@@ -81,8 +81,8 @@ AssimpMeshIO::convertAssimpMesh(aiMesh* importedMesh)
auto mesh = std::make_shared<SurfaceMesh>(std::string(importedMesh->mName.C_Str()));
// Get mesh information
auto numVertices = importedMesh->mNumVertices;
auto numTriangles = importedMesh->mNumFaces;
auto numVertices = importedMesh->mNumVertices;
auto numFaces = importedMesh->mNumFaces;
if (numVertices == 0)
{
......@@ -103,17 +103,20 @@ AssimpMeshIO::convertAssimpMesh(aiMesh* importedMesh)
}
// Triangles
std::shared_ptr<VecDataArray<int, 3>> trianglesPtr = std::make_shared<VecDataArray<int, 3>>(numTriangles);
VecDataArray<int, 3>& triangles = *trianglesPtr;
auto trianglesPtr = std::make_shared<VecDataArray<int, 3>>();
trianglesPtr->reserve(numFaces);
VecDataArray<int, 3>& triangles = *trianglesPtr;
for (unsigned int i = 0; i < numTriangles; i++)
for (unsigned int i = 0; i < numFaces; i++)
{
auto triangle = importedMesh->mFaces[i];
auto indices = triangle.mIndices;
triangles[i][0] = indices[0];
triangles[i][1] = indices[1];
triangles[i][2] = indices[2];
aiFace triangle = importedMesh->mFaces[i];
unsigned int* indices = triangle.mIndices;
if (triangle.mNumIndices == 3) // Only supports triangles
{
triangles.push_back(Vec3i(indices[0], indices[1], indices[2]));
}
}
trianglesPtr->squeeze();
// Vertex normals, tangents, and bitangents
std::shared_ptr<VecDataArray<double, 3>> normalsPtr = std::make_shared<VecDataArray<double, 3>>(numVertices);
......
......@@ -185,8 +185,7 @@ public:
///
/// \brief Get and unordered map of cameras with names
///
const std::unordered_map<std::string, std::shared_ptr<Camera>>&
getCameras() const { return m_cameras; }
const std::unordered_map<std::string, std::shared_ptr<Camera>>& getCameras() const { return m_cameras; }
///
/// \brief Add light from the scene
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment