Skip to content

Commit

Permalink
Eliminate usage of assimp's 2d vector.
Browse files Browse the repository at this point in the history
  • Loading branch information
boxdot committed Jun 12, 2017
1 parent 5136779 commit 5410516
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
6 changes: 4 additions & 2 deletions lib/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ using turner::Point3f;
using turner::Normal3f;
using turner::Bbox3f;
using turner::Ray;
using turner::Vector2f;
using turner::Vector2i;

static constexpr auto AXES3 = turner::AXES3;

Expand Down Expand Up @@ -114,7 +116,7 @@ class Camera : public aiCamera {
* The positioning of the camera is done in its parent's node
* transformation matrix.
*/
Vector3f raster2cam(const aiVector2D& p, float w, float h) const {
Vector3f raster2cam(const Vector2f& p, float w, float h) const {
aiVector3D v = trafo_ * aiVector3D(-delta_x_ * (1 - 2 * p.x / w),
delta_y_ * (1 - 2 * p.y / h), -1);
return {v.x, v.y, v.z};
Expand All @@ -123,7 +125,7 @@ class Camera : public aiCamera {
/**
* Convert 3d world coordinates to raster 2d coordinates.
*/
aiVector2t<int> cam2raster(const Point3f& p, float w, float h) const {
Vector2i cam2raster(const Point3f& p, float w, float h) const {
// move to camera position and convert to camera space
auto v = inverse_trafo_ * (aiVector3D(p.x, p.y, p.z) - mPosition);
// project on z = 1 in normal camera space
Expand Down
4 changes: 2 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ int main(int argc, char const* argv[]) {
dx = gen();
dy = gen();

auto cam_dir = cam.raster2cam(
aiVector2D(x + dx, y + dy), width, height);
auto cam_dir =
cam.raster2cam({x + dx, y + dy}, width, height);

Stats::instance().num_prim_rays += 1;
image(x, y) +=
Expand Down
45 changes: 23 additions & 22 deletions radiosity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,27 +235,28 @@ Image raycast(const KDTree& tree, const RadiosityConfig& conf,
Point3f cam_pos(cam.mPosition.x, cam.mPosition.y, cam.mPosition.z);

for (size_t y = 0; y < image.height(); ++y) {
tasks.emplace_back(pool.enqueue([&image, &cam, &tree, &radiosity, y,
&conf, &cam_pos]() {
// TODO: we need only one tree intersection per thread, not task
KDTreeIntersection tree_intersection(tree);
tasks.emplace_back(pool.enqueue(
[&image, &cam, &tree, &radiosity, y, &conf, &cam_pos]() {
// TODO: we need only one tree intersection per thread, not task
KDTreeIntersection tree_intersection(tree);

for (size_t x = 0; x < image.width(); ++x) {
auto cam_dir = cam.raster2cam(aiVector2D(x, y), image.width(),
image.height());
for (size_t x = 0; x < image.width(); ++x) {
auto cam_dir = cam.raster2cam(
{static_cast<float>(x), static_cast<float>(y)},
image.width(), image.height());

Stats::instance().num_prim_rays += 1;
image(x, y) += trace({cam_pos, cam_dir}, tree_intersection,
radiosity, conf);
Stats::instance().num_prim_rays += 1;
image(x, y) += trace({cam_pos, cam_dir}, tree_intersection,
radiosity, conf);

image(x, y) = exposure(image(x, y), conf.exposure);
image(x, y) = exposure(image(x, y), conf.exposure);

// gamma correction
if (conf.gamma_correction_enabled) {
image(x, y) = gamma(image(x, y), conf.inverse_gamma);
// gamma correction
if (conf.gamma_correction_enabled) {
image(x, y) = gamma(image(x, y), conf.inverse_gamma);
}
}
}
}));
}));
}

long completed = 0;
Expand Down Expand Up @@ -297,8 +298,9 @@ Image raycast(const KDTree& tree, const RadiosityConfig& conf,
KDTreeIntersection tree_intersection(tree);

for (size_t x = 0; x < image.width(); ++x) {
auto cam_dir = cam.raster2cam(aiVector2D(x, y), image.width(),
image.height());
auto cam_dir = cam.raster2cam(
{static_cast<float>(x), static_cast<float>(y)},
image.width(), image.height());

Stats::instance().num_prim_rays += 1;

Expand Down Expand Up @@ -369,7 +371,7 @@ Image render_feature_lines(const KDTree& tree, const RadiosityConfig& conf,
std::unordered_set<KDTreeIntersection::OptionalId> triangle_ids;

// Shoot center ray.
auto cam_dir = cam.raster2cam(aiVector2D(x + 0.5f, y + 0.5f),
auto cam_dir = cam.raster2cam({x + 0.5f, y + 0.5f},
image.width(), image.height());
auto center_id = tree_intersection.intersect(
{cam_pos, cam_dir}, dist_to_triangle, s, t);
Expand All @@ -378,9 +380,8 @@ Image render_feature_lines(const KDTree& tree, const RadiosityConfig& conf,
// Sample disc rays around center.
// TODO: Sample disc with Poisson or similar.
for (auto offset : offsets) {
cam_dir =
cam.raster2cam(aiVector2D(x + offset.x, y + offset.y),
image.width(), image.height());
cam_dir = cam.raster2cam({x + offset.x, y + offset.y},
image.width(), image.height());
auto id = tree_intersection.intersect(
{cam_pos, cam_dir}, dist_to_triangle, s, t);
triangle_ids.insert(id);
Expand Down

0 comments on commit 5410516

Please sign in to comment.