-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENH: Support for binary point file (.bin) reading and writing #943
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,3 +38,5 @@ CMakeFiles/ | |
CTestTestfile.cmake | ||
.idea/ | ||
.githooks/clangFormatMac | ||
/cmake-build-debug/ | ||
/build/ | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,30 +40,60 @@ TransformixInputPointFileReader<TOutputMesh>::GenerateOutputInformation() | |
{ | ||
this->m_Reader.close(); | ||
} | ||
this->m_Reader.open(this->m_FileName); | ||
|
||
/** Read the first entry */ | ||
std::string indexOrPoint; | ||
this->m_Reader >> indexOrPoint; | ||
if( this->m_Binary ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use automatic code formatting by clang-format. It looks like this code still needs to be formatted that way, as I would expect it to place the |
||
this->m_Reader.open(this->m_FileName, std::ios::binary); | ||
|
||
/** Read index flag */ | ||
unsigned long isindex; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry to say the use of (signed or unsigned) |
||
this->m_Reader.read((char*) &isindex, sizeof(isindex)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of C-style |
||
|
||
if( isindex == 0 ) | ||
{ | ||
/** Input points are specified in world coordinates. */ | ||
this->m_PointsAreIndices = false; | ||
} | ||
else //if( indexOrPoint == 1 ) | ||
{ | ||
/** Input points are specified as image indices. */ | ||
this->m_PointsAreIndices = true; | ||
} | ||
|
||
/** Read number of points */ | ||
unsigned long nrofpoints; | ||
this->m_Reader.read((char*) &nrofpoints, sizeof(nrofpoints)); | ||
this->m_NumberOfPoints = nrofpoints; | ||
|
||
/** Leave the file open for the generate data method */ | ||
|
||
/** Set the IsIndex bool and the number of points.*/ | ||
if (indexOrPoint == "point") | ||
{ | ||
/** Input points are specified in world coordinates. */ | ||
this->m_PointsAreIndices = false; | ||
this->m_Reader >> this->m_NumberOfPoints; | ||
} | ||
else if (indexOrPoint == "index") | ||
{ | ||
/** Input points are specified as image indices. */ | ||
this->m_PointsAreIndices = true; | ||
this->m_Reader >> this->m_NumberOfPoints; | ||
} | ||
else | ||
else //if( this->m_Binary ) | ||
{ | ||
/** Input points are assumed to be specified as image indices. */ | ||
this->m_PointsAreIndices = true; | ||
this->m_NumberOfPoints = atoi(indexOrPoint.c_str()); | ||
this->m_Reader.open(this->m_FileName); | ||
|
||
/** Read the first entry */ | ||
std::string indexOrPoint; | ||
this->m_Reader >> indexOrPoint; | ||
|
||
/** Set the IsIndex bool and the number of points.*/ | ||
if (indexOrPoint == "point") | ||
{ | ||
/** Input points are specified in world coordinates. */ | ||
this->m_PointsAreIndices = false; | ||
this->m_Reader >> this->m_NumberOfPoints; | ||
} | ||
else if (indexOrPoint == "index") | ||
{ | ||
/** Input points are specified as image indices. */ | ||
this->m_PointsAreIndices = true; | ||
this->m_Reader >> this->m_NumberOfPoints; | ||
} | ||
else | ||
{ | ||
/** Input points are assumed to be specified as image indices. */ | ||
this->m_PointsAreIndices = true; | ||
this->m_NumberOfPoints = atoi(indexOrPoint.c_str()); | ||
} | ||
} | ||
|
||
/** Leave the file open for the generate data method */ | ||
|
@@ -90,6 +120,27 @@ TransformixInputPointFileReader<TOutputMesh>::GenerateData() | |
/** Read the file */ | ||
if (this->m_Reader.is_open()) | ||
{ | ||
if( this->m_Binary ){ | ||
for( unsigned long i = 0; i < this->m_NumberOfPoints; ++i ) | ||
{ | ||
// read point from binary file | ||
PointType point; | ||
|
||
if( !this->m_Reader.eof() ) | ||
{ | ||
this->m_Reader.read((char*) &point, sizeof(point)); | ||
} else { | ||
std::ostringstream msg; | ||
msg << "The file is not large enough. " | ||
<< std::endl << "Filename: " << this->m_FileName | ||
<< std::endl; | ||
MeshFileReaderException e( __FILE__, __LINE__, msg.str().c_str(), ITK_LOCATION ); | ||
throw e; | ||
} | ||
points->push_back( point ); | ||
} | ||
} | ||
else //if( this->m_Binary ){ | ||
for (unsigned int i = 0; i < this->m_NumberOfPoints; ++i) | ||
{ | ||
// read point from textfile | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to see this as a separate commit. (Following the principle of "One Commit. One Change.") Why do those directories appear in your source tree? Are they specific to a particular tool or platform? I'm fine with the change itself, but I would like some clarification!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, sorry for the late reply due to other obligations.
This can be safely ignored, i did not realize this change in .gitignore