-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aaburamadan patch 1 #9
Open
aaburamadan
wants to merge
2
commits into
Jacobs-University:master
Choose a base branch
from
aaburamadan:aaburamadan-patch-1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
|
||
#include <optional> | ||
#include <vector> | ||
#include <memory> | ||
#include <thread> | ||
#include <math.h> | ||
#include "opencv2/opencv.hpp" | ||
|
||
using namespace cv; | ||
|
||
#ifdef _WIN32 | ||
using byte = unsigned __int8; | ||
using word = unsigned __int16; | ||
using dword = unsigned __int32; | ||
using qword = unsigned __int64; | ||
#else | ||
using byte = uint8_t; | ||
using word = uint16_t; | ||
using dword = uint32_t; | ||
using qword = uint64_t; | ||
#endif | ||
|
||
static const double Pi = 3.1415926; ///< Pi number | ||
static const float Pif = 3.1415926f; ///< Pi number | ||
|
||
static const float Epsilon = 1E-4; | ||
|
||
#define RGB(r, g, b) Vec3f((b), (g), (r)) | ||
|
||
template <class T> T& lvalue_cast(T&& t) { return t; } |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,66 @@ | ||
// Perspective Camera class | ||
// Written by Sergey Kosov in 2005 for Rendering Competition | ||
#pragma once | ||
|
||
#include "ICamera.h" | ||
|
||
// ================================ Perspective Camera Class ================================ | ||
/** | ||
* @brief Perspective Camera class | ||
*/ | ||
class CCameraPerspective : public ICamera | ||
{ | ||
public: | ||
/** | ||
* @brief Constructor | ||
* @param resolution The image resolution in pixels | ||
* @param pos Camera origin (center of projection) | ||
* @param dir Normalized camera viewing direction | ||
* @param up Normalized camera up-vector | ||
* @param angle (Vertical) full opening angle of the viewing frustum in degrees | ||
*/ | ||
CCameraPerspective(Size resolution, const Vec3f& pos, const Vec3f& dir, const Vec3f& up, float angle) | ||
: ICamera(resolution) | ||
, m_pos(pos) | ||
, m_dir(dir) | ||
, m_up(up) | ||
, m_focus(1.0f / tanf(angle * Pif / 360)) // f = 1 / tg(angle / 2) | ||
{ | ||
m_zAxis = dir; | ||
m_xAxis = m_zAxis.cross(m_up); | ||
m_yAxis = m_zAxis.cross(m_xAxis); | ||
|
||
m_xAxis = normalize(m_xAxis); | ||
m_yAxis = normalize(m_yAxis); | ||
m_zAxis = normalize(m_zAxis); | ||
} | ||
virtual ~CCameraPerspective(void) = default; | ||
|
||
virtual void InitRay(Ray& ray, int x, int y) override | ||
{ | ||
float dx = 0.5f; // x-shift to the center of the pixel | ||
float dy = 0.5f; // y-shift to the center of the pixel | ||
|
||
// Screen space coordinates [-1, 1] | ||
float sscx = 2 * (x + dx) / getResolution().width - 1; | ||
float sscy = 2 * (y + dy) / getResolution().height - 1; | ||
|
||
ray.org = m_pos; | ||
ray.dir = normalize(getAspectRatio() * sscx * m_xAxis + sscy * m_yAxis + m_focus * m_zAxis); | ||
ray.t = std::numeric_limits<float>::infinity(); | ||
} | ||
|
||
|
||
private: | ||
// input values | ||
Vec3f m_pos; ///< Camera origin (center of projection) | ||
Vec3f m_dir; ///< Camera viewing direction | ||
Vec3f m_up; ///< Camera up-vector | ||
float m_focus; ///< The focal length | ||
|
||
// preprocessed values | ||
Vec3f m_xAxis; ///< Camera x-axis in WCS | ||
Vec3f m_yAxis; ///< Camera y-axis in WCS | ||
Vec3f m_zAxis; ///< Camera z-axis in WCS | ||
}; | ||
|
||
// Perspective Camera class | ||
// Written by Sergey Kosov in 2005 for Rendering Competition | ||
#pragma once | ||
#include "ICamera.h" | ||
// ================================ Perspective Camera Class ================================ | ||
/** | ||
* @brief Perspective Camera class | ||
*/ | ||
class CCameraPerspective : public ICamera | ||
{ | ||
public: | ||
/** | ||
* @brief Constructor | ||
* @param resolution The image resolution in pixels | ||
* @param pos Camera origin (center of projection) | ||
* @param dir Normalized camera viewing direction | ||
* @param up Normalized camera up-vector | ||
* @param angle (Vertical) full opening angle of the viewing frustum in degrees | ||
*/ | ||
CCameraPerspective(Size resolution, const Vec3f& pos, const Vec3f& dir, const Vec3f& up, float angle) | ||
: ICamera(resolution) | ||
, m_pos(pos) | ||
, m_dir(dir) | ||
, m_up(up) | ||
, m_focus(1.0f / tanf(angle * Pif / 360)) // f = 1 / tg(angle / 2) | ||
{ | ||
m_zAxis = dir; | ||
m_xAxis = m_zAxis.cross(m_up); | ||
m_yAxis = m_zAxis.cross(m_xAxis); | ||
m_xAxis = normalize(m_xAxis); | ||
m_yAxis = normalize(m_yAxis); | ||
m_zAxis = normalize(m_zAxis); | ||
} | ||
virtual ~CCameraPerspective(void) = default; | ||
virtual void InitRay(Ray& ray, int x, int y) override | ||
{ | ||
float dx = 0.5f; // x-shift to the center of the pixel | ||
float dy = 0.5f; // y-shift to the center of the pixel | ||
// Screen space coordinates [-1, 1] | ||
float sscx = 2 * (x + dx) / getResolution().width - 1; | ||
float sscy = 2 * (y + dy) / getResolution().height - 1; | ||
ray.org = m_pos; | ||
ray.dir = normalize(getAspectRatio() * sscx * m_xAxis + sscy * m_yAxis + m_focus * m_zAxis); | ||
ray.t = std::numeric_limits<float>::infinity(); | ||
} | ||
private: | ||
// input values | ||
Vec3f m_pos; ///< Camera origin (center of projection) | ||
Vec3f m_dir; ///< Camera viewing direction | ||
Vec3f m_up; ///< Camera up-vector | ||
float m_focus; ///< The focal length | ||
// preprocessed values | ||
Vec3f m_xAxis; ///< Camera x-axis in WCS | ||
Vec3f m_yAxis; ///< Camera y-axis in WCS | ||
Vec3f m_zAxis; ///< Camera z-axis in WCS | ||
}; | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,54 @@ | ||
// Camera Abstract Interface class | ||
// Written by Sergey Kosov in 2005 for Rendering Competition | ||
#pragma once | ||
|
||
#include "ray.h" | ||
|
||
// ================================ Camera Interface Class ================================ | ||
/** | ||
* @brief Basic camera abstract interface class | ||
*/ | ||
class ICamera | ||
{ | ||
public: | ||
/** | ||
* @brief Constructor | ||
* @param resolution The resolution of the camera in pixels | ||
*/ | ||
ICamera(Size resolution) | ||
: m_resolution(resolution) | ||
, m_aspectRatio(static_cast<float>(resolution.width) / resolution.height) | ||
{} | ||
ICamera(const ICamera&) = delete; | ||
virtual ~ICamera(void) = default; | ||
const ICamera& operator=(const ICamera&) = delete; | ||
|
||
/** | ||
* @brief Initializes a ray \b ray passing trough a screen pixel with coordinates \b x anf \b y | ||
* @details This function initializes the ray pointing from the camera origin to the pixel | ||
* on the camera screen defyned by the coodrinates \b (x,y). The pixel coordinates need to lie | ||
* in the ranges of camera resolution. | ||
* @param[out] ray Reference to the @ref Ray structure to be filled | ||
* @param[in] x The x-coordinate of the pixel lying on the camera screen | ||
* @param[in] y The y-coordinate of the pixel lying on the camera screen | ||
*/ | ||
virtual void InitRay(Ray& ray, int x, int y) = 0; | ||
|
||
/** | ||
* @brief Retuns the camera resolution in pixels | ||
* @return The camera resolution in pixels | ||
*/ | ||
Size getResolution(void) const { return m_resolution; } | ||
/** | ||
* @brief Returns the camera aspect ratio | ||
* @return The camera aspect ratio | ||
*/ | ||
float getAspectRatio(void) const { return m_aspectRatio; } | ||
|
||
|
||
private: | ||
const Size m_resolution; ///< Camera image resolution in pixels | ||
const float m_aspectRatio; ///< Camera image aspect ratio | ||
}; | ||
|
||
using ptr_camera_t = std::shared_ptr<ICamera>; | ||
// Camera Abstract Interface class | ||
// Written by Sergey Kosov in 2005 for Rendering Competition | ||
#pragma once | ||
#include "ray.h" | ||
// ================================ Camera Interface Class ================================ | ||
/** | ||
* @brief Basic camera abstract interface class | ||
*/ | ||
class ICamera | ||
{ | ||
public: | ||
/** | ||
* @brief Constructor | ||
* @param resolution The resolution of the camera in pixels | ||
*/ | ||
ICamera(Size resolution) | ||
: m_resolution(resolution) | ||
, m_aspectRatio(static_cast<float>(resolution.width) / resolution.height) | ||
{} | ||
ICamera(const ICamera&) = delete; | ||
virtual ~ICamera(void) = default; | ||
const ICamera& operator=(const ICamera&) = delete; | ||
/** | ||
* @brief Initializes a ray \b ray passing trough a screen pixel with coordinates \b x anf \b y | ||
* @details This function initializes the ray pointing from the camera origin to the pixel | ||
* on the camera screen defyned by the coodrinates \b (x,y). The pixel coordinates need to lie | ||
* in the ranges of camera resolution. | ||
* @param[out] ray Reference to the @ref Ray structure to be filled | ||
* @param[in] x The x-coordinate of the pixel lying on the camera screen | ||
* @param[in] y The y-coordinate of the pixel lying on the camera screen | ||
*/ | ||
virtual void InitRay(Ray& ray, int x, int y) = 0; | ||
/** | ||
* @brief Retuns the camera resolution in pixels | ||
* @return The camera resolution in pixels | ||
*/ | ||
Size getResolution(void) const { return m_resolution; } | ||
/** | ||
* @brief Returns the camera aspect ratio | ||
* @return The camera aspect ratio | ||
*/ | ||
float getAspectRatio(void) const { return m_aspectRatio; } | ||
private: | ||
const Size m_resolution; ///< Camera image resolution in pixels | ||
const float m_aspectRatio; ///< Camera image aspect ratio | ||
}; | ||
using ptr_camera_t = std::shared_ptr<ICamera>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
#pragma once | ||
|
||
#include "types.h" | ||
|
||
struct Ray; | ||
|
||
// ================================ Light Interface Class ================================ | ||
/** | ||
* @brief Base light source abstract interface class | ||
*/ | ||
class ILight | ||
{ | ||
public: | ||
/** | ||
* @brief Constructor | ||
* @param castShadow Flag indicating whether the light source casts shadows | ||
*/ | ||
ILight(bool castShadow) : m_shadow(castShadow) {} | ||
ILight(const ILight&) = delete; | ||
virtual ~ILight(void) = default; | ||
const ILight& operator=(const ILight&) = delete; | ||
|
||
/** | ||
* @brief Calculates the light intensity, at the point \b ray.org which is to be illuminated. | ||
* @details This function sets the \b ray.dir to be the the direction vector from the surface point \b ray.org to the light source. | ||
* @param[in, out] ray The ray from object point to the light source. The direction ray.dir is modified within the function | ||
* @return The intensity of light hitting the point \b ray.org | ||
*/ | ||
virtual std::optional<Vec3f> illuminate(Ray& ray) = 0; | ||
/** | ||
* @brief Flag indicating if the light source casts shadow or not | ||
* @retval true If the light source casts shadow | ||
* @retval false Otherwise | ||
*/ | ||
virtual bool shadow(void) const { return m_shadow; } | ||
|
||
|
||
private: | ||
bool m_shadow; | ||
}; | ||
|
||
using ptr_light_t = std::shared_ptr<ILight>; | ||
#pragma once | ||
#include "types.h" | ||
struct Ray; | ||
// ================================ Light Interface Class ================================ | ||
/** | ||
* @brief Base light source abstract interface class | ||
*/ | ||
class ILight | ||
{ | ||
public: | ||
/** | ||
* @brief Constructor | ||
* @param castShadow Flag indicating whether the light source casts shadows | ||
*/ | ||
ILight(bool castShadow) : m_shadow(castShadow) {} | ||
ILight(const ILight&) = delete; | ||
virtual ~ILight(void) = default; | ||
const ILight& operator=(const ILight&) = delete; | ||
/** | ||
* @brief Calculates the light intensity, at the point \b ray.org which is to be illuminated. | ||
* @details This function sets the \b ray.dir to be the the direction vector from the surface point \b ray.org to the light source. | ||
* @param[in, out] ray The ray from object point to the light source. The direction ray.dir is modified within the function | ||
* @return The intensity of light hitting the point \b ray.org | ||
*/ | ||
virtual std::optional<Vec3f> illuminate(Ray& ray) = 0; | ||
/** | ||
* @brief Flag indicating if the light source casts shadow or not | ||
* @retval true If the light source casts shadow | ||
* @retval false Otherwise | ||
*/ | ||
virtual bool shadow(void) const { return m_shadow; } | ||
private: | ||
bool m_shadow; | ||
}; | ||
using ptr_light_t = std::shared_ptr<ILight>; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file should not be submitted