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
696cd7bd
Commit
696cd7bd
authored
4 years ago
by
Yoel
Browse files
Options
Downloads
Patches
Plain Diff
Implemented multithreading in setPixels- and raytracing-method
parent
0f05d361
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
RayTracer/sampling/Image.cpp
+24
-7
24 additions, 7 deletions
RayTracer/sampling/Image.cpp
RayTracer/sampling/Image.h
+6
-3
6 additions, 3 deletions
RayTracer/sampling/Image.h
with
30 additions
and
10 deletions
RayTracer/sampling/Image.cpp
+
24
−
7
View file @
696cd7bd
...
...
@@ -10,15 +10,32 @@ Image::Image(int width, int height) : width(width), height(height) {
vec
.
insert
(
vec
.
end
(),
color
);
}
}
/*
void Image::setPixels(std::shared_ptr<Sampler> sampler) {
Threadpool tp(4);
for (int x = 0; x != width; x++) {
for (int y = 0; y != height; y++) {
vec[width * y + x] = sampler->color(x, y);
}
}
} */
void
Image
::
setPixel
(
int
x
,
int
y
,
Vec3
color
)
{
vec
[
width
*
y
+
x
]
=
color
;
}
void
Image
::
setPixels
(
std
::
shared_ptr
<
Sampler
>
sampler
)
{
void
Image
::
setPixels
(
size_t
threadcount
,
std
::
shared_ptr
<
Sampler
>
sampler
)
{
Threadpool
tp
(
threadcount
);
for
(
int
x
=
0
;
x
!=
width
;
x
++
)
{
for
(
int
y
=
0
;
y
!=
height
;
y
++
)
{
setPixel
(
x
,
y
,
sampler
->
color
(
x
,
y
));
tp
.
queueTask
(
std
::
bind
([
this
,
x
,
y
,
sampler
]()
{
this
->
setPixelsTask
(
x
,
y
,
sampler
);
}));
}
}
// std::cout << "Done queing" << std::endl;
}
void
Image
::
setPixelsTask
(
int
x
,
int
y
,
std
::
shared_ptr
<
Sampler
>
sampler
)
{
setPixel
(
x
,
y
,
sampler
->
color
(
x
,
y
));
}
Vec3
Image
::
operator
[](
const
std
::
array
<
int
,
2
>&
i
)
const
{
return
vec
[
width
*
i
[
1
]
+
i
[
0
]];
...
...
@@ -26,13 +43,13 @@ Vec3 Image::operator[](const std::array<int, 2>& i) const {
Vec3
&
Image
::
operator
[](
const
std
::
array
<
int
,
2
>&
i
)
{
return
vec
[
width
*
i
[
1
]
+
i
[
0
]];
}
Image
raytrace
(
const
cam
::
CamObs
&
cam
,
const
std
::
shared_ptr
<
Sampler
>&
sampler
,
size_t
n
)
{
Image
raytrace
(
size_t
threadcount
,
const
cam
::
CamObs
&
cam
,
const
std
::
shared_ptr
<
Sampler
>&
sampler
,
size_t
n
)
{
Image
result
(
cam
.
width
,
cam
.
height
);
result
.
setPixels
(
std
::
make_shared
<
StratifiedSampler
>
(
StratifiedSampler
(
sampler
,
n
))
// sampler
result
.
setPixels
(
threadcount
,
std
::
make_shared
<
StratifiedSampler
>
(
StratifiedSampler
(
sampler
,
n
))
// sampler
);
return
result
;
}
...
...
This diff is collapsed.
Click to expand it.
RayTracer/sampling/Image.h
+
6
−
3
View file @
696cd7bd
...
...
@@ -12,7 +12,7 @@ class Image {
Image
(
int
width
,
int
height
);
void
setPixel
(
int
x
,
int
y
,
Vec3
color
);
void
setPixels
(
std
::
shared_ptr
<
Sampler
>
sampler
);
void
setPixels
(
size_t
threadcount
,
std
::
shared_ptr
<
Sampler
>
sampler
);
Vec3
operator
[](
const
std
::
array
<
int
,
2
>&
i
)
const
;
// int x, int y
Vec3
&
operator
[](
const
std
::
array
<
int
,
2
>&
i
);
...
...
@@ -20,11 +20,14 @@ class Image {
const
int
width
;
const
int
height
;
protected:
void
setPixelsTask
(
int
x
,
int
y
,
std
::
shared_ptr
<
Sampler
>
sampler
);
private:
std
::
vector
<
Vec3
>
vec
;
};
Image
raytrace
(
const
cam
::
CamObs
&
cam
,
const
std
::
shared_ptr
<
Sampler
>&
sampler
,
size_t
n
);
Image
raytrace
(
size_t
threadcount
,
const
cam
::
CamObs
&
cam
,
const
std
::
shared_ptr
<
Sampler
>&
sampler
,
size_t
n
);
}
// namespace util
\ No newline at end of file
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