[skycastle-commits] SF.net SVN: skycastle: [230] trunk/skycastle/modules/texture/src/main/java/ org/skycastle/texture

  • From: zzorn@xxxxxxxxxxxxxxxxxxxxx
  • To: skycastle-commits@xxxxxxxxxxxxx
  • Date: Sat, 06 Oct 2007 23:08:40 -0700

Revision: 230
          http://skycastle.svn.sourceforge.net/skycastle/?rev=230&view=rev
Author:   zzorn
Date:     2007-10-06 23:08:38 -0700 (Sat, 06 Oct 2007)

Log Message:
-----------
Improvements to the procedural texture renderer, and simplified the examples.

Modified Paths:
--------------
    
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/Field.java
    
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/FieldImpl.java
    
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/ParameterSet.java
    
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/ParameterSetImpl.java
    
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/ProceduralTextureView.java
    
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/RectangularAreaParameters.java
    
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/RectangularAreaParametersImpl.java
    
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/component/AbstractComponent.java
    
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/component/Component.java
    
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/example/TextureExample.java

Added Paths:
-----------
    
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/FieldRenderer.java
    
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/example/ComponentUiExample.java
    
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/example/ExampleDataCreator.java

Modified: 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/Field.java
===================================================================
--- 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/Field.java  
    2007-10-07 06:06:42 UTC (rev 229)
+++ 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/Field.java  
    2007-10-07 06:08:38 UTC (rev 230)
@@ -61,4 +61,5 @@
      * @param removedChannel should not be null, and should be present.
      */
     void removeChannel( Channel removedChannel );
+
 }

Modified: 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/FieldImpl.java
===================================================================
--- 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/FieldImpl.java
  2007-10-07 06:06:42 UTC (rev 229)
+++ 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/FieldImpl.java
  2007-10-07 06:08:38 UTC (rev 230)
@@ -54,13 +54,17 @@
         ParameterChecker.checkPositiveNonZeroInteger( xSize, "xSize" );
         ParameterChecker.checkPositiveNonZeroInteger( ySize, "ySize" );
 
-        mySizeX = xSize;
-        mySizeY = ySize;
+        if ( mySizeX != xSize || mySizeY != ySize )
+        {
+            mySizeX = xSize;
+            mySizeY = ySize;
 
-        for ( Channel channel : myChannels.values() )
-        {
-            channel.resize( xSize, ySize );
+            for ( Channel channel : myChannels.values() )
+            {
+                channel.resize( xSize, ySize );
+            }
         }
+
     }
 
 

Added: 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/FieldRenderer.java
===================================================================
--- 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/FieldRenderer.java
                              (rev 0)
+++ 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/FieldRenderer.java
      2007-10-07 06:08:38 UTC (rev 230)
@@ -0,0 +1,220 @@
+package org.skycastle.texture;
+
+import java.awt.image.BufferedImage;
+
+/**
+ * A small utility class that holds a field and calculates and renders it to a 
buffer when requested.
+ */
+public final class FieldRenderer
+{
+
+    //======================================================================
+    // Private Fields
+
+    private final Field myField = new FieldImpl( 1, 1 );
+
+    private final String myRedChannelName;
+    private final String myGreenChannelName;
+    private final String myBlueChannelName;
+    private final String myAlphaChannelName;
+
+    private FieldCalculator myProceduralTexture = null;
+    private RectangularAreaParameters myAreaParameters = null;
+
+    //======================================================================
+    // Public Methods
+
+    //----------------------------------------------------------------------
+    // Constructors
+
+    /**
+     * Creates a new FieldRenderer.
+     * Remember to set the procedural texture and the parameters before 
rendering.
+     */
+    public FieldRenderer()
+    {
+        this( null );
+    }
+
+
+    /**
+     * Creates a new FieldRenderer.
+     * Remember to set the parameters before rendering.
+     *
+     * @param proceduralTexture the calculator used to calculate the fields to 
render.
+     */
+    public FieldRenderer( final FieldCalculator proceduralTexture )
+    {
+        this( proceduralTexture, "red", "green", "blue", "alpha" );
+    }
+
+
+    /**
+     * Creates a new FieldRenderer.
+     * Remember to set the parameters before rendering.
+     *
+     * @param proceduralTexture the calculator used to calculate the fields to 
render.
+     * @param redChannelName    the name of the channel that should be used 
for the red component of the target image.
+     * @param greenChannelName  the name of the channel that should be used 
for the green component of the target image.
+     * @param blueChannelName   the name of the channel that should be used 
for the blue component of the target image.
+     * @param alphaChannelName  the name of the channel that should be used 
for the alpha component of the target image.
+     */
+    public FieldRenderer( final FieldCalculator proceduralTexture,
+                          final String redChannelName,
+                          final String greenChannelName,
+                          final String blueChannelName,
+                          final String alphaChannelName )
+    {
+        myProceduralTexture = proceduralTexture;
+
+        myRedChannelName = redChannelName;
+        myGreenChannelName = greenChannelName;
+        myBlueChannelName = blueChannelName;
+        myAlphaChannelName = alphaChannelName;
+
+        myField.addChannel( myRedChannelName );
+        myField.addChannel( myGreenChannelName );
+        myField.addChannel( myBlueChannelName );
+        myField.addChannel( myAlphaChannelName, 1.0f );
+    }
+
+    //----------------------------------------------------------------------
+    // Other Public Methods
+
+    /**
+     * @return the name of the channel that should be used for rendering the 
red channel of the image.
+     */
+    public String getRedChannelName()
+    {
+        return myRedChannelName;
+    }
+
+
+    /**
+     * @return the name of the channel that should be used for rendering the 
green channel of the image.
+     */
+    public String getGreenChannelName()
+    {
+        return myGreenChannelName;
+    }
+
+
+    /**
+     * @return the name of the channel that should be used for rendering the 
blue channel of the image.
+     */
+    public String getBlueChannelName()
+    {
+        return myBlueChannelName;
+    }
+
+
+    /**
+     * @return the name of the channel that should be used for rendering the 
alpha channel of the image.
+     */
+    public String getAlphaChannelName()
+    {
+        return myAlphaChannelName;
+    }
+
+
+    /**
+     * @return the calculator used to calculate the fields to render.
+     */
+    public FieldCalculator getProceduralTexture()
+    {
+        return myProceduralTexture;
+    }
+
+
+    /**
+     * @param proceduralTexture the calculator used to calculate the fields to 
render.
+     */
+    public void setProceduralTexture( final FieldCalculator proceduralTexture )
+    {
+        myProceduralTexture = proceduralTexture;
+    }
+
+
+    /**
+     * @return global parameters and parameters for the area to render.
+     */
+    public RectangularAreaParameters getAreaParameters()
+    {
+        return myAreaParameters;
+    }
+
+
+    /**
+     * @param areaParameters global parameters and parameters for the area to 
render.
+     */
+    public void setAreaParameters( final RectangularAreaParameters 
areaParameters )
+    {
+        myAreaParameters = areaParameters;
+    }
+
+
+    /**
+     * Calculates the field and renders it to the specified target.
+     *
+     * @param target the buffer to render the procedural exture to.
+     */
+    public void render( BufferedImage target )
+    {
+        if ( canRender( target ) )
+        {
+            resizeFieldIfNeeded( target );
+
+            myProceduralTexture.calculateField( myField, myAreaParameters );
+
+            ChannelUtils.renderChannelsToImage( target,
+                                                myField.getChannel( 
myRedChannelName ),
+                                                myField.getChannel( 
myGreenChannelName ),
+                                                myField.getChannel( 
myBlueChannelName ),
+                                                myField.getChannel( 
myAlphaChannelName ) );
+        }
+    }
+
+
+    /**
+     * Calculates the field and renders it to the specified target.
+     *
+     * @param target         the buffer to render the procedural exture to.
+     * @param areaParameters global parameters and parameters for the area to 
render.
+     */
+    public void render( BufferedImage target, RectangularAreaParameters 
areaParameters )
+    {
+        setAreaParameters( areaParameters );
+        render( target );
+    }
+
+
+    /**
+     * @return true if the render method will render something to the target.
+     */
+    public boolean canRender( BufferedImage target )
+    {
+        if ( target == null )
+        {
+            return false;
+        }
+
+        final int width = target.getWidth();
+        final int height = target.getHeight();
+
+        return width > 0 && height > 0 && myProceduralTexture != null && 
myAreaParameters != null;
+    }
+
+    //======================================================================
+    // Private Methods
+
+    private void resizeFieldIfNeeded( final BufferedImage target )
+    {
+        final int width = target.getWidth();
+        final int height = target.getHeight();
+        if ( myField.getXSize() != width || myField.getYSize() != height )
+        {
+            myField.resize( width, height );
+        }
+    }
+
+}


Property changes on: 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/FieldRenderer.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/ParameterSet.java
===================================================================
--- 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/ParameterSet.java
       2007-10-07 06:06:42 UTC (rev 229)
+++ 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/ParameterSet.java
       2007-10-07 06:08:38 UTC (rev 230)
@@ -58,4 +58,9 @@
      * Removes all parameters set in this parameter set, but doesn't affect 
the fallback parameter set.
      */
     void clear();
+
+    /**
+     * @return the names of the parameters present in this parameter set, in a 
new modifiable Set instance.
+     */
+    Set<String> getParameterNames();
 }

Modified: 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/ParameterSetImpl.java
===================================================================
--- 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/ParameterSetImpl.java
   2007-10-07 06:06:42 UTC (rev 229)
+++ 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/ParameterSetImpl.java
   2007-10-07 06:08:38 UTC (rev 230)
@@ -3,6 +3,7 @@
 import gnu.trove.TObjectDoubleHashMap;
 import gnu.trove.TObjectProcedure;
 
+import java.util.HashSet;
 import java.util.Set;
 
 /**
@@ -144,11 +145,22 @@
         }
     }
 
+
     public void clear()
     {
         myParameters.clear();
     }
 
+
+    public Set<String> getParameterNames()
+    {
+        final HashSet<String> names = new HashSet<String>();
+
+        collectParameterNames( names );
+
+        return names;
+    }
+
     //======================================================================
     // Private Methods
 

Modified: 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/ProceduralTextureView.java
===================================================================
--- 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/ProceduralTextureView.java
      2007-10-07 06:06:42 UTC (rev 229)
+++ 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/ProceduralTextureView.java
      2007-10-07 06:08:38 UTC (rev 230)
@@ -18,6 +18,8 @@
     //======================================================================
     // Private Fields
 
+    private final FieldRenderer myFieldRenderer = new FieldRenderer();
+
     private final ComponentListener myResizeListener = new ComponentListener()
     {
 
@@ -28,13 +30,10 @@
 
             if ( width > 0 && height > 0 )
             {
-                myField.resize( width, height );
-
                 myBuffer = new BufferedImage( width, height, IMAGE_TYPE );
             }
             else
             {
-                myField = null;
                 myBuffer = null;
             }
             repaint();
@@ -60,14 +59,8 @@
 
     };
 
-    private FieldCalculator myProceduralTexture;
-
-    private RectangularAreaParameters myAreaParameters;
-
     private BufferedImage myBuffer = null;
 
-    private Field myField = new FieldImpl( 10, 10 );
-
     //======================================================================
     // Private Constants
 
@@ -93,14 +86,9 @@
 
     public ProceduralTextureView( final FieldCalculator proceduralTexture, 
final RectangularAreaParameters areaParameters )
     {
-        myProceduralTexture = proceduralTexture;
-        myAreaParameters = areaParameters;
+        myFieldRenderer.setProceduralTexture( proceduralTexture );
+        myFieldRenderer.setAreaParameters( areaParameters );
 
-        myField.addChannel( "red" );
-        myField.addChannel( "green" );
-        myField.addChannel( "blue" );
-        myField.addChannel( "alpha", 1.0f );
-
         addComponentListener( myResizeListener );
     }
 
@@ -109,26 +97,27 @@
 
     public FieldCalculator getProceduralTexture()
     {
-        return myProceduralTexture;
+        return myFieldRenderer.getProceduralTexture();
     }
 
 
     public void setProceduralTexture( final FieldCalculator proceduralTexture )
     {
-        myProceduralTexture = proceduralTexture;
+        myFieldRenderer.setProceduralTexture( proceduralTexture );
+
         repaint();
     }
 
 
     public RectangularAreaParameters getAreaParameters()
     {
-        return myAreaParameters;
+        return myFieldRenderer.getAreaParameters();
     }
 
 
     public void setAreaParameters( final RectangularAreaParameters 
areaParameters )
     {
-        myAreaParameters = areaParameters;
+        myFieldRenderer.setAreaParameters( areaParameters );
         repaint();
     }
 
@@ -146,16 +135,10 @@
         graphics2D.fillRect( 0, 0, getWidth(), getHeight() );
 
         // Render texture
-        if ( myProceduralTexture != null && myBuffer != null && 
myAreaParameters != null )
+        if ( myFieldRenderer.canRender( myBuffer ) )
         {
-            myProceduralTexture.calculateField( myField, myAreaParameters );
+            myFieldRenderer.render( myBuffer );
 
-            ChannelUtils.renderChannelsToImage( myBuffer,
-                                                myField.getChannel( "red" ),
-                                                myField.getChannel( "green" ),
-                                                myField.getChannel( "blue" ),
-                                                myField.getChannel( "alpha" ) 
);
-
             // Copy rendered texture to view
             graphics2D.drawImage( myBuffer, 0, 0, null );
         }

Modified: 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/RectangularAreaParameters.java
===================================================================
--- 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/RectangularAreaParameters.java
  2007-10-07 06:06:42 UTC (rev 229)
+++ 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/RectangularAreaParameters.java
  2007-10-07 06:08:38 UTC (rev 230)
@@ -1,5 +1,7 @@
 package org.skycastle.texture;
 
+import java.util.Set;
+
 /**
  * Parameters for a rectangular area.  Meant to be interpolated over the area.
  */
@@ -27,4 +29,9 @@
      * Set the parameter values for the specified corner.
      */
     void setParameters( boolean startOfX, boolean startOfY, ParameterSet 
parameters );
+
+    /**
+     * @return a new modifiable Set with all the names of the parameters that 
are interpolated over the area.
+     */
+    Set<String> getInterpolatedParameterNames();
 }

Modified: 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/RectangularAreaParametersImpl.java
===================================================================
--- 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/RectangularAreaParametersImpl.java
      2007-10-07 06:06:42 UTC (rev 229)
+++ 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/RectangularAreaParametersImpl.java
      2007-10-07 06:08:38 UTC (rev 230)
@@ -1,5 +1,8 @@
 package org.skycastle.texture;
 
+import java.util.HashSet;
+import java.util.Set;
+
 /**
  *
  *
@@ -74,4 +77,21 @@
         myCorners[ y ][ x ] = parameters;
     }
 
+
+    public Set<String> getInterpolatedParameterNames()
+    {
+        final HashSet<String> names = new HashSet<String>();
+
+        for ( int y = 0; y < 2; y++ )
+        {
+            for ( int x = 0; x < 2; x++ )
+            {
+                final ParameterSet parameterSet = myCorners[ y ][ x ];
+                parameterSet.collectParameterNames( names );
+            }
+        }
+
+        return names;
+    }
+
 }

Modified: 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/component/AbstractComponent.java
===================================================================
--- 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/component/AbstractComponent.java
        2007-10-07 06:06:42 UTC (rev 229)
+++ 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/component/AbstractComponent.java
        2007-10-07 06:08:38 UTC (rev 230)
@@ -132,6 +132,7 @@
                                         PROCEDURAL_TEXTURE_PACKAGE_NAME,
                                         PROCEDURAL_TEXTURE_CLASS_NAME );
 
+        // DEBUG:
         System.out.println( "code = \n\n" + code );
 
         // Compile the code
@@ -194,6 +195,18 @@
         }
     }
 
+    public Set<String> getOutputPortNames()
+    {
+        final HashSet<String> names = new HashSet<String>();
+
+        for ( OutputPort outputPort : myOutputPorts )
+        {
+            names.add( outputPort.getName() );
+        }
+
+        return names;
+    }
+
     //----------------------------------------------------------------------
     // Other Public Methods
 

Modified: 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/component/Component.java
===================================================================
--- 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/component/Component.java
        2007-10-07 06:06:42 UTC (rev 229)
+++ 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/component/Component.java
        2007-10-07 06:08:38 UTC (rev 230)
@@ -27,6 +27,10 @@
  */
 public interface Component
 {
+
+    //======================================================================
+    // Public Methods
+
     /**
      * @return an user readable identifier for the component.
      *         The identifier must be a valid Java identifier,
@@ -109,4 +113,10 @@
      *                  or null if it should be removed from its 
CompositeComponent.
      */
     void setContainer( CompositeComponent container );
+
+    /**
+     * @return a new modifiable Set containing the names of all the output 
ports for this Component.
+     */
+    Set<String> getOutputPortNames();
+
 }

Added: 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/example/ComponentUiExample.java
===================================================================
--- 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/example/ComponentUiExample.java
                         (rev 0)
+++ 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/example/ComponentUiExample.java
 2007-10-07 06:08:38 UTC (rev 230)
@@ -0,0 +1,34 @@
+package org.skycastle.texture.example;
+
+import org.skycastle.texture.component.CompositeComponent;
+import org.skycastle.texture.component.ui.ComponentGraph;
+
+import javax.swing.*;
+
+/**
+ * An example of using a Component diagram to present a composition.
+ */
+public final class ComponentUiExample
+{
+
+    //======================================================================
+    // Public Methods
+
+    //----------------------------------------------------------------------
+    // Main Method
+
+    public static void main( String[] args )
+    {
+        final JFrame frame = new JFrame( "TextureExample" );
+
+        final CompositeComponent exampleComposition = 
ExampleDataCreator.createExampleComposition();
+
+        frame.add( new ComponentGraph( exampleComposition ).getView() );
+
+        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
+        frame.pack();
+
+        frame.setVisible( true );
+    }
+
+}


Property changes on: 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/example/ComponentUiExample.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/example/ExampleDataCreator.java
===================================================================
--- 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/example/ExampleDataCreator.java
                         (rev 0)
+++ 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/example/ExampleDataCreator.java
 2007-10-07 06:08:38 UTC (rev 230)
@@ -0,0 +1,155 @@
+package org.skycastle.texture.example;
+
+import org.skycastle.texture.ParameterSetImpl;
+import org.skycastle.texture.RectangularAreaParametersImpl;
+import org.skycastle.texture.component.CompositeComponent;
+import org.skycastle.texture.component.CompositeComponentImpl;
+import org.skycastle.texture.component.SinComponent;
+
+/**
+ * Utility methods for creating texture component related example data.
+ */
+public final class ExampleDataCreator
+{
+
+    //======================================================================
+    // Public Methods
+
+    //----------------------------------------------------------------------
+    // Static Methods
+
+    public static RectangularAreaParametersImpl createExampleParameters()
+    {
+        final ParameterSetImpl globalParameters = new ParameterSetImpl();
+        final ParameterSetImpl upperLeftParameters = new ParameterSetImpl();
+        final ParameterSetImpl upperRightParameters = new ParameterSetImpl();
+        final ParameterSetImpl lowerLeftParameters = new ParameterSetImpl();
+        final ParameterSetImpl lowerRightParameters = new ParameterSetImpl();
+
+        globalParameters.setValue( "scale", 20 );
+
+
+        upperLeftParameters.setValue( "head", 1 );
+        upperRightParameters.setValue( "head", 0 );
+        lowerLeftParameters.setValue( "head", 1 );
+        lowerRightParameters.setValue( "head", 0 );
+        upperLeftParameters.setValue( "front", 1 );
+        upperRightParameters.setValue( "front", 1 );
+        lowerLeftParameters.setValue( "front", 0 );
+        lowerRightParameters.setValue( "front", 0 );
+        upperLeftParameters.setValue( "left", 1 );
+        upperRightParameters.setValue( "left", 0 );
+        lowerLeftParameters.setValue( "left", 0 );
+        lowerRightParameters.setValue( "left", 0 );
+
+
+        final RectangularAreaParametersImpl areaParameters = new 
RectangularAreaParametersImpl( globalParameters,
+                                                                               
                 upperLeftParameters,
+                                                                               
                 upperRightParameters,
+                                                                               
                 lowerLeftParameters,
+                                                                               
                 lowerRightParameters );
+        return areaParameters;
+    }
+
+
+    public static CompositeComponent createExampleComposition()
+    {
+        final CompositeComponent exampleComposition = new 
CompositeComponentImpl( "exampleComposition" );
+
+        exampleComposition.addInputPort( Double.class, "head", 0.0 );
+        exampleComposition.addInputPort( Double.class, "front", 0.0 );
+        exampleComposition.addInputPort( Double.class, "left", 0.0 );
+        exampleComposition.addInputPort( Double.class, "spots", 0.0 );
+
+        exampleComposition.addOutputPort( Double.class, "red", 0.0 );
+        exampleComposition.addOutputPort( Double.class, "green", 0.0 );
+        exampleComposition.addOutputPort( Double.class, "blue", 0.0 );
+        exampleComposition.addOutputPort( Double.class, "alpha", 1.0 );
+
+        SinComponent wavy = new SinComponent( "wavy" );
+        exampleComposition.addComponent( wavy );
+        wavy.setInput( "signal", 
exampleComposition.getParameters().getOutputPort( "head" ) );
+        wavy.setInput( "amplitude", 1 );
+        wavy.setInput( "shift", 0 );
+        wavy.setInput( "scale", Math.PI * 8 * 4 );
+
+        SinComponent snaky = new SinComponent( "snaky" );
+        exampleComposition.addComponent( snaky );
+        snaky.setInput( "signal", 
exampleComposition.getParameters().getOutputPort( "left" ) );
+        snaky.setInput( "shift", wavy.getOutputPort( "result" ) );
+        snaky.setInput( "amplitude", 1 );
+        snaky.setInput( "scale", 100 );
+
+        SinComponent curly = new SinComponent( "curly" );
+        exampleComposition.addComponent( curly );
+        curly.setInput( "signal", snaky.getOutputPort( "result" ) );
+        curly.setInput( "shift", wavy.getOutputPort( "result" ) );
+        curly.setInput( "amplitude", 1 );
+        curly.setInput( "scale", 1.0 );
+
+        SinComponent gnarly = new SinComponent( "gnarly" );
+        exampleComposition.addComponent( gnarly );
+        gnarly.setInput( "signal", 
exampleComposition.getParameters().getOutputPort( "left" ) );
+        gnarly.setInput( "amplitude", 1 );
+        gnarly.setInput( "shift", curly.getOutputPort( "result" ) );
+        gnarly.setInput( "scale", 10 );
+
+        exampleComposition.getResults().setInput( "red", gnarly.getOutputPort( 
"result" ) );
+        exampleComposition.getResults().setInput( "green", 
snaky.getOutputPort( "result" ) );
+        exampleComposition.getResults().setInput( "blue", curly.getOutputPort( 
"result" ) );
+        exampleComposition.getResults().setInput( "alpha", 1 );
+        return exampleComposition;
+    }
+
+    /**
+     * @return an example composition using x and y as parameters, and red, 
green, blue, and alpha as outputs.
+     */
+    public static CompositeComponent createExampleComposition2()
+    {
+        final CompositeComponent exampleComposition = new 
CompositeComponentImpl( "exampleComposition" );
+
+        exampleComposition.addInputPort( Double.class, "x", 0.0 );
+        exampleComposition.addInputPort( Double.class, "y", 0.0 );
+
+        exampleComposition.addOutputPort( Double.class, "red", 0.0 );
+        exampleComposition.addOutputPort( Double.class, "green", 0.0 );
+        exampleComposition.addOutputPort( Double.class, "blue", 0.0 );
+        exampleComposition.addOutputPort( Double.class, "alpha", 1.0 );
+
+        SinComponent undulation = new SinComponent( "undulation" );
+        exampleComposition.addComponent( undulation );
+        undulation.setInput( "signal", 
exampleComposition.getParameters().getOutputPort( "x" ) );
+        undulation.setInput( "amplitude", 1 );
+        undulation.setInput( "shift", 
exampleComposition.getParameters().getOutputPort( "y" ) );
+        undulation.setInput( "scale", 1 );
+
+        SinComponent wavy = new SinComponent( "wavy" );
+        exampleComposition.addComponent( wavy );
+        wavy.setInput( "signal", 
exampleComposition.getParameters().getOutputPort( "x" ) );
+        wavy.setInput( "amplitude", undulation.getOutputPort( "result" ) );
+        wavy.setInput( "shift", 0 );
+        wavy.setInput( "scale", 0.001 );
+
+        SinComponent snaky = new SinComponent( "snaky" );
+        exampleComposition.addComponent( snaky );
+        snaky.setInput( "signal", 
exampleComposition.getParameters().getOutputPort( "y" ) );
+        snaky.setInput( "amplitude", undulation.getOutputPort( "result" ) );
+        snaky.setInput( "shift", 0 );
+        snaky.setInput( "scale", 0.001 );
+
+
+        exampleComposition.getResults().setInput( "red", wavy.getOutputPort( 
"result" ) );
+        exampleComposition.getResults().setInput( "green", 
snaky.getOutputPort( "result" ) );
+        exampleComposition.getResults().setInput( "blue", 
undulation.getOutputPort( "result" ) );
+        exampleComposition.getResults().setInput( "alpha", 1 );
+        return exampleComposition;
+    }
+
+    //======================================================================
+    // Private Methods
+
+    private ExampleDataCreator()
+    {
+    }
+
+}


Property changes on: 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/example/ExampleDataCreator.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Modified: 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/example/TextureExample.java
===================================================================
--- 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/example/TextureExample.java
     2007-10-07 06:06:42 UTC (rev 229)
+++ 
trunk/skycastle/modules/texture/src/main/java/org/skycastle/texture/example/TextureExample.java
     2007-10-07 06:08:38 UTC (rev 230)
@@ -1,23 +1,17 @@
 package org.skycastle.texture.example;
 
 import org.skycastle.texture.FieldCalculator;
-import org.skycastle.texture.ParameterSetImpl;
 import org.skycastle.texture.ProceduralTextureView;
 import org.skycastle.texture.RectangularAreaParametersImpl;
 import org.skycastle.texture.component.CompositeComponent;
-import org.skycastle.texture.component.CompositeComponentImpl;
-import org.skycastle.texture.component.SinComponent;
-import org.skycastle.texture.component.ui.ComponentGraph;
 
 import javax.swing.*;
 import java.awt.Dimension;
-import java.util.HashSet;
-import java.util.Set;
 
 /**
  * Demonstrates using procedural textures.
  */
-public class TextureExample
+public final class TextureExample
 {
 
     //======================================================================
@@ -30,166 +24,20 @@
     {
         final JFrame frame = new JFrame( "TextureExample" );
 
-        final ParameterSetImpl globalParameters = new ParameterSetImpl();
-        final ParameterSetImpl upperLeftParameters = new ParameterSetImpl();
-        final ParameterSetImpl upperRightParameters = new ParameterSetImpl();
-        final ParameterSetImpl lowerLeftParameters = new ParameterSetImpl();
-        final ParameterSetImpl lowerRightParameters = new ParameterSetImpl();
+        final RectangularAreaParametersImpl areaParameters = 
ExampleDataCreator.createExampleParameters();
+        final CompositeComponent exampleComposition = 
ExampleDataCreator.createExampleComposition();
 
-        globalParameters.setValue( "spots", 20 );
+        final FieldCalculator fieldCalculator = exampleComposition.compile( 
areaParameters.getGlobalParameters().getParameterNames(),
+                                                                            
areaParameters.getInterpolatedParameterNames(),
+                                                                            
exampleComposition.getOutputPortNames() );
 
-/*
-        upperLeftParameters.setValue( "signal", 10 );
-        upperRightParameters.setValue( "signal", 3 );
-        lowerLeftParameters.setValue( "signal", 7 );
-        lowerRightParameters.setValue( "signal", 0 );
-        upperLeftParameters.setValue( "amplitude", 2 );
-        upperRightParameters.setValue( "amplitude", 2 );
-        lowerLeftParameters.setValue( "amplitude", 0 );
-        lowerRightParameters.setValue( "amplitude", 0 );
-        upperLeftParameters.setValue( "shift", 1 );
-        upperRightParameters.setValue( "shift", 0 );
-        lowerLeftParameters.setValue( "shift", 2 );
-        lowerRightParameters.setValue( "shift", 3 );
-*/
-
-        upperLeftParameters.setValue( "head", 1 );
-        upperRightParameters.setValue( "head", 0 );
-        lowerLeftParameters.setValue( "head", 1 );
-        lowerRightParameters.setValue( "head", 0 );
-        upperLeftParameters.setValue( "front", 1 );
-        upperRightParameters.setValue( "front", 1 );
-        lowerLeftParameters.setValue( "front", 0 );
-        lowerRightParameters.setValue( "front", 0 );
-        upperLeftParameters.setValue( "left", 1 );
-        upperRightParameters.setValue( "left", 0 );
-        lowerLeftParameters.setValue( "left", 0 );
-        lowerRightParameters.setValue( "left", 0 );
-
-/*
-        final MultiFunction multiFunction = new MultiFunction()
-        {
-            public void calculateValues( final ParameterSet inputValues, final 
ParameterSet outputValues )
-            {
-                outputValues.setValue( "red", Math.random() );
-                outputValues.setValue( "green", Math.random() );
-                outputValues.setValue( "blue", Math.random() );
-                outputValues.setValue( "alpha", Math.random() );
-            }
-        };
-*/
-
-        final RectangularAreaParametersImpl areaParameters = new 
RectangularAreaParametersImpl( globalParameters,
-                                                                               
                 upperLeftParameters,
-                                                                               
                 upperRightParameters,
-                                                                               
                 lowerLeftParameters,
-                                                                               
                 lowerRightParameters );
-
-/*
-        // Create a simple design with just a sin
-        final SinComponent sinComponent = new SinComponent();
-        sinComponent.setName( "exampleSinWave" );
-        final Set<String> globalParametersSet = new HashSet<String>();
-        globalParametersSet.add( "scale" );
-        final Set<String> interpolatedParameters = new HashSet<String>();
-        interpolatedParameters.add( "signal" );
-        interpolatedParameters.add( "amplitude" );
-        interpolatedParameters.add( "shift" );
-        final Set<String> outputParameters = new HashSet<String>();
-        outputParameters.add( "red" );
-
-
-        final FieldCalculator fieldCalculator = sinComponent.compile( 
globalParametersSet,
-                                                                      
interpolatedParameters,
-                                                                      
outputParameters );
-*/
-
-        final CompositeComponent exampleComposition = new 
CompositeComponentImpl( "exampleComposition" );
-
-        exampleComposition.addInputPort( Double.class, "head", 0.0 );
-        exampleComposition.addInputPort( Double.class, "front", 0.0 );
-        exampleComposition.addInputPort( Double.class, "left", 0.0 );
-        exampleComposition.addInputPort( Double.class, "spots", 0.0 );
-
-        exampleComposition.addOutputPort( Double.class, "red", 0.0 );
-        exampleComposition.addOutputPort( Double.class, "green", 0.0 );
-        exampleComposition.addOutputPort( Double.class, "blue", 0.0 );
-        exampleComposition.addOutputPort( Double.class, "alpha", 1.0 );
-
-        SinComponent wavy = new SinComponent( "wavy" );
-        exampleComposition.addComponent( wavy );
-        wavy.setInput( "signal", 
exampleComposition.getParameters().getOutputPort( "head" ) );
-        wavy.setInput( "amplitude", 1 );
-        wavy.setInput( "shift", 0 );
-        wavy.setInput( "scale", Math.PI * 8 * 4 );
-
-        SinComponent snaky = new SinComponent( "snaky" );
-        exampleComposition.addComponent( snaky );
-        snaky.setInput( "signal", 
exampleComposition.getParameters().getOutputPort( "left" ) );
-        snaky.setInput( "shift", wavy.getOutputPort( "result" ) );
-        snaky.setInput( "amplitude", 1 );
-        snaky.setInput( "scale", 100 );
-
-        SinComponent curly = new SinComponent( "curly" );
-        exampleComposition.addComponent( curly );
-        curly.setInput( "signal", snaky.getOutputPort( "result" ) );
-        curly.setInput( "shift", wavy.getOutputPort( "result" ) );
-        curly.setInput( "amplitude", 1 );
-        curly.setInput( "scale", 1.0 );
-
-        SinComponent gnarly = new SinComponent( "gnarly" );
-        exampleComposition.addComponent( gnarly );
-        gnarly.setInput( "signal", 
exampleComposition.getParameters().getOutputPort( "left" ) );
-        gnarly.setInput( "amplitude", 1 );
-        gnarly.setInput( "shift", curly.getOutputPort( "result" ) );
-        gnarly.setInput( "scale", 10 );
-
-        exampleComposition.getResults().setInput( "red", gnarly.getOutputPort( 
"result" ) );
-        exampleComposition.getResults().setInput( "green", 
snaky.getOutputPort( "result" ) );
-        exampleComposition.getResults().setInput( "blue", curly.getOutputPort( 
"result" ) );
-        exampleComposition.getResults().setInput( "alpha", 1 );
-
-        final Set<String> globalParametersSet = new HashSet<String>();
-        globalParametersSet.add( "scale" );
-        final Set<String> interpolatedParameters = new HashSet<String>();
-        interpolatedParameters.add( "head" );
-        interpolatedParameters.add( "front" );
-        interpolatedParameters.add( "left" );
-        final Set<String> outputParameters = new HashSet<String>();
-        outputParameters.add( "red" );
-        outputParameters.add( "green" );
-        outputParameters.add( "blue" );
-        outputParameters.add( "alpha" );
-
-        final FieldCalculator fieldCalculator = exampleComposition.compile( 
globalParametersSet,
-                                                                            
interpolatedParameters,
-                                                                            
outputParameters );
-
         final ProceduralTextureView textureView = new ProceduralTextureView( 
fieldCalculator,
                                                                              
areaParameters );
-/*
-        final ProceduralTextureView textureView = new ProceduralTextureView( 
new PrototypeFieldCalculator(),
-                                                                             
areaParameters );
-*/
-/*
-        final ProceduralTextureView textureView = new ProceduralTextureView( 
new ProceduralTextureImpl( new SinComponent( ) ),
-                                                                             
globalParameters,
-                                                                             
upperLeftParameters,
-                                                                             
upperRightParameters,
-                                                                             
lowerLeftParameters,
-                                                                             
lowerRightParameters );
-*/
-
-/*
+        textureView.setPreferredSize( new Dimension( 800, 600 ) );
         frame.add( textureView );
-*/
 
-        frame.add( new ComponentGraph( exampleComposition ).getView() );
-
         frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
-        textureView.setPreferredSize( new Dimension( 800, 600 ) );
         frame.pack();
-
         frame.setVisible( true );
     }
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

Other related posts:

  • » [skycastle-commits] SF.net SVN: skycastle: [230] trunk/skycastle/modules/texture/src/main/java/ org/skycastle/texture