Mesh Oriented datABase
(version 5.5.1)
An array-based unstructured mesh library
ReadSTL.hpp
Go to the documentation of this file.
1
/**
2
* MOAB, a Mesh-Oriented datABase, is a software component for creating,
3
* storing and accessing finite element mesh data.
4
*
5
* Copyright 2004 Sandia Corporation. Under the terms of Contract
6
* DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
7
* retains certain rights in this software.
8
*
9
* This library is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU Lesser General Public
11
* License as published by the Free Software Foundation; either
12
* version 2.1 of the License, or (at your option) any later version.
13
*
14
*/
15
16
#ifndef READ_STL_HPP
17
#define READ_STL_HPP
18
19
#include <cstdio>
20
#include "
moab/Forward.hpp
"
21
#include "
moab/ReaderIface.hpp
"
22
23
namespace
moab
24
{
25
26
class
ReadUtilIface;
27
28
/**
29
* \brief ASCII and Binary Stereo Lithography File readers.
30
* \author Jason Kraftcheck
31
*
32
* STL files contain no connectivity infomration. Each triangle
33
* is specified as by three sets of single-precision coordinate
34
* triples. This reader does not use ANY tolerance when comparing
35
* vertex locations to recover connectivity. The points must be
36
* EXACTLY equal (including the sign on zero values.) If the file
37
* was written by an application which represented connectivity
38
* explicitly, there is no reason for the vertex coordinates to
39
* be anything other than exactly equal.
40
*
41
* For binary STL files, the defacto standard is that they be written
42
* with a little-endian byte order. The reader will attempt to
43
* determine the byte order automatically, and if it is ambiguous,
44
* will default to little-endian. The byte ordering may be forced by
45
* by creating an integer tag named "__STL_BYTE_ORDER" and setting a
46
* global/mesh value for the tag as 1 for big-endian or 0 for
47
* little-endian.
48
*
49
* For binary files, this reader relies on the file size to determine
50
* the validity of the file and may use it in guessing the byte order.
51
* This should not be an issue, as the file size can be determined
52
* exactly from the number of triangles for a valid file. However, if
53
* for some reason the file is readable even though it is invalid (e.g.
54
* it is some hybrid file with STL data in the beginning and some app-
55
* specific data appended to the end of the file) the check on the file
56
* size can be disabled by giving the reader a something other than a
57
* regular file to read from. For example, on Unix-like systems, have
58
* the reader read from a FIFO instead of a file:
59
* mkfifo /tmp/fifo.stlb
60
* cat my_binary_file.stlb > /tmp/fifo.stlb
61
* and instruct the MOAB-based application to read from /tmp/fifo.stlb
62
*/
63
class
ReadSTL
:
public
ReaderIface
64
{
65
66
public
:
67
//! factory method for STL reader
68
static
ReaderIface
*
factory
(
Interface
* );
69
70
//! Generic file loading code for both binary and ASCII readers.
71
//! Calls reader-specific read_triangles function to do actual I/O.
72
ErrorCode
load_file
(
const
char
* file_name,
73
const
EntityHandle
* file_set,
74
const
FileOptions
& opts,
75
const
SubsetList
* subset_list = 0,
76
const
Tag
* file_id_tag = 0 );
77
78
ErrorCode
read_tag_values
(
const
char
* file_name,
79
const
char
* tag_name,
80
const
FileOptions
& opts,
81
std::vector< int >& tag_values_out,
82
const
SubsetList
* subset_list = 0 );
83
84
//! Constructor
85
ReadSTL
(
Interface
* impl = NULL );
86
87
//! Destructor
88
virtual
~ReadSTL
();
89
90
// An object to hold vertex coordinates, and an operator
91
// for storing them in a STL tree-based container.
92
struct
Point
93
{
94
float
coords
[3];
95
bool
operator<
(
const
Point
& )
const
;
96
};
97
// Data returned by read_triangles.
98
struct
Triangle
99
{
100
Point
points
[3];
101
};
102
103
enum
ByteOrder
104
{
105
STL_BIG_ENDIAN
,
106
STL_LITTLE_ENDIAN
,
107
STL_UNKNOWN_BYTE_ORDER
108
};
109
110
protected
:
111
// I/O specific part of reader - read ASCII file
112
ErrorCode
ascii_read_triangles
(
const
char
* file_name, std::vector< Triangle >& tris_out );
113
114
// I/O specific part of reader - read binary file
115
ErrorCode
binary_read_triangles
(
const
char
* file_name,
ByteOrder
byte_order, std::vector< Triangle >& tris_out );
116
117
ReadUtilIface
*
readMeshIface
;
118
119
//! interface instance
120
Interface
*
mdbImpl
;
121
};
122
123
}
// namespace moab
124
125
#endif
src
io
ReadSTL.hpp
Generated on Sat Dec 14 2024 02:05:17 for Mesh Oriented datABase by
1.9.1.