Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkNDIPassiveTool.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkNDIPassiveTool.h"
14 #include <iostream>
15 #include <fstream>
16 
17 
19 : TrackingTool(),
20 m_SROMData(nullptr),
21 m_SROMDataLength(0),
22 m_TrackingPriority(Dynamic),
23 m_PortHandle()
24 {
25 }
26 
27 
29 {
30  if (m_SROMData != nullptr)
31  {
32  delete[] m_SROMData;
33  m_SROMData = nullptr;
34  }
35 }
36 
37 
38 bool mitk::NDIPassiveTool::LoadSROMFile(const char* filename)
39 {
40  if (filename == nullptr)
41  return false;
42  if (filename[0] == '\0')
43  return false;
44 
45  m_File = filename;
46  std::basic_ifstream<char> file;
47  file.open(filename, std::ios::in | std::ios::binary); // open the file
48  if (file.is_open() == false)
49  return false;
50 
51  file.seekg (0, std::ios::end); // get the length of the file
52  unsigned int newLength = file.tellg();
53  file.seekg (0, std::ios::beg);
54  auto newData = new char [newLength]; // create a buffer to store the srom file
55  file.read(newData, newLength); // read the file into the buffer
56  file.close();
57  if (file.fail() == true) // reading of data unsuccessful?
58  {
59  delete[] newData;
60  return false;
61  }
62  if (m_SROMData != nullptr) // reading was successful, delete old data
63  delete[] m_SROMData;
64  m_SROMDataLength = newLength; // set member variables to new values
65  m_SROMData = (unsigned char*) newData;
66  this->Modified();
67  return true;
68 }
69 
70 
71 const unsigned char* mitk::NDIPassiveTool::GetSROMData() const
72 {
73  return m_SROMData;
74 }
75 
76 
78 {
79  return m_SROMDataLength;
80 }
Interface for all Tracking Tools.
unsigned char * m_SROMData
content of the srom tool description file
virtual bool LoadSROMFile(const char *filename)
load a srom tool description file
std::string m_File
the original file from which this tool was loaded
unsigned int m_SROMDataLength
length of the srom tool description file
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
Definition: jsoncpp.cpp:244
virtual const unsigned char * GetSROMData() const
get loaded srom file as unsigned char array
virtual unsigned int GetSROMDataLength() const
get length of SROMData char array