37 #include <vtkRenderer.h> 38 #include <vtkActor2D.h> 39 #include <vtkTextProperty.h> 40 #include <vtkPolyDataMapper.h> 41 #include <vtkPolyData.h> 42 #include <vtkMatrix4x4.h> 43 #include <vtkProperty2D.h> 58 mSpaceProvider(spaceProvider),
60 mBB_vp(0, 1, 0, 1, 0, 1),
61 mTooltipPointColor(0.96, 0.87, 0.17),
62 mOffsetPointColor(0.96, 0.87, 0.17),
64 mTooltipLineColor(0.25, 0.87, 0.16),
65 mOffsetLineColor(1.0, 0.8, 0.0),
66 mStipplePattern(0xffff)
68 mTooltipLineColor =
settings()->
value(
"View2D/toolColor").value<QColor>();
69 mTooltipPointColor =
settings()->
value(
"View/toolTipPointColor").value<QColor>();
70 mOffsetPointColor =
settings()->
value(
"View/toolOffsetPointColor").value<QColor>();
71 mOffsetLineColor =
settings()->
value(
"View/toolOffsetLineColor").value<QColor>();
74 mUseCrosshair =
false;
76 mUseOffsetText =
false;
77 mMergeOffsetAndToolLine =
false;
78 mProbeSector.reset(
new ProbeSector());
79 mProbeSectorPolyDataMapper = vtkPolyDataMapperPtr::New();
80 mProbeSectorActor = vtkActorPtr::New();
94 return "vm::ToolRep2D";
97 double ToolRep2D::getOffset()
99 if (mSlicer->getTool() && showOffset())
100 return mSlicer->getTool()->getTooltipOffset();
125 disconnect(mSlicer.get(), SIGNAL(transformChanged(
Transform3D)),
this, SLOT(sliceTransformChangedSlot(
Transform3D)));
126 disconnect(mSlicer.get(), SIGNAL(toolTransformAndTimestamp(
Transform3D,
double)),
this, SLOT(toolTransformAndTimestampSlot(
Transform3D,
double)));
127 disconnect(mSlicer.get(), SIGNAL(toolVisible(
bool)),
this, SLOT(toolVisibleSlot(
bool)));
132 connect(mSlicer.get(), SIGNAL(transformChanged(
Transform3D)),
this, SLOT(sliceTransformChangedSlot(
Transform3D)));
133 connect(mSlicer.get(), SIGNAL(toolTransformAndTimestamp(
Transform3D,
double)),
this, SLOT(toolTransformAndTimestampSlot(
Transform3D,
double)));
134 connect(mSlicer.get(), SIGNAL(toolVisible(
bool)),
this, SLOT(toolVisibleSlot(
bool)));
141 if (mUseCrosshair==on)
179 createCrossHair(view->getRenderer() );
180 createToolLine(view->getRenderer(),
Vector3D(0,0,0));
181 createOffsetText(view->getRenderer(),
Vector3D(0,0,0));
182 view->getRenderer()->AddActor(mProbeSectorActor);
194 distanceText.reset();
195 view->getRenderer()->RemoveActor(mProbeSectorActor);
198 void ToolRep2D::sliceTransformChangedSlot(
Transform3D sMr)
203 void ToolRep2D::toolTransformAndTimestampSlot(
Transform3D prMt,
double timestamp)
208 void ToolRep2D::toolVisibleSlot(
bool visible)
219 void ToolRep2D::update()
221 if (!mSlicer->getTool())
225 if (mSlicer->getTool())
227 prMt = mSlicer->getTool()->get_prMt();
236 bool aligned =
similar(fabs(dotted), 1.0, 0.1);
237 if (this->showProbe() && aligned)
241 mProbeSector->setData(mSlicer->getTool()->getProbe()->getProbeDefinition());
243 mProbeSectorPolyDataMapper->SetInputData(mProbeSector->getSectorLinesOnly());
244 if (mProbeSectorPolyDataMapper->GetInput())
246 mProbeSectorActor->SetMapper(mProbeSectorPolyDataMapper);
248 mProbeSectorActor->SetUserMatrix((T*sMt*tMu).
getVtkMatrix());
249 mProbeSectorActor->SetVisibility(mSlicer->getTool()->getVisible());
253 mProbeSectorActor->SetVisibility(
false);
262 cursor->update(cross, mBB_vp);
265 updateToolLine(cross, tooltip, toolback);
274 return mSlicer->getTool() && mUseOffset;
277 void ToolRep2D::setVisibility()
280 bool hasTool = mSlicer->getTool() ?
true :
false;
283 cursor->getActor()->SetVisibility(mUseCrosshair && hasTool);
285 center2Tool->getActor()->SetVisibility(showOffset());
287 tool2Back->getActor()->SetVisibility(mUseToolLine && hasTool);
289 centerPoint->getActor()->SetVisibility(mUseToolLine && hasTool);
291 centerPoint->getActor()->SetVisibility(showOffset() && !mMergeOffsetAndToolLine);
293 distanceText->getActor()->SetVisibility(mUseOffsetText && showOffset() && !mMergeOffsetAndToolLine);
309 void ToolRep2D::crossHairResized()
313 double bordarOffset = 30.0;
314 QColor col =
settings()->
value(
"View2D/toolCrossHairColor").value<QColor>();
315 RGBColor color(col.redF(), col.greenF(), col.blueF());
318 cursor->setValue( focalPoint,
int(mBB_vp.range()[0]),
int(mBB_vp.range()[1]), bordarOffset, color );
328 center2Tool->setPoints(centerPos,
Vector3D(0.0, 0.0, 0.0), mOffsetLineColor, mStipplePattern);
329 center2Tool->setWidth(2);
333 tool2Back->setPoints(
Vector3D(0.0, 0.0, 0.0),
Vector3D(0.0, 0.0, 0.0), mTooltipLineColor);
334 tool2Back->setWidth(2);
338 centerPoint->setValue(centerPos, mOffsetPointColor);
339 centerPoint->setRadius(4);
340 centerPoint->getActor()->VisibilityOff();
344 toolPoint->setValue(
Vector3D(0.0, 0.0, 0.0), mTooltipPointColor);
345 toolPoint->setRadius(3);
352 QColor color = QColor::fromRgbF(0.7372, 0.815, 0.6039);
353 distanceText.reset(
new TextDisplay(
"---", color, 18) );
354 distanceText->getActor()->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
355 distanceText->textProperty()->SetJustificationToRight();
356 distanceText->setPosition(
Vector3D(0.95, 0.95, 0.0));
357 renderer->AddActor( distanceText->getActor() );
367 if (!center2Tool || !tool2Back || !centerPoint || !toolPoint)
370 if (mMergeOffsetAndToolLine)
374 center2Tool->getActor()->SetVisibility(
false);
375 tool2Back->updatePosition(crossPos, toolTipBackPos);
376 if (getOffset() > 0.01)
378 toolPoint->getActor()->SetVisibility(
false);
379 centerPoint->getActor()->SetVisibility(
true);
380 tool2Back->setColor(mOffsetLineColor);
381 tool2Back->setPattern(mStipplePattern);
385 toolPoint->getActor()->SetVisibility(
true);
386 centerPoint->getActor()->SetVisibility(
false);
387 tool2Back->setColor(mTooltipLineColor);
388 tool2Back->setPattern(0xffff);
393 center2Tool->updatePosition(crossPos, toolTipPos);
394 tool2Back->updatePosition(toolTipPos, toolTipBackPos);
395 if (getOffset() > 0.01)
397 centerPoint->getActor()->SetVisibility(
true);
401 centerPoint->getActor()->SetVisibility(
false);
404 centerPoint->update(crossPos);
405 toolPoint->update(toolTipPos);
408 void ToolRep2D::updateOffsetText()
414 if (getOffset() > 2.0 && mUseOffsetText && showOffset())
416 distanceText->updateText(
"Offset: " + QString::number(getOffset(),
'g', 3) +
" mm");
417 distanceText->getActor()->VisibilityOn();
421 distanceText->getActor()->VisibilityOff();
422 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
Helper for drawing a point in 2D.
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
Helper for drawing a line in 2D.
Helper for drawing text in 2D.
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.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
Helper for drawing a crosshair in 2D.
void setColorAndOpacity(vtkPropertyOrProperty2DPtr property, QColor color)
Namespace for all CustusX production code.