Fraxinus  16.5.0-fx-rc4
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
39 namespace cxtest
40 {
41 
43 {
44  mBounds = cx::Vector3D(99,99,99);
45 
46  mProbeMovementDefinition.mRangeNormalizedTranslation = cx::Vector3D::UnitX();
47 // mProbeMovementDefinition.mRangeAngle = M_PI/8;
48 // mProbeMovementDefinition.mSteps = 100;
49  mProbeMovementDefinition.mRangeAngle = 0;
50  mProbeMovementDefinition.mSteps = 200;
51 
52  mProbe = cx::DummyToolTestUtilities::createProbeDefinitionLinear(100, 100, Eigen::Array2i(200,200));
53 }
54 
56 {
57  mProbeMovementDefinition.mRangeNormalizedTranslation = cx::Vector3D::UnitX() * range;
58 }
60 {
61  mProbeMovementDefinition.mRangeAngle = range;
62 }
64 {
65  mProbeMovementDefinition.mSteps = steps;
66 }
68 {
69  mProbe = probe;
70 }
71 
73 {
74  // factors controlling sample rate:
75  // - output volume spacing
76  // - probe plane in-plane spacing
77  // - probe planes spacing (between the planes)
78  //
79  // set all these rates to the input spacing:
80 
81  mBounds = cx::Vector3D::Ones() * size;
82 // this->defineOutputVolume(size, spacing);
83  mProbe = cx::DummyToolTestUtilities::createProbeDefinitionLinear(size, size, Eigen::Array2i(1,1)*(size/spacing+1));
84  mProbeMovementDefinition.mRangeNormalizedTranslation = cx::Vector3D::UnitX();
85  mProbeMovementDefinition.mRangeAngle = 0;
86  mProbeMovementDefinition.mSteps = size/spacing+1;
87 }
88 
90 {
91  QString indent("");
92  mPhantom->printInfo();
93  std::cout << indent << "Probe:\n" << streamXml2String(mProbe) << std::endl;
94  std::cout << indent << "ProbeMovement RangeNormalizedTranslation: " << mProbeMovementDefinition.mRangeNormalizedTranslation << std::endl;
95  std::cout << indent << "ProbeMovement RangeAngle: " << mProbeMovementDefinition.mRangeAngle << std::endl;
96  std::cout << indent << "ProbeMovement Steps: " << mProbeMovementDefinition.mSteps<< std::endl;
97 }
98 
100 {
101  mPhantom.reset(new cx::cxSimpleSyntheticVolume(mBounds));
102 }
103 
105 {
106  mPhantom.reset(new cxtest::SphereSyntheticVolume(mBounds));
107 }
108 
110 {
111 
112 }
113 
114 std::vector<cx::Transform3D> SyntheticReconstructInput::generateFrames_rMt_tilted()
115 {
116  cx::Vector3D p0(mBounds[0]/2, mBounds[1]/2, 0); //probe starting point. pointing along z
117  cx::Vector3D range_translation = mBounds[0] * mProbeMovementDefinition.mRangeNormalizedTranslation;
118  double range_angle = mProbeMovementDefinition.mRangeAngle;
119  int steps = mProbeMovementDefinition.mSteps;
120 
121  // generate transforms from tool to reference.
122  return this->generateFrames(p0,
123  range_translation,
124  range_angle,
125  Eigen::Vector3d::UnitY(),
126  steps);
127 }
128 
133 std::vector<cx::Transform3D> SyntheticReconstructInput::generateFrames(cx::Vector3D p0,
134  cx::Vector3D range_translation,
135  double range_angle,
136  cx::Vector3D rotation_axis,
137  int steps)
138 {
139  // generate transforms from tool to reference.
140  std::vector<cx::Transform3D> planes;
141  for(int i = 0; i < steps; ++i)
142  {
143  double R = steps-1;
144  double t = (i-R/2)/R; // range [-0.5 .. 0.5]
145  cx::Transform3D transform = cx::Transform3D::Identity();
146  transform.translation() = p0 + range_translation*t;
147  transform.rotate(Eigen::AngleAxisd(t*range_angle, rotation_axis));
148  planes.push_back(transform);
149  }
150  return planes;
151 }
152 
154 {
155  cx::Vector3D p0(mBounds[0]/2, mBounds[1]/2, 0); //probe starting point. pointing along z
156  cx::Vector3D range_translation = mBounds[0] * mProbeMovementDefinition.mRangeNormalizedTranslation;
157  double range_angle = mProbeMovementDefinition.mRangeAngle;
158  int steps_full = 3*mProbeMovementDefinition.mSteps;
159 
160  // generate oversampled list of positions, for use both in tracking and imaging.
161  std::vector<cx::Transform3D> rMt_full;
162  rMt_full = this->generateFrames(p0,
163  range_translation,
164  range_angle,
165  Eigen::Vector3d::UnitY(),
166  steps_full);
167 
169 
170  // sample out tracking positions from the full list
171  for (unsigned i=0; i<steps_full; i+=2)
172  {
173  cx::TimedPosition pos;
174  pos.mTime = i;
175  pos.mPos = rMt_full[i]; // TODO: skrell av rMpr
176  result.mPositions.push_back(pos);
177  }
178 
179  // sample out image frames from the full list
180  std::vector<vtkImageDataPtr> frames;
181  for (unsigned i=0; i<steps_full; i+=3)
182  {
183  cx::TimedPosition pos;
184  pos.mTime = i;
185  result.mFrames.push_back(pos);
186 
187  frames.push_back(mPhantom->sampleUsData(rMt_full[i], mProbe));
188  }
189  result.mUsRaw = cx::USFrameData::create("virtual", frames);
190 
191  // fill rest of info
192  result.rMpr = cx::Transform3D::Identity(); // if <>Identity, remember to also change mPositions
193  result.mProbeUid = "testProbe";
194  result.mProbeDefinition.setData(mProbe);
195 
196  return result;
197 }
198 
200 {
201  std::vector<cx::Transform3D> planes = this->generateFrames_rMt_tilted();
202 // std::cout << "Starting sampling\n";
204  retval = mPhantom->sampleUsData(planes, mProbe, dMr);
205 // std::cout << "Done sampling\n";
206  return retval;
207 }
208 
209 
210 } // namespace cxtest
211 
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: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)