Commit 298c6de2 authored by Ricardo Ortiz's avatar Ricardo Ortiz
Browse files

ENH: Only build Examples if testing is enabled.

Use configuration path for examples in order to locate
configurations files.

Modify AVMNidus, FEMSimulator and Shaders examples.

Small fixes all over the place.
parent d967380e
......@@ -317,7 +317,6 @@ add_subdirectory(ContactHandling)
add_subdirectory(Core)
add_subdirectory(Devices)
add_subdirectory(Event)
add_subdirectory(Examples)
add_subdirectory(Geometry)
add_subdirectory(IO)
add_subdirectory(Mesh)
......@@ -366,6 +365,7 @@ install(FILES
if(BUILD_TESTING)
add_subdirectory(Testing)
add_subdirectory(Examples)
endif()
set(CPACK_COMPONENTS_ALL Development)
......
......@@ -41,3 +41,7 @@ set_target_properties(${APP}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)
set(SOURCE_PATH ${PROJECT_SOURCE_DIR}/Testing)
set(BINARY_PATH ${PROJECT_BINARY_DIR}/Testing/ExamplesData/Nidus)
configure_file(${PROJECT_SOURCE_DIR}/Testing/path.in ${CMAKE_CURRENT_BINARY_DIR}/Config.paths @ONLY)
......@@ -39,12 +39,37 @@
#include "Rendering/InitVTKRendering.h"
#include "IO/IOMesh.h"
int main(int ac, char **av)
#include "Testing/ReadPaths.h"
int main(int ac, char** av)
{
std::string configFile = "./nidus.config";
if(ac == 2)
std::string configPaths = "./Config.paths";
if(ac > 1)
{
configPaths = av[1];
}
auto paths = imstk::ReadPaths(configPaths);
if(std::get<imstk::Path::Binary>(paths).empty() &&
std::get<imstk::Path::Source>(paths).empty())
{
std::cerr << "Error: Configuration file not found." << std::endl;
std::cerr << std::endl;
std::cerr << "\tUsage: " << av[0] << " /path_to/Config.paths" << std::endl;
std::cerr << std::endl;
return EXIT_FAILURE;
}
auto dataPath = std::get<imstk::Path::Binary>(paths);
std::string configFile = dataPath+"/nidus.config";
std::string meshFile = dataPath+"/nidusV1764.vtk";
std::string meshWeightsFile = dataPath+"/nidusV1764.interp";
std::string meshSurfaceFile = dataPath+"/nidusS7415.vtk";
if(configFile.empty())
{
configFile = av[1];
std::cerr << "Configuration file not found." << std::endl;
return EXIT_FAILURE;
}
imstk::InitVTKRendering();
......@@ -65,54 +90,47 @@ int main(int ac, char **av)
auto femSimulator = std::make_shared<imstk::ObjectSimulator>();
// create a Vega based FEM object and attach it to the fem simulator
auto femModel = std::make_shared<imstk::VegaFEMDeformableSceneObject>("nidusV1764.vtk",
configFile);
sdk->addSceneActor(femModel, femSimulator);
auto femModel = std::make_shared<imstk::VegaFEMDeformableSceneObject>(meshFile,configFile);
//-------------------------------------------------------
// Create scene actor 2: plane + dummy simulator
//-------------------------------------------------------
// Create dummy simulator
auto staticSimulator = std::make_shared<imstk::ObjectSimulator>();
// Load rendering mesh
auto volumeMesh = std::static_pointer_cast<imstk::VegaVolumetricMesh>(femModel->getPhysicsModel()->getMesh());
// Create a static plane scene object of given normal and position
auto staticObject = std::make_shared<imstk::StaticSceneObject>();
auto visualModel = std::make_shared<imstk::MeshModel>();
visualModel->load(meshSurfaceFile);
auto plane = std::make_shared<imstk::PlaneCollisionModel>(imstk::Vec3d(0.0,0.0,-35.0),
imstk::Vec3d(0.0,0.0,1.0));
staticObject->setModel(plane);
sdk->addSceneActor(staticObject, staticSimulator);
auto visualMesh = visualModel->getMeshAs<imstk::SurfaceMesh>();
//-------------------------------------------------------
// Enable collision between scene actors 1 and 2
// Mesh render detail
// Setup Shaders and textures
//-------------------------------------------------------
auto meshModel = femModel->getCollisionModel();
if(!meshModel)
{
std::cout << "There is no collision model attached to this scene object" << std::endl;
}
else
{
auto planeMeshCollisionPairs = std::make_shared<imstk::CollisionManager>();
planeMeshCollisionPairs->setModels(meshModel, plane);
sdkSimulator->addCollisionPair(planeMeshCollisionPairs);
auto planeToMeshCollisionDetection = std::make_shared<imstk::PlaneToMeshCollision>();
sdkSimulator->registerCollisionDetection(planeToMeshCollisionDetection);
//-------------------------------------------------------
// Enable contact handling between scene actors 1 and 2
//-------------------------------------------------------
auto planeToMeshContact = std::make_shared<imstk::PenaltyContactFemToStatic>(false);
planeToMeshContact->setCollisionPairs(planeMeshCollisionPairs);
planeToMeshContact->setSceneObjects(staticObject, femModel);
imstk::Shaders::createShader("wetshader", dataPath+"/shaders/wet_vert.glsl", dataPath+"/shaders/wet_frag.glsl", "");
auto meshRenderDetail = std::make_shared<imstk::RenderDetail>(IMSTK_RENDER_FACES | IMSTK_RENDER_NORMALS );
meshRenderDetail->setAmbientColor(imstk::Color(0.2,0.2,0.2,1.0));
meshRenderDetail->setDiffuseColor(imstk::Color::colorRed);
meshRenderDetail->setSpecularColor(imstk::Color(1.0, 1.0, 1.0,0.5));
meshRenderDetail->setShininess(100);
// meshRenderDetail->addShaderProgram("wetshader");
// meshRenderDetail->addTexture("decal",
// dataPath+"/textures/brainx.bmp",
// "textureDecal",
// "wetshader");
//
// meshRenderDetail->addTexture("bump",
// dataPath+"/textures/metalbump.jpg",
// "textureBump",
// "wetshader");
sdkSimulator->registerContactHandling(planeToMeshContact);
if(visualMesh)
{
visualMesh->updateInitialVertices();
visualMesh->setRenderDetail(meshRenderDetail);
volumeMesh->attachSurfaceMesh(visualMesh/*,meshWeightsFile*/);
}
femModel->setVisualModel(visualModel);
sdk->addSceneActor(femModel, femSimulator);
//-------------------------------------------------------
// Customize the viewer
......@@ -143,7 +161,7 @@ int main(int ac, char **av)
// Camera setup
auto sceneCamera = imstk::Camera::getDefaultCamera();
sceneCamera->setPos(-60,0,0);
sceneCamera->setPos(60,0,0);
sceneCamera->setZoom(.5);
scene->addCamera(sceneCamera);
......
......@@ -40,3 +40,7 @@ set_target_properties(${APP}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)
set(SOURCE_PATH ${PROJECT_SOURCE_DIR}/Testing)
set(BINARY_PATH ${PROJECT_BINARY_DIR}/Testing/ExamplesData/Box)
configure_file(${PROJECT_SOURCE_DIR}/Testing/path.in ${CMAKE_CURRENT_BINARY_DIR}/Config.paths @ONLY)
......@@ -41,15 +41,38 @@
#include "VirtualTools/ToolCoupler.h"
#include "Rendering/InitVTKRendering.h"
#include "Testing/ReadPaths.h"
int main(int ac, char** av)
{
std::string configFile = "./box.config";
std::string configPaths = "./Config.paths";
if(ac > 1)
{
configFile = av[1];
configPaths = av[1];
}
auto paths = imstk::ReadPaths(configPaths);
if(std::get<imstk::Path::Binary>(paths).empty() &&
std::get<imstk::Path::Source>(paths).empty())
{
std::cerr << "Error: Configuration file not found." << std::endl;
std::cerr << std::endl;
std::cerr << "\tUsage: " << av[0] << " /path_to/Config.paths" << std::endl;
std::cerr << std::endl;
return EXIT_FAILURE;
}
std::string configFile = std::get<imstk::Path::Binary>(paths)+"/box.config";
std::string meshFile = std::get<imstk::Path::Binary>(paths)+"/box.veg";
std::string meshWeightsFile = std::get<imstk::Path::Binary>(paths)+"/box.interp";
std::string meshSurfaceFile = std::get<imstk::Path::Binary>(paths)+"/box.vtk";
std::string loliMeshFile = std::get<imstk::Path::Binary>(paths)+"/loli.vtk";
if(configFile.empty())
{
std::cerr << "Vega configuration file not found." << std::endl;
return EXIT_FAILURE;
}
// initRenderDelegates();
imstk::InitVTKRendering();
imstk::InitIODelegates();
......@@ -85,10 +108,10 @@ int main(int ac, char** av)
// create a Vega based FEM object and attach it to the fem simulator
auto femObject =
std::make_shared<imstk::VegaFEMDeformableSceneObject>("./box.veg",configFile);
std::make_shared<imstk::VegaFEMDeformableSceneObject>(meshFile,configFile);
femObject->setContactForcesOn();
auto meshRenderDetail = std::make_shared<imstk::RenderDetail>(IMSTK_RENDER_WIREFRAME);
auto meshRenderDetail = std::make_shared<imstk::RenderDetail>(IMSTK_RENDER_SURFACE);
meshRenderDetail->setAmbientColor(imstk::Color(0.2,0.2,0.2,1.0));
meshRenderDetail->setDiffuseColor(imstk::Color::colorGray);
meshRenderDetail->setSpecularColor(imstk::Color(1.0, 1.0, 1.0,0.5));
......@@ -98,7 +121,7 @@ int main(int ac, char** av)
auto volumeMesh = std::static_pointer_cast<imstk::VegaVolumetricMesh>(femObject->getPhysicsModel()->getMesh());
auto visualModel = std::make_shared<imstk::MeshModel>();
visualModel->load("./box.vtk");
visualModel->load(meshSurfaceFile);
femObject->setVisualModel(visualModel);
auto visualMesh = visualModel->getMeshAs<imstk::SurfaceMesh>();
......@@ -106,8 +129,8 @@ int main(int ac, char** av)
if(visualMesh)
{
visualMesh->updateInitialVertices();
// visualMesh->setRenderDetail(meshRenderDetail);
volumeMesh->attachSurfaceMesh(visualMesh,"./box.interp");
visualMesh->setRenderDetail(meshRenderDetail);
volumeMesh->attachSurfaceMesh(visualMesh);
}
sdk->addSceneActor(femObject, femSimulator);
......@@ -136,16 +159,16 @@ int main(int ac, char** av)
auto loliSceneObject = std::make_shared<imstk::StaticSceneObject>();
auto loliCollisionModel = std::make_shared<imstk::MeshCollisionModel>();
loliCollisionModel->loadTriangleMesh("./loli.vtk");
loliCollisionModel->loadTriangleMesh(loliMeshFile);
loliSceneObject->setModel(loliCollisionModel);
auto loliMesh = loliCollisionModel->getMesh();
imstk::BaseMesh::TransformType transform =
Eigen::Translation3d(imstk::Vec3d(0,0,0))*Eigen::Scaling(0.1);
auto loliRenderDetail = std::make_shared<imstk::RenderDetail>(IMSTK_RENDER_WIREFRAME);
auto loliRenderDetail = std::make_shared<imstk::RenderDetail>(IMSTK_RENDER_SURFACE);
loliRenderDetail->setAmbientColor(imstk::Color(0.2, 0.2, 0.2, 0.5));
loliRenderDetail->setDiffuseColor(imstk::Color::colorYellow);
loliRenderDetail->setDiffuseColor(imstk::Color::colorGray);
loliRenderDetail->setSpecularColor(imstk::Color(1.0, 1.0, 1.0, 0.5));
loliRenderDetail->setShininess(20.0);
......
......@@ -38,3 +38,7 @@ set_target_properties(${APP}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)
set(SOURCE_PATH ${PROJECT_SOURCE_DIR}/Testing)
set(BINARY_PATH ${PROJECT_BINARY_DIR}/Testing/ExamplesData/Shaders/ShadersData)
configure_file(${PROJECT_SOURCE_DIR}/Testing/path.in ${CMAKE_CURRENT_BINARY_DIR}/Config.paths @ONLY)
......@@ -28,8 +28,29 @@
#include "Rendering/InitVTKRendering.h"
#include "IO/IOMesh.h"
int main()
#include "Testing/ReadPaths.h"
int main(int ac, char** av)
{
std::string configPaths = "./Config.paths";
if(ac > 1)
{
configPaths = av[1];
}
auto paths = imstk::ReadPaths(configPaths);
if(std::get<imstk::Path::Binary>(paths).empty() &&
std::get<imstk::Path::Source>(paths).empty())
{
std::cerr << "Error: Configuration file not found." << std::endl;
std::cerr << std::endl;
std::cerr << "\tUsage: " << av[0] << " /path_to/Config.paths" << std::endl;
std::cerr << std::endl;
return EXIT_FAILURE;
}
auto dataPath = std::get<imstk::Path::Binary>(paths);
imstk::InitVTKRendering();
imstk::InitIODelegates();
......@@ -54,7 +75,9 @@ int main()
//-------------------------------------------------------
// Setup Shaders and textures
//-------------------------------------------------------
imstk::Shaders::createShader("wetshader", "ShadersData/shaders/wet_vert.glsl", "ShadersData/shaders/wet_frag.glsl", "");
imstk::Shaders::createShader("wetshader",
dataPath+"/shaders/wet_vert.glsl",
dataPath+"/shaders/wet_frag.glsl", "");
// Mesh render detail
auto meshRenderDetail = std::make_shared<imstk::RenderDetail>(IMSTK_RENDER_FACES | IMSTK_RENDER_NORMALS );
......@@ -64,8 +87,8 @@ int main()
meshRenderDetail->setShininess(20.0);
meshRenderDetail->addShaderProgram("wetshader");
meshRenderDetail->addTexture("decal", "ShadersData/textures/brainx.bmp", "textureDecal", "wetshader");
meshRenderDetail->addTexture("bump", "ShadersData/textures/metalbump.jpg", "textureBump", "wetshader");
meshRenderDetail->addTexture("decal", dataPath+"/textures/brainx.bmp", "textureDecal", "wetshader");
meshRenderDetail->addTexture("bump", dataPath+"/textures/metalbump.jpg", "textureBump", "wetshader");
// Plane render detail
auto planeMeshRenderDetail = std::make_shared<imstk::RenderDetail>(IMSTK_RENDER_FACES | IMSTK_RENDER_NORMALS);
......@@ -75,8 +98,8 @@ int main()
planeMeshRenderDetail->setShininess(20.0);
planeMeshRenderDetail->addShaderProgram("wetshader");
planeMeshRenderDetail->addTexture("decal", "ShadersData/textures/brain_outside.jpg", "textureDecal", "wetshader");
planeMeshRenderDetail->addTexture("bump", "ShadersData/textures/metalbump.jpg", "textureBump", "wetshader");
planeMeshRenderDetail->addTexture("decal", dataPath+"/textures/brain_outside.jpg", "textureDecal", "wetshader");
planeMeshRenderDetail->addTexture("bump", dataPath+"/textures/metalbump.jpg", "textureBump", "wetshader");
//-------------------------------------------------------
// Customize the scene
......@@ -87,7 +110,7 @@ int main()
// Setup Cube
auto cubeModel = std::make_shared<imstk::MeshModel>();
cubeModel->load("ShadersData/models/brain.obj");
cubeModel->load(dataPath+"/models/brain.obj");
//cubeModel->load("ShadersData/models/brain.3ds");
cubeModel->setRenderDetail(meshRenderDetail);
......@@ -97,7 +120,7 @@ int main()
// Setup Plane
auto planeModel = std::make_shared<imstk::MeshModel>();
planeModel->load("ShadersData/models/plane.obj");
planeModel->load(dataPath+"/models/plane.obj");
planeModel->setRenderDetail(planeMeshRenderDetail);
auto planeObject = std::make_shared<imstk::StaticSceneObject>();
......
......@@ -317,7 +317,7 @@ readWeights(std::shared_ptr<SurfaceMesh> surfaceMesh,
weigths.push_back(w[3]);
}
std::cout << "\tTotal # of weights read: " << weigths.size() / this->mesh->getNumElementVertices() << std::endl;
std::cout << "\tTotal # of weights read: " << weigths.size() / verticesPerElement << std::endl;
}
//---------------------------------------------------------------------------
......@@ -388,6 +388,7 @@ generateWeigths(std::shared_ptr<SurfaceMesh> surfaceMesh,
if(saveToDisk)
{
// TODO: add to logger
this->saveWeights(surfaceMesh, filename);
}
}
......
......@@ -126,7 +126,7 @@ std::shared_ptr< OdeSystemState > DeformableSceneObject::getPreviousState()
}
//---------------------------------------------------------------------------
Eigen::Map<Vec3d> DeformableSceneObject::getVelocity(const int index)
Eigen::Map<Vec3d> DeformableSceneObject::getVelocity(const int index) const
{
auto velocities = this->currentState->getVelocities();
return Vec3d::Map(&velocities(index));
......@@ -138,4 +138,16 @@ const Vec3d& DeformableSceneObject::getGravity() const
return this->gravity;
}
//---------------------------------------------------------------------------
void DeformableSceneObject::updateExternalForces(const std::unordered_map<size_t,Vec3d> &forces)
{
auto externalForce = Matrixd::Map(this->f.data(), 3, this->numOfNodes);
for(const auto & force : forces)
{
auto i = force.first;
externalForce.col(i) -= force.second;
}
}
}
......@@ -86,7 +86,7 @@ public:
///
/// \brief Returns velocity of at a given location for the current state.
///
Eigen::Map<Vec3d> getVelocity(const int index);
Eigen::Map<Vec3d> getVelocity(const int index) const override;
///
/// \brief Returns velocity of at a given location for the current state.
......@@ -96,15 +96,7 @@ public:
///
/// \brief Update cumulative forces
///
void updateExternalForces(const std::unordered_map<size_t,Vec3d> &forces)
{
auto externalForce = Matrixd::Map(this->f.data(),3,this->numOfNodes);
for(const auto &force : forces)
{
auto i = force.first;
externalForce.col(i) -= force.second;
}
}
void updateExternalForces(const std::unordered_map<size_t,Vec3d> &forces);
private:
///////////////////////////////////////////////////////////////////////////////
......@@ -114,18 +106,18 @@ private:
///serialize function explicity writes the object to the memory block
///each scene object should know how to write itself to a memory block
void serialize(void *){}
void serialize(void *) override {}
///Unserialize function can recover the object from the memory location
void unSerialize(void *){};
void unSerialize(void *) override {};
///this function may not be used
///every Scene Object should know how to clone itself. Since the data structures will be
///in the beginning of the modules(such as simulator, viewer, collision etc.)
std::shared_ptr<SceneObject> clone(){return nullptr;};
std::shared_ptr<SceneObject> clone() override { return nullptr; };
/// \brief print information related the scene object
void printInfo() const{};
void printInfo() const override {};
protected:
std::shared_ptr<TimeIntegrator> odeSolver; ///> Integration scheme
......@@ -137,7 +129,7 @@ protected:
SparseMatrixd M; ///> Mass matrix
SparseMatrixd C; ///> Raleigh Damping matrix
SparseMatrixd D; ///> Raleigh Damping matrix
SparseMatrixd D; ///> Lagrangian Damping matrix
SparseMatrixd K; ///> Stiffness matrix
Vectord f; ///> Accumulative forces vector
......
......@@ -150,7 +150,7 @@ const std::unordered_map< int,Vec3d> &SceneObject::getContactPoints() const
}
//---------------------------------------------------------------------------
Eigen::Map<Vec3d> SceneObject::getVelocity(const int)
Eigen::Map<Vec3d> SceneObject::getVelocity(const int) const
{
// TODO: Dangerous - Make this function pure virtual.
return Eigen::Map<Vec3d>(nullptr);
......
......@@ -186,7 +186,7 @@ public:
/// \brief Returns velocity of at a given location
/// (not given node) in contact force vector
///
virtual Eigen::Map<Vec3d> getVelocity(const int);
virtual Eigen::Map<Vec3d> getVelocity(const int) const;
///
/// \brief Set all contact forces to zero (if any)
......
......@@ -25,6 +25,9 @@ OdeSystem::OdeSystem(): BaseSystem(systemMatrix, rhs)
{
}
//---------------------------------------------------------------------------
OdeSystem::~OdeSystem() {}
//---------------------------------------------------------------------------
void OdeSystem::setJaconbianFv(OdeSystem::JacobianOperatorType newDFv)
{
......
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