NorMIT-nav  18.04-rc6
An IGT application
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) 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 #include "cxSonixProbeFileReader.h"
12 #include <iostream>
13 #include <QFile>
14 #include <QDomDocument>
15 #include "cxTypeConversions.h"
16 
17 namespace cx {
18 
20  mFile(probeFile)
21 {
22 }
23 
25 {
26  if(!this->openFile())
27  return false;
28 
29  if(!this->openDomDocument())
30  return false;
31 
32  if(!this->openDocumentElement())
33  return false;
34 
35  return true;
36 }
37 
38 bool SonixProbeFileReader::openFile()
39 {
40  if(!mFile.open(QIODevice::ReadOnly))
41  return false;
42 
43  return true;
44 }
45 
46 bool SonixProbeFileReader::openDomDocument()
47 {
48  if(!mDoc.setContent(&mFile))
49  {
50  mFile.close();
51  return false;
52  }
53  return true;
54 }
55 
56 bool SonixProbeFileReader::openDocumentElement()
57 {
58  mDocElem = mDoc.documentElement();
59  if(mDocElem.isNull())
60  return false;
61 
62  return true;
63 }
64 
65 QDomNode SonixProbeFileReader::getProbeNode(QString probeName)
66 {
67  QDomElement probes = this->getProbes();
68  QDomNode probeNode = probes.firstChild();
69  QDomElement retval;
70  while(!probeNode.isNull() && retval.isNull())
71  {
72  retval = probeNode.toElement();
73  if(!retval.isNull())
74  {
75  if(retval.attribute("name") != probeName)
76  {
77  retval = QDomElement();
78  probeNode = probeNode.nextSibling();
79  }
80  }
81  }
82  return retval;
83 }
84 
86 {
87  return this->getChildWithTag(mDocElem, "probes");
88 }
89 
90 bool SonixProbeFileReader::isProbeLinear(QDomNode probeNode)
91 {
92  QDomElement type = this->getChildWithTag(probeNode, "type");
93  if (type.text() == "2")
94  return true;
95 
96  return false;
97 }
98 
99 QDomElement SonixProbeFileReader::getChildWithTag(QDomNode parent, QString tagName)
100 {
101  QDomNode probesNode = parent.firstChild();
102  QDomElement retval;
103  while(!probesNode.isNull() && retval.isNull())
104  {
105  retval = probesNode.toElement();
106  if(!retval.isNull())
107  {
108  if(retval.tagName() != tagName)
109  {
110  retval = QDomElement();
111  probesNode = probesNode.nextSibling();
112  }
113  }
114  }
115  return retval;
116 }
117 
118 long SonixProbeFileReader::getProbeLenght(QDomNode probeNode)
119 {
120  long retval = this->getProbeParam(probeNode, "pitch") * this->getProbeParam(probeNode, "numElements");
121  return retval;
122 }
123 
124 long SonixProbeFileReader::getProbeParam(QDomNode probeNode, QString param)
125 {
126  QDomElement element = this->getChildWithTag(probeNode, param);
127  QString val = element.text();
128  return val.toLong();
129 }
130 
131 } //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)
Namespace for all CustusX production code.