Fraxinus  16.5.0-fx-rc3
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxCreateProbeDefinitionFromConfiguration.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 "cxTypeConversions.h"
35 #include <iostream>
36 
37 namespace cx
38 {
39 
41 {
43 
44  QSize storedSize(basis.mImageWidth, basis.mImageHeight);
45  if (storedSize!=data.getSize())
46  {
47  // wrong size: resample
48  data.resample(storedSize);
49  }
50 
51  config.mLeftEdge = data.getClipRect_p()[0];
52  config.mRightEdge = data.getClipRect_p()[1];
53  config.mTopEdge = data.getClipRect_p()[2];
54  config.mBottomEdge = data.getClipRect_p()[3];
55 
56  config.mOriginCol = data.getOrigin_p()[0];
57  config.mOriginRow = data.getOrigin_p()[1];
58 
59  config.mPixelWidth = data.getSpacing()[0];
60  config.mPixelHeight = data.getSpacing()[1];
61 
62  config.mImageWidth = data.getSize().width();
63  config.mImageHeight = data.getSize().height();
64 
66  {
67  config.mWidthDeg = data.getWidth() / M_PI*180.0;
68  config.mOffset = data.getDepthStart() / data.getSpacing()[1];
69  config.mDepth = (data.getDepthEnd() - data.getDepthStart()) / data.getSpacing()[1];
70  }
71  else
72  {
73  // derived values
74  config.mWidthDeg = 0.0;
75  config.mOffset = 0;
76  config.mDepth = 0;
77  }
78 
80 
81  return config;
82 }
83 
85 {
86  if(config.isEmpty())
87  return ProbeDefinition();
88 
89  ProbeDefinition probeDefinition;
90 
91  if (config.mWidthDeg > 0.1) // Sector probe
92  {
93  double depthStart = config.mOffset * config.mPixelHeight;
94  double depthEnd = config.mDepth * config.mPixelHeight + depthStart;
95 
96  double width = config.mWidthDeg * M_PI / 180.0;//width in radians
97  probeDefinition = ProbeDefinition(ProbeDefinition::tSECTOR);
98  probeDefinition.setSector(depthStart, depthEnd, width);
99  }
100  else //Linear probe
101  {
102  int widtInPixels = config.mRightEdge - config.mLeftEdge;
103  double width = config.mPixelWidth * double(widtInPixels); //width in mm
104  // correct for top/bottom edges if applicable
105  double depthStart = double(config.mTopEdge-config.mOriginRow) * config.mPixelHeight;
106  double depthEnd = double(config.mBottomEdge-config.mOriginRow) * config.mPixelHeight;
107 
108  probeDefinition = ProbeDefinition(ProbeDefinition::tLINEAR);
109  probeDefinition.setSector(depthStart, depthEnd, width);
110  }
111 
112  probeDefinition.setSpacing(Vector3D(config.mPixelWidth, config.mPixelHeight, 1));
113  probeDefinition.setSize(QSize(config.mImageWidth, config.mImageHeight));
114  probeDefinition.setOrigin_p(Vector3D(config.mOriginCol, config.mOriginRow, 0));
115  probeDefinition.setClipRect_p(DoubleBoundingBox3D(config.mLeftEdge,config.mRightEdge,config.mTopEdge,config.mBottomEdge,0,0));
116  probeDefinition.setTemporalCalibration(config.mTemporalCalibration);
117 
118  return probeDefinition;
119 }
120 
121 } // namespace cx
double getWidth() const
< a easy-to-work-with struct for a specific xml configuration
void setSpacing(Vector3D spacing)
US beam is emitted straight forward.
void resample(QSize mSize)
Set a new image size. Resample all other parameters to match this new image size, keeping sizes in mi...
void setSector(double depthStart, double depthEnd, double width, double centerOffset=0)
double getDepthStart() const
double getDepthEnd() const
Vector3D getOrigin_p() const
void setOrigin_p(Vector3D origin_p)
US beam is emitted radially in a flat cone.
void setTemporalCalibration(double value)
void setClipRect_p(DoubleBoundingBox3D clipRect_p)
Representation of a floating-point bounding box in 3D. The data are stored as {xmin,xmax,ymin,ymax,zmin,zmax}, in order to simplify communication with vtk.
int mImageWidth
Width of the used image format (x dim)
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.
Vector3D getSpacing() const
int mImageHeight
Height of the used image format (y dim)
double mTemporalCalibration
delay in timestamping in grabber source relative to master clock.
double getTemporalCalibration() const
DoubleBoundingBox3D getClipRect_p() const
void setSize(QSize size)
ProbeDefinition createProbeDefinitionFromConfiguration(ProbeXmlConfigParser::Configuration config)
ProbeXmlConfigParser::Configuration createConfigurationFromProbeDefinition(ProbeXmlConfigParser::Configuration basis, ProbeDefinition data)
#define M_PI