15 #include "vtkImageData.h" 16 #include <vtkPointData.h> 17 #include <vtkUnsignedCharArray.h> 18 #include <vtkPolyData.h> 19 #include <vtkPolyDataMapper.h> 21 #include <vtkCellArray.h> 22 #include <vtkFloatArray.h> 23 #include <vtkProperty.h> 25 #include <vtkMatrix4x4.h> 45 mSpaceProvider = spaceProvider;
47 mPolyData = vtkPolyDataPtr::New();
48 mActor = vtkActorPtr::New();
49 mPolyDataMapper = vtkPolyDataMapperPtr::New();
51 mPolyDataMapper->SetInputData(mPolyData);
52 mActor->SetMapper(mPolyDataMapper);
54 mProperty = vtkPropertyPtr::New();
55 mActor->SetProperty( mProperty );
56 mProperty->SetPointSize(4);
60 mPoints = vtkPointsPtr::New();
61 mLines = vtkCellArrayPtr::New();
63 mPolyData->SetPoints(mPoints);
64 mPolyData->SetLines(mLines);
65 mPolyData->SetVerts(mLines);
70 mSpaceListener = mSpaceProvider->createListener();
73 this->onSpaceChanged();
90 this->disconnectTool();
98 mPolyData->Modified();
101 void ToolTracer::connectTool()
103 if (mTool && mRunning)
105 connect(mTool.get(), SIGNAL(toolTransformAndTimestamp(
Transform3D,
double)),
this, SLOT(receiveTransforms(
Transform3D,
double)));
110 void ToolTracer::disconnectTool()
112 if (mTool && mRunning)
114 disconnect(mTool.get(), SIGNAL(toolTransformAndTimestamp(
Transform3D,
double)),
this, SLOT(receiveTransforms(
Transform3D,
double)));
121 mActor->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
126 this->disconnectTool();
141 void ToolTracer::onSpaceChanged()
145 mActor->SetUserMatrix(rMpr.getVtkMatrix());
153 void ToolTracer::receiveTransforms(
Transform3D prMt,
double timestamp)
157 if (mMinDistance > 0.0)
159 if (!mFirstPoint && (mPreviousPoint - p).
length() < mMinDistance)
167 mPoints->InsertNextPoint(p.begin());
169 if (mPoints->GetNumberOfPoints() > 1)
173 mLines->Initialize();
174 std::vector<vtkIdType> ids(mPoints->GetNumberOfPoints());
175 for (
unsigned i=0; i<ids.size(); ++i)
177 mLines->InsertNextCell(ids.size(), &(*ids.begin()));
180 mPolyData->Modified();
186 for(TimedTransformMap::iterator iter=trackerRecordedData_prMt.begin(); iter!=trackerRecordedData_prMt.end(); ++iter)
188 double timestamp = iter->first;
190 this->receiveTransforms(prMt, timestamp);
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
vtkSmartPointer< class vtkActor > vtkActorPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class ToolTracer > ToolTracerPtr
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
RealScalar length() const
static CoordinateSystem patientReference()
std::map< double, Transform3D > TimedTransformMap
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr