CustusX  22.04-rc5
An IGT application
cxtestSyntheticReconstructInput.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
13 #include "cxDummyTool.h"
16 #include "cxTypeConversions.h"
17 
18 
19 namespace cxtest
20 {
21 
23 {
24  mBounds = cx::Vector3D(99,99,99);
25 
26  mProbeMovementDefinition.mRangeNormalizedTranslation = cx::Vector3D::UnitX();
27 // mProbeMovementDefinition.mRangeAngle = M_PI/8;
28 // mProbeMovementDefinition.mSteps = 100;
29  mProbeMovementDefinition.mRangeAngle = 0;
30  mProbeMovementDefinition.mSteps = 200;
31 
32  mProbe = cx::DummyToolTestUtilities::createProbeDefinitionLinear(100, 100, Eigen::Array2i(200,200));
33 }
34 
36 {
37  mProbeMovementDefinition.mRangeNormalizedTranslation = cx::Vector3D::UnitX() * range;
38 }
40 {
41  mProbeMovementDefinition.mRangeAngle = range;
42 }
44 {
45  mProbeMovementDefinition.mSteps = steps;
46 }
48 {
49  mProbe = probe;
50 }
51 
53 {
54  // factors controlling sample rate:
55  // - output volume spacing
56  // - probe plane in-plane spacing
57  // - probe planes spacing (between the planes)
58  //
59  // set all these rates to the input spacing:
60 
61  mBounds = cx::Vector3D::Ones() * size;
62  mProbe = cx::DummyToolTestUtilities::createProbeDefinitionLinear(size, size, Eigen::Array2i(1,1)*((std::lround(size/spacing))+1));
63  mProbeMovementDefinition.mRangeNormalizedTranslation = cx::Vector3D::UnitX();
64  mProbeMovementDefinition.mRangeAngle = 0;
65  mProbeMovementDefinition.mSteps = size/spacing+1;
66 }
67 
69 {
70  QString indent("");
71  mPhantom->printInfo();
72  std::cout << indent << "Probe:\n" << streamXml2String(mProbe) << std::endl;
73  std::cout << indent << "ProbeMovement RangeNormalizedTranslation: " << mProbeMovementDefinition.mRangeNormalizedTranslation << std::endl;
74  std::cout << indent << "ProbeMovement RangeAngle: " << mProbeMovementDefinition.mRangeAngle << std::endl;
75  std::cout << indent << "ProbeMovement Steps: " << mProbeMovementDefinition.mSteps<< std::endl;
76 }
77 
79 {
80  mPhantom.reset(new cx::cxSimpleSyntheticVolume(mBounds));
81 }
82 
84 {
85  mPhantom.reset(new cxtest::SphereSyntheticVolume(mBounds));
86 }
87 
89 {
90 
91 }
92 
93 std::vector<cx::Transform3D> SyntheticReconstructInput::generateFrames_rMt_tilted()
94 {
95  cx::Vector3D p0(mBounds[0]/2, mBounds[1]/2, 0); //probe starting point. pointing along z
96  cx::Vector3D range_translation = mBounds[0] * mProbeMovementDefinition.mRangeNormalizedTranslation;
97  double range_angle = mProbeMovementDefinition.mRangeAngle;
98  int steps = mProbeMovementDefinition.mSteps;
99 
100  // generate transforms from tool to reference.
101  return this->generateFrames(p0,
102  range_translation,
103  range_angle,
104  Eigen::Vector3d::UnitY(),
105  steps);
106 }
107 
112 std::vector<cx::Transform3D> SyntheticReconstructInput::generateFrames(cx::Vector3D p0,
113  cx::Vector3D range_translation,
114  double range_angle,
115  cx::Vector3D rotation_axis,
116  int steps)
117 {
118  // generate transforms from tool to reference.
119  std::vector<cx::Transform3D> planes;
120  for(int i = 0; i < steps; ++i)
121  {
122  double R = steps-1;
123  double t = (i-R/2)/R; // range [-0.5 .. 0.5]
124  cx::Transform3D transform = cx::Transform3D::Identity();
125  transform.translation() = p0 + range_translation*t;
126  transform.rotate(Eigen::AngleAxisd(t*range_angle, rotation_axis));
127  planes.push_back(transform);
128  }
129  return planes;
130 }
131 
133 {
134  cx::Vector3D p0(mBounds[0]/2, mBounds[1]/2, 0); //probe starting point. pointing along z
135  cx::Vector3D range_translation = mBounds[0] * mProbeMovementDefinition.mRangeNormalizedTranslation;
136  double range_angle = mProbeMovementDefinition.mRangeAngle;
137  int steps_full = 3*mProbeMovementDefinition.mSteps;
138 
139  // generate oversampled list of positions, for use both in tracking and imaging.
140  std::vector<cx::Transform3D> rMt_full;
141  rMt_full = this->generateFrames(p0,
142  range_translation,
143  range_angle,
144  Eigen::Vector3d::UnitY(),
145  steps_full);
146 
148 
149  // sample out tracking positions from the full list
150  for (unsigned i=0; i<steps_full; i+=2)
151  {
152  cx::TimedPosition pos;
153  pos.mTime = i;
154  pos.mPos = rMt_full[i]; // TODO: skrell av rMpr
155  result.mPositions.push_back(pos);
156  }
157 
158  // sample out image frames from the full list
159  std::vector<vtkImageDataPtr> frames;
160  for (unsigned i=0; i<steps_full; i+=3)
161  {
162  cx::TimedPosition pos;
163  pos.mTime = i;
164  result.mFrames.push_back(pos);
165 
166  frames.push_back(mPhantom->sampleUsData(rMt_full[i], mProbe));
167  }
168  result.mUsRaw = cx::USFrameData::create("virtual", frames);
169 
170  // fill rest of info
171  result.rMpr = cx::Transform3D::Identity(); // if <>Identity, remember to also change mPositions
172  result.mProbeUid = "testProbe";
173  result.mProbeDefinition.setData(mProbe);
174 
175  return result;
176 }
177 
179 {
180  std::vector<cx::Transform3D> planes = this->generateFrames_rMt_tilted();
181 // std::cout << "Starting sampling\n";
183  retval = mPhantom->sampleUsData(planes, mProbe, dMr);
184 // std::cout << "Done sampling\n";
185  return retval;
186 }
187 
188 
189 } // namespace cxtest
190 
One position with timestamp.
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
cx::USReconstructInputData generateSynthetic_USReconstructInputData()
std::vector< TimedPosition > mFrames
void setOverallBoundsAndSpacing(double size, double spacing)
cx::ProcessedUSInputDataPtr generateSynthetic_ProcessedUSInputData(cx::Transform3D dMr)
Transform3D rMpr
patient registration
std::vector< TimedPosition > mPositions
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
Definition of characteristics for an Ultrasound Probe Sector.
QString streamXml2String(T &val)
boost::shared_ptr< class ProcessedUSInputData > ProcessedUSInputDataPtr
USFrameDataPtr mUsRaw
All imported US data frames with pointers to each frame.
static USFrameDataPtr create(ImagePtr inputFrameData)
float4 transform(float16 matrix, float4 voxel)
static ProbeDefinition createProbeDefinitionLinear(double depth=40, double width=50, Eigen::Array2i frameSize=Eigen::Array2i(80, 40))
Definition: cxDummyTool.cpp:45
void setData(ProbeDefinition data)