Commit 84a914e7 authored by CAMP C++ Builder's avatar CAMP C++ Builder
Browse files

MatrixProcessor enhancements: whitespace and Camera

* parser now allows whitespace in formula
* exports _camera matrix (if present) to m_cameraProperty in parserMode
parent ea0b2656
......@@ -51,6 +51,7 @@ namespace campvis {
, p_matrixBString("MatrixB_String", "Matrix B String", "identity")
, p_matrixBModifiers("MatrixBModifiers", "Matrix B Modifiers")
, p_targetMatrixID("TargetMatrixID", "Target Matrix ID", "ProbeToReference", DataNameProperty::WRITE)
, p_cameraProperty("Camera", "Exported Camera")
, _lastdc(nullptr)
{
addProperty(p_parserMode, INVALID_PROPERTIES);
......@@ -68,6 +69,8 @@ namespace campvis {
addProperty(p_targetMatrixID, INVALID_RESULT);
addProperty(p_cameraProperty, VALID);
invalidate(INVALID_PROPERTIES);
}
......@@ -186,7 +189,7 @@ namespace campvis {
auto l1 = StringUtils::split(p_parserInputString.getValue(), "[");
for (size_t i = 1, s = l1.size(); i < s; ++i) {
auto l2 = StringUtils::split(l1[i], "]");
LDEBUG("Data Name: " << l2[0]);
//LDEBUG("Data Name: " << l2[0]);
_dataDependencies.insert(l2[0]);
}
......@@ -319,7 +322,7 @@ namespace campvis {
//evaluate every assignment
for (size_t i = 0, nEq = equations.size(); i != nEq; ++i)
{
std::string & eqn = equations[i];
std::string eqn = campvis::StringUtils::trim(equations[i]);
try {
//skip empty equations
if (!eqn.size()) continue;
......@@ -332,8 +335,8 @@ namespace campvis {
continue;
}
std::string assignedMatName = eqn.substr(0, equal_pos);
std::string formulaToEvaluate = eqn.substr(equal_pos + 1, std::string::npos);
std::string assignedMatName = campvis::StringUtils::trim(eqn.substr(0, equal_pos));
std::string formulaToEvaluate = campvis::StringUtils::trim(eqn.substr(equal_pos + 1, std::string::npos));
//LDEBUG("Matrix Name: " << assignedMatName << ". Formula: " << formulaToEvaluate);
//split formulaToEvaluate by the multiplications
......@@ -341,7 +344,7 @@ namespace campvis {
std::vector<std::string> multiplicands = StringUtils::split(formulaToEvaluate, "*");
for (size_t m = 0, nMul = multiplicands.size(); m != nMul; ++m)
{
std::string & matStrCombined = multiplicands[m];
std::string matStrCombined = campvis::StringUtils::trim(multiplicands[m]);
//parse multiplicands of form "[<MatrixString>]_<Modifiers>"
size_t delimPos = matStrCombined.find("]");
......@@ -370,10 +373,16 @@ namespace campvis {
// put all results into the data container
// matrix names beginning with an underscore are skipped
// _camera matrix is used to modify m_cameraProperty
for (auto it = results.begin(), end = results.end(); it != end; ++it) {
if (it->first[0] != '_') {
dc.addData(it->first, new TransformData(it->second));
}
if (it->first == "_camera") {
tgt::Camera cam = p_cameraProperty.getValue();
cam.setViewMatrix(it->second);
p_cameraProperty.setValue(cam);
}
}
}
......
......@@ -48,6 +48,10 @@ namespace campvis {
* slower than the "basic" mode, but for most applications this performance hit should not be a problem.
* Performance could be reduced in a future iteration by pre-processing the input string instead of parsing it on the fly in each update call.
* Please note that this features is EXPERIMENTAL and has not been extensively tested.
* An additional feature of the Parser Mode is the option to export a matrix through the \a m_cameraProperty field. Please
* make sure that the m_cameraProperty is initialized and updated correctly regarding viewport changes (for example by setting
* the property as a target for a TrackballEventHandler) as this feature only modifies the position, lookat and up vector of the
* camera.
*
* Example use case: OpenIGTLink client outputs matrices TrackerToReference and TrackerToProbe. Configure
* matrixA as "TrackerToProbe" with modifier "I" and matrixB as "TrackerToReference" with empty modifier
......@@ -97,6 +101,7 @@ namespace campvis {
DataNameProperty p_targetMatrixID; ///< name for the output matrix
CameraProperty p_cameraProperty;
void DataContainerDataAdded(const std::string& name, const DataHandle& data);
......
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