Menu

[r262]: / src / programs / BrainRegis / FeatureBase.cpp  Maximize  Restore  History

Download this file

173 lines (150 with data), 3.8 kB

  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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
* FeatureBase.cpp
* FeatureFinder
*
* Created by Cindy Grimm on 10/26/10.
* Copyright 2010 Washington University in St. Louis. All rights reserved.
*
*/
#include "SF_FeatureBase.H"
#include "SF_FeatureMeshPointInfo.H"
void FeatureBase::Clear()
{
for ( int i = 0; i < m_aopPerMeshInfo.size(); i++ ) {
delete m_aopPerMeshInfo[i];
}
m_aopPerMeshInfo.resize(0);
}
void FeatureBase::Add( const int in_iN )
{
Clear();
m_aopPerMeshInfo.resize( in_iN );
for ( int i = 0; i < m_aopPerMeshInfo.size(); i++ ) {
switch ( m_type ) {
case POINT :
m_aopPerMeshInfo[i] = new FeatureMeshPointInfo;
break;
default :
cout << "Feature type not yet implemented\n";
break;
}
}
}
void FeatureBase::Set( const FeatureType &in_type, const std::string &in_str, const int in_iNMeshes )
{
m_strName = in_str;
if ( m_type != in_type || m_aopPerMeshInfo.size() != in_iNMeshes ) {
m_type = in_type;
Add( in_iNMeshes );
}
}
FeatureBase::~FeatureBase()
{
Clear();
}
void FeatureMeshInfo::Write( ofstream &out ) const
{
out << m_bComplete << "\n";
}
void FeatureMeshInfo::Read( ifstream &in )
{
char c;
in >> c;
if ( c == 't' || c == '1' ) {
m_bComplete = true;
} else {
m_bComplete = false;
}
}
void FeatureBase::Write( ofstream &out ) const
{
out << "Type ";
switch ( m_type ) {
case POINT :
out << "point ";
break;
case LINE :
out << "line ";
break;
case REGION :
out << "region ";
break;
case AXIS :
out << "axis ";
break;
default :
ASSERT(FALSE);
cout << "Not recognized\n";
}
out << m_strName << " " << m_aopPerMeshInfo.size() << "\n";
for ( int i = 0; i < m_aopPerMeshInfo.size(); i++ ) {
m_aopPerMeshInfo[i]->Write( out );
}
out << "End\n";
}
void FeatureBase::Read( ifstream &in )
{
string str;
in >> str;
ASSERT( !str.compare("Type") );
in >> str;
if ( !str.compare("point") ) {
m_type = POINT;
} else if ( !str.compare("line") ) {
m_type = LINE;
} else if ( !str.compare("region") ) {
m_type = REGION;
} else if ( !str.compare("axis") ) {
m_type = AXIS;
} else {
cout << "Type " << str << " not recognized\n";
ASSERT(FALSE);
}
in >> m_strName;
int iN = 0;
in >> iN;
Add( iN );
for ( int i = 0; i < m_aopPerMeshInfo.size(); i++ ) {
m_aopPerMeshInfo[i]->Read( in );
}
in >> str;
ASSERT( !str.compare("End") );
}
void Write( const Array<FeatureBase *> &in_aop, ofstream &out )
{
out << in_aop.num() << "\n";
for ( int i = 0; i < in_aop.num(); i++ ) {
in_aop[i]->Write(out);
}
}
void Write( const Array<FeatureBase *> &in_aop, const std::string &in_str )
{
ofstream out( in_str.c_str(), ios::out );
Write( in_aop, out );
out.close();
}
void Read( Array<FeatureBase *> &out_aop, ifstream &in )
{
for ( int i = 0; i < out_aop.num(); i++ ) {
delete out_aop[i];
}
out_aop.need(0);
if ( !in.good() ) return;
int iN = 0;
in >> iN;
out_aop.need(iN);
for ( FORINT i = 0; i < out_aop.num(); i++ ) {
out_aop[i] = new FeatureBase;
out_aop[i]->Read(in);
}
}
void Read( Array<FeatureBase *> &out_aop, const std::string &in_str )
{
ifstream in(in_str.c_str(), ios::in);
if ( in.good() ) {
Read( out_aop, in);
} else {
cerr << "Reading feature base: file not good " << in_str << "\n";
}
in.close();
}