From a386ca3702cbdbbcb4584d13b50457ebee9b1c11 Mon Sep 17 00:00:00 2001
From: Sreekanth Arikatla <sreekanth.arikatla@kitware.com>
Date: Sun, 8 Jul 2018 18:27:47 -0400
Subject: [PATCH] REFAC: Clean examples

---
 Examples/Audio/Audio.cpp                              | 11 +++++++++--
 Examples/CameraController/CameraController.cpp        | 11 ++++++++---
 Examples/DeformableBody/DeformableBody.cpp            | 10 +---------
 Examples/GeometryTransforms/GeometryTransforms.cpp    |  7 +++++++
 Examples/Graph/Graph.cpp                              |  1 +
 .../LaparoscopicToolController.cpp                    |  6 ++++--
 Examples/MeshIO/MeshIO.cpp                            |  7 +++++++
 Examples/MshVegaIO/MshVegaIO.cpp                      | 10 +++-------
 Examples/PBDCloth/pbdClothExample.cpp                 |  1 -
 Examples/PBDFluids/PBDFluidsExample.cpp               |  1 +
 Examples/PBDVolume/PBDVolumeExample.cpp               |  1 +
 Examples/Picking/Picking.cpp                          |  8 ++++++--
 Examples/PlotVectors/PlotVectors.cpp                  |  1 +
 Examples/Rendering/Rendering.cpp                      |  2 ++
 Examples/SceneManagement/SceneManagement.cpp          |  2 --
 Examples/Screenshot/Screenshot.cpp                    |  1 +
 Examples/Viewer/Viewer.cpp                            |  1 +
 Examples/VirtualCoupling/VirtualCoupling.cpp          |  8 +++++---
 18 files changed, 58 insertions(+), 31 deletions(-)

diff --git a/Examples/Audio/Audio.cpp b/Examples/Audio/Audio.cpp
index 37043adfb..6324fde12 100644
--- a/Examples/Audio/Audio.cpp
+++ b/Examples/Audio/Audio.cpp
@@ -72,7 +72,7 @@ void playSound(const std::string& filename)
         std::cout << std::flush;
     }
     std::cout << "\n" << std::endl;
-#else
+#else if
     LOG(INFO) << "testSound: Audio is supported only on windows!";
 #endif
 }
@@ -117,12 +117,17 @@ void playMusic(const std::string& filename)
 /// \brief This example demonstrates the audio feature in imstk.
 /// NOTE: Example modified from SFML/Examples
 ///
-void main()
+int main()
 {
     // Initialize g3logger
     auto logger = std::make_shared<LogUtility>();
     logger->createLogger("audio-Example", "./");
 
+    #ifndef iMSTK_AUDIO_ENABLED
+        LOG(INFO) << "Audio not enabled at build time\n";        
+        return 1;
+    #endif
+    
     LOG(INFO) << "--Testing audio--\n";
 
     // Test a sound
@@ -130,4 +135,6 @@ void main()
 
     // Test music from an .ogg file
     playMusic(iMSTK_DATA_ROOT "/sound/orchestral.ogg");
+
+    return 0;
 }
\ No newline at end of file
diff --git a/Examples/CameraController/CameraController.cpp b/Examples/CameraController/CameraController.cpp
index dcbb346e8..d9e61b836 100644
--- a/Examples/CameraController/CameraController.cpp
+++ b/Examples/CameraController/CameraController.cpp
@@ -40,7 +40,12 @@ using namespace imstk;
 ///
 int main()
 {
-    // SDK and Scene
+    #ifndef iMSTK_USE_OPENHAPTICS
+        std::cout << "Audio not enabled at build time" << std::endl;        
+        return 1;
+    #endif
+
+    // Create SDK and Scene
     auto sdk = std::make_shared<SimulationManager>();
     auto scene = sdk->createNewScene("CameraController");
 
@@ -57,7 +62,7 @@ int main()
 #endif
 
 
-    // Mesh
+    // Load Mesh
     auto mesh = MeshIO::read(iMSTK_DATA_ROOT "/asianDragon/asianDragon.obj");
     auto meshObject = std::make_shared<VisualObject>("meshObject");
     meshObject->setVisualGeometry(mesh);
@@ -68,7 +73,7 @@ int main()
     cam->setPosition(Vec3d(0, 0, 10));
 
 #ifdef iMSTK_USE_OPENHAPTICS
-
+    
     auto camControllerInput = std::make_shared<CameraController>(*cam, client);
 
     // Set camera controller
diff --git a/Examples/DeformableBody/DeformableBody.cpp b/Examples/DeformableBody/DeformableBody.cpp
index c6ec937d6..b48d1e2fa 100644
--- a/Examples/DeformableBody/DeformableBody.cpp
+++ b/Examples/DeformableBody/DeformableBody.cpp
@@ -47,10 +47,7 @@ int main()
     scene->getCamera()->setPosition(0, 2.0, 15.0);
 
     // b. Load a tetrahedral mesh
-    //auto tetMesh = MeshIO::read(iMSTK_DATA_ROOT "/oneTet/oneTet.veg");
     auto tetMesh = MeshIO::read(iMSTK_DATA_ROOT "/asianDragon/asianDragon.veg");
-    //auto tetMesh = MeshIO::read(iMSTK_DATA_ROOT"/liver/liver.veg");
-    //auto tetMesh = MeshIO::read(iMSTK_DATA_ROOT"/oneTet/oneTet.veg");
     if (!tetMesh)
     {
         LOG(WARNING) << "Could not read mesh from file.";
@@ -90,10 +87,8 @@ int main()
 
     // Configure dynamic model
     auto dynaModel = std::make_shared<FEMDeformableBodyModel>();
-    //dynaModel->configure(iMSTK_DATA_ROOT "/oneTet/oneTet.config");
     dynaModel->configure(iMSTK_DATA_ROOT "/asianDragon/asianDragon.config");
     dynaModel->setTimeStepSizeType(TimeSteppingType::realTime);
-    //dynaModel->configure(iMSTK_DATA_ROOT"/liver/liver.config");
     dynaModel->setModelGeometry(volTetMesh);
     auto timeIntegrator = std::make_shared<BackwardEuler>(0.001);// Create and add Backward Euler time integrator
     dynaModel->setTimeIntegrator(timeIntegrator);
@@ -105,7 +100,6 @@ int main()
     // Scene Object
     auto deformableObj = std::make_shared<DeformableObject>("Dragon");
     deformableObj->setVisualGeometry(surfMesh);
-    //deformableObj->setCollidingGeometry(surfMesh);
     deformableObj->setPhysicsGeometry(volTetMesh);
     deformableObj->setPhysicsToVisualMap(oneToOneNodalMap); //assign the computed map
     deformableObj->setDynamicalModel(dynaModel);
@@ -143,10 +137,7 @@ int main()
     nlSystem->setUpdatePreviousStatesFunction(dynaModel->getUpdatePrevStateFunction());
 
     // create a linear solver
-    //auto linSolver = std::make_shared<ConjugateGradient>();
     auto linSolver = std::make_shared<GaussSeidel>();
-    //auto linSolver = std::make_shared<Jacobi>();
-    //auto linSolver = std::make_shared<SOR>(0.4);
 
     // create a non-linear solver and add to the scene
     auto nlSolver = std::make_shared<NewtonSolver>();
@@ -168,5 +159,6 @@ int main()
     // Run the simulation
     sdk->setActiveScene(scene);
     sdk->startSimulation(SimulationStatus::PAUSED);
+    
     return 0;
 }
diff --git a/Examples/GeometryTransforms/GeometryTransforms.cpp b/Examples/GeometryTransforms/GeometryTransforms.cpp
index 9d781087d..a50ccf6b5 100644
--- a/Examples/GeometryTransforms/GeometryTransforms.cpp
+++ b/Examples/GeometryTransforms/GeometryTransforms.cpp
@@ -39,6 +39,12 @@ int main()
 
     auto sceneObj = apiutils::createAndAddVisualSceneObject(scene, iMSTK_DATA_ROOT "/asianDragon/asianDragon.obj", "Dragon");
 
+    if (!sceneObj)
+    {
+        LOG(WARNING) << "ERROR: Unable to create scene object";
+        return 1;
+    }
+
     auto surfaceMesh = sceneObj->getVisualGeometry();
     surfaceMesh->scale(5., Geometry::TransformType::ConcatenateToTransform);
 
@@ -95,5 +101,6 @@ int main()
     // Run
     sdk->setActiveScene(scene);
     sdk->startSimulation(SimulationStatus::RUNNING);
+
     return 0;
 }
diff --git a/Examples/Graph/Graph.cpp b/Examples/Graph/Graph.cpp
index b6e57f62f..2e0e38a60 100644
--- a/Examples/Graph/Graph.cpp
+++ b/Examples/Graph/Graph.cpp
@@ -76,5 +76,6 @@ int main()
 
     std::cout << "Press any key to exit!" << std::endl;
     getchar();
+
     return 0;
 }
diff --git a/Examples/LaparoscopicToolController/LaparoscopicToolController.cpp b/Examples/LaparoscopicToolController/LaparoscopicToolController.cpp
index 87189f8d0..c3571d2d7 100644
--- a/Examples/LaparoscopicToolController/LaparoscopicToolController.cpp
+++ b/Examples/LaparoscopicToolController/LaparoscopicToolController.cpp
@@ -80,7 +80,9 @@ int main()
     sdk->setActiveScene(scene);
     sdk->startSimulation(SimulationStatus::PAUSED);
 
-#endif
-
     return 0;
+#else if
+    std::cout << "LaparoscopicToolController example needs haptic device to be enabled at build time" << std::endl;
+    return 1;
+#endif
 }
diff --git a/Examples/MeshIO/MeshIO.cpp b/Examples/MeshIO/MeshIO.cpp
index 464fb9969..2d5db5544 100644
--- a/Examples/MeshIO/MeshIO.cpp
+++ b/Examples/MeshIO/MeshIO.cpp
@@ -45,6 +45,12 @@ int main()
     //auto vtkMesh2 = MeshIO::read(iMSTK_DATA_ROOT"/nidus/nidus.vtk");
     auto vegaMesh = MeshIO::read(iMSTK_DATA_ROOT "/asianDragon/asianDragon.veg");
 
+    if (!vegaMesh)
+    {
+        LOG(WARNING) << "Unable to load mesh!";
+        return 1;
+    }
+
     // Extract surface mesh
     auto volumeMesh = std::dynamic_pointer_cast<VolumetricMesh>(vegaMesh); // change to any volumetric mesh above
     volumeMesh->computeAttachedSurfaceMesh();
@@ -64,5 +70,6 @@ int main()
     // Run
     sdk->setActiveScene(scene);
     sdk->startSimulation(SimulationStatus::PAUSED);
+
     return 0;
 }
diff --git a/Examples/MshVegaIO/MshVegaIO.cpp b/Examples/MshVegaIO/MshVegaIO.cpp
index e50b7c976..fb2d42607 100644
--- a/Examples/MshVegaIO/MshVegaIO.cpp
+++ b/Examples/MshVegaIO/MshVegaIO.cpp
@@ -28,7 +28,7 @@ using namespace imstk;
 ///
 /// \brief This example shows how to read .msh and .veg files
 ///
-void MshAndVegaIO()
+int main()
 {
     // SDK and Scene
     auto sdk = std::make_shared<SimulationManager>();
@@ -40,7 +40,7 @@ void MshAndVegaIO()
     if (!volMeshA)
     {
         LOG(WARNING) << "Failed to read msh file : " << ifile;
-        return;
+        return 1;
     }
 
     // Extract surface mesh
@@ -65,7 +65,7 @@ void MshAndVegaIO()
     if (!volMeshB)
     {
         LOG(WARNING) << "Failed to extract topology/geometry from the veg file : " << ofile;
-        return;
+        return 1;
     }
 
     // Extract surface mesh
@@ -91,10 +91,6 @@ void MshAndVegaIO()
     // Run
     sdk->setActiveScene(scene);
     sdk->startSimulation(SimulationStatus::PAUSED);
-}
 
-int main()
-{
-    MshAndVegaIO();
     return 0;
 }
diff --git a/Examples/PBDCloth/pbdClothExample.cpp b/Examples/PBDCloth/pbdClothExample.cpp
index d38b7082f..4bd09d15b 100644
--- a/Examples/PBDCloth/pbdClothExample.cpp
+++ b/Examples/PBDCloth/pbdClothExample.cpp
@@ -129,6 +129,5 @@ int main()
     sdk->setActiveScene(scene);
     sdk->startSimulation(SimulationStatus::PAUSED);
 
-
     return 0;
 }
diff --git a/Examples/PBDFluids/PBDFluidsExample.cpp b/Examples/PBDFluids/PBDFluidsExample.cpp
index 6a85d98fb..fd70ea39c 100644
--- a/Examples/PBDFluids/PBDFluidsExample.cpp
+++ b/Examples/PBDFluids/PBDFluidsExample.cpp
@@ -249,5 +249,6 @@ int main()
 
     sdk->setActiveScene(scene);
     sdk->startSimulation(SimulationStatus::PAUSED);
+
     return 0;
 }
diff --git a/Examples/PBDVolume/PBDVolumeExample.cpp b/Examples/PBDVolume/PBDVolumeExample.cpp
index 7c6ef9585..eb985c8fb 100644
--- a/Examples/PBDVolume/PBDVolumeExample.cpp
+++ b/Examples/PBDVolume/PBDVolumeExample.cpp
@@ -115,5 +115,6 @@ int main()
     sdk->setActiveScene(scene);
     sdk->getViewer()->setBackgroundColors(Vec3d(0.3285, 0.3285, 0.6525), Vec3d(0.13836, 0.13836, 0.2748), true);
     sdk->startSimulation();
+
     return 0;
 }
diff --git a/Examples/Picking/Picking.cpp b/Examples/Picking/Picking.cpp
index cb61bd445..0be9f4255 100644
--- a/Examples/Picking/Picking.cpp
+++ b/Examples/Picking/Picking.cpp
@@ -44,6 +44,10 @@ using namespace imstk;
 ///
 int main()
 {
+#ifndef iMSTK_USE_OPENHAPTICS
+    std::cout << "LaparoscopicToolController example needs haptic device to be enabled at build time" << std::endl;
+    return 1;
+#else if
     // SDK and Scene
     auto sdk = std::make_shared<SimulationManager>();
     auto scene = sdk->createNewScene("Picking");
@@ -126,7 +130,6 @@ int main()
     //----------------------------------------------------------
     // Create object controller
     //----------------------------------------------------------
-#ifdef iMSTK_USE_OPENHAPTICS
 
     // Device clients
     auto client = std::make_shared<HDAPIDeviceClient>(phantomOmni1Name);
@@ -159,7 +162,6 @@ int main()
 
     // Create collision pair
     scene->getCollisionGraph()->addInteractionPair(physicsObj, sphereForPickObj, pickingCD, pickingCH, nullptr);
-#endif
 
     // Set Camera configuration
     auto cam = scene->getCamera();
@@ -169,5 +171,7 @@ int main()
     // Run
     sdk->setActiveScene(scene);
     sdk->startSimulation(SimulationStatus::PAUSED);
+
     return 0;
+#endif
 }
diff --git a/Examples/PlotVectors/PlotVectors.cpp b/Examples/PlotVectors/PlotVectors.cpp
index 95fe9f373..c8e946e1b 100644
--- a/Examples/PlotVectors/PlotVectors.cpp
+++ b/Examples/PlotVectors/PlotVectors.cpp
@@ -43,5 +43,6 @@ int main()
     plotterutils::writePlotterVecVsVecMatPlotlib(a, b, "plotXvsY.py");
 
     getchar();
+
     return 0;
 }
diff --git a/Examples/Rendering/Rendering.cpp b/Examples/Rendering/Rendering.cpp
index 113bbc43e..32fb7b03f 100644
--- a/Examples/Rendering/Rendering.cpp
+++ b/Examples/Rendering/Rendering.cpp
@@ -98,6 +98,8 @@ int main()
     viewer->disableVSync();
     viewer->enableFullscreen();
 #endif
+
     sdk->startSimulation(SimulationStatus::PAUSED);
+
     return 0;
 }
diff --git a/Examples/SceneManagement/SceneManagement.cpp b/Examples/SceneManagement/SceneManagement.cpp
index 9b5aae1d4..605a66811 100644
--- a/Examples/SceneManagement/SceneManagement.cpp
+++ b/Examples/SceneManagement/SceneManagement.cpp
@@ -28,8 +28,6 @@ using namespace imstk;
 ///
 int main()
 {
-    // THIS TESTS NEEDS TO DISABLE STANDALONE VIEWER RENDERING
-
     auto sdk = std::make_shared<SimulationManager>();
 
     // Scenes
diff --git a/Examples/Screenshot/Screenshot.cpp b/Examples/Screenshot/Screenshot.cpp
index 0c09621df..2ea5a975e 100644
--- a/Examples/Screenshot/Screenshot.cpp
+++ b/Examples/Screenshot/Screenshot.cpp
@@ -100,5 +100,6 @@ int main()
     // Run
     sdk->setActiveScene(sceneTest);
     sdk->startSimulation(SimulationStatus::PAUSED);
+
     return 0;
 }
diff --git a/Examples/Viewer/Viewer.cpp b/Examples/Viewer/Viewer.cpp
index 43fccdcf2..22c0be275 100644
--- a/Examples/Viewer/Viewer.cpp
+++ b/Examples/Viewer/Viewer.cpp
@@ -72,5 +72,6 @@ int main()
     // Run
     sdk->setActiveScene(sceneTest);
     sdk->startSimulation(SimulationStatus::PAUSED);
+
     return 0;
 }
diff --git a/Examples/VirtualCoupling/VirtualCoupling.cpp b/Examples/VirtualCoupling/VirtualCoupling.cpp
index 670ee6482..9ce1c0582 100644
--- a/Examples/VirtualCoupling/VirtualCoupling.cpp
+++ b/Examples/VirtualCoupling/VirtualCoupling.cpp
@@ -38,6 +38,10 @@ using namespace imstk;
 ///
 int main()
 {
+#ifndef iMSTK_USE_OPENHAPTICS
+    std::cout << "LaparoscopicToolController example needs haptic device to be enabled at build time" << std::endl;
+    return 1;
+#else if
     // SDK and Scene
     auto sdk = std::make_shared<SimulationManager>();
     auto scene = sdk->createNewScene("VirtualCoupling");
@@ -52,7 +56,6 @@ int main()
     scene->addSceneObject(planeObj);
 
     // Create the virtual coupling object controller
-#ifdef iMSTK_USE_OPENHAPTICS
 
     // Device clients
     auto client = std::make_shared<HDAPIDeviceClient>(phantomOmni1Name);
@@ -97,8 +100,6 @@ int main()
     colHandlingAlgo->setStiffness(5e-01);
     colHandlingAlgo->setDamping(0.005);
 
-#endif
-
     // Move Camera
     auto cam = scene->getCamera();
     cam->setPosition(Vec3d(200, 200, 200));
@@ -115,4 +116,5 @@ int main()
     sdk->startSimulation(SimulationStatus::RUNNING);
 
     return 0;
+#endif
 }
-- 
GitLab