37 #include <vtkRenderer.h>
38 #include <vtkActor2D.h>
39 #include <vtkTextProperty.h>
40 #include <vtkPolyDataMapper.h>
41 #include <vtkPolyData.h>
42 #include <vtkMatrix4x4.h>
56 mSpaceProvider(spaceProvider),
58 mBB_vp(0, 1, 0, 1, 0, 1),
59 mTooltipPointColor(0.96, 0.87, 0.17),
60 mOffsetPointColor(0.96, 0.87, 0.17),
61 mTooltipLineColor(0.25, 0.87, 0.16),
62 mOffsetLineColor(1.0, 0.8, 0.0),
63 mStipplePattern(0xffff)
66 mUseCrosshair =
false;
68 mUseOffsetText =
false;
69 mMergeOffsetAndToolLine =
false;
70 mProbeSector.reset(
new ProbeSector());
71 mProbeSectorPolyDataMapper = vtkPolyDataMapperPtr::New();
72 mProbeSectorActor = vtkActorPtr::New();
86 return "vm::ToolRep2D";
89 double ToolRep2D::getOffset()
92 return mSlicer->getTool()->getTooltipOffset();
114 disconnect(mSlicer.get(), SIGNAL(transformChanged(
Transform3D)),
this, SLOT(sliceTransformChangedSlot(
Transform3D)));
115 disconnect(mSlicer.get(), SIGNAL(toolTransformAndTimestamp(
Transform3D,
double)),
this, SLOT(toolTransformAndTimestampSlot(
Transform3D,
double)));
116 disconnect(mSlicer.get(), SIGNAL(toolVisible(
bool)),
this, SLOT(toolVisibleSlot(
bool)));
121 connect(mSlicer.get(), SIGNAL(transformChanged(
Transform3D)),
this, SLOT(sliceTransformChangedSlot(
Transform3D)));
122 connect(mSlicer.get(), SIGNAL(toolTransformAndTimestamp(
Transform3D,
double)),
this, SLOT(toolTransformAndTimestampSlot(
Transform3D,
double)));
123 connect(mSlicer.get(), SIGNAL(toolVisible(
bool)),
this, SLOT(toolVisibleSlot(
bool)));
164 mMergeOffsetAndToolLine = on;
170 createToolLine(view->getRenderer(),
Vector3D(0,0,0));
171 createCrossHair(view->getRenderer() );
172 createOffsetText(view->getRenderer(),
Vector3D(0,0,0));
173 view->getRenderer()->AddActor(mProbeSectorActor);
185 distanceText.reset();
186 view->getRenderer()->RemoveActor(mProbeSectorActor);
189 void ToolRep2D::sliceTransformChangedSlot(
Transform3D sMr)
194 void ToolRep2D::toolTransformAndTimestampSlot(
Transform3D prMt,
double timestamp)
199 void ToolRep2D::toolVisibleSlot(
bool visible)
210 void ToolRep2D::update()
212 if (!mSlicer->getTool())
216 if (mSlicer->getTool())
218 prMt = mSlicer->getTool()->get_prMt();
227 bool aligned =
similar(fabs(dotted), 1.0, 0.1);
232 mProbeSector->setData(mSlicer->getTool()->getProbe()->getProbeDefinition());
234 mProbeSectorPolyDataMapper->SetInputData(mProbeSector->getSectorLinesOnly());
235 if (mProbeSectorPolyDataMapper->GetInput())
237 mProbeSectorActor->SetMapper(mProbeSectorPolyDataMapper);
239 mProbeSectorActor->SetUserMatrix((T*sMt*tMu).
getVtkMatrix());
240 mProbeSectorActor->SetVisibility(mSlicer->getTool()->getVisible());
244 mProbeSectorActor->SetVisibility(
false);
253 cursor->update(cross, mBB_vp);
256 updateToolLine(cross, tooltip, toolback);
265 return mSlicer->getTool() && mUseOffset;
268 void ToolRep2D::setVisibility()
271 bool hasTool = mSlicer->getTool() ?
true :
false;
274 cursor->getActor()->SetVisibility(mUseCrosshair && hasTool);
276 center2Tool->getActor()->SetVisibility(
showOffset());
278 tool2Back->getActor()->SetVisibility(mUseToolLine && hasTool);
280 centerPoint->getActor()->SetVisibility(mUseToolLine && hasTool);
282 centerPoint->getActor()->SetVisibility(
showOffset() && !mMergeOffsetAndToolLine);
284 distanceText->getActor()->SetVisibility(mUseOffsetText &&
showOffset() && !mMergeOffsetAndToolLine);
293 cursor.reset(
new CrossHair2D(renderer) ) ;
300 void ToolRep2D::crossHairResized()
304 double bordarOffset = 30.0;
305 RGBColor color(1.0, 0.8, 0.0);
309 cursor->setValue( focalPoint,
int(mBB_vp.
range()[0]),
int(mBB_vp.
range()[1]), bordarOffset, color );
318 center2Tool.reset(
new LineSegment(renderer));
319 center2Tool->setPoints(centerPos,
Vector3D(0.0, 0.0, 0.0), mOffsetLineColor, mStipplePattern);
320 center2Tool->setWidth(2);
323 tool2Back.reset(
new LineSegment(renderer));
324 tool2Back->setPoints(
Vector3D(0.0, 0.0, 0.0),
Vector3D(0.0, 0.0, 0.0), mTooltipLineColor);
325 tool2Back->setWidth(2);
328 centerPoint.reset(
new OffsetPoint(renderer));
329 centerPoint->setValue(centerPos, mOffsetPointColor);
330 centerPoint->setRadius(4);
331 centerPoint->getActor()->VisibilityOff();
334 toolPoint.reset(
new OffsetPoint(renderer));
335 toolPoint->setValue(
Vector3D(0.0, 0.0, 0.0), mTooltipPointColor);
336 toolPoint->setRadius(3);
343 QColor color = QColor::fromRgbF(0.7372, 0.815, 0.6039);
344 distanceText.reset(
new TextDisplay(
"---", color, 18) );
345 distanceText->getActor()->GetPositionCoordinate()->SetCoordinateSystemToNormalizedViewport();
346 distanceText->textProperty()->SetJustificationToRight();
347 distanceText->setPosition(
Vector3D(0.95, 0.95, 0.0));
348 renderer->AddActor( distanceText->getActor() );
358 if (!center2Tool || !tool2Back || !centerPoint || !toolPoint)
361 if (mMergeOffsetAndToolLine)
365 center2Tool->getActor()->SetVisibility(
false);
366 tool2Back->updatePosition(crossPos, toolTipBackPos);
367 if (getOffset() > 0.01)
369 toolPoint->getActor()->SetVisibility(
false);
370 centerPoint->getActor()->SetVisibility(
true);
371 tool2Back->setColor(mOffsetLineColor);
372 tool2Back->setPattern(mStipplePattern);
376 toolPoint->getActor()->SetVisibility(
true);
377 centerPoint->getActor()->SetVisibility(
false);
378 tool2Back->setColor(mTooltipLineColor);
379 tool2Back->setPattern(0xffff);
384 center2Tool->updatePosition(crossPos, toolTipPos);
385 tool2Back->updatePosition(toolTipPos, toolTipBackPos);
386 if (getOffset() > 0.01)
388 centerPoint->getActor()->SetVisibility(
true);
392 centerPoint->getActor()->SetVisibility(
false);
395 centerPoint->update(crossPos);
396 toolPoint->update(toolTipPos);
399 void ToolRep2D::updateOffsetText()
405 if (getOffset() > 2.0 && mUseOffsetText &&
showOffset())
407 distanceText->updateText(
"Offset: " + QString::number(getOffset(),
'g', 3) +
" mm");
408 distanceText->getActor()->VisibilityOn();
412 distanceText->getActor()->VisibilityOff();
413 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)
boost::shared_ptr< class View > ViewPtr
boost::shared_ptr< class ToolRep2D > ToolRep2DPtr
bool similar(const DoubleBoundingBox3D &a, const DoubleBoundingBox3D &b, double tol)
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.
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.