Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Createdepth #34

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/core/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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());

Expand Down
2 changes: 0 additions & 2 deletions src/core/imageio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
Expand Down
60 changes: 60 additions & 0 deletions src/integrators/depth.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

*/


#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 &params) {
float factor = params.FindOneFloat("factor", 1.0f);
return new DepthSurfaceIntegrator(factor);
}


55 changes: 55 additions & 0 deletions src/integrators/depth.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

*/

#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 &params);

#endif // PBRT_INTEGRATORS_DIRECTLIGHTING_H
101 changes: 101 additions & 0 deletions src/tools/P2pbrt.py
Original file line number Diff line number Diff line change
@@ -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: {} <camera_matrix.txt> <xresolution> <yresolution>".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')