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
8dea5c44
Commit
8dea5c44
authored
3 years ago
by
Yoel
Browse files
Options
Downloads
Patches
Plain Diff
Image cleanup, no more public constructor, readImage is friend, raytrace is friend and takes scene
parent
1f6f9ab7
No related branches found
Branches containing commit
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
+6
-20
6 additions, 20 deletions
RayTracer/sampling/Image.cpp
RayTracer/sampling/Image.h
+9
-6
9 additions, 6 deletions
RayTracer/sampling/Image.h
with
15 additions
and
26 deletions
RayTracer/sampling/Image.cpp
+
6
−
20
View file @
8dea5c44
...
...
@@ -16,28 +16,18 @@ Image::Image(int width, int 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
(
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
++
)
{
for
(
int
x
=
0
;
x
<
width
;
x
++
)
{
for
(
int
y
=
0
;
y
<
height
;
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
)
{
...
...
@@ -68,14 +58,12 @@ Vec3 Image::color(float x, float y) const {
Vec3
v
=
vec
[
width
*
yy
+
xx
];
return
v
;
}
Image
raytrace
(
size_t
threadcount
,
const
cam
::
CamObs
&
cam
,
const
std
::
shared_ptr
<
Sampler
>&
sampler
,
size_t
n
)
{
Image
result
(
cam
.
width
,
cam
.
height
);
Image
raytrace
(
size_t
threadcount
,
const
std
::
shared_ptr
<
Scene
>&
scene
,
size_t
n
)
{
Image
result
(
scene
->
cam
.
width
,
scene
->
cam
.
height
);
result
.
setPixels
(
threadcount
,
std
::
make_shared
<
StratifiedSampler
>
(
StratifiedSampler
(
sampler
,
n
))
// sampler
);
StratifiedSampler
(
scene
,
n
)));
result
.
gammaCorrect
(
2.2
);
return
result
;
}
...
...
@@ -144,10 +132,8 @@ void writeBmp(const char* filename, Image img) {
char
bgr
[
3
]
=
{
blue
,
green
,
red
};
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
char
c0
=
(
bgr
[
i
]
&
0x00FF
);
// char c8 = ((bgr[i] & (unsigned int)0xFF00) >> 8);
ofile
.
write
(
&
c0
,
sizeof
(
c0
));
// ofile.write (&c8, sizeof (c8));
}
}
// If needed add extra bytes after each row
...
...
This diff is collapsed.
Click to expand it.
RayTracer/sampling/Image.h
+
9
−
6
View file @
8dea5c44
...
...
@@ -4,12 +4,11 @@
#include
"../camera/CamObs.h"
#include
"Sampler.h"
#include
"Scene.h"
namespace
util
{
class
Image
:
public
Sampler
{
public:
Image
(
int
width
,
int
height
);
void
setPixel
(
int
x
,
int
y
,
Vec3
color
);
void
setPixels
(
size_t
threadcount
,
std
::
shared_ptr
<
Sampler
>
sampler
);
...
...
@@ -18,20 +17,24 @@ class Image : public Sampler {
Vec3
color
(
float
x
,
float
y
)
const
override
;
const
int
width
;
const
int
height
;
const
int
width
,
height
;
bool
halfed
;
void
gammaCorrect
(
float
gamma
);
friend
Image
raytrace
(
size_t
threadcount
,
const
std
::
shared_ptr
<
Scene
>&
scene
,
size_t
n
);
friend
Image
readImage
(
const
char
*
filename
);
protected:
void
setPixelsTask
(
int
x
,
int
y
,
std
::
shared_ptr
<
Sampler
>
sampler
);
private:
std
::
vector
<
Vec3
>
vec
;
Image
(
int
width
,
int
height
);
};
Image
raytrace
(
size_t
threadcount
,
const
cam
::
CamObs
&
cam
,
const
std
::
shared_ptr
<
Sampler
>&
sampler
,
size_t
n
);
Image
raytrace
(
size_t
threadcount
,
const
std
::
shared_ptr
<
Scene
>&
scene
,
size_t
n
);
void
writeBmp
(
const
char
*
filename
,
Image
img
);
Image
readImage
(
const
char
*
filename
);
...
...
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