From f37ad9a7bd375f9fe58136950b9a3e9754611355 Mon Sep 17 00:00:00 2001 From: Silvano Galliani Date: Wed, 16 May 2012 16:25:51 +0200 Subject: [PATCH 1/7] Add new integrator "depth" with integer parameter "factor" that gives the distance of a surface to the camera multiplied by factor. --- src/core/api.cpp | 3 ++ src/integrators/depth.cpp | 60 +++++++++++++++++++++++++++++++++++++++ src/integrators/depth.h | 54 +++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 src/integrators/depth.cpp create mode 100644 src/integrators/depth.h diff --git a/src/core/api.cpp b/src/core/api.cpp index f68f26df..b0a1ad97 100644 --- a/src/core/api.cpp +++ b/src/core/api.cpp @@ -51,6 +51,7 @@ #include "integrators/diffuseprt.h" #include "integrators/dipolesubsurface.h" #include "integrators/directlighting.h" +#include "integrators/depth.h" #include "integrators/emission.h" #include "integrators/glossyprt.h" #include "integrators/igi.h" @@ -547,6 +548,8 @@ SurfaceIntegrator *MakeSurfaceIntegrator(const string &name, si = CreateDiffusePRTIntegratorSurfaceIntegrator(paramSet); else if (name == "glossyprt") si = CreateGlossyPRTIntegratorSurfaceIntegrator(paramSet); + else if (name == "depth") + si = CreateDepthSurfaceIntegrator(paramSet); else Warning("Surface integrator \"%s\" unknown.", name.c_str()); diff --git a/src/integrators/depth.cpp b/src/integrators/depth.cpp new file mode 100644 index 00000000..93d48130 --- /dev/null +++ b/src/integrators/depth.cpp @@ -0,0 +1,60 @@ + +/* + pbrt source code Copyright(c) 1998-2010 Matt Pharr and Greg Humphreys. + + This file is part of pbrt. + + pbrt is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. Note that the text contents of + the book "Physically Based Rendering" are *not* licensed under the + GNU GPL. + + pbrt is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + */ + + +// integrators/directlighting.cpp* +#include "stdafx.h" +#include "integrators/depth.h" +#include "intersection.h" +#include "paramset.h" + +// DepthSurfaceIntegrator Method Definitions +DepthSurfaceIntegrator::DepthSurfaceIntegrator(int fa) { + factor = fa; +} + + +DepthSurfaceIntegrator::~DepthSurfaceIntegrator() { +} + + +void DepthSurfaceIntegrator::RequestSamples(Sampler *sampler, + Sample *sample, const Scene *scene) { + +} + + +Spectrum DepthSurfaceIntegrator::Li(const Scene *scene, + const Renderer *renderer, const RayDifferential &ray, + const Intersection &isect, const Sample *sample, RNG &rng, MemoryArena &arena) const { + Spectrum L(factor*ray.maxt); + return L; +} + + +DepthSurfaceIntegrator *CreateDepthSurfaceIntegrator(const ParamSet ¶ms) { + int factor = params.FindOneInt("factor", 1); + return new DepthSurfaceIntegrator(factor); +} + + diff --git a/src/integrators/depth.h b/src/integrators/depth.h new file mode 100644 index 00000000..1f4050a2 --- /dev/null +++ b/src/integrators/depth.h @@ -0,0 +1,54 @@ + +/* + pbrt source code Copyright(c) 1998-2010 Matt Pharr and Greg Humphreys. + + This file is part of pbrt. + + pbrt is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. Note that the text contents of + the book "Physically Based Rendering" are *not* licensed under the + GNU GPL. + + pbrt is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + */ + +#if defined(_MSC_VER) +#pragma once +#endif + +#ifndef PBRT_INTEGRATORS_DEPTHSURFACE_H +#define PBRT_INTEGRATORS_DEPTHSURFACE_H + +// integrators/directlighting.h* +#include "pbrt.h" +#include "integrator.h" +#include "scene.h" + +// DepthSurfaceIntegrator Declarations +class DepthSurfaceIntegrator : public SurfaceIntegrator { +public: + // DepthSurfaceIntegrator Public Methods + DepthSurfaceIntegrator(int fa); + ~DepthSurfaceIntegrator(); + Spectrum Li(const Scene *scene, const Renderer *renderer, + const RayDifferential &ray, const Intersection &isect, + const Sample *sample, RNG &rng, MemoryArena &arena) const; + void RequestSamples(Sampler *sampler, Sample *sample, const Scene *scene); +private: + // DepthSurfaceIntegrator Private Data + int factor; +}; + + +DepthSurfaceIntegrator *CreateDepthSurfaceIntegrator(const ParamSet ¶ms); + +#endif // PBRT_INTEGRATORS_DIRECTLIGHTING_H From 307194b84eee7b8f044498a648b5bbe1c65c4a0c Mon Sep 17 00:00:00 2001 From: Silvano Galliani Date: Thu, 17 Jul 2014 09:42:19 +0200 Subject: [PATCH 2/7] Use float value for a factor in depth integrator --- src/integrators/depth.cpp | 6 +++--- src/integrators/depth.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/integrators/depth.cpp b/src/integrators/depth.cpp index 93d48130..2eae5200 100644 --- a/src/integrators/depth.cpp +++ b/src/integrators/depth.cpp @@ -29,8 +29,8 @@ #include "paramset.h" // DepthSurfaceIntegrator Method Definitions -DepthSurfaceIntegrator::DepthSurfaceIntegrator(int fa) { - factor = fa; +DepthSurfaceIntegrator::DepthSurfaceIntegrator(float _factor) { + factor = _factor; } @@ -53,7 +53,7 @@ Spectrum DepthSurfaceIntegrator::Li(const Scene *scene, DepthSurfaceIntegrator *CreateDepthSurfaceIntegrator(const ParamSet ¶ms) { - int factor = params.FindOneInt("factor", 1); + float factor = params.FindOneFloat("factor", 1.0f); return new DepthSurfaceIntegrator(factor); } diff --git a/src/integrators/depth.h b/src/integrators/depth.h index 1f4050a2..70543adf 100644 --- a/src/integrators/depth.h +++ b/src/integrators/depth.h @@ -45,7 +45,7 @@ class DepthSurfaceIntegrator : public SurfaceIntegrator { void RequestSamples(Sampler *sampler, Sample *sample, const Scene *scene); private: // DepthSurfaceIntegrator Private Data - int factor; + float factor; }; From 7bb8edb9115d6363a9bbdaab6459c7115edec517 Mon Sep 17 00:00:00 2001 From: Silvano Galliani Date: Thu, 17 Jul 2014 09:54:28 +0200 Subject: [PATCH 3/7] remove warning --- src/core/imageio.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/core/imageio.cpp b/src/core/imageio.cpp index f69b53ab..466a4b69 100644 --- a/src/core/imageio.cpp +++ b/src/core/imageio.cpp @@ -419,7 +419,6 @@ static RGBSpectrum *ReadImagePFM(const string &filename, int *xres, int *yres) { static bool WriteImagePFM(const string &filename, const float *rgb, int width, int height) { FILE* fp; - unsigned int nFloats; float scale; fp = fopen(filename.c_str(), "wb"); @@ -446,7 +445,6 @@ static bool WriteImagePFM(const string &filename, const float *rgb, // The raster is a sequence of pixels, packed one after another, with no // delimiters of any kind. They are grouped by row, with the pixels in each // row ordered left to right and the rows ordered bottom to top. - nFloats = 3 * width * height; for (int j=height-1; j>=0; j--) { if (fwrite(rgb + j*width*3, sizeof(float), width*3, fp) < (size_t)(width*3)) goto fail; From ba8700c5acece624ef6ae43adad9e3b25d03fd21 Mon Sep 17 00:00:00 2001 From: Silvano Galliani Date: Thu, 17 Jul 2014 09:54:46 +0200 Subject: [PATCH 4/7] Fix inconsistency in method declaration --- src/integrators/depth.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/integrators/depth.h b/src/integrators/depth.h index 70543adf..86fa25e3 100644 --- a/src/integrators/depth.h +++ b/src/integrators/depth.h @@ -1,6 +1,7 @@ /* pbrt source code Copyright(c) 1998-2010 Matt Pharr and Greg Humphreys. + DepthSurfaceIntegrator Copyright(c) 2014 Silvano Galliani This file is part of pbrt. @@ -37,7 +38,7 @@ class DepthSurfaceIntegrator : public SurfaceIntegrator { public: // DepthSurfaceIntegrator Public Methods - DepthSurfaceIntegrator(int fa); + DepthSurfaceIntegrator(float _factor); ~DepthSurfaceIntegrator(); Spectrum Li(const Scene *scene, const Renderer *renderer, const RayDifferential &ray, const Intersection &isect, From ce2f0ba9e39dad9558f865aba87a4ee8a7a65f9d Mon Sep 17 00:00:00 2001 From: Silvano Galliani Date: Thu, 17 Jul 2014 10:08:51 +0200 Subject: [PATCH 5/7] fix copyright info for DepthSurfaceIntegrator --- src/integrators/depth.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/integrators/depth.cpp b/src/integrators/depth.cpp index 2eae5200..b054b95c 100644 --- a/src/integrators/depth.cpp +++ b/src/integrators/depth.cpp @@ -1,6 +1,7 @@ /* pbrt source code Copyright(c) 1998-2010 Matt Pharr and Greg Humphreys. + DepthSurfaceIntegrator Copyright(c) 2014 Silvano Galliani This file is part of pbrt. From 53d5bc8ba3682ad3a6b3800a1fe61e4e4c9ae0e4 Mon Sep 17 00:00:00 2001 From: Silvano Galliani Date: Thu, 17 Jul 2014 10:15:39 +0200 Subject: [PATCH 6/7] Add script that compute the camera parameters for pbrt given a camera matrix P --- src/tools/P2pbrt.py | 101 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 src/tools/P2pbrt.py diff --git a/src/tools/P2pbrt.py b/src/tools/P2pbrt.py new file mode 100644 index 00000000..b8e1054e --- /dev/null +++ b/src/tools/P2pbrt.py @@ -0,0 +1,101 @@ +# Copyright Silvano Galliani 2014 +# Compute camera parameters for pbrt given a camera matrix P +# Requires numpy and scipy +# Example: python P2pbrt.py 0005.png.camera 3072 2048 +# Where camera contains P matrix as follows +# 2246.17 -2208.64 -62.134 24477.4 +# -316.161 -1091.08 2713.64 -8334.18 +# -0.269944 -0.961723 -0.0471142 -7.01217 + +import numpy as np +import math +from scipy.linalg import rq +from numpy.linalg import det +from numpy.linalg import norm +import sys + +if len(sys.argv) < 3: + print("Usage: {} ".format(sys.argv[0])) + sys.exit() + +# Read input matrix +P = np.genfromtxt('0005.png.P') + +# Save image resolution +nx = float(sys.argv[2]) +ny = float(sys.argv[3]) +##### + + +# Extract variable names to be consistent with Zisserman +M = P[:, :3] +p1 = P[:, 0] +p2 = P[:, 1] +p3 = P[:, 2] +p4 = P[:, 3] +m3 = M[2, :] + +# Extract K and R (Zisserman p163) +K, R = rq(M) + +# make diagonal of K positive +signK = np.sign(np.diag(K)) + +K = signK*K +R = signK*R + +# Algebraically extract camera centre (p163 Zisserman) + +C = np.array([det([p2, p3, p4]), + -det([p1, p3, p4]), + det([p1, p2, p4]), + -det([p1, p2, p3])]) +# Normalize by last component +C = C/C[3] +# Extract Euclidean vector +C = C[:3] + +# Extract principal axis vector as in Zisserman page 161 +v = det(M)*m3 +# Normalize +v = v/norm(v) +# Translate vector to start at camera centre +v = C+v + +# Extract focal lenght in x and y direction +fx = K[0, 0] +fy = K[1, 1] + +# Extract off centered optical axis +cx = K[0, 2] +cy = K[1, 2] + +# Compute aspect ratio and shifted screen size +aspect_ratio = nx/ny +screen_dimentionx = aspect_ratio * (fx/fy) +screen_dimentiony = 1.0 + +# Compute field of view +fov = 2.0*math.degrees(math.atan(ny/(2.0*fy))) + +print('Film "image" "string filename" ["out.pfm"] "integer xresolution" [{:.0f}] \ + "integer yresolution" [{:.0f}]'.format(nx, ny)) +print('SurfaceIntegrator "depth"') +print('LookAt') +print(' '.join(map(str, C))) +print(' '.join(map(str, v))) +print(' '.join(map(str, R[1, :]))) +print +print('Camera "perspective" "float fov" [{}]'.format(fov)) +print('"float screenwindow"') +print('[ {} {} {} {} ]'.format( + -(screen_dimentionx * cx) / (nx/2.0), + (screen_dimentionx * (nx-cx)) / (nx/2.0), + -(screen_dimentiony * cy) / (ny/2.0), + (screen_dimentiony * (ny-cy)) / (ny/2.0))) +print ('WorldBegin') +print ('AttributeBegin') +print ('#Include "fountain-resample.pbrt"') +print ('Include "fountain.pbrt"') +print ('AttributeEnd') +print ('WorldEnd') From aceb5ae13a2016162d3341977ee5a10338fa8311 Mon Sep 17 00:00:00 2001 From: Silvano Galliani Date: Thu, 17 Jul 2014 10:18:18 +0200 Subject: [PATCH 7/7] remove comment --- src/integrators/depth.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/integrators/depth.cpp b/src/integrators/depth.cpp index b054b95c..af795677 100644 --- a/src/integrators/depth.cpp +++ b/src/integrators/depth.cpp @@ -23,7 +23,6 @@ */ -// integrators/directlighting.cpp* #include "stdafx.h" #include "integrators/depth.h" #include "intersection.h"