001: /*
002: * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of Substance Kirill Grouchnikov nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030: package org.jvnet.substance.painter.noise;
031:
032: /**
033: * Noise filter that produces marble-like distribution. This class is part of
034: * officially supported API.
035: *
036: * @author Kirill Grouchnikov
037: */
038: public class MarbleFilter extends BaseNoiseFilter {
039: /**
040: * Creates a new marble filter.
041: *
042: * @param xFactor
043: * Stretch factor for X axis.
044: * @param yFactor
045: * Stretch factor for Y axis.
046: * @param zFactor
047: * Stretch factor for Z axis.
048: * @param trigKind
049: * Trigonometry function.
050: */
051: public MarbleFilter(double xFactor, double yFactor, double zFactor,
052: TrigKind trigKind) {
053: super (xFactor, yFactor, zFactor, 1.0, trigKind);
054: }
055:
056: /**
057: * Creates a new marble filter oriented along X axis.
058: *
059: * @param xFactor
060: * Stretch factor for X axis.
061: * @param trigKind
062: * Trigonometry function.
063: * @return Marble filter oriented along X axis.
064: */
065: public static MarbleFilter getXFilter(double xFactor,
066: TrigKind trigKind) {
067: return new MarbleFilter(xFactor, 0.0, 0.0, trigKind);
068: }
069:
070: /**
071: * Creates a new marble filter oriented along Y axis.
072: *
073: * @param yFactor
074: * Stretch factor for Y axis.
075: * @param trigKind
076: * Trigonometry function.
077: * @return Marble filter oriented along Y axis.
078: */
079: public static MarbleFilter getYFilter(double yFactor,
080: TrigKind trigKind) {
081: return new MarbleFilter(0.0, yFactor, 0.0, trigKind);
082: }
083:
084: /**
085: * Creates a new marble filter oriented along Z axis.
086: *
087: * @param zFactor
088: * Stretch factor for Z axis.
089: * @param trigKind
090: * Trigonometry function.
091: * @return Marble filter oriented along Z axis.
092: */
093: public static MarbleFilter getZFilter(double zFactor,
094: TrigKind trigKind) {
095: return new MarbleFilter(0.0, 0.0, zFactor, trigKind);
096: }
097:
098: /*
099: * (non-Javadoc)
100: *
101: * @see org.jvnet.substance.painter.noise.NoiseFilter#apply(double, double,
102: * double, double)
103: */
104: public double apply(double x, double y, double z, double origValue) {
105: double trans = this .xFactor * x + this .yFactor * y
106: + this .zFactor * z + origValue;
107: double trig = (this .trigKind == TrigKind.COSINE) ? Math
108: .cos(trans) : Math.sin(trans);
109: return 0.5 + 0.5 * trig;
110: }
111: }
|