-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add writer for extended lens file format
- Loading branch information
Showing
7 changed files
with
137 additions
and
0 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
48 changes: 48 additions & 0 deletions
48
src/crayg/src/scene/camera/lensio/LensFileExtendedFormatWriter.cpp
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,48 @@ | ||
#include "LensFileExtendedFormatWriter.h" | ||
#include <tabulate/table.hpp> | ||
|
||
namespace crayg { | ||
void writeMetadata(std::string &content, const std::string &key, float value) { | ||
content += fmt::format("{}: {:.3}\n", key, value); | ||
} | ||
|
||
void writeMetadata(std::string &content, const std::string &key, const std::string &value) { | ||
if (value.empty()) { | ||
return; | ||
} | ||
content += fmt::format("{}: {}\n", key, value); | ||
} | ||
|
||
std::string formatFloat(float t) { | ||
return fmt::format("{:.3}", t); | ||
} | ||
|
||
std::string LensFileExtendedFormatWriter::writeFileContent(const CameraLens &cameraLens) { | ||
std::string content; | ||
|
||
content += "[Metadata]\n"; | ||
writeMetadata(content, "Name", cameraLens.metadata.name); | ||
writeMetadata(content, "Focal Length", cameraLens.metadata.focalLength * 10); | ||
writeMetadata(content, "Maximum F Number", cameraLens.metadata.maximumAperture); | ||
writeMetadata(content, "Squeeze", cameraLens.metadata.squeeze); | ||
writeMetadata(content, "Elements Count", cameraLens.metadata.elementCount); | ||
writeMetadata(content, "Patent", cameraLens.metadata.patent); | ||
writeMetadata(content, "Description", cameraLens.metadata.description); | ||
|
||
content += "[Elements]\n"; | ||
|
||
tabulate::Table styled_table; | ||
styled_table.format().border("").border_left("").corner("").padding_left(0); | ||
styled_table.add_row({"Radius", "Thickness", "IOR", "Housing-Radius", "Abbe-No", "Material", "Geometry"}); | ||
for (auto &element : cameraLens.elements) { | ||
styled_table.add_row({formatFloat(element.curvatureRadius * 10), formatFloat(element.thickness * 10), | ||
formatFloat(element.ior), formatFloat(element.apertureRadius * 10), | ||
formatFloat(element.abbeNumber), fmt::format("{}", element.material), | ||
fmt::format("{}", element.geometry)}); | ||
} | ||
|
||
content += styled_table.str(); | ||
|
||
return content; | ||
} | ||
} // crayg |
15 changes: 15 additions & 0 deletions
15
src/crayg/src/scene/camera/lensio/LensFileExtendedFormatWriter.h
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,15 @@ | ||
#ifndef CRAYG_SRC_CRAYG_SRC_SCENE_CAMERA_LENSIO_LENSFILEEXTENDEDFORMATWRITER_H_ | ||
#define CRAYG_SRC_CRAYG_SRC_SCENE_CAMERA_LENSIO_LENSFILEEXTENDEDFORMATWRITER_H_ | ||
|
||
#include "LensFileWriter.h" | ||
|
||
namespace crayg { | ||
|
||
class LensFileExtendedFormatWriter : public LensFileWriter { | ||
public: | ||
std::string writeFileContent(const CameraLens &cameraLens) override; | ||
}; | ||
|
||
} // crayg | ||
|
||
#endif // CRAYG_SRC_CRAYG_SRC_SCENE_CAMERA_LENSIO_LENSFILEEXTENDEDFORMATWRITER_H_ |
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,65 @@ | ||
#include "fixtures/CameraLensFixtures.h" | ||
#include "scene/camera/CameraLens.h" | ||
#include "scene/camera/lensio/LensFileExtendedFormatWriter.h" | ||
#include <catch2/catch.hpp> | ||
|
||
namespace crayg { | ||
|
||
TEST_CASE("LensFileExtendedFormatWriter::writeFileContent") { | ||
CameraLens canon70_200 = CameraLensFixtures::createCanon70_200mm(); | ||
canon70_200.metadata.patent = "US 123"; | ||
canon70_200.metadata.description = "Super nice lens"; | ||
|
||
SECTION("should ") { | ||
LensFileExtendedFormatWriter lensFileExtendedFormatWriter; | ||
|
||
const std::string content = lensFileExtendedFormatWriter.writeFileContent(canon70_200); | ||
|
||
REQUIRE(content == R"([Metadata] | ||
Name: Canon F/2.8, 70-200mm | ||
Focal Length: 72.1 | ||
Maximum F Number: 3.43 | ||
Squeeze: 1 | ||
Elements Count: 34 | ||
Patent: US 123 | ||
Description: Super nice lens | ||
[Elements] | ||
Radius Thickness IOR Housing-Radius Abbe-No Material Geometry | ||
312 2.8 1.75 38 0 UNKNOWN SPHERICAL | ||
119 0.42 1 38 0 UNKNOWN SPHERICAL | ||
128 8.68 1.5 38 0 UNKNOWN SPHERICAL | ||
-263 0.1 1 38 0 UNKNOWN SPHERICAL | ||
79.5 5.72 1.5 35 0 UNKNOWN SPHERICAL | ||
203 8.78 1 35 0 UNKNOWN SPHERICAL | ||
54.4 2.2 1.85 28 0 UNKNOWN SPHERICAL | ||
45.9 1.13 1 28 0 UNKNOWN SPHERICAL | ||
51.9 8.55 1.49 28 0 UNKNOWN SPHERICAL | ||
5.1e+03 1.64 1 28 0 UNKNOWN SPHERICAL | ||
-489 1.4 1.8 18 0 UNKNOWN SPHERICAL | ||
35.4 5.88 1 18 0 UNKNOWN SPHERICAL | ||
-78.1 1.4 1.49 18 0 UNKNOWN SPHERICAL | ||
38.1 4.97 1.85 18 0 UNKNOWN SPHERICAL | ||
417 2.65 1 18 0 UNKNOWN SPHERICAL | ||
-66.8 1.4 1.73 18 0 UNKNOWN SPHERICAL | ||
-3.36e+03 30.3 1 18 0 UNKNOWN SPHERICAL | ||
247 3.49 1.7 19 0 UNKNOWN SPHERICAL | ||
-99.9 0.15 1 19 0 UNKNOWN SPHERICAL | ||
-190 4.77 1.5 19 0 UNKNOWN SPHERICAL | ||
-40.6 1.45 1.83 19 0 UNKNOWN SPHERICAL | ||
-76.3 14.7 1 19 0 UNKNOWN SPHERICAL | ||
58.4 3.53 1.8 21 0 UNKNOWN SPHERICAL | ||
133 3 1 21 0 UNKNOWN SPHERICAL | ||
0 0.24 0 21 0 UNKNOWN SPHERICAL | ||
34.1 6.35 1.5 21 0 UNKNOWN SPHERICAL | ||
2.26e+03 3.72 1.62 21 0 UNKNOWN SPHERICAL | ||
31.5 28.2 1 21 0 UNKNOWN SPHERICAL | ||
133 5.9 1.52 21 0 UNKNOWN SPHERICAL | ||
-77.5 13.9 1 21 0 UNKNOWN SPHERICAL | ||
-39.5 1.8 1.83 21 0 UNKNOWN SPHERICAL | ||
-95.7 0.15 1 21 0 UNKNOWN SPHERICAL | ||
148 3.62 1.74 21 0 UNKNOWN SPHERICAL | ||
-206 54.5 1 21 0 UNKNOWN SPHERICAL )"); | ||
} | ||
} | ||
|
||
} |