37 #include <vtkRenderer.h>
38 #include <vtkActor2D.h>
39 #include <vtkTextProperty.h>
40 #include <vtkPolyDataMapper.h>
41 #include <vtkPolyData.h>
42 #include <vtkMatrix4x4.h>
57 mSpaceProvider(spaceProvider),
59 mBB_vp(0, 1, 0, 1, 0, 1),
60 mTooltipPointColor(0.96, 0.87, 0.17),
61 mOffsetPointColor(0.96, 0.87, 0.17),
63 mTooltipLineColor(0.25, 0.87, 0.16),
64 mOffsetLineColor(1.0, 0.8, 0.0),
65 mStipplePattern(0xffff)
67 mTooltipLineColor =
settings()->
value(
"View/tool2DColor").value<QColor>();
68 mTooltipPointColor =
settings()->
value(
"View/toolTipPointColor").value<QColor>();
69 mOffsetPointColor =
settings()->
value(
"View/toolOffsetPointColor").value<QColor>();
70 mOffsetLineColor =
settings()->
value(
"View/toolOffsetLineColor").value<QColor>();
73 mUseCrosshair =
false;
75 mUseOffsetText =
false;
76 mMergeOffsetAndToolLine =
false;
77 mProbeSector.reset(
new ProbeSector());
78 mProbeSectorPolyDataMapper = vtkPolyDataMapperPtr::New();
79 mProbeSectorActor = vtkActorPtr::New();
93 return "vm::ToolRep2D";
96 double ToolRep2D::getOffset()
99 return mSlicer->getTool()->getTooltipOffset();
124 disconnect(mSlicer.get(), SIGNAL(transformChanged(
Transform3D)),
this, SLOT(sliceTransformChangedSlot(
Transform3D)));
125 disconnect(mSlicer.get(), SIGNAL(toolTransformAndTimestamp(
Transform3D,
double)),
this, SLOT(toolTransformAndTimestampSlot(
Transform3D,
double)));
126 disconnect(mSlicer.get(), SIGNAL(toolVisible(
bool)),
this, SLOT(toolVisibleSlot(
bool)));
131 connect(mSlicer.get(), SIGNAL(transformChanged(
Transform3D)),
this, SLOT(sliceTransformChangedSlot(
Transform3D)));
132 connect(mSlicer.get(), SIGNAL(toolTransformAndTimestamp(
Transform3D,
double)),
this, SLOT(toolTransformAndTimestampSlot(
Transform3D,
double)));
133 connect(mSlicer.get(), SIGNAL(toolVisible(
bool)),
this, SLOT(toolVisibleSlot(
bool)));
150 if (mUseCrosshair==on)
160 if (mUseToolLine==on)
170 if (mUseOffsetText==on)
182 if (mMergeOffsetAndToolLine==on)
184 mMergeOffsetAndToolLine = on;
190 createToolLine(view->getRenderer(),
Vector3D(0,0,0));
191 createCrossHair(view->getRenderer() );
192 createOffsetText(view->getRenderer(),
Vector3D(0,0,0));
193 view->getRenderer()->AddActor(mProbeSectorActor);
205 distanceText.reset();
206 view->getRenderer()->RemoveActor(mProbeSectorActor);
209 void ToolRep2D::sliceTransformChangedSlot(
Transform3D sMr)
214 void ToolRep2D::toolTransformAndTimestampSlot(
Transform3D prMt,
double timestamp)
219 void ToolRep2D::toolVisibleSlot(
bool visible)
230 void ToolRep2D::update()
232 if (!mSlicer->getTool())
236 if (mSlicer->getTool())
238 prMt = mSlicer->getTool()->get_prMt();
247 bool aligned =
similar(fabs(dotted), 1.0, 0.1);
252 mProbeSector->setData(mSlicer->getTool()->getProbe()->getProbeDefinition());
254 mProbeSectorPolyDataMapper->SetInputData(mProbeSector->getSectorLinesOnly());
255 if (mProbeSectorPolyDataMapper->GetInput())
257 mProbeSectorActor->SetMapper(mProbeSectorPolyDataMapper);
259 mProbeSectorActor->SetUserMatrix((T*sMt*tMu).
getVtkMatrix());
260 mProbeSectorActor->SetVisibility(mSlicer->getTool()->getVisible());
264 mProbeSectorActor->SetVisibility(
false);
273 cursor->update(cross, mBB_vp);
276 updateToolLine(cross, tooltip, toolback);
285 return mSlicer->getTool() && mUseOffset;
288 void ToolRep2D::setVisibility()
291 bool hasTool = mSlicer->getTool() ?
true :
false;
294 cursor->getActor()->SetVisibility(mUseCrosshair && hasTool);
296 center2Tool->getActor()->SetVisibility(
showOffset());
298 tool2Back->getActor()->SetVisibility(mUseToolLine && hasTool);
300 centerPoint->getActor()->SetVisibility(mUseToolLine && hasTool);
302 centerPoint->getActor()->SetVisibility(
showOffset() && !mMergeOffsetAndToolLine);
304 distanceText->getActor()->SetVisibility(mUseOffsetText &&
showOffset() && !mMergeOffsetAndToolLine);
313 cursor.reset(
new CrossHair2D(renderer) ) ;
320 void ToolRep2D::crossHairResized()
324 double bordarOffset = 30.0;
325 QColor col =
settings()->
value(
"View/toolCrossHairColor").value<QColor>();
327 RGBColor color(col.redF(), col.greenF(), col.blueF());
332 cursor->setValue( focalPoint,
int(mBB_vp.
range()[0]),
int(mBB_vp.
range()[1]), bordarOffset, color );
341 center2Tool.reset(
new LineSegment(renderer));
342 center2Tool->setPoints(centerPos,
Vector3D(0.0, 0.0, 0.0), mOffsetLineColor, mStipplePattern);
343 center2Tool->setWidth(2);
346 tool2Back.reset(
new LineSegment(renderer));
347 tool2Back->setPoints(
Vector3D(0.0, 0.0, 0.0),
Vector3D(0.0, 0.0, 0.0), mTooltipLineColor);
348 tool2Back->setWidth(2);
351 centerPoint.reset(
new OffsetPoint(renderer));
352 centerPoint->setValue(centerPos, mOffsetPointColor);
353 centerPoint->setRadius(4);
354 centerPoint->getActor()->VisibilityOff();
357 toolPoint.reset(
new OffsetPoint(renderer));
358 toolPoint->setValue(
Vector3D(0.0, 0.0, 0.0), mTooltipPointColor);
359 toolPoint->setRadius(3);
366 QColor color = QColor::fromRgbF(0.7372, 0.815, 0.6039);
367 distanceText.reset(
new TextDisplay(
"---", color, 18) );
368 distanceText->getActor()->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
369 distanceText->textProperty()->SetJustificationToRight();
370 distanceText->setPosition(
Vector3D(0.95, 0.95, 0.0));
371 renderer->AddActor( distanceText->getActor() );
381 if (!center2Tool || !tool2Back || !centerPoint || !toolPoint)
384 if (mMergeOffsetAndToolLine)
388 center2Tool->getActor()->SetVisibility(
false);
389 tool2Back->updatePosition(crossPos, toolTipBackPos);
390 if (getOffset() > 0.01)
392 toolPoint->getActor()->SetVisibility(
false);
393 centerPoint->getActor()->SetVisibility(
true);
394 tool2Back->setColor(mOffsetLineColor);
395 tool2Back->setPattern(mStipplePattern);
399 toolPoint->getActor()->SetVisibility(
true);
400 centerPoint->getActor()->SetVisibility(
false);
401 tool2Back->setColor(mTooltipLineColor);
402 tool2Back->setPattern(0xffff);
407 center2Tool->updatePosition(crossPos, toolTipPos);
408 tool2Back->updatePosition(toolTipPos, toolTipBackPos);
409 if (getOffset() > 0.01)
411 centerPoint->getActor()->SetVisibility(
true);
415 centerPoint->getActor()->SetVisibility(
false);
418 centerPoint->update(crossPos);
419 toolPoint->update(toolTipPos);
422 void ToolRep2D::updateOffsetText()
428 if (getOffset() > 2.0 && mUseOffsetText &&
showOffset())
430 distanceText->updateText(
"Offset: " + QString::number(getOffset(),
'g', 3) +
" mm");
431 distanceText->getActor()->VisibilityOn();
435 distanceText->getActor()->VisibilityOff();
436 distanceText->updateText(
"" );
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 View > ViewPtr
boost::shared_ptr< class ToolRep2D > ToolRep2DPtr
Vector3D cross(const Vector3D &a, const Vector3D &b)
compute cross product of a and b.
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
Transform3D createTransformTranslate(const Vector3D &translation)
double dot(const Vector3D &a, const Vector3D &b)
compute inner product (or dot product) of a and b.
Settings * settings()
Shortcut for accessing the settings instance.
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)