Commit 8964ce8b authored by Emmanuel Promayon's avatar Emmanuel Promayon

FIXED code cleaning

parent 13878444
......@@ -87,13 +87,13 @@ AnglesAndTranslationAction::~AnglesAndTranslationAction() {
QWidget* AnglesAndTranslationAction::getWidget() {
if (!actionWidget) {
actionWidget = new AnglesAndTranslationWidget(this);
// first call : force visibility of the arbitrary viewer
setViewer(camitk::MedicalImageViewer::VIEWER_ARBITRARY);
}
// update the pointer
currentImageComp = dynamic_cast<ImageComponent*>(getTargets().last())->getArbitrarySlices();
// show the arbitrary viewer
setViewer(camitk::MedicalImageViewer::VIEWER_ARBITRARY);
// make sure the arbitrary slice is visible in 3D
currentImageComp->setViewSliceIn3D(true);
......
......@@ -111,6 +111,12 @@ void Slice::setImageWorldTransform(vtkSmartPointer<vtkTransform> transform) {
image3DActor->SetUserTransform(transform);
}
// -------------------- setReslicerTransform --------------------
void Slice::setArbitraryTransform(vtkSmartPointer<vtkTransform> transform) {
image2DReslicer->SetResliceAxes(transform->GetMatrix());
image2DReslicer->Update();
}
// -------------------- pixelPicked --------------------
void Slice::pixelPicked(double x, double y, double z) {
return;
......@@ -248,12 +254,6 @@ void Slice::setPixelRealPosition(double x, double y, double z) {
updatePixelActor(x, y, z);
}
// -------------------- setReslicerTransform --------------------
void Slice::setArbitraryTransform(vtkSmartPointer<vtkTransform> transform) {
image2DReslicer->SetResliceAxes(transform->GetMatrix());
image2DReslicer->Update();
}
// -------------------- get2DImageActor --------------------
vtkSmartPointer<vtkImageActor> Slice::get2DImageActor() const {
return image2DActor;
......
......@@ -76,54 +76,6 @@ namespace camitk {
.arg(__VA_ARGS__->GetElement(3, 2), 8, 'f', 4, ' ') \
.arg(__VA_ARGS__->GetElement(3, 3), 8, 'f', 4, ' '))
template<typename T>
vtkSmartPointer<vtkMatrix4x4> Multiply4x4(T a, T b) {
vtkSmartPointer<vtkMatrix4x4> c = vtkSmartPointer<vtkMatrix4x4>::New();
vtkMatrix4x4::Multiply4x4(a, b, c);
return c;
}
template<typename T, typename... Args>
vtkSmartPointer<vtkMatrix4x4> Multiply4x4(T a, T b, Args... args) {
return Multiply4x4(a, Multiply4x4(b, args...));
}
bool linePlaneIntersectionPoint(QVector3D lineVector, QVector3D linePoint, QVector3D planeNormal, QVector3D planePoint, QVector3D& intersection) {
lineVector.normalize();
planeNormal.normalize();
// Let P(x,y,z) be the intersection point
// As the plane equation is:
// (P - planePoint) . planeNormal = 0 (. denotes dot product)
// and the line equation:
// P = linePoint + k * lineVector
// The equation linking both above is:
// (linePoint + k * lineVector - planePoint) . planeNormal = 0
// => k = - [ (linePoint - planePoint).planeNormal ] / (lineVector . planeNormal)
// if (lineVector . planeNormal) == 0.0 line is parallel to plane, this method should return false
float lDotN = QVector3D::dotProduct(lineVector, planeNormal);
if (fabs(lDotN) < 1e-10) {
// line and plane are parallel
return false;
}
else {
QVector3D u = linePoint - planePoint; // vector from plane point to the line point
float uDotN = QVector3D::dotProduct(u, planeNormal);
float k = - uDotN / lDotN;
intersection = linePoint + k * lineVector;
return true;
}
}
// rounding to 4 digits to avoid precision errors
float roundTo4Decimals(float input) {
float output = (int)(input * 10000 + .5);
return (float) output / 10000;
}
QVector3D roundTo4Decimals(QVector3D input) {
return QVector3D(roundTo4Decimals(input.x()), roundTo4Decimals(input.y()), roundTo4Decimals(input.z()));
}
// -------------------- constructor --------------------
ArbitrarySingleImageComponent::ArbitrarySingleImageComponent(Component* parentComponent, const QString& name, vtkSmartPointer<vtkWindowLevelLookupTable> lut)
......@@ -432,5 +384,62 @@ int ArbitrarySingleImageComponent::getNumberOfSlices() const {
}
// -----------------------
// maths utility methods
// -----------------------
// -------------------- Multiply4x4 --------------------
template<typename T>
vtkSmartPointer<vtkMatrix4x4> ArbitrarySingleImageComponent::Multiply4x4(T a, T b) {
vtkSmartPointer<vtkMatrix4x4> c = vtkSmartPointer<vtkMatrix4x4>::New();
vtkMatrix4x4::Multiply4x4(a, b, c);
return c;
}
template<typename T, typename... Args>
vtkSmartPointer<vtkMatrix4x4> ArbitrarySingleImageComponent::Multiply4x4(T a, T b, Args... args) {
return Multiply4x4(a, Multiply4x4(b, args...));
}
// -------------------- linePlaneIntersectionPoint --------------------
bool ArbitrarySingleImageComponent::linePlaneIntersectionPoint(QVector3D lineVector, QVector3D linePoint, QVector3D planeNormal, QVector3D planePoint, QVector3D& intersection) {
lineVector.normalize();
planeNormal.normalize();
// Let P(x,y,z) be the intersection point
// As the plane equation is:
// (P - planePoint) . planeNormal = 0 (. denotes dot product)
// and the line equation:
// P = linePoint + k * lineVector
// The equation linking both above is:
// (linePoint + k * lineVector - planePoint) . planeNormal = 0
// => k = - [ (linePoint - planePoint).planeNormal ] / (lineVector . planeNormal)
// if (lineVector . planeNormal) == 0.0 line is parallel to plane, this method should return false
float lDotN = QVector3D::dotProduct(lineVector, planeNormal);
if (fabs(lDotN) < 1e-10) {
// line and plane are parallel
return false;
}
else {
QVector3D u = linePoint - planePoint; // vector from plane point to the line point
float uDotN = QVector3D::dotProduct(u, planeNormal);
float k = - uDotN / lDotN;
intersection = linePoint + k * lineVector;
return true;
}
}
// -------------------- roundTo4Decimals --------------------
float ArbitrarySingleImageComponent::roundTo4Decimals(float input) {
float output = (int)(input * 10000 + .5);
return (float) output / 10000;
}
QVector3D ArbitrarySingleImageComponent::roundTo4Decimals(QVector3D input) {
return QVector3D(roundTo4Decimals(input.x()), roundTo4Decimals(input.y()), roundTo4Decimals(input.z()));
}
}
......@@ -148,7 +148,48 @@ private:
/// This position is expressed in the parent frame coordinate system
/// (required to compute getTranslationInVolume and set new translation)
QVector3D cMinus_P;
/// @name Math utility methods
/// TODO have this in a specific class?
///
/// @{
/// variadic method that enables clear expression of the transformation composition chain
/// Instead of using vtkMatrix4x4::Multiply4x4 multiple times, these methods allow
/// for expressing all transformation in one line.
/// For instance:
/// \code
/// vtkSmartPointer<vtkMatrix4x4> intermediate1 = vtkSmartPointer<vtkMatrix4x4>::New();
/// vtkMatrix4x4::Multiply4x4(a, b, intermediate1);
/// vtkSmartPointer<vtkMatrix4x4> intermediate2 = vtkSmartPointer<vtkMatrix4x4>::New();
/// vtkMatrix4x4::Multiply4x4(intermediate1, c, intermediate2);
/// vtkSmartPointer<vtkMatrix4x4> resultingTransformation = vtkSmartPointer<vtkMatrix4x4>::New();
/// vtkMatrix4x4::Multiply4x4(intermediate2, d, resultingTransformation);
/// \endcode
/// You can just write:
/// \code
/// vtkSmartPointer<vtkMatrix4x4> resultingTransformation = Multiply4x4(a, b, c, d);
/// \endcode
/// which result in a much clearer/cleaner way of expressing the transformation composition
template<typename T> static vtkSmartPointer<vtkMatrix4x4> Multiply4x4(T, T );
template<typename T, typename... Args> static vtkSmartPointer<vtkMatrix4x4> Multiply4x4(T a, T b, Args... args);
/// compute the intersection between a line and a plane
/// @see http://www.realtimerendering.com/intersections.html
/// @param lineVector a vector in the direction of the line
/// @param linePoint a point on the line
/// @param planeNormal a normal vector to the plane
/// @param planePoint a point on the plane
/// @param intersection (output) the point of intersection between the line and the plane
/// @return false if there is no intersection, true otherwise
static bool linePlaneIntersectionPoint(QVector3D, QVector3D, QVector3D, QVector3D, QVector3D&);
/// Round a float to 4 digits
/// This is a great tool to avoid precision errors (when rotation/cos/sin are around, precision is difficult to maintain)
static float roundTo4Decimals(float);
/// Round a QVector3D to 4 digits
/// This is a great tool to avoid precision errors (when rotation/cos/sin are around, precision is difficult to maintain)
static QVector3D roundTo4Decimals(QVector3D);
/// @}
};
}
......
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