Ejemplo n.º 1
0
        public GrassPatchSceneNode(SceneNode parent, SceneManager mgr, int id, bool createIfEmpty,
                                   Vector3D gridPos, string filepath, Texture heightMap, Texture colourMap,
                                   Texture grassMap, SceneNode terrain, WindGenerator wind)
            : base(parent, mgr, id)
        {
            DrawDistance = GRASS_PATCH_SIZE * 1.5f;
            MaxDensity = 800;
            TerrainHeightMap = heightMap;
            TerrainColourMap = colourMap;
            TerrainGrassMap = grassMap;
            Terrain = terrain;
            WindGen = wind;
            lastwindtime = 0;
            lastdrawcount = 0;
            redrawnextloop = true;
            MaxFPS = 0;
            _mgr = mgr;
            WindRes = 5;

            filename = string.Format("{0}/{1}.{2}.grass", filepath, gridpos.X, gridpos.Z);
            gridpos = gridPos;
            Position = new Vector3D(gridpos.X * GRASS_PATCH_SIZE, 0f,
                                    gridpos.Z * GRASS_PATCH_SIZE);

            ImageCount = new Dimension2D(4, 2);

            if (!Load())
                Create(createIfEmpty);
        }
Ejemplo n.º 2
0
        protected internal override void OnRender(RenderEventArgs e)
        {
            e.Canvas.Color = mvarForegroundColor;
            e.Canvas.Translate(0, 12);
            double x = 0, y = 0;

            switch (mvarHorizontalAlignment)
            {
            case Caltron.HorizontalAlignment.Center:
            {
                Dimension2D dim = e.Canvas.MeasureText(base.Text);
                x = ((Size.Width + dim.Width) / 2);
                break;
            }

            case Caltron.HorizontalAlignment.Right:
            {
                Dimension2D dim = e.Canvas.MeasureText(base.Text);
                x = (Size.Width - dim.Width);
                break;
            }
            }
            e.Canvas.DrawText(base.Text, x, y);
            e.Canvas.Translate(0, -12);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates and adds specified number of feature maps to this layer
 /// </summary>
 /// <param name="mapCount">         number of feature maps to create </param>
 /// <param name="dimensions">       feature map dimensions </param>
 /// <param name="neuronProperties"> properties of neurons in feature maps </param>
 protected internal void createFeatureMaps(int mapCount, Dimension2D mapDimensions, Dimension2D kernelDimension, NeuronProperties neuronProperties)
 {
     for (int i = 0; i < mapCount; i++)
     {
         addFeatureMap(new FeatureMapLayer(mapDimensions, neuronProperties, kernelDimension));
     }
 }
Ejemplo n.º 4
0
 public LayerVisialize(FeatureMapsLayer featureMapsLayer)
 {
     this.layerMaps        = new List <>();
     this.featureMapsLayer = featureMapsLayer;
     this.mapDimensions    = featureMapsLayer.MapDimensions;
     initWeights();
 }
Ejemplo n.º 5
0
 private void createFeatureMaps(int mapCount, Dimension2D mapDimensions, NeuronProperties neuronProperties)
 {
     for (int i = 0; i < mapCount; i++)
     {
         addFeatureMap(new FeatureMapLayer(mapDimensions, neuronProperties));
     }
 }
Ejemplo n.º 6
0
        public ProcessingResult <ICroppedArea> ExtractRegionOfInterestFrom(ICroppedArea areaOfExtraction)
        {
            using (areaOfExtraction)
            {
                List <OrderedBitmap> extractedRegionsOfInterest = new List <OrderedBitmap>();

                foreach (var areaPart in areaOfExtraction.CroppedParts)
                {
                    var partBytes = areaPart.Bitmap.AsFlattenedByteArray();

                    var leftEdge   = GetLeftEdgeOfRegionOfInterest(partBytes);
                    var rightEdge  = GetRightEdgeOfRegionOfInterest(partBytes);
                    var topEdge    = GetTopEdgeOfRegionOfInterest(partBytes);
                    var bottomEdge = GetBottomEdgeOfRegionOfInterest(partBytes);

                    if (leftEdge == null || rightEdge == null || topEdge == null || bottomEdge == null ||
                        (bottomEdge.Value - topEdge.Value) < 10)
                    {
                        //Nothing interesting - return empty result
                        extractedRegionsOfInterest.Add(new OrderedBitmap(areaPart.Order, null));
                        continue;
                    }

                    var size = new Dimension2D(rightEdge.Value - leftEdge.Value + 1, bottomEdge.Value - topEdge.Value + 1)
                               .GetInputSizeAsMultipliesOfFour().AsSize();

                    var croppedBitmap = new Crop(new Rectangle(new Point(leftEdge.Value, topEdge.Value), size)).Apply(areaPart.Bitmap);

                    extractedRegionsOfInterest.Add(new OrderedBitmap(areaPart.Order, croppedBitmap));
                }

                return(ProcessingResult <ICroppedArea> .Success(
                           new CroppedArea(areaOfExtraction.AreaUsedForCropping, extractedRegionsOfInterest, areaOfExtraction.DocumentId)));
            }
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Creates new feature maps layer with specified kernel and feature maps.
 /// Also creates feature maps and neurons in feature maps;
 /// </summary>
 /// <param name="kernel">        kernel used for all feature maps in this layer </param>
 /// <param name="mapDimensions"> mapDimensions of feature maps in this layer </param>
 /// <param name="mapCount">      number of feature maps </param>
 /// <param name="neuronProp">    properties for neurons in feature maps </param>
 public FeatureMapsLayer(Dimension2D kernelDimension, Dimension2D mapDimensions, int mapCount, NeuronProperties neuronProp)
 {
     // this.kernel = kernel;
     this.mapDimensions = mapDimensions;
     this.featureMaps   = new List <FeatureMapLayer>();
     createFeatureMaps(mapCount, mapDimensions, kernelDimension, neuronProp);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates 2D layer with specified dimensions, filled with neurons with
 /// specified properties
 /// </summary>
 /// <param name="dimensions">       layer dimensions </param>
 /// <param name="neuronProperties"> neuron properties </param>
 public FeatureMapLayer(Dimension2D dimensions, NeuronProperties neuronProperties, Dimension2D kernelDimension) : this(dimensions, kernelDimension)
 {
     for (int i = 0; i < dimensions.Height * dimensions.Width; i++)
     {
         Neuron neuron = NeuronFactory.createNeuron(neuronProperties);
         addNeuron(neuron);
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Creates an empty 2D layer with specified dimensions
        /// </summary>
        /// <param name="dimensions"> layer dimensions (width and weight) </param>
        public FeatureMapLayer(Dimension2D dimensions, NeuronProperties neuronProperties)
        {
            this.dimensions = dimensions;

            for (int i = 0; i < dimensions.Height * dimensions.Width; i++)
            {
                Neuron neuron = NeuronFactory.createNeuron(neuronProperties);
                addNeuron(neuron);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Creates convolutional layer with specified kernel, and appropriate map
        /// dimensions in regard to previous layer - fromLayer param
        /// </summary>
        /// <param name="fromLayer"> previous layer, which will be connected to this layer </param>
        /// <param name="kernel"> kernel for all feature maps in this layer </param>
        //    public ConvolutionalLayer(FeatureMapsLayer fromLayer, Kernel kernel) {
        //        Dimension2D fromDimension = fromLayer.getMapDimensions();
        //        int mapWidth = fromDimension.getWidth() - (kernel.getWidth() - 1);
        //        int mapHeight = fromDimension.getHeight() - (kernel.getHeight() - 1);
        //        this.mapDimensions = new Dimension2D(mapWidth, mapHeight);
        //
        //        createFeatureMaps(1, this.mapDimensions, ConvolutionalLayer.DEFAULT_NEURON_PROP);
        //    }

        /// <summary>
        /// Creates convolutional layer with specified kernel, appropriate map
        /// dimensions in regard to previous layer (fromLayer param) and specified
        /// number of feature maps with default neuron settings for convolutional
        /// layer.
        /// </summary>
        /// <param name="fromLayer"> previous layer, which will be connected to this layer </param>
        /// <param name="kernel"> kernel for all feature maps </param>
        /// <param name="numberOfMaps"> number of feature maps to create in this layer </param>
        public ConvolutionalLayer(FeatureMapsLayer fromLayer, Dimension2D kernelDimension, int numberOfMaps)
        {
            Dimension2D fromDimension = fromLayer.MapDimensions;

            int mapWidth  = fromDimension.Width - kernelDimension.Width + 1;
            int mapHeight = fromDimension.Height - kernelDimension.Height + 1;

            this.mapDimensions = new Dimension2D(mapWidth, mapHeight);

            createFeatureMaps(numberOfMaps, this.mapDimensions, kernelDimension, ConvolutionalLayer.DEFAULT_NEURON_PROP);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Creates convolutional layer with specified kernel, appropriate map
        /// dimensions in regard to previous layer (fromLayer param) and specified
        /// number of feature maps with given neuron properties.
        /// </summary>
        /// <param name="fromLayer"> previous layer, which will be connected to this layer </param>
        /// <param name="kernel"> kernel for all feature maps </param>
        /// <param name="numberOfMaps"> number of feature maps to create in this layer </param>
        /// <param name="neuronProp"> settings for neurons in feature maps </param>
        public ConvolutionalLayer(FeatureMapsLayer fromLayer, Dimension2D kernelDimension, int numberOfMaps, NeuronProperties neuronProp)
        {
            Dimension2D fromDimension = fromLayer.MapDimensions;

            int mapWidth  = fromDimension.Width - kernelDimension.Width + 1;
            int mapHeight = fromDimension.Height - kernelDimension.Height + 1;

            this.mapDimensions = new Dimension2D(mapWidth, mapHeight);

            createFeatureMaps(numberOfMaps, this.mapDimensions, kernelDimension, neuronProp);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates pooling layer with specified kernel, appropriate map
        /// dimensions in regard to previous layer (fromLayer param) and specified
        /// number of feature maps with given neuron properties.
        /// </summary>
        /// <param name="fromLayer">    previous layer, which will be connected to this layer </param>
        /// <param name="kernel">       kernel for all feature maps </param>
        /// <param name="numberOfMaps"> number of feature maps to create in this layer </param>
        /// <param name="neuronProp">   settings for neurons in feature maps </param>
        public PoolingLayer(FeatureMapsLayer fromLayer, Dimension2D kernelDim, int numberOfMaps, NeuronProperties neuronProp)
        {
            this.kernel = kernel;
            Dimension2D fromDimension = fromLayer.MapDimensions;

            int mapWidth  = fromDimension.Width / kernel.Width;
            int mapHeight = fromDimension.Height / kernel.Height;

            this.mapDimensions = new Dimension2D(mapWidth, mapHeight);

            createFeatureMaps(numberOfMaps, mapDimensions, kernelDim, neuronProp);
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Equals
 /// </summary>
 /// <param name="obj">object</param>
 /// <returns></returns>
 public new  bool Equals(object obj)
 {
     if (obj != null && obj is Dimension2D)
     {
         Dimension2D d = (Dimension2D)obj;
         if (d.getWidth() == width && d.getHeight() == height)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates pooling layer with specified kernel, appropriate map
        /// dimensions in regard to previous layer (fromLayer param) and specified
        /// number of feature maps with default neuron settings for pooling layer.
        /// Number of maps in pooling layer must be the same as number of maps in previous
        /// layer.
        /// </summary>
        /// <param name="fromLayer"> previous layer, which will be connected to this layer </param>
        /// <param name="kernel">    kernel for all feature maps </param>
        public PoolingLayer(FeatureMapsLayer fromLayer, Dimension2D kernelDim)
        {
            this.kernel = new Kernel(kernelDim);
            int         numberOfMaps  = fromLayer.NumberOfMaps;
            Dimension2D fromDimension = fromLayer.MapDimensions;

            int mapWidth  = fromDimension.Width / kernel.Width;
            int mapHeight = fromDimension.Height / kernel.Height;

            this.mapDimensions = new Dimension2D(mapWidth, mapHeight);

            createFeatureMaps(numberOfMaps, mapDimensions, kernelDim, DEFAULT_NEURON_PROP);
        }
Ejemplo n.º 15
0
        public WaterSceneNode(SceneNode parent, SceneManager mgr, Dimension2Df tileSize,
                              Dimension2D tileCount, Dimension2D precision, int id) :
            base(parent, mgr, id)
        {
            _scene = mgr;
            _driver = mgr.VideoDriver;

            AnimatedMesh wmesh = _scene.AddHillPlaneMesh("watermesh" + _current,
                tileSize,
                tileCount, 0,
                new Dimension2Df(0, 0),
                new Dimension2Df(1, 1));
            _current++;

            int dmat;
            if (_driver.DriverType == DriverType.OpenGL)
                dmat = _driver.GPUProgrammingServices.AddHighLevelShaderMaterial(
                 WATER_VERTEX_GLSL, "main", VertexShaderType._1_1, WATER_FRAGMENT_GLSL,
                 "main", PixelShaderType._1_1, OnShaderSet, MaterialType.TransparentAlphaChannel, 0);
            else
                dmat = _driver.GPUProgrammingServices.AddHighLevelShaderMaterial(
                 WATER_HLSL, "vertexMain", VertexShaderType._2_0, WATER_HLSL,
                 "pixelMain", PixelShaderType._2_0, OnShaderSet, MaterialType.TransparentAlphaChannel, 2);

            if (_driver.DriverType == DriverType.OpenGL)
                ClampShader = _driver.GPUProgrammingServices.AddHighLevelShaderMaterial(
                 CLAMP_VERTEX_GLSL, "main", VertexShaderType._1_1, CLAMP_FRAGMENT_GLSL,
                 "main", PixelShaderType._1_1, OnShaderSet, MaterialType.TransparentAlphaChannel, 1);
            else
                ClampShader = _driver.GPUProgrammingServices.AddHighLevelShaderMaterial(
                 CLAMP_HLSL, "vertexMain", VertexShaderType._2_0, CLAMP_HLSL,
                 "pixelMain", PixelShaderType._2_0, OnShaderSet, MaterialType.TransparentAlphaChannel, 3);

            _waternode = _scene.AddMeshSceneNode(wmesh.GetMesh(0), this, -1);
            _waternode.SetMaterialType(dmat);
            _waternode.SetMaterialFlag(MaterialFlag.BackFaceCulling, false);
            _waternode.SetMaterialFlag(MaterialFlag.Lighting, false);
            _waternode.SetMaterialFlag(MaterialFlag.FogEnable, false);

            _rt = _driver.CreateRenderTargetTexture(precision);
            _waternode.SetMaterialTexture(0, _rt);

            CameraSceneNode oldcam = _scene.ActiveCamera;
            _fixedcam = _scene.AddCameraSceneNode(null);
            if (oldcam != null)
                _scene.ActiveCamera = oldcam;
        }
Ejemplo n.º 16
0
        public static void testLearningOneLayer()
        {
            Dimension2D inputDimension = new Dimension2D(5, 5);

            Dimension2D convolutionKernel = new Dimension2D(3, 3);

            ConvolutionalNetwork convolutionNet = (new ConvolutionalNetwork.Builder()).withInputLayer(5, 5, 1).withConvolutionLayer(3, 3, 2).withFullConnectedLayer(2).build();


            // CREATE DATA SET

            DataSet dataSet = new DataSet(25, 2);

            dataSet.addRow(new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, new double[] { 1, 0 });
            dataSet.addRow(new double[] { 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0 }, new double[] { 0, 1 });

            // TRAIN NETWORK

            convolutionNet.LearningRule.MaxError = 0.00001;
            convolutionNet.learn(dataSet);

            Console.WriteLine("Done training!");

            FeatureMapLayer featureMap1 = ((FeatureMapsLayer)convolutionNet.getLayerAt(1)).getFeatureMap(0);
            FeatureMapLayer featureMap2 = ((FeatureMapsLayer)convolutionNet.getLayerAt(1)).getFeatureMap(1);

            //        WeightVisualiser visualiser1 = new WeightVisualiser(featureMap1, convolutionKernel);
            //        visualiser1.displayWeights();
            //
            //        WeightVisualiser visualiser2 = new WeightVisualiser(featureMap2, convolutionKernel);
            //        visualiser2.displayWeights();


            // CREATE TEST SET

            DataSet testSet = new DataSet(25, 2);

            testSet.addRow(new double[] { 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, new double[] { 1, 0 });
            testSet.addRow(new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }, new double[] { 1, 0 });
            testSet.addRow(new double[] { 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0 }, new double[] { 0, 1 });
        }
Ejemplo n.º 17
0
        /// <param name="args"> Command line parameters used to initialize parameters of convolutional network
        ///             [0] - maximal number of epochs during learning
        ///             [1] - learning error stop condition
        ///             [2] - learning rate used during learning process
        ///             [3] - number of feature maps in 1st convolutional layer
        ///             [4] - number of feature maps in 2nd convolutional layer
        ///             [5] - number of feature maps in 3rd convolutional layer </param>
        public static void Main(string[] args)
        {
            try
            {
                int    maxIter      = 10000;         // Integer.parseInt(args[0]);
                double maxError     = 0.01;          //Double.parseDouble(args[1]);
                double learningRate = 0.2;           //  Double.parseDouble(args[2]);

                int layer1 = Convert.ToInt32(args[3]);
                int layer2 = Convert.ToInt32(args[4]);
                int layer3 = Convert.ToInt32(args[5]);

                LOG.info("{}-{}-{}", layer1, layer2, layer3);

                DataSet trainSet = MNISTDataSet.createFromFile(MNISTDataSet.TRAIN_LABEL_NAME, MNISTDataSet.TRAIN_IMAGE_NAME, 100);
                DataSet testSet  = MNISTDataSet.createFromFile(MNISTDataSet.TEST_LABEL_NAME, MNISTDataSet.TEST_IMAGE_NAME, 10000);

                Dimension2D inputDimension    = new Dimension2D(32, 32);
                Dimension2D convolutionKernel = new Dimension2D(5, 5);
                Dimension2D poolingKernel     = new Dimension2D(2, 2);

                ConvolutionalNetwork convolutionNetwork = (new ConvolutionalNetwork.Builder()).withInputLayer(32, 32, 1).withConvolutionLayer(5, 5, layer1).withPoolingLayer(2, 2).withConvolutionLayer(5, 5, layer2).withPoolingLayer(2, 2).withConvolutionLayer(5, 5, layer3).withFullConnectedLayer(10).build();

                ConvolutionalBackpropagation backPropagation = new ConvolutionalBackpropagation();
                backPropagation.LearningRate  = learningRate;
                backPropagation.MaxError      = maxError;
                backPropagation.MaxIterations = maxIter;
                backPropagation.addListener(new LearningListener(convolutionNetwork, testSet));
                backPropagation.ErrorFunction = new MeanSquaredError();

                convolutionNetwork.LearningRule = backPropagation;
                convolutionNetwork.learn(trainSet);

                Evaluation.runFullEvaluation(convolutionNetwork, testSet);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
        }
Ejemplo n.º 18
0
        protected internal override void OnRender(RenderEventArgs e)
        {
            e.Canvas.Color = Colors.Silver; // mvarBackgroundColor;
            e.Canvas.FillRectangle(0, 0, Size.Width, Size.Height);
            if (mvarPressed)
            {
                e.Canvas.DrawSunkenBorder(0, 0, Size.Width, Size.Height, 2);
            }
            else
            {
                e.Canvas.DrawRaisedBorder(0, 0, Size.Width, Size.Height, 2);
            }

            e.Canvas.Color = mvarForegroundColor;
            double      x = 0, y = 0;
            Dimension2D dim = e.Canvas.MeasureText(base.Text);

            x = ((Size.Width - dim.Width) / 2);
            y = ((Size.Height - dim.Height) / 2) + 12;
            e.Canvas.DrawText(Text, x, y);
        }
        public bool InitDevices(Control target_window)
        {
            _target_window = target_window;


            Dimension2D dim = new Dimension2D(target_window.Size.Width, target_window.Size.Height);

            _device = new IrrlichtDevice(DriverType.OpenGL,
                                         dim,
                                         32, false, false, false,
                                         false, target_window.Handle);

            _device.Resizeable = true;

            //_device.OnEvent += new OnEventDelegate(_device_OnEvent);

            _scene  = _device.SceneManager;
            _driver = _device.VideoDriver;

            return(true);
        }
Ejemplo n.º 20
0
        public static void DrawLine(Color color, Position2D start, Dimension2D tSize)
        {
            OGLTools.glDisable(Gl.GL_TEXTURE_2D);
            OGLTools.glEnable(Gl.GL_ALPHA);
            Gl.glEnable(Gl.GL_BLEND);
            Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
            Gl.glColor4f(1.0f, 1.0f, 1.0f, 1f);

            Gl.glPushMatrix();
            Gl.glTranslated(start.X, start.Y, 0);

            float x1, y1;


            Gl.glBegin(Gl.GL_LINES);
            Gl.glColor3f(color.R / 255, color.G / 255, color.B / 255);
            Gl.glVertex2f(0f, 0f);
            Gl.glColor3f(color.R / 255, color.G / 255, color.B / 255);
            Gl.glVertex2f(tSize.Width, tSize.Height);
            Gl.glEnd();

            // disable blending
            glDisable(Gl.GL_BLEND);
            OGLTools.glDisable(Gl.GL_ALPHA);

            Gl.glPopMatrix(); // Need to optimize this like glPopMatrix(sessionID);

        }
 public FlattenedBitmap(int width, int height, int stride, byte[,] data)
 {
     Dimension = new Dimension2D(width, height);
     Stride    = stride;
     Data      = data;
 }
Ejemplo n.º 22
0
        public static void DrawTexture(OGLTexture txt, Position2D texturePosition, Dimension2D textureSize, Position2D targetPosition, Dimension2D targetSize, float Alpha)
        {
            /*if ((targetPosition.X < 0) || (targetPosition.X >= oGL.Width))
                return;
            if ((targetPosition.Y < 0) || (targetPosition.Y >= oGL.Height))
                return;
            if ((targetPosition.X + targetSize.Width < 0) || (targetPosition.X + targetSize.Width >= oGL.Width))
                return;
            if ((targetPosition.Y + targetSize.Height < 0) || (targetPosition.Y + targetSize.Height >= oGL.Height))
                return;*/
            glEnable2D();
            glEnable(Gl.GL_ALPHA);
            OGLTools.glEnable(Gl.GL_TEXTURE_2D);
            Gl.glEnable(Gl.GL_BLEND);
            Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
            Gl.glColor4f(1.0f, 1.0f, 1.0f, Alpha);

            Gl.glPushMatrix();
            Gl.glTranslated(targetPosition.X, targetPosition.Y, 0);

            if (m_CurrentTextureID != (int)txt.TextureId)
            {
                m_CurrentTextureID = (int)txt.TextureId;

                Gl.glBindTexture(Gl.GL_TEXTURE_2D, m_CurrentTextureID);
            }

            float x1, y1;


            Gl.glBegin(Gl.GL_QUADS);

            // Extract bottom left position
            //x1 = (1.0f / (float)txt.Size.Width * (float)texturePosition.X) - txt.Size.GetFloatingX(textureSize.Width - txt.Size.Width);
            //y1 = (1.0f / (float)txt.Size.Height * (float)texturePosition.Y) - txt.Size.GetFloatingY(textureSize.Width - txt.Size.Height);
            x1 = 1 / (float)txt.Size.Width * (float)texturePosition.X;
            y1 = 1 / (float)txt.Size.Height * (float)texturePosition.Y;
            Gl.glTexCoord2f(x1, y1 * -1);
            Gl.glVertex2i(0, 0);

            // Extract bottom right
            //x1 = (1.0f / (float)txt.Size.Width * (float)texturePosition.X) - txt.Size.GetFloatingX(textureSize.Width);
            //y1 = (1.0f / (float)txt.Size.Height * (float)texturePosition.Y) - txt.Size.GetFloatingY(textureSize.Height - txt.Size.Height);
            x1 = 1 / (float)txt.Size.Width * ((float)texturePosition.X + (float)textureSize.Width);
            y1 = 1 / (float)txt.Size.Height * (float)texturePosition.Y;
            Gl.glTexCoord2f(x1, y1 * -1);
            Gl.glVertex2i(targetSize.Width, 0);
            // Extract top right
            //x1 = (1.0f / (float)txt.Size.Width * (float)texturePosition.X) - txt.Size.GetFloatingX(textureSize.Width);
            //y1 = (1.0f / (float)txt.Size.Height * (float)texturePosition.Y) - txt.Size.GetFloatingY(textureSize.Height);
            x1 = 1 / (float)txt.Size.Width * ((float)texturePosition.X + (float)textureSize.Width);
            y1 = 1 / (float)txt.Size.Height * ((float)texturePosition.Y + (float)textureSize.Height);
            Gl.glTexCoord2f(x1, y1 * -1);
            Gl.glVertex2i(targetSize.Width, targetSize.Height);
            // Extract top left position
            //x1 = (1.0f / (float)txt.Size.Width * (float)texturePosition.X) - txt.Size.GetFloatingX(textureSize.Width - txt.Size.Width);
            //y1 = (1.0f / (float)txt.Size.Height * (float)texturePosition.Y) - txt.Size.GetFloatingY(textureSize.Height);
            x1 = 1 / (float)txt.Size.Width * (float)texturePosition.X;
            y1 = 1 / (float)txt.Size.Height * ((float)texturePosition.Y + (float)textureSize.Height);
            Gl.glTexCoord2f(x1, y1 * -1);
            Gl.glVertex2i(0, targetSize.Height + 0);
            Gl.glEnd();

            // disable blending
            glDisable(Gl.GL_BLEND);

            Gl.glPopMatrix(); // Need to optimize this like glPopMatrix(sessionID);
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Creates an empty 2D layer with specified dimensions and kernel
 /// </summary>
 /// <param name="dimensions"> layer dimensions (width and weight) </param>
 public FeatureMapLayer(Dimension2D dimensions, Dimension2D kernelDimension)
 {
     this.dimensions = dimensions;
     this.kernel     = new Kernel(kernelDimension);
 }
Ejemplo n.º 24
0
        public static void DrawFilledRectangle(Color color, Position2D start, Dimension2D size)
        {
            OGLTools.glDisable(Gl.GL_TEXTURE_2D);
            OGLTools.glEnable(Gl.GL_ALPHA);
            Gl.glEnable(Gl.GL_BLEND);
            Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA);
            Gl.glColor4f(1.0f, 1.0f, 1.0f, 1f);

            Gl.glPushMatrix();
            Gl.glTranslated(start.X, start.Y, 0);

            float x1, y1;
            /*
            Gl.glBegin(Gl.GL_QUADS);
            Gl.glColor3f((float)color.R / 255f, (float)color.G / 255f, (float)color.B / 255f);
            Gl.glVertex2f(0f, 0f);
            Gl.glVertex2f(0, size.Height);
            Gl.glVertex2f(size.Width, size.Height);
            Gl.glVertex2f(size.Width, 0);
            Gl.glVertex2f(0f, 0f);
            Gl.glEnd();
            */
            float[] Vertices = new float[] { 0, 0, 0, (float)size.Height, (float)size.Width, (float)size.Height, (float)size.Width, 0, 0, 0 };
            float[] Indices = { 0, 1, 2, 3, 4 };
             
            
            
            //Load the arrays 
            Gl.glColor3f((float)color.R / 255f, (float)color.G / 255f, (float)color.B / 255f);
            Gl.glEnableClientState(Gl.GL_VERTEX_ARRAY);
            Gl.glVertexPointer(2, Gl.GL_FLOAT, 0, Vertices);
            Gl.glDrawArrays(Gl.GL_QUADS, 0, Indices.Length);
            Gl.glDisableClientState(Gl.GL_VERTEX_ARRAY);

            // disable blending
            glDisable(Gl.GL_BLEND);
            OGLTools.glDisable(Gl.GL_ALPHA);                
            


            Gl.glPopMatrix(); // Need to optimize this like glPopMatrix(sessionID);

        }
Ejemplo n.º 25
0
        public static void DrawTexture(OGLTexture txt, Position2D texturePosition, Dimension2D textureSize, Position2D srcPosition, Position2D targetPosition, float Alpha)
        {
            Dimension2D tSize = new Dimension2D(targetPosition.X - srcPosition.X, targetPosition.Y - srcPosition.Y);
            
            DrawTexture(txt, texturePosition, textureSize, srcPosition, tSize, Alpha);

        }
Ejemplo n.º 26
0
 public void SetControlMinimumSize(Control ctl, Dimension2D minimumSize)
 {
     mvarMinimumSizes[ctl] = minimumSize;
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Creates a new empty feature maps layer with specified kernel and
 /// feature map dimensions.
 /// </summary>
 /// <param name="kernel">        kernel used for all feature maps in this layer </param>
 /// <param name="mapDimensions"> mapDimensions of feature maps in this layer </param>
 public FeatureMapsLayer(Dimension2D mapDimensions)         //Kernel kernel,
 {
     //     this.kernel = kernel;
     this.mapDimensions = mapDimensions;
     this.featureMaps   = new List <FeatureMapLayer>();
 }
Ejemplo n.º 28
0
    //xy should be the normalized coordinates in UV space, this function then returns the UV coordinates in pixel coordinates
    Vector2 DecodeUV(Vector2 xy)
    {
        Texture t = _renderer.sharedMaterial.GetTexture("_MainTex");
        Dimension2D wh = new Dimension2D(t.width,t.height);

        return new Vector2(xy.x * wh.width, xy.y * wh.height);
    }
Ejemplo n.º 29
0
 public Rect(Position2D pos, Dimension2D size)
 {
     UpperLeftCorner = new Position2D();
     LowerRightCorner = new Position2D();
     Set(pos, size);
 }
Ejemplo n.º 30
0
    //accepts the pixel coordinates of the
    Vector2 CalcUV(Vector2 xy)
    {
        Texture t = _renderer.sharedMaterial.GetTexture("_MainTex");
        Dimension2D wh = new Dimension2D(t.width,t.height);

        return new Vector2(xy.x / wh.width, (wh.height - xy.y) / wh.height);
    }
Ejemplo n.º 31
0
 void Awake()
 {
     CacheComponents();
     _dimensions = new Vector2(_meshFilter.mesh.bounds.size.x, _meshFilter.mesh.bounds.size.y);
 }
Ejemplo n.º 32
0
 public void Set(Position2D pos, Dimension2D size)
 {
     UpperLeftCorner = pos;
     LowerRightCorner = new Position2D(pos.X + size.Width, pos.Y + size.Height);
 }
Ejemplo n.º 33
0
 /// <summary>
 /// Create InputMapsLayer with specified number of maps with specified dimensions </summary>
 /// <param name="mapDimension"> dimensions of a single feature map </param>
 /// <param name="mapCount">  number of feature maps </param>
 public InputMapsLayer(Dimension2D mapDimensions, int mapCount) : base(mapDimensions, mapCount, InputMapsLayer.DEFAULT_NEURON_PROP)
 {
 }
Ejemplo n.º 34
0
 public Dimension2D GetDimensionsForResizeBeforeCentering(Dimension2D inputSizeAsMultiplesOfFour)
 {
     return(new Dimension2D(
                (int)Math.Ceiling(inputSizeAsMultiplesOfFour.Width / ((double)inputSizeAsMultiplesOfFour.Height / ExpectedSize2D.Height)),
                ExpectedSize2D.Height));
 }
Ejemplo n.º 35
0
 public WaterSceneNode(SceneNode parent, SceneManager mgr, Dimension2Df tileSize, Dimension2D tileCount) :
     this(parent, mgr, tileSize, tileCount, new Dimension2D(256, 256), -1)
 { }
Ejemplo n.º 36
0
 public WaterSceneNode(SceneNode parent, SceneManager mgr, Dimension2Df tileSize, Dimension2D tileCount, Dimension2D precision) :
     this(parent, mgr, tileSize, tileCount, precision, -1)
 { }