Fraxinus  17.12-rc1
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
34 #include "cxDummyTool.h"
37 #include "cxTypeConversions.h"
38 #include "cxMathUtils.h"
39 
40 
41 namespace cxtest
42 {
43 
45 {
46  mBounds = cx::Vector3D(99,99,99);
47 
48  mProbeMovementDefinition.mRangeNormalizedTranslation = cx::Vector3D::UnitX();
49 // mProbeMovementDefinition.mRangeAngle = M_PI/8;
50 // mProbeMovementDefinition.mSteps = 100;
51  mProbeMovementDefinition.mRangeAngle = 0;
52  mProbeMovementDefinition.mSteps = 200;
53 
54  mProbe = cx::DummyToolTestUtilities::createProbeDefinitionLinear(100, 100, Eigen::Array2i(200,200));
55 }
56 
58 {
59  mProbeMovementDefinition.mRangeNormalizedTranslation = cx::Vector3D::UnitX() * range;
60 }
62 {
63  mProbeMovementDefinition.mRangeAngle = range;
64 }
66 {
67  mProbeMovementDefinition.mSteps = steps;
68 }
70 {
71  mProbe = probe;
72 }
73 
75 {
76  // factors controlling sample rate:
77  // - output volume spacing
78  // - probe plane in-plane spacing
79  // - probe planes spacing (between the planes)
80  //
81  // set all these rates to the input spacing:
82 
83  mBounds = cx::Vector3D::Ones() * size;
84  mProbe = cx::DummyToolTestUtilities::createProbeDefinitionLinear(size, size, Eigen::Array2i(1,1)*(int(cx::roundAwayFromZero(size/spacing))+1));
85  mProbeMovementDefinition.mRangeNormalizedTranslation = cx::Vector3D::UnitX();
86  mProbeMovementDefinition.mRangeAngle = 0;
87  mProbeMovementDefinition.mSteps = size/spacing+1;
88 }
89 
91 {
92  QString indent("");
93  mPhantom->printInfo();
94  std::cout << indent << "Probe:\n" << streamXml2String(mProbe) << std::endl;
95  std::cout << indent << "ProbeMovement RangeNormalizedTranslation: " << mProbeMovementDefinition.mRangeNormalizedTranslation << std::endl;
96  std::cout << indent << "ProbeMovement RangeAngle: " << mProbeMovementDefinition.mRangeAngle << std::endl;
97  std::cout << indent << "ProbeMovement Steps: " << mProbeMovementDefinition.mSteps<< std::endl;
98 }
99 
101 {
102  mPhantom.reset(new cx::cxSimpleSyntheticVolume(mBounds));
103 }
104 
106 {
107  mPhantom.reset(new cxtest::SphereSyntheticVolume(mBounds));
108 }
109 
111 {
112 
113 }
114 
115 std::vector<cx::Transform3D> SyntheticReconstructInput::generateFrames_rMt_tilted()
116 {
117  cx::Vector3D p0(mBounds[0]/2, mBounds[1]/2, 0); //probe starting point. pointing along z
118  cx::Vector3D range_translation = mBounds[0] * mProbeMovementDefinition.mRangeNormalizedTranslation;
119  double range_angle = mProbeMovementDefinition.mRangeAngle;
120  int steps = mProbeMovementDefinition.mSteps;
121 
122  // generate transforms from tool to reference.
123  return this->generateFrames(p0,
124  range_translation,
125  range_angle,
126  Eigen::Vector3d::UnitY(),
127  steps);
128 }
129 
134 std::vector<cx::Transform3D> SyntheticReconstructInput::generateFrames(cx::Vector3D p0,
135  cx::Vector3D range_translation,
136  double range_angle,
137  cx::Vector3D rotation_axis,
138  int steps)
139 {
140  // generate transforms from tool to reference.
141  std::vector<cx::Transform3D> planes;
142  for(int i = 0; i < steps; ++i)
143  {
144  double R = steps-1;
145  double t = (i-R/2)/R; // range [-0.5 .. 0.5]
146  cx::Transform3D transform = cx::Transform3D::Identity();
147  transform.translation() = p0 + range_translation*t;
148  transform.rotate(Eigen::AngleAxisd(t*range_angle, rotation_axis));
149  planes.push_back(transform);
150  }
151  return planes;
152 }
153 
155 {
156  cx::Vector3D p0(mBounds[0]/2, mBounds[1]/2, 0); //probe starting point. pointing along z
157  cx::Vector3D range_translation = mBounds[0] * mProbeMovementDefinition.mRangeNormalizedTranslation;
158  double range_angle = mProbeMovementDefinition.mRangeAngle;
159  int steps_full = 3*mProbeMovementDefinition.mSteps;
160 
161  // generate oversampled list of positions, for use both in tracking and imaging.
162  std::vector<cx::Transform3D> rMt_full;
163  rMt_full = this->generateFrames(p0,
164  range_translation,
165  range_angle,
166  Eigen::Vector3d::UnitY(),
167  steps_full);
168 
170 
171  // sample out tracking positions from the full list
172  for (unsigned i=0; i<steps_full; i+=2)
173  {
174  cx::TimedPosition pos;
175  pos.mTime = i;
176  pos.mPos = rMt_full[i]; // TODO: skrell av rMpr
177  result.mPositions.push_back(pos);
178  }
179 
180  // sample out image frames from the full list
181  std::vector<vtkImageDataPtr> frames;
182  for (unsigned i=0; i<steps_full; i+=3)
183  {
184  cx::TimedPosition pos;
185  pos.mTime = i;
186  result.mFrames.push_back(pos);
187 
188  frames.push_back(mPhantom->sampleUsData(rMt_full[i], mProbe));
189  }
190  result.mUsRaw = cx::USFrameData::create("virtual", frames);
191 
192  // fill rest of info
193  result.rMpr = cx::Transform3D::Identity(); // if <>Identity, remember to also change mPositions
194  result.mProbeUid = "testProbe";
195  result.mProbeDefinition.setData(mProbe);
196 
197  return result;
198 }
199 
201 {
202  std::vector<cx::Transform3D> planes = this->generateFrames_rMt_tilted();
203 // std::cout << "Starting sampling\n";
205  retval = mPhantom->sampleUsData(planes, mProbe, dMr);
206 // std::cout << "Done sampling\n";
207  return retval;
208 }
209 
210 
211 } // namespace cxtest
212 
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:35
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:63
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:67
void setData(ProbeDefinition data)