1 /**************************************************************************/ 2 /* Copyright 2012 Tim Day */ 3 /* */ 4 /* This file is part of Evolvotron */ 5 /* */ 6 /* Evolvotron is free software: you can redistribute it and/or modify */ 7 /* it under the terms of the GNU General Public License as published by */ 8 /* the Free Software Foundation, either version 3 of the License, or */ 9 /* (at your option) any later version. */ 10 /* */ 11 /* Evolvotron is distributed in the hope that it will be useful, */ 12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ 14 /* GNU General Public License for more details. */ 15 /* */ 16 /* You should have received a copy of the GNU General Public License */ 17 /* along with Evolvotron. If not, see <http://www.gnu.org/licenses/>. */ 18 /**************************************************************************/ 19 20 /*! \file 21 \brief Functions inspired by tartan patterns. 22 */ 23 24 #ifndef _functions_tartan_h_ 25 #define _functions_tartan_h_ 26 27 #include "common.h" 28 29 #include "function_boilerplate.h" 30 31 //------------------------------------------------------------------------------------------ 32 33 FUNCTION_BEGIN(FunctionTartanSelectFree,10,6,false,FnStructure) 34 35 //! Evaluate function. 36 /*! Sign of one 1D function's dot product determines one bit, ditto for another bit. 37 2 bits used to select from 4 possibilities. 38 There's no guarantee of a repetitive pattern unless the generator functions are. 39 */ evaluate(const XYZ & p)40 virtual const XYZ evaluate(const XYZ& p) const 41 { 42 const XYZ p0(p.x(),param(0),param(1)); 43 const XYZ p1(param(2),p.y(),param(3)); 44 const XYZ d0(param(4),param(5),param(6)); 45 const XYZ d1(param(7),param(8),param(9)); 46 const int b0=(arg(0)(p0)%XYZ(d0)>0.0); 47 const int b1=(arg(1)(p1)%XYZ(d1)>0.0); 48 const int which=2+b0+2*b1; 49 assert(2<=which && which<6); 50 return arg(which)(p); 51 } 52 53 FUNCTION_END(FunctionTartanSelectFree) 54 55 //------------------------------------------------------------------------------------------ 56 57 FUNCTION_BEGIN(FunctionTartanSelect,14,6,false,FnStructure) 58 59 //! Evaluate function. 60 /*! Similar to function free except the generators repeat. 61 */ evaluate(const XYZ & p)62 virtual const XYZ evaluate(const XYZ& p) const 63 { 64 const real x=(param(0)>0.0 ? modulusf(p.x(),param(1)) : trianglef(p.x(),param(1))); 65 const real y=(param(2)>0.0 ? modulusf(p.y(),param(3)) : trianglef(p.y(),param(3))); 66 const XYZ p0(x,param(4),param(5)); 67 const XYZ p1(param(6),y,param(7)); 68 const XYZ d0(param(8),param(9),param(10)); 69 const XYZ d1(param(11),param(12),param(13)); 70 const int b0=(arg(0)(p0)%XYZ(d0)>0.0); 71 const int b1=(arg(1)(p1)%XYZ(d1)>0.0); 72 const int which=2+b0+2*b1; 73 assert(2<=which && which<6); 74 return arg(which)(p); 75 } 76 77 FUNCTION_END(FunctionTartanSelect) 78 79 //------------------------------------------------------------------------------------------ 80 81 FUNCTION_BEGIN(FunctionTartanSelectRepeat,14,6,false,FnStructure) 82 83 //! Evaluate function. 84 /*! Similar to above function except the invoked functions repeat too. 85 */ evaluate(const XYZ & p)86 virtual const XYZ evaluate(const XYZ& p) const 87 { 88 const real x=(param(0)>0.0 ? modulusf(p.x(),param(1)) : trianglef(p.x(),param(1))); 89 const real y=(param(2)>0.0 ? modulusf(p.y(),param(3)) : trianglef(p.y(),param(3))); 90 const XYZ p0(x,param(4),param(5)); 91 const XYZ p1(param(6),y,param(7)); 92 const XYZ d0(param(8),param(9),param(10)); 93 const XYZ d1(param(11),param(12),param(13)); 94 const int b0=(arg(0)(p0)%XYZ(d0)>0.0); 95 const int b1=(arg(1)(p1)%XYZ(d1)>0.0); 96 const int which=2+b0+2*b1; 97 assert(2<=which && which<6); 98 return arg(which)(XYZ(x,y,p.z())); 99 } 100 101 FUNCTION_END(FunctionTartanSelectRepeat) 102 103 //------------------------------------------------------------------------------------------ 104 105 FUNCTION_BEGIN(FunctionTartanMixFree,4,2,false,0) 106 107 //! Evaluate function. 108 /*! As above, but mix 2 functions. 109 */ evaluate(const XYZ & p)110 virtual const XYZ evaluate(const XYZ& p) const 111 { 112 const XYZ p0(p.x(),param(0),param(1)); 113 const XYZ p1(param(2),p.y(),param(3)); 114 const XYZ warp(arg(0)(p0)); 115 const XYZ weft(arg(1)(p1)); 116 return 0.5*(warp+weft); 117 } 118 119 FUNCTION_END(FunctionTartanMixFree) 120 121 //------------------------------------------------------------------------------------------ 122 123 FUNCTION_BEGIN(FunctionTartanMixRepeat,8,2,false,0) 124 125 //! Evaluate function. 126 /*! As above, but mix 2 functions. 127 */ evaluate(const XYZ & p)128 virtual const XYZ evaluate(const XYZ& p) const 129 { 130 const real x=(param(0)>0.0 ? modulusf(p.x(),param(1)) : trianglef(p.x(),param(1))); 131 const real y=(param(2)>0.0 ? modulusf(p.y(),param(3)) : trianglef(p.y(),param(3))); 132 const XYZ p0(x,param(4),param(5)); 133 const XYZ p1(param(6),y,param(7)); 134 const XYZ warp(arg(0)(p0)); 135 const XYZ weft(arg(1)(p1)); 136 return 0.5*(warp+weft); 137 } 138 139 FUNCTION_END(FunctionTartanMixRepeat) 140 141 //------------------------------------------------------------------------------------------ 142 143 #endif 144