Cpp autoformatter

This commit is contained in:
hodasemi 2019-01-24 15:38:18 +01:00
parent 87e032c473
commit 8a97a05969
18 changed files with 518 additions and 552 deletions

View file

@ -13,7 +13,6 @@
#include "LineSegment.h" #include "LineSegment.h"
#include "Point.h" #include "Point.h"
/** /**
* Axis aligned bounding volume hierachy data structure. * Axis aligned bounding volume hierachy data structure.
*/ */
@ -33,11 +32,14 @@ public:
protected: protected:
//storage of bounding box assosiated with aabb_node //storage of bounding box assosiated with aabb_node
Box bounds; Box bounds;
public: public:
AABBNode() { AABBNode()
{
} }
AABBNode(const Box& b): bounds(b) { AABBNode(const Box &b) : bounds(b)
{
} }
//returns the bounding box of the node //returns the bounding box of the node
@ -48,12 +50,10 @@ public:
virtual int NumPrimitives() const = 0; virtual int NumPrimitives() const = 0;
//this method must be implemented to return true for a leaf node and false for a non_lef node //this method must be implemented to return true for a leaf node and false for a non_lef node
virtual bool IsLeaf() const = 0; virtual bool IsLeaf() const = 0;
//virtual destructor //virtual destructor
virtual ~AABBNode() {} virtual ~AABBNode() {}
}; };
///a class representing a leaf node of an aabb tree (non split node) ///a class representing a leaf node of an aabb tree (non split node)
class AABBLeafNode : public AABBNode class AABBLeafNode : public AABBNode
@ -61,14 +61,12 @@ public:
//internal storage to the range (begin and end pointer) of the primitives associated with the current leaf node //internal storage to the range (begin and end pointer) of the primitives associated with the current leaf node
PrimitiveIterator primitivesBegin, primitivesEnd; PrimitiveIterator primitivesBegin, primitivesEnd;
public: public:
//construct a leaf node from //construct a leaf node from
AABBLeafNode(const PrimitiveIterator &primitivesBegin, AABBLeafNode(const PrimitiveIterator &primitivesBegin,
const PrimitiveIterator &primitivesEnd, const PrimitiveIterator &primitivesEnd,
const Box& b): const Box &b) : primitivesBegin(primitivesBegin), primitivesEnd(primitivesEnd), AABBNode(b)
primitivesBegin(primitivesBegin),primitivesEnd(primitivesEnd), AABBNode(b)
{ {
} }
@ -92,8 +90,6 @@ public:
{ {
return primitivesEnd; return primitivesEnd;
} }
}; };
///a class representing a split node of an aabb tree (non leaf node) ///a class representing a split node of an aabb tree (non leaf node)
@ -101,6 +97,7 @@ public:
{ {
//child pointers //child pointers
AABBNode *children[2]; AABBNode *children[2];
public: public:
//default constructor //default constructor
AABBSplitNode() AABBSplitNode()
@ -157,7 +154,6 @@ public:
{ {
return Left()->NumPrimitives() + Right()->NumPrimitives(); return Left()->NumPrimitives() + Right()->NumPrimitives();
} }
}; };
private: private:
@ -172,7 +168,8 @@ private:
//constructor //constructor
SearchEntry(float sqrDistance, const AABBNode *node) SearchEntry(float sqrDistance, const AABBNode *node)
: sqrDistance(sqrDistance), node(node) : sqrDistance(sqrDistance), node(node)
{ } {
}
//search entry a < b means a.sqr_distance > b. sqr_distance //search entry a < b means a.sqr_distance > b. sqr_distance
bool operator<(const SearchEntry &e) const bool operator<(const SearchEntry &e) const
@ -191,11 +188,13 @@ private:
//default constructor //default constructor
ResultEntry() ResultEntry()
: sqrDistance(std::numeric_limits<float>::infinity()), prim(nullptr) : sqrDistance(std::numeric_limits<float>::infinity()), prim(nullptr)
{ } {
}
//constructor //constructor
ResultEntry(float sqrDistance, const Primitive *p) ResultEntry(float sqrDistance, const Primitive *p)
: sqrDistance(sqrDistance), prim(p) : sqrDistance(sqrDistance), prim(p)
{ } {
}
//result_entry are sorted by their sqr_distance using this less than operator //result_entry are sorted by their sqr_distance using this less than operator
bool operator<(const ResultEntry &e) const bool operator<(const ResultEntry &e) const
{ {
@ -214,7 +213,6 @@ private:
//a flag indicating if the tree is constructed //a flag indicating if the tree is constructed
bool completed; bool completed;
public: public:
//returns a pointer to the root node of the tree //returns a pointer to the root node of the tree
AABBNode *Root() AABBNode *Root()
@ -233,10 +231,8 @@ public:
//constructor of aabb tree //constructor of aabb tree
//default maximal tree depth is 20 //default maximal tree depth is 20
//default minimal size of a node not to be further subdivided in the cnstruction process is two //default minimal size of a node not to be further subdivided in the cnstruction process is two
AABBTree(int maxDepth=20, int minSize=2): AABBTree(int maxDepth = 20, int minSize = 2) : maxDepth(maxDepth), minSize(minSize), root(nullptr), completed(false)
maxDepth(maxDepth),minSize(minSize),root(nullptr),completed(false)
{ {
} }
//copy constructor //copy constructor
@ -380,7 +376,6 @@ public:
k_best.pop(); k_best.pop();
} }
return result; return result;
} }
//closest k primitive computation //closest k primitive computation
@ -421,9 +416,7 @@ public:
return sqrt(SqrDistance(p)); return sqrt(SqrDistance(p));
} }
protected: protected:
//helper function to copy a subtree //helper function to copy a subtree
AABBNode *CopyTree(const primitive_list &other_primitives, AABBNode *node) AABBNode *CopyTree(const primitive_list &other_primitives, AABBNode *node)
{ {
@ -453,8 +446,6 @@ protected:
return bounds; return bounds;
} }
//recursive tree construction initially called from method complete() //recursive tree construction initially called from method complete()
//build an aabb (sub)-tree over the range of primitives [begin,end), //build an aabb (sub)-tree over the range of primitives [begin,end),
//the current bounding box is given by bounds and the current tree depth is given by the parameter depth //the current bounding box is given by bounds and the current tree depth is given by the parameter depth
@ -491,16 +482,13 @@ protected:
max_extent = e[2]; max_extent = e[2];
} }
PrimitiveIterator mid = begin + (end - begin) / 2; PrimitiveIterator mid = begin + (end - begin) / 2;
std::nth_element(begin,mid,end,[&axis](const Primitive& a, const Primitive& b) std::nth_element(begin, mid, end, [&axis](const Primitive &a, const Primitive &b) { return a.ReferencePoint()[axis] < b.ReferencePoint()[axis]; });
{ return a.ReferencePoint()[axis] < b.ReferencePoint()[axis];});
Box lbounds = ComputeBounds(begin, mid); Box lbounds = ComputeBounds(begin, mid);
Box rbounds = ComputeBounds(mid, end); Box rbounds = ComputeBounds(mid, end);
return new AABBSplitNode(Build(begin, mid, lbounds, depth + 1), Build(mid, end, rbounds, depth + 1), bounds); return new AABBSplitNode(Build(begin, mid, lbounds, depth + 1), Build(mid, end, rbounds, depth + 1), bounds);
} }
}; };
@ -510,4 +498,3 @@ void BuildAABBTreeFromTriangles(const HEMesh& m, AABBTree<Triangle >& tree);
void BuildAABBTreeFromVertices(const HEMesh &m, AABBTree<Point> &tree); void BuildAABBTreeFromVertices(const HEMesh &m, AABBTree<Point> &tree);
//helper function to construct an aabb tree data structure from the edges of the halfedge mesh m //helper function to construct an aabb tree data structure from the edges of the halfedge mesh m
void BuildAABBTreeFromEdges(const HEMesh &m, AABBTree<LineSegment> &tree); void BuildAABBTreeFromEdges(const HEMesh &m, AABBTree<LineSegment> &tree);

View file

@ -12,7 +12,6 @@ class Box
std::pair<Eigen::Vector3f, Eigen::Vector3f> bounds; std::pair<Eigen::Vector3f, Eigen::Vector3f> bounds;
public: public:
//creates an empty box like the method Clear //creates an empty box like the method Clear
Box(); Box();
@ -77,5 +76,4 @@ public:
//returns the euclidean distance between p and the box //returns the euclidean distance between p and the box
float Distance(const Eigen::Vector3f &p) const; float Distance(const Eigen::Vector3f &p) const;
}; };

View file

@ -47,6 +47,4 @@ public:
//returns a reference point which is on the line segment and is used to sort the primitive in the AABB tree construction //returns a reference point which is on the line segment and is used to sort the primitive in the AABB tree construction
Eigen::Vector3f ReferencePoint() const; Eigen::Vector3f ReferencePoint() const;
}; };

View file

@ -6,7 +6,6 @@
#include "Box.h" #include "Box.h"
#include "util/OpenMeshUtils.h" #include "util/OpenMeshUtils.h"
/* /*
a triangle primitive which can be used with the AABBTree and the HashGrid data structure a triangle primitive which can be used with the AABBTree and the HashGrid data structure
*/ */
@ -22,7 +21,6 @@ class Triangle
OpenMesh::FaceHandle h; OpenMesh::FaceHandle h;
public: public:
//default constructor //default constructor
Triangle(); Triangle();
//constructs a triangle using the vertex positions v0,v1 and v2 //constructs a triangle using the vertex positions v0,v1 and v2
@ -43,6 +41,4 @@ public:
float Distance(const Eigen::Vector3f &p) const; float Distance(const Eigen::Vector3f &p) const;
//returns a reference point which is on the triangle and is used to sort the primitive in the AABB tree construction //returns a reference point which is on the triangle and is used to sort the primitive in the AABB tree construction
Eigen::Vector3f ReferencePoint() const; Eigen::Vector3f ReferencePoint() const;
}; };

View file

@ -24,10 +24,11 @@ public:
void drawContents(); void drawContents();
private: private:
enum PrimitiveType enum PrimitiveType
{ {
Vertex, Edge, Tri Vertex,
Edge,
Tri
}; };
void SetupGUI(); void SetupGUI();

View file

@ -6,7 +6,6 @@
#include "GridUtils.h" #include "GridUtils.h"
#include <limits> #include <limits>
//creates an empty box like the method Clear //creates an empty box like the method Clear
Box::Box() Box::Box()
{ {
@ -174,5 +173,3 @@ float Box::Distance(const Eigen::Vector3f& p) const
{ {
return sqrt(SqrDistance(p)); return sqrt(SqrDistance(p));
} }

View file

@ -5,9 +5,9 @@
#include "GridTraverser.h" #include "GridTraverser.h"
#include "GridUtils.h" #include "GridUtils.h"
GridTraverser::GridTraverser() GridTraverser::GridTraverser()
{ } {
}
GridTraverser::GridTraverser(const Eigen::Vector3f &o, const Eigen::Vector3f &d, const Eigen::Vector3f cell_extents) GridTraverser::GridTraverser(const Eigen::Vector3f &o, const Eigen::Vector3f &d, const Eigen::Vector3f cell_extents)
: orig(o), dir(d), cellExtents(cell_extents) : orig(o), dir(d), cellExtents(cell_extents)
@ -59,5 +59,3 @@ Eigen::Vector3i GridTraverser::operator*()
{ {
return current; return current;
} }

View file

@ -5,7 +5,6 @@
#include "LineSegment.h" #include "LineSegment.h"
#include "GridUtils.h" #include "GridUtils.h"
//default constructor //default constructor
LineSegment::LineSegment() LineSegment::LineSegment()
{ {
@ -86,10 +85,7 @@ bool LineSegment::Overlaps(const Box& b) const
if (!OverlapIntervals(-r, r, lb, ub)) if (!OverlapIntervals(-r, r, lb, ub))
return false; return false;
return true; return true;
} }
//returns the point with smallest distance topoint p which lies on the line segment //returns the point with smallest distance topoint p which lies on the line segment
@ -118,6 +114,3 @@ Eigen::Vector3f LineSegment::ReferencePoint() const
{ {
return 0.5f * (v0 + v1); return 0.5f * (v0 + v1);
} }

View file

@ -33,8 +33,7 @@ bool Point::Overlaps(const Box& b) const
{ {
Eigen::Vector3f lb = b.LowerBound(); Eigen::Vector3f lb = b.LowerBound();
Eigen::Vector3f ub = b.UpperBound(); Eigen::Vector3f ub = b.UpperBound();
return return (v0[0] >= lb[0] && v0[0] <= ub[0] &&
(v0[0] >= lb[0] && v0[0] <= ub[0]&&
v0[1] >= lb[1] && v0[1] <= ub[1] && v0[1] >= lb[1] && v0[1] <= ub[1] &&
v0[2] >= lb[2] && v0[2] <= ub[2]); v0[2] >= lb[2] && v0[2] <= ub[2]);
} }

View file

@ -6,7 +6,6 @@
#include "GridUtils.h" #include "GridUtils.h"
#include <tuple> #include <tuple>
//default constructor //default constructor
Triangle::Triangle() Triangle::Triangle()
{ {
@ -33,7 +32,6 @@ Box Triangle::ComputeBounds() const
return b; return b;
} }
//returns true if the triangle overlaps the given box b //returns true if the triangle overlaps the given box b
bool Triangle::Overlaps(const Box &b) const bool Triangle::Overlaps(const Box &b) const
{ {
@ -75,7 +73,6 @@ void Triangle::ClosestPointBarycentric(const Eigen::Vector3f& p, float& l0, floa
s = 0.f; s = 0.f;
t = -e / c; t = -e / c;
t = std::min(std::max(t, 0.0f), 1.0f); t = std::min(std::max(t, 0.0f), 1.0f);
} }
} }
else else
@ -157,7 +154,6 @@ Eigen::Vector3f Triangle::ClosestPoint(const Eigen::Vector3f& p) const
float l0, l1, l2; float l0, l1, l2;
ClosestPointBarycentric(p, l0, l1, l2); ClosestPointBarycentric(p, l0, l1, l2);
return l0 * v0 + l1 * v1 + l2 * v2; return l0 * v0 + l1 * v1 + l2 * v2;
} }
//returns the squared distance between point p and the triangle //returns the squared distance between point p and the triangle
float Triangle::SqrDistance(const Eigen::Vector3f &p) const float Triangle::SqrDistance(const Eigen::Vector3f &p) const
@ -175,6 +171,3 @@ Eigen::Vector3f Triangle::ReferencePoint() const
{ {
return (v0 + v1 + v2) / 3.0f; return (v0 + v1 + v2) / 3.0f;
} }

View file

@ -75,9 +75,12 @@ void Viewer::SetupGUI()
}); });
sldRaySteps->callback()(sldRaySteps->value()); sldRaySteps->callback()(sldRaySteps->value());
chkRenderMesh = new nanogui::CheckBox(mainWindow, "Render Mesh"); chkRenderMesh->setChecked(true); chkRenderMesh = new nanogui::CheckBox(mainWindow, "Render Mesh");
chkRenderGrid = new nanogui::CheckBox(mainWindow, "Render Non-Empty Grid Cells"); chkRenderGrid->setChecked(false); chkRenderMesh->setChecked(true);
chkRenderRay = new nanogui::CheckBox(mainWindow, "Render Ray"); chkRenderRay->setChecked(false); chkRenderGrid = new nanogui::CheckBox(mainWindow, "Render Non-Empty Grid Cells");
chkRenderGrid->setChecked(false);
chkRenderRay = new nanogui::CheckBox(mainWindow, "Render Ray");
chkRenderRay->setChecked(false);
shadingBtn = new nanogui::ComboBox(mainWindow, {"Smooth Shading", "Flat Shading"}); shadingBtn = new nanogui::ComboBox(mainWindow, {"Smooth Shading", "Flat Shading"});
@ -200,10 +203,14 @@ void Viewer::AddBoxVertices(const Box & box, std::vector<Eigen::Vector4f>& posit
{ {
auto &lb = box.LowerBound(); auto &lb = box.LowerBound();
auto &ub = box.UpperBound(); auto &ub = box.UpperBound();
Eigen::Vector4f o; o << lb, 1.0f; Eigen::Vector4f o;
Eigen::Vector4f x; x << ub.x() - lb.x(), 0, 0, 0; o << lb, 1.0f;
Eigen::Vector4f y; y << 0, ub.y() - lb.y(), 0, 0; Eigen::Vector4f x;
Eigen::Vector4f z; z << 0, 0, ub.z() - lb.z(), 0; x << ub.x() - lb.x(), 0, 0, 0;
Eigen::Vector4f y;
y << 0, ub.y() - lb.y(), 0, 0;
Eigen::Vector4f z;
z << 0, 0, ub.z() - lb.z(), 0;
positions.push_back(o); positions.push_back(o);
positions.push_back(o + x); positions.push_back(o + x);
positions.push_back(o + x); positions.push_back(o + x);

View file

@ -29,7 +29,6 @@ int main(int argc, char* argv[])
{ {
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
} }
} }
nanogui::shutdown(); nanogui::shutdown();