Commit 4e92d9c1 authored by Ricardo Ortiz's avatar Ricardo Ortiz
Browse files

ENH: Improve support for data reading

by examples and unit tests.
parent 9e97b77f
......@@ -14,4 +14,7 @@ target_link_libraries(Assembler
Event
ContactHandling
Simulators
CollisionContext
TimeIntegrators
SceneModels
)
......@@ -120,3 +120,23 @@ function(DOWNLOAD_DATA url filename)
message("${STATUS1}")
endif()
endfunction(DOWNLOAD_DATA)
function(MIDAS_DOWNLOAD MIDAS_URL FILE_SHA1 LOCAL_FILE)
if(NOT EXISTS ${LOCAL_FILE})
file(
DOWNLOAD "${MIDAS_URL}"
"${LOCAL_FILE}"
SHOW_PROGRESS
STATUS DOWNLOAD_STATUS
TIMEOUT 15
TLS_VERIFY ON
EXPECTED_HASH SHA1=${FILE_SHA1}
)
list(GET DOWNLOAD_STATUS 0 STATUS0)
if(NOT STATUS0 STREQUAL "0")
list(GET DOWNLOAD_STATUS 1 STATUS1)
message("${STATUS1}")
endif()
endif()
endfunction()
......@@ -15,3 +15,7 @@ target_link_libraries(CollisionContext
Simulators
ContactHandling
)
if(BUILD_TESTING)
add_subdirectory(UnitTests)
endif()
set(Module CollisionContext)
add_executable(${Module}UnitTestRunner
${BANDIT_RUNNER}
CollisionContextSpec.cpp
)
target_compile_options(${Module}UnitTestRunner PRIVATE $<$<CXX_COMPILER_ID:GNU>:-Wno-old-style-cast -Wno-multichar -Wno-type-limits>)
target_link_libraries(${Module}UnitTestRunner
CollisionContext
Event
Collision
Simulators
ContactHandling)
simple_test(${Module} --reporter=xunit)
// This file is part of the SimMedTK project.
// Copyright (c) Center for Modeling, Simulation, and 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
//
// 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.
//
//---------------------------------------------------------------------------
//
// Authors:
//
// Contact:
//---------------------------------------------------------------------------
#include <bandit/bandit.h>
#include <memory>
// SimMedTK includes
#include "CollisionContext/CollisionContext.h"
using namespace bandit;
go_bandit([](){
describe("Vega Volumetric Mesh", []() {
it("constructs", []() {
auto collisionContext = std::make_shared<CollisionContext>();
AssertThat(collisionContext != nullptr, IsTrue());
});
});
});
......@@ -14,6 +14,7 @@ target_link_libraries(ContactHandling
Collision
Simulators
Solvers
SceneModels
)
if(BUILD_TESTING)
......
......@@ -84,8 +84,6 @@ go_bandit([]() {
handler->setSceneObjects(plane,fem);
AssertThat(handler->getFirstSceneObject() == plane, IsTrue());
AssertThat(handler->getSecondSceneObject() == fem, IsTrue());
AssertThat(handler->getFirstSceneObject()->getType() == core::ClassType::StaticSceneObject, IsTrue());
AssertThat(handler->getSecondSceneObject()->getType() == core::ClassType::VegaFemSceneObject, IsTrue());
});
it("computes contact force ", []() {
......
......@@ -23,33 +23,3 @@ set_target_properties(${APP}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)
set(${APP}_DATA "${CMAKE_CURRENT_BINARY_DIR}")
if(NOT EXISTS ${${APP}_DATA})
file(MAKE_DIRECTORY ${${APP}_DATA})
endif()
set(FILE_URL http://midas3.kitware.com/midas/download/item/318709/nidus.tar)
set(FILE_SHA1 40206fc9b45b9bc32ebda92c64d1553038ab7646)
set(LOCAL_FILE ${EXAMPLES_DATA}/nidus.tar)
midas_download(${FILE_URL} ${FILE_SHA1} ${LOCAL_FILE})
# Extract data
set(DATA
${${APP}_DATA}/nidus-empty.bou
${${APP}_DATA}/nidus.config
${${APP}_DATA}/nidus1764.interp
${${APP}_DATA}/nidus1764.mass
${${APP}_DATA}/nidusS7415.vtk
${${APP}_DATA}/nidusV1764.vtk
)
add_custom_command(
TARGET ${APP}
POST_BUILD
# BYPRODUCTS ${DATA}
COMMAND ${CMAKE_COMMAND} -E tar xf ${LOCAL_FILE}
WORKING_DIRECTORY ${${APP}_DATA}
COMMENT "-- Unpacking ${LOCAL_FILE}"
)
set(EXAMPLES_DATA ${CMAKE_CURRENT_BINARY_DIR}/Data)
if(NOT EXISTS ${EXAMPLES_DATA})
file(MAKE_DIRECTORY ${EXAMPLES_DATA})
endif()
function(MIDAS_DOWNLOAD MIDAS_URL FILE_SHA1 LOCAL_FILE)
if(NOT EXISTS ${LOCAL_FILE})
file(
DOWNLOAD "${MIDAS_URL}"
"${LOCAL_FILE}"
SHOW_PROGRESS
STATUS DOWNLOAD_STATUS
TIMEOUT 15
TLS_VERIFY ON
EXPECTED_HASH SHA1=${FILE_SHA1}
)
list(GET DOWNLOAD_STATUS 0 STATUS0)
if(NOT STATUS0 STREQUAL "0")
list(GET DOWNLOAD_STATUS 1 STATUS1)
message("${STATUS1}")
endif()
endif()
endfunction()
add_subdirectory(FEMSimulator)
add_subdirectory(LaparoscopicCamera)
add_subdirectory(AVMNidus)
......
......@@ -22,83 +22,3 @@ set_target_properties(${APP}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)
set(${APP}_DATA "${CMAKE_CURRENT_BINARY_DIR}")
if(NOT EXISTS ${${APP}_DATA})
file(MAKE_DIRECTORY ${${APP}_DATA})
endif()
set(FILE_URL http://midas3.kitware.com/midas/download/item/318708/box.tar)
set(FILE_SHA1 928294a91477bc5d6fa494afb34016ba7f0b40c5)
set(LOCAL_FILE ${EXAMPLES_DATA}/box.tar)
midas_download(${FILE_URL} ${FILE_SHA1} ${LOCAL_FILE})
# Extract data
set(DATA
${${APP}_DATA}/box.bou
${${APP}_DATA}/box.config
${${APP}_DATA}/box.interp
${${APP}_DATA}/box.mass
${${APP}_DATA}/box.vtk
${${APP}_DATA}/box.veg
)
add_custom_command(
TARGET ${APP}
POST_BUILD
# BYPRODUCTS ${DATA}
COMMAND ${CMAKE_COMMAND} -E tar xf ${LOCAL_FILE}
WORKING_DIRECTORY ${${APP}_DATA}
COMMENT "Unpacking ${LOCAL_FILE}"
)
# Configure an example to run in the build directory:
# set(dropbox_files
# dropbox.bou
# dropbox.config
# dropbox.lights
# dropbox.mtl
# dropbox.vtk
# dropbox.veg
# )
# set(SimMedTK_VEGA_EXAMPLE_DIR "${CMAKE_CURRENT_BINARY_DIR}")
# foreach (_file ${dropbox_files})
# configure_file(
# ${CMAKE_CURRENT_SOURCE_DIR}/dropbox/${_file}.in
# ${CMAKE_CURRENT_BINARY_DIR}/dropbox/${_file}
# @ONLY
# )
# endforeach()
# Generate the mass-matrix and interpolation simulation
# inputs from the volume mesh and surface mesh.
# add_custom_command(
# OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/dropbox/dropbox.mass"
# COMMAND
# "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/generateMassMatrix"
# "${CMAKE_CURRENT_BINARY_DIR}/dropbox/dropbox.veg"
# "${CMAKE_CURRENT_BINARY_DIR}/dropbox/dropbox.mass"
# MAIN_DEPENDENCY
# "${CMAKE_CURRENT_BINARY_DIR}/dropbox/dropbox.veg"
# COMMENT "Generating mass matrix for dropbox example."
# )
# add_custom_command(
# OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/dropbox/dropbox.interp"
# COMMAND
# "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/generateInterpolant"
# "${CMAKE_CURRENT_BINARY_DIR}/dropbox/dropbox.veg"
# "${CMAKE_CURRENT_BINARY_DIR}/dropbox/dropbox.obj"
# "${CMAKE_CURRENT_BINARY_DIR}/dropbox/dropbox.interp"
# MAIN_DEPENDENCY
# "${CMAKE_CURRENT_BINARY_DIR}/dropbox/dropbox.veg"
# DEPENDS
# "${CMAKE_CURRENT_BINARY_DIR}/dropbox/dropbox.obj"
# "${CMAKE_CURRENT_BINARY_DIR}/dropbox/dropbox.mtl"
# COMMENT "Generating surface interpolation weights for dropbox example."
# )
# add_custom_target(dropbox_aux ALL
# DEPENDS
# "${CMAKE_CURRENT_BINARY_DIR}/dropbox/dropbox.interp"
# "${CMAKE_CURRENT_BINARY_DIR}/dropbox/dropbox.mass"
# )
......@@ -21,30 +21,3 @@ set_target_properties(${APP}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)
set(${APP}_DATA "${CMAKE_CURRENT_BINARY_DIR}")
if(NOT EXISTS ${${APP}_DATA})
file(MAKE_DIRECTORY ${${APP}_DATA})
endif()
set(FILE_URL http://midas3.kitware.com/midas/download/item/318840/CameraNavAppData.tar)
set(FILE_SHA1 405ac1c0c2bb5a7ef5395887ae2b8fcc620493f5)
set(LOCAL_FILE ${EXAMPLES_DATA}/CameraNavAppData.tar)
midas_download(${FILE_URL} ${FILE_SHA1} ${LOCAL_FILE})
# Extract data
set(DATA
${${APP}_DATA}/target.png
${${APP}_DATA}/viewfinder.png
)
add_custom_command(
TARGET ${APP}
POST_BUILD
# BYPRODUCTS ${DATA}
COMMAND ${CMAKE_COMMAND} -E tar xf ${LOCAL_FILE}
WORKING_DIRECTORY ${${APP}_DATA}
COMMENT "Unpacking ${LOCAL_FILE}"
)
......@@ -20,22 +20,3 @@ set_target_properties(${APP}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)
set(${APP}_DATA "${CMAKE_CURRENT_BINARY_DIR}")
if(NOT EXISTS ${${APP}_DATA})
file(MAKE_DIRECTORY ${${APP}_DATA})
endif()
set(FILE_URL http://midas3.kitware.com/midas/download/item/318851/ShadersData.tar)
set(FILE_SHA1 df719673804075b4505ea267b39e5cd68568f72c)
set(LOCAL_FILE ${EXAMPLES_DATA}/ShadersData.tar)
midas_download(${FILE_URL} ${FILE_SHA1} ${LOCAL_FILE})
add_custom_command(
TARGET ${APP}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E tar xf ${LOCAL_FILE}
WORKING_DIRECTORY ${${APP}_DATA}
COMMENT "-- Unpacking ${LOCAL_FILE}"
)
set(Module IO)
configure_file(IOMeshSpec.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/IOMeshSpec.cpp @ONLY)
add_executable(${Module}UnitTestRunner
${BANDIT_RUNNER}
${CMAKE_CURRENT_BINARY_DIR}/IOMeshSpec.cpp
IOMeshSpec.cpp
)
target_compile_options(${Module}UnitTestRunner PRIVATE $<$<CXX_COMPILER_ID:GNU>:-Wno-old-style-cast -Wno-multichar -Wno-type-limits>)
......@@ -12,3 +10,7 @@ target_compile_options(${Module}UnitTestRunner PRIVATE $<$<CXX_COMPILER_ID:GNU>:
target_link_libraries(${Module}UnitTestRunner Core Mesh IO)
simple_test(${Module} --reporter=spec)
set(SOURCE_PATH ${PROJECT_SOURCE_DIR}/Testing/Models)
set(BINARY_PATH ${PROJECT_BINARY_DIR}/Testing/Models)
configure_file(${PROJECT_SOURCE_DIR}/Testing/path.in ${CMAKE_CURRENT_BINARY_DIR}/${Module}Config.paths @ONLY)
......@@ -30,16 +30,19 @@
#include "IO/IOMesh.h"
#include "IO/InitIO.h"
#include "Core/MakeUnique.h"
#include "Testing/ReadPaths.h"
const std::string ds3MeshFileName = "@CMAKE_SOURCE_DIR@/Testing/Models/cube.3ds";
const std::string objMeshFileName = "@CMAKE_SOURCE_DIR@/Testing/Models/cube.obj";
const std::string vegMeshFileName = "@CMAKE_SOURCE_DIR@/Testing/Models/SampleMesh.veg";
const std::string plyMeshFileName = "@CMAKE_SOURCE_DIR@/Testing/Models/sphere.ply";
const std::string stlMeshFileName = "@CMAKE_SOURCE_DIR@/Testing/Models/sphere.stl";
const std::string vtkMeshFileName = "@CMAKE_SOURCE_DIR@/Testing/Models/sphere.vtk";
const std::string vtuMeshFileName = "@CMAKE_SOURCE_DIR@/Testing/Models/sphere.vtu";
const std::string vtuPropFileName = "@CMAKE_BINARY_DIR@/Testing/Models/TestMesh.vtu";
const std::string vtpMeshFileName = "@CMAKE_SOURCE_DIR@/Testing/Models/sphere.vtp";
auto paths = imstk::ReadPaths("./IOConfig.paths");
const std::string ds3MeshFileName = std::get<imstk::Path::Source>(paths)+"/cube.3ds";
const std::string objMeshFileName = std::get<imstk::Path::Source>(paths)+"/cube.obj";
const std::string vegMeshFileName = std::get<imstk::Path::Source>(paths)+"/SampleMesh.veg";
const std::string plyMeshFileName = std::get<imstk::Path::Source>(paths)+"/sphere.ply";
const std::string stlMeshFileName = std::get<imstk::Path::Source>(paths)+"/sphere.stl";
const std::string vtkMeshFileName = std::get<imstk::Path::Source>(paths)+"/sphere.vtk";
const std::string vtuMeshFileName = std::get<imstk::Path::Source>(paths)+"/sphere.vtu";
const std::string vtuPropFileName = std::get<imstk::Path::Binary>(paths)+"/TestMesh.vtu";
const std::string vtpMeshFileName = std::get<imstk::Path::Source>(paths)+"/sphere.vtp";
using namespace bandit;
......
set(Module Mesh)
configure_file(VegaVolumetricMeshSpec.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/VegaVolumetricMeshSpec.cpp @ONLY)
add_executable(${Module}UnitTestRunner
${BANDIT_RUNNER}
${CMAKE_CURRENT_BINARY_DIR}/VegaVolumetricMeshSpec.cpp
VegaVolumetricMeshSpec.cpp
)
target_compile_options(${Module}UnitTestRunner PRIVATE $<$<CXX_COMPILER_ID:GNU>:-Wno-old-style-cast -Wno-multichar -Wno-type-limits>)
target_link_libraries(${Module}UnitTestRunner Core Mesh IO)
simple_test(${Module} --reporter=xunit)
set(SOURCE_PATH ${PROJECT_SOURCE_DIR}/Testing/Models)
set(BINARY_PATH ${PROJECT_BINARY_DIR})
configure_file(${PROJECT_SOURCE_DIR}/Testing/path.in ${CMAKE_CURRENT_BINARY_DIR}/${Module}Config.paths @ONLY)
......@@ -29,17 +29,17 @@
#include "Mesh/SurfaceMesh.h"
#include "IO/IOMesh.h"
#include "IO/InitIO.h"
const std::string vegaMeshFileName = "@CMAKE_SOURCE_DIR@/Testing/Models/SampleMesh.veg";
#include "Testing/ReadPaths.h"
using namespace bandit;
go_bandit([](){
InitIODelegates();
describe("Vega Volumetric Mesh", []() {
auto paths = imstk::ReadPaths("./MeshConfig.paths");
describe("Vega Volumetric Mesh", [&]() {
auto ioMesh = std::make_shared<IOMesh>();
ioMesh->read(vegaMeshFileName);
ioMesh->read(std::get<imstk::Path::Source>(paths)+"/SampleMesh.veg");
auto vegaMesh = std::static_pointer_cast<VegaVolumetricMesh>(ioMesh->getMesh());
it("constructs", []() {
......
......@@ -316,8 +316,8 @@ readWeights(std::shared_ptr<SurfaceMesh> surfaceMesh,
const auto verticesPerElement = this->mesh->getNumElementVertices();
int index;
int v[verticesPerElement];
double w[verticesPerElement];
std::vector<int> v(verticesPerElement,0.0);
std::vector<double> w(verticesPerElement,0.0);
while(fileStream >> index
>> v[0] >> w[0]
......
......@@ -8,3 +8,7 @@ add_executable(${Module}UnitTestRunner
target_compile_options(${Module}UnitTestRunner PRIVATE $<$<CXX_COMPILER_ID:GNU>:-Wno-old-style-cast -Wno-multichar -Wno-type-limits>)
target_link_libraries(${Module}UnitTestRunner Core Mesh IO Solvers TimeIntegrators SceneModels)
simple_test(${Module} --reporter=xunit)
set(SOURCE_PATH ${PROJECT_SOURCE_DIR})
set(BINARY_PATH ${PROJECT_BINARY_DIR}/Testing/ExamplesData/Box)
configure_file(${PROJECT_SOURCE_DIR}/Testing/path.in ${CMAKE_CURRENT_BINARY_DIR}/${Module}Config.paths @ONLY)
......@@ -28,6 +28,7 @@
// SimMedTK includes
#include "SceneModels/VegaFEMDeformableSceneObject.h"
#include "IO/InitIO.h"
#include "Testing/ReadPaths.h"
using namespace bandit;
using namespace core;
......@@ -35,9 +36,12 @@ using namespace core;
go_bandit([]()
{
InitIODelegates();
auto paths = imstk::ReadPaths("./SceneModelsConfig.paths");
describe("Vega Deformable Scene Object", [&]()
{
auto sceneObject = std::make_shared<VegaFEMDeformableSceneObject>("box.veg","box.config");
auto sceneObject = std::make_shared<VegaFEMDeformableSceneObject>(std::get<imstk::Path::Binary>(paths)+"/box.veg",
std::get<imstk::Path::Binary>(paths)+"/box.config");
it("constructs", [&]()
{
AssertThat(sceneObject != nullptr, IsTrue());
......
......@@ -363,6 +363,7 @@ void VegaFEMDeformableSceneObject::initialize()
this->initTangentStiffnessMatrix();
this->gravityForce.resize(this->numOfDOF);
this->gravityForce.setZero();
this->gravity *= this->vegaFemConfig->floatsOptionMap.at("gravity");
this->volumetricMesh->computeGravity(this->gravity,this->gravityForce);
}
......
Supports Markdown
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