Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkNDIPassiveTool.h"
18 #include <iostream>
19 #include <fstream>
20 
21 
24 m_SROMData(nullptr),
25 m_SROMDataLength(0),
26 m_TrackingPriority(Dynamic),
27 m_PortHandle()
28 {
29 }
30 
31 
33 {
34  if (m_SROMData != nullptr)
35  {
36  delete[] m_SROMData;
37  m_SROMData = nullptr;
38  }
39 }
40 
41 
43 {
44  if (filename == nullptr)
45  return false;
46  if (filename[0] == '\0')
47  return false;
48 
49  m_File = filename;
50  std::basic_ifstream<char> file;
51  file.open(filename, std::ios::in | std::ios::binary); // open the file
52  if (file.is_open() == false)
53  return false;
54 
55  file.seekg (0, std::ios::end); // get the length of the file
56  unsigned int newLength = file.tellg();
57  file.seekg (0, std::ios::beg);
58  auto newData = new char [newLength]; // create a buffer to store the srom file
59  file.read(newData, newLength); // read the file into the buffer
60  file.close();
61  if (file.fail() == true) // reading of data unsuccessful?
62  {
63  delete[] newData;
64  return false;
65  }
66  if (m_SROMData != nullptr) // reading was successful, delete old data
67  delete[] m_SROMData;
68  m_SROMDataLength = newLength; // set member variables to new values
69  m_SROMData = (unsigned char*) newData;
70  this->Modified();
71  return true;
72 }
73 
74 
75 const unsigned char* mitk::NDIPassiveTool::GetSROMData() const
76 {
77  return m_SROMData;
78 }
79 
80 
82 {
83  return m_SROMDataLength;
84 }
virtual bool LoadSROMFile(const char *filename)
load a srom tool description file
implements TrackingTool interface
virtual unsigned int GetSROMDataLength() const
get length of SROMData char array
static const std::string filename
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