Commit c6667732 authored by Stephen Aylward's avatar Stephen Aylward
Browse files

BUG: Fixed bugs in Form and hidden virtual funcs in Image

parent 09efa171
......@@ -117,7 +117,7 @@ IF(WIN32)
ENDIF(WIN32)
#SUBDIRS(tests)
SUBDIRS(tests)
if(NOT METAIO_INSTALL_NO_LIBRARIES)
install(TARGETS ${METAIO_NAMESPACE}
......
......@@ -578,16 +578,6 @@ GetUserField(const char* _name)
return NULL;
}
bool MetaForm::
AddUserField(const char* _fieldName, MET_ValueEnumType _type, int _length,
bool _required, int _dependsOn)
{
MET_FieldRecordType* mFr = new MET_FieldRecordType;
MET_InitReadField(mFr,_fieldName, _type, _required,_dependsOn,_length);
m_UserDefinedReadFields.push_back(mFr);
return 1;
}
//
//
//
......@@ -617,6 +607,9 @@ Read(const char *_fileName)
strcpy(m_FileName, _fileName);
}
METAIO_STREAM::cout << "Read FileName = _" << m_FileName << "_"
<< METAIO_STREAM::endl;
METAIO_STREAM::ifstream * tmpReadStream = new METAIO_STREAM::ifstream;
#ifdef __sgi
tmpReadStream->open(m_FileName, METAIO_STREAM::ios::in);
......@@ -700,6 +693,9 @@ Write(const char *_fileName)
FileName(_fileName);
}
METAIO_STREAM::cout << "Write FileName = _" << m_FileName << "_"
<< METAIO_STREAM::endl;
METAIO_STREAM::ofstream * tmpWriteStream = new METAIO_STREAM::ofstream;
#ifdef __sgi
......@@ -708,15 +704,16 @@ Write(const char *_fileName)
METAIO_STREAM::ofstream tFile(m_FileName, METAIO_STREAM::ios::out);
tFile.close();
}
tmpWriteStream->open(_fileName, METAIO_STREAM::ios::out);
tmpWriteStream->open(m_FileName, METAIO_STREAM::ios::out);
#else
tmpWriteStream->open(_fileName, METAIO_STREAM::ios::binary |
tmpWriteStream->open(m_FileName, METAIO_STREAM::ios::binary |
METAIO_STREAM::ios::out);
#endif
if(!tmpWriteStream->rdbuf()->is_open())
{
delete tmpWriteStream;
METAIO_STREAM::cout << "Write failed." << METAIO_STREAM::endl;
return false;
}
......
......@@ -111,12 +111,6 @@ class METAIO_EXPORT MetaForm
void * GetUserField(const char* _name);
bool AddUserField(const char* _fieldName,
MET_ValueEnumType _type,
int _length=0,
bool _required=true,
int _dependsOn=-1);
template <class TType>
bool AddUserField(const char* _fieldName,
MET_ValueEnumType _type,
......@@ -140,11 +134,11 @@ class METAIO_EXPORT MetaForm
//
//
//
virtual bool CanRead(const char * _fileName=NULL) const;
bool CanRead(const char * _fileName=NULL) const;
bool Read(const char * _fileName=NULL);
virtual bool CanReadStream(METAIO_STREAM::ifstream * _stream) const;
bool CanReadStream(METAIO_STREAM::ifstream * _stream) const;
bool ReadStream(METAIO_STREAM::ifstream * _stream);
......
......@@ -105,7 +105,7 @@ class METAIO_EXPORT MetaImage : public MetaObject
virtual void Clear(void);
virtual bool InitializeEssential(int _nDims,
bool InitializeEssential(int _nDims,
const int * _dimSize,
const float * _elementSpacing,
MET_ValueEnumType _elementType,
......@@ -234,13 +234,13 @@ class METAIO_EXPORT MetaImage : public MetaObject
//
//
//
virtual bool CanRead(const char *_headerName=NULL) const;
bool CanRead(const char *_headerName=NULL) const;
virtual bool Read(const char *_headerName=NULL,
bool Read(const char *_headerName=NULL,
bool _readElements=true,
void * _buffer=NULL);
virtual bool ReadROI(int * _indexMin, int * _indexMax,
bool ReadROI(int * _indexMin, int * _indexMax,
const char *_headerName=NULL,
bool _readElements=true,
void * _buffer=NULL,
......@@ -248,27 +248,27 @@ class METAIO_EXPORT MetaImage : public MetaObject
);
virtual bool CanReadStream(METAIO_STREAM::ifstream * _stream) const;
bool CanReadStream(METAIO_STREAM::ifstream * _stream) const;
virtual bool ReadStream(int _nDims,
bool ReadStream(int _nDims,
METAIO_STREAM::ifstream * _stream,
bool _readElements=true,
void * _buffer=NULL);
virtual bool ReadROIStream(int * _indexMin, int * _indexMax,
bool ReadROIStream(int * _indexMin, int * _indexMax,
int _nDims,
METAIO_STREAM::ifstream * _stream,
bool _readElements=true,
void * _buffer=NULL,
unsigned int subSamplingFactor=1);
virtual bool Write(const char *_headName=NULL,
bool Write(const char *_headName=NULL,
const char *_dataName=NULL,
bool _writeElements=true,
const void * _constElementData=NULL,
bool _append=false);
virtual bool WriteROI(int * _indexMin, int * _indexMax,
bool WriteROI(int * _indexMin, int * _indexMax,
const char *_headName=NULL,
const char *_dataName=NULL,
bool _writeElements=true,
......@@ -276,12 +276,12 @@ class METAIO_EXPORT MetaImage : public MetaObject
bool _append=false
);
virtual bool WriteStream(METAIO_STREAM::ofstream * _stream,
bool WriteStream(METAIO_STREAM::ofstream * _stream,
bool _writeElements=true,
const void * _constElementData=NULL);
virtual bool Append(const char *_headName=NULL);
bool Append(const char *_headName=NULL);
typedef METAIO_STL::pair<long,long> CompressionOffsetType;
......@@ -327,13 +327,13 @@ class METAIO_EXPORT MetaImage : public MetaObject
char m_ElementDataFileName[255];
void M_Destroy(void);
virtual void M_Destroy(void);
void M_SetupReadFields(void);
virtual void M_SetupReadFields(void);
void M_SetupWriteFields(void);
virtual void M_SetupWriteFields(void);
bool M_Read(void);
virtual bool M_Read(void);
// _dataQuantity is expressed in number of pixels. Internally it will be
// scaled by the number of components and number of bytes per component.
......
......@@ -130,7 +130,7 @@ METAIO_STL::string MET_ReadForm(METAIO_STREAM::istream &_fp)
METAIO_STL::streampos pos = _fp.tellg();
METAIO_STL::vector<MET_FieldRecordType *> fields;
MET_FieldRecordType* mF = new MET_FieldRecordType;
MET_InitReadField(mF, "Form", MET_STRING, false);
MET_InitReadField(mF, "FormTypeName", MET_STRING, false);
mF->required = false;
mF->terminateRead = true;
fields.push_back(mF);
......
......@@ -35,19 +35,23 @@ int main(int argc, char **argv)
tObj.Clear();
tObj.ClearUserFields();
tObj.AddUserField("MyName", MET_STRING);
tObj.AddUserField("MyArray", MET_INT_ARRAY,3);
tObj.AddUserField("MyMatrix", MET_FLOAT_MATRIX,2);
tObj.AddUserField("MyName", MET_STRING, strlen("default"), "default");
tObj.AddUserField("MyArray", MET_INT_ARRAY, 3, myarray);
tObj.AddUserField("MyMatrix", MET_FLOAT_MATRIX, 2, myMatrix);
METAIO_STREAM::cout << "Read: " << METAIO_STREAM::endl;
tObj.Read();
METAIO_STREAM::cout << "PrintInfo: " << METAIO_STREAM::endl;
tObj.PrintInfo();
METAIO_STREAM::cout << "Check fields: " << METAIO_STREAM::endl;
char* name = static_cast<char*>(tObj.GetUserField("MyName"));
if(strcmp(name,"Julien"))
if(!strcmp(name,"Julien"))
{
METAIO_STREAM::cout << "MyName: FAIL" << METAIO_STREAM::endl;
return 0;
}
METAIO_STREAM::cout << "MyName: " << name << METAIO_STREAM::endl;
int* array = static_cast<int*>(tObj.GetUserField("MyArray"));
......@@ -59,6 +63,7 @@ int main(int argc, char **argv)
return 0;
}
}
METAIO_STREAM::cout << "MyArray: PASS" << METAIO_STREAM::endl;
float* matrix = static_cast<float*>(tObj.GetUserField("MyMatrix"));
for(i=0; i<4; i++)
......@@ -68,6 +73,7 @@ int main(int argc, char **argv)
METAIO_STREAM::cout << "MyMatrix: FAIL" << METAIO_STREAM::endl;
}
}
METAIO_STREAM::cout << "MyMatrix: PASS" << METAIO_STREAM::endl;
METAIO_STREAM::cout << "PASSED!" << METAIO_STREAM::endl;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment