diff --git a/Examples/BoneShaving/BoneShavingExample.cpp b/Examples/BoneShaving/BoneShavingExample.cpp index 314d687e132224d88641da73f77ba53289ac6f9c..299c4151cfaae650a59c9c3e00af4024d7cfd3dc 100644 --- a/Examples/BoneShaving/BoneShavingExample.cpp +++ b/Examples/BoneShaving/BoneShavingExample.cpp @@ -25,7 +25,7 @@ #include "imstkHapticDeviceClient.h" #include "imstkHapticDeviceManager.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" @@ -88,10 +88,10 @@ main() InteractionType::CollidingObjToCollidingObjBoneDrilling, CollisionDetection::Type::PointSetToSphere)); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setFocalPoint(Vec3d(5.0, -8.0, -5.0)); light->setIntensity(1.0); - scene->addLight(light); + scene->addLight("light0", light); scene->getActiveCamera()->setPosition(Vec3d(0.0, 3.0, 25.0)); diff --git a/Examples/CameraController/CameraControllerExample.cpp b/Examples/CameraController/CameraControllerExample.cpp index a50bb128bc7b190acb106fd2693cee921faaad19..5427aadb8c5fdb44f4a3c19da9cef59670815711 100644 --- a/Examples/CameraController/CameraControllerExample.cpp +++ b/Examples/CameraController/CameraControllerExample.cpp @@ -24,7 +24,7 @@ #include "imstkHapticDeviceClient.h" #include "imstkHapticDeviceManager.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" @@ -77,10 +77,10 @@ main() scene->addController(camController); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setFocalPoint(Vec3d(5.0, -8.0, -5.0)); light->setIntensity(1.0); - scene->addLight(light); + scene->addLight("light0", light); // Run the simulation { diff --git a/Examples/CollisionDetection/ManualCDWithOctree/ManualCDWithOctreeExample.cpp b/Examples/CollisionDetection/ManualCDWithOctree/ManualCDWithOctreeExample.cpp index b586424f621133e942d2dc699f94f827d760fe55..c7c067cb2577bb5a8f40c8c8258758557fed937b 100644 --- a/Examples/CollisionDetection/ManualCDWithOctree/ManualCDWithOctreeExample.cpp +++ b/Examples/CollisionDetection/ManualCDWithOctree/ManualCDWithOctreeExample.cpp @@ -25,7 +25,7 @@ #include "imstkDebugRenderGeometry.h" #include "imstkKeyboardDeviceClient.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkMouseSceneControl.h" #include "imstkNew.h" #include "imstkOctreeBasedCD.h" @@ -456,15 +456,15 @@ main() scene->getActiveCamera()->setPosition(Vec3d(0.0, 15.0, 50.0)); // Light - imstkNew<DirectionalLight> light1("Light1"); + imstkNew<DirectionalLight> light1; light1->setFocalPoint(Vec3d(-1.0, -1.0, -1.0)); light1->setIntensity(1.0); - scene->addLight(light1); + scene->addLight("light1", light1); - imstkNew<DirectionalLight> light2("Light2"); + imstkNew<DirectionalLight> light2; light2->setFocalPoint(Vec3d(1.0, -1.0, -1.0)); light2->setIntensity(1.0); - scene->addLight(light2); + scene->addLight("light2", light2); // Run the simulation { diff --git a/Examples/CreateEnclosingMesh/CreateEnclosingMesh.cpp b/Examples/CreateEnclosingMesh/CreateEnclosingMesh.cpp index 3ddc19e30c01997adaaa1688c6f73c833eb03086..dc639c8b32a4bbc868fe1ef5230851d1604ed522 100644 --- a/Examples/CreateEnclosingMesh/CreateEnclosingMesh.cpp +++ b/Examples/CreateEnclosingMesh/CreateEnclosingMesh.cpp @@ -22,7 +22,7 @@ #include "imstkCamera.h" #include "imstkGeometryUtilities.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" @@ -84,10 +84,10 @@ main() scene->addSceneObject(volObject); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setFocalPoint(Vec3d(5.0, -8.0, -5.0)); light->setIntensity(1); - scene->addLight(light); + scene->addLight("light0", light); } // Run the simulation diff --git a/Examples/DebugRendering/DebugRenderingExample.cpp b/Examples/DebugRendering/DebugRenderingExample.cpp index 819b50af7e635501d2fe0883a5a96ed929dfb2e9..8754d1aad8d728979c9160cd4b1148813830ea79 100644 --- a/Examples/DebugRendering/DebugRenderingExample.cpp +++ b/Examples/DebugRendering/DebugRenderingExample.cpp @@ -22,7 +22,7 @@ #include "imstkCamera.h" #include "imstkDebugRenderGeometry.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMouseSceneControl.h" #include "imstkNew.h" @@ -178,15 +178,15 @@ main() scene->getActiveCamera()->setPosition(Vec3d(0.0, 0.0, 50.0)); // Light - imstkNew<DirectionalLight> light1("light1"); + imstkNew<DirectionalLight> light1; light1->setFocalPoint(Vec3d(-1.0, -1.0, -1.0)); light1->setIntensity(1.0); - scene->addLight(light1); + scene->addLight("light1", light1); - imstkNew<DirectionalLight> light2("light2"); + imstkNew<DirectionalLight> light2; light2->setFocalPoint(Vec3d(1.0, -1.0, -1.0)); light2->setIntensity(1.0); - scene->addLight(light2); + scene->addLight("light2", light2); // Run the simulation { diff --git a/Examples/DeformableBody/DeformableBodyExample.cpp b/Examples/DeformableBody/DeformableBodyExample.cpp index 3e6e0e4f998a22ac2be2c156484f664b13a58aa0..866d5c4c1f7119d9a8c5848a81ef8aaac739e282 100644 --- a/Examples/DeformableBody/DeformableBodyExample.cpp +++ b/Examples/DeformableBody/DeformableBodyExample.cpp @@ -24,7 +24,7 @@ #include "imstkFeDeformableObject.h" #include "imstkFEMDeformableBodyModel.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" @@ -106,10 +106,10 @@ main() scene->addSceneObject(planeObj); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setFocalPoint(Vec3d(5.0, -8.0, -5.0)); light->setIntensity(1); - scene->addLight(light); + scene->addLight("light", light); } // Run the simulation diff --git a/Examples/FemurCut/FemurCutExample.cpp b/Examples/FemurCut/FemurCutExample.cpp index 40c976569dec5f7f38711b79d1c661b6912c3fad..320b960830e6c9a9f4f3799e47417b8ce0777f7f 100644 --- a/Examples/FemurCut/FemurCutExample.cpp +++ b/Examples/FemurCut/FemurCutExample.cpp @@ -26,7 +26,7 @@ #include "imstkKeyboardSceneControl.h" #include "imstkLevelSetCH.h" #include "imstkLevelSetModel.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" @@ -131,10 +131,10 @@ main() scene->getCollisionGraph()->addInteraction(interaction); // Light (white) - imstkNew<DirectionalLight> whiteLight("whiteLight"); + imstkNew<DirectionalLight> whiteLight; whiteLight->setDirection(Vec3d(0.0, -8.0, 5.0)); whiteLight->setIntensity(1.0); - scene->addLight(whiteLight); + scene->addLight("whiteLight", whiteLight); // Adjust camera scene->getActiveCamera()->setFocalPoint(0.25, 0.83, 1.58); diff --git a/Examples/GeometryProcessing/GeometryProcessingExample.cpp b/Examples/GeometryProcessing/GeometryProcessingExample.cpp index 5e198b2b1cbd1697bc6d1376b6376131f71e4dfd..8539cee933a755c9d388ba455c81ba6644384efd 100644 --- a/Examples/GeometryProcessing/GeometryProcessingExample.cpp +++ b/Examples/GeometryProcessing/GeometryProcessingExample.cpp @@ -22,7 +22,7 @@ #include "imstkCamera.h" #include "imstkDataArray.h" #include "imstkImageData.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkNew.h" @@ -109,10 +109,10 @@ main() scene->getActiveCamera()->setPosition(Vec3d(0.0, 12.0, 12.0)); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setFocalPoint(Vec3d(5.0, -8.0, -5.0)); light->setIntensity(1); - scene->addLight(light); + scene->addLight("light", light); // Run the simulation { diff --git a/Examples/GeometryTransforms/GeometryTransformsExample.cpp b/Examples/GeometryTransforms/GeometryTransformsExample.cpp index d612eed653d9ef84097ad211a076d604f4183767..287d5f2e74c974c33fda3a290ab23458a5e6451c 100644 --- a/Examples/GeometryTransforms/GeometryTransformsExample.cpp +++ b/Examples/GeometryTransforms/GeometryTransformsExample.cpp @@ -23,7 +23,7 @@ #include "imstkCamera.h" #include "imstkCylinder.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMouseSceneControl.h" #include "imstkNew.h" @@ -113,10 +113,10 @@ main() scene->getActiveCamera()->setPosition(Vec3d(0.0, 30.0, 30.0)); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setDirection(Vec3d(5.0, -8.0, -5.0)); light->setIntensity(1.0); - scene->addLight(light); + scene->addLight("light", light); // Run the simulation { diff --git a/Examples/Levelset/levelsetExample.cpp b/Examples/Levelset/levelsetExample.cpp index 0256682ce45d2657e631d6086d9d894216dcee51..ecbb08dfec1714c7c4cd57e6a4b8d5ed7206e22a 100644 --- a/Examples/Levelset/levelsetExample.cpp +++ b/Examples/Levelset/levelsetExample.cpp @@ -23,7 +23,7 @@ #include "imstkKeyboardSceneControl.h" #include "imstkLevelSetDeformableObject.h" #include "imstkLevelSetModel.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" #include "imstkNew.h" @@ -111,10 +111,10 @@ main() scene->addSceneObject(obj); // Light (white) - imstkNew<DirectionalLight> whiteLight("whiteLight"); + imstkNew<DirectionalLight> whiteLight; whiteLight->setFocalPoint(Vec3d(5.0, -8.0, -5.0)); whiteLight->setIntensity(1.0); - scene->addLight(whiteLight); + scene->addLight("whitelight", whiteLight); // Adjust camera scene->getActiveCamera()->setPosition(0.0, 10.0, -10.0); diff --git a/Examples/MultipleScenes/multipleScenes.cpp b/Examples/MultipleScenes/multipleScenes.cpp index e1b4897380f75eee9db89b4ea16503da0f2588ae..83bb19dd4e28c58ea6d76809ca9d48f8b5bd7242 100644 --- a/Examples/MultipleScenes/multipleScenes.cpp +++ b/Examples/MultipleScenes/multipleScenes.cpp @@ -22,7 +22,8 @@ #include "imstkCamera.h" #include "imstkConsoleModule.h" #include "imstkKeyboardDeviceClient.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" +#include "imstkSpotLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkNew.h" @@ -210,19 +211,19 @@ createClothScene(std::string sceneName) scene->addSceneObject(clothObj); // Light (white) - imstkNew<DirectionalLight> whiteLight("whiteLight"); + imstkNew<DirectionalLight> whiteLight; whiteLight->setFocalPoint(Vec3d(5.0, -8.0, -5.0)); whiteLight->setIntensity(1.0); - scene->addLight(whiteLight); + scene->addLight("whitelight", whiteLight); // Light (red) - imstkNew<SpotLight> colorLight("colorLight"); + imstkNew<SpotLight> colorLight; colorLight->setPosition(Vec3d(-5.0, -3.0, 5.0)); colorLight->setFocalPoint(Vec3d(0.0, -5.0, 5.0)); colorLight->setIntensity(100.); colorLight->setColor(Color::Red); colorLight->setSpotAngle(30.0); - scene->addLight(colorLight); + scene->addLight("colorlight", colorLight); // Adjust camera scene->getActiveCamera()->setFocalPoint(0.0, -5.0, 5.0); diff --git a/Examples/ObjectController/ObjectControllerExample.cpp b/Examples/ObjectController/ObjectControllerExample.cpp index 99db5e0b61ded5a77456a7e3b9ac6274d6918394..78f2c4194af19253672f664344e90242ece85f05 100644 --- a/Examples/ObjectController/ObjectControllerExample.cpp +++ b/Examples/ObjectController/ObjectControllerExample.cpp @@ -27,7 +27,7 @@ #include "imstkHapticDeviceManager.h" #include "imstkKeyboardDeviceClient.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMouseSceneControl.h" #include "imstkNew.h" @@ -81,10 +81,10 @@ main() cam->setFocalPoint(geometries[0]->getPosition()); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setDirection(Vec3d(5.0, -8.0, -5.0)); light->setIntensity(1.0); - scene->addLight(light); + scene->addLight("light", light); //Run the simulation { diff --git a/Examples/ObjectControllerDummyClient/ObjectCtrlDummyClientExample.cpp b/Examples/ObjectControllerDummyClient/ObjectCtrlDummyClientExample.cpp index 8d586705c6c8cb8a38ccecfd6b28cffeb971afa4..19a6ddb71d01504a1ba329cadff7080b16b7b9fd 100644 --- a/Examples/ObjectControllerDummyClient/ObjectCtrlDummyClientExample.cpp +++ b/Examples/ObjectControllerDummyClient/ObjectCtrlDummyClientExample.cpp @@ -22,7 +22,7 @@ #include "imstkCamera.h" #include "imstkCollidingObject.h" #include "imstkDummyClient.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkNew.h" #include "imstkOrientedBox.h" @@ -77,10 +77,10 @@ main() scene->getActiveCamera()->setFocalPoint(geom->getPosition()); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setFocalPoint(Vec3d(5.0, -8.0, -5.0)); light->setIntensity(1.0); - scene->addLight(light); + scene->addLight("light", light); // Run the simulation { diff --git a/Examples/Octree/OctreeExample.cpp b/Examples/Octree/OctreeExample.cpp index da1d90c76c21fed29fb49879243e660c8d45769b..7ce63ab69ce0ce8300be2abebdab746a15369272 100644 --- a/Examples/Octree/OctreeExample.cpp +++ b/Examples/Octree/OctreeExample.cpp @@ -22,7 +22,7 @@ #include "imstkCamera.h" #include "imstkDebugRenderGeometry.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkLooseOctree.h" #include "imstkMouseSceneControl.h" @@ -264,15 +264,15 @@ main() // Lights { - imstkNew<DirectionalLight> light1("Light 1"); + imstkNew<DirectionalLight> light1; light1->setFocalPoint(Vec3d(-1.0, -1.0, -1.0)); light1->setIntensity(1.0); - scene->addLight(light1); + scene->addLight("light 1", light1); - imstkNew<DirectionalLight> light2("Light 2"); + imstkNew<DirectionalLight> light2; light2->setFocalPoint(Vec3d(1.0, -1.0, -1.0)); light2->setIntensity(1.0); - scene->addLight(light2); + scene->addLight("light 2", light2); } // Run the simulation diff --git a/Examples/OpenVRController/OpenVRControllerExample.cpp b/Examples/OpenVRController/OpenVRControllerExample.cpp index 74491f6d54b9338dfdd796023bdb4afe53e477ba..7004c7baac72c35cc629ccd0b2749c9ad95585bd 100644 --- a/Examples/OpenVRController/OpenVRControllerExample.cpp +++ b/Examples/OpenVRController/OpenVRControllerExample.cpp @@ -20,7 +20,7 @@ =========================================================================*/ #include "imstkCamera.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkNew.h" @@ -118,10 +118,10 @@ main() scene->addSceneObject(tableObj); // Lights - imstkNew<DirectionalLight> dirLight("DirLight"); + imstkNew<DirectionalLight> dirLight; dirLight->setIntensity(4); dirLight->setColor(Color(1.0, 0.95, 0.8)); - scene->addLight(dirLight); + scene->addLight("dirlight", dirLight); { // Add a module to run the viewer diff --git a/Examples/PBD/PBDCloth/pbdClothExample.cpp b/Examples/PBD/PBDCloth/pbdClothExample.cpp index 3002dfe2b02bdb12e04c2203c426c2d122abcee5..fc86c0a84e17e2194cda6c3e43a30b4fed4a2165 100644 --- a/Examples/PBD/PBDCloth/pbdClothExample.cpp +++ b/Examples/PBD/PBDCloth/pbdClothExample.cpp @@ -23,7 +23,7 @@ #include "imstkImageData.h" #include "imstkKeyboardDeviceClient.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" diff --git a/Examples/PBD/PBDClothRemap/pbdClothRemapExample.cpp b/Examples/PBD/PBDClothRemap/pbdClothRemapExample.cpp index df20fdeee9208ed804fd8945dd2cb7f369364004..2379bcf831509258248b7ffa199d87d85487b6bf 100644 --- a/Examples/PBD/PBDClothRemap/pbdClothRemapExample.cpp +++ b/Examples/PBD/PBDClothRemap/pbdClothRemapExample.cpp @@ -22,7 +22,8 @@ #include "imstkCamera.h" #include "imstkKeyboardDeviceClient.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" +#include "imstkSpotLight.h" #include "imstkLogger.h" #include "imstkMouseSceneControl.h" #include "imstkNew.h" @@ -166,19 +167,19 @@ main() scene->addSceneObject(clothObj); // Light (white) - imstkNew<DirectionalLight> whiteLight("whiteLight"); + imstkNew<DirectionalLight> whiteLight; whiteLight->setFocalPoint(Vec3d(5.0, -8.0, -5.0)); whiteLight->setIntensity(1.0); - scene->addLight(whiteLight); + scene->addLight("whitelight", whiteLight); // Light (red) - imstkNew<SpotLight> colorLight("colorLight"); + imstkNew<SpotLight> colorLight; colorLight->setPosition(Vec3d(-5.0, -3.0, 5.0)); colorLight->setFocalPoint(Vec3d(0.0, -5.0, 5.0)); colorLight->setIntensity(100.); colorLight->setColor(Color::Red); colorLight->setSpotAngle(30.0); - scene->addLight(colorLight); + scene->addLight("colorlight", colorLight); // Adjust camera scene->getActiveCamera()->setFocalPoint(0.0, -5.0, 5.0); diff --git a/Examples/PBD/PBDCollisionMultipleObjects/PBDCollisionMultipleObjectsExample.cpp b/Examples/PBD/PBDCollisionMultipleObjects/PBDCollisionMultipleObjectsExample.cpp index 07b382ee40359ccee5bae0d22b0fe1af3bbec987..65fc121cd9d1418d8bfbd06d8a97a781240d0872 100644 --- a/Examples/PBD/PBDCollisionMultipleObjects/PBDCollisionMultipleObjectsExample.cpp +++ b/Examples/PBD/PBDCollisionMultipleObjects/PBDCollisionMultipleObjectsExample.cpp @@ -22,7 +22,7 @@ #include "imstkCamera.h" #include "imstkCollisionGraph.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" @@ -147,10 +147,10 @@ main() } // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setFocalPoint(Vec3d(5, -8, -5)); light->setIntensity(1); - scene->addLight(light); + scene->addLight("light", light); // Set Camera configuration std::shared_ptr<Camera> cam = scene->getActiveCamera(); diff --git a/Examples/PBD/PBDCollisionOneObject/PBDCollisionOneObjectExample.cpp b/Examples/PBD/PBDCollisionOneObject/PBDCollisionOneObjectExample.cpp index 8a07a6e223de6734414dc2ca0213615fca134b89..724557236341f6737adbaa3dc8f90f42eeb16f7d 100644 --- a/Examples/PBD/PBDCollisionOneObject/PBDCollisionOneObjectExample.cpp +++ b/Examples/PBD/PBDCollisionOneObject/PBDCollisionOneObjectExample.cpp @@ -22,7 +22,7 @@ #include "imstkCamera.h" #include "imstkCollisionGraph.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" @@ -159,10 +159,10 @@ main() InteractionType::PbdObjToPbdObjCollision, CollisionDetection::Type::MeshToMeshBruteForce)); // Light - imstkNew<DirectionalLight> light("Light"); + imstkNew<DirectionalLight> light; light->setFocalPoint(Vec3d(5, -8, -5)); light->setIntensity(1); - scene->addLight(light); + scene->addLight("light0", light); } // Run the simulation diff --git a/Examples/PBD/PBDCollisionStairs/PBDCollisionStairsExample.cpp b/Examples/PBD/PBDCollisionStairs/PBDCollisionStairsExample.cpp index 60d0e78d8604e7fc68a1626450b99e79a3a65ceb..11563b357b5dcb685310446c559ee76d473f94b4 100644 --- a/Examples/PBD/PBDCollisionStairs/PBDCollisionStairsExample.cpp +++ b/Examples/PBD/PBDCollisionStairs/PBDCollisionStairsExample.cpp @@ -22,7 +22,7 @@ #include "imstkCamera.h" #include "imstkCollisionGraph.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" @@ -209,15 +209,15 @@ main() InteractionType::PbdObjToPbdObjCollision, CollisionDetection::Type::MeshToMeshBruteForce)); // Light - imstkNew<DirectionalLight> light("Light1"); + imstkNew<DirectionalLight> light; light->setFocalPoint(Vec3d(5.0, -8.0, 5.0)); light->setIntensity(1.0); - scene->addLight(light); + scene->addLight("light", light); - imstkNew<DirectionalLight> light2("Light2"); + imstkNew<DirectionalLight> light2; light2->setFocalPoint(-Vec3d(5, -8, 5)); light2->setIntensity(1.2); - scene->addLight(light2); + scene->addLight("light2", light2); } // Run the simulation diff --git a/Examples/PBD/PBDDeformableObject/PBD3DDeformableObject.cpp b/Examples/PBD/PBDDeformableObject/PBD3DDeformableObject.cpp index af1fa47207317c7e3d3be207e1354ed4fcbd460c..72f9f312bfae3f89ad0972b052233355149c8956 100644 --- a/Examples/PBD/PBDDeformableObject/PBD3DDeformableObject.cpp +++ b/Examples/PBD/PBDDeformableObject/PBD3DDeformableObject.cpp @@ -21,7 +21,7 @@ #include "imstkCamera.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" @@ -65,10 +65,10 @@ main() scene->addSceneObject(createAndAddPbdObject(tetMeshFileName)); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setFocalPoint(Vec3d(5, -8, -5)); light->setIntensity(1.1); - scene->addLight(light); + scene->addLight("light", light); // Run the simulation { diff --git a/Examples/PBD/PBDInjection/PBDInjectExample.cpp b/Examples/PBD/PBDInjection/PBDInjectExample.cpp index 37de20a2fe9e76c7c02a4310be583ac9047cac69..ab7581c8b0a70f5786320a894b20476c8394143e 100644 --- a/Examples/PBD/PBDInjection/PBDInjectExample.cpp +++ b/Examples/PBD/PBDInjection/PBDInjectExample.cpp @@ -24,7 +24,7 @@ #include "imstkImageData.h" #include "imstkKeyboardDeviceClient.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkMouseSceneControl.h" #include "imstkOneToOneMap.h" #include "imstkPbdModel.h" @@ -123,10 +123,10 @@ main() //scene->getCollisionGraph()->addInteraction(interaction); // Light - imstkNew<DirectionalLight> light("Light"); + imstkNew<DirectionalLight> light; light->setFocalPoint(Vec3d(5, -8, -5)); light->setIntensity(1); - scene->addLight(light); + scene->addLight("light", light); // Run the simulation { diff --git a/Examples/PBDCutting/PBDCuttingExample.cpp b/Examples/PBDCutting/PBDCuttingExample.cpp index d372d7611fe86d2ed865d83745842ac188e0f3b7..a01412b13823fad02604a7ce0ca2d0ec295f63f4 100644 --- a/Examples/PBDCutting/PBDCuttingExample.cpp +++ b/Examples/PBDCutting/PBDCuttingExample.cpp @@ -24,7 +24,7 @@ #include "imstkHapticDeviceManager.h" #include "imstkKeyboardDeviceClient.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMouseSceneControl.h" #include "imstkNew.h" @@ -192,10 +192,10 @@ main() scene->getActiveCamera()->setFocalPoint(Vec3d(0, -50, 0)); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setFocalPoint(Vec3d(5.0, -8.0, -5.0)); light->setIntensity(1.0); - scene->addLight(light); + scene->addLight("light", light); //Run the simulation { diff --git a/Examples/PBDPicking/PBDPickingExample.cpp b/Examples/PBDPicking/PBDPickingExample.cpp index 71c3845b0bd826ac84d8b9449f34dc59fea339dc..6bf26551983bfa165409a29fec1061ec13632bd6 100644 --- a/Examples/PBDPicking/PBDPickingExample.cpp +++ b/Examples/PBDPicking/PBDPickingExample.cpp @@ -26,7 +26,7 @@ #include "imstkHapticDeviceManager.h" #include "imstkKeyboardSceneControl.h" #include "imstkLaparoscopicToolController.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" @@ -246,10 +246,10 @@ main() scene->getActiveCamera()->setFocalPoint(Vec3d(0, -50, 0)); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setFocalPoint(Vec3d(5.0, -8.0, -5.0)); light->setIntensity(1.0); - scene->addLight(light); + scene->addLight("light", light); //Run the simulation { diff --git a/Examples/ReducedFEM/ReducedFEM.cpp b/Examples/ReducedFEM/ReducedFEM.cpp index 4192ca9f1588ec591875cd89bd534a94ca965dca..34f315e436c58e76dd7ff79efb677d50b0b26690 100644 --- a/Examples/ReducedFEM/ReducedFEM.cpp +++ b/Examples/ReducedFEM/ReducedFEM.cpp @@ -28,7 +28,7 @@ #include "imstkMouseSceneControl.h" #include "imstkNew.h" #include "imstkOneToOneMap.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkCamera.h" #include "imstkReducedStVKBodyModel.h" #include "imstkReducedFeDeformableObject.h" diff --git a/Examples/Rendering/RenderingExample.cpp b/Examples/Rendering/RenderingExample.cpp index 17fd9a6ba26551310251b1d4f80dc3f98ff59b51..90633cd4efe11c285c215f14e457b65cf5b4bc6a 100644 --- a/Examples/Rendering/RenderingExample.cpp +++ b/Examples/Rendering/RenderingExample.cpp @@ -23,7 +23,7 @@ #include "imstkCamera.h" #include "imstkIBLProbe.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" #include "imstkNew.h" @@ -83,10 +83,10 @@ main() scene->getActiveCamera()->setFocalPoint(0.0, 0.25, 0.0); // Lights - imstkNew<DirectionalLight> dirLight("DirectionalLight"); + imstkNew<DirectionalLight> dirLight; dirLight->setIntensity(10.0); dirLight->setColor(Color(1.0, 0.95, 0.8)); - scene->addLight(dirLight); + scene->addLight("directionalLight", dirLight); // Plane auto planeObj = apiutils::createVisualAnalyticalSceneObject("Plane", scene, "VisualPlane", Vec3d(10.0, 10.0, 10.0)); diff --git a/Examples/RigidBodyDynamics/RigidBodyDynamicsExample.cpp b/Examples/RigidBodyDynamics/RigidBodyDynamicsExample.cpp index 01b4d27ea8705b0bf9bff6d5e7fce8ad9a84db53..267b8004adb23376ece015feab4d6312836e226a 100644 --- a/Examples/RigidBodyDynamics/RigidBodyDynamicsExample.cpp +++ b/Examples/RigidBodyDynamics/RigidBodyDynamicsExample.cpp @@ -22,7 +22,7 @@ #include "imstkCamera.h" #include "imstkIsometricMap.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" @@ -188,9 +188,9 @@ main() scene->getActiveCamera()->setPosition(Vec3d(300.0, 300.0, 300.0)); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setIntensity(1.0); - scene->addLight(light); + scene->addLight("light", light); } // Run the simulation diff --git a/Examples/RigidBodyDynamics2/RigidBodyDynamicsExample2.cpp b/Examples/RigidBodyDynamics2/RigidBodyDynamicsExample2.cpp index 5968337071aad3bc76fea619a45b4e5469c1b3ff..fa9d857d9f91199e3b12726d535293a863fb199d 100644 --- a/Examples/RigidBodyDynamics2/RigidBodyDynamicsExample2.cpp +++ b/Examples/RigidBodyDynamics2/RigidBodyDynamicsExample2.cpp @@ -26,7 +26,7 @@ #include "imstkImplicitGeometryToImageData.h" #include "imstkKeyboardDeviceClient.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMouseSceneControl.h" #include "imstkNew.h" @@ -153,9 +153,9 @@ main() scene->getActiveCamera()->setPosition(0.0, 40.0, 40.0); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setIntensity(1.0); - scene->addLight(light); + scene->addLight("light", light); } // Run the simulation diff --git a/Examples/RigidBodyVirtualCoupling/RigidBodyVirtualCouplingExample.cpp b/Examples/RigidBodyVirtualCoupling/RigidBodyVirtualCouplingExample.cpp index 0dcc94293ce39ada4257f2e345e47e91d7651a15..98eb057e922e013330e26809c913712cf6a31a3c 100644 --- a/Examples/RigidBodyVirtualCoupling/RigidBodyVirtualCouplingExample.cpp +++ b/Examples/RigidBodyVirtualCoupling/RigidBodyVirtualCouplingExample.cpp @@ -24,7 +24,7 @@ #include "imstkHapticDeviceManager.h" #include "imstkIsometricMap.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" @@ -229,9 +229,9 @@ main() scene->getActiveCamera()->setPosition(Vec3d(300.0, 300.0, 300.0)); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setIntensity(1.0); - scene->addLight(light); + scene->addLight("light", light); // Run the simulation { diff --git a/Examples/SDFHaptics/SDFHapticsExample.cpp b/Examples/SDFHaptics/SDFHapticsExample.cpp index 60badea5d7b914d41f08bb8993f6faabd6aecc3f..be42b31d7d51f84b3736d55f318f55b17e313a4c 100644 --- a/Examples/SDFHaptics/SDFHapticsExample.cpp +++ b/Examples/SDFHaptics/SDFHapticsExample.cpp @@ -26,7 +26,7 @@ #include "imstkImageData.h" #include "imstkImplicitFunctionFiniteDifferenceFunctor.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkLogger.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" @@ -79,11 +79,11 @@ main() } // Light (white) - imstkNew<DirectionalLight> whiteLight("whiteLight"); + imstkNew<DirectionalLight> whiteLight; { whiteLight->setDirection(Vec3d(5.0, -8.0, -5.0)); whiteLight->setIntensity(1.0); - scene->addLight(whiteLight); + scene->addLight("whitelight", whiteLight); } } diff --git a/Examples/SPH-FEM-PBD/sphFemPbdExample.cpp b/Examples/SPH-FEM-PBD/sphFemPbdExample.cpp index 592832d12e13e91170b9ef9626a65d40ad72ea79..68282cb79ce18ba97b68076ca71d4ee3a8dea166 100644 --- a/Examples/SPH-FEM-PBD/sphFemPbdExample.cpp +++ b/Examples/SPH-FEM-PBD/sphFemPbdExample.cpp @@ -25,7 +25,7 @@ #include "imstkFEMDeformableBodyModel.h" #include "imstkImageData.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" #include "imstkNew.h" @@ -266,10 +266,10 @@ main() scene->addSceneObject(sphFluidBox); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setDirection(0.0, -1.0, -1.0); light->setIntensity(1); - scene->addLight(light); + scene->addLight("light", light); } // Run the simulation diff --git a/Examples/SPH-Obj-SDF/SPH-Obj-SDFInteractionExample.cpp b/Examples/SPH-Obj-SDF/SPH-Obj-SDFInteractionExample.cpp index 8d8edd2e88d711a0095d9de6027e499b98f627f8..3a6842746602f72289a4c01bdcfb3c599cf31e9d 100644 --- a/Examples/SPH-Obj-SDF/SPH-Obj-SDFInteractionExample.cpp +++ b/Examples/SPH-Obj-SDF/SPH-Obj-SDFInteractionExample.cpp @@ -22,7 +22,7 @@ #include "imstkCamera.h" #include "imstkCollisionGraph.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" #include "imstkNew.h" @@ -182,10 +182,10 @@ main() scene->getCollisionGraph()->addInteraction(interaction); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setDirection(0.0, -1.0, -1.0); light->setIntensity(1); - scene->addLight(light); + scene->addLight("light", light); } // Run the simulation diff --git a/Examples/SPHFluid/SPHFluidExample.hpp b/Examples/SPHFluid/SPHFluidExample.hpp index 3d42132967a91006aca270684a043b68f6951a5d..b09d7a797c340e5ddebf5f8b161c9423adc52a30 100644 --- a/Examples/SPHFluid/SPHFluidExample.hpp +++ b/Examples/SPHFluid/SPHFluidExample.hpp @@ -23,7 +23,7 @@ #include "imstkCollisionDetection.h" #include "imstkCollisionGraph.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkMouseSceneControl.h" #include "imstkNew.h" #include "imstkObjectInteractionFactory.h" @@ -108,10 +108,10 @@ main(int argc, char* argv[]) scene->getActiveCamera()->setPosition(-0.475, 8.116, -6.728); // configure light (white) - imstkNew<DirectionalLight> whiteLight("whiteLight"); + imstkNew<DirectionalLight> whiteLight; whiteLight->setFocalPoint(Vec3d(5.0, -8.0, -5.0)); whiteLight->setIntensity(1.5); - scene->addLight(whiteLight); + scene->addLight("whitelight", whiteLight); // Run the simulation { diff --git a/Examples/Screenshot/ScreenshotExample.cpp b/Examples/Screenshot/ScreenshotExample.cpp index 7d5f00659ad6f0cbc7f04dbeca286453db64c41d..cf23b74884025ff6c7c2789927889313eabfaa1f 100644 --- a/Examples/Screenshot/ScreenshotExample.cpp +++ b/Examples/Screenshot/ScreenshotExample.cpp @@ -22,7 +22,9 @@ #include "imstkCamera.h" #include "imstkKeyboardDeviceClient.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" +#include "imstkPointLight.h" +#include "imstkSpotLight.h" #include "imstkLogger.h" #include "imstkMouseSceneControl.h" #include "imstkNew.h" @@ -71,12 +73,12 @@ main() sphereObj->setVisualGeometry(sphereGeom); // Light (white) - imstkNew<PointLight> whiteLight("whiteLight"); + imstkNew<PointLight> whiteLight; whiteLight->setIntensity(1.0); whiteLight->setPosition(Vec3d(5.0, 8.0, 5.0)); // Light (red) - imstkNew<SpotLight> colorLight("colorLight"); + imstkNew<SpotLight> colorLight; colorLight->setPosition(Vec3d(4.0, -3.0, 1.0)); colorLight->setFocalPoint(Vec3d(0.0, 0.0, 0.0)); colorLight->setIntensity(1.0); @@ -87,8 +89,8 @@ main() scene->addSceneObject(planeObj); scene->addSceneObject(cubeObj); scene->addSceneObject(sphereObj); - scene->addLight(whiteLight); - scene->addLight(colorLight); + scene->addLight("whitelight", whiteLight); + scene->addLight("colorlight", colorLight); // Update Camera scene->getActiveCamera()->setPosition(Vec3d(-5.5, 2.5, 32.0)); diff --git a/Examples/Vessel/vesselExample.cpp b/Examples/Vessel/vesselExample.cpp index 2ea57aebf3e2f30b6b34203f2641e3bb9289705d..3ace436fb1045557a5603f6f5198c99ddced9db7 100644 --- a/Examples/Vessel/vesselExample.cpp +++ b/Examples/Vessel/vesselExample.cpp @@ -25,7 +25,7 @@ #include "imstkImageData.h" #include "imstkImageDistanceTransform.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkMeshIO.h" #include "imstkMouseSceneControl.h" #include "imstkNew.h" @@ -242,10 +242,10 @@ main() scene->getCollisionGraph()->addInteraction(collisionInteraction); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setDirection(0.0, 1.0, -1.0); light->setIntensity(1.0); - scene->addLight(light); + scene->addLight("light0", light); } // Run the simulation diff --git a/Examples/VirtualCoupling/VirtualCouplingExample.cpp b/Examples/VirtualCoupling/VirtualCouplingExample.cpp index 2b72da632accffdc9bfe8a726d5a2b08ed873adb..2618da3eabc6b7035b4a05710ad293083c2b36d7 100644 --- a/Examples/VirtualCoupling/VirtualCouplingExample.cpp +++ b/Examples/VirtualCoupling/VirtualCouplingExample.cpp @@ -28,7 +28,7 @@ #include "imstkHapticDeviceClient.h" #include "imstkHapticDeviceManager.h" #include "imstkKeyboardSceneControl.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" #include "imstkMouseSceneControl.h" #include "imstkNew.h" #include "imstkPlane.h" @@ -112,10 +112,10 @@ main() scene->getActiveCamera()->setFocalPoint(Vec3d(0, 0, 0)); // Light - imstkNew<DirectionalLight> light("light"); + imstkNew<DirectionalLight> light; light->setFocalPoint(Vec3d(5.0, -8.0, -5.0)); light->setIntensity(1.0); - scene->addLight(light); + scene->addLight("light0", light); //Run the simulation { diff --git a/Source/Rendering/VTKRenderer/imstkVTKRenderer.cpp b/Source/Rendering/VTKRenderer/imstkVTKRenderer.cpp index 01d19b585aedb7e276d63d8878220393be8bf2f9..718501404790638fd2b796f7b816196a0acb8718 100644 --- a/Source/Rendering/VTKRenderer/imstkVTKRenderer.cpp +++ b/Source/Rendering/VTKRenderer/imstkVTKRenderer.cpp @@ -22,7 +22,9 @@ #include "imstkVTKRenderer.h" #include "imstkCamera.h" #include "imstkDebugRenderGeometry.h" -#include "imstkLight.h" +#include "imstkDirectionalLight.h" +#include "imstkPointLight.h" +#include "imstkSpotLight.h" #include "imstkLogger.h" #include "imstkScene.h" #include "imstkSceneObject.h" @@ -536,7 +538,8 @@ VTKRenderer::sceneModifed(Event* imstkNotUsed(e)) // If the SceneObject is being rendered but not in the scene for (auto i = m_renderedObjects.begin(); i != m_renderedObjects.end(); i++) { - if (!m_scene->hasSceneObject(*i)) + auto sos = m_scene->getSceneObjects(); + if (sos.find(*i) == sos.end()) { i = removeSceneObject(*i); } diff --git a/Source/Scene/CMakeLists.txt b/Source/Scene/CMakeLists.txt index 5d1a4640b5f69e59067630d2063dab2976020dd0..f148e111e272c64eb740a39a926b329070668d03 100644 --- a/Source/Scene/CMakeLists.txt +++ b/Source/Scene/CMakeLists.txt @@ -15,6 +15,6 @@ imstk_add_library( Scene #----------------------------------------------------------------------------- # Testing #----------------------------------------------------------------------------- -#if( ${PROJECT_NAME}_BUILD_TESTING ) -# add_subdirectory( Testing ) -#endif() \ No newline at end of file +if( ${PROJECT_NAME}_BUILD_TESTING ) + add_subdirectory( Testing ) +endif() \ No newline at end of file diff --git a/Source/Scene/Testing/CMakeLists.txt b/Source/Scene/Testing/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4881706a7effbdc913ce4bd62d5b6fb51bc0f2f5 --- /dev/null +++ b/Source/Scene/Testing/CMakeLists.txt @@ -0,0 +1,2 @@ +include(imstkAddTest) +imstk_add_test( Scene ) \ No newline at end of file diff --git a/Source/Scene/Testing/imstkSceneTest.cpp b/Source/Scene/Testing/imstkSceneTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f661900e9128a10572494ca3022c6355886dd3c8 --- /dev/null +++ b/Source/Scene/Testing/imstkSceneTest.cpp @@ -0,0 +1,177 @@ +/*========================================================================= + + Library: iMSTK + + Copyright (c) Kitware, Inc. & Center for Modeling, Simulation, + & Imaging in Medicine, Rensselaer Polytechnic Institute. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0.txt + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +=========================================================================*/ + +#include "gtest/gtest.h" + +#include "imstkScene.h" +#include "imstkCamera.h" +#include "imstkDirectionalLight.h" +#include "imstkSpotLight.h" +#include "imstkSceneObject.h" +#include "imstkTaskGraph.h" + +using namespace imstk; + +TEST(imstkSceneTest, empty_scene_emptiness_checks) +{ + Scene scene("test scene"); + + // Do some basic checks for empty scene + EXPECT_EQ(scene.getName(), "test scene"); + EXPECT_EQ(scene.getSceneObjects().size(), 0); + EXPECT_EQ(scene.getControllers().size(), 0); + EXPECT_EQ(scene.getLights().size(), 0); + EXPECT_EQ(scene.getFPS(), 0.0); + EXPECT_EQ(scene.getGlobalIBLProbe(), nullptr); + + EXPECT_EQ(scene.getCameras().size(), 2); + EXPECT_EQ(scene.getCameraName(scene.getActiveCamera()), "default"); +} + +TEST(imstkSceneTest, empty_scene_default_cameras) +{ + Scene scene("test scene"); + + EXPECT_EQ(scene.getCameras().size(), 2); + EXPECT_EQ(scene.getCameraName(scene.getActiveCamera()), "default"); +} + +TEST(imstkSceneTest, empty_scene_initialize_advance) +{ + Scene scene("test scene"); + + // Calling advance before initialize should do nothing + EXPECT_NO_THROW({ scene.advance(0.1); }); + + // Initialize the first time + EXPECT_EQ(scene.initialize(), true); + EXPECT_EQ(scene.initialize(), true); // Repeated call + + // Advance after initialization + EXPECT_NO_THROW({ scene.advance(0.1); }); +} + +TEST(imstkSceneTest, empty_scene_bounding_box) +{ + Scene scene("test scene"); + + // check bounding box + Vec3d lowerLeft, upperRight; + scene.computeBoundingBox(lowerLeft, upperRight, 2.0); + EXPECT_EQ(lowerLeft, Vec3d(0.0, 0.0, 0.0)); + EXPECT_EQ(upperRight, Vec3d(0.0, 0.0, 0.0)); +} + +TEST(imstkSceneTest, empty_scene_build_task_graph) +{ + Scene scene("test scene"); + EXPECT_NO_THROW(scene.buildTaskGraph(); ); +} + +TEST(imstkSceneTest, add_camera) +{ + Scene m_scene("test scene"); + + const auto defaultNumCam = m_scene.getCameras().size(); + + m_scene.addCamera("default", std::make_shared<Camera>()); // camera by name 'default' already exists + EXPECT_EQ(m_scene.getCameras().size(), defaultNumCam); + m_scene.addCamera("debug", std::make_shared<Camera>()); // camera by name 'debug' already exists + EXPECT_EQ(m_scene.getCameras().size(), defaultNumCam); + + auto cam0 = std::make_shared<Camera>(); + m_scene.addCamera("cam0", cam0); + EXPECT_EQ(m_scene.getCamera("cam0"), cam0); + EXPECT_EQ(m_scene.getCameras().size(), defaultNumCam + 1); +} + +TEST(imstkSceneTest, remove_camera) +{ + Scene m_scene("test scene"); + + const auto defaultNumCam = m_scene.getCameras().size(); + + m_scene.addCamera("cam0", std::make_shared<Camera>()); + + // test remove camera + m_scene.removeCamera("default"); // default cannot be removed + EXPECT_EQ(m_scene.getCameraName(m_scene.getActiveCamera()), "default"); + EXPECT_EQ(m_scene.getCameras().size(), defaultNumCam + 1); + + m_scene.removeCamera("cam0"); + EXPECT_EQ(m_scene.getCamera("cam0"), nullptr); + EXPECT_EQ(m_scene.getCameras().size(), defaultNumCam); +} + +TEST(imstkSceneTest, get_set_active_camera) +{ + Scene m_scene("test scene"); + + EXPECT_EQ(m_scene.getCameraName(m_scene.getActiveCamera()), "default"); + auto defaultCam = m_scene.getActiveCamera(); + + auto cam0 = std::make_shared<Camera>(); + m_scene.addCamera("cam0", cam0); + m_scene.setActiveCamera("cam0"); + EXPECT_EQ(m_scene.getActiveCamera(), cam0); + + m_scene.setActiveCamera("default"); // switch back + EXPECT_EQ(m_scene.getActiveCamera(), defaultCam); +} + +TEST(imstkSceneTest, add_remove_lights) +{ + Scene m_scene("sample scene"); + + auto light0 = std::make_shared<SpotLight>(); + m_scene.addLight("light0", light0); + EXPECT_EQ(m_scene.getLight("light0"), light0); + EXPECT_EQ(m_scene.getLights().size(), 1); + + // Add another light with the same name + auto light0_2 = std::make_shared<DirectionalLight>(); + m_scene.addLight("light0", light0_2); + EXPECT_NE(m_scene.getLight("light0"), light0_2); + + // test remove light + m_scene.removeLight("light0"); + EXPECT_EQ(m_scene.getLight("light0"), nullptr); + EXPECT_EQ(m_scene.getLights().size(), 0); +} + +TEST(imstkSceneTest, add_remove_scene_objects) +{ + Scene m_scene("sample scene"); + + // Add a scene object and do some checks + auto so = std::make_shared<SceneObject>("sceneObject0"); + m_scene.addSceneObject(so); + EXPECT_EQ(m_scene.getSceneObject("sceneObject0"), so); + EXPECT_EQ(m_scene.getSceneObjects().size(), 1); + + m_scene.addSceneObject(so); + EXPECT_EQ(m_scene.getSceneObjects().size(), 1); + + // remove the scene object and do some checks + m_scene.removeSceneObject(so); + EXPECT_EQ(m_scene.getSceneObject("sceneObject0"), nullptr); + EXPECT_EQ(m_scene.getSceneObjects().size(), 0); +} \ No newline at end of file diff --git a/Source/Scene/imstkScene.cpp b/Source/Scene/imstkScene.cpp index a2022f16141d353aa5f7e42ec8eaecf958384f4d..751faecd8825fae3778f4bedf81b7adb06186ae0 100644 --- a/Source/Scene/imstkScene.cpp +++ b/Source/Scene/imstkScene.cpp @@ -100,6 +100,13 @@ Scene::initialize() void Scene::computeBoundingBox(Vec3d& lowerCorner, Vec3d& upperCorner, const double paddingPercent) { + if (this->getSceneObjects().size() == 0) + { + lowerCorner = Vec3d(0., 0., 0.); + upperCorner = Vec3d(0., 0., 0.); + return; + } + lowerCorner = Vec3d(IMSTK_DOUBLE_MAX, IMSTK_DOUBLE_MAX, IMSTK_DOUBLE_MAX); upperCorner = Vec3d(IMSTK_DOUBLE_MIN, IMSTK_DOUBLE_MIN, IMSTK_DOUBLE_MIN); @@ -243,20 +250,6 @@ Scene::getSceneObject(const std::string& name) const return (iter == m_sceneObjects.end()) ? nullptr : *iter; } -bool -Scene::hasSceneObject(std::shared_ptr<SceneObject> sceneObject) -{ - return m_sceneObjects.count(sceneObject) != 0; -} - -bool -Scene::hasSceneObjectName(const std::string& name) -{ - auto iter = std::find_if(m_sceneObjects.begin(), m_sceneObjects.end(), - [name](const std::shared_ptr<SceneObject>& i) { return i->getName() == name; }); - return iter != m_sceneObjects.end(); -} - const std::vector<std::shared_ptr<VisualModel>> Scene::getDebugRenderModels() const { @@ -275,7 +268,7 @@ Scene::addSceneObject(std::shared_ptr<SceneObject> newSceneObject) { std::string name = newSceneObject->getName(); - if (this->hasSceneObjectName(name)) + if (this->getSceneObject(name) != nullptr) { LOG(WARNING) << "Can not add object: '" << name << "' is already registered in this scene."; @@ -333,12 +326,6 @@ Scene::removeSceneObject(std::shared_ptr<SceneObject> sceneObject) } } -bool -Scene::isLightRegistered(const std::string& lightName) const -{ - return m_lightsMap.find(lightName) != m_lightsMap.end(); -} - const std::vector<std::shared_ptr<Light>> Scene::getLights() const { @@ -357,7 +344,7 @@ Scene::getLights() const std::shared_ptr<Light> Scene::getLight(const std::string& lightName) const { - if (!this->isLightRegistered(lightName)) + if ((m_lightsMap.find(lightName) == m_lightsMap.end())) { LOG(WARNING) << "No light named '" << lightName << "' was registered in this scene."; @@ -368,26 +355,24 @@ Scene::getLight(const std::string& lightName) const } void -Scene::addLight(std::shared_ptr<Light> newLight) +Scene::addLight(const std::string& name, std::shared_ptr<Light> newLight) { - std::string newlightName = newLight->getName(); - - if (this->isLightRegistered(newlightName)) + if (this->getLight(name) != nullptr) { - LOG(WARNING) << "Can not add light: '" << newlightName + LOG(WARNING) << "Can not add light: '" << name << "' is already registered in this scene."; return; } - m_lightsMap[newlightName] = newLight; + m_lightsMap[name] = newLight; this->postEvent(Event(modified())); - LOG(INFO) << newlightName << " light added to " << m_name; + LOG(INFO) << name << " light added to " << m_name; } void Scene::removeLight(const std::string& lightName) { - if (!this->isLightRegistered(lightName)) + if (this->getLight(lightName) == nullptr) { LOG(WARNING) << "No light named '" << lightName << "' was registered in this scene."; @@ -427,6 +412,16 @@ Scene::getCamera(const std::string name) const } } +void +Scene::addCamera(const std::string& name, std::shared_ptr<Camera> cam) +{ + if (m_cameras.find(name) != m_cameras.end()) + { + LOG(WARNING) << "Cannot add camera: Camera with the name " << name << " already exists."; + } + m_cameras[name] = cam; +} + void Scene::setActiveCamera(const std::string name) { @@ -437,6 +432,22 @@ Scene::setActiveCamera(const std::string name) } } +void +Scene::removeCamera(const std::string name) +{ + auto i = m_cameras.find(name); + if (i != m_cameras.end() && !(name == "default" || name == "debug")) + { + m_cameras.erase(name); + LOG(INFO) << name << " camera removed from " << m_name; + } + else + { + LOG(WARNING) << "No camera named '" << name + << "' is part of the scene."; + } +} + void Scene::addController(std::shared_ptr<TrackingDeviceControl> controller) { @@ -499,7 +510,10 @@ Scene::advance(const double dt) CollisionDetection::updateInternalOctreeAndDetectCollision(); // Execute the computational graph - m_taskGraphController->execute(); + if (m_taskGraphController != nullptr) + { + m_taskGraphController->execute(); + } // Apply updated forces on device for (auto controller : this->getControllers()) diff --git a/Source/Scene/imstkScene.h b/Source/Scene/imstkScene.h index bb4b14e25289ef793fd91de0fb8c638a518b60ef..dbe860f0fd2c0491385b8a0d443a2d59271a589c 100644 --- a/Source/Scene/imstkScene.h +++ b/Source/Scene/imstkScene.h @@ -158,7 +158,7 @@ public: /// /// \brief Return a vector of shared pointers to the scene objects - /// NOTE: A separate list might be efficient as this is called runtime + /// \note A separate list might be efficient as this is called runtime /// const std::vector<std::shared_ptr<VisualModel>> getDebugRenderModels() const; @@ -172,16 +172,6 @@ public: /// std::shared_ptr<SceneObject> getSceneObject(const std::string& sceneObjectName) const; - /// - /// \brief Returns true if SceneObject is apart of scene - /// - bool hasSceneObject(std::shared_ptr<SceneObject> sceneObject); - - /// - /// \brief Returns true if a SceneObject with name already exists - /// - bool hasSceneObjectName(const std::string& name); - /// /// \brief Add/remove a scene object /// @@ -202,11 +192,6 @@ public: /// void addDebugVisualModel(std::shared_ptr<VisualModel> dbgRenderModel); - /// - /// \brief Returns true if the light (checked against name) is registered to the scene, else false. - /// - bool isLightRegistered(const std::string& lightName) const; - /// /// \brief Return a vector of lights in the scene /// @@ -218,14 +203,14 @@ public: std::shared_ptr<Light> getLight(const std::string& lightName) const; /// - /// \brief + /// \brief Get and unordered map of cameras with names /// const NamedMap<Camera>& getCameras() const { return m_cameras; } /// /// \brief Add light from the scene /// - void addLight(std::shared_ptr<Light> newLight); + void addLight(const std::string& name, std::shared_ptr<Light> newLight); /// /// \brief Remove light with a given name from the scene @@ -270,7 +255,7 @@ public: /// /// \brief Set the camera for the scene /// - void addCamera(std::string name, std::shared_ptr<Camera> cam) { m_cameras[name] = cam; } + void addCamera(const std::string& name, std::shared_ptr<Camera> cam); /// /// \brief Switch the active camera to the one requested by name. @@ -278,6 +263,11 @@ public: /// void setActiveCamera(const std::string name); + /// + /// \brief Remove the camera with a given name + /// + void removeCamera(const std::string name); + /// /// \brief Return the collision graph of the scene /// diff --git a/Source/SceneEntities/Lights/imstkDirectionalLight.h b/Source/SceneEntities/Lights/imstkDirectionalLight.h new file mode 100644 index 0000000000000000000000000000000000000000..7c56afb0ec14b909200b279d761dd3f4904c738b --- /dev/null +++ b/Source/SceneEntities/Lights/imstkDirectionalLight.h @@ -0,0 +1,54 @@ +/*========================================================================= + + Library: iMSTK + + Copyright (c) Kitware, Inc. & Center for Modeling, Simulation, + & Imaging in Medicine, Rensselaer Polytechnic Institute. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0.txt + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +=========================================================================*/ + +#pragma once + +#include "imstkLight.h" + +namespace imstk +{ +/// +/// \class DirectionalLight +/// +/// \brief Directional light class +/// +/// A directional light has no position or range. The focal point is the +/// direction. +/// +class DirectionalLight : public Light +{ +public: + DirectionalLight() : Light(LightType::Directional) + { + this->setFocalPoint(-1.0f, -1.0f, -1.0f); + } + + virtual ~DirectionalLight() override = default; + + virtual const std::string getTypeName() const { return "DirectionalLight"; } + + /// + /// \brief Direction of the light + /// + void setDirection(const Vec3d& dir) { setFocalPoint(dir); } + void setDirection(const double x, const double y, const double z) { setFocalPoint(Vec3d(x, y, z)); } +}; +} // imstk \ No newline at end of file diff --git a/Source/SceneEntities/Lights/imstkLight.cpp b/Source/SceneEntities/Lights/imstkLight.cpp index ee9dea0c8b1828510ff7dae9051579f3b64c91d6..fc1604d4b41bb3e263627a4f840730a4a092372e 100644 --- a/Source/SceneEntities/Lights/imstkLight.cpp +++ b/Source/SceneEntities/Lights/imstkLight.cpp @@ -36,6 +36,4 @@ Light::setFocalPoint(const float& x, const float& y, const float& z) LOG(WARNING) << "Directional lights can't have focal point at (0, 0, 0)"; } } - -//--------------------------------------------------------------------------------- } // imstk diff --git a/Source/SceneEntities/Lights/imstkLight.h b/Source/SceneEntities/Lights/imstkLight.h index 333df01c14bc24a8fae9537559737e3044466752..8b2106aaf4f307e1f6ea4ec5292b7d2b9715f424 100644 --- a/Source/SceneEntities/Lights/imstkLight.h +++ b/Source/SceneEntities/Lights/imstkLight.h @@ -107,18 +107,8 @@ public: /// void setIntensity(double intensity) { m_intensity = (float)intensity; } - /// - /// \brief Get the light name - /// - const std::string& getName() const { return m_name; } - - /// - /// \brief Set the light name - /// - void setName(std::string name) { m_name = name; } - protected: - Light(const std::string& name, const LightType& type) : SceneEntity(), m_name(name), m_type(type) { } + Light(const LightType& type) : SceneEntity(), m_type(type) { } // properties with defaults float m_intensity = 1.; @@ -126,134 +116,6 @@ protected: bool m_switchState = true; Vec3f m_focalPoint = Vec3f(0, 0, 0); - std::string m_name; - LightType m_type; -}; - -//----------------------------------------------------------------------------- - -/// -/// \class DirectionalLight -/// -/// \brief Directional light class -/// -/// A directional light has no position or range. The focal point is the -/// direction. -/// -class DirectionalLight : public Light -{ -public: - DirectionalLight(const std::string& name) : Light(name, LightType::Directional) - { - this->setFocalPoint(-1.0f, -1.0f, -1.0f); - } - - virtual ~DirectionalLight() override = default; - -public: - virtual const std::string getTypeName() const { return "DirectionalLight"; } - - /// - /// \brief Direction of the light - /// - void setDirection(const Vec3d& dir) { setFocalPoint(dir); } - void setDirection(const double x, const double y, const double z) { setFocalPoint(Vec3d(x, y, z)); } - -protected: -}; - -//----------------------------------------------------------------------------- - -/// -/// \class PointLight -/// -/// \brief Point light class -/// -/// A point light has a position, and it's range is determined by it's -/// intensity. -/// -class PointLight : public Light -{ -public: - /// - /// \brief Constructors - /// - PointLight(const std::string& name, const LightType& type = LightType::Point) : Light(name, type) { } - - virtual ~PointLight() override = default; - -public: - virtual const std::string getTypeName() const { return "PointLight"; } - - /// - /// \brief Get the cone angle - /// - const float getConeAngle() const { return m_coneAngle; } - - /// - /// \brief Get the light position - /// - void setConeAngle(const double angle) { m_coneAngle = (float)angle; } - - /// - /// \brief Get the light position - /// - const Vec3f getPosition() const { return m_position; } - - /// - /// \brief Set the light position - /// - void setPosition(const Vec3d& p) - { - m_position = Vec3f( - static_cast<float>(p[0]), - static_cast<float>(p[1]), - static_cast<float>(p[2])); - }; - void setPosition(const double& x, const double& y, const double& z) - { - this->setPosition(Vec3d(x, y, z)); - } - -protected: - Vec3f m_position = Vec3f(0.0f, 0.0f, 0.0f); - float m_coneAngle = 179.0f; -}; - -//----------------------------------------------------------------------------- - -/// -/// \class Spot light class -/// -/// \brief A spot light is a point light in a cone shape. -/// -class SpotLight : public PointLight -{ -public: - /// - /// \brief Constructors - /// - SpotLight(const std::string& name) : PointLight(name, LightType::Spot) - { - m_coneAngle = 10.0f; - } - - virtual ~SpotLight() override = default; - -public: - virtual const std::string getTypeName() const { return "SpotLight"; } - - /// - /// \brief Get the spotlight angle in degrees - /// - float getSpotAngle() const { return m_spotAngle; } - - /// - /// \brief Set the spotlight angle in degrees - /// - void setSpotAngle(const double& angle) { m_spotAngle = static_cast<float>(angle); } - -protected: - float m_spotAngle = 45.0f; + LightType m_type; }; } // imstk \ No newline at end of file diff --git a/Source/SceneEntities/Lights/imstkPointLight.h b/Source/SceneEntities/Lights/imstkPointLight.h new file mode 100644 index 0000000000000000000000000000000000000000..690e00357a122fda790ce4a690df5be68c55abf3 --- /dev/null +++ b/Source/SceneEntities/Lights/imstkPointLight.h @@ -0,0 +1,83 @@ +/*========================================================================= + + Library: iMSTK + + Copyright (c) Kitware, Inc. & Center for Modeling, Simulation, + & Imaging in Medicine, Rensselaer Polytechnic Institute. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0.txt + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +=========================================================================*/ + +#pragma once + +#include "imstkLight.h" + +namespace imstk +{ +/// +/// \class PointLight +/// +/// \brief Point light class +/// +/// A point light has a position, and it's range is determined by it's +/// intensity. +/// +class PointLight : public Light +{ +public: + /// + /// \brief Constructors + /// + PointLight(const LightType& type = LightType::Point) : Light(type) { } + + virtual ~PointLight() override = default; + +public: + virtual const std::string getTypeName() const { return "PointLight"; } + + /// + /// \brief Get the cone angle + /// + const float getConeAngle() const { return m_coneAngle; } + + /// + /// \brief Get the light position + /// + void setConeAngle(const double angle) { m_coneAngle = (float)angle; } + + /// + /// \brief Get the light position + /// + const Vec3f getPosition() const { return m_position; } + + /// + /// \brief Set the light position + /// + void setPosition(const Vec3d& p) + { + m_position = Vec3f( + static_cast<float>(p[0]), + static_cast<float>(p[1]), + static_cast<float>(p[2])); + }; + void setPosition(const double& x, const double& y, const double& z) + { + this->setPosition(Vec3d(x, y, z)); + } + +protected: + Vec3f m_position = Vec3f(0.0f, 0.0f, 0.0f); + float m_coneAngle = 179.0f; +}; +} // imstk \ No newline at end of file diff --git a/Source/SceneEntities/Lights/imstkSpotLight.h b/Source/SceneEntities/Lights/imstkSpotLight.h new file mode 100644 index 0000000000000000000000000000000000000000..c9c3205a1095a82fb500940fcba9acf1ed55a22a --- /dev/null +++ b/Source/SceneEntities/Lights/imstkSpotLight.h @@ -0,0 +1,64 @@ +/*========================================================================= + + Library: iMSTK + + Copyright (c) Kitware, Inc. & Center for Modeling, Simulation, + & Imaging in Medicine, Rensselaer Polytechnic Institute. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0.txt + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +=========================================================================*/ + +#pragma once + +#include "imstkPointLight.h" + +#include <string> + +namespace imstk +{ +/// +/// \class Spot light class +/// +/// \brief A spot light is a point light in a cone shape. +/// +class SpotLight : public PointLight +{ +public: + /// + /// \brief Constructors + /// + SpotLight() : PointLight(LightType::Spot) + { + m_coneAngle = 10.0f; + } + + virtual ~SpotLight() override = default; + +public: + virtual const std::string getTypeName() const { return "SpotLight"; } + + /// + /// \brief Get the spotlight angle in degrees + /// + float getSpotAngle() const { return m_spotAngle; } + + /// + /// \brief Set the spotlight angle in degrees + /// + void setSpotAngle(const double& angle) { m_spotAngle = static_cast<float>(angle); } + +protected: + float m_spotAngle = 45.0f; +}; +} // imstk \ No newline at end of file