opensurgsim
Computation.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_PHYSICS_COMPUTATION_H
17 #define SURGSIM_PHYSICS_COMPUTATION_H
18 
19 #include <vector>
20 #include <memory>
21 
22 #include "SurgSim/Framework/Timer.h"
23 
24 namespace SurgSim
25 {
26 namespace Physics
27 {
28 
29 class PhysicsManagerState;
30 
33 {
34 public:
35 
38  explicit Computation(bool doCopyState);
39 
41  virtual ~Computation();
42 
49  std::shared_ptr<PhysicsManagerState> update(double dt, const std::shared_ptr<PhysicsManagerState>& state);
50 
53  void setDoCopyState(bool val);
54 
57  bool isCopyingState();
58 
62  virtual std::string getClassName() const = 0;
63 
67 
68 protected:
69 
71  virtual std::shared_ptr<PhysicsManagerState> doUpdate(
72  const double& dt,
73  const std::shared_ptr<PhysicsManagerState>& state) = 0;
74 
75 private:
76  bool m_copyState;
77 
79  std::shared_ptr<PhysicsManagerState> preparePhysicsState(const std::shared_ptr<PhysicsManagerState>& state);
80 
82  Framework::Timer m_timer;
83 };
84 
85 
86 }; // Physics
87 }; // SurgSim
88 
89 #endif // SURGSIM_PHYSICS_COMPUTATION_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
virtual ~Computation()
Destructor.
Definition: Computation.cpp:31
std::shared_ptr< PhysicsManagerState > update(double dt, const std::shared_ptr< PhysicsManagerState > &state)
Public Interface execute this objects computations, dt is the time from the last update call in secon...
Definition: Computation.cpp:36
Framework::Timer & getTimer()
Provides access to the update timer.
Definition: Computation.cpp:54
void setDoCopyState(bool val)
Sets up whether the computation will copy the state of PhysicsManagerState before executing...
Definition: Computation.cpp:44
Timer class, measures execution times.
Definition: Timer.h:31
virtual std::shared_ptr< PhysicsManagerState > doUpdate(const double &dt, const std::shared_ptr< PhysicsManagerState > &state)=0
Override this function to implement the computations specific behavior.
Encapsulates a calculation over a selection of objects, needs to be subclassed to be used...
Definition: Computation.h:32
virtual std::string getClassName() const =0
The class name for this class.
Computation(bool doCopyState)
Constructor.
Definition: Computation.cpp:26
bool isCopyingState()
Query if this object is copying the PhysicsManagerState.
Definition: Computation.cpp:49