16 #include <vtkRenderer.h>
17 #include <vtkActor2D.h>
18 #include <vtkTextProperty.h>
19 #include <vtkPolyDataMapper.h>
20 #include <vtkPolyData.h>
21 #include <vtkMatrix4x4.h>
22 #include <vtkProperty2D.h>
37 mSpaceProvider(spaceProvider),
39 mBB_vp(0, 1, 0, 1, 0, 1),
40 mTooltipPointColor(0.96, 0.87, 0.17),
41 mOffsetPointColor(0.96, 0.87, 0.17),
43 mTooltipLineColor(0.25, 0.87, 0.16),
44 mOffsetLineColor(1.0, 0.8, 0.0),
45 mStipplePattern(0xffff)
47 mTooltipLineColor =
settings()->
value(
"View2D/toolColor").value<QColor>();
48 mTooltipPointColor =
settings()->
value(
"View/toolTipPointColor").value<QColor>();
49 mOffsetPointColor =
settings()->
value(
"View/toolOffsetPointColor").value<QColor>();
50 mOffsetLineColor =
settings()->
value(
"View/toolOffsetLineColor").value<QColor>();
53 mUseCrosshair =
false;
55 mUseOffsetText =
false;
56 mMergeOffsetAndToolLine =
false;
57 mProbeSector.reset(
new ProbeSector());
58 mProbeSectorPolyDataMapper = vtkPolyDataMapperPtr::New();
59 mProbeSectorActor = vtkActorPtr::New();
73 return "vm::ToolRep2D";
76 double ToolRep2D::getOffset()
79 return mSlicer->getTool()->getTooltipOffset();
104 disconnect(mSlicer.get(), SIGNAL(transformChanged(
Transform3D)),
this, SLOT(sliceTransformChangedSlot(
Transform3D)));
105 disconnect(mSlicer.get(), SIGNAL(toolTransformAndTimestamp(
Transform3D,
double)),
this, SLOT(toolTransformAndTimestampSlot(
Transform3D,
double)));
106 disconnect(mSlicer.get(), SIGNAL(toolVisible(
bool)),
this, SLOT(toolVisibleSlot(
bool)));
111 connect(mSlicer.get(), SIGNAL(transformChanged(
Transform3D)),
this, SLOT(sliceTransformChangedSlot(
Transform3D)));
112 connect(mSlicer.get(), SIGNAL(toolTransformAndTimestamp(
Transform3D,
double)),
this, SLOT(toolTransformAndTimestampSlot(
Transform3D,
double)));
113 connect(mSlicer.get(), SIGNAL(toolVisible(
bool)),
this, SLOT(toolVisibleSlot(
bool)));
120 if (mUseCrosshair==on)
158 createCrossHair(view->getRenderer() );
159 createToolLine(view->getRenderer(),
Vector3D(0,0,0));
160 createOffsetText(view->getRenderer(),
Vector3D(0,0,0));
161 view->getRenderer()->AddActor(mProbeSectorActor);
173 distanceText.reset();
174 view->getRenderer()->RemoveActor(mProbeSectorActor);
177 void ToolRep2D::sliceTransformChangedSlot(
Transform3D sMr)
182 void ToolRep2D::toolTransformAndTimestampSlot(
Transform3D prMt,
double timestamp)
187 void ToolRep2D::toolVisibleSlot(
bool visible)
198 void ToolRep2D::update()
200 if (!mSlicer->getTool())
204 if (mSlicer->getTool())
206 prMt = mSlicer->getTool()->get_prMt();
215 bool aligned =
similar(fabs(dotted), 1.0, 0.1);
220 mProbeSector->setData(mSlicer->getTool()->getProbe()->getProbeDefinition());
222 mProbeSectorPolyDataMapper->SetInputData(mProbeSector->getSectorLinesOnly());
223 if (mProbeSectorPolyDataMapper->GetInput())
225 mProbeSectorActor->SetMapper(mProbeSectorPolyDataMapper);
227 mProbeSectorActor->SetUserMatrix((T*sMt*tMu).
getVtkMatrix());
228 mProbeSectorActor->SetVisibility(mSlicer->getTool()->getVisible());
232 mProbeSectorActor->SetVisibility(
false);
241 cursor->update(
cross, mBB_vp);
244 updateToolLine(
cross, tooltip, toolback);
253 return mSlicer->getTool() && mUseOffset;
256 void ToolRep2D::setVisibility()
259 bool hasTool = mSlicer->getTool() ? true :
false;
262 cursor->getActor()->SetVisibility(mUseCrosshair && hasTool);
264 center2Tool->getActor()->SetVisibility(
showOffset());
266 tool2Back->getActor()->SetVisibility(mUseToolLine && hasTool);
268 centerPoint->getActor()->SetVisibility(mUseToolLine && hasTool);
270 centerPoint->getActor()->SetVisibility(
showOffset() && !mMergeOffsetAndToolLine);
272 distanceText->getActor()->SetVisibility(mUseOffsetText &&
showOffset() && !mMergeOffsetAndToolLine);
281 cursor.reset(
new CrossHair2D(renderer) ) ;
288 void ToolRep2D::crossHairResized()
292 double bordarOffset = 30.0;
293 QColor col =
settings()->
value(
"View2D/toolCrossHairColor").value<QColor>();
294 RGBColor color(col.redF(), col.greenF(), col.blueF());
297 cursor->setValue( focalPoint,
int(mBB_vp.
range()[0]),
int(mBB_vp.
range()[1]), bordarOffset, color );
306 center2Tool.reset(
new LineSegment(renderer));
307 center2Tool->setPoints(centerPos,
Vector3D(0.0, 0.0, 0.0), mOffsetLineColor, mStipplePattern);
308 center2Tool->setWidth(2);
311 tool2Back.reset(
new LineSegment(renderer));
312 tool2Back->setPoints(
Vector3D(0.0, 0.0, 0.0),
Vector3D(0.0, 0.0, 0.0), mTooltipLineColor);
313 tool2Back->setWidth(2);
316 centerPoint.reset(
new OffsetPoint(renderer));
317 centerPoint->setValue(centerPos, mOffsetPointColor);
318 centerPoint->setRadius(4);
319 centerPoint->getActor()->VisibilityOff();
322 toolPoint.reset(
new OffsetPoint(renderer));
323 toolPoint->setValue(
Vector3D(0.0, 0.0, 0.0), mTooltipPointColor);
324 toolPoint->setRadius(3);
331 QColor color = QColor::fromRgbF(0.7372, 0.815, 0.6039);
332 distanceText.reset(
new TextDisplay(
"---", color, 18) );
333 distanceText->getActor()->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
334 distanceText->textProperty()->SetJustificationToRight();
335 distanceText->setPosition(
Vector3D(0.95, 0.95, 0.0));
336 renderer->AddActor( distanceText->getActor() );
346 if (!center2Tool || !tool2Back || !centerPoint || !toolPoint)
349 if (mMergeOffsetAndToolLine)
353 center2Tool->getActor()->SetVisibility(
false);
354 tool2Back->updatePosition(crossPos, toolTipBackPos);
355 if (getOffset() > 0.01)
357 toolPoint->getActor()->SetVisibility(
false);
358 centerPoint->getActor()->SetVisibility(
true);
359 tool2Back->setColor(mOffsetLineColor);
360 tool2Back->setPattern(mStipplePattern);
364 toolPoint->getActor()->SetVisibility(
true);
365 centerPoint->getActor()->SetVisibility(
false);
366 tool2Back->setColor(mTooltipLineColor);
367 tool2Back->setPattern(0xffff);
372 center2Tool->updatePosition(crossPos, toolTipPos);
373 tool2Back->updatePosition(toolTipPos, toolTipBackPos);
374 if (getOffset() > 0.01)
376 centerPoint->getActor()->SetVisibility(
true);
380 centerPoint->getActor()->SetVisibility(
false);
383 centerPoint->update(crossPos);
384 toolPoint->update(toolTipPos);
387 void ToolRep2D::updateOffsetText()
393 if (getOffset() > 2.0 && mUseOffsetText &&
showOffset())
395 distanceText->updateText(
"Offset: " + QString::number(getOffset(),
'g', 3) +
" mm");
396 distanceText->getActor()->VisibilityOn();
400 distanceText->getActor()->VisibilityOff();
401 distanceText->updateText(
"" );