Merging Marion's code, improved Vector, changed file names

This commit is contained in:
Thomas FORGIONE 2015-02-21 13:33:02 +01:00
parent 5de379f92f
commit c1df156a1b
12 changed files with 455 additions and 248 deletions

View File

@ -2,7 +2,7 @@
#define BASE_HPP #define BASE_HPP
#include <vector> #include <vector>
#include "Vector3.hpp" #include "Vector.hpp"
namespace pae namespace pae
{ {

View File

@ -3,7 +3,7 @@
#include <vector> #include <vector>
#include <utility> #include <utility>
#include "Vector3.hpp" #include "Vector.hpp"
namespace pae namespace pae
{ {

View File

@ -28,12 +28,12 @@ Mesh& Mesh::operator+=(Mesh const& m)
std::ostream& operator<<(std::ostream& out, Mesh const& mesh) std::ostream& operator<<(std::ostream& out, Mesh const& mesh)
{ {
for (auto const& v : mesh.vertices) for (auto const& v : mesh.vertices)
out << "v " << v.x << " " << v.y << " " << v.z << "\n"; out << "v " << v.x() << " " << v.y() << " " << v.z() << "\n";
out << "\n"; out << "\n";
for (auto const& f : mesh.faces) for (auto const& f : mesh.faces)
out << "f " << f.x << " " << f.y << " " << f.z << "\n"; out << "f " << f.x() << " " << f.y() << " " << f.z() << "\n";
return out << std::endl; return out << std::endl;
} }
@ -41,9 +41,9 @@ std::ostream& operator<<(std::ostream& out, Mesh const& mesh)
void Mesh::draw() const void Mesh::draw() const
{ {
glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(Vector3<float>), &(glVertices[0].x)); glVertexPointer(3, GL_FLOAT, sizeof(Vector3<float>), &(glVertices[0].x()));
glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(Vector3<float>), &(glNormals[0].x)); glNormalPointer(GL_FLOAT, sizeof(Vector3<float>), &(glNormals[0].x()));
glColor3f(0,0,1); glColor3f(0,0,1);
glEnable(GL_LIGHT0); glEnable(GL_LIGHT0);
@ -66,9 +66,9 @@ void Mesh::prepare(bool gouraudShading)
// Generate the vertices for glDrawArrays(); // Generate the vertices for glDrawArrays();
for (auto const& f : faces) for (auto const& f : faces)
{ {
glVertices.push_back(Vector3<float>{vertices[f.x].x, vertices[f.x].y, vertices[f.x].z}); glVertices.push_back(Vector3<float>{vertices[f.x()].x(), vertices[f.x()].y(), vertices[f.x()].z()});
glVertices.push_back(Vector3<float>{vertices[f.y].x, vertices[f.y].y, vertices[f.y].z}); glVertices.push_back(Vector3<float>{vertices[f.y()].x(), vertices[f.y()].y(), vertices[f.y()].z()});
glVertices.push_back(Vector3<float>{vertices[f.z].x, vertices[f.z].y, vertices[f.z].z}); glVertices.push_back(Vector3<float>{vertices[f.z()].x(), vertices[f.z()].y(), vertices[f.z()].z()});
// Compute the normal for the current face // Compute the normal for the current face
auto normal = crossProduct( auto normal = crossProduct(
@ -93,7 +93,7 @@ void Mesh::prepareGouraudShading()
std::vector<Vector3<float>> tmpNormals; std::vector<Vector3<float>> tmpNormals;
for (unsigned int i = 0; i < vertices.size(); i++) for (unsigned int i = 0; i < vertices.size(); i++)
{ {
tmpNormals.push_back(Vector3<float>{0,0,0}); tmpNormals.push_back(Vector3<float>{0.0f,0.0f,0.0f});
} }
@ -101,9 +101,9 @@ void Mesh::prepareGouraudShading()
// of the faces in which this vertex appears // of the faces in which this vertex appears
for (unsigned int i = 0; i < faces.size(); i++) for (unsigned int i = 0; i < faces.size(); i++)
{ {
tmpNormals[faces[i].x] += normals[i]; tmpNormals[faces[i].x()] += normals[i];
tmpNormals[faces[i].y] += normals[i]; tmpNormals[faces[i].y()] += normals[i];
tmpNormals[faces[i].z] += normals[i]; tmpNormals[faces[i].z()] += normals[i];
} }
// Normalize the normals on each vertex // Normalize the normals on each vertex
@ -115,9 +115,9 @@ void Mesh::prepareGouraudShading()
// Fill the glNormals wich the corresponding normal // Fill the glNormals wich the corresponding normal
for (unsigned int i = 0; i < faces.size(); i++) for (unsigned int i = 0; i < faces.size(); i++)
{ {
glNormals.push_back(tmpNormals[faces[i].x]); glNormals.push_back(tmpNormals[faces[i].x()]);
glNormals.push_back(tmpNormals[faces[i].y]); glNormals.push_back(tmpNormals[faces[i].y()]);
glNormals.push_back(tmpNormals[faces[i].z]); glNormals.push_back(tmpNormals[faces[i].z()]);
} }
} }

View File

@ -3,7 +3,7 @@
#include <vector> #include <vector>
#include "Spline.hpp" #include "Spline.hpp"
#include "Vector3.hpp" #include "Vector.hpp"
namespace pae namespace pae
{ {

View File

@ -2,6 +2,7 @@
#define SKELETON3D_HPP #define SKELETON3D_HPP
#include <vector> #include <vector>
#include <list>
#include "Mesh.hpp" #include "Mesh.hpp"
#include "Spline.hpp" #include "Spline.hpp"
@ -18,6 +19,21 @@ namespace pae
//////////////////////////////////////////////////////// ////////////////////////////////////////////////////////
using Junction = std::vector<std::pair<unsigned int,float>>; using Junction = std::vector<std::pair<unsigned int,float>>;
namespace detail
{
template<typename T>
using Point = std::pair<unsigned int, Vector3<T>>;
template<typename T>
bool whichSide(std::array<double,4> const& plane, Vector3<float> const& point);
template<typename T>
std::array<double,4> closestPlane(std::vector<std::pair<Point<T>,Point<T>>> const& points);
template<typename T>
std::vector<std::list<Point<T>>> sortedPoints(std::array<double,4> const& plane, std::vector<Circle<T>> const& junction_circles, std::vector<std::pair<Point<T>,Point<T>>> const& closest_points);
}
template<typename... Types> template<typename... Types>
class Skeleton3D class Skeleton3D
{ {
@ -50,6 +66,8 @@ class Skeleton3D
void arcSubdivise(Vector3<float> pt1, Vector3<float> pt2, unsigned int profondeur, std::vector<Vector3<float>>& arc, Vector3<float> center, float radius); void arcSubdivise(Vector3<float> pt1, Vector3<float> pt2, unsigned int profondeur, std::vector<Vector3<float>>& arc, Vector3<float> center, float radius);
std::pair<detail::Point<float>,detail::Point<float>> closestPointsCircles(Circle<float> const& circle1, Circle<float> const& circle2);
template<typename... T> template<typename... T>
friend std::ostream& operator<<(std::ostream& out, Skeleton3D<T...> const& s); friend std::ostream& operator<<(std::ostream& out, Skeleton3D<T...> const& s);

View File

@ -2,6 +2,8 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <cmath> #include <cmath>
#include <list>
#include <eigen3/Eigen/Dense>
#include "Skeleton3D.hpp" #include "Skeleton3D.hpp"
#include <algorithm> #include <algorithm>
@ -148,13 +150,49 @@ void Skeleton3D<T...>::meshJunction(Mesh mesh, std::vector<std::vector<Circle<fl
} }
// Compute the closest points between two consecutives circles // Compute the closest points between two consecutives circles
for( unsigned int i = 0; i<junction_circles.size(); i++) std::vector<std::pair<detail::Point<float>,detail::Point<float>>> closestPoints;
for (unsigned int i = 0; i<junction_circles.size(); i++)
{ {
Circle<float>& circle1 = junction_circles[i];
Circle<float>& circle2 = junction_circles[(i+1)%junction_circles.size()];
closestPoints.push_back(closestPointsCircles(circle1,circle2));
} }
// Find the medium plane that cut the circles in two
std::array<double,4> plane = detail::closestPlane<float>(closestPoints);
// Compute list of points upside with the closestPointsCircles "correspondants" and outside
//TODO écrire un commentaire compréhensible !
std::vector<std::list<detail::Point<float>>> sorted_points = detail::sortedPoints<float>(plane, junction_circles,closestPoints);
} }
template<typename... T>
std::pair<detail::Point<float>,detail::Point<float>> Skeleton3D<T...>::closestPointsCircles(Circle<float> const& circle1, Circle<float> const& circle2)
{
float bestDistance = (circle1.points[0].second - circle2.points[0].second).norm2();
detail::Point<float> const* bestPoint1 = nullptr;
detail::Point<float> const* bestPoint2 = nullptr;
for(auto const& point1:circle1.points)
{
for(auto const& point2:circle2.points)
{
float twoDistance = (point1.second - point2.second).norm2();
if( twoDistance < bestDistance)
{
bestDistance = twoDistance;
bestPoint1 = &point1;
bestPoint2 = &point2;
}
}
}
return std::make_pair(*bestPoint1,*bestPoint2);
}
template<typename... T> template<typename... T>
std::vector<std::pair<unsigned int, float>> Skeleton3D<T...>::findExtremities() std::vector<std::pair<unsigned int, float>> Skeleton3D<T...>::findExtremities()
{ {
@ -450,4 +488,99 @@ std::ostream& operator<<(std::ostream& out, Skeleton3D<T...> const& s)
return out; return out;
} }
namespace detail
{
template<typename T>
bool whichSide(std::array<double,4> const& plane, Vector3<float> const& point)
{
return plane[0]*point.x() + plane[1]*point.y() + plane[2]*point.z() < - plane[3];
}
template<typename T>
std::array<double,4> closestPlane(std::vector<std::pair<Point<T>,Point<T>>> const& points)
{
Eigen::MatrixXd m{points.size()*2,3};
for ( unsigned int i = 0; i < points.size()*2; i+=2)
{
m(i,0) = points[i].first.second.x();
m(i,1) = points[i].first.second.y();
m(i,2) = points[i].first.second.z();
m(i+1,0) = points[i].second.second.x();
m(i+1,1) = points[i].second.second.y();
m(i+1,2) = points[i].second.second.z();
}
Eigen::MatrixXd centered = m.rowwise() - m.colwise().mean();
Eigen::MatrixXd cov = centered.adjoint() * centered;
Eigen::SelfAdjointEigenSolver<Eigen::MatrixXd> eig{cov};
Eigen::Vector3d v1 = eig.eigenvectors().col(1);
Eigen::Vector3d v2 = eig.eigenvectors().col(2);
Eigen::Vector3d n = v1.cross(v2);
return( std::array<double,4>{n(0),n(1),n(2), n.dot(m.colwise().mean())} );
}
template<typename T>
std::vector<std::list<Point<T>>> sortedPoints(std::array<double,4> const& plane, std::vector<Circle<T>> const& junction_circles, std::vector<std::pair<Point<T>,Point<T>>> const& closest_points)
{
std::vector<std::list<Point<float>>> sorted_points;
for (unsigned int i = 0; i < junction_circles.size(); i++)
{
std::list<Point<float>> first_points;
std::list<Point<float>> second_points;
bool up_side = whichSide<double>(plane, junction_circles[i].points[0].second);
bool current_points = up_side;
for (unsigned int j = 0; j < junction_circles[i].points.size(); j++)
{
if (up_side == current_points)
{
if (whichSide<double>(plane, junction_circles[i].points[j].second) == up_side)
{
first_points.push_back(junction_circles[i].points[j]);
}
else
{
current_points = whichSide<double>(plane, junction_circles[i].points[j].second);
second_points.push_back(junction_circles[i].points[j]);
}
}
else
{
if (whichSide<double>(plane, junction_circles[i].points[j].second) == current_points)
{
second_points.push_back(junction_circles[i].points[j]);
}
else
{
break;
}
}
}
for (int j = static_cast<int>(junction_circles[i].points.size()-1); j >= 0; j--)
{
if (whichSide<double>(plane, junction_circles[i].points[j].second) == up_side)
{
first_points.push_front(junction_circles[i].points[j]);
}
else
{
break;
}
}
sorted_points.push_back(first_points);
sorted_points.push_back(second_points);
}
return sorted_points;
}
} // namespace detail
} // namespace pae } // namespace pae

View File

@ -2,7 +2,7 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <cmath> #include <cmath>
#include "Vector3.hpp" #include "Vector.hpp"
#include "Base.hpp" #include "Base.hpp"
#include "Spline.hpp" #include "Spline.hpp"
@ -21,7 +21,7 @@ std::vector<Circle<float>> Spline<Types...>::computeCircles(unsigned int nbCircl
std::vector<Circle<float>> circles; std::vector<Circle<float>> circles;
unsigned int offset = 0; unsigned int offset = 0;
pae::Vector3<float> v{0,0,1}; pae::Vector3<float> v{0.0f,0.0f,1.0f};
for (unsigned int i = 0; i < nbCircles; i++) for (unsigned int i = 0; i < nbCircles; i++)
{ {
@ -48,12 +48,12 @@ Circle<float> Spline<Types...>::computeCircle(float t, unsigned int const nbPoin
C_prime_t /= C_prime_t.norm(); C_prime_t /= C_prime_t.norm();
auto a = C_prime_t.x; auto a = C_prime_t.x();
auto b = C_prime_t.y; auto b = C_prime_t.y();
auto c = C_prime_t.z; auto c = C_prime_t.z();
auto d = r_t * r_prime_t - C_t.x * C_prime_t.x - C_t.y * C_prime_t.y - C_t.z * C_prime_t.z; auto d = r_t * r_prime_t - C_t.x() * C_prime_t.x() - C_t.y() * C_prime_t.y() - C_t.z() * C_prime_t.z();
auto dist = std::abs(a * C_t.x + b * C_t.y + c * C_t.z + d)/std::sqrt(a*a+b*b+c*c); auto dist = std::abs(a * C_t.x() + b * C_t.y() + c * C_t.z() + d)/std::sqrt(a*a+b*b+c*c);
// std::cout << "dist : " << dist << std::endl; // std::cout << "dist : " << dist << std::endl;
auto C_P_t = C_t + dist * C_prime_t; auto C_P_t = C_t + dist * C_prime_t;

View File

@ -0,0 +1,77 @@
#ifndef VECTOR_HPP
#define VECTOR_HPP
#include <cmath>
#include <array>
#include <istream>
namespace pae
{
template<typename T, std::size_t N>
class Vector
{
public:
Vector();
template<typename... Types>
Vector(Types... l);
Vector(Vector const& v);
T norm2() const;
T norm() const;
Vector<T,N>& operator=(T t);
Vector<T,N>& operator=(Vector<T,N> t);
Vector<T,N> operator-();
Vector<T,N>& operator+=(Vector<T,N> const& v);
Vector<T,N>& operator-=(Vector<T,N> const& v);
Vector<T,N>& operator*=(float f);
Vector<T,N>& operator/=(float f);
T& x() {static_assert(N > 0, "x() doesn't exist on Vector<T,0>"); return data[0]; };
T& y() {static_assert(N > 1, "y() doesn't exist on Vector<T,1>"); return data[1]; };
T& z() {static_assert(N > 2, "z() doesn't exist on Vector<T,2>"); return data[2]; };
T const& x() const {static_assert(N > 0, "x() doesn't exist on Vector<T,0>"); return data[0]; };
T const& y() const {static_assert(N > 1, "y() doesn't exist on Vector<T,1>"); return data[1]; };
T const& z() const {static_assert(N > 2, "z() doesn't exist on Vector<T,2>"); return data[2]; };
std::array<T,N> data;
};
template<typename T, std::size_t N>
bool operator==(Vector<T,N> const& l, Vector<T,N> const& r);
template<typename T, std::size_t N>
bool operator!=(Vector<T,N> const& l, Vector<T,N> const& r);
template<typename T, std::size_t N>
Vector<T,N> operator+(Vector<T,N> l, Vector<T,N> const& r);
template<typename T, std::size_t N>
Vector<T,N> operator-(Vector<T,N> l, Vector<T,N> const& r);
template<typename T, std::size_t N>
Vector<T,N> operator*(Vector<T,N> l, float f);
template<typename T, std::size_t N>
Vector<T,N> operator/(Vector<T,N> l, float f);
template<typename T, std::size_t N>
std::istream& operator>>(std::istream& stream, Vector<T,N>& v);
template<typename T, std::size_t N>
std::ostream& operator<<(std::ostream& stream, Vector<T,N> const& v);
template<typename T>
using Vector3 = Vector<T,3>;
} // namespace pae
#include "Vector.inl"
#endif // VECTOR_HPP

175
Code/src/Spline/Vector.inl Normal file
View File

@ -0,0 +1,175 @@
#include <iostream>
#include <cmath>
#include "Vector.hpp"
namespace pae
{
template<typename T, std::size_t N>
Vector<T,N>::Vector() : data{}
{
}
template<typename T, std::size_t N>
template<typename...Types>
Vector<T,N>::Vector(Types... l) : data{{l...}}
{
}
template<typename T, std::size_t N>
Vector<T,N>::Vector(Vector<T,N> const& v) : data(v.data)
{
}
template<typename T, std::size_t N>
T Vector<T,N>::norm2() const
{
return (*this) * (*this);
}
template<typename T, std::size_t N>
T Vector<T,N>::norm() const
{
return std::sqrt(norm2());
}
template<typename T, std::size_t N>
Vector<T,N>& Vector<T,N>::operator=(T t)
{
for (auto& d : data)
d = t;
return *this;
}
template<typename T, std::size_t N>
Vector<T,N>& Vector<T,N>::operator=(Vector<T,N> t)
{
this->data = std::move(t.data);
return *this;
}
template<typename T, std::size_t N>
std::istream& operator>>(std::istream& stream, Vector<T,N>& v)
{
for (auto& d : v.data)
stream >> d;
return stream;
}
template<typename T, std::size_t N>
std::ostream& operator<<(std::ostream& stream, Vector<T,N> const& v)
{
stream << "[" << v.data[0];
for (std::size_t i = 1; i < N; i++)
stream << ", " << v.data[i];
return stream << "]";
}
template<typename T, std::size_t N>
bool operator==(Vector<T,N> const& l, Vector<T,N> const& r)
{
bool ret = true;
for (std::size_t i = 0; i < N; i++)
ret = ret && (l.data[i] == r.data[i]);
return ret;
}
template<typename T, std::size_t N>
bool operator!=(Vector<T,N> const& l, Vector<T,N> const& r)
{
return !(l == r);
}
template<typename T, std::size_t N>
Vector<T,N> Vector<T,N>::operator-()
{
Vector<T,N> ret;
for (std::size_t i = 0; i < N; i++)
{
ret.data[i] = -data[i];
}
return ret;
}
template<typename T, std::size_t N>
Vector<T,N>& Vector<T,N>::operator+=(Vector<T,N> const& v)
{
for (std::size_t i = 0; i < N; i++)
data[i] += v.data[i];
return *this;
}
template<typename T, std::size_t N>
Vector<T,N>& Vector<T,N>::operator-=(Vector<T,N> const& v)
{
for (std::size_t i = 0; i < N; i++)
data[i] -= v.data[i];
return *this;
}
template<typename T, std::size_t N>
Vector<T,N>& Vector<T,N>::operator*=(float f)
{
for (std::size_t i = 0; i < N; i++)
data[i] *= f;
return *this;
}
template<typename T, std::size_t N>
Vector<T,N>& Vector<T,N>::operator/=(float f)
{
for (std::size_t i = 0; i < N; i++)
data[i] /= f;
return *this;
}
template<typename T, std::size_t N>
Vector<T,N> operator+(Vector<T,N> t, Vector<T,N> const& r) { return t+=r; }
template<typename T, std::size_t N>
Vector<T,N> operator-(Vector<T,N> t, Vector<T,N> const& r) { return t-=r; }
template<typename T, std::size_t N>
Vector<T,N> operator*(Vector<T,N> l, float r) { return l*=r; }
template<typename T, std::size_t N>
Vector<T,N> operator*(float r, Vector<T,N> l) { return l*r; }
template<typename T, std::size_t N>
Vector<T,N> operator/(Vector<T,N> l, float r) { return l/=r; }
template<typename T, std::size_t N>
T operator*(Vector<T,N> const& l, Vector<T,N> const& r)
{
T ret = 0;
for (std::size_t i = 0; i < N; i++)
ret += (l.data[i] * r.data[i]);
return ret;
}
template <typename T>
Vector<T,3> crossProduct(Vector<T,3> const& v1, Vector<T,3> const& v2)
{
return Vector<T,3>{
v1.y() * v2.z() - v1.z() * v2.y(),
v1.z() * v2.x() - v1.x() * v2.z(),
v1.x() * v2.y() - v1.y() * v2.x()
};
}
} // namespace pae

View File

@ -1,65 +0,0 @@
#ifndef VECTOR3_HPP
#define VECTOR3_HPP
#include <cmath>
#include <istream>
namespace pae
{
template<typename T>
class Vector3
{
public:
Vector3();
Vector3(T x, T y, T z);
Vector3(Vector3 const& v);
T norm2() const;
T norm() const;
Vector3<T>& operator=(T t);
Vector3<T>& operator=(Vector3<T> t);
Vector3<T> operator-();
Vector3<T>& operator+=(Vector3<T> const& v);
Vector3<T>& operator-=(Vector3<T> const& v);
Vector3<T>& operator*=(float f);
Vector3<T>& operator/=(float f);
T x;
T y;
T z;
};
template<typename T>
bool operator==(Vector3<T> const& l, Vector3<T> const& r);
template<typename T>
bool operator!=(Vector3<T> const& l, Vector3<T> const& r);
template<typename T>
Vector3<T> operator+(Vector3<T> l, Vector3<T> const& r);
template<typename T>
Vector3<T> operator-(Vector3<T> l, Vector3<T> const& r);
template<typename T>
Vector3<T> operator*(Vector3<T> l, float f);
template<typename T>
Vector3<T> operator/(Vector3<T> l, float f);
template<typename Type>
std::istream& operator>>(std::istream& stream, Vector3<Type>& v);
template<typename Type>
std::ostream& operator<<(std::ostream& stream, Vector3<Type> const& v);
} // namespace pae
#include "Vector3.inl"
#endif // VECTOR3_HPP

View File

@ -1,124 +0,0 @@
#include <iostream>
#include <cmath>
#include "Vector3.hpp"
namespace pae
{
template<typename T>
Vector3<T>::Vector3() : Vector3<T>{0,0,0}
{
}
template<typename T>
Vector3<T>::Vector3(T x, T y, T z) : x{std::move(x)}, y{std::move(y)}, z{std::move(z)}
{
}
template<typename T>
Vector3<T>::Vector3(Vector3 const& v) : Vector3<T>{v.x,v.y,v.z}
{
}
template<typename T>
T Vector3<T>::norm2() const
{
return (*this) * (*this);
}
template<typename T>
T Vector3<T>::norm() const
{
return std::sqrt(norm2());
}
template<typename T>
Vector3<T>& Vector3<T>::operator=(T t)
{
x = t;
y = t;
z = t;
return *this;
}
template<typename T>
Vector3<T>& Vector3<T>::operator=(Vector3<T> t)
{
this->x = std::move(t.x);
this->y = std::move(t.y);
this->z = std::move(t.z);
return *this;
}
template<typename Type>
std::istream& operator>>(std::istream& stream, Vector3<Type>& v)
{
return stream >> v.x >> v.y >> v.z;
}
template<typename Type>
std::ostream& operator<<(std::ostream& stream, Vector3<Type> const& v)
{
return stream << "[" << v.x << ", " << v.y << ", " << v.z << "]";
}
template<typename T>
bool operator==(Vector3<T> const& l, Vector3<T> const& r)
{
return l.x == r.x && l.y == r.y && l.z == r.z;
}
template<typename T>
bool operator!=(Vector3<T> const& l, Vector3<T> const& r)
{
return !(l == r);
}
template<typename T>
Vector3<T> Vector3<T>::operator-() { return Vector3<T>{-x,-y,-z}; }
template<typename T>
Vector3<T>& Vector3<T>::operator+=(Vector3<T> const& v) {x+=v.x; y+=v.y; z+=v.z; return *this;}
template<typename T>
Vector3<T>& Vector3<T>::operator-=(Vector3<T> const& v) {x-=v.x; y-=v.y; z-=v.z; return *this;}
template<typename T>
Vector3<T>& Vector3<T>::operator*=(float f) { x*=f; y*=f; z*=f; return *this;}
template<typename T>
Vector3<T>& Vector3<T>::operator/=(float f) { x/=f; y/=f; z/=f; return *this; }
template<typename T>
Vector3<T> operator+(Vector3<T> t, Vector3<T> const& r) { return t+=r; }
template<typename T>
Vector3<T> operator-(Vector3<T> t, Vector3<T> const& r) { return t-=r; }
template<typename T>
Vector3<T> operator*(Vector3<T> l, float r) { return l*=r; }
template<typename T>
Vector3<T> operator*(float r, Vector3<T> l) { return l*r; }
template<typename T>
Vector3<T> operator/(Vector3<T> l, float r) { return l/=r; }
template<typename T>
T operator*(Vector3<T> const& l, Vector3<T> const& r) { return l.x*r.x + l.y*r.y + l.z*r.z;}
template <typename T>
Vector3<T> crossProduct(Vector3<T> const& v1, Vector3<T> const& v2)
{
return Vector3<T>{v1.y * v2.z - v1.z * v2.y,
v1.z * v2.x - v1.x * v2.z,
v1.x * v2.y - v1.y * v2.x
};
}
} // namespace pae

View File

@ -1,48 +1,41 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include "Vector3.hpp" #include "Vector.hpp"
#include "Skeleton3D.hpp" #include "Skeleton3D.hpp"
#include "Spline.hpp" #include "Spline.hpp"
#include "Mesh.hpp" #include "Mesh.hpp"
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
pae::Skeleton3D<pae::Vector3<float>, float> skeleton; using namespace pae;
skeleton.loadFromFile("dino.skl"); using namespace pae::detail;
auto circles = skeleton.splines[0].computeCircles(12u,16u); Circle<float> c;
c.points.push_back(std::make_pair(7,pae::Vector3<float>{0.0f,2.0f,-1.0f}));
c.points.push_back(std::make_pair(8,pae::Vector3<float>{0.0f,1.0f,-1.0f}));
c.points.push_back(std::make_pair(9,pae::Vector3<float>{0.0f,0.0f,-1.0f}));
// for (auto const& circle : circles) c.points.push_back(std::make_pair(0,pae::Vector3<float>{0.0f,0.0f, 1.0f}));
// { c.points.push_back(std::make_pair(1,pae::Vector3<float>{0.0f,1.0f, 1.0f}));
// std::cout << circle.center << std::endl; c.points.push_back(std::make_pair(2,pae::Vector3<float>{0.0f,2.0f, 1.0f}));
// } c.points.push_back(std::make_pair(3,pae::Vector3<float>{0.0f,3.0f, 1.0f}));
c.points.push_back(std::make_pair(4,pae::Vector3<float>{0.0f,4.0f, 1.0f}));
c.points.push_back(std::make_pair(5,pae::Vector3<float>{0.0f,4.0f,-1.0f}));
c.points.push_back(std::make_pair(6,pae::Vector3<float>{0.0f,3.0f,-1.0f}));
// std::cout << skeleton << std::endl; auto v = sortedPoints(std::array<double,4>{0,0,1,0},
std::vector<Circle<float>>{c},
std::vector<std::pair<Point<float>, Point<float>>>{});
// auto const& splines = skeleton.splines; for (auto& element : v)
{
for (auto& e : element)
{
std::cout << e.first << " " << e.second << std::endl;
}
std::cout << std::endl;
}
// auto spline = splines[7]; return 0;
// unsigned int nbCircles = 10;
// unsigned int const nbPoints = 8;
// //std::vector<pae::Circle<float>> circles = spline.computeCircles(nbCircles, nbPoints);
// auto circles = spline.computeCircles(nbCircles, nbPoints);
pae::Mesh mesh;
mesh = pae::splineMeshing(circles);
// std::cout << mesh << std::endl;
// std::cout << "Il y a : " << mesh.vertices.size() << " vertices." << std::endl;
// std::cout << "Il y a : " << mesh.faces.size() << " faces." << std::endl;
// std:: cout << std::endl;
// for (unsigned int i = 0; i < mesh.faces.size(); i++)
// {
// std::cout << "La face " << i+1 << " est composée des faces " << mesh.faces[i] << std::endl;
// }
// return 0;
} }