Commit 859a6a9e authored by Nghia Truong's avatar Nghia Truong Committed by Nghia Truong

Merge branch 'master' into 'FixSPHBoundaryCondition'

# Conflicts:
#   Source/Collision/CollisionHandling/imstkSPHCollisionHandling.cpp
parents a34d9928 137d2d48
Pipeline #141254 failed with stage
......@@ -31,7 +31,8 @@
using namespace imstk;
void playSound(const std::string& filename)
void
playSound(const std::string& filename)
{
#ifdef iMSTK_AUDIO_ENABLED
// Load a sound buffer from a .wav file
......@@ -77,7 +78,8 @@ void playSound(const std::string& filename)
#endif
}
void playMusic(const std::string& filename)
void
playMusic(const std::string& filename)
{
#ifdef iMSTK_AUDIO_ENABLED
// Load an ogg music file
......@@ -117,7 +119,8 @@ void playMusic(const std::string& filename)
/// \brief This example demonstrates the audio feature in imstk.
/// NOTE: Example modified from SFML/Examples
///
int main()
int
main()
{
// Initialize g3logger
auto logger = std::make_shared<LogUtility>();
......
......@@ -54,10 +54,11 @@ using namespace imstk;
/// \brief This example demonstrates bone drilling.
/// NOTE: Requires GeoMagic Touch device
///
int main()
int
main()
{
// SDK and Scene
auto sdk = std::make_shared<SimulationManager>();
auto sdk = std::make_shared<SimulationManager>();
auto scene = sdk->createNewScene("BoneDrilling");
// Add virtual coupling object in the scene.
......@@ -103,7 +104,7 @@ int main()
// Create a collision graph
auto graph = scene->getCollisionGraph();
auto pair = graph->addInteractionPair(bone,
auto pair = graph->addInteractionPair(bone,
drill,
CollisionDetection::Type::PointSetToSphere,
CollisionHandling::Type::BoneDrilling,
......
......@@ -38,7 +38,8 @@ using namespace imstk;
/// \brief This example demonstrates controlling the camera
/// using external device. NOTE: Requires GeoMagic Touch device
///
int main()
int
main()
{
#ifndef iMSTK_USE_OPENHAPTICS
std::cout << "Audio not enabled at build time" << std::endl;
......@@ -46,7 +47,7 @@ int main()
#endif
// Create SDK and Scene
auto sdk = std::make_shared<SimulationManager>();
auto sdk = std::make_shared<SimulationManager>();
auto scene = sdk->createNewScene("CameraController");
#ifdef iMSTK_USE_OPENHAPTICS
......@@ -62,7 +63,7 @@ int main()
#endif
// Load Mesh
auto mesh = MeshIO::read(iMSTK_DATA_ROOT "/asianDragon/asianDragon.obj");
auto mesh = MeshIO::read(iMSTK_DATA_ROOT "/asianDragon/asianDragon.obj");
auto meshObject = std::make_shared<VisualObject>("meshObject");
meshObject->setVisualGeometry(mesh);
scene->addSceneObject(meshObject);
......
......@@ -20,81 +20,169 @@
=========================================================================*/
#include "imstkSimulationManager.h"
#include "imstkTetrahedralMesh.h"
#include "imstkMeshIO.h"
#include "imstkSceneObject.h"
#include "imstkDebugGeometry.h"
#include "imstkAPIUtilities.h"
#include "imstkSurfaceMesh.h"
#include <memory>
#include "imstkVTKViewer.h"
#include "imstkVTKTextStatusManager.h"
#include <thread>
#include <chrono>
using namespace imstk;
///
/// \brief This example demonstrates the debug rendering
///
int main()
std::shared_ptr<DebugRenderGeometry>
addPointsDebugRendering(const std::shared_ptr<Scene>& scene)
{
auto sdk = std::make_shared<SimulationManager>();
auto scene = sdk->createNewScene("DebugRendering");
scene->getCamera()->setPosition(0, 2.0, 15.0);
auto debugPoints = std::make_shared<DebugRenderPoints>("Debug Points");
auto material = std::make_shared<RenderMaterial>();
material->setDebugColor(Color::Blue);
debugPoints->setRenderMaterial(material);
scene->addDebugGeometry(debugPoints);
// Create debug triangles
auto debugTriangleGeo = std::make_shared<DebugRenderTriangles>("debugtriangles", 9);
StdVectorOfVec3d triVerts;
triVerts.push_back(Vec3d(0., 0., 0.));
triVerts.push_back(Vec3d(0., 10., 0.));
triVerts.push_back(Vec3d(0., 0., 10.));
triVerts.push_back(Vec3d(0., 0., 0.));
triVerts.push_back(Vec3d(10., 0., 0.));
triVerts.push_back(Vec3d(0., 0., 10.));
return std::dynamic_pointer_cast<DebugRenderGeometry>(debugPoints);
}
triVerts.push_back(Vec3d(0., 0., 0.));
triVerts.push_back(Vec3d(10., 0., 0.));
triVerts.push_back(Vec3d(0., 10., 0.));
std::shared_ptr<DebugRenderGeometry>
addLinesDebugRendering(const std::shared_ptr<Scene>& scene)
{
auto debugLines = std::make_shared<DebugRenderLines>("Debug Lines");
auto material = std::make_shared<RenderMaterial>();
material->setBackFaceCulling(false);
material->setDebugColor(Color::Green);
material->setLineWidth(2.0);
debugLines->setRenderMaterial(material);
scene->addDebugGeometry(debugLines);
debugTriangleGeo->setVertexData(triVerts);
return std::dynamic_pointer_cast<DebugRenderGeometry>(debugLines);
}
auto material = std::make_shared<RenderMaterial>();
std::shared_ptr<DebugRenderGeometry>
addTrianglesDebugRendering(const std::shared_ptr<Scene>& scene)
{
auto debugTriangles = std::make_shared<DebugRenderTriangles>("Debug Triangles");
auto material = std::make_shared<RenderMaterial>();
material->setBackFaceCulling(false);
material->setDebugColor(Color::Red);
material->setDisplayMode(RenderMaterial::DisplayMode::WIREFRAME_SURFACE);
debugTriangleGeo->setRenderMaterial(material);
scene->addDebugGeometry(debugTriangleGeo);
// Create debug Lines
auto debugLinesGeo = std::make_shared<DebugRenderLines>("debugLines");
StdVectorOfVec3d linesVerts;
linesVerts.push_back(Vec3d(15, 0, 0));
linesVerts.push_back(Vec3d(100, 0, 0));
debugTriangles->setRenderMaterial(material);
scene->addDebugGeometry(debugTriangles);
linesVerts.push_back(Vec3d(0, 15, 0));
linesVerts.push_back(Vec3d(0, 100, 0));
linesVerts.push_back(Vec3d(0, 0, 15));
linesVerts.push_back(Vec3d(0, 0, 100));
debugLinesGeo->setVertexData(linesVerts);
auto materialLines = std::make_shared<RenderMaterial>();
materialLines->setBackFaceCulling(false);
materialLines->setDebugColor(Color::Green);
materialLines->setLineWidth(2.0);
debugLinesGeo->setRenderMaterial(materialLines);
scene->addDebugGeometry(debugLinesGeo);
return std::dynamic_pointer_cast<DebugRenderGeometry>(debugTriangles);
}
// Add light
auto light = std::make_shared<DirectionalLight>("light");
light->setFocalPoint(Vec3d(5, -8, -5));
light->setIntensity(1);
scene->addLight(light);
Vec3d
getRandomPositions(double radius)
{
return radius * Vec3d(2.0 * static_cast<double>(rand()) / static_cast<double>(RAND_MAX) - 1.0,
2.0 * static_cast<double>(rand()) / static_cast<double>(RAND_MAX) - 1.0,
2.0 * static_cast<double>(rand()) / static_cast<double>(RAND_MAX) - 1.0);
}
// Run the simulation
///
/// \brief This example demonstrates debug rendering in iMSTK
///
int
main()
{
// SDK and Scene
auto sdk = std::make_shared<SimulationManager>();
auto scene = sdk->createNewScene("Debug rendering example");
sdk->setActiveScene(scene);
sdk->startSimulation(SimulationStatus::PAUSED);
// Get the VTKViewer
auto viewer = std::dynamic_pointer_cast<VTKViewer>(sdk->getViewer());
viewer->getVtkRenderWindow()->SetSize(1920, 1080);
auto statusManager = viewer->getTextStatusManager();
statusManager->setStatusFontSize(VTKTextStatusManager::Custom, 30);
statusManager->setStatusFontColor(VTKTextStatusManager::Custom, Color::Orange);
// Get VTK Renderer
auto renderer = std::dynamic_pointer_cast<VTKRenderer>(viewer->getActiveRenderer());
LOG_IF(FATAL, (!renderer)) << "Invalid renderer: Only VTKRenderer is supported for debug rendering";
auto debugPoints = addPointsDebugRendering(scene);
auto debugLines = addLinesDebugRendering(scene);
auto debugTriangles = addTrianglesDebugRendering(scene);
int mode = 0; // 0: add point, 1: add line, 2: add triangle
int count = 0; // The number of times cycling between modes
auto updateFunc =
[&](Module*) {
if (count > 5)
{
count = 0;
debugPoints->clear();
debugLines->clear();
debugTriangles->clear();
}
if (mode % 3 == 0)
{
debugPoints->appendVertex(getRandomPositions(15.0));
}
else if (mode % 3 == 1)
{
auto p = getRandomPositions(50.0);
auto shift = getRandomPositions(1.0);
debugLines->appendVertex(p + shift);
debugLines->appendVertex(-p + shift);
}
else
{
auto shift = getRandomPositions(10.0);
debugTriangles->appendVertex(getRandomPositions(5.0) + shift);
debugTriangles->appendVertex(getRandomPositions(5.0) + shift);
debugTriangles->appendVertex(getRandomPositions(5.0) + shift);
mode = -1;
++count;
}
++mode;
debugPoints->turnDataModifiedFlagON();
debugLines->turnDataModifiedFlagON();
debugTriangles->turnDataModifiedFlagON();
// Must call to update render data
for (auto& delegate : renderer->getDebugRenderDelegates())
{
delegate->updateDataSource();
}
statusManager->setCustomStatus("Primatives: " +
std::to_string(debugPoints->getNumVertices()) + " (points) | " +
std::to_string(debugLines->getNumVertices() / 2) + " (lines) | " +
std::to_string(debugTriangles->getNumVertices() / 3) + " (triangles)"
);
std::this_thread::sleep_for(std::chrono::milliseconds(500));
};
sdk->getSceneManager(scene)->setPostUpdateCallback(updateFunc);
// Set Camera configuration
auto cam = scene->getCamera();
cam->setPosition(Vec3d(0, 0, 50));
cam->setFocalPoint(Vec3d(0, 0, 0));
// Light
{
auto light = std::make_shared<DirectionalLight>("Light 1");
light->setFocalPoint(Vec3d(-1, -1, -1));
light->setIntensity(1);
scene->addLight(light);
}
{
auto light = std::make_shared<DirectionalLight>("Light 2");
light->setFocalPoint(Vec3d(1, -1, -1));
light->setIntensity(1);
scene->addLight(light);
}
// Run
sdk->startSimulation(SimulationStatus::RUNNING);
return 0;
}
......@@ -40,10 +40,11 @@ using namespace imstk;
/// \brief This example demonstrates the soft body simulation
/// using Finite elements
///
int main()
int
main()
{
// SDK and Scene
auto sdk = std::make_shared<SimulationManager>();
auto sdk = std::make_shared<SimulationManager>();
auto scene = sdk->createNewScene("DeformableBodyFEM");
scene->getCamera()->setPosition(0, 2.0, 15.0);
......@@ -56,7 +57,7 @@ int main()
}
// Extract the surface mesh
auto surfMesh = std::make_shared<SurfaceMesh>();
auto surfMesh = std::make_shared<SurfaceMesh>();
auto volTetMesh = std::dynamic_pointer_cast<TetrahedralMesh>(tetMesh);
if (!volTetMesh)
{
......@@ -66,7 +67,7 @@ int main()
volTetMesh->extractSurfaceMesh(surfMesh, true);
StopWatch wct;
CpuTimer cput;
CpuTimer cput;
wct.start();
cput.start();
......@@ -123,8 +124,8 @@ int main()
// create a linear solver
auto linSolver = std::make_shared<ConjugateGradient>();
if (linSolver->getType() == imstk::LinearSolver<imstk::SparseMatrixd>::Type::GaussSeidel &&
dynaModel->isFixedBCImplemented())
if (linSolver->getType() == imstk::LinearSolver<imstk::SparseMatrixd>::Type::GaussSeidel
&& dynaModel->isFixedBCImplemented())
{
LOG(WARNING) << "The GS solver may not be viable!";
}
......
......@@ -28,14 +28,15 @@ using namespace imstk;
/// \brief This example shows how to extract the triangular surface
/// mesh from a volumetric tetrahedral mesh
///
void extractSurfaceMesh()
void
extractSurfaceMesh()
{
auto sdk = std::make_shared<SimulationManager>();
// a. Construct a sample tetrahedral mesh
// a.1 add vertex positions
auto tetMesh = std::make_shared<TetrahedralMesh>();
auto tetMesh = std::make_shared<TetrahedralMesh>();
StdVectorOfVec3d vertList;
vertList.push_back(Vec3d(0, 0, 0));
vertList.push_back(Vec3d(1.0, 0, 0));
......@@ -47,8 +48,8 @@ void extractSurfaceMesh()
// a.2 add connectivity
std::vector<TetrahedralMesh::TetraArray> tetConnectivity;
TetrahedralMesh::TetraArray tet1 = { 0, 1, 2, 3 };
TetrahedralMesh::TetraArray tet2 = { 1, 2, 3, 4 };
TetrahedralMesh::TetraArray tet1 = { 0, 1, 2, 3 };
TetrahedralMesh::TetraArray tet2 = { 1, 2, 3, 4 };
tetConnectivity.push_back(tet1);
tetConnectivity.push_back(tet2);
tetMesh->setTetrahedraVertices(tetConnectivity);
......@@ -71,7 +72,8 @@ void extractSurfaceMesh()
getchar();
}
int main()
int
main()
{
extractSurfaceMesh();
......
......@@ -32,15 +32,16 @@ using namespace imstk;
/// \brief This example demonstrates the GUI feature.
/// NOTE: Requires enabling Vulkan rendering backend
///
int main()
int
main()
{
// SDK and Scene
auto sdk = std::make_shared<SimulationManager>();
auto scene = sdk->createNewScene("GraphicalUserInterface");
auto sdk = std::make_shared<SimulationManager>();
auto scene = sdk->createNewScene("GraphicalUserInterface");
auto canvas = sdk->getViewer()->getCanvas();
// Cube
auto cube = apiutils::createVisualAnalyticalSceneObject(Geometry::Type::Cube, scene, "cube", 0.5);
auto cube = apiutils::createVisualAnalyticalSceneObject(Geometry::Type::Cube, scene, "cube", 0.5);
auto sphere = std::make_shared<Sphere>();
cube->getVisualModel(0)->getGeometry()->translate(0, 0, 0);
cube->getVisualModel(0)->getGeometry()->rotate(UP_VECTOR, PI_4);
......@@ -49,16 +50,16 @@ int main()
auto plane = apiutils::createVisualAnalyticalSceneObject(Geometry::Type::Plane, scene, "plane", 10);
// Window logic
auto window = std::make_shared<GUIOverlay::Window>("Test Window", "Test Window", 200.0f, 100.0f, 200.0f, 0.0f);
auto window = std::make_shared<GUIOverlay::Window>("Test Window", "Test Window", 200.0f, 100.0f, 200.0f, 0.0f);
auto windowText = std::make_shared<GUIOverlay::Text>("Window Text", "Window Text", 0.0f, 0.0f);
window->addWidget(windowText);
auto circle = std::make_shared<GUIOverlay::Circle>("Circle", 100.0f, 100.0f, 25.0f, Color::Red, true);
auto circle = std::make_shared<GUIOverlay::Circle>("Circle", 100.0f, 100.0f, 25.0f, Color::Red, true);
auto circleOutline = std::make_shared<GUIOverlay::Circle>("CircleOutline", 100.0f, 100.0f, 25.0f, Color::Black, false);
// These two rectangles show that the ordering matters
auto underRectangle = std::make_shared<GUIOverlay::Rectangle>("UnderRectangle", 100.0f, 100.0f, 100.0f, 100.0f, Color(0.0f, 0.0f, 1.0f, 0.7f), true);
auto overRectangle = std::make_shared<GUIOverlay::Rectangle>("OverRectangle", 0.0f, 0.0f, 100.0f, 100.0f, Color(0.7f, 0.0f, 1.0f, 0.7f), true);
auto overRectangle = std::make_shared<GUIOverlay::Rectangle>("OverRectangle", 0.0f, 0.0f, 100.0f, 100.0f, Color(0.7f, 0.0f, 1.0f, 0.7f), true);
canvas->addWidget(underRectangle);
canvas->addWidget(circle);
......@@ -69,13 +70,13 @@ int main()
StopWatch watch;
watch.start();
auto startTime = watch.getTimeElapsed();
auto lastTime = startTime;
auto lastTime = startTime;
// Update function
auto GUIUpdateFunction =
[&](InteractorStyle* style) -> bool
{
auto time = watch.getTimeElapsed();
auto time = watch.getTimeElapsed();
float angle = time / 1000.0f;
circle->setPosition(std::sin(angle) * 50.0f + 100.0f, std::cos(angle) * 50.0f + 100.0f);
circle->setRadius(std::abs(std::sin(angle)) * 25.0f);
......@@ -92,7 +93,7 @@ int main()
};
sdk->getViewer()->setOnTimerFunction(GUIUpdateFunction);
bool canvasVisible = true;
bool canvasVisible = true;
auto hideShowCanvasFunction =
[&](InteractorStyle* style) -> bool
{
......
......@@ -31,10 +31,11 @@ using namespace imstk;
///
/// \brief This example demonstrates the geometry transforms in imstk
///
int main()
int