00001 /*========================================================================= 00002 00003 Program: Medical Imaging & Interaction Toolkit 00004 Language: C++ 00005 Date: $Date$ 00006 Version: $Revision$ 00007 00008 Copyright (c) German Cancer Research Center, Division of Medical and 00009 Biological Informatics. All rights reserved. 00010 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 00018 #include "mitkInternalTrackingTool.h" 00019 00020 #include <itkMutexLockHolder.h> 00021 00022 typedef itk::MutexLockHolder<itk::FastMutexLock> MutexLockHolder; 00023 00024 mitk::InternalTrackingTool::InternalTrackingTool() 00025 : TrackingTool(), 00026 m_TrackingError(0.0f), 00027 m_Enabled(true), 00028 m_DataValid(false) 00029 { 00030 m_Position[0] = 0.0f; 00031 m_Position[1] = 0.0f; 00032 m_Position[2] = 0.0f; 00033 m_Orientation[0] = 0.0f; 00034 m_Orientation[1] = 0.0f; 00035 m_Orientation[2] = 0.0f; 00036 m_Orientation[3] = 0.0f; 00037 } 00038 00039 mitk::InternalTrackingTool::~InternalTrackingTool() 00040 { 00041 } 00042 00043 00044 void mitk::InternalTrackingTool::SetToolName(const char* _arg) 00045 { 00046 itkDebugMacro("setting m_ToolName to " << _arg); 00047 MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex 00048 if ( _arg && (_arg == this->m_ToolName) ) 00049 { 00050 return; 00051 } 00052 if (_arg) 00053 { 00054 this->m_ToolName= _arg; 00055 } 00056 else 00057 { 00058 this->m_ToolName= ""; 00059 } 00060 this->Modified(); 00061 } 00062 00063 00064 void mitk::InternalTrackingTool::SetToolName( const std::string _arg ) 00065 { 00066 this->SetToolName(_arg.c_str()); 00067 } 00068 00069 00070 void mitk::InternalTrackingTool::GetPosition(mitk::Point3D& position) const 00071 { 00072 MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex 00073 position[0] = m_Position[0]; 00074 position[1] = m_Position[1]; 00075 position[2] = m_Position[2]; 00076 this->Modified(); 00077 } 00078 00079 00080 void mitk::InternalTrackingTool::SetPosition(mitk::Point3D position) 00081 { 00082 itkDebugMacro("setting m_Position to " << position); 00083 00084 MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex 00085 if (mitk::Equal(position, m_Position)) 00086 { 00087 return; 00088 } 00089 m_Position = position; 00090 this->Modified(); 00091 } 00092 00093 00094 void mitk::InternalTrackingTool::GetOrientation(mitk::Quaternion& orientation) const 00095 { 00096 MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex 00097 orientation = m_Orientation; 00098 } 00099 00100 00101 void mitk::InternalTrackingTool::SetOrientation(mitk::Quaternion orientation) 00102 { 00103 itkDebugMacro("setting m_Orientation to " << orientation); 00104 MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex 00105 if (mitk::Equal(orientation, m_Orientation)) 00106 { 00107 return; 00108 } 00109 m_Orientation = orientation; 00110 this->Modified(); 00111 } 00112 00113 00114 void mitk::InternalTrackingTool::SetTrackingError(float error) 00115 { 00116 itkDebugMacro("setting m_TrackingError to " << error); 00117 MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex 00118 if (error == m_TrackingError) 00119 { 00120 return; 00121 } 00122 m_TrackingError = error; 00123 this->Modified(); 00124 } 00125 00126 00127 float mitk::InternalTrackingTool::GetTrackingError() const 00128 { 00129 MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex 00130 float r = m_TrackingError; 00131 return r; 00132 } 00133 00134 00135 bool mitk::InternalTrackingTool::Enable() 00136 { 00137 MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex 00138 if (m_Enabled == false) 00139 { 00140 this->m_Enabled = true; 00141 this->Modified(); 00142 } 00143 return true; 00144 } 00145 00146 00147 bool mitk::InternalTrackingTool::Disable() 00148 { 00149 MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex 00150 if (m_Enabled == true) 00151 { 00152 this->m_Enabled = false; 00153 this->Modified(); 00154 } 00155 return true; 00156 } 00157 00158 00159 bool mitk::InternalTrackingTool::IsEnabled() const 00160 { 00161 MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex 00162 return m_Enabled; 00163 } 00164 00165 00166 bool mitk::InternalTrackingTool::IsDataValid() const 00167 { 00168 MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex 00169 return m_DataValid; 00170 } 00171 00172 00173 void mitk::InternalTrackingTool::SetDataValid(bool _arg) 00174 { 00175 itkDebugMacro("setting m_DataValid to " << _arg); 00176 if (this->m_DataValid != _arg) 00177 { 00178 MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex 00179 this->m_DataValid = _arg; 00180 this->Modified(); 00181 } 00182 } 00183 00184 00185 void mitk::InternalTrackingTool::SetErrorMessage(const char* _arg) 00186 { 00187 itkDebugMacro("setting m_ErrorMessage to " << _arg); 00188 MutexLockHolder lock(*m_MyMutex); // lock and unlock the mutex 00189 if ((_arg == NULL) || (_arg == this->m_ErrorMessage)) 00190 return; 00191 00192 if (_arg != NULL) 00193 this->m_ErrorMessage = _arg; 00194 else 00195 this->m_ErrorMessage = ""; 00196 this->Modified(); 00197 }