Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
VTK
VTK
Commits
a00719d9
Commit
a00719d9
authored
Mar 03, 1994
by
Will Schroeder
Browse files
ENH: Added error checking for bad binary files.
parent
e5ebd8b9
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/STLRead.hh
View file @
a00719d9
...
...
@@ -37,8 +37,8 @@ public:
protected:
char
*
Filename
;
void
Execute
();
void
ReadBinarySTL
(
FILE
*
fp
,
vlFloatPoints
*
,
vlCellArray
*
);
void
ReadASCIISTL
(
FILE
*
fp
,
vlFloatPoints
*
,
vlCellArray
*
);
int
ReadBinarySTL
(
FILE
*
fp
,
vlFloatPoints
*
,
vlCellArray
*
);
int
ReadASCIISTL
(
FILE
*
fp
,
vlFloatPoints
*
,
vlCellArray
*
);
int
GetSTLFileType
(
FILE
*
fp
);
};
...
...
src/STLRead.cc
View file @
a00719d9
...
...
@@ -44,11 +44,11 @@ void vlSTLReader::Execute()
//
if
(
this
->
GetSTLFileType
(
fp
)
==
ASCII
)
{
this
->
ReadASCIISTL
(
fp
,
newPts
,
newPolys
);
if
(
this
->
ReadASCIISTL
(
fp
,
newPts
,
newPolys
)
)
return
;
}
else
{
this
->
ReadBinarySTL
(
fp
,
newPts
,
newPolys
);
if
(
this
->
ReadBinarySTL
(
fp
,
newPts
,
newPolys
)
)
return
;
}
vlDebugMacro
(
<<
"Read "
<<
newPts
->
NumberOfPoints
()
<<
" points
\n
"
);
...
...
@@ -66,9 +66,9 @@ void vlSTLReader::Execute()
this
->
SetPolys
(
newPolys
);
}
void
vlSTLReader
::
ReadBinarySTL
(
FILE
*
fp
,
vlFloatPoints
*
newPts
,
vlCellArray
*
newPolys
)
int
vlSTLReader
::
ReadBinarySTL
(
FILE
*
fp
,
vlFloatPoints
*
newPts
,
vlCellArray
*
newPolys
)
{
int
i
,
n
o_t
ris
,
pts
[
3
];
int
i
,
n
umT
ris
,
pts
[
3
];
unsigned
long
ulint
;
unsigned
short
ibuff2
;
char
header
[
81
];
...
...
@@ -83,9 +83,13 @@ void vlSTLReader::ReadBinarySTL(FILE *fp, vlFloatPoints *newPts, vlCellArray *ne
fread
(
header
,
1
,
80
,
fp
);
fread
(
&
ulint
,
1
,
4
,
fp
);
swap
.
Swap4
(
&
ulint
);
no_tris
=
(
int
)
ulint
;
if
(
(
numTris
=
(
int
)
ulint
)
<=
0
)
{
vlErrorMacro
(
<<
"Bad binary STL file
\n
"
);
return
1
;
}
for
(
i
=
0
;
fread
(
&
facet
,
48
,
1
,
fp
)
&&
i
<
n
o_t
ris
;
i
++
)
for
(
i
=
0
;
fread
(
&
facet
,
48
,
1
,
fp
)
&&
i
<
n
umT
ris
;
i
++
)
{
fread
(
&
ibuff2
,
2
,
1
,
fp
);
/* read extra junk */
...
...
@@ -111,14 +115,13 @@ void vlSTLReader::ReadBinarySTL(FILE *fp, vlFloatPoints *newPts, vlCellArray *ne
newPolys
->
InsertNextCell
(
3
,
pts
);
if
(
this
->
Debug
&&
(
i
%
5000
)
==
0
&&
i
!=
0
)
fprintf
(
stderr
,
"%s: triangle #%d
\n
"
,
this
->
GetClassName
(),
newPolys
->
GetNumberOfCells
());
fprintf
(
stderr
,
"%s: triangle #%d
\n
"
,
this
->
GetClassName
(),
i
);
}
return
;
return
0
;
}
void
vlSTLReader
::
ReadASCIISTL
(
FILE
*
fp
,
vlFloatPoints
*
newPts
,
vlCellArray
*
newPolys
)
int
vlSTLReader
::
ReadASCIISTL
(
FILE
*
fp
,
vlFloatPoints
*
newPts
,
vlCellArray
*
newPolys
)
{
char
line
[
256
];
int
i
;
...
...
@@ -151,7 +154,7 @@ void vlSTLReader::ReadASCIISTL(FILE *fp, vlFloatPoints *newPts, vlCellArray *new
fprintf
(
stderr
,
"%s: triangle #%d
\n
"
,
this
->
GetClassName
(),
newPolys
->
GetNumberOfCells
());
}
return
;
return
0
;
}
int
vlSTLReader
::
GetSTLFileType
(
FILE
*
fp
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment