NorMIT-nav  22.09
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 
cx::ProbeDefinition
Definition of characteristics for an Ultrasound Probe Sector.
Definition: cxProbeDefinition.h:101
cx::USReconstructInputData::mUsRaw
USFrameDataPtr mUsRaw
All imported US data frames with pointers to each frame.
Definition: cxUSReconstructInputData.h:52
cx::USReconstructInputData::mFrames
std::vector< TimedPosition > mFrames
Definition: cxUSReconstructInputData.h:53
transform
float4 transform(float16 matrix, float4 voxel)
cx::ProcessedUSInputDataPtr
boost::shared_ptr< class ProcessedUSInputData > ProcessedUSInputDataPtr
Definition: cxReconstructionMethodService.h:36
cx::TimedPosition::mPos
Transform3D mPos
Definition: cxUSReconstructInputData.h:41
cxDummyTool.h
cxtest::SphereSyntheticVolume
Definition: cxtestSphereSyntheticVolume.h:26
cx::USFrameData::create
static USFrameDataPtr create(ImagePtr inputFrameData)
Definition: cxUSFrameData.cpp:117
cxtestSyntheticReconstructInput.h
cxtest::SyntheticReconstructInput::generateSynthetic_ProcessedUSInputData
cx::ProcessedUSInputDataPtr generateSynthetic_ProcessedUSInputData(cx::Transform3D dMr)
Definition: cxtestSyntheticReconstructInput.cpp:178
cxtest::SyntheticReconstructInput::setWireCrossPhantom
void setWireCrossPhantom()
Definition: cxtestSyntheticReconstructInput.cpp:88
cxtest::SyntheticReconstructInput::setSpherePhantom
void setSpherePhantom()
Definition: cxtestSyntheticReconstructInput.cpp:83
cxtest::SyntheticReconstructInput::generateSynthetic_USReconstructInputData
cx::USReconstructInputData generateSynthetic_USReconstructInputData()
Definition: cxtestSyntheticReconstructInput.cpp:132
cxtest::SyntheticReconstructInput::defineProbeMovementSteps
void defineProbeMovementSteps(int steps)
Definition: cxtestSyntheticReconstructInput.cpp:43
cxtest::SyntheticReconstructInput::defineProbeMovementAngleRange
void defineProbeMovementAngleRange(double range)
Definition: cxtestSyntheticReconstructInput.cpp:39
cx::USReconstructInputData::mProbeUid
QString mProbeUid
Definition: cxUSReconstructInputData.h:58
cx::ProbeSector::setData
void setData(ProbeDefinition data)
Definition: cxProbeSector.cpp:48
cxtest::SyntheticReconstructInput::setOverallBoundsAndSpacing
void setOverallBoundsAndSpacing(double size, double spacing)
Definition: cxtestSyntheticReconstructInput.cpp:52
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cxTypeConversions.h
cxtest
Definition: cxtestDirectSignalListener.cpp:13
cx::TimedPosition
One position with timestamp.
Definition: cxUSReconstructInputData.h:36
cxSimpleSyntheticVolume.h
cxtest::SyntheticReconstructInput::defineProbe
void defineProbe(cx::ProbeDefinition probe)
Definition: cxtestSyntheticReconstructInput.cpp:47
cx::USReconstructInputData::rMpr
Transform3D rMpr
patient registration
Definition: cxUSReconstructInputData.h:59
cx::USReconstructInputData::mPositions
std::vector< TimedPosition > mPositions
Definition: cxUSReconstructInputData.h:54
cx::cxSimpleSyntheticVolume
Definition: cxSimpleSyntheticVolume.h:21
cx::TimedPosition::mTime
double mTime
Definition: cxUSReconstructInputData.h:39
cxtest::SyntheticReconstructInput::printConfiguration
void printConfiguration()
Definition: cxtestSyntheticReconstructInput.cpp:68
cx::USReconstructInputData
Definition: cxUSReconstructInputData.h:48
cx::USReconstructInputData::mProbeDefinition
ProbeSector mProbeDefinition
Definition: cxUSReconstructInputData.h:57
cxtestSphereSyntheticVolume.h
cxtest::SyntheticReconstructInput::setBoxAndLinesPhantom
void setBoxAndLinesPhantom()
Definition: cxtestSyntheticReconstructInput.cpp:78
cxtest::SyntheticReconstructInput::SyntheticReconstructInput
SyntheticReconstructInput()
Definition: cxtestSyntheticReconstructInput.cpp:22
cxtest::SyntheticReconstructInput::defineProbeMovementNormalizedTranslationRange
void defineProbeMovementNormalizedTranslationRange(double range)
Definition: cxtestSyntheticReconstructInput.cpp:35
streamXml2String
QString streamXml2String(T &val)
Definition: cxTypeConversions.h:89
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
cx::DummyToolTestUtilities::createProbeDefinitionLinear
static ProbeDefinition createProbeDefinitionLinear(double depth=40, double width=50, Eigen::Array2i frameSize=Eigen::Array2i(80, 40))
Definition: cxDummyTool.cpp:45