14 #include <QVBoxLayout> 15 #include <QPushButton> 16 #include <QApplication> 18 #include <vtkRenderer.h> 19 #include <vtkPolyData.h> 36 BaseWidget(parent,
"shape_sensor_widget",
"Shape Sensor"),
38 mVerticalLayout(new QVBoxLayout(this)),
44 mSocketConnection->setConnectionInfo(info);
48 mOptions =
profile()->getXmlSettings().descend(
"shape");
49 QDomElement element = mOptions.
getElement(
"shape");
51 mIpAddress = this->getIPAddress(element);
52 mIpPort = this->getIPPort(element);
53 mShapePointLock = this->getShapePointLock(element);
55 this->setWhatsThis(this->defaultWhatsThis());
64 mTool = mServices->tracking()->getActiveTool();
67 mConnectButton =
new QPushButton(
"Connect",
this);
68 mShowShapeButton =
new QPushButton(
"Hide shape",
this);
69 mSaveShapeButton =
new QPushButton(
"Save mesh snapshot to file",
this);
70 mTestShapeButton =
new QPushButton(
"Create test shape",
this);
72 connect(mConnectButton, &QPushButton::clicked,
this, &ShapeSensorWidget::connectClickedSlot);
73 connect(mShowShapeButton, &QPushButton::clicked,
this, &ShapeSensorWidget::showClickedSlot);
74 connect(mSaveShapeButton, &QPushButton::clicked,
this, &ShapeSensorWidget::saveShapeClickedSlot);
75 connect(mTestShapeButton, &QPushButton::clicked,
this, &ShapeSensorWidget::testShapeClickedSlot);
78 connect(mShapePointLock.get(), &
Property::changed,
this, &ShapeSensorWidget::shapePointLockChangedSlot);
84 mVerticalLayout->addWidget(addressWidget);
85 mVerticalLayout->addWidget(portWidget);
87 mVerticalLayout->addWidget(mConnectButton);
89 mVerticalLayout->addWidget(mShowShapeButton);
90 mVerticalLayout->addWidget(shapePointLockWidget);
91 mVerticalLayout->addWidget(activeToolWidget);
93 mVerticalLayout->addStretch(1);
94 mVerticalLayout->addWidget(mSaveShapeButton);
95 mVerticalLayout->addWidget(mTestShapeButton);
96 mVerticalLayout->addStretch();
98 this->toolChangedSlot();
105 QString ShapeSensorWidget::defaultWhatsThis()
const 108 "<h3>Shape Sensor plugin.</h3>" 109 "<p>Widget for connecting to Fiber Bragg Shape Sensor/p>" 116 QString defaultValue =
"127.0.0.1";
119 retval->setGroup(
"Connection");
129 retval->setAdvanced(
true);
130 retval->setGroup(
"Connection");
138 "Lock a specific point in the shape to the position of the active tool ",
141 retval->setAdvanced(
true);
142 retval->setGroup(
"Connection");
146 void ShapeSensorWidget::shapePointLockChangedSlot()
148 mReadFbgsMessage->setShapePointLock(mShapePointLock->getValue());
151 void ShapeSensorWidget::updateShapePointLockRange()
153 int rangeMax = mReadFbgsMessage->getRangeMax();
156 DoubleRange range = mShapePointLock->getValueRange();
157 if (range.
max() != rangeMax)
159 range.
mMax = rangeMax;
160 mShapePointLock->setValueRange(range);
162 if (mShapePointLock->getValue() > rangeMax)
163 mShapePointLock->setValue(rangeMax);
171 mConnectButton->setText(
"Disconnect");
175 mConnectButton->setText(
"Connect");
179 void ShapeSensorWidget::connectClickedSlot()
183 info.
port = mIpPort->getValue();
184 info.
host = mIpAddress->getValue();
185 mSocketConnection->setConnectionInfo(info);
188 mSocketConnection->requestConnect();
190 mSocketConnection->requestDisconnect();
196 void ShapeSensorWidget::showClickedSlot()
200 mShowShapeButton->setText(
"Show shape");
202 mShowShapeButton->setText(
"Hide shape");
203 mShowShape = !mShowShape;
207 void ShapeSensorWidget::showShape()
210 mServices->view()->get3DView()->getRenderer()->AddActor(mReadFbgsMessage->getActor());
212 mServices->view()->get3DView()->getRenderer()->RemoveActor(mReadFbgsMessage->getActor());
215 void ShapeSensorWidget::testShapeClickedSlot()
223 for(
int i = 1; i < 100; ++i)
225 xAxis->push_back(i+std::rand()/((RAND_MAX + 1u)/3));
226 yAxis->push_back(i+std::rand()/((RAND_MAX + 1u)/3));
227 zAxis->push_back(i+std::rand()/((RAND_MAX + 1u)/3));
229 mReadFbgsMessage->createPolyData();
232 void ShapeSensorWidget::saveShapeClickedSlot()
234 mReadFbgsMessage->saveMeshSnapshot();
237 void ShapeSensorWidget::dataAvailableSlot()
242 void ShapeSensorWidget::processData()
248 qApp->processEvents();
250 bool bufferUpdated = this->readBuffer();
254 mReadFbgsMessage->readBuffer(mBuffer);
255 this->updateShapePointLockRange();
258 bool ShapeSensorWidget::readBuffer()
260 bool ok = this->readMessageLenght();
264 bool bufferUpdated =
false;
273 char *charBuffer = (
char*)malloc(mDataLenght);
274 ok = mSocketConnection->socketReceive(charBuffer, mDataLenght);
277 bufferUpdated =
true;
279 mBuffer = QString(charBuffer);
280 ok = this->readMessageLenght();
288 return bufferUpdated;
291 bool ShapeSensorWidget::readMessageLenght()
296 unsigned char charSize[4];
297 ok = mSocketConnection->socketReceive(&charSize, 4);
303 mDataLenght = int( ( (
unsigned char)(charSize[0]) << 24 )
304 | ( (
unsigned char)(charSize[1]) << 16 )
305 | ( (
unsigned char)(charSize[2]) << 8 )
306 | ( (
unsigned char)(charSize[3]) ) );
311 void ShapeSensorWidget::toolChangedSlot()
319 mTool = mServices->tracking()->getTool(mSelector->getValue());
323 void ShapeSensorWidget::receiveTransforms(
Transform3D prMt,
double timestamp)
325 mReadFbgsMessage->set_prMt(prMt);
CX_SOCKETCONNECTION_STATE
cxResource_EXPORT ProfilePtr profile()
double max() const
maximum value
boost::shared_ptr< class VisServices > VisServicesPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Utility class for describing a bounded numeric range.
void stateChanged(CX_SOCKETCONNECTION_STATE status)
QDomElement getElement()
return the current element
boost::shared_ptr< class StringProperty > StringPropertyPtr
boost::shared_ptr< class StringPropertyBase > StringPropertyBasePtr
boost::shared_ptr< class DoublePropertyBase > DoublePropertyBasePtr
void changed()
emit when the underlying data value is changed: The user interface will be updated.
static StringPropertyPtr initialize(const QString &uid, QString name, QString help, QString value, QStringList range, QDomNode root=QDomNode())
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
boost::shared_ptr< class DoubleProperty > DoublePropertyPtr
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
Helper class for xml files used to store ssc/cx data.
Namespace for all CustusX production code.