15 #include "boost/bind.hpp" 17 #include <vtkProperty.h> 18 #include <vtkPolyDataMapper.h> 19 #include <vtkPolyDataNormals.h> 20 #include <vtkSTLReader.h> 21 #include <vtkMatrix4x4.h> 22 #include <vtkRenderer.h> 39 mSpaceProvider(spaceProvider),
40 mSphereRadiusInNormalizedViewport(false),
41 mStipplePattern(0xFFFF)
43 mTooltipPointColor =
settings()->
value(
"View/toolTipPointColor").value<QColor>();
44 mOffsetPointColor =
settings()->
value(
"View/toolOffsetPointColor").value<QColor>();
45 mOffsetLineColor =
settings()->
value(
"View/toolOffsetLineColor").value<QColor>();
47 mSphereRadius =
settings()->
value(
"View3D/sphereRadius").value<
double>();
48 mStayHiddenAfterVisible =
false;
49 mStayVisibleAfterHide =
false;
50 mOffsetPointVisibleAtZeroOffset =
false;
51 mToolActor = vtkActorPtr::New();
52 mPolyDataMapper = vtkPolyDataMapperPtr::New();
60 mProbeSectorPolyDataMapper = vtkPolyDataMapperPtr::New();
61 mProbeSectorActor = vtkActorPtr::New();
89 void ToolRep3D::updateToolActor()
93 mToolActor->SetMapper(NULL);
102 normals->SetInputData(model);
103 mPolyDataMapper->SetInputConnection(normals->GetOutputPort());
104 mPolyDataMapper->Update();
105 mToolActor->SetMapper(mPolyDataMapper);
109 mToolActor->GetProperty()->SetColor(1.0, 1.0, 1.0);
116 mToolActor->SetVisibility(mTool->getVisible());
124 mTracer->setTool(tool);
128 disconnect(mTool.get(), SIGNAL(toolTransformAndTimestamp(
Transform3D,
double)),
this, SLOT(
setModified()));
129 disconnect(mTool.get(), SIGNAL(toolVisible(
bool)),
this, SLOT(receiveVisible(
bool)));
130 disconnect(mTool.get(), SIGNAL(tooltipOffset(
double)),
this, SLOT(tooltipOffsetSlot(
double)));
131 disconnect(mTool.get(), SIGNAL(toolProbeSector()),
this, SLOT(probeSectorChanged()));
132 disconnect(mTool.get(), SIGNAL(toolProbeSector()),
this, SLOT(updateToolActor()));
140 connect(mTool.get(), SIGNAL(toolVisible(
bool)),
this, SLOT(receiveVisible(
bool)));
141 connect(mTool.get(), SIGNAL(tooltipOffset(
double)),
this, SLOT(tooltipOffsetSlot(
double)));
142 connect(mTool.get(), SIGNAL(toolProbeSector()),
this, SLOT(probeSectorChanged()));
143 connect(mTool.get(), SIGNAL(toolProbeSector()),
this, SLOT(updateToolActor()));
146 this->updateToolActor();
148 this->probeSectorChanged();
153 return (mTool == tool);
158 mSphereRadius = radius;
160 mOffsetPoint->setRadius(mSphereRadius);
162 mTooltipPoint->setRadius(mSphereRadius);
167 if (mSphereRadiusInNormalizedViewport == on)
170 mSphereRadiusInNormalizedViewport = on;
175 mViewportListener->setCallback(boost::bind(&ToolRep3D::scaleSpheres,
this));
179 mViewportListener.reset();
193 mTooltipPoint->setColor(color);
199 mOffsetPoint->setColor(color);
205 mOffsetLine->setColor(color);
210 view->getRenderer()->AddActor(mTracer->getActor());
212 view->getRenderer()->AddActor(mToolActor);
213 view->getRenderer()->AddActor(mProbeSectorActor);
216 mOffsetPoint->setRadius(mSphereRadius);
217 mOffsetPoint->setColor(mOffsetPointColor);
220 mTooltipPoint->setRadius(mSphereRadius);
221 mTooltipPoint->setColor(mTooltipPointColor);
224 mOffsetLine->setColor(mOffsetLineColor);
225 mOffsetLine->setStipple(mStipplePattern);
227 mTooltipPoint->getActor()->SetVisibility(
false);
228 mOffsetPoint->getActor()->SetVisibility(
false);
229 mOffsetLine->getActor()->SetVisibility(
false);
231 if (mViewportListener)
232 mViewportListener->startListen(view->getRenderer());
237 view->getRenderer()->RemoveActor(mTracer->getActor());
238 view->getRenderer()->RemoveActor(mToolActor);
239 view->getRenderer()->RemoveActor(mProbeSectorActor);
245 if (mViewportListener)
246 mViewportListener->stopListen();
255 void ToolRep3D::scaleSpheres()
257 if (!mViewportListener)
259 if (!mViewportListener->isListening())
263 double size = mViewportListener->getVpnZoom();
264 double sphereSize = mSphereRadius/100/size;
267 mOffsetPoint->setRadius(sphereSize);
269 mTooltipPoint->setRadius(sphereSize);
278 void ToolRep3D::update()
282 prMt = mTool->get_prMt();
286 mToolActor->SetUserMatrix(rMt.getVtkMatrix());
291 mProbeSectorActor->SetUserMatrix((rMpr * prMt * tMu).
getVtkMatrix());
292 mProbeSectorActor->SetVisibility(mTool->getVisible());
295 mProbeSectorActor->SetVisibility(
false);
297 this->updateOffsetGraphics();
300 void ToolRep3D::probeSectorChanged()
310 mProbeSector->setData(mTool->getProbe()->getProbeDefinition());
313 mProbeSectorPolyDataMapper->SetInputData(mProbeSector->getSectorLinesOnly());
314 if (mProbeSectorPolyDataMapper->GetInput())
316 mProbeSectorActor->SetMapper(mProbeSectorPolyDataMapper);
318 mProbeSectorActor->SetUserMatrix((rMpr * prMt * tMu).
getVtkMatrix());
319 mProbeSectorActor->SetVisibility(mTool->getVisible());
322 mProbeSectorActor->SetVisibility(
false);
325 void ToolRep3D::updateOffsetGraphics()
327 bool visible = mTool && mTool->getVisible();
329 if (!mStayVisibleAfterHide || (mOffsetPoint->getActor()->GetVisibility() ==
false))
331 mOffsetPoint->getActor()->SetVisibility(visible);
332 mTooltipPoint->getActor()->SetVisibility(visible);
334 if (mStayHiddenAfterVisible)
335 mTooltipPoint->getActor()->SetVisibility(
false);
336 mOffsetLine->getActor()->SetVisibility(visible);
339 if (
similar(0.0, mTool->getTooltipOffset()))
342 mTooltipPoint->getActor()->SetVisibility(
false);
344 mTooltipPoint->getActor()->SetVisibility(visible && mOffsetPointVisibleAtZeroOffset);
345 mOffsetPoint->getActor()->SetVisibility(
false);
346 mOffsetLine->getActor()->SetVisibility(
false);
356 mOffsetPoint->setValue(p1);
357 mOffsetLine->setValue(p0, p1);
358 mTooltipPoint->setValue(
Vector3D(p0));
360 this->scaleSpheres();
363 void ToolRep3D::receiveVisible(
bool visible)
365 if (!visible && mStayVisibleAfterHide)
367 mToolActor->SetVisibility(visible);
369 if (mStayHiddenAfterVisible)
370 mToolActor->SetVisibility(
false);
372 mToolActor->SetVisibility(mTool->getVisible());
379 mStayHiddenAfterVisible = val;
381 receiveVisible(mTool->getVisible());
390 mStayVisibleAfterHide = val;
395 mOffsetPointVisibleAtZeroOffset = val;
398 void ToolRep3D::tooltipOffsetSlot(
double val)
400 updateOffsetGraphics();
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
boost::shared_ptr< class ToolTracer > ToolTracerPtr
Helper for rendering a point in 3D.
boost::shared_ptr< class View > ViewPtr
Listens to changes in viewport and camera matrix.
vtkSmartPointer< class vtkPolyDataNormals > vtkPolyDataNormalsPtr
Helper for rendering a line in 3D.
Default implementation of Rep.
Settings * settings()
Shortcut for accessing the settings instance.
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
Utility functions for drawing an US Probe sector.
boost::shared_ptr< class ToolRep3D > ToolRep3DPtr
void setColorAndOpacity(vtkPropertyOrProperty2DPtr property, QColor color)
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr