diff options
Diffstat (limited to 'source/blender/freestyle/intern/system')
25 files changed, 1627 insertions, 0 deletions
diff --git a/source/blender/freestyle/intern/system/BaseIterator.h b/source/blender/freestyle/intern/system/BaseIterator.h new file mode 100755 index 00000000000..45cc19df4fe --- /dev/null +++ b/source/blender/freestyle/intern/system/BaseIterator.h @@ -0,0 +1,90 @@ +// +// Filename : BaseIterator.h +// Author(s) : Stephane Grabli +// Purpose : Classes defining the basic "Iterator" design pattern +// Date of creation : 18/03/2003 +// +/////////////////////////////////////////////////////////////////////////////// + + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef BASEITERATOR_H +# define BASEITERATOR_H + +# include <iterator> + +// use for iterators defintions +template <class Element> +class Nonconst_traits; + +template <class Element> +class Const_traits { +public: + typedef Element value_type; + typedef const Element& reference; + typedef const Element* pointer; + typedef ptrdiff_t difference_type; + typedef Nonconst_traits<Element> Non_const_traits; +}; + +template <class Element> +class Nonconst_traits { +public: + typedef Element value_type; + typedef Element& reference; + typedef Element* pointer; + typedef ptrdiff_t difference_type; + typedef Nonconst_traits<Element> Non_const_traits; +}; + +class InputIteratorTag_Traits { +public: + typedef std::input_iterator_tag iterator_category; +}; + +class BidirectionalIteratorTag_Traits { +public: + typedef std::bidirectional_iterator_tag iterator_category; +}; + +template<class Traits, class IteratorTagTraits> +class IteratorBase +{ +public: + + virtual ~IteratorBase() {} + + virtual bool begin() const = 0; + virtual bool end() const = 0; + + typedef typename IteratorTagTraits::iterator_category iterator_category; + typedef typename Traits::value_type value_type; + typedef typename Traits::difference_type difference_type; + typedef typename Traits::pointer pointer; + typedef typename Traits::reference reference; + +protected: + + IteratorBase() {} +}; + +#endif // BASEITERATOR_H diff --git a/source/blender/freestyle/intern/system/BaseObject.cpp b/source/blender/freestyle/intern/system/BaseObject.cpp new file mode 100755 index 00000000000..0cf1c917195 --- /dev/null +++ b/source/blender/freestyle/intern/system/BaseObject.cpp @@ -0,0 +1 @@ +#include "BaseObject.h" diff --git a/source/blender/freestyle/intern/system/BaseObject.h b/source/blender/freestyle/intern/system/BaseObject.h new file mode 100755 index 00000000000..a8515f98385 --- /dev/null +++ b/source/blender/freestyle/intern/system/BaseObject.h @@ -0,0 +1,73 @@ +// +// Filename : BaseObject.h +// Author(s) : Stephane Grabli +// Purpose : Base Class for most shared objects (Node, Rep). +// Defines the addRef, release system. +// Inspired by COM IUnknown system. +// Date of creation : 06/02/2002 +// +/////////////////////////////////////////////////////////////////////////////// + + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef BASEOBJECT_H +# define BASEOBJECT_H + +#include "FreestyleConfig.h" + +class LIB_SYSTEM_EXPORT BaseObject +{ +public: + + inline BaseObject() { + _ref_counter = 0; + } + + virtual ~BaseObject() {} + + /*! At least makes a release on this. + * The BaseObject::destroy method must be + * explicitely called at the end of any + * overloaded destroy + */ + virtual int destroy() { + return release(); + } + + /*! Increments the reference counter */ + inline int addRef() { + return ++_ref_counter; + } + + /*! Decrements the reference counter */ + inline int release() { + if (_ref_counter) + _ref_counter--; + return _ref_counter; + } + +private: + + unsigned _ref_counter; +}; + +#endif // BASEOBJECT_H diff --git a/source/blender/freestyle/intern/system/Cast.h b/source/blender/freestyle/intern/system/Cast.h new file mode 100755 index 00000000000..15af767443e --- /dev/null +++ b/source/blender/freestyle/intern/system/Cast.h @@ -0,0 +1,44 @@ +// +// Filename : Cast.h +// Author(s) : Emmanuel Turquin +// Purpose : Cast function +// Date of creation : 01/07/2003 +// +/////////////////////////////////////////////////////////////////////////////// + + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef CAST_HPP +# define CAST_HPP + +namespace Cast { + + template <class T, class U> + U* cast(T* in) { + if (!in) + return NULL; + return dynamic_cast<U*>(in); + } + +} // end of namespace Cast + +#endif // CAST_HPP diff --git a/source/blender/freestyle/intern/system/Exception.cpp b/source/blender/freestyle/intern/system/Exception.cpp new file mode 100755 index 00000000000..d1d12d18297 --- /dev/null +++ b/source/blender/freestyle/intern/system/Exception.cpp @@ -0,0 +1,24 @@ + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#include "Exception.h" + +Exception::exception_type Exception::_exception = Exception::NO_EXCEPTION; diff --git a/source/blender/freestyle/intern/system/Exception.h b/source/blender/freestyle/intern/system/Exception.h new file mode 100755 index 00000000000..378de6b558f --- /dev/null +++ b/source/blender/freestyle/intern/system/Exception.h @@ -0,0 +1,64 @@ +// +// Filename : Exception.h +// Author(s) : Stephane Grabli +// Purpose : Singleton to manage exceptions +// Date of creation : 10/01/2003 +// +/////////////////////////////////////////////////////////////////////////////// + + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef EXCEPTION_H +# define EXCEPTION_H + +# include "FreestyleConfig.h" + +class LIB_SYSTEM_EXPORT Exception +{ +public: + + typedef enum { + NO_EXCEPTION, + UNDEFINED + } exception_type; + + static int getException() { + exception_type e = _exception; + _exception = NO_EXCEPTION; + return e; + } + + static int raiseException(exception_type exception = UNDEFINED) { + _exception = exception; + return _exception; + } + + static void reset() { + _exception = NO_EXCEPTION; + } + +private: + + static exception_type _exception; +}; + +#endif // EXCEPTION_H diff --git a/source/blender/freestyle/intern/system/FreestyleConfig.h b/source/blender/freestyle/intern/system/FreestyleConfig.h new file mode 100755 index 00000000000..f06b9928d1d --- /dev/null +++ b/source/blender/freestyle/intern/system/FreestyleConfig.h @@ -0,0 +1,90 @@ +// +// Filename : Config.h +// Author(s) : Emmanuel Turquin +// Purpose : Configuration definitions +// Date of creation : 25/02/2003 +// +/////////////////////////////////////////////////////////////////////////////// + + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + + +#ifndef CONFIG_H +# define CONFIG_H + +# include <string> +# include "BLI_math.h" + +using namespace std; + +namespace Config { + + // Directory separators +# ifdef WIN32 + static const string DIR_SEP("\\"); + static const string PATH_SEP(";"); +# else + static const string DIR_SEP("/"); + static const string PATH_SEP(":"); +# endif // WIN32 + + // DLL import/export macros for Win32 + +# ifndef LIB_SYSTEM_EXPORT +# define LIB_SYSTEM_EXPORT +# endif // LIB_SYSTEM_EXPORT + +# ifndef LIB_IMAGE_EXPORT +# define LIB_IMAGE_EXPORT +# endif // LIB_IMAGE_EXPORT + +# ifndef LIB_GEOMETRY_EXPORT +# define LIB_GEOMETRY_EXPORT +# endif // LIB_GEOMETRY_EXPORT + +# ifndef LIB_SCENE_GRAPH_EXPORT +# define LIB_SCENE_GRAPH_EXPORT +# endif // LIB_SCENE_GRAPH_EXPORT + +# ifndef LIB_WINGED_EDGE_EXPORT +# define LIB_WINGED_EDGE_EXPORT +# endif // LIB_WINGED_EDGE_EXPORT + +# ifndef LIB_VIEW_MAP_EXPORT +# define LIB_VIEW_MAP_EXPORT +# endif // LIB_VIEW_MAP_EXPORT + +# ifndef LIB_STROKE_EXPORT +# define LIB_STROKE_EXPORT +# endif // LIB_STROKE_EXPORT + +# ifndef LIB_RENDERING_EXPORT +# define LIB_RENDERING_EXPORT +# endif // LIB_RENDERING_EXPORT + +# ifndef LIB_WRAPPER_EXPORT +# define LIB_WRAPPER_EXPORT +# endif // LIB_WRAPPER_EXPORT + +} // end of namespace Config + +#endif // CONFIG_H diff --git a/source/blender/freestyle/intern/system/Id.h b/source/blender/freestyle/intern/system/Id.h new file mode 100755 index 00000000000..1f2206ed337 --- /dev/null +++ b/source/blender/freestyle/intern/system/Id.h @@ -0,0 +1,126 @@ +// +// Filename : Id.h +// Author(s) : Emmanuel Turquin +// Purpose : Identification system +// Date of creation : 01/07/2003 +// +/////////////////////////////////////////////////////////////////////////////// + + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef ID_H +# define ID_H + +/*! Class used to tag any object by an id . + * It is made of two unsigned integers. + */ +class Id +{ +public: + + typedef unsigned id_type; + + /*! Default constructor */ + Id() { + _first = 0; + _second = 0; + } + + /*! Builds an Id from an integer. + * The second number is set to 0. + */ + Id(id_type id) { + _first = id; + _second = 0; + } + + /*! Builds the Id from the two numbers */ + Id(id_type ifirst, id_type isecond) { + _first = ifirst; + _second = isecond; + } + + /*! Copy constructor */ + Id(const Id& iBrother) { + _first = iBrother._first; + _second = iBrother._second; + } + + /*! Operator= */ + Id& operator=(const Id& iBrother) { + _first = iBrother._first; + _second = iBrother._second; + return *this; + } + + /*! Returns the first Id number */ + id_type getFirst() const { + return _first; + } + + /*! Returns the second Id number */ + id_type getSecond() const { + return _second; + } + + /*! Sets the first number constituing the Id */ + void setFirst(id_type first) { + _first = first; + } + + /*! Sets the second number constituing the Id */ + void setSecond(id_type second) { + _second = second; + } + + /*! Operator== */ + bool operator==(const Id& id) const { + return ((_first == id._first) && (_second == id._second)); + } + + /*! Operator!= */ + bool operator!=(const Id& id) const { + return !((*this)==id); + } + + /*! Operator< */ + bool operator<(const Id& id) const { + if (_first < id._first) + return true; + if (_first == id._first && _second < id._second) + return true; + return false; +} + +private: + + id_type _first; + id_type _second; +}; + +// stream operator +inline std::ostream& operator<<(std::ostream& s, const Id& id) { + s << "[" << id.getFirst() << ", " << id.getSecond() << "]"; + return s; +} + +# endif // ID_H diff --git a/source/blender/freestyle/intern/system/Interpreter.h b/source/blender/freestyle/intern/system/Interpreter.h new file mode 100755 index 00000000000..75aaa2ccd18 --- /dev/null +++ b/source/blender/freestyle/intern/system/Interpreter.h @@ -0,0 +1,56 @@ +// +// Filename : Interpreter.h +// Author(s) : Emmanuel Turquin +// Purpose : Base Class of all script interpreters +// Date of creation : 17/04/2003 +// +/////////////////////////////////////////////////////////////////////////////// + + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef INTERPRETER_H +# define INTERPRETER_H + +# include <string> + +using namespace std; + +class LIB_SYSTEM_EXPORT Interpreter +{ + public: + + Interpreter() { _language = "Unknown"; } + + virtual ~Interpreter() {}; //soc + + virtual int interpretFile(const string& filename) = 0; + + virtual string getLanguage() const { return _language; } + + virtual void reset() = 0; + + protected: + + string _language; +}; + +#endif // INTERPRETER_H diff --git a/source/blender/freestyle/intern/system/Iterator.cpp b/source/blender/freestyle/intern/system/Iterator.cpp new file mode 100644 index 00000000000..67acc893589 --- /dev/null +++ b/source/blender/freestyle/intern/system/Iterator.cpp @@ -0,0 +1 @@ +#include "Iterator.h" diff --git a/source/blender/freestyle/intern/system/Iterator.h b/source/blender/freestyle/intern/system/Iterator.h new file mode 100644 index 00000000000..1801c1e3b2f --- /dev/null +++ b/source/blender/freestyle/intern/system/Iterator.h @@ -0,0 +1,41 @@ +#ifndef ITERATOR_H +#define ITERATOR_H + +#include <iostream> +#include <string> +using namespace std; + + +class Iterator +{ +public: + + virtual ~Iterator() {} + + virtual string getExactTypeName() const { + return "Iterator"; + } + + virtual int increment() { + cerr << "Warning: increment() not implemented" << endl; + return 0; + } + + virtual int decrement() { + cerr << "Warning: decrement() not implemented" << endl; + return 0; + } + + virtual bool isBegin() const { + cerr << "Warning: isBegin() not implemented" << endl; + return false; + } + + virtual bool isEnd() const { + cerr << "Warning: isEnd() not implemented" << endl; + return false; + } + +}; + +#endif // ITERATOR_H diff --git a/source/blender/freestyle/intern/system/PointerSequence.h b/source/blender/freestyle/intern/system/PointerSequence.h new file mode 100644 index 00000000000..72c6aa458fd --- /dev/null +++ b/source/blender/freestyle/intern/system/PointerSequence.h @@ -0,0 +1,97 @@ +// +// Filename : PointerSequence.h +// Author(s) : Alexander Beels +// Purpose : Class to define a cell grid surrounding +// the projected image of a scene +// Date of creation : 22/11/2010 +// +/////////////////////////////////////////////////////////////////////////////// + + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +// +// Simple RAII wrappers for std:: sequential containers +// +/////////////////////////////////////////////////////////////////////////////// + +// +// PointerSequence +// +// Produces a wrapped version of a sequence type (std::vector, std::deque, std::list) +// that will take ownership of pointers tht it stores. Those pointers will be deleted +// in its destructor. +// +// Because the contained pointers are wholly owned by the sequence, you cannot make a +// copy of the sequence. Making a copy would result in a double free. +// +// This is a no-frills class that provides no additional facilities. The user is +// responsible for managing any pointers that are removed from the list, and for making +// sure that any pointers contained in the class are not deleted elsewhere. Because +// this class does no reference counting, the user must also make sure that any pointer +// appears only once in the sequence. +// +// If more sophisticated facilities are needed, use tr1::shared_ptr or boost::shared_ptr. +// This class is only intended to allow one to eke by in projects where tr1 or boost are +// not available. +// +// Usage: The template takes two parameters, the standard container, and the class held +// in the container. This is a limitation of C++ templates, where T::iterator is not a +// type when T is a template parameter. If anyone knows a way around this +// limitation, then the second parameter can be eliminated. +// +// Example: +// PointerSequence<vector<Widget*>, Widget*> v; +// v.push_back(new Widget); +// cout << v[0] << endl; // operator[] is provided by std::vector, not by PointerSequence +// v.destroy(); // Deletes all pointers in sequence and sets them to NULL. +// +// The idiom for removing a pointer from a sequence is: +// Widget* w = v[3]; +// v.erase(v.begin() + 3); // or v[3] = 0; +// The user is now responsible for disposing of w properly. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef POINTERSEQUENCE_H +# define POINTERSEQUENCE_H + +#include <algorithm> + +template <typename C, typename T> +class PointerSequence : public C { + PointerSequence (PointerSequence& other); + PointerSequence& operator= (PointerSequence& other); + static void destroyer (T t) { + delete t; + } +public: + PointerSequence () {}; + ~PointerSequence () { + destroy(); + } + void destroy () { + for_each (this->begin(), this->end(), destroyer); + } +}; + +#endif // POINTERSEQUENCE_H + diff --git a/source/blender/freestyle/intern/system/Precision.h b/source/blender/freestyle/intern/system/Precision.h new file mode 100755 index 00000000000..24327a280df --- /dev/null +++ b/source/blender/freestyle/intern/system/Precision.h @@ -0,0 +1,39 @@ +// +// Filename : Precision.h +// Author(s) : Stephane Grabli +// Purpose : Define the float precision used in the program +// Date of creation : 30/07/2002 +// +/////////////////////////////////////////////////////////////////////////////// + + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef PRECISION_H +# define PRECISION_H + +typedef double real; + +# ifndef SWIG +static const real M_EPSILON = 0.00000001; +# endif // SWIG + +#endif // PRECISION_H diff --git a/source/blender/freestyle/intern/system/ProgressBar.h b/source/blender/freestyle/intern/system/ProgressBar.h new file mode 100755 index 00000000000..5b61f936c90 --- /dev/null +++ b/source/blender/freestyle/intern/system/ProgressBar.h @@ -0,0 +1,85 @@ +// +// Filename : ProgressBar.h +// Author(s) : Stephane Grabli +// Purpose : Class to encapsulate a progress bar +// Date of creation : 27/08/2002 +// +/////////////////////////////////////////////////////////////////////////////// + + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef PROGRESSBAR_H +# define PROGRESSBAR_H + +# include <string> + +using namespace std; + +class ProgressBar +{ +public: + + inline ProgressBar() { + _numtotalsteps = 0; + _progress = 0; + } + + virtual ~ProgressBar() {} + + virtual void reset() { + _numtotalsteps = 0; + _progress = 0; + } + + virtual void setTotalSteps(unsigned n) { + _numtotalsteps = n; + } + + virtual void setProgress(unsigned i) { + _progress = i; + } + + virtual void setLabelText(const string& s) { + _label = s; + } + + /*! accessors */ + inline unsigned int getTotalSteps() const { + return _numtotalsteps; + } + + inline unsigned int getProgress() const { + return _progress; + } + + inline string getLabelText() const { + return _label; + } + +protected: + + unsigned _numtotalsteps; + unsigned _progress; + string _label; +}; + +#endif // PROGRESSBAR_H diff --git a/source/blender/freestyle/intern/system/PseudoNoise.cpp b/source/blender/freestyle/intern/system/PseudoNoise.cpp new file mode 100755 index 00000000000..7a5fee2da4f --- /dev/null +++ b/source/blender/freestyle/intern/system/PseudoNoise.cpp @@ -0,0 +1,109 @@ + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#include <math.h> +#include "RandGen.h" +#include "PseudoNoise.h" + +static const unsigned NB_VALUE_NOISE = 512; + +real *PseudoNoise::_values; + +PseudoNoise::PseudoNoise () +{ +} + +void +PseudoNoise::init (long seed) +{ + _values = new real[NB_VALUE_NOISE]; + RandGen::srand48(seed); + for (unsigned int i=0; i<NB_VALUE_NOISE; i++) + _values[i] = -1.0 + 2.0 * RandGen::drand48(); +} + +real +PseudoNoise::linearNoise (real x) +{ + real tmp; + int i = modf(x, &tmp) * NB_VALUE_NOISE; + real x1=_values[i], x2=_values[(i+1)%NB_VALUE_NOISE]; + real t = modf(x * NB_VALUE_NOISE, &tmp); + return x1*(1-t)+x2*t; +} + +real +LanczosWindowed(real t) +{ + if (fabs(t)>2) return 0; + if (fabs(t)<M_EPSILON) return 1.0; + return sin(M_PI*t)/(M_PI*t) * sin(M_PI*t/2.0)/(M_PI*t/2.0); +} + +real +PseudoNoise::smoothNoise (real x) +{ + real tmp; + int i = modf(x, &tmp) * NB_VALUE_NOISE; + int h = i - 1; + if (h < 0) + { + h = NB_VALUE_NOISE + h; + } + + real x1=_values[i], x2=_values[(i+1)%NB_VALUE_NOISE]; + real x0=_values[h], x3=_values[(i+2)%NB_VALUE_NOISE]; + + real t = modf(x * NB_VALUE_NOISE, &tmp); + real y0=LanczosWindowed(-1-t); + real y1=LanczosWindowed(-t); + real y2=LanczosWindowed(1-t); + real y3=LanczosWindowed(2-t); + // cerr<<"x0="<<x0<<" x1="<<x1<<" x2="<<x2<<" x3="<<x3<<endl; + // cerr<<"y0="<<y0<<" y1="<<y1<<" y2="<<y2<<" y3="<<y3<<" :"; + return (x0*y0+x1*y1+x2*y2+x3*y3)/(y0+y1+y2+y3); +} + +real +PseudoNoise::turbulenceSmooth (real x, unsigned nbOctave) +{ + real y=0; + real k=1.0; + for (unsigned i=0; i<nbOctave; i++) + { + y=y+k*smoothNoise(x*k); + k=k/2.0; + } + return y; +} + +real +PseudoNoise::turbulenceLinear (real x, unsigned nbOctave) +{ + real y=0; + real k=1.0; + for (unsigned i=0; i<nbOctave; i++) + { + y=y+k*linearNoise(x*k); + k=k/2.0; + } + return y; +} diff --git a/source/blender/freestyle/intern/system/PseudoNoise.h b/source/blender/freestyle/intern/system/PseudoNoise.h new file mode 100755 index 00000000000..43143865600 --- /dev/null +++ b/source/blender/freestyle/intern/system/PseudoNoise.h @@ -0,0 +1,58 @@ +// +// Filename : PseudoNoise.h +// Author(s) : Fredo Durand +// Purpose : Class to define a pseudo Perlin noise +// Date of creation : 16/06/2003 +// +/////////////////////////////////////////////////////////////////////////////// + + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef PSEUDONOISE_H +# define PSEUDONOISE_H + +# include "FreestyleConfig.h" +# include "Precision.h" + +class LIB_SYSTEM_EXPORT PseudoNoise +{ +public: + + PseudoNoise (); + + virtual ~PseudoNoise () {} + + real smoothNoise (real x); + real linearNoise (real x); + + real turbulenceSmooth (real x, unsigned nbOctave = 8); + real turbulenceLinear (real x, unsigned nbOctave = 8); + + static void init (long seed); + +protected: + + static real *_values; +}; + +#endif // PSEUDONOISE_H + diff --git a/source/blender/freestyle/intern/system/PythonInterpreter.cpp b/source/blender/freestyle/intern/system/PythonInterpreter.cpp new file mode 100755 index 00000000000..821bd32b40b --- /dev/null +++ b/source/blender/freestyle/intern/system/PythonInterpreter.cpp @@ -0,0 +1,25 @@ + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#include "PythonInterpreter.h" + +string PythonInterpreter::_path = ""; +bool PythonInterpreter::_initialized = false; diff --git a/source/blender/freestyle/intern/system/PythonInterpreter.h b/source/blender/freestyle/intern/system/PythonInterpreter.h new file mode 100755 index 00000000000..81e2f70c82e --- /dev/null +++ b/source/blender/freestyle/intern/system/PythonInterpreter.h @@ -0,0 +1,180 @@ +// +// Filename : PythonInterpreter.h +// Author(s) : Emmanuel Turquin +// Purpose : Python Interpreter +// Date of creation : 17/04/2003 +// +/////////////////////////////////////////////////////////////////////////////// + + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef PYTHON_INTERPRETER_H +# define PYTHON_INTERPRETER_H + +# include <Python.h> +# include <iostream> +# include "StringUtils.h" +# include "Interpreter.h" + +//soc +extern "C" { +#include "MEM_guardedalloc.h" +#include "DNA_text_types.h" +#include "BKE_main.h" +#include "BKE_context.h" +#include "BKE_global.h" +#include "BKE_report.h" +#include "BKE_text.h" +#include "BKE_library.h" +#include "BPY_extern.h" +} + +class LIB_SYSTEM_EXPORT PythonInterpreter : public Interpreter +{ + public: + + PythonInterpreter() { + _language = "Python"; + _context = 0; + //Py_Initialize(); + } + + virtual ~PythonInterpreter() { + //Py_Finalize(); + } + + void setContext(bContext *C) { + _context = C; + } + + int interpretFile(const string& filename) { + + initPath(); + + ReportList* reports = CTX_wm_reports(_context); + BKE_reports_clear(reports); + char *fn = const_cast<char*>(filename.c_str()); +#if 0 + int status = BPY_filepath_exec(_context, fn, reports); +#else + int status; + Text *text = BKE_text_load(fn, G.main->name); + if (text) { + status = BPY_text_exec(_context, text, reports, false); + BKE_text_unlink(G.main, text); + BKE_libblock_free(&G.main->text, text); + } else { + BKE_reportf(reports, RPT_ERROR, "Cannot open file: %s", fn); + status = 0; + } +#endif + + if (status != 1) { + cout << "\nError executing Python script from PythonInterpreter::interpretFile" << endl; + cout << "File: " << fn << endl; + cout << "Errors: " << endl; + BKE_reports_print(reports, RPT_ERROR); + return 1; + } + + // cleaning up + BKE_reports_clear(reports); + + return 0; + } + + int interpretText(struct Text *text, const string& name) { + + initPath(); + + ReportList* reports = CTX_wm_reports(_context); + + BKE_reports_clear(reports); + + if (!BPY_text_exec(_context, text, reports, false)) { + cout << "\nError executing Python script from PythonInterpreter::interpretText" << endl; + cout << "Name: " << name << endl; + cout << "Errors: " << endl; + BKE_reports_print(reports, RPT_ERROR); + return 1; + } + + BKE_reports_clear(reports); + + return 0; + } + + struct Options + { + static void setPythonPath(const string& path) { + _path = path; + } + + static string getPythonPath() { + return _path; + } + }; + + void reset() { + Py_Finalize(); + Py_Initialize(); + _initialized = false; + } + +private: + + bContext* _context; + + void initPath() { + if (_initialized) + return; + + vector<string> pathnames; + StringUtils::getPathName(_path, "", pathnames); + + struct Text *text = BKE_text_add("tmp_freestyle_initpath.txt"); + string cmd = "import sys\n"; + txt_insert_buf(text, const_cast<char*>(cmd.c_str())); + + for (vector<string>::const_iterator it = pathnames.begin(); it != pathnames.end();++it) { + if ( !it->empty() ) { + cout << "Adding Python path: " << *it << endl; + cmd = "sys.path.append(r\"" + *it + "\")\n"; + txt_insert_buf(text, const_cast<char*>(cmd.c_str())); + } + } + + BPY_text_exec(_context, text, NULL, false); + + // cleaning up + BKE_text_unlink(G.main, text); + BKE_libblock_free(&G.main->text, text); + + //PyRun_SimpleString("from Freestyle import *"); + _initialized = true; + } + + static bool _initialized; + static string _path; +}; + +#endif // PYTHON_INTERPRETER_H diff --git a/source/blender/freestyle/intern/system/RandGen.cpp b/source/blender/freestyle/intern/system/RandGen.cpp new file mode 100755 index 00000000000..a328cb7f583 --- /dev/null +++ b/source/blender/freestyle/intern/system/RandGen.cpp @@ -0,0 +1,86 @@ + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#include "RandGen.h" + +// +// Macro definitions +// +/////////////////////////////////////////////////////////////////////////////// + +#define N 16 +#define MASK ((unsigned)(1 << (N - 1)) + (1 << (N - 1)) - 1) +#define X0 0x330E +#define X1 0xABCD +#define X2 0x1234 +#define A0 0xE66D +#define A1 0xDEEC +#define A2 0x5 +#define C 0xB +#define HI_BIT (1L << (2 * N - 1)) + +#define LOW(x) ((unsigned)(x) & MASK) +#define HIGH(x) LOW((x) >> N) +#define MUL(x, y, z) { long l = (long)(x) * (long)(y); \ + (z)[0] = LOW(l); (z)[1] = HIGH(l); } +#define CARRY(x, y) ((unsigned long)((long)(x) + (long)(y)) > MASK) +#define ADDEQU(x, y, z) (z = CARRY(x, (y)), x = LOW(x + (y))) +#define SET3(x, x0, x1, x2) ((x)[0] = (x0), (x)[1] = (x1), (x)[2] = (x2)) +#define SETLOW(x, y, n) SET3(x, LOW((y)[n]), LOW((y)[(n)+1]), LOW((y)[(n)+2])) +#define SEED(x0, x1, x2) (SET3(x, x0, x1, x2), SET3(a, A0, A1, A2), c = C) +#define REST(v) for (i = 0; i < 3; i++) { xsubi[i] = x[i]; x[i] = temp[i]; } \ + return (v); +#define NEST(TYPE, f, F) TYPE f(register unsigned short *xsubi) { \ + register int i; register TYPE v; unsigned temp[3]; \ + for (i = 0; i < 3; i++) { temp[i] = x[i]; x[i] = LOW(xsubi[i]); } \ + v = F(); REST(v); } + +static unsigned x[3] = { X0, X1, X2 }, a[3] = { A0, A1, A2 }, c = C; + +// +// Methods implementation +// +/////////////////////////////////////////////////////////////////////////////// + +real RandGen::drand48() { + static real two16m = 1.0 / (1L << N); + next(); + return (two16m * (two16m * (two16m * x[0] + x[1]) + x[2])); +} + +void RandGen::srand48(long seedval) { + SEED(X0, LOW(seedval), HIGH(seedval)); +} + +void RandGen::next() { + unsigned p[2], q[2], r[2], carry0, carry1; + + MUL(a[0], x[0], p); + ADDEQU(p[0], c, carry0); + ADDEQU(p[1], carry0, carry1); + MUL(a[0], x[1], q); + ADDEQU(p[1], q[0], carry0); + MUL(a[1], x[0], r); + x[2] = LOW(carry0 + carry1 + CARRY(p[1], r[0]) + q[1] + r[1] + + a[0] * x[2] + a[1] * x[1] + a[2] * x[0]); + x[1] = LOW(p[1] + r[0]); + x[0] = LOW(p[0]); +} diff --git a/source/blender/freestyle/intern/system/RandGen.h b/source/blender/freestyle/intern/system/RandGen.h new file mode 100755 index 00000000000..409d3b79609 --- /dev/null +++ b/source/blender/freestyle/intern/system/RandGen.h @@ -0,0 +1,48 @@ +// +// Filename : RandGen.h +// Author(s) : Fredo Durand +// Purpose : Pseudo-random number generator +// Date of creation : 20/05/2003 +// +/////////////////////////////////////////////////////////////////////////////// + + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef RAND_GEN_H +# define RAND_GEN_H + +# include "FreestyleConfig.h" +# include "../system/Precision.h" + +class LIB_SYSTEM_EXPORT RandGen +{ +public: + + static real drand48(); + static void srand48(long value); + +private: + + static void next(); +}; + +#endif // RAND_GEN_H diff --git a/source/blender/freestyle/intern/system/StringUtils.cpp b/source/blender/freestyle/intern/system/StringUtils.cpp new file mode 100755 index 00000000000..58798daf42a --- /dev/null +++ b/source/blender/freestyle/intern/system/StringUtils.cpp @@ -0,0 +1,74 @@ + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +//soc #include <qfileinfo.h> +#include "FreestyleConfig.h" +#include "StringUtils.h" + +namespace StringUtils { + + void getPathName(const string& path, const string& base, vector<string>& pathnames) { + string dir; + string res; + char cleaned[FILE_MAX]; + unsigned size = path.size(); + + pathnames.push_back(base); + + for ( unsigned pos = 0, sep = path.find(Config::PATH_SEP, pos); + pos < size; + pos = sep + 1, sep = path.find(Config::PATH_SEP, pos)) { + + if (sep == (unsigned)string::npos) + sep = size; + + dir = path.substr(pos, sep - pos); + + BLI_strncpy(cleaned, dir.c_str(), FILE_MAX); + BLI_cleanup_file(NULL, cleaned); + res = toAscii( string(cleaned) ); + + if (!base.empty()) + res += Config::DIR_SEP + base; + + pathnames.push_back(res); + } + } + + string toAscii( const string &str ){ + stringstream out(""); + char s; + + for(unsigned int i=0; i < str.size() ; i++){ + s = ((char)(str.at(i) & 0x7F)); + out << s; + } + + return out.str(); + } + + const char* toAscii( const char *str ){ + return toAscii(string(str)).c_str(); + } + + + +} // end of namespace StringUtils diff --git a/source/blender/freestyle/intern/system/StringUtils.h b/source/blender/freestyle/intern/system/StringUtils.h new file mode 100755 index 00000000000..d44d3f62732 --- /dev/null +++ b/source/blender/freestyle/intern/system/StringUtils.h @@ -0,0 +1,62 @@ +// +// Filename : StringUtils.h +// Author(s) : Emmanuel Turquin +// Purpose : String utilities +// Date of creation : 20/05/2003 +// +/////////////////////////////////////////////////////////////////////////////// +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef STRING_UTILS_H +# define STRING_UTILS_H + +# include <cstring> +# include <vector> +# include <string> +# include <sstream> +# include <iostream> +# include "FreestyleConfig.h" + +//soc +extern "C" { +#include "BKE_utildefines.h" +#include "BLI_blenlib.h" +} + +using namespace std; + +namespace StringUtils { + + LIB_SYSTEM_EXPORT + void getPathName(const string& path, const string& base, vector<string>& pathnames); + string toAscii( const string &str ); + const char* toAscii( const char *str ); + + // STL related + struct ltstr{ + bool operator()(const char* s1, const char* s2) const{ + return strcmp(s1, s2) < 0; + } +}; + +} // end of namespace StringUtils + +#endif // STRING_UTILS_H diff --git a/source/blender/freestyle/intern/system/TimeStamp.cpp b/source/blender/freestyle/intern/system/TimeStamp.cpp new file mode 100755 index 00000000000..c66e1131611 --- /dev/null +++ b/source/blender/freestyle/intern/system/TimeStamp.cpp @@ -0,0 +1,25 @@ + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#include "TimeStamp.h" + +LIB_SYSTEM_EXPORT +TimeStamp* TimeStamp::_instance = 0; diff --git a/source/blender/freestyle/intern/system/TimeStamp.h b/source/blender/freestyle/intern/system/TimeStamp.h new file mode 100755 index 00000000000..568a7851e30 --- /dev/null +++ b/source/blender/freestyle/intern/system/TimeStamp.h @@ -0,0 +1,71 @@ +// +// Filename : TimeStamp.h +// Author(s) : Stephane Grabli +// Purpose : Class defining a singleton used as timestamp +// Date of creation : 12/12/2002 +// +/////////////////////////////////////////////////////////////////////////////// + + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef TIMESTAMP_H +# define TIMESTAMP_H + +# include "FreestyleConfig.h" + +class LIB_SYSTEM_EXPORT TimeStamp +{ + public: + + static inline TimeStamp* instance() { + if (_instance == 0) + _instance = new TimeStamp; + return _instance; + } + + inline unsigned getTimeStamp() const { + return _time_stamp; + } + + inline void increment() { + ++_time_stamp; + } + + inline void reset() { + _time_stamp = 1; + } + + protected: + + TimeStamp() { + _time_stamp = 1; + } + + TimeStamp(const TimeStamp&) {} + + private: + + static TimeStamp* _instance; + unsigned _time_stamp; +}; + +#endif // TIMESTAMP_H diff --git a/source/blender/freestyle/intern/system/TimeUtils.h b/source/blender/freestyle/intern/system/TimeUtils.h new file mode 100755 index 00000000000..99dd5b0a669 --- /dev/null +++ b/source/blender/freestyle/intern/system/TimeUtils.h @@ -0,0 +1,58 @@ +// +// Filename : TimeUtils.h +// Author(s) : Stephane Grabli +// Purpose : Class to measure ellapsed time +// Date of creation : 10/04/2002 +// +/////////////////////////////////////////////////////////////////////////////// + + +// +// Copyright (C) : Please refer to the COPYRIGHT file distributed +// with this source distribution. +// +// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef TIMEUTILS_H +# define TIMEUTILS_H + +#include <time.h> +#include "FreestyleConfig.h" + +class Chronometer +{ + public: + + inline Chronometer() {} + inline ~Chronometer() {} + + inline clock_t start() { + _start = clock(); + return _start; + } + + inline double stop() { + clock_t stop = clock(); + return (double)(stop - _start) / CLOCKS_PER_SEC ; + } + + private: + + clock_t _start; +}; + +#endif // TIMEUTILS_H |