Computation.h
Go to the documentation of this file.
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 namespace SurgSim
23 {
24 namespace Physics
25 {
26 
27 class PhysicsManagerState;
28 
31 {
32 public:
33 
36  explicit Computation(bool doCopyState);
37 
39  virtual ~Computation();
40 
47  std::shared_ptr<PhysicsManagerState> update(double dt, const std::shared_ptr<PhysicsManagerState>& state);
48 
51  void setDoCopyState(bool val);
52 
55  bool isCopyingState();
56 
57 protected:
58 
60  virtual std::shared_ptr<PhysicsManagerState> doUpdate(
61  const double& dt,
62  const std::shared_ptr<PhysicsManagerState>& state) = 0;
63 
64 private:
66 
68  std::shared_ptr<PhysicsManagerState> preparePhysicsState(const std::shared_ptr<PhysicsManagerState>& state);
69 };
70 
71 
72 }; // Physics
73 }; // SurgSim
74 
75 #endif // SURGSIM_PHYSICS_COMPUTATION_H
Definition: DriveElementFromInputBehavior.cpp:27
virtual ~Computation()
Destructor.
Definition: Computation.cpp:30
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:35
void setDoCopyState(bool val)
Sets up whether the computation will copy the state of PhysicsManagerState before executing...
Definition: Computation.cpp:40
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.
std::shared_ptr< PhysicsManagerState > preparePhysicsState(const std::shared_ptr< PhysicsManagerState > &state)
Copy the PhysicsManagerState object when isCopyingState() is true.
Definition: Computation.cpp:50
Encapsulates a calculation over a selection of objects, needs to be subclassed to be used...
Definition: Computation.h:30
bool m_copyState
Definition: Computation.h:65
Computation(bool doCopyState)
Constructor.
Definition: Computation.cpp:25
bool isCopyingState()
Query if this object is copying the PhysicsManagerState.
Definition: Computation.cpp:45