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 00019 #include "mitkSurfaceInteractor.h" 00020 #include "mitkPointLocator.h" 00021 #include "mitkSurface.h" 00022 00023 #include "mitkStateEvent.h" 00024 #include "mitkInteractionConst.h" 00025 #include "mitkBaseRenderer.h" 00026 00027 #include <vtkPolyData.h> 00028 00029 mitk::SurfaceInteractor::SurfaceInteractor(const char * type, DataNode* dataNode) 00030 : AffineInteractor(type, dataNode) 00031 { 00032 m_PtLoc = PLocType::New(); 00033 } 00034 00035 00036 float mitk::SurfaceInteractor::CanHandleEvent( StateEvent const* stateEvent ) const 00037 { 00038 float jd = 0.0f; 00039 00040 if( ! ( stateEvent->GetEvent()->GetButtonState() == mitk::BS_ControlButton && stateEvent->GetEvent()->GetType() == mitk::Type_MouseButtonPress )) 00041 return jd; 00042 00043 if ( stateEvent->GetEvent()->GetSender()->GetMapperID() == mitk::BaseRenderer::Standard3D ) 00044 return jd; 00045 00046 mitk::Surface* surf = dynamic_cast<mitk::Surface*>(this->GetData()); 00047 if (surf) 00048 { 00049 mitk::DisplayPositionEvent const *event = dynamic_cast <const mitk::DisplayPositionEvent *> (stateEvent->GetEvent()); 00050 mitk::PointSet::PointType pt = event->GetWorldPosition(); 00051 00052 // Use ANN to get the point of the polydata closest to the world event 00053 if( surf->GetVtkPolyData(m_TimeStep) == NULL ) itkExceptionMacro(<< "No polydata at this time step!"); 00054 m_PtLoc->SetPoints(dynamic_cast<vtkPointSet*>(surf->GetVtkPolyData(m_TimeStep))); 00055 mitk::PointLocator::DistanceType dst = m_PtLoc->GetMinimalDistance(pt); 00056 00057 mitk::BaseRenderer* ren = stateEvent->GetEvent()->GetSender(); 00058 00059 // Get the diameter of the render window bounding box 00060 mitk::DataStorage* storage = ren->GetDataStorage(); 00061 mitk::BoundingBox::Pointer bb = storage->ComputeBoundingBox(); 00062 mitk::BoundingBox::AccumulateType dia = std::sqrt(bb->GetDiagonalLength2()); 00063 00064 if (dia > 0.00001) //if diameter not zero 00065 { 00066 float verh = dst/dia; 00067 if (verh>1) verh = 1; //if dst is bigger than dia, then set to 1 00068 //now inverse (0 = bad and 1 = good) and set between 0.5 and 1 00069 jd = ((1-verh)/2)+0.5f; 00070 } 00071 } 00072 return jd; 00073 }