STL Reader Binary/ASCII destinguishing wrong
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
I compiled VTK 4.2.2 with VS7 on XP Out of vtkstlreader.cxx, my comments start with -->
// Initialize // if ((fp = fopen(this->FileName, "r")) == NULL) --> this opens the file in ascii mode, and thus getstlfiletype will also use ascii mode to query the file { vtkErrorMacro(<< "File " << this->FileName << " not found"); return; }
newPts = vtkPoints::New(); newPts->Allocate(5000,10000); newPolys = vtkCellArray::New(); newPolys->Allocate(10000,20000);
// Depending upon file type, read differently // if ( this->GetSTLFileType(fp) == VTK_ASCII ) --> because fp is open in "r" mode, if there is a character 26 in a binary file, then this will be interpreted as EOF, giving maybe a wrong result, because no illegal character for ascii will be found. { if (ScalarTags) { newScalars = vtkFloatArray::New(); newScalars->Allocate(5000,10000); } if ( this->ReadASCIISTL(fp,newPts,newPolys,newScalars) ) { return; } } else { fclose(fp); fp = fopen(this->FileName, "rb");
if ( this->ReadBinarySTL(fp,newPts,newPolys) )
{
return;
}
}
My proposed solution is obviously: // Initialize // if ((fp = fopen(this->FileName, "rb")) == NULL) { vtkErrorMacro(<< "File " << this->FileName << " not found"); return; }
newPts = vtkPoints::New(); newPts->Allocate(5000,10000); newPolys = vtkCellArray::New(); newPolys->Allocate(10000,20000);
// Depending upon file type, read differently // if ( this->GetSTLFileType(fp) == VTK_ASCII ) { fclose(fp); fp = fopen(this->FileName, "r"); if (ScalarTags) { newScalars = vtkFloatArray::New(); newScalars->Allocate(5000,10000); } if ( this->ReadASCIISTL(fp,newPts,newPolys,newScalars) ) { return; } } else {
if ( this->ReadBinarySTL(fp,newPts,newPolys) )
{
return;
}
}
Greetings Gregi