Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test cases updated #19

Merged
merged 2 commits into from
Jun 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 35 additions & 38 deletions include/meshio/meshio_defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define __MESHIO_DEFINES_HPP__

#include <vector>
#include "vectors.hpp"

namespace meshio
{
Expand All @@ -20,39 +21,6 @@ enum STLFormat {
STL_BINARY = 1
};

template<typename T>
struct Vec4 {
T x;
T y;
T z;
T w;
};

template<typename T>
struct Vec3 {
T x;
T y;
T z;
struct Vec3& operator+=(const struct Vec3& pVec3) {
x += pVec3.x;
y += pVec3.y;
z += pVec3.z;
return *this;
}
struct Vec3& operator/=(const int pDiv) {
x /= pDiv;
y /= pDiv;
z /= pDiv;
return *this;
}
};

template<typename T>
struct Vec2 {
T x;
T y;
};

template<class T>
class Mesh {
public:
Expand All @@ -62,6 +30,12 @@ class Mesh {
std::vector< Vec4<float> > mColors;
std::vector< unsigned > mIndices;

Mesh() {}

~Mesh() {
this->clear();
}

void resize(unsigned pSize) {
mPositions.resize(pSize);
mNormals.resize(pSize);
Expand All @@ -82,14 +56,19 @@ class Mesh {
}
};

/*
* struct to store data from STL file
*/
template<typename T>
struct STLData {
/* STLData class to store data from STL file */
template<class T>
class STLData {
public:
std::vector< Vec4<T> > mPositions;
std::vector< Vec3<float> > mNormals;

STLData() {}

~STLData() {
this->clear();
}

void resize(unsigned pNumTriangles) {
mPositions.resize(3*pNumTriangles);
mNormals.resize(pNumTriangles);
Expand All @@ -99,6 +78,24 @@ struct STLData {
mPositions.clear();
mNormals.clear();
}

bool operator==(STLData<T>& pSTLObj) {
if(this->mPositions.size() != pSTLObj.mPositions.size())
return false;

if(this->mNormals.size() != pSTLObj.mNormals.size())
return false;

for(unsigned i = 0; i < mPositions.size(); ++i)
if(!(this->mPositions[i] == pSTLObj.mPositions[i]))
return false;

for(unsigned i = 0; i < mNormals.size(); ++i)
if(!(this->mNormals[i] == pSTLObj.mNormals[i]))
return false;

return true;
}
};

}
Expand Down
251 changes: 251 additions & 0 deletions include/meshio/vectors.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
/*
* Copyright (c) 2015, Lakshman Anumolu, Pradeep Garigipati
* All rights reserved.
*
* This file is part of MeshIO whose distribution is governed by
* the BSD 2-Clause License contained in the accompanying LICENSE.txt
* file.
*/

#ifndef __VECTORS_HPP__
#define __VECTORS_HPP__

#include <vector>

namespace meshio
{

template<class T>
class Vec2 {
public:
T x,y;

Vec2(T pX, T pY) {
x = pX;
y = pY;
}

Vec2(T pX) {
Vec2(pX, 0);
}

Vec2() {
Vec2(0, 0);
}

Vec2(const Vec2& pVec2) {
*this = pVec2;
}

~Vec2() {}

void operator=(const Vec2& pVec2) {
x = pVec2.x;
y = pVec2.y;
}

Vec2& operator+=(const Vec2& pVec2) {
x += pVec2.x;
y += pVec2.y;
return *this;
}

Vec2& operator-=(const Vec2& pVec2) {
x -= pVec2.x;
y -= pVec2.y;
return *this;
}

Vec2& operator*=(const T pDiv) {
x *= pDiv;
y *= pDiv;
return *this;
}

Vec2& operator/=(const T pDiv) {
T oneByPDiv = (T)1/pDiv;
x *= oneByPDiv;
y *= oneByPDiv;
return *this;
}

bool operator==(const Vec2& pVec2) {
return ((x == pVec2.x) && (y == pVec2.y));
}

/* Dot product of two vectors */
Vec2 operator&(const Vec2& pVec2) {
return Vec2(this->x*pVec2.x, this->y*pVec2.y);
}

/* Cross product of two vectors */
Vec2 operator^(const Vec2& pVec2) {
return Vec3(0, 0, this->x*pVec2.y-this->y*pVec2.x);
}
};

template<class T>
class Vec3 {
public:
T x,y,z;

Vec3(T pX, T pY, T pZ) {
x = pX;
y = pY;
z = pZ;
}

Vec3(T pX, T pY) {
Vec3(pX, pY, 0);
}

Vec3(T pX) {
Vec3(pX, 0, 0);
}

Vec3() {
Vec3(0, 0, 0);
}

Vec3(const Vec3& pVec3) {
*this = pVec3;
}

~Vec3() {}

void operator=(const Vec3& pVec3) {
x = pVec3.x;
y = pVec3.y;
z = pVec3.z;
}

Vec3& operator+=(const Vec3& pVec3) {
x += pVec3.x;
y += pVec3.y;
z += pVec3.z;
return *this;
}

Vec3& operator-=(const Vec3& pVec3) {
x -= pVec3.x;
y -= pVec3.y;
z -= pVec3.z;
return *this;
}

Vec3& operator*=(const T pDiv) {
x *= pDiv;
y *= pDiv;
z *= pDiv;
return *this;
}

Vec3& operator/=(const T pDiv) {
T oneByPDiv = (T)1/pDiv;
x *= oneByPDiv;
y *= oneByPDiv;
z *= oneByPDiv;
return *this;
}

bool operator==(const Vec3& pVec3) {
return ((x == pVec3.x) && (y == pVec3.y) && (z == pVec3.z));
}

/* Dot product of two vectors */
Vec3 operator&(const Vec3& pVec3) {
return Vec3(this->x*pVec3.x, this->y*pVec3.y, this->z*pVec3.z);
}

/* Cross product of two vectors */
Vec3 operator^(const Vec3& pVec3) {
return Vec3(this->y*pVec3.z-this->z*pVec3.y,
this->z*pVec3.x-this->x*pVec3.z,
this->x*pVec3.y-this->y*pVec3.x);
}
};

template<class T>
class Vec4 {
public:
T x,y,z,w;

Vec4(T pX, T pY, T pZ, T pW) {
x = pX;
y = pY;
z = pZ;
w = pW;
}

Vec4(T pX, T pY, T pZ) {
Vec4(pX, pY, pZ, 0);
}

Vec4(T pX, T pY) {
Vec4(pX, pY, 0, 0);
}

Vec4(T pX) {
Vec4(pX, 0, 0, 0);
}

Vec4() {
Vec4(0, 0, 0, 0);
}

Vec4(const Vec4& pVec4) {
*this = pVec4;
}

~Vec4() {}

void operator=(const Vec4& pVec4) {
x = pVec4.x;
y = pVec4.y;
z = pVec4.z;
w = pVec4.w;
}

Vec4& operator+=(const Vec4& pVec4) {
x += pVec4.x;
y += pVec4.y;
z += pVec4.z;
w += pVec4.w;
return *this;
}

Vec4& operator-=(const Vec4& pVec4) {
x -= pVec4.x;
y -= pVec4.y;
z -= pVec4.z;
w -= pVec4.w;
return *this;
}

Vec4& operator*=(const T pDiv) {
x *= pDiv;
y *= pDiv;
z *= pDiv;
w *= pDiv;
return *this;
}

Vec4& operator/=(const T pDiv) {
T oneByPDiv = (T)1/pDiv;
x *= oneByPDiv;
y *= oneByPDiv;
z *= oneByPDiv;
w *= oneByPDiv;
return *this;
}

bool operator==(const Vec4& pVec4) {
return ((x == pVec4.x) && (y == pVec4.y) && (z == pVec4.z) &&
(w == pVec4.w));
}
};


}

#endif // __VECTORS_HPP__
Binary file added resources/cube_binary.stl
Binary file not shown.
Loading