Fraxinus  18.10
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 #include "cxMathUtils.h"
18 
19 
20 namespace cxtest
21 {
22 
24 {
25  mBounds = cx::Vector3D(99,99,99);
26 
27  mProbeMovementDefinition.mRangeNormalizedTranslation = cx::Vector3D::UnitX();
28 // mProbeMovementDefinition.mRangeAngle = M_PI/8;
29 // mProbeMovementDefinition.mSteps = 100;
30  mProbeMovementDefinition.mRangeAngle = 0;
31  mProbeMovementDefinition.mSteps = 200;
32 
33  mProbe = cx::DummyToolTestUtilities::createProbeDefinitionLinear(100, 100, Eigen::Array2i(200,200));
34 }
35 
37 {
38  mProbeMovementDefinition.mRangeNormalizedTranslation = cx::Vector3D::UnitX() * range;
39 }
41 {
42  mProbeMovementDefinition.mRangeAngle = range;
43 }
45 {
46  mProbeMovementDefinition.mSteps = steps;
47 }
49 {
50  mProbe = probe;
51 }
52 
54 {
55  // factors controlling sample rate:
56  // - output volume spacing
57  // - probe plane in-plane spacing
58  // - probe planes spacing (between the planes)
59  //
60  // set all these rates to the input spacing:
61 
62  mBounds = cx::Vector3D::Ones() * size;
63  mProbe = cx::DummyToolTestUtilities::createProbeDefinitionLinear(size, size, Eigen::Array2i(1,1)*(int(cx::roundAwayFromZero(size/spacing))+1));
64  mProbeMovementDefinition.mRangeNormalizedTranslation = cx::Vector3D::UnitX();
65  mProbeMovementDefinition.mRangeAngle = 0;
66  mProbeMovementDefinition.mSteps = size/spacing+1;
67 }
68 
70 {
71  QString indent("");
72  mPhantom->printInfo();
73  std::cout << indent << "Probe:\n" << streamXml2String(mProbe) << std::endl;
74  std::cout << indent << "ProbeMovement RangeNormalizedTranslation: " << mProbeMovementDefinition.mRangeNormalizedTranslation << std::endl;
75  std::cout << indent << "ProbeMovement RangeAngle: " << mProbeMovementDefinition.mRangeAngle << std::endl;
76  std::cout << indent << "ProbeMovement Steps: " << mProbeMovementDefinition.mSteps<< std::endl;
77 }
78 
80 {
81  mPhantom.reset(new cx::cxSimpleSyntheticVolume(mBounds));
82 }
83 
85 {
86  mPhantom.reset(new cxtest::SphereSyntheticVolume(mBounds));
87 }
88 
90 {
91 
92 }
93 
94 std::vector<cx::Transform3D> SyntheticReconstructInput::generateFrames_rMt_tilted()
95 {
96  cx::Vector3D p0(mBounds[0]/2, mBounds[1]/2, 0); //probe starting point. pointing along z
97  cx::Vector3D range_translation = mBounds[0] * mProbeMovementDefinition.mRangeNormalizedTranslation;
98  double range_angle = mProbeMovementDefinition.mRangeAngle;
99  int steps = mProbeMovementDefinition.mSteps;
100 
101  // generate transforms from tool to reference.
102  return this->generateFrames(p0,
103  range_translation,
104  range_angle,
105  Eigen::Vector3d::UnitY(),
106  steps);
107 }
108 
113 std::vector<cx::Transform3D> SyntheticReconstructInput::generateFrames(cx::Vector3D p0,
114  cx::Vector3D range_translation,
115  double range_angle,
116  cx::Vector3D rotation_axis,
117  int steps)
118 {
119  // generate transforms from tool to reference.
120  std::vector<cx::Transform3D> planes;
121  for(int i = 0; i < steps; ++i)
122  {
123  double R = steps-1;
124  double t = (i-R/2)/R; // range [-0.5 .. 0.5]
125  cx::Transform3D transform = cx::Transform3D::Identity();
126  transform.translation() = p0 + range_translation*t;
127  transform.rotate(Eigen::AngleAxisd(t*range_angle, rotation_axis));
128  planes.push_back(transform);
129  }
130  return planes;
131 }
132 
134 {
135  cx::Vector3D p0(mBounds[0]/2, mBounds[1]/2, 0); //probe starting point. pointing along z
136  cx::Vector3D range_translation = mBounds[0] * mProbeMovementDefinition.mRangeNormalizedTranslation;
137  double range_angle = mProbeMovementDefinition.mRangeAngle;
138  int steps_full = 3*mProbeMovementDefinition.mSteps;
139 
140  // generate oversampled list of positions, for use both in tracking and imaging.
141  std::vector<cx::Transform3D> rMt_full;
142  rMt_full = this->generateFrames(p0,
143  range_translation,
144  range_angle,
145  Eigen::Vector3d::UnitY(),
146  steps_full);
147 
149 
150  // sample out tracking positions from the full list
151  for (unsigned i=0; i<steps_full; i+=2)
152  {
153  cx::TimedPosition pos;
154  pos.mTime = i;
155  pos.mPos = rMt_full[i]; // TODO: skrell av rMpr
156  result.mPositions.push_back(pos);
157  }
158 
159  // sample out image frames from the full list
160  std::vector<vtkImageDataPtr> frames;
161  for (unsigned i=0; i<steps_full; i+=3)
162  {
163  cx::TimedPosition pos;
164  pos.mTime = i;
165  result.mFrames.push_back(pos);
166 
167  frames.push_back(mPhantom->sampleUsData(rMt_full[i], mProbe));
168  }
169  result.mUsRaw = cx::USFrameData::create("virtual", frames);
170 
171  // fill rest of info
172  result.rMpr = cx::Transform3D::Identity(); // if <>Identity, remember to also change mPositions
173  result.mProbeUid = "testProbe";
174  result.mProbeDefinition.setData(mProbe);
175 
176  return result;
177 }
178 
180 {
181  std::vector<cx::Transform3D> planes = this->generateFrames_rMt_tilted();
182 // std::cout << "Starting sampling\n";
184  retval = mPhantom->sampleUsData(planes, mProbe, dMr);
185 // std::cout << "Done sampling\n";
186  return retval;
187 }
188 
189 
190 } // namespace cxtest
191 
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)
double roundAwayFromZero(double val)
Definition: cxMathUtils.cpp:21
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:46
void setData(ProbeDefinition data)