Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CppRaytracer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Yoel
CppRaytracer
Commits
1f86f54a
Commit
1f86f54a
authored
4 years ago
by
Yoel
Browse files
Options
Downloads
Patches
Plain Diff
first commit
parent
a0287c6c
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
RayTracer/Main.cpp
+10
-1
10 additions, 1 deletion
RayTracer/Main.cpp
RayTracer/shape/TriangleMesh.cpp
+48
-44
48 additions, 44 deletions
RayTracer/shape/TriangleMesh.cpp
RayTracer/shape/TriangleMesh.h
+11
-3
11 additions, 3 deletions
RayTracer/shape/TriangleMesh.h
with
69 additions
and
48 deletions
RayTracer/Main.cpp
+
10
−
1
View file @
1f86f54a
...
@@ -36,7 +36,7 @@ using namespace shapes;
...
@@ -36,7 +36,7 @@ using namespace shapes;
using
namespace
std
;
using
namespace
std
;
int
main
()
{
int
main
()
{
if
(
tru
e
)
{
if
(
fals
e
)
{
cout
<<
"Start"
<<
endl
;
cout
<<
"Start"
<<
endl
;
// Image img = Image (100, 100);
// Image img = Image (100, 100);
...
@@ -112,5 +112,14 @@ int main() {
...
@@ -112,5 +112,14 @@ int main() {
// test::shape_test();
// test::shape_test();
test
::
axisalignedboundingbox_test
();
test
::
axisalignedboundingbox_test
();
}
else
{
}
else
{
std
::
ifstream
is
(
"Cube.obj"
);
TriangleMesh
mesh
(
is
,
nullptr
);
cout
<<
"triangles: "
<<
mesh
.
triangles
.
size
()
<<
endl
;
cout
<<
"leaves: "
<<
mesh
.
leaves
.
size
()
<<
endl
;
cout
<<
"hierarchy: "
<<
mesh
.
hierarchy
.
size
()
<<
endl
;
for
(
auto
hier
:
mesh
.
hierarchy
)
{
cout
<<
"{"
<<
hier
.
left
<<
" "
<<
hier
.
right
<<
" "
<<
hier
.
leaves_i
<<
" "
<<
hier
.
leaves_size
<<
"}"
<<
endl
;
}
}
}
};
};
This diff is collapsed.
Click to expand it.
RayTracer/shape/TriangleMesh.cpp
+
48
−
44
View file @
1f86f54a
...
@@ -11,29 +11,22 @@
...
@@ -11,29 +11,22 @@
namespace
shapes
{
namespace
shapes
{
// Only a test constructor. Can not be used for actual rendering
// Only a test constructor. Can not be used for actual rendering
TriangleMesh
::
TriangleMesh
(
std
::
vector
<
Triangle
>
triangles
)
TriangleMesh
::
TriangleMesh
(
std
::
vector
<
Triangle
>
triangles
)
:
triangles
(
triangles
),
:
triangles
(
triangles
),
material
(
nullptr
),
hierarchy
({})
{
material
(
nullptr
),
hierarchy
(
Group
(
util
::
identity
(),
false
))
{
}
}
TriangleMesh
::
TriangleMesh
(
std
::
istream
&
in
,
TriangleMesh
::
TriangleMesh
(
std
::
istream
&
in
,
const
std
::
shared_ptr
<
material
::
Material
>&
mat
)
const
std
::
shared_ptr
<
material
::
Material
>&
mat
)
:
material
(
mat
),
hierarchy
(
Group
(
util
::
identity
(),
false
)
)
{
:
material
(
mat
),
hierarchy
(
{}
)
{
triangles
=
util
::
loadObj
(
in
,
material
);
triangles
=
util
::
loadObj
(
in
,
material
);
hierarchy
.
setBounds
(
initBB
()
);
hierarchy
.
push_back
({
initBB
(),
-
1
,
-
1
,
-
1
,
-
1
}
);
std
::
vector
<
std
::
shared_ptr
<
Shap
e
>>
v
;
std
::
vector
<
std
::
shared_ptr
<
Triangl
e
>>
v
;
for
(
auto
tri
:
triangles
)
v
.
push_back
(
std
::
make_shared
<
Triangle
>
(
tri
));
for
(
auto
tri
:
triangles
)
v
.
push_back
(
std
::
make_shared
<
Triangle
>
(
tri
));
hierarch
(
hierarchy
,
v
,
100
);
hierarch
(
0
,
v
);
}
}
std
::
optional
<
cam
::
Hit
>
TriangleMesh
::
intersect
(
const
cam
::
Ray
&
r
)
const
{
std
::
optional
<
cam
::
Hit
>
TriangleMesh
::
intersect
(
const
cam
::
Ray
&
r
)
const
{
if
(
hierarchy
.
bounds
().
intersects
(
r
))
{
return
std
::
nullopt
;
// std::cout << "In Intersect" << std::endl;
auto
hit
=
hierarchy
.
intersect
(
r
);
return
hit
;
}
else
return
std
::
nullopt
;
}
}
util
::
AxisAlignedBoundingBox
TriangleMesh
::
bounds
()
const
{
util
::
AxisAlignedBoundingBox
TriangleMesh
::
bounds
()
const
{
return
hierarchy
.
bounds
()
;
return
hierarchy
[
0
].
bb
;
}
}
util
::
SurfacePoint
TriangleMesh
::
sampleLight
()
const
{
util
::
SurfacePoint
TriangleMesh
::
sampleLight
()
const
{
...
@@ -49,44 +42,55 @@ util::AxisAlignedBoundingBox TriangleMesh::initBB() {
...
@@ -49,44 +42,55 @@ util::AxisAlignedBoundingBox TriangleMesh::initBB() {
return
init
;
return
init
;
}
}
void
hierarch
(
Group
&
group
,
std
::
vector
<
std
::
shared_ptr
<
Shape
>>&
v
,
void
TriangleMesh
::
hierarch
(
size_t
i
,
size_t
depth
)
{
std
::
vector
<
std
::
shared_ptr
<
Triangle
>>
v
)
{
for
(
auto
tri_ptr
:
v
)
assert
(
group
.
bounds
().
contains
(
tri_ptr
->
bounds
()));
if
(
v
.
empty
())
return
;
auto
bb_pair
=
util
::
splitAABB
(
hierarchy
[
i
].
bb
);
if
(
depth
==
0
)
return
;
TriMeshNode
left
({
bb_pair
[
0
],
-
1
,
-
1
,
-
1
,
-
1
});
TriMeshNode
right
({
bb_pair
[
1
],
-
1
,
-
1
,
-
1
,
-
1
});
auto
bb_pair
=
util
::
splitAABB
(
group
.
bounds
());
std
::
vector
<
std
::
shared_ptr
<
Triangle
>>
left_non_leaves
;
Group
left
(
util
::
identity
(),
false
);
std
::
vector
<
std
::
shared_ptr
<
Triangle
>>
right_non_leaves
;
left
.
setBounds
(
bb_pair
[
0
]);
std
::
vector
<
std
::
shared_ptr
<
Triangle
>>
middle
;
Group
right
(
util
::
identity
(),
false
);
right
.
setBounds
(
bb_pair
[
1
]);
std
::
vector
<
std
::
shared_ptr
<
Shape
>>
left_non_leaves
;
std
::
vector
<
std
::
shared_ptr
<
Shape
>>
right_non_leaves
;
for
(
auto
tri_ptr
:
v
)
{
for
(
auto
tri_ptr
:
v
)
{
if
(
left
.
bounds
().
contains
(
tri_ptr
->
bounds
()))
{
if
(
left
.
bb
.
contains
(
tri_ptr
->
bounds
()))
{
left
.
add
(
tri_ptr
);
left_non_leaves
.
push_back
(
tri_ptr
);
left_non_leaves
.
push_back
(
tri_ptr
);
}
else
if
(
right
.
bounds
().
contains
(
tri_ptr
->
bounds
()))
{
}
else
if
(
right
.
bb
.
contains
(
tri_ptr
->
bounds
()))
{
right
.
add
(
tri_ptr
);
right_non_leaves
.
push_back
(
tri_ptr
);
right_non_leaves
.
push_back
(
tri_ptr
);
}
else
{
}
else
{
assert
(
left
.
b
ounds
()
.
partiallyContains
(
tri_ptr
->
bounds
()));
assert
(
left
.
b
b
.
partiallyContains
(
tri_ptr
->
bounds
()));
assert
(
right
.
b
ounds
()
.
partiallyContains
(
tri_ptr
->
bounds
()));
assert
(
right
.
b
b
.
partiallyContains
(
tri_ptr
->
bounds
()));
group
.
add
(
tri_ptr
);
middle
.
push_back
(
tri_ptr
);
}
}
}
}
v
.
clear
();
// std::cout << depth << " Left: " << left.shapeList.size() << std::endl;
std
::
cout
<<
depth
<<
" Left: "
<<
left
.
shapeList
.
size
()
<<
std
::
endl
;
// std::cout << depth << " Right: " << right.shapeList.size() << std::endl;
std
::
cout
<<
depth
<<
" Right: "
<<
right
.
shapeList
.
size
()
<<
std
::
endl
;
// std::cout << depth << " Middle: " << group.shapeList.size() << std::endl;
std
::
cout
<<
depth
<<
" Middle: "
<<
group
.
shapeList
.
size
()
<<
std
::
endl
;
size_t
hierarch_min_cluster_size
=
1
;
// Handle middle leaves
hierarchy
[
i
].
leaves_i
=
leaves
.
size
();
hierarchy
[
i
].
leaves_size
=
middle
.
size
();
for
(
auto
tri_ptr
:
middle
)
leaves
.
push_back
(
*
tri_ptr
);
// Handle left box
hierarchy
.
push_back
(
left
);
std
::
cout
<<
i
<<
std
::
endl
;
hierarchy
[
i
].
left
=
hierarchy
.
size
();
// Handle right box
hierarchy
.
push_back
(
right
);
hierarchy
[
i
].
right
=
hierarchy
.
size
();
// Handle recursion
hierarch
(
hierarchy
.
size
()
-
2
,
left_non_leaves
);
hierarch
(
hierarchy
.
size
()
-
1
,
right_non_leaves
);
/*size_t hierarch_min_cluster_size = 1;
if (left.shapeList.size() >= hierarch_min_cluster_size) {
if (left.shapeList.size() >= hierarch_min_cluster_size) {
group
.
add
(
left
);
group.add(left);
hierarch
(
left
,
left_non_leaves
,
depth
-
1
);
hierarch(left, left_non_leaves, depth - 1);
}
}
if (right.shapeList.size() >= hierarch_min_cluster_size) {
if (right.shapeList.size() >= hierarch_min_cluster_size) {
group
.
add
(
right
);
group.add(right);
hierarch
(
right
,
right_non_leaves
,
depth
-
1
);
hierarch(right, right_non_leaves, depth - 1);
}
}
*/
}
}
}
// namespace shapes
}
// namespace shapes
This diff is collapsed.
Click to expand it.
RayTracer/shape/TriangleMesh.h
+
11
−
3
View file @
1f86f54a
...
@@ -9,6 +9,14 @@
...
@@ -9,6 +9,14 @@
#include
"Triangle.h"
#include
"Triangle.h"
namespace
shapes
{
namespace
shapes
{
struct
TriMeshNode
{
util
::
AxisAlignedBoundingBox
bb
;
int_fast16_t
left
;
int_fast16_t
right
;
int_fast16_t
leaves_i
;
int_fast16_t
leaves_size
;
};
class
TriangleMesh
:
public
Light
,
public
Shape
{
class
TriangleMesh
:
public
Light
,
public
Shape
{
public:
public:
TriangleMesh
(
std
::
vector
<
Triangle
>
triangles
);
TriangleMesh
(
std
::
vector
<
Triangle
>
triangles
);
...
@@ -24,11 +32,11 @@ class TriangleMesh : public Light, public Shape {
...
@@ -24,11 +32,11 @@ class TriangleMesh : public Light, public Shape {
public:
public:
std
::
shared_ptr
<
material
::
Material
>
material
;
std
::
shared_ptr
<
material
::
Material
>
material
;
std
::
vector
<
Triangle
>
triangles
;
std
::
vector
<
Triangle
>
triangles
;
Group
hierarchy
;
std
::
vector
<
Triangle
>
leaves
;
std
::
vector
<
TriMeshNode
>
hierarchy
;
private:
private:
util
::
AxisAlignedBoundingBox
initBB
();
util
::
AxisAlignedBoundingBox
initBB
();
void
hierarch
(
size_t
i
,
const
std
::
vector
<
std
::
shared_ptr
<
Triangle
>>
v
);
};
};
void
hierarch
(
Group
&
group
,
std
::
vector
<
std
::
shared_ptr
<
Shape
>>&
v
,
size_t
depth
=
5
);
}
// namespace shapes
}
// namespace shapes
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment