Skip to content

Commit

Permalink
Initial import of LinearObjectRegistration module.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewsholden committed Mar 30, 2013
1 parent 6ee0151 commit 14ae67b
Show file tree
Hide file tree
Showing 34 changed files with 3,020 additions and 0 deletions.
73 changes: 73 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#-----------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8.7)

#-----------------------------------------------------------------------------
set(MODULE_NAME "LinearObjectRegistration")
set(MODULE_TITLE ${MODULE_NAME})

string(TOUPPER ${MODULE_NAME} MODULE_NAME_UPPER)

#-----------------------------------------------------------------------------
if ( NOT DEFINED ${EXTENSION_NAME}_SUPERBUILD )
find_package(Slicer REQUIRED)
include(${Slicer_USE_FILE})
endif()

#-----------------------------------------------------------------------------
add_subdirectory(Logic)
add_subdirectory(Widgets)

#-----------------------------------------------------------------------------
set(MODULE_EXPORT_DIRECTIVE "Q_SLICER_QTMODULES_${MODULE_NAME_UPPER}_EXPORT")

# Current_{source,binary} and Slicer_{Libs,Base} already included
set(MODULE_INCLUDE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}/Logic
${CMAKE_CURRENT_BINARY_DIR}/Logic
${CMAKE_CURRENT_SOURCE_DIR}/Widgets
${CMAKE_CURRENT_BINARY_DIR}/Widgets
)

set(MODULE_SRCS
qSlicer${MODULE_NAME}Module.cxx
qSlicer${MODULE_NAME}Module.h
qSlicer${MODULE_NAME}ModuleWidget.cxx
qSlicer${MODULE_NAME}ModuleWidget.h
)

set(MODULE_MOC_SRCS
qSlicer${MODULE_NAME}Module.h
qSlicer${MODULE_NAME}ModuleWidget.h
)

set(MODULE_UI_SRCS
Resources/UI/qSlicer${MODULE_NAME}Module.ui
)

set(MODULE_TARGET_LIBRARIES
vtkSlicer${MODULE_NAME}ModuleLogic
qSlicer${MODULE_NAME}ModuleWidgets
)

set(MODULE_RESOURCES
Resources/qSlicer${MODULE_NAME}Module.qrc
)

#-----------------------------------------------------------------------------
slicerMacroBuildQtModule(
NAME ${MODULE_NAME}
TITLE ${MODULE_TITLE}
EXPORT_DIRECTIVE ${MODULE_EXPORT_DIRECTIVE}
INCLUDE_DIRECTORIES ${MODULE_INCLUDE_DIRECTORIES}
SRCS ${MODULE_SRCS}
MOC_SRCS ${MODULE_MOC_SRCS}
UI_SRCS ${MODULE_UI_SRCS}
TARGET_LIBRARIES ${MODULE_TARGET_LIBRARIES}
RESOURCES ${MODULE_RESOURCES}
)

#-----------------------------------------------------------------------------
if(BUILD_TESTING)
add_subdirectory(Testing)
endif()

6 changes: 6 additions & 0 deletions Documentation/LinearObjectRegistration.dox
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
\defgroup Slicer_QtModules_LinearObjectRegistration LinearObjectRegistration
\ingroup Slicer_QtModules
This module allows to ...

*/
42 changes: 42 additions & 0 deletions Logic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
project(vtkSlicer${MODULE_NAME}ModuleLogic)

set(KIT ${PROJECT_NAME})

set(${KIT}_EXPORT_DIRECTIVE "VTK_SLICER_${MODULE_NAME_UPPER}_MODULE_LOGIC_EXPORT")

set(${KIT}_INCLUDE_DIRECTORIES
)

set(${KIT}_SRCS
vtkSlicer${MODULE_NAME}Logic.cxx
vtkSlicer${MODULE_NAME}Logic.h
LinearObject.cxx
LinearObject.h
Reference.cxx
Reference.h
Point.cxx
Point.h
Line.cxx
Line.h
Plane.cxx
Plane.h
LinearObjectBuffer.cxx
LinearObjectBuffer.h
PointObservation.cxx
PointObservation.h
PointObservationBuffer.cxx
PointObservationBuffer.h
)

set(${KIT}_TARGET_LIBRARIES
${ITK_LIBRARIES}
)

#-----------------------------------------------------------------------------
SlicerMacroBuildModuleLogic(
NAME ${KIT}
EXPORT_DIRECTIVE ${${KIT}_EXPORT_DIRECTIVE}
INCLUDE_DIRECTORIES ${${KIT}_INCLUDE_DIRECTORIES}
SRCS ${${KIT}_SRCS}
TARGET_LIBRARIES ${${KIT}_TARGET_LIBRARIES}
)
146 changes: 146 additions & 0 deletions Logic/Line.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@

#include "Line.h"

Line
::Line()
{
this->Type = "Line";
}


Line
::Line( std::vector<double> newBasePoint, std::vector<double> newEndPoint )
{
this->Type = "Line";
this->BasePoint = newBasePoint;
this->EndPoint = newEndPoint;
}


Line
::~Line()
{
this->EndPoint.clear();
}


std::vector<double> Line
::GetDirection()
{
std::vector<double> vector = Subtract( this->EndPoint, this->BasePoint );
return Multiply( 1 / Norm( vector ), vector );
}


std::vector<double> Line
::ProjectVector( std::vector<double> vector )
{
std::vector<double> outVec = Subtract( vector, this->BasePoint );
return Add( Multiply( Dot( this->GetDirection(), outVec ), this->GetDirection() ), this->BasePoint );
}


void Line
::Translate( std::vector<double> vector )
{
for ( int i = 0; i < vector.size(); i++ )
{
this->BasePoint.at(i) = this->BasePoint.at(i) + vector.at(i);
this->EndPoint.at(i) = this->EndPoint.at(i) + vector.at(i);
}
}


std::vector<double> Line
::GetOrthogonalNormal1()
{
// Find the two axis unit vectors least parallel with the direction vector
std::vector<double> e1( 3, 0.0 );
std::vector<double> e2( 3, 0.0 );
if ( this->GetDirection().at(1) <= this->GetDirection().at(0) && this->GetDirection().at(2) <= this->GetDirection().at(0) )
{
e1.at(0) = 0; e1.at(1) = 1; e1.at(2) = 0;
e2.at(0) = 0; e2.at(1) = 0; e2.at(2) = 1;
}
if ( this->GetDirection().at(0) <= this->GetDirection().at(1) && this->GetDirection().at(2) <= this->GetDirection().at(1) )
{
e1.at(0) = 1; e1.at(1) = 0; e1.at(2) = 0;
e2.at(0) = 0; e2.at(1) = 0; e2.at(2) = 1;
}
if ( this->GetDirection().at(0) <= this->GetDirection().at(2) && this->GetDirection().at(1) <= this->GetDirection().at(2) )
{
e1.at(0) = 1; e1.at(1) = 0; e1.at(2) = 0;
e2.at(0) = 0; e2.at(1) = 1; e2.at(2) = 0;
}

std::vector<double> Normal1 = Subtract( e1, Multiply( Dot( e1, this->GetDirection() ), this->GetDirection() ) );
Normal1 = Multiply( 1 / Norm( Normal1 ), Normal1 );

std::vector<double> Normal2 = Subtract( e2, Add( Multiply( Dot( e2, this->GetDirection() ), this->GetDirection() ), Multiply( Dot( e2, Normal1 ), Normal1 ) ) );
Normal2 = Multiply( 1 / Norm( Normal2 ), Normal2 );

return Normal1;
}


std::vector<double> Line
::GetOrthogonalNormal2()
{
// Find the two axis unit vectors least parallel with the direction vector
std::vector<double> e1( 3, 0.0 );
std::vector<double> e2( 3, 0.0 );
if ( this->GetDirection().at(1) <= this->GetDirection().at(0) && this->GetDirection().at(2) <= this->GetDirection().at(0) )
{
e1.at(0) = 0; e1.at(1) = 1; e1.at(2) = 0;
e2.at(0) = 0; e2.at(1) = 0; e2.at(2) = 1;
}
if ( this->GetDirection().at(0) <= this->GetDirection().at(1) && this->GetDirection().at(2) <= this->GetDirection().at(1) )
{
e1.at(0) = 1; e1.at(1) = 0; e1.at(2) = 0;
e2.at(0) = 0; e2.at(1) = 0; e2.at(2) = 1;
}
if ( this->GetDirection().at(0) <= this->GetDirection().at(2) && this->GetDirection().at(1) <= this->GetDirection().at(2) )
{
e1.at(0) = 1; e1.at(1) = 0; e1.at(2) = 0;
e2.at(0) = 0; e2.at(1) = 1; e2.at(2) = 0;
}

std::vector<double> Normal1 = Subtract( e1, Multiply( Dot( e1, this->GetDirection() ), this->GetDirection() ) );
Normal1 = Multiply( 1 / Norm( Normal1 ), Normal1 );

std::vector<double> Normal2 = Subtract( e2, Add( Multiply( Dot( e2, this->GetDirection() ), this->GetDirection() ), Multiply( Dot( e2, Normal1 ), Normal1 ) ) );
Normal2 = Multiply( 1 / Norm( Normal2 ), Normal2 );

return Normal2;
}


std::string Line
::ToXMLString()
{
std::stringstream xmlstring;

xmlstring << " <Line";
xmlstring << " Name=\"" << this->Name << "\"";
xmlstring << " BasePoint=\"" << VectorToString( this->BasePoint ) << "\"";
xmlstring << " EndPoint=\"" << VectorToString( this->EndPoint ) << "\"";
xmlstring << " />" << std::endl;

return xmlstring.str();
}


void Line
::FromXMLElement( vtkXMLDataElement* element )
{

if ( strcmp( element->GetName(), "Line" ) != 0 )
{
return; // If it's not a "log" or is the wrong tool jump to the next.
}

this->Name = std::string( element->GetAttribute( "Name" ) );
this->BasePoint = StringToVector( std::string( element->GetAttribute( "BasePoint" ) ), 3 );
this->EndPoint = StringToVector( std::string( element->GetAttribute( "EndPoint" ) ), 3 );

}
37 changes: 37 additions & 0 deletions Logic/Line.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//BTX

#ifndef LINE_H
#define LINE_H

#include "LinearObject.h"

#include <string>
#include <sstream>
#include <vector>
#include <cmath>

// This class stores a vector of values and a string label
class Line : public LinearObject
{
public:
std::vector<double> EndPoint;

Line();
Line( std::vector<double> newBasePoint, std::vector<double> newEndPoint );
~Line();

std::vector<double> GetDirection();
std::vector<double> ProjectVector( std::vector<double> vector );
void Translate( std::vector<double> vector );

std::vector<double> GetOrthogonalNormal1();
std::vector<double> GetOrthogonalNormal2();

std::string ToXMLString();
void FromXMLElement( vtkXMLDataElement* element );

};

#endif

//ETX
Loading

0 comments on commit 14ae67b

Please sign in to comment.