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 <mitkPositionTracker.h> 00019 00020 #include <mitkBaseRenderer.h> 00021 #include <mitkDataStorage.h> 00022 #include <mitkNodePredicateProperty.h> 00023 #include <mitkDisplayPositionEvent.h> 00024 #include <mitkAction.h> 00025 #include <mitkStateEvent.h> 00026 #include <mitkUndoController.h> 00027 #include <mitkInteractionConst.h> 00028 #include <mitkPointSet.h> 00029 #include <mitkRenderingManager.h> 00030 #include <mitkVector.h> // for PointDataType 00031 #include <mitkProperties.h> 00032 00033 00034 mitk::PositionTracker::PositionTracker(const char * type, mitk::OperationActor* /*operationActor*/) 00035 : mitk::StateMachine(type) 00036 {} 00037 00038 00039 bool mitk::PositionTracker::ExecuteAction(Action* /*action*/, mitk::StateEvent const* stateEvent) 00040 { 00041 bool ok = false; 00042 const DisplayPositionEvent* displayPositionEvent = dynamic_cast<const DisplayPositionEvent*>(stateEvent->GetEvent()); 00043 00044 mitk::DataNode::Pointer dtnode; 00045 mitk::DataStorage* ds = NULL; 00046 if (displayPositionEvent == NULL) 00047 return false; 00048 00049 if (stateEvent->GetEvent()->GetSender()!=NULL) 00050 { 00051 ds = stateEvent->GetEvent()->GetSender()->GetDataStorage(); 00052 } 00053 else 00054 { 00055 itkWarningMacro(<<"StateEvent::GetSender()==NULL - setting timeInMS to 0"); 00056 return false; 00057 } 00058 if (ds == NULL) 00059 return false; 00060 00061 // looking for desired point set 00062 dtnode = ds->GetNode(mitk::NodePredicateProperty::New("inputdevice", mitk::BoolProperty::New(true))); 00063 if (dtnode.IsNull()) 00064 return false; 00065 00066 dtnode->SetIntProperty("BaseRendererMapperID", stateEvent->GetEvent()->GetSender()->GetMapperID()); 00067 mitk::PointSet* ps = dynamic_cast<mitk::PointSet*>(dtnode->GetData()); 00068 if (ps == NULL) 00069 return false; 00070 00071 int position = 0; 00072 if( ps->GetPointSet()->GetPoints()->IndexExists( position )) //first element 00073 { 00074 ps->GetPointSet()->GetPoints()->SetElement( position, displayPositionEvent->GetWorldPosition()); 00075 } 00076 else 00077 { 00078 mitk::PointSet::PointDataType pointData = {position , false /*selected*/, mitk::PTUNDEFINED}; 00079 ps->GetPointSet()->GetPointData()->InsertElement(position, pointData); 00080 ps->GetPointSet()->GetPoints()->InsertElement(position, displayPositionEvent->GetWorldPosition()); 00081 } 00082 ps->Modified(); 00083 mitk::RenderingManager::GetInstance()->RequestUpdateAll(); 00084 return ok; 00085 }