Clean up and optimization. Changed debugging output.
This commit is contained in:
parent
cdd2472f0f
commit
71ffe9df12
3 changed files with 58 additions and 29 deletions
|
@ -49,6 +49,7 @@ namespace CompFab
|
||||||
|
|
||||||
Vec3iStruct();
|
Vec3iStruct();
|
||||||
Vec3iStruct(int x, int y, int z);
|
Vec3iStruct(int x, int y, int z);
|
||||||
|
Vec3iStruct(int i);
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
int m_pos[3];
|
int m_pos[3];
|
||||||
|
@ -104,7 +105,9 @@ namespace CompFab
|
||||||
//Compute v1 - v2
|
//Compute v1 - v2
|
||||||
Vec3 operator-(const Vec3 &v1, const Vec3 &v2);
|
Vec3 operator-(const Vec3 &v1, const Vec3 &v2);
|
||||||
|
|
||||||
Vec3 operator+(const Vec3 &v1, const Vec3 &v2);
|
Vec3 operator+(const Vec3 & v1, const Vec3 & v2);
|
||||||
|
|
||||||
|
Vec3i operator+(const Vec3i & v1, const Vec3i & v2);
|
||||||
|
|
||||||
//Cross Product
|
//Cross Product
|
||||||
Vec3 operator%(const Vec3 &v1, const Vec3 &v2);
|
Vec3 operator%(const Vec3 &v1, const Vec3 &v2);
|
||||||
|
|
|
@ -48,6 +48,14 @@ CompFab::Vec3iStruct::Vec3iStruct(int x, int y, int z)
|
||||||
m_z = z;
|
m_z = z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CompFab::Vec3iStruct::Vec3iStruct(int i)
|
||||||
|
{
|
||||||
|
m_x = i;
|
||||||
|
m_y = i;
|
||||||
|
m_z = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
CompFab::Vec2fStruct::Vec2fStruct()
|
CompFab::Vec2fStruct::Vec2fStruct()
|
||||||
{
|
{
|
||||||
m_x = m_y = 0.0;
|
m_x = m_y = 0.0;
|
||||||
|
@ -99,6 +107,16 @@ CompFab::Vec3 CompFab::operator+(const Vec3 &v1, const Vec3 &v2)
|
||||||
return v3;
|
return v3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CompFab::Vec3i CompFab::operator+(const Vec3i &v1, const Vec3i &v2)
|
||||||
|
{
|
||||||
|
Vec3i v3i;
|
||||||
|
v3i[0] = v1[0] + v2[0];
|
||||||
|
v3i[1] = v1[1] + v2[1];
|
||||||
|
v3i[2] = v1[2] + v2[2];
|
||||||
|
|
||||||
|
return v3i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Cross Product
|
//Cross Product
|
||||||
Vec3 CompFab::operator%(const Vec3 &v1, const Vec3 &v2)
|
Vec3 CompFab::operator%(const Vec3 &v1, const Vec3 &v2)
|
||||||
|
|
|
@ -39,7 +39,7 @@ void findLW(Mesh &m, double &l, double &w)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate translation matrices and output them as a vector of Vec3s.
|
// Calculate translation matrices and output them as a vector of Vec3s.
|
||||||
std::vector<CompFab::Vec3> createVec3d(int layers, double spacing, double length, double width)
|
std::vector<CompFab::Vec3> createVec3d(std::vector<CompFab::Vec3> &t, int layers, double spacing, double length, double width)
|
||||||
{
|
{
|
||||||
std::vector<CompFab::Vec3> *output = new std::vector<CompFab::Vec3>();
|
std::vector<CompFab::Vec3> *output = new std::vector<CompFab::Vec3>();
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ std::vector<CompFab::Vec3> createVec3d(int layers, double spacing, double length
|
||||||
|
|
||||||
// Vec3 to hold our current translation matrix.
|
// Vec3 to hold our current translation matrix.
|
||||||
CompFab::Vec3 *trans = new CompFab::Vec3(0, spacing, 0);
|
CompFab::Vec3 *trans = new CompFab::Vec3(0, spacing, 0);
|
||||||
|
*output = t;
|
||||||
|
|
||||||
// cl for current layer.
|
// cl for current layer.
|
||||||
for(int cl = 1; cl < layers; cl++)
|
for(int cl = 1; cl < layers; cl++)
|
||||||
|
@ -67,9 +68,27 @@ std::vector<CompFab::Vec3> createVec3d(int layers, double spacing, double length
|
||||||
{
|
{
|
||||||
angle = (c/(2*cl))*(0.5*PI);
|
angle = (c/(2*cl))*(0.5*PI);
|
||||||
*trans = CompFab::Vec3(ls*cos(angle), ws*sin(angle), 0);
|
*trans = CompFab::Vec3(ls*cos(angle), ws*sin(angle), 0);
|
||||||
*temp = *temp + *trans;
|
*temp += *trans;
|
||||||
|
for(int j = 0; j < t.size(); j++)
|
||||||
output->push_back(*temp);
|
{
|
||||||
|
output->push_back(t[j] + *temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return *output;
|
||||||
|
}
|
||||||
|
std::vector<CompFab::Vec3i> createVec3id(std::vector<CompFab::Vec3i> &t, std::vector<CompFab::Vec3> &v, int layers)
|
||||||
|
{
|
||||||
|
std::vector<CompFab::Vec3i> *output = new std::vector<CompFab::Vec3i>();
|
||||||
|
*output = t;
|
||||||
|
|
||||||
|
for(int n = 1; n < pow((2*layers - 1), 2); n++)
|
||||||
|
{
|
||||||
|
CompFab::Vec3i *offset = new CompFab::Vec3i(v.size()*n);
|
||||||
|
for(int k = 0; k < t.size(); k++)
|
||||||
|
{
|
||||||
|
output->push_back(t[k] + *offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,12 +106,11 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Modularize these.
|
// TODO: Modularize these.
|
||||||
int layers = 10;
|
int layers = 5;
|
||||||
double spacing = 1.0;
|
double spacing = 1;
|
||||||
|
|
||||||
// Create Mesh object from file, output to manipulate from template Mesh.
|
// Create Mesh object from file, output to manipulate from template Mesh.
|
||||||
Mesh *test = new Mesh(argv[1], false);
|
Mesh *test = new Mesh(argv[1], false);
|
||||||
Mesh *output = new Mesh(test->v, test->t);
|
|
||||||
|
|
||||||
double l = 0, w = 0;
|
double l = 0, w = 0;
|
||||||
double *length = &l, *width = &w;
|
double *length = &l, *width = &w;
|
||||||
|
@ -100,27 +118,14 @@ int main(int argc, char **argv)
|
||||||
// Find the X and Y dimensions for the mesh. Assumes the mesh is facing upright.
|
// Find the X and Y dimensions for the mesh. Assumes the mesh is facing upright.
|
||||||
findLW(*test, *length, *width);
|
findLW(*test, *length, *width);
|
||||||
|
|
||||||
// Calculate the translation matrices needed.
|
// Calculate the translation matrices needed and apply them.
|
||||||
std::vector<CompFab::Vec3> d = createVec3d(layers, spacing, *length, *width);
|
std::vector<CompFab::Vec3> vv = createVec3d(test->v, layers, spacing, *length, *width);
|
||||||
|
|
||||||
// Duplicating template, will later be replaced with a much more robust procedural generation function.
|
|
||||||
for(int i = 0; i < d.size(); i++)
|
|
||||||
{
|
|
||||||
for(int j = 0; j < test->v.size(); j++)
|
|
||||||
{
|
|
||||||
output->v.push_back(CompFab::Vec3(test->v[j] + d[i]));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copying needed triangle data.
|
// Copying needed triangle data.
|
||||||
for(int n = 1; n < pow((2*layers - 1), 2); n++)
|
std::vector<CompFab::Vec3i> tt = createVec3id(test->t, test->v, layers);
|
||||||
{
|
|
||||||
int offset = test->v.size()*n;
|
// Using contructor to create new output Mesh.
|
||||||
for(int k = 0; k < test->t.size(); k++)
|
Mesh *output = new Mesh(vv, tt);
|
||||||
{
|
|
||||||
output->t.push_back(CompFab::Vec3i(test->t[k].m_x +offset, test->t[k].m_y + offset, test->t[k].m_z + offset));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Debugging
|
// Debugging
|
||||||
if(argc > 3)
|
if(argc > 3)
|
||||||
|
@ -130,8 +135,11 @@ int main(int argc, char **argv)
|
||||||
for(int j = 0; j < output->v.size(); j++)
|
for(int j = 0; j < output->v.size(); j++)
|
||||||
{
|
{
|
||||||
std::cout << output->v[j].m_x << " " << output->v[j].m_y << " " << output->v[j].m_z << std::endl;
|
std::cout << output->v[j].m_x << " " << output->v[j].m_y << " " << output->v[j].m_z << std::endl;
|
||||||
std::cout << output->t[j].m_x << " " << output->t[j].m_y << " " << output->t[j].m_z << std::endl;
|
}
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
for(int k = 0; k < output->t.size(); k++)
|
||||||
|
{
|
||||||
|
std::cout << output->t[k].m_x << " " << output->t[k].m_y << " " << output->t[k].m_z << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
Reference in a new issue