diff --git a/examples/CollisionDetectionBVH/CollisionDetectionBVH.cpp b/examples/CollisionDetectionBVH/CollisionDetectionBVH.cpp index 66af0688d148c45f3590fa01469026f2030d4129..7aeb2861a75aad4d5d6d9283ea8c02c6d6fcddf6 100644 --- a/examples/CollisionDetectionBVH/CollisionDetectionBVH.cpp +++ b/examples/CollisionDetectionBVH/CollisionDetectionBVH.cpp @@ -92,18 +92,18 @@ CollisionDetectionBVH::CollisionDetectionBVH() // Create a static scene modelA = std::make_shared<smStaticSceneObject>(); - modelA->setMesh(collisionModelA->getMesh()); + modelA->setModel(collisionModelA); sdk->registerSceneObject(modelA); - sdk->registerMesh(modelA->mesh); + sdk->registerMesh(collisionModelA->getMesh()); // Attach object to the dummy simulator. it will be simulated by dummy simulator modelA->attachObjectSimulator(defaultSimulator); // Initialize the scecond object modelB = std::make_shared<smStaticSceneObject>(); - modelB->setMesh(collisionModelB->getMesh()); + modelB->setModel(collisionModelB); sdk->registerSceneObject(modelB); - sdk->registerMesh(modelB->mesh); + sdk->registerMesh(collisionModelB->getMesh()); // Add object to the scene scene->addSceneObject(modelA); @@ -142,13 +142,13 @@ void CollisionDetectionBVH::simulateMain(const smSimulationMainParam &/*p_param* { if ((10 > moveObj) && (moveObj > 0)) { - modelB->mesh->translate(1, 0, 0); + modelB->getModel()->getMesh()->translate(1, 0, 0); moveObj--; } else { moveObj = 9; // reset - modelB->mesh->translate(-moveObj, 0, 0); + modelB->getModel()->getMesh()->translate(-moveObj, 0, 0); } std::this_thread::sleep_for(std::chrono::milliseconds(50)); diff --git a/examples/CollisionDetectionSpatialHashing/CollisionDetectionSpatialHashing.cpp b/examples/CollisionDetectionSpatialHashing/CollisionDetectionSpatialHashing.cpp index 2dc30d16168a102f33d726762e51c85ae5643caa..a82b251393d49faee231fb2079d5388b0477950d 100644 --- a/examples/CollisionDetectionSpatialHashing/CollisionDetectionSpatialHashing.cpp +++ b/examples/CollisionDetectionSpatialHashing/CollisionDetectionSpatialHashing.cpp @@ -68,39 +68,39 @@ CollisionDetectionSpatialHashing::CollisionDetectionSpatialHashing() smTextureManager::loadTexture("textures/brick.jpg", "wallImage"); smTextureManager::loadTexture("textures/brick-normal.jpg", "wallBumpImage"); + // Create collision models + std::shared_ptr<smMeshCollisionModel> collisionModelA = std::make_shared<smMeshCollisionModel>(); + collisionModelA->loadTriangleMesh("models/liverNormalized_SB2.3DS", SM_FILETYPE_3DS); + collisionModelA->getMesh()->assignTexture("livertexture1"); + collisionModelA->getMesh()->getRenderDetail()->renderType = (SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_WIREFRAME); + collisionModelA->getMesh()->translate(7, 3, 0); + collisionModelA->getMesh()->getRenderDetail()->lineSize = 2; + collisionModelA->getMesh()->getRenderDetail()->pointSize = 5; + + std::shared_ptr<smMeshCollisionModel> collisionModelB = std::make_shared<smMeshCollisionModel>(); + collisionModelB->loadTriangleMesh("models/liverNormalized_SB2.3DS", SM_FILETYPE_3DS); + collisionModelB->getMesh()->assignTexture("livertexture2"); + collisionModelB->getMesh()->translate(smVec3d(2, 0, 0)); + collisionModelB->getMesh()->assignTexture("livertexture2"); + collisionModelB->getMesh()->getRenderDetail()->shadowColor.rgba[0] = 1.0; + collisionModelB->getMesh()->getRenderDetail()->renderType = (SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_WIREFRAME); + // Create a static scene modelA = std::make_shared<smStaticSceneObject>(); + modelA->setModel(collisionModelA); sdk->registerSceneObject(modelA); - sdk->registerMesh(modelA->mesh); - - // Load mesh - modelA->mesh->loadMeshLegacy("models/liverNormalized_SB2.3DS", SM_FILETYPE_3DS); - - // Assign a texture - modelA->mesh->assignTexture("livertexture1"); - - // Set the rendering features - modelA->mesh->getRenderDetail()->renderType = (SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_WIREFRAME); - modelA->mesh->translate(7, 3, 0); - modelA->mesh->getRenderDetail()->lineSize = 2; - modelA->mesh->getRenderDetail()->pointSize = 5; + sdk->registerMesh(collisionModelA->getMesh()); // Attach object to the dummy simulator. it will be simulated by dummy simulator modelA->attachObjectSimulator(defaultSimulator); - spatialHashing->addMesh(modelA->mesh); + spatialHashing->addMesh(collisionModelA->getMesh()); // Initialize the scecond object modelB = std::make_shared<smStaticSceneObject>(); sdk->registerSceneObject(modelB); - sdk->registerMesh(modelB->mesh); - - modelB->mesh->loadMeshLegacy("models/liverNormalized_SB2.3DS", SM_FILETYPE_3DS); - modelB->mesh->translate(smVec3d(2, 0, 0)); + sdk->registerMesh(collisionModelB->getMesh()); - modelB->mesh->assignTexture("livertexture2"); - modelB->mesh->getRenderDetail()->shadowColor.rgba[0] = 1.0; - modelB->mesh->getRenderDetail()->renderType = (SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_WIREFRAME); - spatialHashing->addMesh(modelB->mesh); + spatialHashing->addMesh(collisionModelB->getMesh()); // Add object to the scene scene->addSceneObject(modelA); @@ -124,8 +124,6 @@ CollisionDetectionSpatialHashing::CollisionDetectionSpatialHashing() // Create dummy collision pair std::shared_ptr<smCollisionPair> collisionPair = std::make_shared<smCollisionPair>(); - std::shared_ptr<smMeshCollisionModel> collisionModelB = std::make_shared<smMeshCollisionModel>(); - std::shared_ptr<smMeshCollisionModel> collisionModelA = std::make_shared<smMeshCollisionModel>(); collisionPair->setModels(collisionModelA,collisionModelB); simulator->addCollisionPair(collisionPair); @@ -143,13 +141,13 @@ void CollisionDetectionSpatialHashing::simulateMain(const smSimulationMainParam { if ((10 > moveObj) && (moveObj > 0)) { - modelB->mesh->translate(1, 0, 0); + modelB->getModel()->getMesh()->translate(1, 0, 0); moveObj--; } else { moveObj = 9; // reset - modelB->mesh->translate(-moveObj, 0, 0); + modelB->getModel()->getMesh()->translate(-moveObj, 0, 0); } std::this_thread::sleep_for(std::chrono::milliseconds(50)); diff --git a/examples/demo 1/CMakeLists.txt b/examples/demo 1/CMakeLists.txt index 1f8d2289b0c67483df4ec86e5f703c8b5e61716d..31af4ab16335a6647341402a139e1a0706370a52 100644 --- a/examples/demo 1/CMakeLists.txt +++ b/examples/demo 1/CMakeLists.txt @@ -1,5 +1,5 @@ -add_executable(vegaFemExample main.cpp demo1.cpp demo1.h) +add_executable(vegaFemExample main.cpp) target_link_libraries(demo1 smCore smRendering diff --git a/examples/demo 1/demo1.cpp b/examples/demo 1/demo1.cpp deleted file mode 100644 index 84d58139e620286053b2bcbf45f38409bce813e1..0000000000000000000000000000000000000000 --- a/examples/demo 1/demo1.cpp +++ /dev/null @@ -1,83 +0,0 @@ -// 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 "vegaFemExample.h" - -/// \brief Create a scene with one fem object using vega library -demo1Scene::demo1Scene() -{ - //Create an instance of the SoFMIS framework/SDK - sdk = smSDK::createSDK(); - - //Create a new scene to work in - scene = sdk->createScene(); - - //Create a viewer to see the scene - sdk->addViewer(&viewer); - - //------------------------------------------------------- - // Create scene object 1: fem scene object - //------------------------------------------------------- - - /// create a FEM simulator - femSim = new smVegaFemSimulator(sdk->getErrorLog()); - sdk->registerObjectSim(femSim); - - /// create a Vega based FEM object and attach it to the fem simulator - femobj = new smVegaFemSceneObject(sdk->getErrorLog(), - "../../../resources/vega/asianDragon/asianDragon.config"); - femobj->attachObjectSimulator(femSim); - - sdk->registerSceneObject(femobj); - - //------------------------------------------------------- - // Create scene object 2: static plane - //------------------------------------------------------- - - // Create dummy simulator - defaultSimulator = std::make_shared<smDummySimulator>(sdk->getErrorLog()); - sdk->registerObjectSim(defaultSimulator); - - - - /// add the FEM object to the scene - scene->addSceneObject(femobj); - - /// create a simulator module and register FEM simulator - simulator = sdk->createSimulator(); - simulator->registerObjectSimulator(femSim); - - /// create a viewer - viewer.viewerRenderDetail = viewer.viewerRenderDetail | SIMMEDTK_VIEWERRENDER_FADEBACKGROUND; - viewer.setEventDispatcher(sdk->getEventDispatcher()); - - /// run the SDK - sdk->run(); -} - -void buildDemo1Scene() -{ - vegaFemExample *ve = new vegaFemExample(); - delete ve; -} - diff --git a/examples/demo 1/demo1.h b/examples/demo 1/demo1.h deleted file mode 100644 index 5043fbdaae3820a7644ce66f5d93c3ed6c27dbd6..0000000000000000000000000000000000000000 --- a/examples/demo 1/demo1.h +++ /dev/null @@ -1,50 +0,0 @@ -// 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 "smCore/smConfig.h" -#include "smCore/smErrorLog.h" -#include "smCore/smCoreClass.h" -#include "smCore/smSDK.h" -#include "smRendering/smViewer.h" -#include "smSimulators/smVegaFemSimulator.h" -#include "smSimulators/smVegaFemSceneObject.h" - -class demo1Scene : public smSimulationMain, public smCoreClass -{ - -public: - demo1Scene(); - - virtual ~demo1Scene(){} - void simulateMain(smSimulationMainParam /*p_param*/) { }; -private: - std::unique_ptr<smSDK> sdk; - smVegaFemSceneObject *femobj; - smVegaFemSimulator *femSim; - smMatrix33d mat; - smSimulator *simulator; - smViewer viewer; - smScene *scene1; -}; - -void buildDemo1Scene(); diff --git a/examples/demo 1/main.cpp b/examples/demo 1/main.cpp index 4d7549568c3df29785ff2b1b43cff751ef10731c..38dda84532d4f3bdcb8cebc360adade1b37e6ac1 100644 --- a/examples/demo 1/main.cpp +++ b/examples/demo 1/main.cpp @@ -21,10 +21,74 @@ // Contact: //--------------------------------------------------------------------------- -#include "vegaFemExample.h" +// Core SimMedTK includes +#include "smCore/smConfig.h" +#include "smCore/smErrorLog.h" +#include "smCore/smCoreClass.h" +#include "smCore/smSDK.h" +#include "smRendering/smViewer.h" +#include "smCore/smSceneObject.h" + +// Include required types scene objects +#include "smSimulators/smVegaFemSceneObject.h" +#include "smCore/smStaticSceneObject.h" + +// Include required simulators +#include "smSimulators/smVegaFemSimulator.h" +#include "smSimulators/smDummySimulator.h" int main() { - demo1(); + //------------------------------------------------------- + // 1. Create an instance of the SoFMIS framework/SDK + // 2. Create viewer + // 3. Create default scene (scene 0) + //------------------------------------------------------- + std::unique_ptr<smSDK> sdk = smSDK::createStandardSDK(); + + //------------------------------------------------------- + // Create scene actor 1: fem scene object + fem simulator + //------------------------------------------------------- + + // create a FEM simulator + std::shared_ptr<smVegaFemSimulator> femSimulator = + std::make_shared<smVegaFemSimulator>(sdk->getErrorLog()); + + // create a Vega based FEM object and attach it to the fem simulator + std::make_shared<smVegaFemSceneObject> femObject = + std::make_shared<smVegaFemSceneObject>(sdk->getErrorLog(), + "../../../resources/vega/asianDragon/asianDragon.config"); + + sdk->addSceneActor(femObject, femSimulator); + + //------------------------------------------------------- + // Create scene actor 2: plane + dummy simulator + //------------------------------------------------------- + + // Create dummy simulator + std::make_shared<smDummySimulator> staticSimulator = + std::make_shared<smDummySimulator>(sdk->getErrorLog()); + + // create a static scene object + std::shared_ptr<smStaticSceneObject> staticObject = + std::make_shared<smStaticSceneObject>(); + + sdk->addSceneActor(staticObject, staticSimulator); + + //------------------------------------------------------- + // Customize viewer + //------------------------------------------------------- + cstd::shared_ptr<smStaticSceneObject> viewer = sdk->getViewerInstance(); + + viewer->viewerRenderDetail = viewer->viewerRenderDetail | + SIMMEDTK_VIEWERRENDER_FADEBACKGROUND; + + viewer->setEventDispatcher(sdk->getEventDispatcher()); + + //------------------------------------------------------- + // Run the SDK + //------------------------------------------------------- + sdk->run(); + return 0; } diff --git a/examples/renderCube/CMakeLists.txt b/examples/renderCube/CMakeLists.txt index 174f179c24dd9d3c6fbb62fa6f3b0c6feb2007a8..5efcf315863e18331bbc8cc9db784076d5536e93 100755 --- a/examples/renderCube/CMakeLists.txt +++ b/examples/renderCube/CMakeLists.txt @@ -6,6 +6,7 @@ target_link_libraries(renderCube smShader smMesh smEvent + smCollision ExamplesCommon sfml::system sfml::audio diff --git a/examples/renderCube/main.cpp b/examples/renderCube/main.cpp index 5cce0f94c318e33e7d0bbe65a65293f5dcbd804d..8b238acfefb4527930e3fca7fcf05a2bf3956e8a 100644 --- a/examples/renderCube/main.cpp +++ b/examples/renderCube/main.cpp @@ -28,6 +28,7 @@ #include "smCore/smSDK.h" #include "smCore/smTextureManager.h" +#include "smCollision/smMeshCollisionModel.h" int main() { @@ -56,18 +57,17 @@ int main() //Initialize the texture manager smTextureManager::init(sdk->getErrorLog()); + + std::shared_ptr<smMeshCollisionModel> cubeModel = std::make_shared<smMeshCollisionModel>(); + cubeModel->loadTriangleMesh("models/cube.obj", SM_FILETYPE_OBJ); + cubeModel->getMesh()->assignTexture("cubetex"); + cubeModel->getMesh()->getRenderDetail()->renderType = (SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_TEXTURE); //Load in the texture for the cube model smTextureManager::loadTexture("textures/cube.png", "cubetex"); cube = std::make_shared<smStaticSceneObject>(); - - //Load the cube model - cube->mesh->loadMesh("models/cube.obj", SM_FILETYPE_OBJ); - //Assign the previously loaded texture to the cube model - cube->mesh->assignTexture("cubetex"); - //Tell SimMedTK to render the faces of the model, and the texture assigned - cube->mesh->getRenderDetail()->renderType = (SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_TEXTURE); + cube->setModel(cubeModel); //Add the cube to the scene to be rendered scene1->addSceneObject(cube); diff --git a/examples/renderCubeToTexture/CMakeLists.txt b/examples/renderCubeToTexture/CMakeLists.txt index 6f71e87976df780bd85d2194f4ddff7c39eb8101..d9b1022da92b9ed87669feb797680de1e3922b83 100755 --- a/examples/renderCubeToTexture/CMakeLists.txt +++ b/examples/renderCubeToTexture/CMakeLists.txt @@ -6,5 +6,6 @@ target_link_libraries(renderCubeToTexture smRendering smShader smMesh + smCollision ExamplesCommon ) diff --git a/examples/renderCubeToTexture/main.cpp b/examples/renderCubeToTexture/main.cpp index 102ce8dd4449aba4f3a573256e16c180de1fa1ea..df8e08464bf491eb42ee562144958525c29acac4 100644 --- a/examples/renderCubeToTexture/main.cpp +++ b/examples/renderCubeToTexture/main.cpp @@ -28,6 +28,7 @@ #include "smCore/smSDK.h" #include "smCore/smTextureManager.h" +#include "smCollision/smMeshCollisionModel.h" int main() { @@ -61,37 +62,36 @@ int main() //Load in the texture for the cube model smTextureManager::loadTexture("textures/cube.png", "cubetex"); + std::shared_ptr<smMeshCollisionModel> cubeModel = std::make_shared<smMeshCollisionModel>(); + cubeModel->loadTriangleMesh("models/cube.obj", SM_FILETYPE_OBJ); + cubeModel->getMesh()->assignTexture("cubetex"); + cubeModel->getMesh()->getRenderDetail()->renderType = (SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_TEXTURE); //setup scene1 cube = std::make_shared<smStaticSceneObject>(); - - //Load the cube model - cube->mesh->loadMesh("models/cube.obj", SM_FILETYPE_OBJ); - //Assign the previously loaded texture to the cube model - cube->mesh->assignTexture("cubetex"); - //Tell SimMedTK to render the faces of the model, and the texture assigned - cube->mesh->getRenderDetail()->renderType = (SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_TEXTURE); + cube->setModel(cubeModel); //Add the cube to the scene to be rendered scene1->addSceneObject(cube); //setup scene2 + //Create a color and depth texture for the FBO + smTextureManager::createColorTexture("colorTex1", 64, 64); + smTextureManager::createDepthTexture("depthTex1", 64, 64); + std::shared_ptr<smMeshCollisionModel> squareModel = std::make_shared<smMeshCollisionModel>(); + squareModel->loadTriangleMesh("models/square.obj", SM_FILETYPE_OBJ); + squareModel->getMesh()->assignTexture("colorTex1"); + squareModel->getMesh()->getRenderDetail()->renderType = (SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_TEXTURE); square = std::make_shared<smStaticSceneObject>(); + square->setModel(cubeModel); //Setup an FBO for rendering in the viewer. - //Create a color and depth texture for the FBO - smTextureManager::createColorTexture("colorTex1", 64, 64); - smTextureManager::createDepthTexture("depthTex1", 64, 64); //Add the FBO and textures to the viewer viewer->addFBO("fbo1", smTextureManager::getTexture("colorTex1"), smTextureManager::getTexture("depthTex1"), 64, 64); - square->mesh->loadMesh("models/square.obj", SM_FILETYPE_OBJ); - square->mesh->assignTexture("colorTex1"); - square->mesh->getRenderDetail()->renderType = (SIMMEDTK_RENDER_FACES | SIMMEDTK_RENDER_TEXTURE); - //Add the square to the scene scene2->addSceneObject(square); diff --git a/include/smCollision/smMeshCollisionModel.h b/include/smCollision/smMeshCollisionModel.h index 50b7d74fc2f22a4ce560dba68e5b71e65bd95342..842ecce45085c85354ba5010498ab52a6151ffa2 100644 --- a/include/smCollision/smMeshCollisionModel.h +++ b/include/smCollision/smMeshCollisionModel.h @@ -100,7 +100,7 @@ public: void draw() override { - this->mesh->draw(); +// this->mesh->draw(); } private: diff --git a/include/smCollision/smPlaneCollisionModel.h b/include/smCollision/smPlaneCollisionModel.h index 69c2a44d6f798a3491edf07f3a61468ed654c5ac..3aace4b10fe74bcee44515a9b0077bfd280751c8 100644 --- a/include/smCollision/smPlaneCollisionModel.h +++ b/include/smCollision/smPlaneCollisionModel.h @@ -20,6 +20,9 @@ #include <memory> +// Eigen include +#include<Eigen/Geometry> + #include "smCore/smGeometry.h" #include "smCore/smModelRepresentation.h" diff --git a/include/smContactHandling/smContactHandling.h b/include/smContactHandling/smContactHandling.h index 9004fad823492ee8d001543e2daa4e8a92f2f87b..5e6ab1677ba1820bcbc516f9bff72d33ad1841a7 100644 --- a/include/smContactHandling/smContactHandling.h +++ b/include/smContactHandling/smContactHandling.h @@ -30,26 +30,29 @@ // SimMedTK includes #include "smCore/smCoreClass.h" #include "smContactHandling/smContactConfig.h" +#include "smCore/smSceneObject.h" class smMesh; class smCollisionPair; +enum smContactHandlingType +{ + SIMMEDTK_CONTACT_PENALTY_UNILATERAL, + SIMMEDTK_CONTACT_PENALTY_BILATERAL, + SIMMEDTK_CONTACT_PBD_UNILATERAL, + SIMMEDTK_CONTACT_PBD_BILATERAL, + SIMMEDTK_CONTACT_LPC_UNILATERAL, + SIMMEDTK_CONTACT_LCP_UNILATERAL, + SIMMEDTK_CONTACT_LCP_BILATERAL +}; + /// \brief Base class to for handling contact for collision response /// Input: collision pairs containig the collision information /// Output: contact forces or Jacobians or projection/PBD constraints class smContactHandling: public smCoreClass { public: - enum smContactHandlingType - { - SIMMEDTK_CONTACT_PENALTY_UNILATERAL, - SIMMEDTK_CONTACT_PENALTY_BILATERAL, - SIMMEDTK_CONTACT_PBD_UNILATERAL, - SIMMEDTK_CONTACT_PBD_BILATERAL, - SIMMEDTK_CONTACT_LPC_UNILATERAL, - SIMMEDTK_CONTACT_LCP_UNILATERAL, - SIMMEDTK_CONTACT_LCP_BILATERAL - }; + smContactHandling() {}; diff --git a/include/smContactHandling/smPenaltyContactHandling.h b/include/smContactHandling/smPenaltyContactHandling.h index a6292368ded4f8ec67ae6ca81349cb97b852e450..85c02c1ea8cbf1b94b78588797eeee846e4a0921 100644 --- a/include/smContactHandling/smPenaltyContactHandling.h +++ b/include/smContactHandling/smPenaltyContactHandling.h @@ -26,23 +26,28 @@ #define SMPENALTY_CONTACTHANDLING_H // SimMedTK includes -#include "smCollision/smContactHandling.h" +#include "smContactHandling/smContactHandling.h" +#include "smCollision/smCollisionPair.h" class smCollisionPair; /// /// @brief Penalty based for contact handling /// -class smPenaltyCollisionHandling : public smContactHandling +class smPenaltyContactHandling : public smContactHandling { public: - smPenaltyCollisionHandling(smContactHandlingType contactHandlingType); + smPenaltyContactHandling(bool typeBilateral); - smPenaltyCollisionHandling(smContactHandlingType contactHandlingType, + smPenaltyContactHandling(bool typeBilateral, const std::shared_ptr<smSceneObject>& sceneObjFirst, const std::shared_ptr<smSceneObject>& sceneObjSecond); - virtual ~smPenaltyCollisionHandling() {}; + smContactHandlingType getContactHandlingType() const; + + void resolveContacts(); + + virtual ~smPenaltyContactHandling() {}; private: diff --git a/include/smCore/smCoreClass.h b/include/smCore/smCoreClass.h index 8344f55a3b4df9360d8ba96d1183b636cb16919a..5519a9d5322b8ecc7b8667c600a3c1493d338448 100644 --- a/include/smCore/smCoreClass.h +++ b/include/smCore/smCoreClass.h @@ -120,7 +120,7 @@ public: /// /// \brief draw function is called for visualization the object /// - virtual void draw(); +// virtual void draw(); /// /// \brief initialization of simulation diff --git a/include/smCore/smGeometry.h b/include/smCore/smGeometry.h index 54df944616640ee1a1c5452c0399fc6137d7168d..36d6c5b4d091a578fa58f088e15c02421eae09db 100644 --- a/include/smCore/smGeometry.h +++ b/include/smCore/smGeometry.h @@ -38,10 +38,11 @@ public: smAnalyticalGeometry(){} ~smAnalyticalGeometry(){} - virtual void translate(const smVec3d t)=0; - virtual void rotate(const smMatrix33d &rot)=0; + void translate(const smVec3d t)=0; + void rotate(const smMatrix33d &rot)=0; + + void draw()=0; - virtual void draw()=0; }; /// \brief Simple Plane definition with unit normal and spatial location @@ -105,7 +106,10 @@ public: } private: + /// \brief unit normal of the plane smVec3d unitNormal; + + /// \brief any point on the plane smVec3d point; }; @@ -116,7 +120,7 @@ class smSphere : public smAnalyticalGeometry public: /// \brief constructor smSphere(); - + /// \brief sphere constructor with center and radius smSphere(const smVec3d &c, const double &r) { @@ -124,7 +128,7 @@ public: this->radius = r; } - ~smSphere(); + ~smSphere(){} void setRadius(const double r) { @@ -141,7 +145,7 @@ public: this->radius += r; } - void translate(const smVec3d t) + void translate(const smVec3d &t) { center += t; } diff --git a/include/smCore/smModelRepresentation.h b/include/smCore/smModelRepresentation.h index 30725a38ee728b33dc621a77e8398e1c0a798a54..1ec9ef018f8ab42d595f31c5af8ae2fcf885a829 100644 --- a/include/smCore/smModelRepresentation.h +++ b/include/smCore/smModelRepresentation.h @@ -41,10 +41,10 @@ public: smModelRepresentation(){} ~smModelRepresentation(){} - virtual std::shared_ptr<smMesh> getMesh() = 0; - virtual std::shared_ptr<smCoreClass> getObject() = 0; + virtual std::shared_ptr<smMesh> getMesh(){} + virtual std::shared_ptr<smCoreClass> getObject(){} - virtual void draw() = 0; + virtual void draw(){} }; #endif // SMMODELREPRESENTATION_H diff --git a/include/smCore/smSDK.h b/include/smCore/smSDK.h index 7fc314c73f0a8ae80cd29b040710fc56d0323ec4..d72273b5dbe01f250acf0afd2c72f67446e9f8b2 100644 --- a/include/smCore/smSDK.h +++ b/include/smCore/smSDK.h @@ -46,6 +46,7 @@ class smMotionTransformer; class smPipe; template<typename T> class smIndiceArray; class smScene; + /// \brief module registration enum smSDKReturnType { @@ -56,6 +57,7 @@ enum smSDKReturnType struct smBaseHolder { }; + /// \brief mesh holder struct smMeshHolder: public smBaseHolder { @@ -72,6 +74,7 @@ struct smMeshHolder: public smBaseHolder return mesh == p_param.mesh; } }; + /// \brief module holder struct smModuleHolder: public smBaseHolder { @@ -88,6 +91,7 @@ struct smModuleHolder: public smBaseHolder return module == p_param.module; } }; + /// \brief simulator holder struct smObjectSimulatorHolder: public smBaseHolder { @@ -104,6 +108,7 @@ struct smObjectSimulatorHolder: public smBaseHolder return objectSim == p_param.objectSim; } }; + /// \brief scene holders struct smSceneHolder: public smBaseHolder { @@ -119,6 +124,7 @@ struct smSceneHolder: public smBaseHolder } }; + /// \brief scene object holder struct smSceneObjectHolder: public smBaseHolder { @@ -135,6 +141,7 @@ struct smSceneObjectHolder: public smBaseHolder } }; + /// \brief pipe holder struct smPipeHolder: public smBaseHolder { @@ -157,6 +164,7 @@ struct smPipeHolder: public smBaseHolder } }; + /// \brief SDK class. it is a singlenton class for each machine runs the framework class smSDK: public smCoreClass { @@ -187,27 +195,7 @@ private: std::vector<std::thread> modules; ///< Stores a list of running module threads /// \brief constructor - smSDK() - { - shutdown = false; - sceneIdCounter = 1; - isModulesStarted = false; - type = SIMMEDTK_SMSDK; - viewer = nullptr; - simulator = nullptr; - sceneList.clear(); - - errorLog = std::make_shared<smErrorLog>(); - - // TODO: Fix these! Leaking... - meshesRef = new smIndiceArray<smMeshHolder>(SIMMEDTK_SDK_MAXMESHES); - modulesRef = new smIndiceArray<smModuleHolder>(SIMMEDTK_SDK_MAXMODULES) ; - objectSimulatorsRef = new smIndiceArray<smObjectSimulatorHolder>(SIMMEDTK_SDK_MAXOBJECTSIMULATORS); - collisionDetectorsRef = new smIndiceArray<smObjectSimulatorHolder>(SIMMEDTK_SDK_MAXOBJECTSIMULATORS) ; - scenesRef = new smIndiceArray<smSceneHolder>(SIMMEDTK_SDK_MAXSCENES); - sceneObjectsRef = new smIndiceArray<smSceneObjectHolder>(SIMMEDTK_SDK_MAXSCENEOBJTECTS); - pipesRef = new smIndiceArray<smPipeHolder>(SIMMEDTK_SDK_MAXSCENEOBJTECTS); - } + smSDK(); public: /// \brief destructor @@ -228,12 +216,19 @@ public: ///for now both functions below are the same. But it maybe subject to change. static std::shared_ptr<smSDK> createSDK(); + ///Creates the sdk, viewer and scene 0 + std::shared_ptr<smSDK> createStandardSDK(); + static std::shared_ptr<smSDK> getInstance(); /// \brief Registers a viewer object with the SDK /// void addViewer(std::shared_ptr<smViewer> p_viewer); + /// \brief Creates and registers a viewer object with the SDK + /// + std::shared_ptr<smViewer> createViewer(); + ///SDK returns a pointer to the viewer std::shared_ptr<smViewer> getViewerInstance(); @@ -241,19 +236,13 @@ public: std::shared_ptr<smSimulator> createSimulator(); ///SDK creates simualtor - std::shared_ptr<smSimulator> getSimulator() - { - return this->simulator; - } + std::shared_ptr<smSimulator> getSimulator(); ///SDK creates scene std::shared_ptr<smScene> createScene(); ///SDK returns logger for the system - std::shared_ptr<smErrorLog> getErrorLog() - { - return errorLog; - }; + std::shared_ptr<smErrorLog> getErrorLog(); ///terminates every module. Do it later on with smMessager void terminateAll(); @@ -271,71 +260,27 @@ public: void removeRef(std::shared_ptr<smCoreClass> p_coreClass); /// \brief register functions - smInt registerMesh(std::shared_ptr<smBaseMesh> p_mesh) - { - smMeshHolder mh; - mh.mesh = p_mesh; - return meshesRef->checkAndAdd(mh); - } + smInt registerMesh(std::shared_ptr<smBaseMesh> p_mesh); - smInt registerModule(std::shared_ptr<smModule> p_mod) - { - smModuleHolder mh; - mh.module = p_mod; - return modulesRef->checkAndAdd(mh); - } + smInt registerModule(std::shared_ptr<smModule> p_mod); - void registerObjectSim(std::shared_ptr<smObjectSimulator> p_os) - { - smObjectSimulatorHolder os; - os.objectSim = p_os; - objectSimulatorsRef->checkAndAdd(os); - } + void registerObjectSim(std::shared_ptr<smObjectSimulator> p_os); - void registerCollDet(std::shared_ptr<smObjectSimulator> p_col) - { - smObjectSimulatorHolder col; - col.objectSim = p_col; - collisionDetectorsRef->checkAndAdd(col); - } + void registerCollDet(std::shared_ptr<smObjectSimulator> p_col); - void registerScene(std::shared_ptr<smScene> p_sc) - { - smSceneHolder sc; - sc.scene = p_sc; - scenesRef->checkAndAdd(sc); - } + void registerScene(std::shared_ptr<smScene> p_sc); - void registerSceneObject(std::shared_ptr<smSceneObject> p_sco) - { - smSceneObjectHolder sh; - sh.sceneObject = p_sco; - sceneObjectsRef->checkAndAdd(sh); - } + void registerSceneObject(std::shared_ptr<smSceneObject> p_sco); - /// \brief getter functions + void addSceneActor(std::shared_ptr<smSceneObject> p_sco, std::shared_ptr<smObjectSimulator> p_os, int p_scId=0); - smPipe* getPipeByName(smString p_name) - { - return (pipesRef->getByRef(p_name).pipe); - } + smPipe* getPipeByName(smString p_name); /// \brief register pipe - void registerPipe(smPipe*p_pipe) - { - smPipeHolder ph; - ph.pipe = p_pipe; - pipesRef->checkAndAdd(ph); - } + void registerPipe(smPipe*p_pipe); /// \brief create a pipe - smPipe *createPipe(smString p_pipeName, smInt p_elementSize, smInt p_size) - { - smPipe *pipe; - pipe = new smPipe(p_pipeName, p_elementSize, p_size); - registerPipe(pipe); - return pipe; - } + smPipe* createPipe(smString p_pipeName, smInt p_elementSize, smInt p_size); }; #endif diff --git a/include/smCore/smSceneObject.h b/include/smCore/smSceneObject.h index 3018bc15570451327d4811a9d1325b43a139dd5e..2af400c0a38a4edc8f1b9f0ed7ce13d256c8c6ff 100644 --- a/include/smCore/smSceneObject.h +++ b/include/smCore/smSceneObject.h @@ -57,6 +57,7 @@ class smSceneObject: public smCoreClass public: /// \brief constructor smSceneObject(); + ~smSceneObject(){} /// \brief returns object id smInt getObjectId() diff --git a/include/smCore/smStaticSceneObject.h b/include/smCore/smStaticSceneObject.h index 27f1e2d955b2e72c2a04449cbfd976764429d0dd..44f6226c900f76cfd7ebe78d0158a591f4a10be6 100644 --- a/include/smCore/smStaticSceneObject.h +++ b/include/smCore/smStaticSceneObject.h @@ -30,6 +30,7 @@ #include "smCore/smSceneObject.h" #include "smMesh/smSurfaceMesh.h" #include "smCore/smCoreClass.h" +#include "smCore/smModelRepresentation.h" namespace smtk{ namespace Event{ diff --git a/include/smMesh/smMesh.h b/include/smMesh/smMesh.h index 9b4ef1d912f3ab1c51a004d8058ade855f9c2056..579958952da953a538584e4d6cf7dfa66aa856fc 100644 --- a/include/smMesh/smMesh.h +++ b/include/smMesh/smMesh.h @@ -38,7 +38,7 @@ #include "smCore/smGeometry.h" //VEGA includes -// #include "objMesh.h" +#include "objMesh.h" #define SIMMEDTK_MESH_AABBSKINFACTOR 0.1 ///Bounding box skin value #define SIMMEDTK_MESH_RESERVEDMAXEDGES 6000 ///this value is initially allocated buffer size for thge edges @@ -197,16 +197,13 @@ public: virtual smBool loadMesh(const smString& fileName, const smMeshFileType &fileType) = 0; /// \brief load the mesh -// bool importSurfaceMeshDataFromVEGA_Format(objMesh *vegaSurfaceMesh, bool perProcessingStage); + bool importSurfaceMeshDataFromVEGA_Format(const ObjMesh* const vegaSurfaceMesh, const bool perProcessingStage); - /// \brief render the surface mesh - virtual void draw(const smDrawParam &p_params) override; + /// \brief update the surface mesh data after the deformation + void updateSurfaceMeshDataFromVEGA_Format(const ObjMesh* const vegaSurfaceMesh); /// \brief render the surface mesh - virtual void draw() override - { - - } + virtual void draw(const smDrawParam &/*p_params*/) override; public: smInt nbrTriangles; ///< number of triangles diff --git a/include/smMesh/smVolumeMesh.h b/include/smMesh/smVolumeMesh.h index edc21b061e9f387022628a414015b4ca9ce745c1..323e38699b9b3c19ed0bcfe46191a5606217a800 100644 --- a/include/smMesh/smVolumeMesh.h +++ b/include/smMesh/smVolumeMesh.h @@ -28,7 +28,7 @@ #include "smMesh/smMesh.h" // VEGA includes -// #include "volumetricMesh.h" +#include "volumetricMesh.h" /// \brief this class is derived from generic Mesh class. Tetrahedron are building blocks of this volume mesh. /// It also retains the surface triangle structure for rendering and collision detection purposes. @@ -76,7 +76,10 @@ public: smBool loadMesh(const smString& fileName, const smMeshFileType &fileType); /// \brief populate the mesh data from the vega volumetric mesh file format -// void importVolumeMeshDataFromVEGA_Format(VolumetricMesh *vega3dMesh, bool perProcessingStage); + void importVolumeMeshDataFromVEGA_Format(const std::shared_ptr<const VolumetricMesh> vega3dMesh, const bool preProcessingStage); + + /// \brief update the mesh data from the vega volumetric mesh after deformation happens + void updateVolumeMeshDataFromVEGA_Format(const std::shared_ptr<const VolumetricMesh> vega3dMesh); public: /// push smMesh class specific errors here diff --git a/include/smSimulators/smFemSceneObject.h b/include/smSimulators/smFemSceneObject.h index aa3ca0e4ecc12d0c2cc90e182f7a1de35d5760b7..69b8ec2a718b7823a956bc2672e5ede0955ceb3b 100644 --- a/include/smSimulators/smFemSceneObject.h +++ b/include/smSimulators/smFemSceneObject.h @@ -43,7 +43,20 @@ class smFemSceneObject: public smSceneObject { public: /// \brief constructor - smFemSceneObject(std::shared_ptr<smErrorLog> p_log = nullptr); + smFemSceneObject(std::shared_ptr<smErrorLog> p_log = nullptr) + { + type = SIMMEDTK_SMFEMSCENEOBJECT; + v_mesh = new smVolumeMesh( SMMESH_DEFORMABLE, p_log ); + pullUp = true; + dynamicFem = false; + + if ( dynamicFem ) + { + dT = 0.02; + density = 500; + } + } + ~smFemSceneObject(){} /// \brief build FEM LM matrix void buildLMmatrix(); @@ -87,6 +100,8 @@ public: /// \brief !! This function does not clone!, it simply returns a pointer...this is dangerous virtual std::shared_ptr<smSceneObject> clone() override; + virtual void init(); + public: //fem objetc has two representations: surface and volume smVolumeMesh *v_mesh; ///< volume mesh diff --git a/include/smSimulators/smVegaFemSceneObject.h b/include/smSimulators/smVegaFemSceneObject.h index e097308754c004b708e87a29de696a86c18cb434..65ea4be8f18d6f7cfaff3a64ecab7da0a7a98978 100644 --- a/include/smSimulators/smVegaFemSceneObject.h +++ b/include/smSimulators/smVegaFemSceneObject.h @@ -155,28 +155,20 @@ public: /// \brief draws cartesian axis void drawAxes(double axisLength); - /// \brief - virtual void serialize(void *) override - { - //add code in future - } - - /// \brief - virtual void unSerialize(void *) override - { - - } - - /// \brief not implemented yet. + /*/// \brief not implemented yet. virtual std::shared_ptr<smSceneObject> clone() override { return safeDownCast<smSceneObject>(); - } + }*/ + + void setRenderUsingVega(const bool vegaRender); /// \brief Displays the fem object with primary or secondary mesh, fixed vertices, /// vertices interacted with, ground plane etc. virtual void draw(const smDrawParam &p_params) override; + void renderWithVega(); + virtual void init() override {} public: @@ -206,6 +198,8 @@ public: PerformanceCounter cpuLoadCounter; int timestepCounter; int subTimestepCounter; + bool renderUsingVega; + bool importAndUpdateVolumeMeshToSmtk; /// Force models, time integrators, sparse matrices and meshes. /// some variable names are self explainatory @@ -253,6 +247,9 @@ public: std::shared_ptr<SceneObjectDeformable> deformableObjectRenderingMesh; std::shared_ptr<SceneObjectDeformable> secondaryDeformableObjectRenderingMesh; + + std::shared_ptr<smVolumeMesh> smtkVolumeMesh; + std::shared_ptr<smSurfaceMesh> smtkSurfaceMesh; }; #endif diff --git a/src/smCollision/CMakeLists.txt b/src/smCollision/CMakeLists.txt index eca51a342242380de83d1c76b92523e1523d0dba..da8e11786f6b16faf7e317e0f1c9b332c2620841 100644 --- a/src/smCollision/CMakeLists.txt +++ b/src/smCollision/CMakeLists.txt @@ -12,6 +12,7 @@ simmedtk_add_library(smCollision smMeshCollisionModel.cpp smMeshToMeshCollision.cpp smPlaneToMeshCollision.cpp + smPlaneCollisionModel.cpp PUBLIC_HEADERS ${CMAKE_SOURCE_DIR}/include/smCollision/smCollisionConfig.h ${CMAKE_SOURCE_DIR}/include/smCollision/smCollisionDetection.h diff --git a/src/smCollision/smPlaneCollisionModel.cpp b/src/smCollision/smPlaneCollisionModel.cpp index 0f2f20454433c72924f626ecf4e5a2112467bd32..dbd679ae88c6f3a39ce692ce632a679eaba313e7 100644 --- a/src/smCollision/smPlaneCollisionModel.cpp +++ b/src/smCollision/smPlaneCollisionModel.cpp @@ -28,7 +28,7 @@ void smPlaneCollisionModel::draw() } const smVec3d& smPlaneCollisionModel::getNormal() const { - return this->transform.linear() * this->plane->getUnitNormal(); +// return this->transform.linear() * this->plane->getUnitNormal(); } void smPlaneCollisionModel::setNormal(const smVec3d& normal) { diff --git a/src/smContactHandling/smContactHandling.cpp b/src/smContactHandling/smContactHandling.cpp index b58a11876f25c90d1213f4664f59d7dad14f798b..40df497378b1387a3a9d0a40b716e627201b0edf 100644 --- a/src/smContactHandling/smContactHandling.cpp +++ b/src/smContactHandling/smContactHandling.cpp @@ -30,28 +30,28 @@ void smContactHandling::setSceneObjects(const std::shared_ptr< smSceneObject >& this->collidingSceneObjects.second = second; } -void setCollisionPairs(const std::shared_ptr< smCollisionPair >& colPair) +void smContactHandling::setCollisionPairs(const std::shared_ptr< smCollisionPair >& colPair) { this->collisionPairs = colPair; } -std::shared_ptr<smCollisionPair> getCollisionPairs() const +std::shared_ptr<smCollisionPair> smContactHandling::getCollisionPairs() const { return this->collisionPairs; } -smContactHandlingType smContactHandling::getContactHandlingType() +smContactHandlingType smContactHandling::getContactHandlingType() const { return this->contactHandlingType; } -std::shared_ptr<smSceneObject> smContactHandling::getFirstSceneObject() +std::shared_ptr<smSceneObject> smContactHandling::getFirstSceneObject() const { return this->collidingSceneObjects.first; } -std::shared_ptr<smSceneObject> smContactHandling::getSecondSceneObject() +std::shared_ptr<smSceneObject> smContactHandling::getSecondSceneObject() const { return this->collidingSceneObjects.second; } diff --git a/src/smContactHandling/smPenaltyContactHandling.cpp b/src/smContactHandling/smPenaltyContactHandling.cpp index a03fb3218cc93920216c322ec84ac8f2d81f8971..c3c15d74c23526d15fb7512d1a488345602a2ba9 100644 --- a/src/smContactHandling/smPenaltyContactHandling.cpp +++ b/src/smContactHandling/smPenaltyContactHandling.cpp @@ -21,18 +21,22 @@ // Contact: //--------------------------------------------------------------------------- -#include "smCollision/smContactHandling.h" +#include "smContactHandling/smPenaltyContactHandling.h" #include "smSimulators/smVegaFemSceneObject.h" -smPenaltyCollisionHandling(bool typeBilateral) +smPenaltyContactHandling::smPenaltyContactHandling(bool typeBilateral) { if (typeBilateral) - contactHandlingType = SIMMEDTK_CONTACT_PENALTY_UNILATERAL; - else + { contactHandlingType = SIMMEDTK_CONTACT_PENALTY_BILATERAL; + } + else + { + contactHandlingType = SIMMEDTK_CONTACT_PENALTY_UNILATERAL; + } } -smPenaltyCollisionHandling(smContactHandlingType contactHandlingType, +smPenaltyContactHandling::smPenaltyContactHandling(bool typeBilateral, const std::shared_ptr<smSceneObject>& sceneObjFirst, const std::shared_ptr<smSceneObject>& sceneObjSecond) { @@ -45,14 +49,14 @@ smPenaltyCollisionHandling(smContactHandlingType contactHandlingType, this->collidingSceneObjects.second = sceneObjSecond; } -smContactHandlingType smPenaltyCollisionHandling::getContactHandlingType() +smContactHandlingType smPenaltyContactHandling::getContactHandlingType() const { return contactHandlingType; } -void smPenaltyCollisionHandling::processContacts() +void smPenaltyContactHandling::resolveContacts() { - if (typeBilateral) + if (contactHandlingType == SIMMEDTK_CONTACT_PENALTY_UNILATERAL) { computeUnilateralContactForces(); } @@ -62,7 +66,7 @@ void smPenaltyCollisionHandling::processContacts() } } -void smPenaltyCollisionHandling::computeUnilateralContactForces() +void smPenaltyContactHandling::computeUnilateralContactForces() { int penetratedNode, nodeDofID; const double stiffness=1.0e5, damping=2000.0; @@ -76,17 +80,23 @@ void smPenaltyCollisionHandling::computeUnilateralContactForces() auto femSceneObject = std::static_pointer_cast<smVegaFemSceneObject>(this->getFirstSceneObject()); femSceneObject->setContactForcesToZero(); - - for (int i = 0; i < this->getCollisionPairs()->size(); i++) + smVec3d force; + for (int i = 0; i < contactInfo.size(); i++) { - nodeDofID = 3*contactInfo->nodeIndex; + nodeDofID = 3*contactInfo[i]->index; velocityProjection = smVec3d(femSceneObject->uvel[nodeDofID], femSceneObject->uvel[nodeDofID+1], femSceneObject->uvel[nodeDofID+2]); - velocityProjection = contactInfo->normal*velocityProjection.transpose(); - - femSceneObject->f_contact(nodeDofID ) += stiffness*contactInfo->depth*contactInfo->normal - damping*velocityProjection(0,0); - femSceneObject->f_contact(nodeDofID + 1) += stiffness*contactInfo->depth*contactInfo->normal - damping*velocityProjection(0,1); - femSceneObject->f_contact(nodeDofID + 2) += stiffness*contactInfo->depth*contactInfo->normal - damping*velocityProjection(0,2); + velocityProjection = contactInfo[i]->normal.dot(velocityProjection)*contactInfo[i]->normal; + + force = stiffness*contactInfo[i]->depth*contactInfo[i]->normal - damping*velocityProjection; + + femSceneObject->f_contact[nodeDofID] += force(0); + femSceneObject->f_contact[nodeDofID + 1] += force(1); + femSceneObject->f_contact[nodeDofID + 2] += force(2); + +// femSceneObject->f_contact[nodeDofID] += (stiffness*contactInfo[i]->depth)*contactInfo[i]->normal - damping*velocityProjection(0); +// femSceneObject->f_contact[nodeDofID + 1] += (stiffness*contactInfo[i]->depth)*contactInfo[i]->normal - damping*velocityProjection(1); +// femSceneObject->f_contact[nodeDofID + 2] += (stiffness*contactInfo[i]->depth)*contactInfo[i]->normal - damping*velocityProjection(2); } @@ -95,7 +105,7 @@ void smPenaltyCollisionHandling::computeUnilateralContactForces() } -void smPenaltyCollisionHandling::computeBilateralContactForces() +void smPenaltyContactHandling::computeBilateralContactForces() { diff --git a/src/smCore/CMakeLists.txt b/src/smCore/CMakeLists.txt index f120b92736644d16bb68482b31f3d16f9d045ed7..a7946862628f112db088d86c7d231e0faab899ea 100644 --- a/src/smCore/CMakeLists.txt +++ b/src/smCore/CMakeLists.txt @@ -48,7 +48,8 @@ target_link_libraries(smCore GLUT::GLUT ${OPENGL_LIBRARY} sfml::graphics - INTERFACE + VegaFEM::objMesh + VegaFEM::volumetricMesh ) if(NOT MSVC) diff --git a/src/smCore/smCoreClass.cpp b/src/smCore/smCoreClass.cpp index f013ad14f89b4ad5837a1e6099533e3876e6bd9e..42248a51c663f542676fb696cd1301517de13282 100644 --- a/src/smCore/smCoreClass.cpp +++ b/src/smCore/smCoreClass.cpp @@ -97,3 +97,8 @@ const std::string &smCoreClass::getName() const { return name; } +// void smCoreClass::draw() +// { +// std::cout << "Default draw function called. Nothing drawn." << std::endl; +// } + diff --git a/src/smCore/smSDK.cpp b/src/smCore/smSDK.cpp index 850b076df086a5d10bf506c19038457860c5602c..e6d45348e4fc6debc99ea8566b72129d5bd2ca8c 100644 --- a/src/smCore/smSDK.cpp +++ b/src/smCore/smSDK.cpp @@ -41,6 +41,33 @@ smIndiceArray<smSceneObjectHolder>*smSDK::sceneObjectsRef; smIndiceArray<smMotionTransformer*> *smSDK::motionTransRef; smIndiceArray<smPipeHolder> *smSDK::pipesRef; +/// \brief constructor +smSDK::smSDK() +{ + shutdown = false; + sceneIdCounter = 1; + isModulesStarted = false; + type = SIMMEDTK_SMSDK; + viewer = nullptr; + simulator = nullptr; + sceneList.clear(); + + errorLog = std::make_shared<smErrorLog>(); + + // TODO: Fix these! Leaking... + meshesRef = new smIndiceArray<smMeshHolder>(SIMMEDTK_SDK_MAXMESHES); + modulesRef = new smIndiceArray<smModuleHolder>(SIMMEDTK_SDK_MAXMODULES) ; + objectSimulatorsRef = new smIndiceArray<smObjectSimulatorHolder>(SIMMEDTK_SDK_MAXOBJECTSIMULATORS); + collisionDetectorsRef = new smIndiceArray<smObjectSimulatorHolder>(SIMMEDTK_SDK_MAXOBJECTSIMULATORS) ; + scenesRef = new smIndiceArray<smSceneHolder>(SIMMEDTK_SDK_MAXSCENES); + sceneObjectsRef = new smIndiceArray<smSceneObjectHolder>(SIMMEDTK_SDK_MAXSCENEOBJTECTS); + pipesRef = new smIndiceArray<smPipeHolder>(SIMMEDTK_SDK_MAXSCENEOBJTECTS); +} + +smSDK::~smSDK() +{ + std::cout << "Killing SDK" << std::endl; +} /// \brief creates the scene of the simulator std::shared_ptr<smScene> smSDK::createScene() @@ -56,9 +83,13 @@ void smSDK::releaseScene(std::shared_ptr<smScene> scene) scene.reset(); } -smSDK::~smSDK() +std::shared_ptr<smViewer> smSDK::createViewer() { - std::cout << "Killing SDK" << std::endl; + this->viewer = std::make_shared<smViewer>(); + this->viewer->log = this->errorLog; + this->registerModule(this->viewer); + + return this->viewer; } void smSDK::addViewer(std::shared_ptr<smViewer> p_viewer) @@ -181,10 +212,34 @@ std::shared_ptr<smSDK> smSDK::createSDK() return sdk; } +std::shared_ptr<smSDK> smSDK::createStandardSDK() +{ + static std::shared_ptr<smSDK> sdk; ///< singleton sdk. + + std::call_once(sdkCallOnceFlag, + [] + { + sdk.reset(new smSDK); + }); + + auto scene = std::make_shared<smScene>(errorLog); + registerScene(scene); + scene->setName("Scene" + std::to_string(scene->getUniqueId()->getId())); + + viewer = std::make_shared<smViewer>(); + viewer->log = this->errorLog; + registerModule(this->viewer); + + createSimulator(); + + return sdk; +} + std::shared_ptr<smSDK> smSDK::getInstance() { return smSDK::createSDK(); } + void smSDK::terminateAll() { @@ -206,3 +261,93 @@ void smSDK::terminateAll() } } } + +/// \brief register functions +smInt smSDK::registerMesh(std::shared_ptr<smBaseMesh> p_mesh) +{ + smMeshHolder mh; + mh.mesh = p_mesh; + return meshesRef->checkAndAdd(mh); +} + +smInt smSDK::registerModule(std::shared_ptr<smModule> p_mod) +{ + smModuleHolder mh; + mh.module = p_mod; + return modulesRef->checkAndAdd(mh); +} + +void smSDK::registerObjectSim(std::shared_ptr<smObjectSimulator> p_os) +{ + smObjectSimulatorHolder os; + os.objectSim = p_os; + objectSimulatorsRef->checkAndAdd(os); +} + +void smSDK::registerCollDet(std::shared_ptr<smObjectSimulator> p_col) +{ + smObjectSimulatorHolder col; + col.objectSim = p_col; + collisionDetectorsRef->checkAndAdd(col); +} + +void smSDK::registerScene(std::shared_ptr<smScene> p_sc) +{ + smSceneHolder sc; + sc.scene = p_sc; + scenesRef->checkAndAdd(sc); +} + +void smSDK::registerSceneObject(std::shared_ptr<smSceneObject> p_sco) +{ + smSceneObjectHolder sh; + sh.sceneObject = p_sco; + sceneObjectsRef->checkAndAdd(sh); +} + +void smSDK::addSceneActor(std::shared_ptr<smSceneObject> p_sco, std::shared_ptr<smObjectSimulator> p_os, int p_scId) +{ + assert(p_os); + assert(p_sco); + + p_sco->attachObjectSimulator(p_os); + + this->registerObjectSim(p_os); + + this->registerSceneObject(p_sco); + + sceneList[p_scId]->addSceneObject(p_sco); +} + +smPipe* smSDK::getPipeByName(smString p_name) +{ + return (pipesRef->getByRef(p_name).pipe); +} + +/// \brief register pipe +void smSDK::registerPipe(smPipe*p_pipe) +{ + smPipeHolder ph; + ph.pipe = p_pipe; + pipesRef->checkAndAdd(ph); +} + +/// \brief create a pipe +smPipe* smSDK::createPipe(smString p_pipeName, smInt p_elementSize, smInt p_size) +{ + smPipe *pipe; + pipe = new smPipe(p_pipeName, p_elementSize, p_size); + registerPipe(pipe); + return pipe; +} + +///SDK returns logger for the system +std::shared_ptr<smErrorLog> smSDK::getErrorLog() +{ + return errorLog; +}; + +std::shared_ptr<smSimulator> smSDK::getSimulator() +{ + return this->simulator; +} \ No newline at end of file diff --git a/src/smMesh/smLattice.cpp b/src/smMesh/smLattice.cpp index 3a4cfaa51f78e4a0098080dd4e933886e68df3f3..d05b721affa0ab49a348e28c817f970766b2d97b 100644 --- a/src/smMesh/smLattice.cpp +++ b/src/smMesh/smLattice.cpp @@ -22,6 +22,7 @@ //--------------------------------------------------------------------------- #include "smMesh/smLattice.h" +#include "smCollision/smMeshCollisionModel.h" smLattice::smLattice() { @@ -244,7 +245,13 @@ void smLattice::addObject( smSceneObject *obj ) { case SIMMEDTK_SMSTATICSCENEOBJECT: { - mesh = static_cast<smStaticSceneObject*>(obj)->mesh; + auto staticSceneObject = static_cast<smStaticSceneObject*>(obj); + auto model = std::static_pointer_cast<smMeshCollisionModel>(staticSceneObject->getModel()); + if(nullptr == model) + { + break; + } + std::shared_ptr<smMesh> mesh = model->getMesh(); break; } default: diff --git a/src/smMesh/smMesh.cpp b/src/smMesh/smMesh.cpp index 82c75e2af50648c1f12a7435b059509bdee94ac5..d22855cda35ea865875a4ecfdeec4608acf2132c 100644 --- a/src/smMesh/smMesh.cpp +++ b/src/smMesh/smMesh.cpp @@ -841,11 +841,21 @@ bool smLineMesh::isMeshTextured() return isTextureCoordAvailable; } -/* -bool smMesh::importSurfaceMeshDataFromVEGA_Format(objMesh *vegaSurfaceMesh, bool perProcessingStage) +void smMesh::updateSurfaceMeshDataFromVEGA_Format(const ObjMesh* const vegaSurfaceMesh) { + //copy the vertex co-ordinates + for(smInt i=0; i<this->nbrVertices ; i++) + { + this->vertices[i][0] = vertices[i][0]; + this->vertices[i][1] = vertices[i][1]; + this->vertices[i][2] = vertices[i][2]; + } +} - if(!vegaSurfaceMesh->isTriangularMesh()) +bool smMesh::importSurfaceMeshDataFromVEGA_Format(const ObjMesh* const vegaSurfaceMesh, const bool perProcessingStage) +{ + + if(!vegaSurfaceMesh->isTriangularMesh()) { if (this->log != nullptr) { @@ -864,7 +874,7 @@ bool smMesh::importSurfaceMeshDataFromVEGA_Format(objMesh *vegaSurfaceMesh, bool smInt * numGroups; smInt ** triangleGroups; - vegaSurfaceMesh->exportGeometry(numVertices, vertices, numTriangles , triangles, numGroups, triangleGroups) ; + vegaSurfaceMesh->exportGeometry(numVertices, vertices, numTriangles , triangles, numGroups, triangleGroups); this->nbrVertices = *numVertices; this->nbrTriangles = *numTriangles; @@ -915,4 +925,4 @@ bool smMesh::importSurfaceMeshDataFromVEGA_Format(objMesh *vegaSurfaceMesh, bool return 1; -}*/ +} diff --git a/src/smMesh/smVolumeMesh.cpp b/src/smMesh/smVolumeMesh.cpp index e206e20b22886d54ad31c61aa12eef580bf43a15..f9aba2adad8a08dafadee73a6fc20dd0d262b403 100644 --- a/src/smMesh/smVolumeMesh.cpp +++ b/src/smMesh/smVolumeMesh.cpp @@ -338,8 +338,22 @@ void smVolumeMesh::initSurface() updateTriangleNormals(); updateVertexNormals(); } -/* -void smVolumeMesh::importVolumeMeshDataFromVEGA_Format(VolumetricMesh *vega3dMesh, bool perProcessingStage) + +void smVolumeMesh::updateVolumeMeshDataFromVEGA_Format(const std::shared_ptr<const VolumetricMesh> vega3dMesh) +{ + smInt i, threeI; + + //copy the nodal co-ordinates + for(i=0; i<this->nbrVertices ; i++) + { + threeI = 3*i; + /*this->nodes[i][0] = (*nodes)[threeI]; + this->nodes[i][1] = (*nodes)[threeI+1]; + this->nodes[i][2] = (*nodes)[threeI+2];*/ + } +} + +void smVolumeMesh::importVolumeMeshDataFromVEGA_Format(const std::shared_ptr<const VolumetricMesh> vega3dMesh, const bool preProcessingStage) { smInt i, threeI, j; @@ -374,7 +388,8 @@ void smVolumeMesh::importVolumeMeshDataFromVEGA_Format(VolumetricMesh *vega3dMes this->nodes[i][2] = (*nodes)[threeI+2]; } - if(perProcessingStage){ + if(preProcessingStage) + { // do something here! } @@ -396,7 +411,6 @@ void smVolumeMesh::importVolumeMeshDataFromVEGA_Format(VolumetricMesh *vega3dMes delete [] nodes; } -*/ /// \brief destructor smVolumeMesh::~smVolumeMesh() diff --git a/src/smSimulators/smFemSceneObject.cpp b/src/smSimulators/smFemSceneObject.cpp index 03cd65d817947226c62bc7f2f4cf8cf2510f7144..732658a312c0b0c61ffde1e1d96f68a520b9f600 100644 --- a/src/smSimulators/smFemSceneObject.cpp +++ b/src/smSimulators/smFemSceneObject.cpp @@ -454,34 +454,13 @@ void smFemSceneObject::calculateDisplacements_Dynamic(smStdVector3d &vertices) void smFemSceneObject::draw(const smDrawParam &p_params) { -// p_params.caller = this; + // p_params.caller = this; this->v_mesh->draw(p_params); } -smFemSceneObject::smFemSceneObject( std::shared_ptr<smErrorLog> p_log ) -{ - type = SIMMEDTK_SMFEMSCENEOBJECT; - v_mesh = new smVolumeMesh( SMMESH_DEFORMABLE, p_log ); - pullUp = true; - dynamicFem = false; - - if ( dynamicFem ) - { - dT = 0.02; - density = 500; - } -} std::shared_ptr<smSceneObject> smFemSceneObject::clone() { return safeDownCast<smSceneObject>(); } - -void smFemSceneObject::serialize( void */*p_memoryBlock*/ ) -{ -} - -void smFemSceneObject::unSerialize( void */*p_memoryBlock*/ ) -{ - -} +void smFemSceneObject::init() {} diff --git a/src/smSimulators/smVegaFemSceneObject.cpp b/src/smSimulators/smVegaFemSceneObject.cpp index 2e6a9b1e9d07c3cb26ad31efc4461d08d39d53b1..8f826122b4d942c0ef3855929427e233024e4da2 100644 --- a/src/smSimulators/smVegaFemSceneObject.cpp +++ b/src/smSimulators/smVegaFemSceneObject.cpp @@ -80,6 +80,9 @@ smVegaFemSceneObject::smVegaFemSceneObject(std::shared_ptr<smErrorLog>/*p_log*/, secondaryDeformableObjectRenderingMesh_interpolation_vertices = nullptr; secondaryDeformableObjectRenderingMesh_interpolation_weights = nullptr; + renderUsingVega = true; + importAndUpdateVolumeMeshToSmtk = false; + type = SIMMEDTK_SMFEMSCENEOBJECT; femConfig = std::make_shared<smVegaConfigFemObject>(); @@ -169,6 +172,27 @@ void smVegaFemSceneObject::initSimulation() setDeformableModel(); loadMeshes(); loadRenderingMesh(); + + if(importAndUpdateVolumeMeshToSmtk) + { + this->smtkVolumeMesh = std::make_shared<smVolumeMesh>(); + this->smtkVolumeMesh->importVolumeMeshDataFromVEGA_Format(this->volumetricMesh, true); + } + + if(!renderUsingVega) + { + this->smtkSurfaceMesh = std::make_shared<smSurfaceMesh>(); + if(strcmp(femConfig->secondaryRenderingMeshFilename, "__none") == 0) + { + this->smtkSurfaceMesh->importSurfaceMeshDataFromVEGA_Format(this->deformableObjectRenderingMesh()->getMesh(), true); + } + else + { + this->smtkSurfaceMesh->importSurfaceMeshDataFromVEGA_Format(this->secondaryDeformableObjectRenderingMesh()->getMesh(), true); + } + + } + loadFixedBC(); // make room for deformation and force vectors @@ -943,6 +967,9 @@ void smVegaFemSceneObject::advanceDynamics() // apply pre-defined external forces applyScriptedExternalForces(); + // apply external forces arising from contact + applyContactForces(); + // set forces to the integrator integratorBaseSparse->SetExternalForces(f_ext); @@ -953,6 +980,11 @@ void smVegaFemSceneObject::advanceDynamics() memcpy(u, integratorBase->Getq(), sizeof(double) * 3 * n); + if(importAndUpdateVolumeMeshToSmtk) + { + smtkVolumeMesh->updateVolumeMeshDataFromVEGA_Format(this->volumetricMesh); + } + if (femConfig->singleStepMode == 1) { femConfig->singleStepMode = 2; @@ -979,6 +1011,19 @@ void smVegaFemSceneObject::advanceDynamics() // update the secondary mesh updateSecondaryRenderingMesh(); + if(!renderUsingVega) + { + + if(strcmp(femConfig->secondaryRenderingMeshFilename, "__none") == 0) + { + this->smtkSurfaceMesh->updateSurfaceMeshDataFromVEGA_Format(this->deformableObjectRenderingMesh()->getMesh()); + } + else + { + this->smtkSurfaceMesh->updateSurfaceMeshDataFromVEGA_Format(this->secondaryDeformableObjectRenderingMesh()->getMesh()); + } + } + // update stasts updateStats(); @@ -1280,9 +1325,25 @@ inline void smVegaFemSceneObject::updateStats() } } +void smVegaFemSceneObject::setRenderUsingVega(bool vegaRender) +{ + this->renderUsingVega = vegaRender; +} + +void smVegaFemSceneObject::draw(const smDrawParam &p_params) +{ + if(!renderUsingVega) + { + smtkSurfaceMesh->draw(); + } + else + { + renderWithVega(); + } +} // Displays the fem object with primary or secondary mesh, fixed vertices, vertices interacted with, ground plane etc. -void smVegaFemSceneObject::draw(const smDrawParam &/*p_params*/) +void smVegaFemSceneObject::renderWithVega() { glEnable(GL_LIGHTING); diff --git a/src/smUtilities/smGLUtils.cpp b/src/smUtilities/smGLUtils.cpp index 67fa281abf4c089a08231eee43c29b45650df6de..f0fc8dc6c5e636f4f27fa8315306b9412e4ce380 100644 --- a/src/smUtilities/smGLUtils.cpp +++ b/src/smUtilities/smGLUtils.cpp @@ -69,13 +69,13 @@ void smGLUtils::fadeBackgroundDraw() glLoadIdentity(); glOrtho(-1, 1, -1, 1, 0.1, 1.1); glBegin(GL_POLYGON); - glColor3f(0.219, 0.219, 0.435); + glColor3f(0.4, 0.4, 0.8); glVertex3d(-1, -1, -1); - glColor3f(0.219, 0.219, 0.435); + glColor3f(0.4, 0.4, 0.8); glVertex3d(1, -1, -1); - glColor3f(0.0, 0.0, 0.0); + glColor3f(0.1, 0.1, 0.2); glVertex3d(1, 1, -1); - glColor3f(0.0, 0.0, 0.0); + glColor3f(0.1, 0.1, 0.2); glVertex3d(-1, 1, -1); glEnd(); glEnable(GL_DEPTH_TEST);