Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
CAMP
campvis-public
Commits
f9dfcb97
Commit
f9dfcb97
authored
May 18, 2014
by
Jakob Weiss
Browse files
new matrix processor. also, small bugfix to openigtlink client
parent
b335a18b
Changes
5
Hide whitespace changes
Inline
Side-by-side
modules/openigtlink/pipelines/streamingoigtldemo.cpp
View file @
f9dfcb97
...
...
@@ -32,6 +32,7 @@ namespace campvis {
:
AutoEvaluationPipeline
(
dc
)
{
addProcessor
(
&
_igtlClient
);
addProcessor
(
&
_matrixProcessor
);
//addEventListenerToBack(&_ve);
}
...
...
@@ -43,11 +44,13 @@ namespace campvis {
AutoEvaluationPipeline
::
init
();
_igtlClient
.
s_validated
.
connect
(
this
,
&
StreamingOIGTLDemo
::
onProcessorValidated
);
_matrixProcessor
.
s_validated
.
connect
(
this
,
&
StreamingOIGTLDemo
::
onProcessorValidated
);
_renderTargetID
.
setValue
(
"combine"
);
_renderTargetID
.
setValue
(
"IGTL.image.ImagerClient"
);
_matrixProcessor
.
p_matrixA
.
setValue
(
"IGTL.transform.ProbeToTracker"
);
_matrixProcessor
.
p_matrixB
.
setValue
(
"IGTL.transform.ReferenceToTracker"
);
_igtlClient
.
p_address
.
setValue
(
"127.0.0.1"
);
_igtlClient
.
p_targetImagePrefix
.
setValue
(
"combine"
);
_canvasSize
.
s_changed
.
connect
<
StreamingOIGTLDemo
>
(
this
,
&
StreamingOIGTLDemo
::
onRenderTargetSizeChanged
);
}
...
...
modules/openigtlink/pipelines/streamingoigtldemo.h
View file @
f9dfcb97
...
...
@@ -26,9 +26,9 @@
#define STREAMINGOIGTLDEMO_H__
#include "modules/openigtlink/processors/openigtlinkclient.h"
#include "modules/openigtlink/processors/matrixprocessor.h"
#include "core/pipeline/autoevaluationpipeline.h"
#include "core/properties/cameraproperty.h"
#include "modules/vis/processors/volumeexplorer.h"
namespace
campvis
{
class
StreamingOIGTLDemo
:
public
AutoEvaluationPipeline
{
...
...
@@ -64,6 +64,7 @@ namespace campvis {
virtual
void
onProcessorValidated
(
AbstractProcessor
*
processor
);
OpenIGTLinkClient
_igtlClient
;
MatrixProcessor
_matrixProcessor
;
};
}
...
...
modules/openigtlink/processors/matrixprocessor.cpp
0 → 100644
View file @
f9dfcb97
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// 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.
//
// ================================================================================================
#define CAMPCOM_FAST_SERIALIZATION
#include "matrixprocessor.h"
#include "core/datastructures/imagedata.h"
#include "core/datastructures/genericimagerepresentationlocal.h"
#include "core/tools/stringutils.h"
#include "../datastructures/transformdata.h"
namespace
campvis
{
const
std
::
string
MatrixProcessor
::
loggerCat_
=
"CAMPVis.modules.core.MatrixProcessor"
;
MatrixProcessor
::
MatrixProcessor
()
:
AbstractProcessor
()
,
p_matrixA
(
"MatrixA"
,
"Matrix A"
,
"matrixA"
)
,
p_matrixB
(
"MatrixB"
,
"Matrix B"
,
"matrixB"
)
,
p_matrixAModifiers
(
"MatrixAModifiers"
,
"Matrix A Modifiers"
)
,
p_matrixBModifiers
(
"MatrixBModifiers"
,
"Matrix B Modifiers"
)
,
p_targetMatrixID
(
"TargetMatrixID"
,
"Target Matrix ID"
,
"result.matrix"
,
DataNameProperty
::
WRITE
)
{
addProperty
(
p_matrixA
,
VALID
);
addProperty
(
p_matrixAModifiers
,
VALID
);
addProperty
(
p_matrixB
,
VALID
);
addProperty
(
p_matrixBModifiers
,
VALID
);
addProperty
(
p_targetMatrixID
,
VALID
);
}
MatrixProcessor
::~
MatrixProcessor
()
{
}
void
MatrixProcessor
::
init
()
{
}
void
MatrixProcessor
::
deinit
()
{
}
void
MatrixProcessor
::
updateResult
(
DataContainer
&
data
)
{
tgt
::
mat4
matA
=
processMatrixString
(
p_matrixA
.
getValue
(),
data
);
tgt
::
mat4
matB
=
processMatrixString
(
p_matrixB
.
getValue
(),
data
);
tgt
::
mat4
matAProcessed
=
processModifierString
(
matA
,
p_matrixAModifiers
.
getValue
());
tgt
::
mat4
matBProcessed
=
processModifierString
(
matB
,
p_matrixBModifiers
.
getValue
());
tgt
::
mat4
result
=
matAProcessed
*
matBProcessed
;
LDEBUG
(
"Matrix A: "
<<
std
::
endl
<<
matA
);
LDEBUG
(
"Matrix A':"
<<
std
::
endl
<<
matAProcessed
);
LDEBUG
(
"Matrix B "
<<
std
::
endl
<<
matB
);
LDEBUG
(
"Matrix B':"
<<
std
::
endl
<<
matBProcessed
);
LDEBUG
(
"Result Matrix: "
<<
std
::
endl
<<
result
);
LDEBUG
(
std
::
endl
);
TransformData
*
td
=
new
TransformData
(
result
);
data
.
addData
(
p_targetMatrixID
.
getValue
(),
td
);
validate
(
INVALID_RESULT
);
}
tgt
::
mat4
MatrixProcessor
::
processMatrixString
(
std
::
string
matrixString
,
DataContainer
&
data
)
{
std
::
vector
<
std
::
string
>
tokens
=
StringUtils
::
split
(
matrixString
,
" "
);
if
(
tokens
.
size
()
==
0
||
tokens
[
0
]
==
"identity"
)
{
return
tgt
::
mat4
(
tgt
::
mat4
::
identity
);
}
// if we have exactly 16 tokens, we assume we have a matrix in numerical form
else
if
(
tokens
.
size
()
==
16
)
{
tgt
::
mat4
mat
;
float
*
p
=
mat
.
elem
;
for
(
int
i
=
0
;
i
<
16
;
i
++
)
{
*
p
=
atof
(
tokens
[
i
].
c_str
());
p
++
;
}
return
mat
;
}
// if the first token is "rot", we create an angle axis rotation matrix with the specified arguments
else
if
(
tokens
[
0
]
==
"rot"
)
{
if
(
tokens
.
size
()
!=
5
)
{
LWARNING
(
"Rotation matrix string does not have the correct number of arguments!"
);
return
tgt
::
mat4
::
createIdentity
();
}
float
angle
;
tgt
::
vec3
axis
;
angle
=
atof
(
tokens
[
1
].
c_str
());
axis
[
0
]
=
atof
(
tokens
[
2
].
c_str
());
axis
[
1
]
=
atof
(
tokens
[
3
].
c_str
());
axis
[
2
]
=
atof
(
tokens
[
4
].
c_str
());
return
tgt
::
mat4
::
createRotation
(
angle
,
axis
);
}
else
if
(
tokens
[
0
]
==
"trans"
)
{
if
(
tokens
.
size
()
!=
4
)
{
LWARNING
(
"Translation matrix string does not have the correct number of arguments!"
);
return
tgt
::
mat4
::
createIdentity
();
}
tgt
::
vec3
translation
;
translation
[
0
]
=
atof
(
tokens
[
1
].
c_str
());
translation
[
1
]
=
atof
(
tokens
[
2
].
c_str
());
translation
[
2
]
=
atof
(
tokens
[
3
].
c_str
());
return
tgt
::
mat4
::
createTranslation
(
translation
);
}
else
if
(
tokens
[
0
]
==
"scale"
)
{
if
(
tokens
.
size
()
!=
2
&&
tokens
.
size
()
!=
4
)
{
LWARNING
(
"Scaling matrix string does not have the correct number of arguments!"
);
return
tgt
::
mat4
::
createIdentity
();
}
tgt
::
vec3
scale
;
scale
[
0
]
=
atof
(
tokens
[
1
].
c_str
());
if
(
tokens
.
size
()
==
4
)
{
scale
[
1
]
=
atof
(
tokens
[
2
].
c_str
());
scale
[
2
]
=
atof
(
tokens
[
3
].
c_str
());
}
else
{
scale
[
1
]
=
scale
[
2
]
=
scale
[
0
];
}
return
tgt
::
mat4
::
createScale
(
scale
);
}
// if we cannot find another pattern, we assume we have a data container ID
else
{
ScopedTypedData
<
TransformData
>
td
(
data
,
matrixString
);
if
(
td
==
0
)
{
LWARNING
(
"Data Container ID
\"
"
<<
matrixString
<<
"
\"
was not suitable as input Matrix"
);
return
tgt
::
mat4
::
createIdentity
();
}
return
td
->
getTransform
();
}
}
tgt
::
mat4
MatrixProcessor
::
processModifierString
(
tgt
::
mat4
matrix
,
std
::
string
modifiers
)
{
int
pos
=
0
;
tgt
::
mat4
result
=
matrix
,
tmp
;
while
(
pos
<
modifiers
.
size
())
{
switch
(
modifiers
[
pos
])
{
case
'I'
:
if
(
!
result
.
invert
(
tmp
))
{
LWARNING
(
"Matrix Inversion failed."
);
}
else
result
=
tmp
;
break
;
case
'T'
:
result
=
tgt
::
transpose
(
result
);
break
;
case
'-'
:
result
=
tgt
::
mat4
::
zero
-
result
;
break
;
case
'r'
:
result
=
result
.
getRotationalPart
();
break
;
case
's'
:
result
=
tgt
::
mat4
::
createScale
(
result
.
getScalingPart
());
break
;
default:
LWARNING
(
"Ignoring unknown modifier: "
<<
modifiers
[
pos
]);
}
}
return
result
;
}
}
\ No newline at end of file
modules/openigtlink/processors/matrixprocessor.h
0 → 100644
View file @
f9dfcb97
// ================================================================================================
//
// This file is part of the CAMPVis Software Framework.
//
// If not explicitly stated otherwise: Copyright (C) 2012-2014, all rights reserved,
// Christian Schulte zu Berge <christian.szb@in.tum.de>
// Chair for Computer Aided Medical Procedures
// Technische Universitaet Muenchen
// Boltzmannstr. 3, 85748 Garching b. Muenchen, Germany
//
// For a full list of authors and contributors, please refer to the file "AUTHORS.txt".
//
// 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 MATRIXPROCESSOR_H__
#define MATRIXPROCESSOR_H__
#include <string>
#include <tgt/matrix.h>
#include "core/pipeline/abstractprocessor.h"
#include "core/properties/buttonproperty.h"
#include "core/properties/datanameproperty.h"
#include "core/properties/floatingpointproperty.h"
#include "core/properties/stringproperty.h"
namespace
campvis
{
/**
* Experimental demo implementation how to receive MHD files via CAMPCom, convert it to
* CAMPVis ImageData and store it into the DataContainer.
*/
class
MatrixProcessor
:
public
AbstractProcessor
{
public:
/**
* Constructs a new CampcomMhdReceiver Processor
**/
MatrixProcessor
();
/**
* Destructor
**/
virtual
~
MatrixProcessor
();
/// \see AbstractProcessor::init()
virtual
void
init
();
/// \see AbstractProcessor::deinit()
virtual
void
deinit
();
/// \see AbstractProcessor::getName()
virtual
const
std
::
string
getName
()
const
{
return
"MatrixProcessor"
;
};
/// \see AbstractProcessor::getDescription()
virtual
const
std
::
string
getDescription
()
const
{
return
"Matrix Processor to process/combine one or two matrices and write the result into the data container"
;
};
/// \see AbstractProcessor::getAuthor()
virtual
const
std
::
string
getAuthor
()
const
{
return
"Jakob Weiss <weissj@in.tum.de>"
;
};
/// \see AbstractProcessor::getProcessorState()
virtual
ProcessorState
getProcessorState
()
const
{
return
AbstractProcessor
::
EXPERIMENTAL
;
};
StringProperty
p_matrixA
;
///< first Matrix input for the computation. \see MatrixProcessor::processMatrixString()
StringProperty
p_matrixB
;
///< second Matrix input for the computation. \see MatrixProcessor::processMatrixString()
StringProperty
p_matrixAModifiers
;
///< modifier string to be applied to matrix A. \see MatrixProcessor::processModifiers()
StringProperty
p_matrixBModifiers
;
///< modifier string to be applied to matrix B. \see MatrixProcessor::processModifiers()
DataNameProperty
p_targetMatrixID
;
///< image ID for read image
protected:
/// \see AbstractProcessor::updateResult()
virtual
void
updateResult
(
DataContainer
&
dataContainer
);
tgt
::
mat4
processModifierString
(
tgt
::
mat4
matrix
,
std
::
string
modifiers
);
tgt
::
mat4
processMatrixString
(
std
::
string
matrixString
,
DataContainer
&
data
);
static
const
std
::
string
loggerCat_
;
};
}
#endif // MATRIXPROCESSOR_H__
modules/openigtlink/processors/openigtlinkclient.cpp
View file @
f9dfcb97
...
...
@@ -58,14 +58,16 @@ namespace campvis {
addProperty
(
p_connect
,
VALID
);
addProperty
(
p_receiveTransforms
,
INVALID_RESULT
|
INVALID_PROPERTIES
);
addProperty
(
p_receiveImages
,
INVALID_RESULT
|
INVALID_PROPERTIES
);
addProperty
(
p_receiveTransforms
,
INVALID_PROPERTIES
);
addProperty
(
p_receiveImages
,
INVALID_PROPERTIES
);
addProperty
(
p_targetTransformPrefix
,
VALID
);
addProperty
(
p_targetImagePrefix
,
VALID
);
addProperty
(
p_imageOffset
,
VALID
);
addProperty
(
p_voxelSize
,
VALID
);
addProperty
(
p_receivePositions
,
INVALID_RESULT
|
INVALID_PROPERTIES
);
addProperty
(
p_receivePositions
,
INVALID_PROPERTIES
);
addProperty
(
p_targetPositionPrefix
,
VALID
);
invalidate
(
INVALID_PROPERTIES
);
}
OpenIGTLinkClient
::~
OpenIGTLinkClient
()
{
...
...
@@ -169,6 +171,7 @@ namespace campvis {
p_imageOffset
.
setVisible
(
p_receiveImages
.
getValue
());
p_voxelSize
.
setVisible
(
p_receiveImages
.
getValue
());
p_targetTransformPrefix
.
setVisible
(
p_receiveImages
.
getValue
()
||
p_receiveTransforms
.
getValue
());
p_targetPositionPrefix
.
setVisible
(
p_receivePositions
.
getValue
());
}
void
OpenIGTLinkClient
::
connectToServer
()
{
...
...
Write
Preview
Markdown
is supported
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