Skip to content

Commit

Permalink
Update accelerator interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsy committed Mar 12, 2016
1 parent 4935777 commit 05b7653
Show file tree
Hide file tree
Showing 23 changed files with 382 additions and 415 deletions.
2 changes: 1 addition & 1 deletion include/spica.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// --------------------------------------------
// Accelerators
// --------------------------------------------
#include "../sources/accel/bbvh_accel.h"
#include "../sources/accelerator/spica_accelerator.h"

// --------------------------------------------
// BxDF
Expand Down
2 changes: 1 addition & 1 deletion sources/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ process_subdirectory(random)
process_subdirectory(light)
process_subdirectory(camera)
process_subdirectory(scenes)
process_subdirectory(accel)
process_subdirectory(accelerator)
process_subdirectory(material)
process_subdirectory(texture)

Expand Down
10 changes: 6 additions & 4 deletions sources/accelerator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
set(ACCEL_SOURCES ${ACCEL_SOURCES}
${CMAKE_CURRENT_LIST_DIR}/kdtree.cc
# ${CMAKE_CURRENT_LIST_DIR}/kdtree.cc
${CMAKE_CURRENT_LIST_DIR}/bvh.cc
${CMAKE_CURRENT_LIST_DIR}/qbvh.cc)
# ${CMAKE_CURRENT_LIST_DIR}/qbvh.cc
)

set(ACCEL_HEADERS ${ACCEL_HEADERS}
${CMAKE_CURRENT_LIST_DIR}/spica_accelerator.h
${CMAKE_CURRENT_LIST_DIR}/accelerator.h
${CMAKE_CURRENT_LIST_DIR}/kdtree.h
# ${CMAKE_CURRENT_LIST_DIR}/kdtree.h
${CMAKE_CURRENT_LIST_DIR}/bvh.h
${CMAKE_CURRENT_LIST_DIR}/qbvh.h)
# ${CMAKE_CURRENT_LIST_DIR}/qbvh.h
)

set(SOURCES ${SOURCES} ${ACCEL_SOURCES} PARENT_SCOPE)
set(HEADERS ${HEADERS} ${ACCEL_HEADERS} PARENT_SCOPE)
58 changes: 13 additions & 45 deletions sources/accelerator/accelerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#pragma once
#endif

#ifndef _SPICA_ACCEL_INTERFACE_H_
#define _SPICA_ACCEL_INTERFACE_H_
#ifndef _SPICA_ACCELERATOR_H_
#define _SPICA_ACCELERATOR_H_

#include <vector>
#include <map>
Expand All @@ -18,66 +18,34 @@

namespace spica {

/** Accelerator type enum
/** Interface for intersection test accelerators.
* @ingroup accel_module
* @brief Enumerator for acclerator types.
*/
enum class AccelType : int {
KdTree, /**< K-D tree acclerator */
BBVH, /**< binary BVH accelerator */
QBVH /**< SIMD-acclerated QBVH acclerator */
};

/** Interface for intersection test accelerators.
* @ingroup accel_module
*/
class SPICA_EXPORTS AccelInterface : public Aggregate, Uncopyable {
class SPICA_EXPORTS Accelerator : public Aggregate, Uncopyable {
public:
// Public methods
explicit AccelInterface(AccelType type) : type_{ type } {}
virtual ~AccelInterface() {}
explicit Accelerator(const std::vector<std::shared_ptr<Primitive>>& primitives)
: primitives_{ primitives } {}
virtual ~Accelerator() {}
virtual void construct() = 0;
virtual Bounds3d worldBound() const override {
return worldBound_;
}

inline const std::vector<std::shared_ptr<Primitive>>& primitives() const {
return primitives_;
}

protected:
// Protected internal classes
struct IndexedTriangle;
struct AxisComparator;

// Protected fields
AccelType type_;
std::vector<std::shared_ptr<Primitive>> primitives_;
Bounds3d worldBound_;
};

struct AccelInterface::IndexedTriangle {
IndexedTriangle()
: idx(-1)
, tri() {
}
IndexedTriangle(int i, const Triangle& t)
: idx(i)
, tri(t) {
}

int idx;
Triangle tri;
};

struct AccelInterface::AxisComparator {
int dim;
explicit AxisComparator(int dim_ = 0)
: dim(dim_)
{
Assertion(0 <= dim_ && dim_ <= 2, "Dimension must be between 0 and 2");
}

bool operator()(const IndexedTriangle& t1, const IndexedTriangle& t2) const {
return t1.tri.gravity()[dim] < t2.tri.gravity()[dim];
}
};

} // namespace spica

#endif // _SPICA_ACCEL_INTERFACE_H_
#endif // _SPICA_ACCELERATOR_H_
7 changes: 3 additions & 4 deletions sources/accelerator/bvh.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define SPICA_API_EXPORT
#include "bbvh_accel.h"
#include "bvh.h"

#include <stack>
#include <functional>
Expand Down Expand Up @@ -92,10 +92,9 @@ struct BBVHAccel::CompareToBucket {
};

BBVHAccel::BBVHAccel(const std::vector<std::shared_ptr<Primitive>>& prims,
int maxPrimsInNode)
: AccelInterface{ AccelType::BBVH }
int maxPrimsInNode)
: Accelerator{ prims }
, maxPrimInNode_{ maxPrimsInNode }
, primitives_{ prims }
, _root{ nullptr } {
construct();
}
Expand Down
7 changes: 2 additions & 5 deletions sources/accelerator/bvh.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

#include <memory>

#include "accel_interface.h"
#include "accelerator.h"

namespace spica {

/** Binary BVH accelerator class
* @ingroup accel_module
*/
class SPICA_EXPORTS BBVHAccel : public AccelInterface {
class SPICA_EXPORTS BBVHAccel : public Accelerator {
public:
BBVHAccel(const std::vector<std::shared_ptr<Primitive>> &prims,
int maxPrimsInNode = 1);
Expand All @@ -40,11 +40,8 @@ class SPICA_EXPORTS BBVHAccel : public AccelInterface {

// Private fields
const int maxPrimInNode_;
std::vector<std::shared_ptr<Primitive>> primitives_;
BBvhNode* _root;
//std::vector<Triangle> _tris;
std::vector<std::unique_ptr<BBvhNode> > _nodes;
//void release();

}; // class BBVHAccel

Expand Down
4 changes: 2 additions & 2 deletions sources/accelerator/kdtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <vector>

#include "accel_interface.h"
#include "accelerator.h"
#include "../core/common.h"
#include "../core/uncopyable.h"

Expand All @@ -17,7 +17,7 @@ namespace spica {
* K-D tree accelerator class
* @ingroup accel_module
*/
class SPICA_EXPORTS KdTreeAccel : public AccelInterface {
class SPICA_EXPORTS KdTreeAccel : public Accelerator {
private:
struct KdTreeNode {
Bounds3d bbox;
Expand Down
4 changes: 2 additions & 2 deletions sources/accelerator/qbvh.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
#include <vector>
#include <xmmintrin.h>

#include "accel_interface.h"
#include "accelerator.h"

namespace spica {

/**
* Quad BVH accelerator class
* @ingroup accel_module
*/
class SPICA_EXPORTS QBVHAccel : public AccelInterface {
class SPICA_EXPORTS QBVHAccel : public Accelerator {
public:
QBVHAccel();
virtual ~QBVHAccel();
Expand Down
13 changes: 13 additions & 0 deletions sources/accelerator/spica_accelerator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifdef _MSC_VER
#pragma once
#endif

#ifndef _SPICA_ACCELERATOR_HEADERS_H_
#define _SPICA_ACCELERATOR_HEADERS_H_

#include "accelerator.h"
#include "bvh.h"
// #include "kdtree.h"
// #include "qbvh.h"

#endif // _SPICA_ACCELERATOR_HEADERS_H_
1 change: 1 addition & 0 deletions sources/core/bounds3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Bounds3_ {

void merge(const Bounds3_<T>& b);
void merge(const Point3_<T>& p);
bool inside(const Point3_<T>& p) const;

T area() const;

Expand Down
7 changes: 7 additions & 0 deletions sources/core/bounds3d_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ void Bounds3_<T>::merge(const Point3_<T>& p) {
posMax_ = Point3_<T>::maximum(p, posMax_);
}

template <class T>
bool Bounds3_<T>::inside(const Point3_<T>& p) const {
return (posMin_.x() < p.x() && p.x() < posMax_.x() &&
posMin_.x() < p.y() && p.x() < posMax_.y() &&
posMin_.x() < p.z() && p.x() < posMax_.z());
}

template <class T>
T Bounds3_<T>::area() const {
Vector3_<T> diff = posMax_ - posMin_;
Expand Down
2 changes: 1 addition & 1 deletion sources/core/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "../random/random.h"
#include "../random/halton.h"

#include "../accel/bbvh_accel.h"
#include "../accelerator/spica_accelerator.h"
#include "../scenes/scene.h"

#include <boost/property_tree/ptree.hpp>
Expand Down
1 change: 1 addition & 0 deletions sources/core/primitive.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "../core/interaction.h"
#include "../shape/shape.h"
#include "../shape/triangle.h"
#include "../material/material.h"

namespace spica {
Expand Down
8 changes: 4 additions & 4 deletions sources/integrator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ set(SOURCES
${CMAKE_CURRENT_LIST_DIR}/directlighting.cc
# ${CMAKE_CURRENT_LIST_DIR}/bdpt.cc
# ${CMAKE_CURRENT_LIST_DIR}/mlt.cc
# ${CMAKE_CURRENT_LIST_DIR}/photon_map.cc
# ${CMAKE_CURRENT_LIST_DIR}/ppmprob.cc
${CMAKE_CURRENT_LIST_DIR}/sppm.cc
${CMAKE_CURRENT_LIST_DIR}/hierarchical.cc
# ${CMAKE_CURRENT_LIST_DIR}/photon_map.cc
# ${CMAKE_CURRENT_LIST_DIR}/hierarchical.cc
PARENT_SCOPE)

set(HEADERS
Expand All @@ -27,8 +27,8 @@ set(HEADERS
${CMAKE_CURRENT_LIST_DIR}/directlighting.h
# ${CMAKE_CURRENT_LIST_DIR}/bdpt.h
# ${CMAKE_CURRENT_LIST_DIR}/mlt.h
# ${CMAKE_CURRENT_LIST_DIR}/photon_map.h
# ${CMAKE_CURRENT_LIST_DIR}/ppmprob.h
${CMAKE_CURRENT_LIST_DIR}/sppm.h
${CMAKE_CURRENT_LIST_DIR}/hierarchical.h
# ${CMAKE_CURRENT_LIST_DIR}/photon_map.h
# ${CMAKE_CURRENT_LIST_DIR}/hierarchical.h
PARENT_SCOPE)
Loading

0 comments on commit 05b7653

Please sign in to comment.