[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [43788] trunk/blender/source/blender/ python/mathutils/mathutils_noise.c: previous move lost history on this file , restoring next commit.

Campbell Barton ideasman42 at gmail.com
Tue Jan 31 05:58:18 CET 2012


Revision: 43788
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=43788
Author:   campbellbarton
Date:     2012-01-31 04:58:06 +0000 (Tue, 31 Jan 2012)
Log Message:
-----------
previous move lost history on this file, restoring next commit.

Removed Paths:
-------------
    trunk/blender/source/blender/python/mathutils/mathutils_noise.c

Deleted: trunk/blender/source/blender/python/mathutils/mathutils_noise.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_noise.c	2012-01-31 04:23:49 UTC (rev 43787)
+++ trunk/blender/source/blender/python/mathutils/mathutils_noise.c	2012-01-31 04:58:06 UTC (rev 43788)
@@ -1,911 +0,0 @@
-/*
- * ***** BEGIN GPL LICENSE BLOCK *****
- *
- * 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.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * This is a new part of Blender.
- *
- * Contributor(s): eeshlo, Campbell Barton
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/python/mathutils/mathutils_noise.c
- *  \ingroup mathutils
- *
- * This file defines the 'noise' module, a general purpose module to access
- * blenders noise functions.
- */
-
-
-/************************/
-/* Blender Noise Module */
-/************************/
-
-#include <Python.h>
-
-#include "structseq.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_texture_types.h"
-
-#include "mathutils.h"
-#include "mathutils_noise.h"
-
-/* 2.6 update
- * Moved to submodule of mathutils.
- * All vector functions now return mathutils.Vector
- * Updated docs to be compatible with autodocs generation.
- * Updated vector functions to use nD array functions.
- * noise.vl_vector --> noise.variable_lacunarity
- * noise.vector --> noise.noise_vector
- */
-
-/*-----------------------------------------*/
-/* 'mersenne twister' random number generator */
-
-/* 
-   A C-program for MT19937, with initialization improved 2002/2/10.
-   Coded by Takuji Nishimura and Makoto Matsumoto.
-   This is a faster version by taking Shawn Cokus's optimization,
-   Matthe Bellew's simplification, Isaku Wada's real version.
-
-   Before using, initialize the state by using init_genrand(seed) 
-   or init_by_array(init_key, key_length).
-
-   Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
-   All rights reserved.                          
-
-   Redistribution and use in source and binary forms, with or without
-   modification, are permitted provided that the following conditions
-   are met:
-
-     1. Redistributions of source code must retain the above copyright
-        notice, this list of conditions and the following disclaimer.
-
-     2. Redistributions in binary form must reproduce the above copyright
-        notice, this list of conditions and the following disclaimer in the
-        documentation and/or other materials provided with the distribution.
-
-     3. The names of its contributors may not be used to endorse or promote 
-        products derived from this software without specific prior written 
-        permission.
-
-   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
-   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
-   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-
-   Any feedback is very welcome.
-   http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
-   email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
-*/
-
-/* Period parameters */
-#define N 624
-#define M 397
-#define MATRIX_A 0x9908b0dfUL	/* constant vector a */
-#define UMASK 0x80000000UL	/* most significant w-r bits */
-#define LMASK 0x7fffffffUL	/* least significant r bits */
-#define MIXBITS(u,v) (((u) & UMASK) | ((v) & LMASK))
-#define TWIST(u,v) ((MIXBITS(u,v) >> 1) ^ ((v)&1UL ? MATRIX_A : 0UL))
-
-static unsigned long state[N];	/* the array for the state vector  */
-static int left = 1;
-static int initf = 0;
-static unsigned long *next;
-
-/* initializes state[N] with a seed */
-static void init_genrand(unsigned long s)
-{
-	int j;
-	state[0] = s & 0xffffffffUL;
-	for (j = 1; j < N; j++) {
-		state[j] =
-			(1812433253UL *
-			  (state[j - 1] ^ (state[j - 1] >> 30)) + j);
-		/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
-		/* In the previous versions, MSBs of the seed affect   */
-		/* only MSBs of the array state[].                        */
-		/* 2002/01/09 modified by Makoto Matsumoto             */
-		state[j] &= 0xffffffffUL;	/* for >32 bit machines */
-	}
-	left = 1;
-	initf = 1;
-}
-
-static void next_state(void)
-{
-	unsigned long *p = state;
-	int j;
-
-	/* if init_genrand() has not been called, */
-	/* a default initial seed is used         */
-	if (initf == 0)
-		init_genrand(5489UL);
-
-	left = N;
-	next = state;
-
-	for (j = N - M + 1; --j; p++)
-		*p = p[M] ^ TWIST(p[0], p[1]);
-
-	for (j = M; --j; p++)
-		*p = p[M - N] ^ TWIST(p[0], p[1]);
-
-	*p = p[M - N] ^ TWIST(p[0], state[0]);
-}
-
-/*------------------------------------------------------------*/
-
-static void setRndSeed(int seed)
-{
-	if (seed == 0)
-		init_genrand(time(NULL));
-	else
-		init_genrand(seed);
-}
-
-/* float number in range [0, 1) using the mersenne twister rng */
-static float frand(void)
-{
-	unsigned long y;
-
-	if (--left == 0)
-		next_state();
-	y = *next++;
-
-	/* Tempering */
-	y ^= (y >> 11);
-	y ^= (y << 7) & 0x9d2c5680UL;
-	y ^= (y << 15) & 0xefc60000UL;
-	y ^= (y >> 18);
-
-	return (float) y / 4294967296.f;
-}
-
-/*------------------------------------------------------------*/
-/* Utility Functions */
-/*------------------------------------------------------------*/
-
-/* Fills an array of length size with random numbers in the range (-1, 1)*/
-static void rand_vn(float *array_tar, const int size)
-{
-	float *array_pt = array_tar + (size-1);
-	int i = size;
-	while (i--) { *(array_pt--) = 2.0f * frand() - 1.0f; }
-}
-
-/* Fills an array of length 3 with noise values */
-static void noise_vector(float x, float y, float z, int nb, float v[3])
-{
-	/* Simply evaluate noise at 3 different positions */
-	v[0] = (float)(2.0f * BLI_gNoise(1.f, x + 9.321f, y - 1.531f, z - 7.951f, 0, nb) - 1.0f);
-	v[1] = (float)(2.0f * BLI_gNoise(1.f, x, y, z, 0, nb) - 1.0f);
-	v[2] = (float)(2.0f * BLI_gNoise(1.f, x + 6.327f, y + 0.1671f, z - 2.672f, 0, nb) - 1.0f);
-}
-
-/* Returns a turbulence value for a given position (x, y, z) */
-static float turb(float x, float y, float z, int oct, int hard, int nb,
-		   float ampscale, float freqscale)
-{
-	float amp, out, t;
-	int i;
-	amp = 1.f;
-	out = (float)(2.0f * BLI_gNoise(1.f, x, y, z, 0, nb) - 1.0f);
-	if (hard)
-		out = fabsf(out);
-	for (i = 1; i < oct; i++) {
-		amp *= ampscale;
-		x *= freqscale;
-		y *= freqscale;
-		z *= freqscale;
-		t = (float)(amp * (2.0f * BLI_gNoise(1.f, x, y, z, 0, nb) - 1.0f));
-		if (hard)
-			t = fabsf(t);
-		out += t;
-	}
-	return out;
-}
-
-/* Fills an array of length 3 with the turbulence vector for a given
-position (x, y, z) */
-static void vTurb(float x, float y, float z, int oct, int hard, int nb,
-                  float ampscale, float freqscale, float v[3])
-{
-	float amp, t[3];
-	int i;
-	amp = 1.f;
-	noise_vector(x, y, z, nb, v);
-	if (hard) {
-		v[0] = fabsf(v[0]);
-		v[1] = fabsf(v[1]);
-		v[2] = fabsf(v[2]);
-	}
-	for (i = 1; i < oct; i++) {
-		amp *= ampscale;
-		x *= freqscale;
-		y *= freqscale;
-		z *= freqscale;
-		noise_vector(x, y, z, nb, t);
-		if (hard) {
-			t[0] = fabsf(t[0]);
-			t[1] = fabsf(t[1]);
-			t[2] = fabsf(t[2]);
-		}
-		v[0] += amp * t[0];
-		v[1] += amp * t[1];
-		v[2] += amp * t[2];
-	}
-}
-
-/*-------------------------DOC STRINGS ---------------------------*/
-PyDoc_STRVAR(M_Noise_doc,
-"The Blender noise module"
-);
-
-/*------------------------------------------------------------*/
-/* Python Functions */
-/*------------------------------------------------------------*/
-
-PyDoc_STRVAR(M_Noise_random_doc,
-".. function:: random()\n"
-"\n"
-"   Returns a random number in the range [0, 1].\n"
-"\n"
-"   :return: The random number.\n"
-"   :rtype: float\n"
-);
-static PyObject *M_Noise_random(PyObject *UNUSED(self))
-{
-	return PyFloat_FromDouble(frand());
-}
-
-PyDoc_STRVAR(M_Noise_random_unit_vector_doc,
-".. function:: random_unit_vector(size=3)\n"
-"\n"
-"   Returns a unit vector with random entries.\n"
-"\n"
-"   :arg size: The size of the vector to be produced.\n"
-"   :type size: Int\n"
-"   :return: The random unit vector.\n"
-"   :rtype: :class:`mathutils.Vector`\n"
-);
-static PyObject *M_Noise_random_unit_vector(PyObject *UNUSED(self), PyObject *args)
-{
-	float vec[4] = {0.0f, 0.0f, 0.0f, 0.0f};
-	float norm = 2.0f;
-	int size = 3;
-
-	if (!PyArg_ParseTuple(args, "|i:random_vector", &size))
-		return NULL;
-
-	if (size > 4 || size < 2) {
-		PyErr_SetString(PyExc_ValueError, "Vector(): invalid size");
-		return NULL;
-	}
-
-	while (norm == 0.0f || norm >= 1.0f) {
-		rand_vn(vec, size);
-		norm = normalize_vn(vec, size);
-	}
-
-	return Vector_CreatePyObject(vec, size, Py_NEW, NULL);
-}
-/* This is dumb, most people will want a unit vector anyway, since this doesn't have uniform distribution over a sphere*/
-/*
-PyDoc_STRVAR(M_Noise_random_vector_doc,
-".. function:: random_vector(size=3)\n"
-"\n"
-"   Returns a vector with random entries in the range [0, 1).\n"
-"\n"
-"   :arg size: The size of the vector to be produced.\n"
-"   :type size: Int\n"
-"   :return: The random vector.\n"
-"   :rtype: :class:`mathutils.Vector`\n"
-);

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-blender-cvs mailing list