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