00001 00002 /*************************************************************************** 00003 * Copyright (C) 1998-2008 by authors (see AUTHORS.txt ) * 00004 * * 00005 * This file is part of Lux Renderer. * 00006 * * 00007 * Lux Renderer is free software; you can redistribute it and/or modify * 00008 * it under the terms of the GNU General Public License as published by * 00009 * the Free Software Foundation; either version 3 of the License, or * 00010 * (at your option) any later version. * 00011 * * 00012 * Lux Renderer is distributed in the hope that it will be useful, * 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00015 * GNU General Public License for more details. * 00016 * * 00017 * You should have received a copy of the GNU General Public License * 00018 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00019 * * 00020 * This project is based on PBRT ; see http://www.pbrt.org * 00021 * Lux Renderer website : http://www.luxrender.org * 00022 ***************************************************************************/ 00023 00024 // Brute force ray intersection (de)accelerator. 00025 // Only useful for debugging as this is way slow on big scenes. 00026 00027 // bruteforce.cpp* 00028 #include "bruteforce.h" 00029 #include "paramset.h" 00030 00031 using namespace lux; 00032 00033 // BruteForceAccel Method Definitions 00034 BruteForceAccel::BruteForceAccel(const vector<Primitive* > &p) { 00035 for (u_int i = 0; i < p.size(); ++i) 00036 p[i]->FullyRefine(prims); 00037 // Compute bounds 00038 for (u_int i = 0; i < prims.size(); ++i) 00039 bounds = Union(bounds, prims[i]->WorldBound()); 00040 } 00041 00042 BruteForceAccel::~BruteForceAccel() { 00043 } 00044 00045 BBox BruteForceAccel::WorldBound() const { 00046 return bounds; 00047 } 00048 00049 bool BruteForceAccel::Intersect(const Ray &ray, 00050 Intersection *isect) const { 00051 bool hitSomething = false; 00052 00053 if (!bounds.IntersectP(ray)) 00054 return false; 00055 00056 for (u_int i = 0; i < prims.size(); ++i) { 00057 hitSomething |= prims[i]->Intersect(ray, isect); 00058 } 00059 00060 return hitSomething; 00061 } 00062 00063 bool BruteForceAccel::IntersectP(const Ray &ray) const { 00064 if (!bounds.IntersectP(ray)) 00065 return false; 00066 00067 for (u_int i = 0; i < prims.size(); ++i) { 00068 if(prims[i]->IntersectP(ray)) 00069 return true; 00070 } 00071 00072 return false; 00073 } 00074 00075 Primitive* BruteForceAccel::CreateAccelerator(const vector<Primitive* > &prims, 00076 const ParamSet &ps) { 00077 return new BruteForceAccel(prims); 00078 }