18 #include <QTableWidget>
19 #include <QMessageBox>
20 #include <QFileDialog>
21 #include <QInputDialog>
27 #include <mitkIGTException.h>
40 : QWidget(parent), m_Controls(NULL), m_Tracker(NULL), m_Source(NULL),
41 m_Delegate(NULL), m_SROMCellDefaultText(
"<click to load SROM file>"), m_RepresentatonCellDefaultText(
"<click to select representation>")
60 m_Controls =
new Ui::QmitkNDIConfigurationWidget;
64 comPorts <<
"COM1" <<
"COM2" <<
"COM3" <<
"COM4" <<
"COM5" <<
"COM6" <<
"COM7" <<
"COM8" <<
"COM9";
66 comPorts <<
"/dev/ttyS1" <<
"/dev/ttyS2" <<
"/dev/ttyS3" <<
"/dev/ttyS4" <<
"/dev/ttyS5" <<
"/dev/ttyUSB0" <<
"/dev/ttyUSB1" <<
"/dev/ttyUSB2" <<
"/dev/ttyUSB3";
68 m_Controls->m_ComPortSelector->addItems(comPorts);
87 connect(
m_Controls->m_ToolTable->model(), SIGNAL(dataChanged(
const QModelIndex &,
const QModelIndex &)),
this, SLOT(
UpdateTrackerFromToolTable(
const QModelIndex &,
const QModelIndex &)));
113 QMessageBox::warning(NULL,
"Error", QString(
"Connection failed, error message: ") + e.GetDescription());
142 QMessageBox::warning(NULL,
"Error", QString(
"Connection failed due to an unknown reason!"));
175 m_Controls->m_lConnection->setText(
"III. Enable connection to device ");
179 m_Controls->m_DiscoverToolsBtn->setDisabled(
true);
187 m_Controls->m_lConnection->setText(
"III. Enable connection to device ");
190 m_Controls->m_DiscoverToolsBtn->setDisabled(
true);
197 m_Controls->m_lConnection->setText(
"III. Disable connection to device ");
200 m_Controls->m_DiscoverToolsBtn->setEnabled(
true);
209 return QString(
"Not connected");
211 QString devName = QString::fromStdString(
m_Tracker->GetType());
214 return QString(
"Connected to %1 on %2. Device is ready.").arg(devName).arg(
m_Tracker->GetDeviceName());
216 return QString(
"%1 is tracking.").arg(devName);
225 QMessageBox::warning(NULL,
"Error", QString(
"Connection failed. No tracking device found."));
239 QStringList filenames = QFileDialog::getOpenFileNames(
this,
"Select NDI SROM file", QDir::currentPath(),
"NDI SROM files (*.rom)");
240 if (filenames.isEmpty())
245 foreach(QString fileName, filenames)
250 m_Tracker->AddTool(QFileInfo(fileName).baseName().toLatin1(), fileName.toLatin1());
277 QString deviceName =
m_Controls->m_ComPortSelector->currentText();
279 deviceName.prepend(
"\\\\.\\");
281 return deviceName.toStdString();
296 disconnect(
m_Controls->m_ToolTable->model(), SIGNAL(dataChanged(
const QModelIndex &,
const QModelIndex &)),
this, SLOT(
UpdateTrackerFromToolTable(
const QModelIndex &,
const QModelIndex &)));
307 for (
unsigned int i = 0; i <
m_Tracker->GetToolCount(); ++i)
320 if (dynamic_cast<mitk::NDIPassiveTool*>(t)->GetSROMDataLength() > 0)
344 m_Controls->m_ToolTable->resizeColumnsToContents();
346 connect(
m_Controls->m_ToolTable->model(), SIGNAL(dataChanged(
const QModelIndex &,
const QModelIndex &)),
this, SLOT(
UpdateTrackerFromToolTable(
const QModelIndex &,
const QModelIndex &)));
355 QString status =
"Scanning ";
358 for (
unsigned int i = 1; i < 40; ++i)
361 devName = QString(
"COM%1").arg(i);
363 devName = QString(
"\\\\.\\COM%1").arg(i);
364 portsAndDevices[devName];
365 status += QString(
"COM%1").arg(i) +
", ";
367 #else //linux/posix systems
368 for(
unsigned int i = 1; i < 6; ++i)
370 QString devName = QString(
"/dev/ttyS%1").arg(i);
371 portsAndDevices[devName];
372 status += devName +
", ";
374 for(
unsigned int i = 0; i <7; ++i)
376 QString devName = QString(
"/dev/ttyUSB%1").arg(i);
377 portsAndDevices[devName];
378 status += devName +
", ";
383 status +=
" for NDI tracking devices...";
387 QString result =
"The following tracking devices were found:<BR/>\n";
388 for (PortDeviceMap::const_iterator it = portsAndDevices.begin(); it != portsAndDevices.end(); ++it)
390 QString tmpComPort = it.key();
391 if (tmpComPort.startsWith(
"\\"))
393 tmpComPort.remove(0,4);
395 result += tmpComPort +
": ";
399 result += QString::fromStdString(it.value());
401 m_Controls->m_ComPortSelector->addItem(tmpComPort);
405 result +=
"No NDI tracking device found<BR/>\n";
416 tracker->SetDeviceName(port.toStdString());
417 return tracker->TestConnection();
424 for (PortDeviceMap::iterator it = portsAndDevices.begin(); it != portsAndDevices.end(); ++it)
425 it.value() = this->
ScanPort(it.key());
435 QStringList toolNames;
438 for (
unsigned int i = 0; i <
m_Tracker->GetToolCount(); ++i)
488 QTableWidgetItem* filenameItem;
490 switch (topLeft.column())
494 filename = QFileDialog::getOpenFileName(
this,
"Select Surface File", QDir::currentPath(),
"STL files (*.stl)");
496 filenameItem =
new QTableWidgetItem(filename);
497 m_Controls->m_ToolTable->setItem( topLeft.row(), topLeft.column(), filenameItem );
499 if(QFileInfo(filename).exists())
503 if(surface.IsNotNull())
516 if (topLeft.column()<1)
522 if (topLeft.row() >= (int)
m_Tracker->GetToolCount())
525 QAbstractItemModel* model =
m_Controls->m_ToolTable->model();
533 switch (topLeft.column())
538 tool->
SetToolName(model->data(model->index(topLeft.row(), 1)).toString().toLatin1());
544 if (QFileInfo(romfile).exists())
563 QAbstractItemModel* model =
m_Controls->m_ToolTable->model();
565 if (modelIndex.isValid() ==
false)
568 return model->data(modelIndex).toString();
577 QAbstractItemModel* model =
m_Controls->m_ToolTable->model();
579 if (modelIndex.isValid() ==
false)
582 return model->data(modelIndex).toString();
588 QMap<QString, unsigned int>
map;
591 QAbstractItemModel* model =
m_Controls->m_ToolTable->model();
592 for (
int i = 0; i < model->rowCount(); ++i)
596 if ((indexIndex.isValid() ==
false) || (typeIndex.isValid() ==
false))
598 map.insert(model->data(typeIndex).toString(), model->data(indexIndex).toUInt());
606 QList<unsigned int> list;
609 QAbstractItemModel* model =
m_Controls->m_ToolTable->model();
610 for (
int i = 0; i < model->rowCount(); ++i)
614 if ((indexIndex.isValid() ==
false) || (typeIndex.isValid() ==
false))
616 if (model->data(typeIndex).toString() == toolType)
617 list.append(model->data(indexIndex).toUInt());
628 QAbstractItemModel* model =
m_Controls->m_ToolTable->model();
635 m_Controls->m_gbPolarisOptions->setHidden(on);
645 int cols =
m_Controls->m_ToolTable->columnCount();
661 int rows =
m_Controls->m_ToolTable->rowCount();
664 for(
int i=0; i < rows; ++i)
676 QMessageBox *infoBox =
new QMessageBox(
this);
677 infoBox->setText(
"Click \"Scan Ports\" to get a list of all connected NDI tracking devices. This will clear the selection menu below and add the ports for discovered NDI tracking devices. Use this function, if a port is not listed.");
694 toolName =
m_Controls->m_ToolTable->item(row,column)->text();
695 m_Controls->m_ToolSelectionComboBox->setItemText(row, toolName);
713 int currId =
m_Controls->m_ToolSelectionComboBox->currentIndex();
714 QString
filename = QFileDialog::getSaveFileName(NULL,
"Save NDI-Tool", QString(QString(
m_Tracker->GetTool(currId)->GetToolName())),
"NDI Tracking Tool file(*.ntf)");
718 if(filename.isEmpty())
730 QMessageBox::warning(NULL,
"Saving Tool Error", QString(
"An error occured! Could not save tool!\n\n"));
731 MBI_ERROR<<
"Could not save tool surface!";
732 MBI_ERROR<< toolWriter->GetErrorMessage();
734 QFile maybeCorruptFile(filename);
736 if(maybeCorruptFile.exists())
737 maybeCorruptFile.remove();
749 QString
filename = QFileDialog::getOpenFileName(NULL,
"Load NDI-Tools", QDir::currentPath(),
"NDI Tracking Tool file(*.ntf)");
750 int currId =
m_Controls->m_ToolSelectionComboBox->currentIndex();
752 if(filename.isEmpty())
760 navTool = toolReader->DoRead(filename.toStdString());
764 QMessageBox::warning(NULL,
"Loading Tool Error", QString(
"An error occured! Could not load tool!\n\n"));
765 MBI_ERROR<<
"Could not load tool surface!";
766 MBI_ERROR<< toolReader->GetErrorMessage();
769 int currSelectedToolID =
m_Controls->m_ToolSelectionComboBox->currentIndex();
801 if(passiveTool.IsNull())
802 throw std::runtime_error(
"Could not cast TrackingTool to PassiveTool");
804 int currSelectedToolID =
m_Controls->m_ToolSelectionComboBox->currentIndex();
810 QFile sromFile(sromFileName);
811 if(sromFile.exists())
812 navTool->SetCalibrationFile(sromFileName.toStdString());
815 navTool->SetSerialNumber(passiveTool->GetSerialNumber());
827 QMessageBox::warning(NULL,
"Loading Surface Error", QString(
"An error occured! Could not load surface from .stl file!\n\n"));
828 MBI_ERROR<<
"Could not load .stl tool surface!";
832 if(toolSurface.IsNotNull())
834 node->SetData(toolSurface);
838 navTool->SetDataNode(node);
844 if(currentToolType.compare(
"Instrument") == 0)
846 else if(currentToolType.compare(
"Fiducial") == 0)
848 else if(currentToolType.compare(
"Skinmarker") == 0)
853 navTool->SetType(type);
863 QFile surfaceFile(surfaceFilename);
864 if(surfaceFile.exists())
869 catch(std::exception& e )
871 MBI_ERROR<<
"Could not load surface for tool!";
885 m_Controls->m_DiscoverToolsBtn->setEnabled(enable);
static mitk::Surface::Pointer LoadSurface(const std::string &path)
LoadSurface Convenience method to load an arbitrary mitkSurface.
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
An object of this class represents an exception of the MITK-IGT module.
static const std::string filename
std::string TrackingDeviceType
superclass for specific NDI tracking Devices that use serial communication.
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer map(const InputImageType *input, const RegistrationType *registration, bool throwOnOutOfInputAreaError=false, const double &paddingValue=0, const ResultImageGeometryType *resultGeometry=NULL, bool throwOnMappingError=true, const double &errorValue=0, mitk::ImageMappingInterpolator::Type interpolatorType=mitk::ImageMappingInterpolator::Linear)
Class for nodes of the DataTree.