diff --git a/src/core/api.cpp b/src/core/api.cpp index 957290a5..ad899c48 100644 --- a/src/core/api.cpp +++ b/src/core/api.cpp @@ -59,6 +59,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" @@ -555,6 +556,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/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; diff --git a/src/integrators/depth.cpp b/src/integrators/depth.cpp new file mode 100644 index 00000000..af795677 --- /dev/null +++ b/src/integrators/depth.cpp @@ -0,0 +1,60 @@ + +/* + pbrt source code Copyright(c) 1998-2010 Matt Pharr and Greg Humphreys. + DepthSurfaceIntegrator Copyright(c) 2014 Silvano Galliani + + 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 . + + */ + + +#include "stdafx.h" +#include "integrators/depth.h" +#include "intersection.h" +#include "paramset.h" + +// DepthSurfaceIntegrator Method Definitions +DepthSurfaceIntegrator::DepthSurfaceIntegrator(float _factor) { + factor = _factor; +} + + +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) { + float factor = params.FindOneFloat("factor", 1.0f); + return new DepthSurfaceIntegrator(factor); +} + + diff --git a/src/integrators/depth.h b/src/integrators/depth.h new file mode 100644 index 00000000..86fa25e3 --- /dev/null +++ b/src/integrators/depth.h @@ -0,0 +1,55 @@ + +/* + pbrt source code Copyright(c) 1998-2010 Matt Pharr and Greg Humphreys. + DepthSurfaceIntegrator Copyright(c) 2014 Silvano Galliani + + 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(float _factor); + ~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 + float factor; +}; + + +DepthSurfaceIntegrator *CreateDepthSurfaceIntegrator(const ParamSet ¶ms); + +#endif // PBRT_INTEGRATORS_DIRECTLIGHTING_H 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')