Skip to content

Commit

Permalink
simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
sevec committed Jun 24, 2020
1 parent d133428 commit e3495cb
Show file tree
Hide file tree
Showing 20 changed files with 3,029 additions and 135 deletions.
2 changes: 1 addition & 1 deletion Assert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

#include <cassert>

#define ASSERT(x, ...) assert(x)
#define PVL_ASSERT(x, ...) assert(x)
56 changes: 29 additions & 27 deletions Box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,76 @@

namespace Pvl {

template <typename T, int Dim>
template <typename Vec>
class BoundingBox {
Vector<T, Dim> lower_;
Vector<T, Dim> upper_;
Vec lower_;
Vec upper_;

public:
using Vector = Vec;
using Float = typename Vec::Float;

BoundingBox()
: lower_(std::numeric_limits<T>::max())
, upper_(std::numeric_limits<T>::lowest()) {}
: lower_(std::numeric_limits<Float>::max())
, upper_(std::numeric_limits<Float>::lowest()) {}

BoundingBox(const Vector<T, Dim>& lower, const Vector<T, Dim>& upper)
BoundingBox(const Vec& lower, const Vec& upper)
: lower_(lower)
, upper_(upper) {}

Vector<T, Dim>& lower() {
Vec& lower() {
return lower_;
}

const Vector<T, Dim>& lower() const {
const Vec& lower() const {
return lower_;
}

Vector<T, Dim>& upper() {
Vec& upper() {
return upper_;
}

const Vector<T, Dim>& upper() const {
const Vec& upper() const {
return upper_;
}

Vector<T, Dim> size() const {
Vec size() const {
return upper_ - lower_;
}

Vector<T, Dim> center() const {
return T(0.5) * (upper_ + lower_);
Vec center() const {
return Float(0.5) * (upper_ + lower_);
}


bool contains(const Vector<T, Dim>& p) const {
for (int i = 0; i < Dim; ++i) {
bool contains(const Vec& p) const {
for (int i = 0; i < Vec::size(); ++i) {
if (p[i] < lower_[i] || p[i] > upper_[i]) {
return false;
}
}
return true;
}

void extend(const Vector<T, Dim>& p) {
void extend(const Vec& p) {
lower_ = min(lower_, p);
upper_ = max(upper_, p);
}
};

using Box3f = BoundingBox<Vec3f>;

/// \brief Splits the box along given coordinate.
///
/// The splitting plane must pass through the box.
template <typename T, int Dim>
std::pair<BoundingBox<T, Dim>, BoundingBox<T, Dim>> splitBox(const BoundingBox<T, Dim>& box,
const int dim,
const T x) {
template <typename Box, typename T>
std::pair<Box, Box> splitBox(const Box& box, const int dim, const T x) {
/*ASSERT(isValid());*/
ASSERT(dim < Dim);
ASSERT(x >= box.lower()[dim] && x <= box.upper()[dim]);
BoundingBox<T, Dim> b1 = box;
BoundingBox<T, Dim> b2 = box;
b1.lower()[dim] = x;
b2.upper()[dim] = x;
PVL_ASSERT(dim < Box::Vector::size());
PVL_ASSERT(x >= box.lower()[dim] && x <= box.upper()[dim]);
Box b1 = box;
Box b2 = box;
b1.upper()[dim] = x;
b2.lower()[dim] = x;
return std::make_pair(b1, b2);
}

Expand Down
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ project(pvl LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")

find_package(TBB REQUIRED tbb)

find_package(Catch2 REQUIRED catch2)

#find_package( Boost 1.40 COMPONENTS bgl REQUIRED )
#include_directories( ${Boost_INCLUDE_DIR} )
include_directories("/usr/include/catch2/")

add_executable(pvl
main.cpp
Utils.hpp
Expand All @@ -16,12 +24,14 @@ add_executable(pvl
Matrix.hpp
Svd.hpp
Box.hpp
KdTree.h KdTree.inl.h
KdTree.hpp KdTree.inl.hpp
PlyWriter.hpp PlyReader.hpp
Cloud.hpp
CloudUtils.hpp
Kernels.hpp
TriangleMesh.hpp
MeshUtils.hpp
Refinement.hpp
Simplification.hpp
Range.hpp
Graph.hpp Graph.inl.hpp
UniformGrid.hpp
Expand Down
60 changes: 59 additions & 1 deletion Cloud.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
#pragma once

namespace Pvl {}
#include "Box.hpp"
#include <vector>

namespace Pvl {

template <typename Type>
class CloudProperty {
private:
std::vector<Type> values_;

public:
};


template <typename Vec>
class PointInsideBoxPredicate {
BoundingBox<Vec> box_;

public:
bool operator()(const Vec& p) const {
return box_.contains(p);
}
};

template <typename Iterator, typename Predicate>
class SubsetIterator {
Iterator iter_;
Predicate predicate_;

public:
SubsetIterator(const Predicate& predicate)
: predicate_(predicate) {}

SubsetIterator& operator++() {
do {
++iter_;
} while (!predicate_());
return *this;
}

bool operator!=(const SubsetIterator& other) const {
return iter_ != other.iter_;
}
};

template <typename Predicate>
class CloudSubset {
public:
/*SubsetIterator<Predicate> begin() {}
SubsetIterator<Predicate> end() {}*/
};

template <typename... Properties>
class Cloud : public Properties... {};

// using MyCloud = Cloud<Velocity, Normals, Colors, Custom>;

} // namespace Pvl
Loading

0 comments on commit e3495cb

Please sign in to comment.