00001 // $Id: noisef.cpp 1282 2006-06-09 09:46:49Z alex $ 00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE 00003 ================================XARAHEADERSTART=========================== 00004 00005 Xara LX, a vector drawing and manipulation program. 00006 Copyright (C) 1993-2006 Xara Group Ltd. 00007 Copyright on certain contributions may be held in joint with their 00008 respective authors. See AUTHORS file for details. 00009 00010 LICENSE TO USE AND MODIFY SOFTWARE 00011 ---------------------------------- 00012 00013 This file is part of Xara LX. 00014 00015 Xara LX is free software; you can redistribute it and/or modify it 00016 under the terms of the GNU General Public License version 2 as published 00017 by the Free Software Foundation. 00018 00019 Xara LX and its component source files are distributed in the hope 00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the 00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00022 See the GNU General Public License for more details. 00023 00024 You should have received a copy of the GNU General Public License along 00025 with Xara LX (see the file GPL in the root directory of the 00026 distribution); if not, write to the Free Software Foundation, Inc., 51 00027 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00028 00029 00030 ADDITIONAL RIGHTS 00031 ----------------- 00032 00033 Conditional upon your continuing compliance with the GNU General Public 00034 License described above, Xara Group Ltd grants to you certain additional 00035 rights. 00036 00037 The additional rights are to use, modify, and distribute the software 00038 together with the wxWidgets library, the wxXtra library, and the "CDraw" 00039 library and any other such library that any version of Xara LX relased 00040 by Xara Group Ltd requires in order to compile and execute, including 00041 the static linking of that library to XaraLX. In the case of the 00042 "CDraw" library, you may satisfy obligation under the GNU General Public 00043 License to provide source code by providing a binary copy of the library 00044 concerned and a copy of the license accompanying it. 00045 00046 Nothing in this section restricts any of the rights you have under 00047 the GNU General Public License. 00048 00049 00050 SCOPE OF LICENSE 00051 ---------------- 00052 00053 This license applies to this program (XaraLX) and its constituent source 00054 files only, and does not necessarily apply to other Xara products which may 00055 in part share the same code base, and are subject to their own licensing 00056 terms. 00057 00058 This license does not apply to files in the wxXtra directory, which 00059 are built into a separate library, and are subject to the wxWindows 00060 license contained within that directory in the file "WXXTRA-LICENSE". 00061 00062 This license does not apply to the binary libraries (if any) within 00063 the "libs" directory, which are subject to a separate license contained 00064 within that directory in the file "LIBS-LICENSE". 00065 00066 00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS 00068 ---------------------------------------------- 00069 00070 Subject to the terms of the GNU Public License (see above), you are 00071 free to do whatever you like with your modifications. However, you may 00072 (at your option) wish contribute them to Xara's source tree. You can 00073 find details of how to do this at: 00074 http://www.xaraxtreme.org/developers/ 00075 00076 Prior to contributing your modifications, you will need to complete our 00077 contributor agreement. This can be found at: 00078 http://www.xaraxtreme.org/developers/contribute/ 00079 00080 Please note that Xara will not accept modifications which modify any of 00081 the text between the start and end of this header (marked 00082 XARAHEADERSTART and XARAHEADEREND). 00083 00084 00085 MARKS 00086 ----- 00087 00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara 00089 designs are registered or unregistered trademarks, design-marks, and/or 00090 service marks of Xara Group Ltd. All rights in these marks are reserved. 00091 00092 00093 Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK. 00094 http://www.xara.com/ 00095 00096 =================================XARAHEADEREND============================ 00097 */ 00098 00099 #include "camtypes.h" 00100 #include "noisef.h" 00101 #include "vector3d.h" 00102 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00103 #include "bitmpinf.h" 00104 //#include "bitmap.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00105 #include "macros.h" 00106 #include "noisebas.h" 00107 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00108 00109 CC_IMPLEMENT_DYNCREATE(NoiseFractalFill,CCObject); 00110 00111 /******************************************************************************************** 00112 00113 NoiseFractalFill::NoiseFractalFill() 00114 00115 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00116 Created: 16/01/97 00117 Purpose: A noise based fill. Really simply defined as the projection of a 3d noise 00118 function onto a surface. 00119 For documentation, see Docs\Specs\Textures\Phase1 Spec v1,2 and 3 .doc 00120 00121 ********************************************************************************************/ 00122 00123 NoiseFractalFill::NoiseFractalFill() 00124 { 00125 } 00126 00127 00128 /******************************************************************************************** 00129 00130 > BOOL NoiseFractalFill::DoFill(double scale, 00131 double tuber, 00132 double sweepr, 00133 KernelBitmap *pBitmap) const 00134 00135 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00136 Created: 16/01/97 00137 Purpose: A noise based fill. Really simply defined as the projection of a 3d noise 00138 function on a torus of given swept radius and tube radius. 00139 00140 ********************************************************************************************/ 00141 /* 00142 BOOL NoiseFractalFill::DoFill(double scale, 00143 double tuber, 00144 double sweepr, 00145 KernelBitmap *pBitmap) const 00146 { 00147 // go get the noise manager 00148 NoiseMan* pNoiseMan = GetApplication()->GetNoiseManager(); 00149 if (pNoiseMan==NULL) 00150 return FALSE; 00151 00152 BitmapInfo Info; 00153 pBitmap->ActualBitmap->GetInfo(&Info); 00154 00155 INT32 Width = Info.PixelWidth; 00156 INT32 Height = Info.PixelHeight; 00157 00158 double n; 00159 INT32 i,j; 00160 BYTE cn; 00161 Vector3D p; 00162 00163 double theta,phi,sin_phi,cos_phi; 00164 00165 double vstep = XS_2PI/Height; 00166 double ustep = XS_2PI/Width; 00167 double ls = 1.0/scale; 00168 00169 for (j=0; j<Height; j++) 00170 { 00171 phi = j*vstep; 00172 00173 sin_phi = sin(phi); 00174 cos_phi = cos(phi); 00175 00176 for (i=0; i<Width; i++) 00177 { 00178 theta = i*ustep; 00179 00180 p.x = sweepr + tuber*cos(theta); 00181 p.y = tuber*sin(theta); 00182 00183 p.z = p.x*sin_phi; 00184 p.x = p.x*cos_phi; 00185 00186 p.x *= 8.0; 00187 00188 // translate into the positive octant 00189 p.x += sweepr+tuber; 00190 p.y += tuber; 00191 p.z += sweepr+tuber; 00192 00193 // find the noise value at this position 00194 n = pNoiseMan->NOISE1D(p*ls); 00195 // turn this into a grey scale 00196 cn = (BYTE)(n*255.0+0.5); 00197 // and place it in the bitmap 00198 pBitmap->PlotPixel(i,j,cn); 00199 } 00200 } 00201 00202 return TRUE; 00203 } 00204 */ 00205 00206 /* 00207 00208 BOOL NoiseFractalFill::DoFill(double scale, 00209 double tuber, 00210 double sweepr, 00211 KernelBitmap *pBitmap) const 00212 { 00213 double ustep,vstep,ls,n,s,c; 00214 Vector3D p; 00215 BYTE cn; 00216 BitmapInfo Info; 00217 INT32 Width,Height,i,j; 00218 00219 // go get the noise manager 00220 NoiseMan* pNoiseMan = GetApplication()->GetNoiseManager(); 00221 if (pNoiseMan==NULL) 00222 return FALSE; 00223 00224 pBitmap->ActualBitmap->GetInfo(&Info); 00225 00226 Width = Info.PixelWidth; 00227 Height = Info.PixelHeight; 00228 00229 ustep = 1.0/(double)Width; 00230 vstep = 1.0/(double)Height; 00231 ls = 1.0/scale; 00232 p.z = 0.0; 00233 00234 for (j=0; j<Height; j++) 00235 { 00236 p.y = j*vstep*100.0; 00237 s = sin(2.0*p.y*XS_2PI); 00238 for (i=0; i<Width; i++) 00239 { 00240 p.x = i*ustep*100.0; 00241 c = s*cos(2.0*p.x*XS_2PI); 00242 // find the noise value at this position 00243 n = pNoiseMan->NOISE1D(p*ls); 00244 // turn this into a grey scale 00245 cn = (BYTE)(128+n*c*127.0+0.5); 00246 // and place it in the bitmap 00247 pBitmap->PlotPixel(i,j,cn); 00248 } 00249 } 00250 00251 return TRUE; 00252 } 00253 00254 */ 00255 00256 /******************************************************************************************** 00257 00258 > BOOL NoiseFractalFill::DoFill(double scale, 00259 double tuber, 00260 double sweepr, 00261 KernelBitmap *pBitmap) const 00262 00263 Author: Mike_Kenny (Xara Group Ltd) <camelotdev@xara.com> 00264 Created: 16/01/97 00265 Purpose: A noise based fill. This version uses 2d noise built from an array of random 00266 numbers which are spline interpolated and wrapped at the edges. This is 00267 dirtier and quicker than the 3d version and is less succeptable to warping 00268 yet still manages to tile. 00269 00270 ********************************************************************************************/ 00271 00272 BOOL NoiseFractalFill::DoFill(double scale, 00273 UINT32 seed, 00274 KernelBitmap *pBitmap) const 00275 { 00276 double ustep,vstep,ustart,vstart; 00277 double n; 00278 Vector3D p; 00279 BYTE cn; 00280 BitmapInfo Info; 00281 INT32 Width,Height,i,j; 00282 00283 // go get the noise manager 00284 NoiseMan* pNoiseMan = GetApplication()->GetNoiseManager(); 00285 if (pNoiseMan==NULL) 00286 return FALSE; 00287 00288 // set the random number generator. 00289 pNoiseMan->SEEDTABLE(seed); 00290 00291 pBitmap->ActualBitmap->GetInfo(&Info); 00292 00293 Width = Info.PixelWidth; 00294 Height = Info.PixelHeight; 00295 00296 ustep = 1.0/(double)Width; 00297 vstep = 1.0/(double)Height; 00298 vstart = vstep/2.0; 00299 00300 p.z = 0.0; 00301 for (j=0; j<Height; j++) 00302 { 00303 p.y = vstart; 00304 ustart = ustep/2.0; 00305 for (i=0; i<Width; i++) 00306 { 00307 p.x = ustart; 00308 // find the noise value at this position 00309 n = pNoiseMan->NOISE1D(p, scale); 00310 // turn this into a grey scale 00311 cn = (BYTE)(n*255.0+0.5); 00312 // and place it in the bitmap 00313 pBitmap->PlotPixel(i,j,cn); 00314 ustart += ustep; 00315 } 00316 vstart += vstep; 00317 } 00318 00319 /* double ng2 = ustep/2.0; 00320 double ng1 = 1.0 - ng2; 00321 00322 double n0,n1; 00323 double t; 00324 00325 vstart = vstep + vstep/2.0; 00326 for (j=1; j<Height-1; j++) 00327 { 00328 p.y = vstart; 00329 p.x = ng1; 00330 n0 = pNoiseMan->NOISE1D(p); 00331 p.x = ng2; 00332 n1 = pNoiseMan->NOISE1D(p); 00333 00334 t = 1.0/3.0; 00335 n = n0 + t*(n1-n0); 00336 cn = (BYTE)(n*255.0+0.5); 00337 pBitmap->PlotPixel(Width-1,j,cn); 00338 00339 t = 2.0/3.0; 00340 n = n0 + t*(n1-n0); 00341 cn = (BYTE)(n*255.0+0.5); 00342 pBitmap->PlotPixel(0,j,cn); 00343 00344 vstart += vstep; 00345 } 00346 */ 00347 return TRUE; 00348 } 00349 00350 00351