MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkNDIPassiveTool.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
13#include "mitkNDIPassiveTool.h"
14#include <iostream>
15#include <fstream>
16
17
18mitk::NDIPassiveTool::NDIPassiveTool()
19: TrackingTool(),
20m_SROMData(nullptr),
21m_SROMDataLength(0),
22m_TrackingPriority(Dynamic),
23m_PortHandle()
24{
25}
26
27
29{
30 if (m_SROMData != nullptr)
31 {
32 delete[] m_SROMData;
33 m_SROMData = nullptr;
34 }
35}
36
37
38bool 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
71const unsigned char* mitk::NDIPassiveTool::GetSROMData() const
72{
73 return m_SROMData;
74}
75
76
78{
79 return m_SROMDataLength;
80}
virtual unsigned int GetSROMDataLength() const
get length of SROMData char array
virtual bool LoadSROMFile(const char *filename)
load a srom tool description file
unsigned char * m_SROMData
content of the srom tool description file
virtual const unsigned char * GetSROMData() const
get loaded srom file as unsigned char array