Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pulse Physiology Suite
engine
Commits
2437a233
Commit
2437a233
authored
Jun 26, 2020
by
Aaron Bray
Browse files
Merge branch 'feature/documentation' of
https://gitlab.kitware.com/physiology/engine
into HEAD
parents
a852ca74
369d03a2
Changes
17
Expand all
Hide whitespace changes
Inline
Side-by-side
src/c/PulseEngineC.cpp
View file @
2437a233
...
...
@@ -80,9 +80,9 @@ C_EXPORT bool C_CALL SerializeToString(PulseEngineThunk* thunk, int format, char
}
extern
"C"
C_EXPORT
bool
C_CALL
InitializeEngine
(
PulseEngineThunk
*
thunk
,
const
char
*
patient_configuration
,
const
char
*
data_requests
,
int
format
,
const
char
*
data_dir
=
"."
)
C_EXPORT
bool
C_CALL
InitializeEngine
(
PulseEngineThunk
*
thunk
,
const
char
*
patient_configuration
,
const
char
*
data_requests
,
int
format
)
{
return
thunk
->
InitializeEngine
(
patient_configuration
==
nullptr
?
""
:
patient_configuration
,
data_requests
==
nullptr
?
""
:
data_requests
,
(
SerializationFormat
)
format
,
data_dir
==
nullptr
?
"./"
:
data_dir
);
return
thunk
->
InitializeEngine
(
patient_configuration
==
nullptr
?
""
:
patient_configuration
,
data_requests
==
nullptr
?
""
:
data_requests
,
(
SerializationFormat
)
format
);
}
extern
"C"
...
...
src/cpp/cdm/io/protobuf/PBEngine.cpp
View file @
2437a233
...
...
@@ -368,6 +368,7 @@ void PBEngine::Serialize(const CDM_BIND::PatientConfigurationData& src, SEPatien
const
CDM_BIND
::
ScalarPropertyData
&
sp
=
src
.
scalaroverride
()[
i
];
dst
.
AddScalarOverride
(
sp
.
name
(),
sp
.
value
(),
sp
.
unit
());
}
dst
.
SetDataRoot
(
src
.
dataroot
());
}
CDM_BIND
::
PatientConfigurationData
*
PBEngine
::
Unload
(
const
SEPatientConfiguration
&
src
)
{
...
...
@@ -391,6 +392,7 @@ void PBEngine::Serialize(const SEPatientConfiguration& src, CDM_BIND::PatientCon
}
dst
.
set_allocated_conditions
(
PBEngine
::
Unload
(
*
src
.
GetConditions
()));
dst
.
set_dataroot
(
src
.
GetDataRoot
());
}
...
...
src/cpp/cpm/PulsePhysiologyEngine.cpp
View file @
2437a233
...
...
@@ -139,7 +139,7 @@ std::string PulseEngineThunk::SerializeToString(SerializationFormat format)
return
state
;
}
bool
PulseEngineThunk
::
InitializeEngine
(
std
::
string
const
&
patient_configuration
,
std
::
string
const
&
data_requests
,
SerializationFormat
format
,
std
::
string
const
&
data_dir
)
bool
PulseEngineThunk
::
InitializeEngine
(
std
::
string
const
&
patient_configuration
,
std
::
string
const
&
data_requests
,
SerializationFormat
format
)
{
SEPatientConfiguration
pc
(
data
->
eng
->
GetLogger
());
if
(
!
pc
.
SerializeFromString
(
patient_configuration
,
format
,
data
->
eng
->
GetSubstanceManager
()))
...
...
src/cpp/cpm/PulsePhysiologyEngine.h
View file @
2437a233
...
...
@@ -41,7 +41,7 @@ public:
bool
SerializeFromString
(
std
::
string
const
&
state
,
std
::
string
const
&
data_requests
,
SerializationFormat
format
);
std
::
string
SerializeToString
(
SerializationFormat
format
);
bool
InitializeEngine
(
std
::
string
const
&
patient_configuration
,
std
::
string
const
&
data_requests
,
SerializationFormat
format
,
std
::
string
const
&
data_dir
=
"./"
);
bool
InitializeEngine
(
std
::
string
const
&
patient_configuration
,
std
::
string
const
&
data_requests
,
SerializationFormat
format
);
std
::
string
GetInitialPatient
(
SerializationFormat
format
);
std
::
string
GetPatientAssessment
(
int
type
,
SerializationFormat
format
);
...
...
src/cpp/cpm/controller/Controller.cpp
View file @
2437a233
...
...
@@ -284,6 +284,7 @@ bool PulseController::InitializeEngine(const std::string& patient_configuration,
bool
PulseController
::
InitializeEngine
(
const
SEPatientConfiguration
&
patient_configuration
)
{
Info
(
"Looking for files in "
+
patient_configuration
.
GetDataRoot
());
m_DataDir
=
patient_configuration
.
GetDataRoot
();
m_EngineTrack
->
ResetFile
();
m_State
=
EngineState
::
Initialization
;
...
...
src/csharp/howto/HowTo_EngineUse.cs
View file @
2437a233
...
...
@@ -152,8 +152,9 @@ namespace HowTo_UseEngine
// Initialization requires that you have all data files on disk for Pulse to find when creating a patient
// - Patient file (if not creating an inline patient definition)
// - Substance, Stabilization (config folder), nutrition, environments, ecg files
// The data_dir field can be changed in the InitializeEngine method
// If you have those folders in another location
// If you have those folders in another location,
// The data root dir can be changed in the SEPatientConfiguration object
cfg
.
SetDataRootDir
(
"./"
);
// The default is "./"
if
(!
pulse
.
InitializeEngine
(
cfg
,
data_mgr
))
{
Console
.
WriteLine
(
"Error Initializing Pulse!"
);
...
...
src/csharp/pulse/cdm/engine/SEPatientConfiguration.cs
View file @
2437a233
...
...
@@ -8,6 +8,7 @@ namespace Pulse.CDM
protected
SEPatient
patient
;
protected
string
patient_file
;
protected
SEConditionManager
condition_manager
;
protected
string
data_root_dir
;
public
SEPatientConfiguration
()
{
...
...
@@ -19,6 +20,7 @@ namespace Pulse.CDM
patient_file
=
null
;
patient
=
null
;
condition_manager
=
null
;
data_root_dir
=
"./"
;
}
public
bool
IsValid
()
...
...
@@ -28,6 +30,15 @@ namespace Pulse.CDM
return
true
;
}
public
string
GetDataRootDir
()
{
return
data_root_dir
;
}
public
void
SetDataRootDir
(
string
dir
)
{
data_root_dir
=
dir
;
}
public
bool
HasPatientFile
()
{
return
patient_file
!=
null
;
...
...
src/csharp/pulse/cdm/io/PBPatientConfiguration.cs
View file @
2437a233
...
...
@@ -21,6 +21,7 @@ namespace Pulse.CDM
PBPatient
.
Serialize
(
src
.
Patient
,
dst
.
GetPatient
());
if
(
src
.
Conditions
!=
null
)
Serialize
(
src
.
Conditions
,
dst
.
GetConditions
());
dst
.
SetDataRootDir
(
src
.
DataRoot
);
}
public
static
bool
SerializeFromString
(
string
src
,
SEPatientConfiguration
dst
)
{
...
...
@@ -50,6 +51,7 @@ namespace Pulse.CDM
dst
.
Patient
=
PBPatient
.
Unload
(
src
.
GetPatient
());
if
(
src
.
HasConditions
())
dst
.
Conditions
=
PBPatientConfiguration
.
Unload
(
src
.
GetConditions
());
dst
.
DataRoot
=
src
.
GetDataRootDir
();
}
public
static
string
SerializeToString
(
SEPatientConfiguration
src
)
{
...
...
src/csharp/pulse/engine/PulseEngine.cs
View file @
2437a233
...
...
@@ -87,13 +87,13 @@ namespace Pulse
}
[
DllImport
(
PulseLib
,
CharSet
=
CharSet
.
Ansi
,
CallingConvention
=
CallingConvention
.
StdCall
)]
static
extern
bool
InitializeEngine
(
IntPtr
pulse
,
string
patient_configuration
,
string
data_mgr
,
int
thunk_format
,
string
data_dir
);
public
bool
InitializeEngine
(
SEPatientConfiguration
patient_configuration
,
SEDataRequestManager
data_mgr
,
string
data_dir
=
"./"
)
static
extern
bool
InitializeEngine
(
IntPtr
pulse
,
string
patient_configuration
,
string
data_mgr
,
int
thunk_format
);
public
bool
InitializeEngine
(
SEPatientConfiguration
patient_configuration
,
SEDataRequestManager
data_mgr
)
{
data_values
=
new
double
[
data_mgr
.
GetDataRequests
().
Count
+
1
];
string
patient_configuration_str
=
PBPatientConfiguration
.
SerializeToString
(
patient_configuration
);
string
data_mgr_str
=
PBDataRequest
.
SerializeToString
(
data_mgr
,
thunk_as
);
alive
=
InitializeEngine
(
pulse_cptr
,
patient_configuration_str
,
data_mgr_str
,
(
int
)
thunk_as
,
data_dir
);
alive
=
InitializeEngine
(
pulse_cptr
,
patient_configuration_str
,
data_mgr_str
,
(
int
)
thunk_as
);
return
alive
;
}
...
...
src/java/com/kitware/pulse/cdm/engine/SEPatientConfiguration.java
View file @
2437a233
...
...
@@ -10,13 +10,13 @@ import com.kitware.pulse.cdm.bind.Engine.AnyConditionData;
import
com.kitware.pulse.cdm.bind.Engine.PatientConfigurationData
;
import
com.kitware.pulse.cdm.conditions.SECondition
;
import
com.kitware.pulse.cdm.patient.SEPatient
;
import
com.kitware.pulse.cdm.substance.SESubstanceManager
;
public
class
SEPatientConfiguration
{
protected
SEPatient
patient
;
protected
String
patientFile
;
protected
List
<
SECondition
>
conditions
;
protected
String
dataRootDir
=
"./"
;
public
SEPatientConfiguration
()
{
...
...
@@ -52,6 +52,7 @@ public class SEPatientConfiguration
for
(
AnyConditionData
cData
:
src
.
getConditions
().
getAnyConditionList
())
dst
.
conditions
.
add
(
SECondition
.
ANY2CDM
(
cData
));
dst
.
setDataRootDir
(
src
.
getDataRoot
());
}
public
static
PatientConfigurationData
unload
(
SEPatientConfiguration
src
)
...
...
@@ -71,6 +72,7 @@ public class SEPatientConfiguration
for
(
SECondition
c
:
src
.
conditions
)
dst
.
getConditionsBuilder
().
addAnyCondition
(
SECondition
.
CDM2ANY
(
c
));
}
dst
.
setDataRoot
(
src
.
dataRootDir
);
}
public
boolean
isValid
()
...
...
@@ -80,6 +82,15 @@ public class SEPatientConfiguration
return
true
;
}
public
void
setDataRootDir
(
String
dir
)
{
dataRootDir
=
dir
;
}
public
String
getDataRootDir
()
{
return
dataRootDir
;
}
public
SEPatient
getPatient
()
{
return
patient
;
...
...
src/java/com/kitware/pulse/engine/PulseEngine.java
View file @
2437a233
...
...
@@ -133,16 +133,12 @@ public class PulseEngine
//////////////////////
public
boolean
initializeEngine
(
SEPatientConfiguration
patientConfiguration
,
SEDataRequestManager
dataRequests
)
{
return
initializeEngine
(
patientConfiguration
,
dataRequests
,
"./"
);
}
public
boolean
initializeEngine
(
SEPatientConfiguration
patientConfiguration
,
SEDataRequestManager
dataRequests
,
String
dataDir
)
{
try
{
String
pcString
=
JsonFormat
.
printer
().
print
(
SEPatientConfiguration
.
unload
(
patientConfiguration
));
String
drString
=
JsonFormat
.
printer
().
print
(
SEDataRequestManager
.
unload
(
dataRequests
));
alive
=
nativeInitializeEngine
(
nativeObj
,
pcString
,
drString
,
thunkType
.
value
()
,
dataDir
);
alive
=
nativeInitializeEngine
(
nativeObj
,
pcString
,
drString
,
thunkType
.
value
());
}
catch
(
Exception
ex
)
{
...
...
@@ -430,7 +426,7 @@ public class PulseEngine
protected
native
boolean
nativeSerializeFromString
(
long
nativeObj
,
String
state
,
String
dataRequests
,
int
format
);
protected
native
String
nativeSerializeToString
(
long
nativeObj
,
String
stateFile
,
int
format
);
protected
native
boolean
nativeInitializeEngine
(
long
nativeObj
,
String
patient_configuration
,
String
dataRequests
,
int
thunk_format
,
String
dataDir
);
protected
native
boolean
nativeInitializeEngine
(
long
nativeObj
,
String
patient_configuration
,
String
dataRequests
,
int
thunk_format
);
protected
native
void
nativeLogToConsole
(
long
nativeObj
,
boolean
b
);
protected
native
void
nativeSetLogFilename
(
long
nativeObj
,
String
filename
);
...
...
src/java/com/kitware/pulse/howto/HowTo_EngineUse.java
View file @
2437a233
This diff is collapsed.
Click to expand it.
src/java/jni/PulseEngineJNI.cpp
View file @
2437a233
...
...
@@ -161,7 +161,7 @@ JNIEXPORT jstring JNICALL Java_com_kitware_pulse_engine_PulseEngine_nativeSerial
extern
"C"
JNIEXPORT
jboolean
JNICALL
Java_com_kitware_pulse_engine_PulseEngine_nativeInitializeEngine
(
JNIEnv
*
env
,
jobject
obj
,
jlong
ptr
,
jstring
patient_configuration
,
jstring
dataRequests
,
jint
format
,
jstring
dataDir
)
JNIEXPORT
jboolean
JNICALL
Java_com_kitware_pulse_engine_PulseEngine_nativeInitializeEngine
(
JNIEnv
*
env
,
jobject
obj
,
jlong
ptr
,
jstring
patient_configuration
,
jstring
dataRequests
,
jint
format
)
{
bool
bRet
;
PulseEngineJNI
*
engineJNI
=
reinterpret_cast
<
PulseEngineJNI
*>
(
ptr
);
...
...
@@ -176,20 +176,11 @@ JNIEXPORT jboolean JNICALL Java_com_kitware_pulse_engine_PulseEngine_nativeIniti
if
(
dataRequests
!=
nullptr
)
drStr
=
env
->
GetStringUTFChars
(
dataRequests
,
JNI_FALSE
);
const
char
*
ddStr
=
nullptr
;
if
(
dataDir
!=
nullptr
)
{
ddStr
=
env
->
GetStringUTFChars
(
dataDir
,
JNI_FALSE
);
bRet
=
engineJNI
->
InitializeEngine
(
pcStr
,
drStr
,
(
SerializationFormat
)
format
,
ddStr
);
}
else
bRet
=
engineJNI
->
InitializeEngine
(
pcStr
,
drStr
,
(
SerializationFormat
)
format
);
env
->
ReleaseStringUTFChars
(
patient_configuration
,
pcStr
);
if
(
drStr
!=
nullptr
)
env
->
ReleaseStringUTFChars
(
dataRequests
,
drStr
);
if
(
ddStr
!=
nullptr
)
env
->
ReleaseStringUTFChars
(
dataDir
,
ddStr
);
return
bRet
;
}
...
...
src/python/pulse/cdm/io/engine.py
View file @
2437a233
...
...
@@ -322,6 +322,7 @@ def serialize_patient_configuration_to_bind(src: SEPatientConfiguration, dst: Pa
serialize_condition_manager_to_bind
(
src
.
get_conditions
(),
dst
.
Conditions
)
for
override
in
src
.
get_scalar_overrides
():
serialize_scalar_property_to_bind
(
override
,
dst
.
ScalarOverride
.
add
())
dst
.
DataRoot
=
src
.
get_data_root_dir
()
def
serialize_patient_configuration_from_bind
(
src
:
PatientConfigurationData
,
dst
:
SEPatientConfiguration
):
raise
Exception
(
"serialize_patient_configuration_from_bind not implemented"
)
...
...
src/python/pulse/cdm/patient.py
View file @
2437a233
...
...
@@ -11,7 +11,7 @@ class eSex(Enum):
Female
=
1
class
SEPatientConfiguration
():
__slots__
=
[
"_patient"
,
"_patient_file"
,
"_condition_manager"
,
"_scalar_overrides"
]
__slots__
=
[
"_patient"
,
"_patient_file"
,
"_condition_manager"
,
"_scalar_overrides"
,
"_data_root_dir"
]
def
__init__
(
self
):
self
.
clear
()
...
...
@@ -21,12 +21,18 @@ class SEPatientConfiguration():
self
.
_patient_file
=
None
self
.
_scalar_overrides
=
[]
self
.
_condition_manager
=
None
self
.
_data_root_dir
=
"./"
def
is_valid
(
self
):
if
not
self
.
has_patient
()
and
not
self
.
has_patient_file
():
return
False
;
return
True
def
set_data_root_dir
(
self
,
dir
:
str
):
self
.
_data_root_dir
=
dir
def
get_data_root_dir
(
self
):
return
self
.
_data_root_dir
def
has_patient
(
self
):
return
self
.
_patient
is
not
None
def
get_patient
(
self
):
...
...
src/python/pulse/cpm/PulsePhysiologyEngine.py
View file @
2437a233
...
...
@@ -68,12 +68,11 @@ class PulsePhysiologyEngine:
return
None
def
initialize_engine
(
self
,
patient_configuration
:
SEPatientConfiguration
,
data_request_mgr
:
SEDataRequestManager
,
data_dir
:
str
=
"./"
):
data_request_mgr
:
SEDataRequestManager
):
# Process requests and setup our results structure
drm
=
self
.
_process_requests
(
data_request_mgr
,
eSerializationFormat
.
JSON
)
pc
=
serialize_patient_configuration_to_string
(
patient_configuration
,
eSerializationFormat
.
JSON
)
self
.
_is_ready
=
self
.
__pulse
.
initialize_engine
(
pc
,
drm
,
PyPulse
.
serialization_format
.
json
,
data_dir
)
self
.
_is_ready
=
self
.
__pulse
.
initialize_engine
(
pc
,
drm
,
PyPulse
.
serialization_format
.
json
)
self
.
_dt_s
=
self
.
__pulse
.
get_timestep
(
"s"
)
if
self
.
_is_ready
:
self
.
_pull
(
True
)
...
...
src/python/pulse/howto/HowTo_EngineUse.py
View file @
2437a233
...
...
@@ -111,7 +111,7 @@ def HowTo_UseEngine():
data_req_mgr
.
set_results_filename
(
"./test_results/HowTo_EngineUse.py.csv"
)
# There are several ways to initialize an engine to a patient
start_type
=
eStartType
.
Stat
e
start_type
=
eStartType
.
Sta
bilize_PatientObjec
t
if
start_type
is
eStartType
.
State
:
# The engine is ready instantaneously
if
not
pulse
.
serialize_from_file
(
"./states/Soldier@0s.pbb"
,
data_req_mgr
):
print
(
"Unable to load initial state file"
)
...
...
@@ -153,6 +153,10 @@ def HowTo_UseEngine():
env
.
get_environmental_conditions
().
get_ambient_temperature
().
set_value
(
33
,
TemperatureUnit
.
C
)
env
.
get_environmental_conditions
().
get_respiration_ambient_temperature
().
set_value
(
33
,
TemperatureUnit
.
C
)
# By default, pulse will look for data files in the working directory of your program "./"
# You can change that in your patient configuration
pc
.
set_data_root_dir
(
"./"
)
# Initialize the engine with our configuration
# Optionally you can provide a data_dir root where Pulse will look for required data files
if
not
pulse
.
initialize_engine
(
pc
,
data_req_mgr
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment