File: igstkFiducialsPlanIO.cxx

package info (click to toggle)
igstk 4.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 36,940 kB
  • ctags: 6,895
  • sloc: cpp: 70,958; makefile: 99; xml: 70
file content (105 lines) | stat: -rw-r--r-- 2,604 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*=========================================================================

Program:   Image Guided Surgery Software Toolkit
Module:    $RCSfile: igstkFiducialsPlanIO.cxx,v $
Language:  C++
Date:      $Date: 2009-02-03 15:59:03 $
Version:   $Revision: 1.1 $

Copyright (c) ISC  Insight Software Consortium.  All rights reserved.
  See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.

This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.  See the above copyright notices for more information.

=========================================================================*/

#include "igstkFiducialsPlanIO.h"
#include "stdio.h"

namespace igstk
{

/** Constructor: Initializes all internal variables. */
FiducialsPlanIO::FiducialsPlanIO()
{
  m_FiducialsPlan = new FiducialsPlan;
  m_FileName      = "";
}

int FiducialsPlanIO::RequestRead()
{

  std::ifstream planFile( m_FileName.c_str() );
  if ( planFile.is_open())
    {
    std::string line;
    float p[3];

    std::getline( planFile, line ); // First line, description, starts with #
    if ( line[0] != '#')
      {
      std::cerr << "Incorrect file format!\n";
      planFile.close();
      return 0;
      }
    m_FiducialsPlan->m_FiducialPoints.clear();
    while ( std::getline( planFile, line ) )
      {
      if( sscanf( line.c_str(), "%f %f %f", &p[0], &p[1], &p[2]) != 3 )
        {
        std::cerr << "Incorrect file format!\n";
        planFile.close();
        return 0;
        }
      FiducialsPlan::PointType fp;
      fp[0] = p[0];
      fp[1] = p[1];
      fp[2] = p[2];
      m_FiducialsPlan->m_FiducialPoints.push_back( fp );
      }
    if (m_FiducialsPlan->m_FiducialPoints.size()<3)
      {
      std::cerr << "At least 3 fiducial points needed!\n";
      planFile.close();
      return 0;
      }
    planFile.close();
    return 1;
    }
  else
    {
    return 0;
    }  
}

int FiducialsPlanIO::RequestWrite()
{
  std::ofstream  planFile;
  planFile.open( m_FileName.c_str(), ios::trunc );
  if ( planFile.is_open())
    {
    std::string line;
    FiducialsPlan::PointType p;

    planFile << "# Fiducial points\n"; // First line, description
    for ( unsigned int i=0; i<m_FiducialsPlan->m_FiducialPoints.size(); i++)
      {
      p = m_FiducialsPlan->m_FiducialPoints[i];
      planFile << p[0] << "\t" << p[1] << "\t" << p[2] << "\n";
      }
    planFile.close();
    return 1;
    }
  else
    {
    return 0;
    }  
}
/** Destructor */
FiducialsPlanIO::~FiducialsPlanIO()
{

}
} // end of namespace