qadmesh affine transform parenting
This commit is contained in:
@@ -180,7 +180,7 @@ public:
|
||||
signals:
|
||||
|
||||
// signal to emit when the box is updated //
|
||||
void Updated() { ULIB_SIGNAL_EMIT(ContainerBox::Updated); }
|
||||
virtual void Updated() override { ULIB_SIGNAL_EMIT(ContainerBox::Updated); }
|
||||
|
||||
private:
|
||||
AffineTransform m_LocalT;
|
||||
|
||||
@@ -35,10 +35,10 @@ void QuadMesh::PrintSelf(std::ostream &o)
|
||||
o << " #Quads : " << m_Quads.size() << "\n";
|
||||
for(int i=0; i < m_Quads.size(); ++i ) {
|
||||
o << " - quad[" << i << "]" <<
|
||||
" " << m_Quads[i](0) << "->(" << m_Points[m_Quads[i](0)].transpose() << ") " <<
|
||||
" " << m_Quads[i](1) << "->(" << m_Points[m_Quads[i](1)].transpose() << ") " <<
|
||||
" " << m_Quads[i](2) << "->(" << m_Points[m_Quads[i](2)].transpose() << ") " <<
|
||||
" " << m_Quads[i](3) << "->(" << m_Points[m_Quads[i](3)].transpose() << ") " <<
|
||||
" " << m_Quads[i](0) << "->(" << GetPoint(m_Quads[i](0)).transpose() << ") " <<
|
||||
" " << m_Quads[i](1) << "->(" << GetPoint(m_Quads[i](1)).transpose() << ") " <<
|
||||
" " << m_Quads[i](2) << "->(" << GetPoint(m_Quads[i](2)).transpose() << ") " <<
|
||||
" " << m_Quads[i](3) << "->(" << GetPoint(m_Quads[i](3)).transpose() << ") " <<
|
||||
" \n";
|
||||
}
|
||||
o << " // ------------------------- // \n";
|
||||
@@ -46,7 +46,16 @@ void QuadMesh::PrintSelf(std::ostream &o)
|
||||
|
||||
void QuadMesh::AddPoint(const Vector3f &pt)
|
||||
{
|
||||
this->m_Points.push_back(pt);
|
||||
Vector4f p(pt.x(), pt.y(), pt.z(), 1.0f);
|
||||
Vector4f localP = this->GetWorldMatrix().inverse() * p;
|
||||
this->m_Points.push_back(localP.head<3>());
|
||||
}
|
||||
|
||||
Vector3f QuadMesh::GetPoint(const Id_t id) const
|
||||
{
|
||||
Vector4f p(m_Points.at(id).x(), m_Points.at(id).y(), m_Points.at(id).z(), 1.0f);
|
||||
Vector4f worldP = this->GetWorldMatrix() * p;
|
||||
return worldP.head<3>();
|
||||
}
|
||||
|
||||
void QuadMesh::AddQuad(const Id_t *id)
|
||||
@@ -63,9 +72,9 @@ void QuadMesh::AddQuad(const Vector4i &id)
|
||||
Vector3f QuadMesh::GetNormal(const Id_t id) const
|
||||
{
|
||||
const Vector4i &quad = m_Quads.at(id);
|
||||
const Vector3f &v0 = m_Points.at(quad(0));
|
||||
const Vector3f &v1 = m_Points.at(quad(1));
|
||||
const Vector3f &v3 = m_Points.at(quad(3));
|
||||
const Vector3f v0 = this->GetPoint(quad(0));
|
||||
const Vector3f v1 = this->GetPoint(quad(1));
|
||||
const Vector3f v3 = this->GetPoint(quad(3));
|
||||
|
||||
Vector3f edge1 = v1 - v0;
|
||||
Vector3f edge2 = v3 - v0;
|
||||
|
||||
@@ -29,25 +29,33 @@
|
||||
#include <vector>
|
||||
|
||||
#include "Math/Dense.h"
|
||||
#include "Core/Object.h"
|
||||
#include "Math/Transform.h"
|
||||
|
||||
namespace uLib {
|
||||
|
||||
class QuadMesh
|
||||
class QuadMesh : public AffineTransform, public Object
|
||||
{
|
||||
public:
|
||||
void PrintSelf(std::ostream &o);
|
||||
|
||||
/** @brief Adds a point in global coordinates. Stored in local coordinates. */
|
||||
void AddPoint(const Vector3f &pt);
|
||||
|
||||
void AddQuad(const Id_t *id);
|
||||
void AddQuad(const Vector4i &id);
|
||||
|
||||
/** @brief Returns point in global coordinates. */
|
||||
Vector3f GetPoint(const Id_t id) const;
|
||||
|
||||
inline std::vector<Vector3f> & Points() { return this->m_Points; }
|
||||
inline std::vector<Vector4i> & Quads() { return this->m_Quads; }
|
||||
|
||||
const Vector4i & GetQuad(const Id_t id) const { return m_Quads.at(id); }
|
||||
Vector3f GetNormal(const Id_t id) const;
|
||||
|
||||
virtual void Updated() override { ULIB_SIGNAL_EMIT(QuadMesh::Updated); }
|
||||
|
||||
private:
|
||||
std::vector<Vector3f> m_Points;
|
||||
std::vector<Vector4i> m_Quads;
|
||||
|
||||
@@ -47,5 +47,17 @@ int main() {
|
||||
ASSERT_EQ(mesh.Points().size(), 4);
|
||||
ASSERT_EQ(mesh.Quads().size(), 1);
|
||||
|
||||
// Test transformation
|
||||
mesh.Translate(Vector3f(10, 20, 30));
|
||||
Vector3f p0 = mesh.GetPoint(0);
|
||||
TEST1( (p0 - Vector3f(10, 20, 30)).norm() < 1e-6 );
|
||||
|
||||
// Test AddPoint during transformation
|
||||
mesh.AddPoint(Vector3f(11, 21, 31)); // Should be stored as (1, 1, 1) locally
|
||||
Id_t lastId = mesh.Points().size() - 1;
|
||||
TEST1( (mesh.Points().at(lastId) - Vector3f(1, 1, 1)).norm() < 1e-5 );
|
||||
|
||||
mesh.PrintSelf(std::cout);
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user