blender/intern/cycles/util/util_vector.h
Ton Roosendaal da376e0237 Cycles render engine, initial commit. This is the engine itself, blender modifications and build instructions will follow later.
Cycles uses code from some great open source projects, many thanks them:

* BVH building and traversal code from NVidia's "Understanding the Efficiency of Ray Traversal on GPUs":
http://code.google.com/p/understanding-the-efficiency-of-ray-traversal-on-gpus/
* Open Shading Language for a large part of the shading system:
http://code.google.com/p/openshadinglanguage/
* Blender for procedural textures and a few other nodes.
* Approximate Catmull Clark subdivision from NVidia Mesh tools:
http://code.google.com/p/nvidia-mesh-tools/
* Sobol direction vectors from:
http://web.maths.unsw.edu.au/~fkuo/sobol/
* Film response functions from:
http://www.cs.columbia.edu/CAVE/software/softlib/dorf.php
2011-04-27 11:58:34 +00:00

138 lines
2.4 KiB
C++

/*
* Copyright 2011, Blender Foundation.
*
* This program 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.
*
* This program 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, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __UTIL_VECTOR_H__
#define __UTIL_VECTOR_H__
/* Vector */
#include <vector>
CCL_NAMESPACE_BEGIN
using std::vector;
/* Array
*
* Simplified version of vector, serving two purposes:
* - somewhat faster in that it does not clear memory on resize/alloc,
* this was actually showing up in profiles quite significantly
* - if this is used, we are not tempted to use inefficient operations */
template<typename T>
class array
{
public:
array()
{
data = NULL;
datasize = 0;
}
array(size_t newsize)
{
if(newsize == 0) {
data = NULL;
datasize = 0;
}
else {
data = new T[newsize];
datasize = newsize;
}
}
array(const array& from)
{
*this = from;
}
array& operator=(const array& from)
{
if(from.datasize == 0) {
data = NULL;
datasize = 0;
}
else {
data = new T[from.datasize];
memcpy(data, from.data, from.datasize*sizeof(T));
datasize = from.datasize;
}
return *this;
}
array& operator=(const vector<T>& from)
{
datasize = from.size();
data = NULL;
if(datasize > 0) {
data = new T[datasize];
memcpy(data, &from[0], datasize*sizeof(T));
}
return *this;
}
~array()
{
delete [] data;
}
void resize(size_t newsize)
{
if(newsize == 0) {
clear();
}
else {
T *newdata = new T[newsize];
memcpy(newdata, data, ((datasize < newsize)? datasize: newsize)*sizeof(T));
delete [] data;
data = newdata;
datasize = newsize;
}
}
void clear()
{
delete [] data;
data = NULL;
datasize = 0;
}
size_t size() const
{
return datasize;
}
T& operator[](size_t i) const
{
return data[i];
}
protected:
T *data;
size_t datasize;
};
CCL_NAMESPACE_END
#endif /* __UTIL_VECTOR_H__ */