-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port classes and features from other projects
- Loading branch information
1 parent
edf9844
commit 8d1b806
Showing
29 changed files
with
1,504 additions
and
15 deletions.
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
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
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
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
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
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
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 @@ | ||
This is a placeholder file for an empty directory. |
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
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,37 @@ | ||
#include "educelab/core/io/ImageIO.hpp" | ||
#include "educelab/core/types/Image.hpp" | ||
#include "educelab/core/types/Vec.hpp" | ||
#include "educelab/core/utils/Iteration.hpp" | ||
|
||
using namespace educelab; | ||
|
||
auto main() -> int | ||
{ | ||
// Construct an image | ||
Image image(600, 800, 3, Depth::F32); | ||
|
||
// Fill image with a color gradient | ||
for (const auto [y, x] : range2D(image.height(), image.width())) { | ||
// Create RGB values | ||
auto r = float(x) / float(image.width() - 1); | ||
auto g = float(y) / float(image.height() - 1); | ||
auto b = 0.25F; | ||
|
||
// Assign value to the correct pixel. Like its equivalent in OpenCV, | ||
// Image.at gives you access to the raw image buffer memory, | ||
// reinterpreted as the type you request. Make sure you know the data | ||
// type and channels when you access a pixel! | ||
image.at<Vec3f>(y, x) = {r, g, b}; | ||
} | ||
|
||
// (Optional) Apply gamma correction | ||
image = Image::Gamma(image); | ||
|
||
// (Optional) Convert image to the correct format for output. write_image() | ||
// will automatically convert if the output format doesn't support the | ||
// given bit depth, but it's always good to control the conversion. | ||
image = image.convert(Depth::U8); | ||
|
||
// Write the image | ||
write_image("educelab_core_ImageExample.ppm", image); | ||
} |
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,55 @@ | ||
#include <cmath> | ||
#include <iostream> | ||
|
||
#include "educelab/core/types/Mat.hpp" | ||
#include "educelab/core/types/Vec.hpp" | ||
#include "educelab/core/utils/Iteration.hpp" | ||
#include "educelab/core/utils/Math.hpp" | ||
|
||
using namespace educelab; | ||
|
||
auto main() -> int | ||
{ | ||
// Type aliases | ||
using Matrix = Mat<4, 4, float>; | ||
using Point = Vec<float, 4>; | ||
|
||
// Input point | ||
Point p{0, 0, 0, 1}; | ||
std::cout << "Starting point: " << p << "\n\n"; | ||
|
||
// Translate 1 unit along x | ||
auto translate = Matrix::Eye(); | ||
translate(0, 3) = 1.f; | ||
p = translate * p; | ||
std::cout << "Translation matrix:\n" << translate << "\n"; | ||
std::cout << "After translation: " << p << "\n\n"; | ||
|
||
// Rotate around z | ||
auto theta = to_radians(90.F); | ||
auto rotate = Matrix::Eye(); | ||
rotate(0, 0) = std::cos(theta); | ||
rotate(0, 1) = -std::sin(theta); | ||
rotate(1, 0) = std::sin(theta); | ||
rotate(1, 1) = std::cos(theta); | ||
p = rotate * p; | ||
std::cout << "Rotation matrix:\n" << rotate << "\n"; | ||
std::cout << "After rotation: " << p << "\n\n"; | ||
|
||
// Scale by 10 | ||
auto scale = Matrix::Eye(); | ||
for (auto i : range(3)) { | ||
scale(i, i) = 10.F; | ||
} | ||
p = scale * p; | ||
std::cout << "Scale matrix:\n" << scale << "\n"; | ||
std::cout << "After scale: " << p << "\n\n"; | ||
|
||
// Restore original point and apply a single multiplication | ||
p = {0, 0, 0, 1}; | ||
auto transform = scale * rotate * translate; | ||
std::cout << "Restored starting point: " << p << "\n"; | ||
p = transform * p; | ||
std::cout << "Transform matrix:\n" << transform << "\n"; | ||
std::cout << "After transform: " << p << "\n"; | ||
} |
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
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,16 @@ | ||
#pragma once | ||
|
||
/** @file */ | ||
|
||
#include <filesystem> | ||
#include <fstream> | ||
|
||
#include "educelab/core/types/Image.hpp" | ||
|
||
namespace educelab | ||
{ | ||
|
||
/** @brief Write an Image to disk */ | ||
void write_image(const std::filesystem::path& path, const Image& image); | ||
|
||
} // namespace educelab |
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
Oops, something went wrong.