36 #include "boost/bind.hpp"
38 #include <vtkProperty.h>
39 #include <vtkPolyDataMapper.h>
40 #include <vtkPolyDataNormals.h>
41 #include <vtkSTLReader.h>
42 #include <vtkMatrix4x4.h>
43 #include <vtkRenderer.h>
59 mSpaceProvider(spaceProvider),
60 mSphereRadiusInNormalizedViewport(false),
61 mTooltipPointColor(QColor::fromRgbF(1.0, 0.8, 0.0)),
62 mOffsetPointColor(QColor::fromRgbF(1.0, 0.8, 0.0)),
63 mOffsetLineColor(QColor::fromRgbF(1.0, 0.8, 0.0)),
64 mStipplePattern(0xFFFF)
67 mStayHiddenAfterVisible =
false;
68 mStayVisibleAfterHide =
false;
69 mOffsetPointVisibleAtZeroOffset =
false;
70 mToolActor = vtkActorPtr::New();
71 mPolyDataMapper = vtkPolyDataMapperPtr::New();
79 mProbeSectorPolyDataMapper = vtkPolyDataMapperPtr::New();
80 mProbeSectorActor = vtkActorPtr::New();
108 void ToolRep3D::updateToolActor()
112 mToolActor->SetMapper(NULL);
121 normals->SetInputData(model);
122 mPolyDataMapper->SetInputConnection(normals->GetOutputPort());
123 mPolyDataMapper->Update();
124 mToolActor->SetMapper(mPolyDataMapper);
128 mToolActor->GetProperty()->SetColor(1.0, 1.0, 1.0);
135 mToolActor->SetVisibility(mTool->getVisible());
143 mTracer->setTool(tool);
147 disconnect(mTool.get(), SIGNAL(toolTransformAndTimestamp(
Transform3D,
double)),
this, SLOT(
setModified()));
148 disconnect(mTool.get(), SIGNAL(toolVisible(
bool)),
this, SLOT(receiveVisible(
bool)));
149 disconnect(mTool.get(), SIGNAL(tooltipOffset(
double)),
this, SLOT(tooltipOffsetSlot(
double)));
150 disconnect(mTool.get(), SIGNAL(toolProbeSector()),
this, SLOT(probeSectorChanged()));
151 disconnect(mTool.get(), SIGNAL(toolProbeSector()),
this, SLOT(updateToolActor()));
159 connect(mTool.get(), SIGNAL(toolVisible(
bool)),
this, SLOT(receiveVisible(
bool)));
160 connect(mTool.get(), SIGNAL(tooltipOffset(
double)),
this, SLOT(tooltipOffsetSlot(
double)));
161 connect(mTool.get(), SIGNAL(toolProbeSector()),
this, SLOT(probeSectorChanged()));
162 connect(mTool.get(), SIGNAL(toolProbeSector()),
this, SLOT(updateToolActor()));
165 this->updateToolActor();
167 this->probeSectorChanged();
172 return (mTool == tool);
177 mSphereRadius = radius;
179 mOffsetPoint->setRadius(mSphereRadius);
181 mTooltipPoint->setRadius(mSphereRadius);
186 mTooltipPointColor = c;
191 mOffsetPointColor = c;
196 mOffsetLineColor = c;
201 mStipplePattern = pattern;
206 if (mSphereRadiusInNormalizedViewport == on)
209 mSphereRadiusInNormalizedViewport = on;
214 mViewportListener->setCallback(boost::bind(&ToolRep3D::scaleSpheres,
this));
218 mViewportListener.reset();
224 view->getRenderer()->AddActor(mTracer->getActor());
226 view->getRenderer()->AddActor(mToolActor);
227 view->getRenderer()->AddActor(mProbeSectorActor);
230 mOffsetPoint->setRadius(mSphereRadius);
231 mOffsetPoint->setColor(mOffsetPointColor);
234 mTooltipPoint->setRadius(mSphereRadius);
235 mTooltipPoint->setColor(mTooltipPointColor);
238 mOffsetLine->setColor(mOffsetLineColor);
239 mOffsetLine->setStipple(mStipplePattern);
241 mTooltipPoint->getActor()->SetVisibility(
false);
242 mOffsetPoint->getActor()->SetVisibility(
false);
243 mOffsetLine->getActor()->SetVisibility(
false);
245 if (mViewportListener)
246 mViewportListener->startListen(view->getRenderer());
251 view->getRenderer()->RemoveActor(mTracer->getActor());
252 view->getRenderer()->RemoveActor(mToolActor);
253 view->getRenderer()->RemoveActor(mProbeSectorActor);
259 if (mViewportListener)
260 mViewportListener->stopListen();
269 void ToolRep3D::scaleSpheres()
271 if (!mViewportListener)
273 if (!mViewportListener->isListening())
276 double size = mViewportListener->getVpnZoom();
277 double sphereSize = mSphereRadius/100/size;
280 mOffsetPoint->setRadius(sphereSize);
282 mTooltipPoint->setRadius(sphereSize);
291 void ToolRep3D::update()
295 prMt = mTool->get_prMt();
299 mToolActor->SetUserMatrix(rMt.getVtkMatrix());
304 mProbeSectorActor->SetUserMatrix((rMpr * prMt * tMu).
getVtkMatrix());
305 mProbeSectorActor->SetVisibility(mTool->getVisible());
308 mProbeSectorActor->SetVisibility(
false);
310 this->updateOffsetGraphics();
313 void ToolRep3D::probeSectorChanged()
323 mProbeSector->setData(mTool->getProbe()->getProbeDefinition());
326 mProbeSectorPolyDataMapper->SetInputData(mProbeSector->getSectorLinesOnly());
327 if (mProbeSectorPolyDataMapper->GetInput())
329 mProbeSectorActor->SetMapper(mProbeSectorPolyDataMapper);
331 mProbeSectorActor->SetUserMatrix((rMpr * prMt * tMu).
getVtkMatrix());
332 mProbeSectorActor->SetVisibility(mTool->getVisible());
335 mProbeSectorActor->SetVisibility(
false);
338 void ToolRep3D::updateOffsetGraphics()
340 bool visible = mTool && mTool->getVisible();
342 if (!mStayVisibleAfterHide || (mOffsetPoint->getActor()->GetVisibility() ==
false))
344 mOffsetPoint->getActor()->SetVisibility(visible);
345 mTooltipPoint->getActor()->SetVisibility(visible);
347 if (mStayHiddenAfterVisible)
348 mTooltipPoint->getActor()->SetVisibility(
false);
349 mOffsetLine->getActor()->SetVisibility(visible);
352 if (
similar(0.0, mTool->getTooltipOffset()))
355 mTooltipPoint->getActor()->SetVisibility(
false);
357 mTooltipPoint->getActor()->SetVisibility(visible && mOffsetPointVisibleAtZeroOffset);
358 mOffsetPoint->getActor()->SetVisibility(
false);
359 mOffsetLine->getActor()->SetVisibility(
false);
369 mOffsetPoint->setValue(p1);
370 mOffsetLine->setValue(p0, p1);
371 mTooltipPoint->setValue(
Vector3D(p0));
373 this->scaleSpheres();
376 void ToolRep3D::receiveVisible(
bool visible)
378 if (!visible && mStayVisibleAfterHide)
380 mToolActor->SetVisibility(visible);
382 if (mStayHiddenAfterVisible)
383 mToolActor->SetVisibility(
false);
385 mToolActor->SetVisibility(mTool->getVisible());
392 mStayHiddenAfterVisible = val;
394 receiveVisible(mTool->getVisible());
403 mStayVisibleAfterHide = val;
408 mOffsetPointVisibleAtZeroOffset = val;
411 void ToolRep3D::tooltipOffsetSlot(
double val)
413 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)
boost::shared_ptr< class ToolTracer > ToolTracerPtr
Helper for rendering a point in 3D.
boost::shared_ptr< class View > ViewPtr
bool similar(const DoubleBoundingBox3D &a, const DoubleBoundingBox3D &b, double tol)
Listens to changes in viewport and camera matrix.
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
vtkSmartPointer< class vtkPolyDataNormals > vtkPolyDataNormalsPtr
Helper for rendering a line in 3D.
Default implementation of Rep.
cxLogicManager_EXPORT SpaceProviderPtr spaceProvider()
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Utility functions for drawing an US Probe sector.
boost::shared_ptr< class ToolRep3D > ToolRep3DPtr
void setColorAndOpacity(vtkPropertyPtr property, QColor color)
boost::shared_ptr< class Tool > ToolPtr