Fraxinus  16.5.0-fx-rc5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxSonixProbeFileReader.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 #include "cxSonixProbeFileReader.h"
33 #include <iostream>
34 #include <QFile>
35 #include <QDomDocument>
36 #include "cxTypeConversions.h"
37 
38 namespace cx {
39 
41  mFile(probeFile)
42 {
43 }
44 
46 {
47  if(!this->openFile())
48  return false;
49 
50  if(!this->openDomDocument())
51  return false;
52 
53  if(!this->openDocumentElement())
54  return false;
55 
56  return true;
57 }
58 
59 bool SonixProbeFileReader::openFile()
60 {
61  if(!mFile.open(QIODevice::ReadOnly))
62  return false;
63 
64  return true;
65 }
66 
67 bool SonixProbeFileReader::openDomDocument()
68 {
69  if(!mDoc.setContent(&mFile))
70  {
71  mFile.close();
72  return false;
73  }
74  return true;
75 }
76 
77 bool SonixProbeFileReader::openDocumentElement()
78 {
79  mDocElem = mDoc.documentElement();
80  if(mDocElem.isNull())
81  return false;
82 
83  return true;
84 }
85 
86 QDomNode SonixProbeFileReader::getProbeNode(QString probeName)
87 {
88  QDomElement probes = this->getProbes();
89  QDomNode probeNode = probes.firstChild();
90  QDomElement retval;
91  while(!probeNode.isNull() && retval.isNull())
92  {
93  retval = probeNode.toElement();
94  if(!retval.isNull())
95  {
96  if(retval.attribute("name") != probeName)
97  {
98  retval = QDomElement();
99  probeNode = probeNode.nextSibling();
100  }
101  }
102  }
103  return retval;
104 }
105 
107 {
108  return this->getChildWithTag(mDocElem, "probes");
109 }
110 
111 bool SonixProbeFileReader::isProbeLinear(QDomNode probeNode)
112 {
113  QDomElement type = this->getChildWithTag(probeNode, "type");
114  if (type.text() == "2")
115  return true;
116 
117  return false;
118 }
119 
120 QDomElement SonixProbeFileReader::getChildWithTag(QDomNode parent, QString tagName)
121 {
122  QDomNode probesNode = parent.firstChild();
123  QDomElement retval;
124  while(!probesNode.isNull() && retval.isNull())
125  {
126  retval = probesNode.toElement();
127  if(!retval.isNull())
128  {
129  if(retval.tagName() != tagName)
130  {
131  retval = QDomElement();
132  probesNode = probesNode.nextSibling();
133  }
134  }
135  }
136  return retval;
137 }
138 
139 long SonixProbeFileReader::getProbeLenght(QDomNode probeNode)
140 {
141  long retval = this->getProbeParam(probeNode, "pitch") * this->getProbeParam(probeNode, "numElements");
142  return retval;
143 }
144 
145 long SonixProbeFileReader::getProbeParam(QDomNode probeNode, QString param)
146 {
147  QDomElement element = this->getChildWithTag(probeNode, param);
148  QString val = element.text();
149  return val.toLong();
150 }
151 
152 } //namespace cx
QDomElement getProbes()
Traverse top level nodes. Return first node where tag=="probes".
SonixProbeFileReader(QString probeFile)
bool isProbeLinear(QDomNode probeNode)
long getProbeLenght(QDomNode probeNode)
QDomNode getProbeNode(QString probeName)
Traverse all first childs of the probes node. Return the first node where attribute name==probeName...
long getProbeParam(QDomNode probeNode, QString param)