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>();
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())
262 double size = mViewportListener->getVpnZoom(this->
getTool()->get_prMt().translation());
263 double sphereSize = mSphereRadius/100/size;
266 mOffsetPoint->setRadius(sphereSize);
268 mTooltipPoint->setRadius(sphereSize);
277 void ToolRep3D::update()
281 prMt = mTool->get_prMt();
285 mToolActor->SetUserMatrix(rMt.getVtkMatrix());
290 mProbeSectorActor->SetUserMatrix((rMpr * prMt * tMu).
getVtkMatrix());
291 mProbeSectorActor->SetVisibility(mTool->getVisible());
294 mProbeSectorActor->SetVisibility(
false);
296 this->updateOffsetGraphics();
299 void ToolRep3D::probeSectorChanged()
309 mProbeSector->setData(mTool->getProbe()->getProbeDefinition());
312 mProbeSectorPolyDataMapper->SetInputData(mProbeSector->getSectorLinesOnly());
313 if (mProbeSectorPolyDataMapper->GetInput())
315 mProbeSectorActor->SetMapper(mProbeSectorPolyDataMapper);
317 mProbeSectorActor->SetUserMatrix((rMpr * prMt * tMu).
getVtkMatrix());
318 mProbeSectorActor->SetVisibility(mTool->getVisible());
321 mProbeSectorActor->SetVisibility(
false);
324 void ToolRep3D::updateOffsetGraphics()
326 bool visible = mTool && mTool->getVisible();
328 if (!mStayVisibleAfterHide || (mOffsetPoint->getActor()->GetVisibility() ==
false))
330 mOffsetPoint->getActor()->SetVisibility(visible);
331 mTooltipPoint->getActor()->SetVisibility(visible);
333 if (mStayHiddenAfterVisible)
334 mTooltipPoint->getActor()->SetVisibility(
false);
335 mOffsetLine->getActor()->SetVisibility(visible);
338 if (
similar(0.0, mTool->getTooltipOffset()))
341 mTooltipPoint->getActor()->SetVisibility(
false);
343 mTooltipPoint->getActor()->SetVisibility(visible && mOffsetPointVisibleAtZeroOffset);
344 mOffsetPoint->getActor()->SetVisibility(
false);
345 mOffsetLine->getActor()->SetVisibility(
false);
355 mOffsetPoint->setValue(p1);
356 mOffsetLine->setValue(p0, p1);
357 mTooltipPoint->setValue(
Vector3D(p0));
359 this->scaleSpheres();
362 void ToolRep3D::receiveVisible(
bool visible)
364 if (!visible && mStayVisibleAfterHide)
366 mToolActor->SetVisibility(visible);
368 if (mStayHiddenAfterVisible)
369 mToolActor->SetVisibility(
false);
371 mToolActor->SetVisibility(mTool->getVisible());
378 mStayHiddenAfterVisible = val;
380 receiveVisible(mTool->getVisible());
389 mStayVisibleAfterHide = val;
394 mOffsetPointVisibleAtZeroOffset = val;
397 void ToolRep3D::tooltipOffsetSlot(
double val)
399 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