BinaryReaderSTLOneTriangleUnitTest.cpp File Reference
#include <fstream>
#include <iostream>
#include <BinaryReader.h>
#include <Logger.h>
#include <Math/Vector.h>
#include <CMakeDefinitions.h>

Functions

int main ()
 Test of the binary reader. The files used is STL file with containing one triange. More...
 

Function Documentation

◆ main()

int main ( )

Test of the binary reader. The files used is STL file with containing one triange.

This code users BinaryReader to open a binary file called SimpleTrianlge.stl and read in currently the single tringle from this file. The triangle was created using nclab.org and contains a single triangle with normal (0,0,1) and vertex (0,1,0), (1,0,0) and (1,1,0). This is currently a UnitTest as does not require selftest data; however, it does require he file SimpleTrianlge.stl to exist

22 {
23 
24  std::ifstream STLFile;
25 
27 
28  BinaryReader STLReader(directory+"/Drivers/ImportTools/ExampleSTLFiles/SimpleTrianlge.stl");
29 
30  //First read the 80 character header
31  std::string header;
32  header=STLReader.readString(80);
33  //logger(INFO, "Header : %" ,header);
34 
35  //The next four characters contain at unsigned int which is the number of triangeles
36  unsigned int numTriangles = STLReader.readUnsignedInt(4);
37  //logger(INFO, "Number of traingles: %", numTriangles);
38 
39  if (numTriangles!=1)
40  logger(FATAL,"Failed to read the correct number of triangles");
41 
42  double xTmp,yTmp,zTmp;
43 
44  for (unsigned int i=0; i<(numTriangles);i++)
45  {
46 
47 
48  xTmp = STLReader.readFloat(4);
49  yTmp = STLReader.readFloat(4);
50  zTmp = STLReader.readFloat(4);
51 
52  Vec3D Normal(xTmp,yTmp,zTmp);
53 
54  if (!(Normal.isEqualTo(Vec3D(0,0,1),1e-10)))
55  logger(FATAL,"The normal has been misread");
56 
57 
58  xTmp = STLReader.readFloat(4);
59  yTmp = STLReader.readFloat(4);
60  zTmp = STLReader.readFloat(4);
61 
62  Vec3D Point1(xTmp,yTmp,zTmp);
63 
64  if (!(Point1.isEqualTo(Vec3D(0,1,0),1e-10)))
65  logger(FATAL,"The first vertex has been misread");
66 
67  xTmp = STLReader.readFloat(4);
68  yTmp = STLReader.readFloat(4);
69  zTmp = STLReader.readFloat(4);
70 
71  Vec3D Point2(xTmp,yTmp,zTmp);
72 
73  if (!(Point2.isEqualTo(Vec3D(1,0,0),1e-10)))
74  logger(FATAL,"The second vertex has been misread");
75 
76 
77  xTmp = STLReader.readFloat(4);
78  yTmp = STLReader.readFloat(4);
79  zTmp = STLReader.readFloat(4);
80 
81  Vec3D Point3(xTmp,yTmp,zTmp);
82 
83  if (!(Point3.isEqualTo(Vec3D(1,1,0),1e-10)))
84  logger(FATAL,"The third vertex has been misread");
85 
86  //Now ignore (read) the two dummy characters
88 
89  }
90 
91 
92 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
const std::string getMercuryDPMSourceDir()
This file is used for generating definitions that give access to CMakeVariables from within a cpp fil...
Definition: Configuration/CMakeDefinitions.cc:10
Array< double, 1, 3 > e(1./3., 0.5, 2.)
LL< Log::FATAL > FATAL
Definition of the different loglevels by its wrapper class LL. These are used as tags in template met...
Definition: Logger.cc:31
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
This gives functionality to read information from binary formats like STL etc. This class is complete...
Definition: BinaryReader.h:16
double readFloat(unsigned int size)
read the next so many bytes as a double (not in this case they were saves as a float orgainlly)
Definition: BinaryReader.cc:85
void ignoreChar(unsigned int size)
read and ignore the next number of characters
Definition: BinaryReader.cc:110
unsigned int readUnsignedInt(unsigned int size)
read the next so many bytes as a unsined int
Definition: BinaryReader.cc:98
std::string readString(unsigned int numChar)
reads the next so many Characters (bytes) as a std::string
Definition: BinaryReader.cc:57
Definition: BinaryReaderSTL1by1by1bySquareUnitTest.cpp:48
Definition: Kernel/Math/Vector.h:30
std::string string(const unsigned &i)
Definition: oomph_definitions.cc:286

References e(), FATAL, getMercuryDPMSourceDir(), i, BinaryReader::ignoreChar(), Vec3D::isEqualTo(), logger, BinaryReader::readFloat(), BinaryReader::readString(), BinaryReader::readUnsignedInt(), and oomph::Global_string_for_annotation::string().