Commit 8b34b702 authored by Harald Scheirich's avatar Harald Scheirich
Browse files

Merge branch 'master' into feature/event-tests

parents 8066a75c 8a88d29a
......@@ -50,10 +50,11 @@ function(imstk_add_test_internal target kind)
# Link test driver against current target, gtest and pthread
target_link_libraries(${test_driver_executable}
${target}
Testing
Threads::Threads
GTest::gtest
GTest::gmock
GTest::gtest_main
Threads::Threads
)
if (MSVC)
......
......@@ -377,6 +377,7 @@ add_subdirectory(Source/CollisionDetection)
add_subdirectory(Source/CollisionHandling)
add_subdirectory(Source/Scene)
add_subdirectory(Source/SimulationManager)
add_subdirectory(Source/Testing)
add_subdirectory(Source/Filtering)
add_subdirectory(Source/FilteringCore)
......
......@@ -52,7 +52,7 @@ Designed more specifically for developers, the issue tracker allows developers t
##### On Linux:
```bash
sudo apt-get install build-essentials libgl1-mesa-dev libxt-dev libusb-1.0-0-dev
sudo apt-get install build-essential libgl1-mesa-dev libxt-dev libusb-1.0-0-dev
```
## Getting started with iMSTK
......
/*=========================================================================
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.
=========================================================================*/
#pragma once
#include "imstkAnalyticalGeometry.h"
namespace imstk
{
class Decal : public AnalyticalGeometry
{
public:
Decal(const std::string& name = std::string(""));
virtual ~Decal() override = default;
///
/// \brief Returns the string representing the type name of the geometry
///
virtual const std::string getTypeName() const override { return "Decal"; }
public:
///
/// \brief Print the cube info
///
void print() const override;
///
/// \brief Returns the volume of the cube
///
double getVolume() override { return m_dimensions[0] * m_dimensions[1] * m_dimensions[2]; }
///
/// \brief Update decal transforms
///
void updateDecal(Mat4d& viewMatrix);
protected:
// Hide these functions
using AnalyticalGeometry::getFunctionValue;
void applyTransform(const Mat4d& m) override;
Vec3d m_dimensions;
Mat4d m_inverse;
};
}
/*=========================================================================
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 "imstkDecalPool.h"
#include "imstkDecal.h"
#include "imstkLogger.h"
namespace imstk
{
DecalPool::DecalPool(unsigned int maxNumDecals /*= 128*/, const std::string& name)
: Geometry(name)
{
if (maxNumDecals <= 128)
{
m_maxNumDecals = maxNumDecals;
}
else
{
m_maxNumDecals = 128;
LOG(WARNING) << "The maximum number of decals is 128";
}
m_vertexPositions[0] = Vec3d(0.5, 0.5, 0.5);
m_vertexPositions[1] = Vec3d(0.5, 0.5, -0.5);
m_vertexPositions[2] = Vec3d(0.5, -0.5, 0.5);
m_vertexPositions[3] = Vec3d(0.5, -0.5, -0.5);
m_vertexPositions[4] = Vec3d(-0.5, 0.5, 0.5);
m_vertexPositions[5] = Vec3d(-0.5, 0.5, -0.5);
m_vertexPositions[6] = Vec3d(-0.5, -0.5, 0.5);
m_vertexPositions[7] = Vec3d(-0.5, -0.5, -0.5);
m_triangles[0] = Vec3i(2, 1, 0);
m_triangles[1] = Vec3i(1, 2, 3);
m_triangles[2] = Vec3i(4, 5, 6);
m_triangles[3] = Vec3i(7, 6, 5);
m_triangles[4] = Vec3i(0, 1, 4);
m_triangles[5] = Vec3i(5, 4, 1);
m_triangles[6] = Vec3i(6, 3, 2);
m_triangles[7] = Vec3i(3, 6, 7);
m_triangles[8] = Vec3i(4, 2, 0);
m_triangles[9] = Vec3i(2, 4, 6);
m_triangles[10] = Vec3i(1, 3, 5);
m_triangles[11] = Vec3i(7, 5, 3);
for (unsigned int i = 0; i < maxNumDecals; i++)
{
m_freeDecals.push_back(std::make_shared<Decal>("Decal-" + std::to_string(i)));
}
}
std::shared_ptr<Decal>
DecalPool::addDecal()
{
if (m_numDecals >= m_maxNumDecals && !m_recycle)
{
LOG(WARNING) << "Decal pool exhausted, unable to add more decals";
return nullptr;
}
if (m_recycle && m_numDecals >= m_maxNumDecals)
{
m_freeDecals.push_back(m_orderedDecals.front());
m_orderedDecals.pop_front();
}
auto decal = m_freeDecals.front();
m_orderedDecals.push_back(decal);
m_freeDecals.pop_front();
if (m_numDecals < m_maxNumDecals)
{
m_numDecals++;
}
return decal;
}
void
DecalPool::removeDecal()
{
m_freeDecals.push_back(m_orderedDecals.front());
m_orderedDecals.pop_front();
m_numDecals--;
}
std::deque<std::shared_ptr<Decal>>&
DecalPool::getDecals()
{
return m_orderedDecals;
}
void
DecalPool::setRecycle(bool recycle)
{
m_recycle = recycle;
}
bool
DecalPool::getRecycle()
{
return m_recycle;
}
unsigned int
DecalPool::getNumDecals()
{
return m_numDecals;
}
unsigned int
DecalPool::getMaxNumDecals()
{
return m_maxNumDecals;
}
}
/*=========================================================================
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.
=========================================================================*/
#pragma once
#include "imstkGeometry.h"
#include "imstkMath.h"
#include <array>
#include <queue>
#ifdef WIN32
#pragma warning( push )
#pragma warning( disable : 4201 )
#endif
#ifdef WIN32
#pragma warning( pop )
#endif
namespace imstk
{
class Decal;
class DecalPool : public Geometry
{
public:
///
/// \brief Constructor
///
DecalPool(unsigned int maxNumDecals = 128, const std::string& name = std::string(""));
///
/// \brief Deconstructor
///
virtual ~DecalPool() override = default;
///
/// \brief Returns the string representing the type name of the geometry
///
virtual const std::string getTypeName() const override { return "DecalPool"; }
public:
///
/// \brief Add a \ref Decal object to this pool
///
std::shared_ptr<Decal> addDecal();
///
/// \brief Remove a \ref Decal object to this pool
///
void removeDecal();
///
/// \brief Get all decals
///
std::deque<std::shared_ptr<Decal>>& getDecals();
///
/// \brief Set/Get recyle
///
void setRecycle(bool recycle);
bool getRecycle();
///
/// \brief Get the number of decals
///
unsigned int getNumDecals();
///
/// \brief Get the max number of decals
///
unsigned int getMaxNumDecals();
protected:
std::deque<std::shared_ptr<Decal>> m_orderedDecals;
std::deque<std::shared_ptr<Decal>> m_freeDecals;
void applyTransform(const Mat4d& imstkNotUsed(m)) override { }
virtual void updatePostTransformData() const override { }
unsigned int m_maxNumDecals;
unsigned int m_numDecals = 0;
bool m_recycle = true;
Vec3d m_vertexPositions[8];
Vec3i m_triangles[12];
};
}
#-----------------------------------------------------------------------------
# Create target
#-----------------------------------------------------------------------------
if( ${PROJECT_NAME}_BUILD_TESTING )
include(imstkAddLibrary)
imstk_add_library( Testing
DEPENDS
Common
GTest::gtest
${VTK_LIBRARIES}
)
endif()
\ No newline at end of file
......@@ -19,38 +19,34 @@
=========================================================================*/
#include "imstkDecal.h"
#include "imstkLogger.h"
#include <vtksys/SystemTools.hxx>
namespace imstk
{
Decal::Decal(const std::string& name) : AnalyticalGeometry(name),
m_dimensions(Vec3d(1.0, 1.0, 1.0))
{
}
#include <gtest/gtest.h>
void
Decal::print() const
{
Geometry::print();
LOG(INFO) << "Dimensions: " << m_dimensions[0]
<< ", " << m_dimensions[1]
<< ", " << m_dimensions[2];
}
void
Decal::applyTransform(const Mat4d& m)
{
const Vec3d s = Vec3d(
m.block<3, 1>(0, 0).norm(),
m.block<3, 1>(0, 1).norm(),
m.block<3, 1>(0, 2).norm());
m_dimensions = m_dimensions.cwiseProduct(s);
}
void
Decal::updateDecal(Mat4d& imstkNotUsed(viewMatrix))
#include "imstkLogger.h"
int
main(int argc, char** argv)
{
m_inverse = m_transform.inverse();
}
bool removeLog = true;
for (int i = 0; i < argc; ++i)
{
if (std::string(argv[i]) == "--imstk_keep_log")
{
removeLog = false;
}
}
if (removeLog)
{
vtksys::SystemTools::RemoveADirectory("log");
}
vtksys::SystemTools::MakeDirectory("log");
auto& logger = imstk::Logger::getInstance();
logger.addFileSink("test", "log");
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment