summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordon bright <hugh.m.bright@gmail.com>2013-02-02 16:53:13 (GMT)
committerdon bright <hugh.m.bright@gmail.com>2013-02-02 16:53:13 (GMT)
commite9e62272a6cda04c453dd2d27b1a7e91be05f242 (patch)
tree07bdd7a9822ad5938660d77e9c08a4decace8ff2 /src
parente357399fd9906604a83dee497b17e074a6fe8876 (diff)
replace packed struct with union. remove some extraneous/debug code
Diffstat (limited to 'src')
-rw-r--r--src/import.cc63
1 files changed, 16 insertions, 47 deletions
diff --git a/src/import.cc b/src/import.cc
index c17d915..8980448 100644
--- a/src/import.cc
+++ b/src/import.cc
@@ -115,67 +115,45 @@ AbstractNode *ImportModule::evaluate(const Context *ctx, const ModuleInstantiati
return node;
}
-#ifdef _MSC_VER
-#pragma pack(push,1)
-#endif
-struct stl_data {
- float i, j, k;
- float x1, y1, z1;
- float x2, y2, z2;
- float x3, y3, z3;
- unsigned short acount;
-}
-#ifdef __GNUC__
- __attribute__ ((packed))
-#endif
-#ifdef _MSC_VER
-#pragma pack(pop)
-#endif
-;
-
-#define STL_FACET_SIZE 4*3*4+2
+#define STL_FACET_NUMBYTES 4*3*4+2
+// as there is no 'float32_t' standard, we assume the systems 'float'
+// is a 'binary32' aka 'single' standard IEEE 32-bit floating point type
union stl_facet {
- uint8_t data8[ STL_FACET_SIZE ];
+ uint8_t data8[ STL_FACET_NUMBYTES ];
uint32_t data32[4*3];
struct facet_data {
- // assume 'float' is 'binary32' aka 'single' IEEE 32-bit
- // floating point type.
float i, j, k;
float x1, y1, z1;
float x2, y2, z2;
float x3, y3, z3;
- uint16_t acount;
+ uint16_t attribute_byte_count;
} data;
};
void uint32_byte_swap( uint32_t &x )
{
-/*#if defined(__GNUC__) || defined(__clang__)
+#if defined(__GNUC__) || defined(__clang__)
x = __builtin_bswap32( x );
-#elif defined(_MSVC)
+#elif defined(_MSC_VER)
x = _byteswap_ulong( x );
-#else*/
+#else
uint32_t b1 = ( 0x000000FF & x ) << 24;
uint32_t b2 = ( 0x0000FF00 & x ) << 8;
uint32_t b3 = ( 0x00FF0000 & x ) >> 8;
uint32_t b4 = ( 0xFF000000 & x ) >> 24;
x = b1 | b2 | b3 | b4;
-//#endif
-}
-
-void stl_endian_repair( uint32_t &x )
-{
-#ifdef BOOST_BIG_ENDIAN
- uint32_byte_swap( x );
#endif
}
void read_stl_facet( std::ifstream &f, stl_facet &facet )
{
- f.read( (char*)facet.data8, STL_FACET_SIZE );
+ f.read( (char*)facet.data8, STL_FACET_NUMBYTES );
+#ifdef BOOST_BIG_ENDIAN
for ( int i = 0; i < 12; i++ ) {
- stl_endian_repair( facet.data32[ i ] );
+ uint32_byte_swap( facet.data32[ i ] );
}
+ // we ignore attribute byte count
+#endif
}
PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const
@@ -205,7 +183,9 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const
if (!f.eof()) {
uint32_t facenum = 0;
f.read((char *)&facenum, sizeof(uint32_t));
- stl_endian_repair( facenum );
+#ifdef BOOST_BIG_ENDIAN
+ uint32_byte_swap( facenum );
+#endif
if (file_size == 80 + 4 + 50*facenum) binary = true;
}
f.seekg(0);
@@ -253,7 +233,6 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const
{
f.ignore(80-5+4);
while (1) {
-#ifdef BOOST_BIG_ENDIAN
stl_facet facet;
read_stl_facet( f, facet );
if (f.eof()) break;
@@ -261,15 +240,6 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const
p->append_vertex(facet.data.x1, facet.data.y1, facet.data.z1);
p->append_vertex(facet.data.x2, facet.data.y2, facet.data.z2);
p->append_vertex(facet.data.x3, facet.data.y3, facet.data.z3);
-#else
- stl_data stldata;
- f.read((char *)&stldata, sizeof(stldata));
- if (f.eof()) break;
- p->append_poly();
- p->append_vertex(stldata.x1, stldata.y1, stldata.z1);
- p->append_vertex(stldata.x2, stldata.y2, stldata.z2);
- p->append_vertex(stldata.x3, stldata.y3, stldata.z3);
-#endif
}
}
}
@@ -302,7 +272,6 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const
}
if (p) p->convexity = this->convexity;
- std::cout << p->dump() << "\n";
return p;
}
contact: Jan Huwald // Impressum