CGI/exercise4/src/Point.cpp

65 lines
1.6 KiB
C++
Raw Normal View History

2019-01-24 14:38:18 +00:00
// This source code is property of the Computer Graphics and Visualization
// chair of the TU Dresden. Do not distribute!
2018-09-06 12:35:43 +00:00
// Copyright (C) CGV TU Dresden - All Rights Reserved
#include "Point.h"
#include "GridUtils.h"
//default constructor
2019-01-24 14:38:18 +00:00
Point::Point() {}
2018-09-06 12:35:43 +00:00
//construct a point with given point position v0
2019-01-24 14:38:18 +00:00
Point::Point(const Eigen::Vector3f &v0) : v0(v0)
2018-09-06 12:35:43 +00:00
{
}
//construct a point from vertex v of giben halfedge mesh m
2019-01-24 14:38:18 +00:00
Point::Point(const HEMesh &m, const OpenMesh::VertexHandle &v) : h(v)
2018-09-06 12:35:43 +00:00
{
v0 = ToEigenVector(m.point(v));
}
2019-01-24 14:38:18 +00:00
2018-09-06 12:35:43 +00:00
//returns axis aligned bounding box of point
Box Point::ComputeBounds() const
{
2019-01-24 14:38:18 +00:00
Box b;
2018-09-06 12:35:43 +00:00
b.Insert(v0);
2019-01-24 14:38:18 +00:00
2018-09-06 12:35:43 +00:00
return b;
}
//returns true if point overlap with box b
2019-01-24 14:38:18 +00:00
bool Point::Overlaps(const Box &b) const
2018-09-06 12:35:43 +00:00
{
Eigen::Vector3f lb = b.LowerBound();
Eigen::Vector3f ub = b.UpperBound();
2019-01-24 14:38:18 +00:00
return (v0[0] >= lb[0] && v0[0] <= ub[0] &&
v0[1] >= lb[1] && v0[1] <= ub[1] &&
v0[2] >= lb[2] && v0[2] <= ub[2]);
2018-09-06 12:35:43 +00:00
}
//returns the point position
2019-01-24 14:38:18 +00:00
Eigen::Vector3f Point::ClosestPoint(const Eigen::Vector3f &p) const
2018-09-06 12:35:43 +00:00
{
return v0;
}
//returns the squared distance between the query point p and the current point
2019-01-24 14:38:18 +00:00
float Point::SqrDistance(const Eigen::Vector3f &p) const
2018-09-06 12:35:43 +00:00
{
2019-01-24 14:38:18 +00:00
Eigen::Vector3f d = p - ClosestPoint(p);
2018-09-06 12:35:43 +00:00
return d.squaredNorm();
}
//returns the euclidean distance between the query point p and the current point
2019-01-24 14:38:18 +00:00
float Point::Distance(const Eigen::Vector3f &p) const
2018-09-06 12:35:43 +00:00
{
return sqrt(SqrDistance(p));
}
//returns a the position of the point as a reference point which is used to sort the primitive in the AABB tree construction
Eigen::Vector3f Point::ReferencePoint() const
{
return v0;
}