Commit 5c071823 authored by Ricardo Ortiz's avatar Ricardo Ortiz
Browse files

ENH: Remove the now redundant DefaultSimulator class.

parent 298c6de2
......@@ -160,6 +160,7 @@ private:
static void VRPN_CALLBACK analogChangeHandler(void *userData, const vrpn_ANALOGCB a);
protected:
DeviceType deviceType; //!< Device type
std::string deviceURL; //!< Connection device URL
private:
......
......@@ -28,7 +28,7 @@ namespace imstk {
VRPNForceDevice::VRPNForceDevice(std::string deviceURL)
: VRPNDeviceClient(DeviceType::PHANTOM_OMNI, deviceURL),
enableForce(true),
contactPlane(core::Vec4f(0.0,1.0,0.0,100)),
contactPlane(Vec4f(0.0,1.0,0.0,100)),
dampingCoefficient(0.5),
dynamicFriction(0.0),
springCoefficient(1.0),
......
......@@ -36,7 +36,6 @@
#include "Mesh/VegaVolumetricMesh.h"
#include "SceneModels/StaticSceneObject.h"
#include "SceneModels/VegaFEMDeformableSceneObject.h"
#include "Simulators/DefaultSimulator.h"
#include "Simulators/ObjectSimulator.h"
#include "VirtualTools/ToolCoupler.h"
#include "Rendering/InitVTKRendering.h"
......
......@@ -34,12 +34,11 @@
#include "Devices/VRPNDeviceServer.h"
#include "VirtualTools/ToolCoupler.h"
#include "VirtualTools/LaparoscopicCameraController.h"
#include "Simulators/DefaultSimulator.h"
#include "Collision/PlaneCollisionModel.h"
#include "Collision/MeshCollisionModel.h"
#include "IO/InitIO.h"
#include "VTKRendering/InitVTKRendering.h"
#include "VTKRendering/VTKViewer.h"
#include "Rendering/InitVTKRendering.h"
#include "Rendering/VTKViewer.h"
// VTK includes
#include <vtkNew.h>
......@@ -342,7 +341,7 @@ void add2DOverlay(std::shared_ptr<imstk::VTKViewer> vtkViewer,
imageActor->SetPosition(0.5, 0.5);
// Renderer
vtkRenderer* rendererVtk = vtkViewer->getRenderWindow()->GetRenderers()->GetFirstRenderer();
vtkRenderer* rendererVtk = vtkViewer->getVtkRenderWindow()->GetRenderers()->GetFirstRenderer();
rendererVtk->AddActor2D(imageActor.GetPointer());
}
......@@ -358,26 +357,45 @@ int addCameraController(std::shared_ptr<imstk::SDK> sdk)
switch( controllerType )
{
case imstk::DeviceType::NAVIGATOR_3DCONNEXION:
{
deviceURL = "navigator@localhost";
break;
}
case imstk::DeviceType::SPACE_EXPLORER_3DCONNEXION:
{
deviceURL = "device0@localhost";
break;
}
case imstk::DeviceType::PHANTOM_OMNI:
{
deviceURL = "Phantom0@localhost"; //"Phantom@10.171.2.217"
break;
}
case imstk::DeviceType::XKEYS_XK3:
{
deviceURL = "xkeys0@localhost";
break;
}
case imstk::DeviceType::OSVR_HDK:
{
deviceURL = "com_osvr_Multiserver/OSVRHackerDevKit0@localhost";
break;
}
case imstk::DeviceType::RAZER_HYDRA:
{
deviceURL = "razer@localhost";
break;
}
default:
{
std::cerr << "Unknown controller type" << std::endl;
}
}
auto camClient = std::make_shared<imstk::VRPNDeviceClient>(controllerType, deviceURL);
std::cout<<"Device URL = "<<camClient->getDeviceURL()<<std::endl;
// Set server
std::shared_ptr<imstk::VRPNDeviceServer> server = std::make_shared<VRPNDeviceServer>();
std::shared_ptr<imstk::VRPNDeviceServer> server = std::make_shared<imstk::VRPNDeviceServer>();
server->addDeviceClient(camClient);
// Get vtkCamera
......@@ -395,6 +413,7 @@ int addCameraController(std::shared_ptr<imstk::SDK> sdk)
sdk->registerModule(server);
sdk->registerModule(camClient);
sdk->registerModule(camController);
return 0;
}
int main()
......@@ -432,7 +451,7 @@ int main()
// not to erase the changes on the observers made to the
// interactor in vtkViewer::addRenderer()
vtkNew<ScreenCaptureInteractorStyle> style;
style->initialize(vtkViewer->getRenderWindow());
style->initialize(vtkViewer->getVtkRenderWindow());
vtkViewer->getVtkRenderWindowInteractor()->SetInteractorStyle(style.GetPointer());
style->SetCurrentRenderer(vtkViewer->getVtkRenderer());
......
......@@ -25,5 +25,5 @@ add_executable(${Module}UnitTestRunner
)
target_compile_options(${Module}UnitTestRunner PRIVATE $<$<CXX_COMPILER_ID:GNU>:-Wno-old-style-cast -Wno-multichar -Wno-type-limits>)
target_link_libraries(${Module}UnitTestRunner Core Mesh Rendering Geometry IO)
target_link_libraries(${Module}UnitTestRunner Core Mesh Rendering Geometry IO SceneModels)
simple_test(${Module} --reporter=xunit)
......@@ -311,7 +311,7 @@ public:
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor;
};
VTKViewer::VTKViewer() : renderer(make_unique<VTKRenderer> (this))
VTKViewer::VTKViewer() : renderer(imstk::make_unique<VTKRenderer> (this))
{
this->name = "VTKViewer";
}
......
......@@ -97,6 +97,7 @@ void DeformableSceneObject::update(const double dt)
!std::isfinite(this->newState->getVelocities().sum()))
{
// TODO: log this and throw exception, this is a fatal error
std::cerr << "Error: Invalid state." << std::endl;
return;
}
......
......@@ -96,7 +96,7 @@ public:
///
/// \brief Update cumulative forces
///
void updateExternalForces(const std::unordered_map<size_t,Vec3d> &forces);
void updateExternalForces(const std::unordered_map<size_t,Vec3d> &forces) override;
private:
///////////////////////////////////////////////////////////////////////////////
......
......@@ -44,8 +44,9 @@ go_bandit([]()
it("updates", [&]()
{
sceneObject->update(0.01);
bool validState = !std::isfinite(sceneObject->getCurrentState()->getPositions().sum()) ||
!std::isfinite(sceneObject->getCurrentState()->getVelocities().sum());
auto sum1 = sceneObject->getCurrentState()->getPositions().sum();
auto sum2 = sceneObject->getCurrentState()->getVelocities().sum();
bool validState = std::isfinite(sum1) && std::isfinite(sum2);
AssertThat(validState, IsTrue());
});
});
......
......@@ -370,7 +370,7 @@ void VegaFEMDeformableSceneObject::initialize()
//---------------------------------------------------------------------------
bool VegaFEMDeformableSceneObject::configure(const std::string &configFile)
{
this->vegaFemConfig = make_unique<VegaConfiguration>(configFile);
this->vegaFemConfig = imstk::make_unique<VegaConfiguration>(configFile);
this->setMassMatrix();
this->setTangentStiffnessMatrix();
......
......@@ -31,6 +31,7 @@ target_link_libraries(SimulationManager
PRIVATE
Core
Simulators
Rendering
)
if(BUILD_TESTING)
......
// This file is part of the iMSTK project.
//
// Copyright (c) Kitware, Inc.
//
// 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.
// iMSTK includes
#include "Simulators/DefaultSimulator.h"
#include "SceneModels/StaticSceneObject.h"
#include "Core/Event.h"
#include "Event/KeyboardEvent.h"
#include "Collision/MeshCollisionModel.h"
#include "Devices/VRPNForceDevice.h"
#include "VirtualTools/ToolCoupler.h"
namespace imstk {
DefaultSimulator::DefaultSimulator( ) : ObjectSimulator( )
{
this->addOperation([](std::shared_ptr<MeshModel> &model)
{
for(auto &x : model->getMesh()->getVertices())
{
x.array() += 0.000001;
}
});
}
void DefaultSimulator::beginExecution()
{
//start the job
}
void DefaultSimulator::initialize()
{
//do nothing for now
}
void DefaultSimulator::run()
{
beginExecution();
for(auto &model : this->simulatedModels)
{
model->update(this->timeStep);
this->updateHapticForces(model);
}
endExecution();
}
void DefaultSimulator::endExecution()
{
//end the job
}
void DefaultSimulator::syncBuffers()
{
}
void DefaultSimulator::handleEvent(std::shared_ptr<Event> p_event )
{
if(!this->isListening())
{
return;
}
auto keyboardEvent = std::static_pointer_cast<imstk::KeyboardEvent>(p_event);
if(keyboardEvent)
{
switch(keyboardEvent->getKeyPressed())
{
case imstk::Key::F1:
{
std::cout << "F1 Keyboard is pressed " ;//<< keyboardEvent->getKeyPressed() << std::endl;
break;
}
default:
break;
}
}
}
void DefaultSimulator::updateHapticForces(std::shared_ptr<SceneObject> sceneObject)
{
auto outputDevice = std::dynamic_pointer_cast<VRPNForceDevice>(this->hapticTool->getOutputDevice());
if(!outputDevice)
{
// TODO: log this
return;
}
auto forces = sceneObject->getContactForces();
auto points = sceneObject->getContactPoints();
if(forces.size() == 0)
{
Vec3f normal(0,1,0);
outputDevice->setContactPlane(normal,100);
return;
}
Vec3d totalForce = Vec3d::Zero();
for(const auto &f : forces)
{
totalForce = f.second;
}
Vec3d contactPoint = Vec3d::Zero();
for(const auto &p : points)
{
contactPoint = p.second;
}
contactPoint /= points.size();
float norm = totalForce.norm();
auto normal = totalForce.normalized();
outputDevice->setContactPlane(normal.cast<float>(),0);
outputDevice->setDampingCoefficient(0.001);
outputDevice->setDynamicFriction(0.0);
outputDevice->setSpringCoefficient(norm);
outputDevice->setStaticFriction(0.0);
}
}
// This file is part of the iMSTK project.
//
// Copyright (c) Kitware, Inc.
//
// 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.
#ifndef SIMULATORS_DUMMYSIMULATOR_H
#define SIMULATORS_DUMMYSIMULATOR_H
#include <memory>
#include <vector>
#include <functional>
// iMSTK includes
#include "Core/Config.h"
#include "Simulators/ObjectSimulator.h"
#include "Core/ErrorLog.h"
#include "Core/Vector.h"
namespace imstk {
class ToolCoupler;
class MeshModel;
///
/// \brief Default simulator that applies operations to the position array of the
/// undelying scene object model.
/// Operations can be added to the list of operator using \addOperation.
/// This function takes a lambda with void(std::vector<Vec3d>&) signature.
///
class DefaultSimulator: public ObjectSimulator
{
typedef std::function<void(std::shared_ptr<MeshModel> &sceneObject)> OperationType;
public:
/// \brief Constructor/Destructor
DefaultSimulator();
~DefaultSimulator(){}
void addOperation(const OperationType &op)
{
this->operatorFunctions.push_back(op);
}
protected:
///
/// Overriden methods
///
virtual void beginExecution() override;
virtual void initialize() override;
virtual void run() override;
void endExecution() override;
void syncBuffers() override;
void handleEvent(std::shared_ptr<Event> p_event) override;
void updateHapticForces(std::shared_ptr<SceneObject> sceneObject);
private:
std::vector<OperationType> operatorFunctions;
std::shared_ptr<ToolCoupler> hapticTool;
};
}
#endif
......@@ -25,9 +25,6 @@ OdeSystem::OdeSystem(): BaseSystem(systemMatrix, rhs)
{
}
//---------------------------------------------------------------------------
OdeSystem::~OdeSystem() {}
//---------------------------------------------------------------------------
void OdeSystem::setJaconbianFv(OdeSystem::JacobianOperatorType newDFv)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment