Add Chromium-only Blender WebEngine parity work
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Classes defining the basic "Iterator" design pattern
|
||||
*/
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
// use for iterators definitions
|
||||
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;
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle: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;
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Nonconst_traits")
|
||||
};
|
||||
|
||||
class InputIteratorTag_Traits {
|
||||
public:
|
||||
typedef std::input_iterator_tag iterator_category;
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:InputIteratorTag_Traits")
|
||||
};
|
||||
|
||||
class BidirectionalIteratorTag_Traits {
|
||||
public:
|
||||
typedef std::bidirectional_iterator_tag iterator_category;
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BidirectionalIteratorTag_Traits")
|
||||
};
|
||||
|
||||
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() {}
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:IteratorBase")
|
||||
};
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,11 @@
|
||||
/* SPDX-FileCopyrightText: 2009-2022 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Base Class for most shared objects (Node, Rep). Defines the addRef, release system.
|
||||
* \brief Inspired by COM IUnknown system.
|
||||
*/
|
||||
|
||||
#include "BaseObject.h"
|
||||
@@ -0,0 +1,57 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Base Class for most shared objects (Node, Rep). Defines the addRef, release system.
|
||||
* \brief Inspired by COM IUnknown system.
|
||||
*/
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_sys_types.h"
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
class BaseObject {
|
||||
public:
|
||||
inline BaseObject()
|
||||
{
|
||||
_ref_counter = 0;
|
||||
}
|
||||
|
||||
virtual ~BaseObject() {}
|
||||
|
||||
/** At least makes a release on this.
|
||||
* The BaseObject::destroy method must be explicitly 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:
|
||||
uint _ref_counter;
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:BaseObject")
|
||||
};
|
||||
|
||||
} /* namespace Freestyle */
|
||||
24
blender-5.2.0/source/blender/freestyle/intern/system/Cast.h
Normal file
24
blender-5.2.0/source/blender/freestyle/intern/system/Cast.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Cast function
|
||||
*/
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
namespace Cast {
|
||||
template<class T, class U> U *cast(T *in)
|
||||
{
|
||||
if (!in) {
|
||||
return nullptr;
|
||||
}
|
||||
return dynamic_cast<U *>(in);
|
||||
}
|
||||
} // end of namespace Cast
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,16 @@
|
||||
/* SPDX-FileCopyrightText: 2012-2022 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Singleton to manage exceptions
|
||||
*/
|
||||
|
||||
#include "Exception.h"
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
Exception::exception_type Exception::_exception = Exception::NO_EXCEPTION;
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,47 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Singleton to manage exceptions
|
||||
*/
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
class Exception {
|
||||
public:
|
||||
enum exception_type {
|
||||
NO_EXCEPTION,
|
||||
UNDEFINED,
|
||||
};
|
||||
|
||||
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;
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Exception")
|
||||
};
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,39 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Configuration definitions
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
/* Part of `BLI_sys_types.h`, declare here as BLI is not in the include path. */
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned short ushort;
|
||||
typedef unsigned long ulong;
|
||||
typedef unsigned char uchar;
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
namespace Config {
|
||||
|
||||
/* Directory separators. */
|
||||
|
||||
/* TODO: Use Blender's stuff for such things! */
|
||||
#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
|
||||
|
||||
} // end of namespace Config
|
||||
|
||||
} /* namespace Freestyle */
|
||||
123
blender-5.2.0/source/blender/freestyle/intern/system/Id.h
Normal file
123
blender-5.2.0/source/blender/freestyle/intern/system/Id.h
Normal file
@@ -0,0 +1,123 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Identification system
|
||||
*/
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
/** Class used to tag any object by an id.
|
||||
* It is made of two unsigned-integers.
|
||||
*/
|
||||
class Id {
|
||||
public:
|
||||
typedef uint 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 constituting the Id */
|
||||
void setFirst(id_type first)
|
||||
{
|
||||
_first = first;
|
||||
}
|
||||
|
||||
/** Sets the second number constituting 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;
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Id")
|
||||
};
|
||||
|
||||
// stream operator
|
||||
inline std::ostream &operator<<(std::ostream &s, const Id &id)
|
||||
{
|
||||
s << "[" << id.getFirst() << ", " << id.getSecond() << "]";
|
||||
return s;
|
||||
}
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,44 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Base Class of all script interpreters
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
class Interpreter {
|
||||
public:
|
||||
Interpreter()
|
||||
{
|
||||
_language = "Unknown";
|
||||
}
|
||||
|
||||
virtual ~Interpreter() {}
|
||||
|
||||
virtual int interpretFile(const string &filename) = 0;
|
||||
|
||||
virtual string getLanguage() const
|
||||
{
|
||||
return _language;
|
||||
}
|
||||
|
||||
virtual void reset() = 0;
|
||||
|
||||
protected:
|
||||
string _language;
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Interpreter")
|
||||
};
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,9 @@
|
||||
/* SPDX-FileCopyrightText: 2008-2022 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
*/
|
||||
|
||||
#include "Iterator.h"
|
||||
@@ -0,0 +1,56 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Iterator")
|
||||
};
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,80 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief 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 that 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:
|
||||
* \code{.cc}
|
||||
* 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 nullptr.
|
||||
* \endcode
|
||||
*
|
||||
* The idiom for removing a pointer from a sequence is:
|
||||
* \code{.cc}
|
||||
* Widget* w = v[3];
|
||||
* v.erase(v.begin() + 3); // or v[3] = 0;
|
||||
* \endcode
|
||||
* The user is now responsible for disposing of `w` properly.
|
||||
*/
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:PointerSequence")
|
||||
};
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,20 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Define the float precision used in the program
|
||||
*/
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
typedef double real;
|
||||
|
||||
#ifndef SWIG
|
||||
static const real M_EPSILON = 0.00000001;
|
||||
#endif // SWIG
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,75 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Class to encapsulate a progress bar
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
class ProgressBar {
|
||||
public:
|
||||
inline ProgressBar()
|
||||
{
|
||||
_numtotalsteps = 0;
|
||||
_progress = 0;
|
||||
}
|
||||
|
||||
virtual ~ProgressBar() {}
|
||||
|
||||
virtual void reset()
|
||||
{
|
||||
_numtotalsteps = 0;
|
||||
_progress = 0;
|
||||
}
|
||||
|
||||
virtual void setTotalSteps(uint n)
|
||||
{
|
||||
_numtotalsteps = n;
|
||||
}
|
||||
|
||||
virtual void setProgress(uint i)
|
||||
{
|
||||
_progress = i;
|
||||
}
|
||||
|
||||
virtual void setLabelText(const string &s)
|
||||
{
|
||||
_label = s;
|
||||
}
|
||||
|
||||
/** accessors */
|
||||
inline uint getTotalSteps() const
|
||||
{
|
||||
return _numtotalsteps;
|
||||
}
|
||||
|
||||
inline uint getProgress() const
|
||||
{
|
||||
return _progress;
|
||||
}
|
||||
|
||||
inline string getLabelText() const
|
||||
{
|
||||
return _label;
|
||||
}
|
||||
|
||||
protected:
|
||||
uint _numtotalsteps;
|
||||
uint _progress;
|
||||
string _label;
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ProgressBar")
|
||||
};
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,106 @@
|
||||
/* SPDX-FileCopyrightText: 2008-2022 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Class to define a pseudo Perlin noise
|
||||
*/
|
||||
|
||||
#include "BLI_math_base.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "PseudoNoise.h"
|
||||
#include "RandGen.h"
|
||||
|
||||
static int modf_to_index(Freestyle::real x, uint range)
|
||||
{
|
||||
if (isfinite(x)) {
|
||||
Freestyle::real tmp;
|
||||
int i = abs(int(modf(x, &tmp) * range));
|
||||
BLI_assert(i >= 0 && i < range);
|
||||
return i;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
real PseudoNoise::_values[];
|
||||
|
||||
void PseudoNoise::init(long seed)
|
||||
{
|
||||
RandGen::srand48(seed);
|
||||
for (uint 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_to_index(x, 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;
|
||||
}
|
||||
|
||||
static 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_to_index(x, NB_VALUE_NOISE);
|
||||
int h = i - 1;
|
||||
if (UNLIKELY(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);
|
||||
#if 0
|
||||
cerr << "x0=" << x0 << " x1=" << x1 << " x2=" << x2 << " x3=" << x3 << endl;
|
||||
cerr << "y0=" << y0 << " y1=" << y1 << " y2=" << y2 << " y3=" << y3 << " :" << endl;
|
||||
#endif
|
||||
return (x0 * y0 + x1 * y1 + x2 * y2 + x3 * y3) / (y0 + y1 + y2 + y3);
|
||||
}
|
||||
|
||||
real PseudoNoise::turbulenceSmooth(real x, uint nbOctave)
|
||||
{
|
||||
real y = 0;
|
||||
real k = 1.0;
|
||||
for (uint i = 0; i < nbOctave; i++) {
|
||||
y = y + k * smoothNoise(x * k);
|
||||
k = k / 2.0;
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
real PseudoNoise::turbulenceLinear(real x, uint nbOctave)
|
||||
{
|
||||
real y = 0;
|
||||
real k = 1.0;
|
||||
for (uint i = 0; i < nbOctave; i++) {
|
||||
y = y + k * linearNoise(x * k);
|
||||
k = k / 2.0;
|
||||
}
|
||||
return y;
|
||||
}
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,37 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Class to define a pseudo Perlin noise
|
||||
*/
|
||||
|
||||
#include "Precision.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
class PseudoNoise {
|
||||
public:
|
||||
virtual ~PseudoNoise() {}
|
||||
|
||||
real smoothNoise(real x);
|
||||
real linearNoise(real x);
|
||||
|
||||
real turbulenceSmooth(real x, uint nbOctave = 8);
|
||||
real turbulenceLinear(real x, uint nbOctave = 8);
|
||||
|
||||
static void init(long seed);
|
||||
|
||||
protected:
|
||||
static const uint NB_VALUE_NOISE = 512;
|
||||
static real _values[NB_VALUE_NOISE];
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:PseudoNoise")
|
||||
};
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,10 @@
|
||||
/* SPDX-FileCopyrightText: 2012-2022 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Python Interpreter
|
||||
*/
|
||||
|
||||
#include "PythonInterpreter.h"
|
||||
@@ -0,0 +1,98 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Python Interpreter
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include "Interpreter.h"
|
||||
|
||||
#include "BKE_context.hh"
|
||||
#include "BKE_global.hh"
|
||||
#include "BKE_lib_id.hh"
|
||||
#include "BKE_main.hh"
|
||||
#include "BKE_text.h"
|
||||
|
||||
#include "BPY_extern_run.hh"
|
||||
|
||||
#include "bpy_capi_utils.hh"
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
class PythonInterpreter : public Interpreter {
|
||||
public:
|
||||
PythonInterpreter()
|
||||
{
|
||||
_language = "Python";
|
||||
}
|
||||
|
||||
void setContext(blender::bContext *C)
|
||||
{
|
||||
_context = C;
|
||||
}
|
||||
|
||||
int interpretFile(const string &filename)
|
||||
{
|
||||
char *fn = const_cast<char *>(filename.c_str());
|
||||
#if 0
|
||||
bool ok = BPY_run_filepath(_context, fn, nullptr);
|
||||
#else
|
||||
bool ok;
|
||||
blender::Text *text = BKE_text_load(&_freestyle_bmain, fn, blender::G.main->filepath);
|
||||
if (text) {
|
||||
ok = BPY_run_text(_context, text, nullptr, false);
|
||||
BKE_id_delete(&_freestyle_bmain, text);
|
||||
}
|
||||
else {
|
||||
cerr << "Cannot open file" << endl;
|
||||
ok = false;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (ok == false) {
|
||||
cerr << "\nError executing Python script from PythonInterpreter::interpretFile" << endl;
|
||||
cerr << "File: " << fn << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int interpretString(const string &str, const string &name)
|
||||
{
|
||||
if (!BPY_run_string_eval(_context, nullptr, str.c_str())) {
|
||||
cerr << "\nError executing Python script from PythonInterpreter::interpretString" << endl;
|
||||
cerr << "Name: " << name << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int interpretText(struct blender::Text *text, const string &name)
|
||||
{
|
||||
if (!blender::BPY_run_text(_context, text, nullptr, false)) {
|
||||
cerr << "\nError executing Python script from PythonInterpreter::interpretText" << endl;
|
||||
cerr << "Name: " << name << endl;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
private:
|
||||
blender::bContext *_context = nullptr;
|
||||
blender::Main _freestyle_bmain = {};
|
||||
};
|
||||
|
||||
} /* namespace Freestyle */
|
||||
122
blender-5.2.0/source/blender/freestyle/intern/system/RandGen.cpp
Normal file
122
blender-5.2.0/source/blender/freestyle/intern/system/RandGen.cpp
Normal file
@@ -0,0 +1,122 @@
|
||||
/* SPDX-FileCopyrightText: 2012-2022 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Pseudo-random number generator
|
||||
*/
|
||||
|
||||
#include "RandGen.h"
|
||||
|
||||
#include "BLI_sys_types.h"
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
//
|
||||
// Macro definitions
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define N 16
|
||||
#define MASK (uint(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
|
||||
#if 0 // XXX Unused
|
||||
# define HI_BIT (1L << (2 * N - 1))
|
||||
#endif
|
||||
|
||||
#define LOW(x) (uint(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); \
|
||||
} \
|
||||
((void)0)
|
||||
|
||||
#define CARRY(x, y) (ulong(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))
|
||||
#if 0 // XXX, unused
|
||||
# define SETLOW(x, y, n) SET3(x, LOW((y)[n]), LOW((y)[(n) + 1]), LOW((y)[(n) + 2]))
|
||||
#endif
|
||||
#define SEED(x0, x1, x2) (SET3(x, x0, x1, x2), SET3(a, A0, A1, A2), c = C)
|
||||
|
||||
#if 0 // XXX, unused
|
||||
# define REST(v) \
|
||||
for (i = 0; i < 3; i++) { \
|
||||
xsubi[i] = x[i]; \
|
||||
x[i] = temp[i]; \
|
||||
} \
|
||||
return (v); \
|
||||
(void)0
|
||||
|
||||
# define NEST(TYPE, f, F) \
|
||||
TYPE f(ushort *xsubi) \
|
||||
{ \
|
||||
int i; \
|
||||
TYPE v; \
|
||||
uint temp[3]; \
|
||||
for (i = 0; i < 3; i++) { \
|
||||
temp[i] = x[i]; \
|
||||
x[i] = LOW(xsubi[i]); \
|
||||
} \
|
||||
v = F(); \
|
||||
REST(v); \
|
||||
}
|
||||
#endif
|
||||
|
||||
static uint x[3] = {
|
||||
X0,
|
||||
X1,
|
||||
X2,
|
||||
};
|
||||
static uint a[3] = {
|
||||
A0,
|
||||
A1,
|
||||
A2,
|
||||
};
|
||||
static uint 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()
|
||||
{
|
||||
uint 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]);
|
||||
}
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,31 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Pseudo-random number generator
|
||||
*/
|
||||
|
||||
/* TODO: Check whether we could replace this with BLI rand stuff. */
|
||||
|
||||
#include "../system/Precision.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
class RandGen {
|
||||
public:
|
||||
static real drand48();
|
||||
static void srand48(long seedval);
|
||||
|
||||
private:
|
||||
static void next();
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:RandGen")
|
||||
};
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,54 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Classes defining the basic "Iterator" design pattern
|
||||
*/
|
||||
|
||||
#include "render_types.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
class RenderMonitor {
|
||||
public:
|
||||
inline RenderMonitor(blender::Render *re)
|
||||
{
|
||||
_re = re;
|
||||
}
|
||||
|
||||
virtual ~RenderMonitor() {}
|
||||
|
||||
inline void setInfo(std::string info)
|
||||
{
|
||||
if (_re && !info.empty()) {
|
||||
_re->i.infostr = info.c_str();
|
||||
_re->display->stats_draw(&_re->i);
|
||||
_re->i.infostr = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
inline void progress(float i)
|
||||
{
|
||||
if (_re) {
|
||||
_re->display->progress(i);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool testBreak()
|
||||
{
|
||||
return _re && _re->display->test_break();
|
||||
}
|
||||
|
||||
protected:
|
||||
blender::Render *_re;
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:RenderMonitor")
|
||||
};
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,49 @@
|
||||
/* SPDX-FileCopyrightText: 2008-2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief String utilities
|
||||
*/
|
||||
|
||||
// soc #include <qfileinfo.h>
|
||||
|
||||
#include "StringUtils.h"
|
||||
#include "FreestyleConfig.h"
|
||||
|
||||
#include "BLI_sys_types.h"
|
||||
|
||||
namespace Freestyle::StringUtils {
|
||||
|
||||
void getPathName(const string &path, const string &base, vector<string> &pathnames)
|
||||
{
|
||||
string dir;
|
||||
string res;
|
||||
char cleaned[FILE_MAX];
|
||||
uint size = path.size();
|
||||
|
||||
pathnames.push_back(base);
|
||||
|
||||
for (uint pos = 0, sep = path.find(Config::PATH_SEP, pos); pos < size;
|
||||
pos = sep + 1, sep = path.find(Config::PATH_SEP, pos))
|
||||
{
|
||||
if (sep == uint(string::npos)) {
|
||||
sep = size;
|
||||
}
|
||||
|
||||
dir = path.substr(pos, sep - pos);
|
||||
|
||||
blender::STRNCPY(cleaned, dir.c_str());
|
||||
blender::BLI_path_normalize(cleaned);
|
||||
res = string(cleaned);
|
||||
|
||||
if (!base.empty()) {
|
||||
res += Config::DIR_SEP + base;
|
||||
}
|
||||
|
||||
pathnames.push_back(res);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Freestyle::StringUtils
|
||||
@@ -0,0 +1,39 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief String utilities
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "BLI_path_utils.hh"
|
||||
#include "BLI_string.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
namespace StringUtils {
|
||||
|
||||
void getPathName(const string &path, const string &base, vector<string> &pathnames);
|
||||
|
||||
// STL related
|
||||
struct ltstr {
|
||||
bool operator()(const char *s1, const char *s2) const
|
||||
{
|
||||
return strcmp(s1, s2) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
} // end of namespace StringUtils
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,16 @@
|
||||
/* SPDX-FileCopyrightText: 2012-2022 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Class defining a singleton used as timestamp
|
||||
*/
|
||||
|
||||
#include "TimeStamp.h"
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
TimeStamp TimeStamp::_instance;
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,55 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Class defining a singleton used as timestamp
|
||||
*/
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
#include "BLI_sys_types.h"
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
class TimeStamp {
|
||||
public:
|
||||
static inline TimeStamp *instance()
|
||||
{
|
||||
return &_instance;
|
||||
}
|
||||
|
||||
inline uint 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;
|
||||
uint _time_stamp;
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:TimeStamp")
|
||||
};
|
||||
|
||||
} /* namespace Freestyle */
|
||||
@@ -0,0 +1,41 @@
|
||||
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
|
||||
#pragma once
|
||||
|
||||
/** \file
|
||||
* \ingroup freestyle
|
||||
* \brief Class to measure elapsed time
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
namespace Freestyle {
|
||||
|
||||
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;
|
||||
|
||||
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Chronometer")
|
||||
};
|
||||
|
||||
} /* namespace Freestyle */
|
||||
Reference in New Issue
Block a user