The method SetSurface() doesn't work in all cases. You have to use the class GeneralNavigationToolModel to get a working Surface. The error doesn't occure in the method SetSurface() but later on when the method OnCalcInitPosition() is called which happens when the user clicks the corresponding button. The error manifests itself in the fact, that no surface is loaded and accordingly no initial position is calculated.
I've the suspicion that the error occurs when the programm tries to convert the stl-image into a binary image (method makeImage()).
An example:
this code works:
mitk::GeneralNavigationToolModel::Pointer m_NavigationToolModel = mitk::GeneralNavigationToolModel::New();
QString fileName = QFileDialog::getOpenFileName(NULL,"Open Surface","/","surface files (*.stl *.vtk *.vtp *.obj)"); if (fileName==QString::null)return; m_NavigationToolModel->SetSurfaceFilePath(fileName.toStdString()); m_NavigationToolModel->CreateSurface(); m_Controls->m_NeedleShapedRegistrationWidget->SetSurface(dynamic_cast<mitk::Surface*>(m_NavigationToolModel.GetPointer()));
and this not:
std::string filename = "C:\\tools\\Tool11c_ANCHOR._KwongTest3.stl";
mitk::STLFileReader::Pointer stlReader = mitk::STLFileReader::New(); try { stlReader->SetFileName( filename.c_str() ); stlReader->Update(); } catch (...) { } if ( stlReader->GetOutput() == NULL ); else { m_Controls->m_NeedleShapeRegistrationWidget->SetSurface(stlReader->GetOutput()); std::cout << "Loaded testing tool succesfully!"; }