Skip to content
This repository was archived by the owner on Jul 14, 2022. It is now read-only.

Commit 10ee261

Browse files
committed
fix gl_depth on init
1 parent d52c785 commit 10ee261

File tree

5 files changed

+59
-2
lines changed

5 files changed

+59
-2
lines changed

src/apcomp/compositor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ Compositor::Composite()
192192
{
193193
CompositeVisOrder();
194194
}
195-
// Make this a param to avoid the copy?
195+
// TODO Make this a param/ref to avoid the copy?
196196
return m_images[0];
197197
}
198198

src/apcomp/image.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Image::Init(const float *color_buffer,
6262
m_bounds.m_max_x = width;
6363
m_bounds.m_max_y = height;
6464
m_orig_bounds = m_bounds;
65+
m_gl_depth = gl_depth;
6566
const int size = width * height;
6667
m_pixels.resize(size * 4);
6768
m_depths.resize(size);
@@ -100,6 +101,7 @@ Image::Init(const unsigned char *color_buffer,
100101
m_bounds.m_max_x = width;
101102
m_bounds.m_max_y = height;
102103
m_orig_bounds = m_bounds;
104+
m_gl_depth = gl_depth;
103105

104106
const int size = width * height;
105107
m_pixels.resize(size * 4);
@@ -173,6 +175,7 @@ Image::SubsetFrom(const Image &image,
173175
m_bounds = sub_region;
174176
m_orig_rank = image.m_orig_rank;
175177
m_composite_order = image.m_composite_order;
178+
m_gl_depth = image.m_gl_depth;
176179

177180
assert(sub_region.m_min_x >= image.m_bounds.m_min_x);
178181
assert(sub_region.m_min_y >= image.m_bounds.m_min_y);
@@ -213,6 +216,7 @@ void
213216
Image::SubsetTo(Image &image) const
214217
{
215218
image.m_composite_order = m_composite_order;
219+
image.m_gl_depth = m_gl_depth;
216220
assert(m_bounds.m_min_x >= image.m_bounds.m_min_x);
217221
assert(m_bounds.m_min_y >= image.m_bounds.m_min_y);
218222
assert(m_bounds.m_max_x <= image.m_bounds.m_max_x);
@@ -253,6 +257,7 @@ Image::Swap(Image &other)
253257

254258
m_orig_bounds = other.m_orig_bounds;
255259
m_bounds = other.m_bounds;
260+
m_gl_depth = other.m_gl_depth;
256261

257262
other.m_orig_bounds = orig;
258263
other.m_bounds = bounds;
@@ -322,4 +327,50 @@ void Image::Save(std::string name)
322327
encoder.Save(name + ".png");
323328
}
324329

330+
void Image::SaveDepth(std::string name)
331+
{
332+
int width = m_bounds.m_max_x - m_bounds.m_min_x + 1;
333+
int height = m_bounds.m_max_y - m_bounds.m_min_y + 1;
334+
335+
if(width * height <= 0)
336+
{
337+
throw Error("Image: cannot save empty image");
338+
}
339+
340+
float inf = std::numeric_limits<float>::infinity();
341+
float min_v = inf;
342+
float max_v = -inf;
343+
for(int i = 0; i < width * height;++i)
344+
{
345+
float d = m_depths[i];
346+
if(d != inf)
347+
{
348+
min_v = std::min(min_v, d);
349+
max_v = std::max(max_v, d);
350+
}
351+
}
352+
353+
const float len = max_v - min_v;
354+
std::vector<float> ndepths(width*height*4);
355+
356+
for(int i = 0; i < width * height;++i)
357+
{
358+
const float depth = m_depths[i];
359+
float value = 0.f;
360+
const int offset = i * 4;
361+
if(depth != inf)
362+
{
363+
value = (depth - min_v) / len;
364+
}
365+
ndepths[offset + 0] = value;
366+
ndepths[offset + 1] = value;
367+
ndepths[offset + 2] = value;
368+
ndepths[offset + 3] = 1.f;
369+
}
370+
371+
PNGEncoder encoder;
372+
encoder.Encode(&ndepths[0], width, height);
373+
encoder.Save(name + ".png");
374+
}
375+
325376
} // namespace apcomp

src/apcomp/image.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct APCOMP_API Image
8282
std::string ToString() const;
8383

8484
void Save(std::string name);
85+
void SaveDepth(std::string name);
8586
};
8687

8788
} //namespace apcomp

src/apcomp/internal/ImageCompositor.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class APCOMP_API ImageCompositor
5454
front.m_depths[i] = depth;
5555
}
5656
}
57-
// Only composite values the GL depths range (0,1)
57+
5858
void ZBufferComposite(apcomp::Image &front, const apcomp::Image &image)
5959
{
6060
assert(front.m_depths.size() == front.m_pixels.size() / 4);
@@ -67,6 +67,7 @@ void ZBufferComposite(apcomp::Image &front, const apcomp::Image &image)
6767
bool gl_depth = front.m_gl_depth;
6868
if(gl_depth)
6969
{
70+
// Only composite values the GL depths range (0,1)
7071
#ifdef apcomp_USE_OPENMP
7172
#pragma omp parallel for
7273
#endif

src/apcomp/internal/RadixKCompositor.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,10 @@ void
177177
RadixKCompositor::CompositeSurface(apcompdiy::mpi::communicator &diy_comm,
178178
Image &image)
179179
{
180+
std::cout<<"["<<diy_comm.rank()<<"] "<<image.m_gl_depth<<"\n";
181+
std::stringstream ss;
182+
ss<<"apcomp_depth_"<<diy_comm.rank();
183+
image.SaveDepth(ss.str());
180184
CompositeImpl(diy_comm, image);
181185
}
182186

0 commit comments

Comments
 (0)