diff --git a/Plugins/org.mitk.gui.qt.igt.app.echotrack/src/internal/Filter/mitkUSNavigationTargetOcclusionFilter.cpp b/Plugins/org.mitk.gui.qt.igt.app.echotrack/src/internal/Filter/mitkUSNavigationTargetOcclusionFilter.cpp index 96c60f6604..ddb5e240e1 100644 --- a/Plugins/org.mitk.gui.qt.igt.app.echotrack/src/internal/Filter/mitkUSNavigationTargetOcclusionFilter.cpp +++ b/Plugins/org.mitk.gui.qt.igt.app.echotrack/src/internal/Filter/mitkUSNavigationTargetOcclusionFilter.cpp @@ -1,193 +1,193 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // MITK #include "mitkUSNavigationTargetOcclusionFilter.h" #include "mitkDataNode.h" #include "mitkSurface.h" // VTK #include "vtkSmartPointer.h" #include "vtkPointData.h" #include "vtkPolyData.h" #include "vtkOBBTree.h" #include "vtkFloatArray.h" #include "vtkTransform.h" #include "vtkTransformPolyDataFilter.h" mitk::USNavigationTargetOcclusionFilter::USNavigationTargetOcclusionFilter() : m_StartPositionInput(0) { } mitk::USNavigationTargetOcclusionFilter::~USNavigationTargetOcclusionFilter() { } void mitk::USNavigationTargetOcclusionFilter::SetTargetStructure(itk::SmartPointer targetStructure) { m_TargetStructure = targetStructure; } void mitk::USNavigationTargetOcclusionFilter::SetObstacleStructures(DataStorage::SetOfObjects::ConstPointer obstacleStructures) { m_ObstacleStructures = obstacleStructures; } void mitk::USNavigationTargetOcclusionFilter::SelectStartPositionInput(unsigned int n) { m_StartPositionInput = n; } void mitk::USNavigationTargetOcclusionFilter::GenerateData() { mitk::NavigationDataPassThroughFilter::GenerateData(); // get vtk surface an the points vtkPolyData* targetSurfaceVtk = this->GetVtkPolyDataOfTarget(); if ( ! targetSurfaceVtk ) { return; } // cannot do anything without a target surface vtkIdType numberOfPoints = targetSurfaceVtk->GetNumberOfPoints(); // create array for scalar values vtkSmartPointer colors = vtkSmartPointer::New(); colors->SetNumberOfComponents(1); colors->SetName("USNavigation::Occlusion"); const mitk::NavigationData* nd = this->GetInput(m_StartPositionInput); // set every value to -1 if there is no (valid) navigation data if ( nd == 0 || ! nd->IsDataValid() ) { float intersection = -1; for ( vtkIdType n = 0; n < numberOfPoints; n++ ) { - colors->InsertNextTupleValue(&intersection); + colors->InsertNextTuple1(intersection); } if ( numberOfPoints > 0 ) { targetSurfaceVtk->GetPointData()->AddArray(colors); targetSurfaceVtk->GetPointData()->Update(); } return; } // initialize values with 0 (no intersection) if there is valid navigation // data and there are some obstacle structures defined else if ( m_ObstacleStructures.IsNull() ) { float intersection = 0; for ( vtkIdType n = 0; n < numberOfPoints; n++ ) { - colors->InsertNextTupleValue(&intersection); + colors->InsertNextTuple1(intersection); } if ( numberOfPoints > 0 ) { targetSurfaceVtk->GetPointData()->AddArray(colors); targetSurfaceVtk->GetPointData()->Update(); } return; } // get the current position from the navigation data mitk::Point3D position = nd->GetPosition(); double point1[3]; point1[0] = position[0]; point1[1] = position[1]; point1[2] = position[2]; // transform vtk polydata according to mitk geometry vtkSmartPointer transformFilter = vtkSmartPointer::New(); transformFilter->SetInputData(0, targetSurfaceVtk); transformFilter->SetTransform(m_TargetStructure->GetData()->GetGeometry()->GetVtkTransform()); transformFilter->Update(); vtkPolyData* targetSurfaceVtkTransformed = transformFilter->GetOutput(); std::vector occlusion(numberOfPoints, false); // calculate occlusion for every obstacle structure for (mitk::DataStorage::SetOfObjects::ConstIterator it = m_ObstacleStructures->Begin(); it != m_ObstacleStructures->End(); ++it) { vtkPolyData* polyData = dynamic_cast(it->Value()->GetData())->GetVtkPolyData(); // transform the obstacle strucutre according to the mitk geometry vtkSmartPointer transformFilter = vtkSmartPointer::New(); transformFilter->SetInputData(0, polyData); transformFilter->SetTransform(it->Value()->GetData()->GetGeometry()->GetVtkTransform()); transformFilter->Update(); polyData = transformFilter->GetOutput(); // build an obb tree locator vtkSmartPointer cellLocator = vtkSmartPointer::New(); cellLocator->SetDataSet(polyData); cellLocator->BuildLocator(); // test for intersection with every point on the surface for ( unsigned int n = 0; n < numberOfPoints; n++ ) { vtkSmartPointer points = vtkSmartPointer::New(); if ( cellLocator->IntersectWithLine(point1, targetSurfaceVtkTransformed->GetPoint(n), points, nullptr) != 0 ) { occlusion.at(n) = true; } } } if ( numberOfPoints > 0 ) { // set the occlusion values as scalar array to the vtkPolyData float one = 1.0f; float zero = 0.0f; for ( std::vector::iterator it = occlusion.begin(); it != occlusion.end(); ++it ) { - colors->InsertNextTupleValue(*it ? &one : &zero); + colors->InsertNextTuple1(*it ? one : zero); } targetSurfaceVtk->GetPointData()->AddArray(colors); targetSurfaceVtk->GetPointData()->Update(); } } vtkSmartPointer mitk::USNavigationTargetOcclusionFilter::GetVtkPolyDataOfTarget() { if ( m_TargetStructure.IsNull() ) { MITK_WARN("USNavigationTargetOcclusionFilter") << "Target structure must not be null."; return nullptr; } mitk::Surface::Pointer targetSurface = dynamic_cast(m_TargetStructure->GetData()); if ( targetSurface.IsNull() ) { MITK_WARN("USNavigationTargetOcclusionFilter") << "A mitk::Surface has to be set to the data node."; return nullptr; } vtkSmartPointer targetSurfaceVtk = targetSurface->GetVtkPolyData(); if( targetSurfaceVtk == 0 ) { MITK_WARN("USNavigationTargetOcclusionFilter") << "VtkPolyData of the mitk::Surface of the data node must not be null."; return nullptr; } return targetSurfaceVtk; } diff --git a/Plugins/org.mitk.gui.qt.igt.app.echotrack/src/internal/Filter/mitkUSNavigationTargetUpdateFilter.cpp b/Plugins/org.mitk.gui.qt.igt.app.echotrack/src/internal/Filter/mitkUSNavigationTargetUpdateFilter.cpp index 397185d4a7..47835e4675 100644 --- a/Plugins/org.mitk.gui.qt.igt.app.echotrack/src/internal/Filter/mitkUSNavigationTargetUpdateFilter.cpp +++ b/Plugins/org.mitk.gui.qt.igt.app.echotrack/src/internal/Filter/mitkUSNavigationTargetUpdateFilter.cpp @@ -1,270 +1,270 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkUSNavigationTargetUpdateFilter.h" #include #include "mitkDataNode.h" #include "mitkSurface.h" #include "vtkSmartPointer.h" #include "vtkUnsignedCharArray.h" #include "vtkPolyData.h" #include "vtkPointData.h" #include "vtkLookupTable.h" #include "mitkLookupTable.h" #include "mitkLookupTableProperty.h" #include "vtkFloatArray.h" #include "vtkTransformPolyDataFilter.h" #include "vtkLinearTransform.h" mitk::USNavigationTargetUpdateFilter::USNavigationTargetUpdateFilter() : m_NumberOfTargets(0), m_OptimalAngle(0), m_ScalarArrayIdentifier("USNavigation::NoIdentifierSet"), m_UseMaximumScore(false) { } mitk::USNavigationTargetUpdateFilter::~USNavigationTargetUpdateFilter() { } void mitk::USNavigationTargetUpdateFilter::SetTargetStructure(DataNode::Pointer targetStructure) { m_TargetStructure = targetStructure; // get vtk surface and the points vtkSmartPointer targetSurfaceVtk = this->GetVtkPolyDataOfTarget(); int numberOfPoints = targetSurfaceVtk->GetNumberOfPoints(); if ( numberOfPoints > 0 ) { // create vtk scalar array for score values vtkSmartPointer colors = vtkSmartPointer::New(); colors->SetNumberOfComponents(1); colors->SetName(m_ScalarArrayIdentifier.c_str()); // initialize with green color float color = 1; for (int n = 0; n < numberOfPoints ; ++n) { - colors->InsertNextTupleValue(&color); + colors->InsertNextTuple1(color); } // add the scores array to the target surface targetSurfaceVtk->GetPointData()->AddArray(colors); targetSurfaceVtk->GetPointData()->Update(); } } bool mitk::USNavigationTargetUpdateFilter::SetNumberOfTargets(unsigned int numberOfTargets) { if ( numberOfTargets < 1 || numberOfTargets > 4 ) { MITK_WARN << "Number of targets can only be between 1 and 4."; return false; } if ( numberOfTargets == 1 ) { m_OptimalAngle = 0; } else if ( numberOfTargets < 5 ) { // for every number of targets between 2 and 4 the optimal angle can be // calculated using the arcus cosinus m_OptimalAngle = acos(-1.0/(numberOfTargets-1)); } m_NumberOfTargets = numberOfTargets; return true; } void mitk::USNavigationTargetUpdateFilter::SetOptimalAngle(double optimalAngle) { m_OptimalAngle = optimalAngle; } double mitk::USNavigationTargetUpdateFilter::GetOptimalAngle() { return m_OptimalAngle; } void mitk::USNavigationTargetUpdateFilter::SetScalarArrayIdentifier(std::string scalarArrayIdentifier) { m_ScalarArrayIdentifier = scalarArrayIdentifier; } void mitk::USNavigationTargetUpdateFilter::SetUseMaximumScore(bool useMaximumScore) { m_UseMaximumScore = useMaximumScore; } void mitk::USNavigationTargetUpdateFilter::SetControlNode(unsigned int id, itk::SmartPointer controlNode) { // make sure that the node fit into the vector and insert it then if ( m_ControlNodesVector.size() <= id ) { m_ControlNodesVector.resize(id+1); } m_ControlNodesVector[id] = controlNode; this->UpdateTargetScores(); } void mitk::USNavigationTargetUpdateFilter::RemovePositionOfTarget(unsigned int id) { if ( id >= m_ControlNodesVector.size() ) { mitkThrow() << "Given id is larger than the vector size."; } m_ControlNodesVector.erase(m_ControlNodesVector.begin()+id); this->UpdateTargetScores(); } void mitk::USNavigationTargetUpdateFilter::Reset() { m_ControlNodesVector.clear(); if ( m_TargetStructure.IsNotNull() ) { this->UpdateTargetScores(); } } void mitk::USNavigationTargetUpdateFilter::UpdateTargetScores() { mitk::BaseGeometry::Pointer targetStructureGeometry = this->GetGeometryOfTarget(); mitk::Point3D targetStructureOrigin = targetStructureGeometry->GetOrigin(); // get vtk surface and the points vtkSmartPointer targetSurfaceVtk = this->GetVtkPolyDataOfTarget(); int numberOfPoints = targetSurfaceVtk->GetNumberOfPoints(); // transform vtk polydata according to mitk geometry vtkSmartPointer transformFilter = vtkSmartPointer::New(); transformFilter->SetInputData(0, targetSurfaceVtk); transformFilter->SetTransform(targetStructureGeometry->GetVtkTransform()); transformFilter->Update(); vtkPolyData* targetSurfaceVtkTransformed = transformFilter->GetOutput(); if ( numberOfPoints > 0 ) { vtkSmartPointer colors = vtkSmartPointer::New(); colors->SetNumberOfComponents(1); colors->SetName(m_ScalarArrayIdentifier.c_str()); for (int n = 0; n < numberOfPoints ; ++n) { float score = m_UseMaximumScore ? 0.0 : 1.0; if ( m_ControlNodesVector.empty() ) { // first target can be placed everywhere score = 1; } else if ( m_ControlNodesVector.size() == m_NumberOfTargets ) { // if all targets are placed, there is no // good position for another target score = 0; } else { double coordinates[3]; mitk::Point3D coordinatesMitk; targetSurfaceVtkTransformed->GetPoint(n, coordinates); coordinatesMitk[0] = coordinates[0]; coordinatesMitk[1] = coordinates[1]; coordinatesMitk[2] = coordinates[2]; // vector pointing from the current surface coordinates to the origin // of the target structure itk::Vector vector = targetStructureOrigin - coordinatesMitk; vector.Normalize(); for (std::vector::iterator it = m_ControlNodesVector.begin(); it != m_ControlNodesVector.end(); ++it) { if ( (*it)->GetData() == 0 || (*it)->GetData()->GetGeometry() == 0 ) { mitkThrow() << "Control data node and geometry of the node must not be null."; } itk::Vector controlPointToOriginVector = targetStructureOrigin - (*it)->GetData()->GetGeometry()->GetOrigin(); controlPointToOriginVector.Normalize(); float angle = acos( vector * controlPointToOriginVector ); float angleDifference = angle - m_OptimalAngle; float tmpScore = 1 - (angleDifference >= 0 ? angleDifference : -angleDifference); // update the score if the current score is larger (or lower) than // this score if ( (m_UseMaximumScore && tmpScore > score) || (!m_UseMaximumScore && tmpScore < score) ) { score = tmpScore; } } } - colors->InsertNextTupleValue(&score); + colors->InsertNextTuple1(score); } targetSurfaceVtk->GetPointData()->AddArray(colors); targetSurfaceVtk->GetPointData()->Update(); } } vtkSmartPointer mitk::USNavigationTargetUpdateFilter::GetVtkPolyDataOfTarget() { if ( m_TargetStructure.IsNull() ) { mitkThrow() << "Target structure must not be null."; } mitk::Surface::Pointer targetSurface = dynamic_cast(m_TargetStructure->GetData()); if ( targetSurface.IsNull() ) { mitkThrow() << "A mitk::Surface has to be set to the data node."; } vtkSmartPointer targetSurfaceVtk = targetSurface->GetVtkPolyData(); if( targetSurfaceVtk == 0 ) { mitkThrow() << "VtkPolyData of the mitk::Surface of the data node must not be null."; } return targetSurfaceVtk; } mitk::BaseGeometry::Pointer mitk::USNavigationTargetUpdateFilter::GetGeometryOfTarget() { if ( m_TargetStructure.IsNull() ) { mitkThrow() << "Target structure must be set before position of target is set."; } mitk::BaseData* targetStructureData = m_TargetStructure->GetData(); if ( ! targetStructureData ) { mitkThrow() << "Data of target structure must not be null."; } mitk::BaseGeometry::Pointer targetStructureGeometry = targetStructureData->GetGeometry(); if ( targetStructureGeometry.IsNull() ) { mitkThrow() << "Geometry of target structure must not be null."; } return targetStructureGeometry; } diff --git a/Plugins/org.mitk.gui.qt.materialeditor/src/internal/QmitkMITKSurfaceMaterialEditorView.cpp b/Plugins/org.mitk.gui.qt.materialeditor/src/internal/QmitkMITKSurfaceMaterialEditorView.cpp index 1840d78368..0ed3e54de0 100644 --- a/Plugins/org.mitk.gui.qt.materialeditor/src/internal/QmitkMITKSurfaceMaterialEditorView.cpp +++ b/Plugins/org.mitk.gui.qt.materialeditor/src/internal/QmitkMITKSurfaceMaterialEditorView.cpp @@ -1,245 +1,244 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "QmitkMITKSurfaceMaterialEditorView.h" #include "mitkBaseRenderer.h" #include "mitkNodePredicateDataType.h" #include "mitkProperties.h" #include "mitkIDataStorageService.h" #include "mitkDataNodeObject.h" #include "berryIEditorPart.h" #include "berryIWorkbenchPage.h" #include "QmitkDataStorageComboBox.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include "mitkStandaloneDataStorage.h" const std::string QmitkMITKSurfaceMaterialEditorView::VIEW_ID = "org.mitk.views.mitksurfacematerialeditor"; QmitkMITKSurfaceMaterialEditorView::QmitkMITKSurfaceMaterialEditorView() : QmitkAbstractView(), m_Controls(nullptr) { fixedProperties.push_back( "shader" ); fixedProperties.push_back( "material.representation" ); fixedProperties.push_back( "color" ); fixedProperties.push_back( "opacity" ); fixedProperties.push_back( "material.wireframeLineWidth" ); fixedProperties.push_back( "material.ambientCoefficient" ); fixedProperties.push_back( "material.diffuseCoefficient" ); fixedProperties.push_back( "material.ambientColor" ); fixedProperties.push_back( "material.diffuseColor" ); fixedProperties.push_back( "material.specularColor" ); fixedProperties.push_back( "material.specularCoefficient" ); fixedProperties.push_back( "material.specularPower" ); fixedProperties.push_back( "material.interpolation" ); shaderProperties.push_back( "shader" ); shaderProperties.push_back( "material.representation" ); shaderProperties.push_back( "color" ); shaderProperties.push_back( "opacity" ); shaderProperties.push_back( "material.wireframeLineWidth" ); observerAllocated = false; } QmitkMITKSurfaceMaterialEditorView::~QmitkMITKSurfaceMaterialEditorView() { } void QmitkMITKSurfaceMaterialEditorView::InitPreviewWindow() { usedTimer=0; vtkSphereSource* sphereSource = vtkSphereSource::New(); sphereSource->SetThetaResolution(25); sphereSource->SetPhiResolution(25); sphereSource->Update(); vtkPolyData* sphere = sphereSource->GetOutput(); m_Surface = mitk::Surface::New(); m_Surface->SetVtkPolyData( sphere ); m_DataNode = mitk::DataNode::New(); m_DataNode->SetData( m_Surface ); m_DataTree = mitk::StandaloneDataStorage::New(); m_DataTree->Add( m_DataNode , (mitk::DataNode *)0 ); m_Controls->m_PreviewRenderWindow->GetRenderer()->SetDataStorage( m_DataTree ); m_Controls->m_PreviewRenderWindow->GetRenderer()->SetMapperID( mitk::BaseRenderer::Standard3D ); sphereSource->Delete(); } void QmitkMITKSurfaceMaterialEditorView::RefreshPropertiesList() { mitk::DataNode* SrcND = m_SelectedDataNode; mitk::DataNode* DstND = m_DataNode; mitk::PropertyList* DstPL = DstND->GetPropertyList(); m_Controls->m_ShaderPropertyList->SetPropertyList( 0 ); DstPL->Clear(); if(observerAllocated) { - observedProperty->RemoveObserver( observerIndex ); observerAllocated=false; } if(SrcND) { mitk::PropertyList* SrcPL = SrcND->GetPropertyList(); std::string shaderState = "fixed"; // if(shaderEnum.IsNotNull()) // { // shaderState = shaderEnum->GetValueAsString(); // itk::MemberCommand::Pointer propertyModifiedCommand = itk::MemberCommand::New(); // propertyModifiedCommand->SetCallbackFunction(this, &QmitkMITKSurfaceMaterialEditorView::shaderEnumChange); // observerIndex = shaderEnum->AddObserver(itk::ModifiedEvent(), propertyModifiedCommand); // observedProperty = shaderEnum; // observerAllocated=true; // } MITK_INFO << "PROPERTIES SCAN BEGIN"; for(mitk::PropertyList::PropertyMap::const_iterator it=SrcPL->GetMap()->begin(); it!=SrcPL->GetMap()->end(); it++) { std::string name=it->first; mitk::BaseProperty *p=it->second; // MITK_INFO << "property '" << name << "' found"; if(shaderState.compare("fixed")==0) { if(std::find(fixedProperties.begin(), fixedProperties.end(), name) != fixedProperties.end()) { DstPL->SetProperty(name,p); } } else { //if(std::find(shaderProperties.begin(), shaderProperties.end(), name) != shaderProperties.end()) { DstPL->SetProperty(name,p); } } } MITK_INFO << "PROPERTIES SCAN END"; } m_Controls->m_ShaderPropertyList->SetPropertyList( DstPL ); //m_Controls->m_PreviewRenderWindow->GetRenderer()->GetVtkRenderer()->ResetCameraClippingRange(); } void QmitkMITKSurfaceMaterialEditorView::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkMITKSurfaceMaterialEditorViewControls; m_Controls->setupUi(parent); this->CreateConnections(); InitPreviewWindow(); RefreshPropertiesList(); } } void QmitkMITKSurfaceMaterialEditorView::SetFocus() { m_Controls->m_ShaderPropertyList->setFocus(); } void QmitkMITKSurfaceMaterialEditorView::CreateConnections() { } void QmitkMITKSurfaceMaterialEditorView::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*part*/, const QList& nodes) { if(!nodes.empty()) { m_SelectedDataNode = nodes.at(0); MITK_INFO << "Node '" << m_SelectedDataNode->GetName() << "' selected"; SurfaceSelected(); } } void QmitkMITKSurfaceMaterialEditorView::SurfaceSelected() { postRefresh(); } void QmitkMITKSurfaceMaterialEditorView::shaderEnumChange(const itk::Object * /*caller*/, const itk::EventObject & /*event*/) { postRefresh(); } void QmitkMITKSurfaceMaterialEditorView::postRefresh() { if(usedTimer) return; usedTimer=startTimer(0); } void QmitkMITKSurfaceMaterialEditorView::timerEvent( QTimerEvent *e ) { if(usedTimer!=e->timerId()) { MITK_ERROR << "INTERNAL ERROR: usedTimer[" << usedTimer << "] != timerId[" << e->timerId() << "]"; } if(usedTimer) { killTimer(usedTimer); usedTimer=0; } RefreshPropertiesList(); }