public void FindNextBox()
    {
        box next = null;

        Debug.Log(boxes.Count);

        if (boxes.Count > 0)
        {
            foreach (GameObject g in boxes)
            {
                if ((next == null || g.GetComponent <box>().GetTimeUnformatted() < next.GetTimeUnformatted()) && g.GetComponent <box>().GetTimeUnformatted() != 0)
                {
                    next = g.GetComponent <box>();
                }
            }

            if (next != null)
            {
                Debug.Log(next.GetTimeUnformatted() + " < " + this.GetTimeUnformatted());
                if (next.GetTimeUnformatted() < this.GetTimeUnformatted())
                {
                    currentExport = next.gameObject;
                    et.setTruck(next.GetComponent <SpriteRenderer>().color, currentExport.GetComponent <box>().ToString());
                }
            }
        }
    }
Example #2
0
    public static void Main(String[] args)
    {
        box b1 = new box(1, 2, 3);
        box b2 = new box(1, 7, 9);
        box b3 = new box();

        b3 = b1 + b2;

        Console.WriteLine("l=" + b3.l);
        Console.WriteLine("h=" + b3.h);
        Console.WriteLine("b=" + b3.b);
        Console.WriteLine("enter age");
        int age = Convert.ToInt32(Console.ReadLine());

        try
        {
            if (age < 0)
            {
                throw(new cutex("enter proper age"));
            }
            else
            {
                Console.WriteLine("okk good!!");
            }
        }
        catch (cutex e)
        {
            Console.WriteLine(e.Message);
        }

        Console.ReadKey();
    }
Example #3
0
            public SiteInfoResponseType GetSitesInBox(
                float west, float south, float east, float north,
                Boolean IncludeSeries
                )
            {
                Stopwatch timer = System.Diagnostics.Stopwatch.StartNew();

                box queryBox = new box(west, south, east, north);

                queryLog2.LogStart(CustomLogging.Methods.GetSitesInBoxObject, queryBox.ToString(),
                                   appContext.Request.UserHostName);

                SiteInfoResponseType resp = new SiteInfoResponseType();

                resp.site = WebServiceUtils.GetSitesByBox(queryBox, IncludeSeries);

                //set query info
                resp.queryInfo = CuahsiBuilder.CreateQueryInfoType("GetSitesInBox");
                NoteType note = CuahsiBuilder.createNote("box");

                resp.queryInfo.note = CuahsiBuilder.addNote(null, note);

                queryLog2.LogEnd(CustomLogging.Methods.GetSitesInBoxObject,
                                 queryBox.ToString(),
                                 timer.ElapsedMilliseconds.ToString(),
                                 resp.site.Length.ToString(),
                                 appContext.Request.UserHostName);
                return(resp);
            }
    public void ShowBox(box _box)
    {
        connectWindow.SetActive(false);
        nicknameWindow.SetActive(false);
        lobbyWindow.SetActive(false);
        connectAlert.SetActive(false);
        disconectWindow.SetActive(false);

        switch (_box)
        {
        case box.ip:
            connectWindow.SetActive(true);
            break;

        case box.name:
            nicknameWindow.SetActive(true);
            break;

        case box.lobby:
            lobbyWindow.SetActive(true);
            break;

        case box.connect:
            connectAlert.SetActive(true);
            break;
        }
    }
Example #5
0
    /// <summary>
    /// Calculate wall porints from normal
    /// </summary>
    /// <param name="box1">box definition</param>
    /// <param name="normal">wall normal</param>
    /// <returns></returns>
    Pair <Vector3, Vector3> calcWallPointsFromNormal(box box1, Vector3 normal)
    {
        Pair <Vector3, Vector3> line = new Pair <Vector3, Vector3>();

        if (normal == z_positive)
        {
            line.find_line(new Vector3(box1.xmin, 0, box1.zmax), new Vector3(box1.xmax, 0, box1.zmax));
            return(line);
        }
        else if (normal == z_negative)
        {
            line.find_line(new Vector3(box1.xmin, 0, box1.zmin), new Vector3(box1.xmax, 0, box1.zmin));
            return(line);
        }
        else if (normal == x_positive)
        {
            line.find_line(new Vector3(box1.xmax, 0, box1.zmin), new Vector3(box1.xmax, 0, box1.zmax));
            return(line);
        }
        else
        {
            line.find_line(new Vector3(box1.xmin, 0, box1.zmin), new Vector3(box1.xmin, 0, box1.zmax));
            return(line);
        }
    }
Example #6
0
        private void button_mibai_Click(object sender, EventArgs e)
        {
            if (curItem_id == 0)
            {
                return;
            }
            privItem_id = curItem_id;
            var context = new DBClassDataContext(Globals.ConnectionString);

            if (curItem_id < 90000)
            {
                item curItem = context.item.Single(n => n.item_id == curItem_id);
                privItemSellPrice      = curItem.item_sellprice;
                privItemSellTime       = curItem.item_selltime;
                privItemSellOperatorId = curItem.item_sell_operator;
                curItem.item_sellprice = null;
                curItem.item_selltime  = null;
            }
            else
            {
                box curBox   = context.box.Single(n => n.box_id == (curItem_id - 90000));
                var curItems = (from n in context.item
                                where n.item_box_id == curBox.box_id
                                select n).ToList();
                foreach (var q in curItems)
                {
                    q.item_sellprice = null;
                    q.item_selltime  = null;
                }
            }

            context.SubmitChanges();

            this.textBox_ban_err("次の品番を入力してね");
        }
Example #7
0
        public async Task <IActionResult> Edit(int id, [Bind("box_id,box_name,box_row,box_column,box_createddate")] box box)
        {
            if (id != box.box_id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(box);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!boxExists(box.box_id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(box));
        }
            public static siteInfoDataSet GetSiteInfoDataSet(box geomBox)
            {
                siteInfoDataSet ds = CreateBaseSiteInfoDataset();

                GetSiteInfoDataSet(geomBox, ds);
                return(ds);
            }
Example #9
0
    public static void Prim(box box, Color color, float duration = 0)
    {
        var size  = box.size;
        var axisX = mul(box.rotation, float3(1, 0, 0)) * size.x;
        var axisY = mul(box.rotation, float3(0, 1, 0)) * size.y;
        var axisZ = mul(box.rotation, float3(0, 0, 1)) * size.z;

        var A = box.center + (axisX + axisY + axisZ) * 0.5f;
        var B = A - axisY;
        var C = B - axisZ;
        var D = C + axisY;

        var E = A - axisX;
        var F = B - axisX;
        var G = C - axisX;
        var H = D - axisX;

        Debug.DrawLine(A, B, color, duration);
        Debug.DrawLine(B, C, color, duration);
        Debug.DrawLine(C, D, color, duration);
        Debug.DrawLine(D, A, color, duration);

        Debug.DrawLine(E, F, color, duration);
        Debug.DrawLine(F, G, color, duration);
        Debug.DrawLine(G, H, color, duration);
        Debug.DrawLine(H, E, color, duration);

        Debug.DrawLine(A, E, color, duration);
        Debug.DrawLine(B, F, color, duration);
        Debug.DrawLine(C, G, color, duration);
        Debug.DrawLine(H, D, color, duration);
    }
Example #10
0
        public static siteInfoDataSet GetSiteInfoDataSet(locationParam[] LocationParameters)
        {
            siteInfoDataSet ds = new siteInfoDataSet();

            SpatialReferencesTableAdapter spatialTableAdapter =
                new SpatialReferencesTableAdapter();
            sitesTableAdapter sitesTableAdapter = new sitesTableAdapter();

            spatialTableAdapter.Connection.ConnectionString = Config.ODDB();
            sitesTableAdapter.Connection.ConnectionString   = Config.ODDB();

            try
            {
                spatialTableAdapter.Fill(ds.SpatialReferences);
            }
            catch (Exception e)
            {
                log.Fatal("Cannot connect to database " + e.Message); //+ spatialTableAdapter.Connection.DataSource
                throw new WaterOneFlowServerException(e.Message);
            }
            if (LocationParameters[0].isGeometry)
            {
                if (LocationParameters[0].Geometry.GetType().Equals(typeof(box)))
                {
                    box queryBox = (box)LocationParameters[0].Geometry;
                    sitesTableAdapter.FillByBox(ds.sites,
                                                queryBox.South, queryBox.North, queryBox.West, queryBox.East);
                }
            }
            else
            {
                siteInfoDataSet.sitesDataTable aSitetable = new siteInfoDataSet.sitesDataTable();

                foreach (locationParam s in LocationParameters)
                {
                    try
                    {
                        if (s.IsId)
                        {
                            int siteID = int.Parse(s.SiteCode);
                            sitesTableAdapter.FillBySiteID(aSitetable, siteID);
                        }
                        else
                        {
                            sitesTableAdapter.FillBySiteCode(aSitetable, s.SiteCode);
                        }
                        ds.sites.Merge(aSitetable);
                    }
                    catch (Exception e)
                    {
                        log.Fatal("Cannot connect to database " + e.Message); //+ sitesTableAdapter.Connection.DataSource
                        throw new WaterOneFlowServerException(e.Message);
                    }
                }
            }

            return(ds);
        }
Example #11
0
    public void Start()
    {
        //Pull variables from RobotControllerScript
        GameObject           robot       = GameObject.Find("robot 1");
        RobotControllerSript robotScript = robot.GetComponent <RobotControllerSript>();

        //Pull Variables from box script
        GameObject box       = GameObject.Find("testCrate");
        box        boxScript = box.GetComponent <box> ();

        //Pull variables from trigger script
        GameObject trigger       = GameObject.Find("switch_1");
        trigger    triggerScript = trigger.GetComponent <trigger> ();

        //Pull variables from RobotUP Script
        GameObject up       = GameObject.Find("robot_1");
        RobotUP    upScript = up.GetComponent <RobotUP> ();

        //Begin Tests 1
        //Test the character is alive when level is loaded
        Assertions.Equals(robotScript.dead, false);

        //Test the character is facing right when level is loaded
        Assertions.Equals(robotScript.facingRight, true);

        //Test ground check is working
        Assertions.Equals(robotScript.groundCheck, true);
        //End Tests 1

        //Begin Test 2
        //Test gravity is set properly
        Assertions.Equals(grav, Physics2D.gravity);

        //Test variable tacking gravity is set correctly
        Assertions.Equals(robotScript.jumpdir, 1);
        //End Test 2

        //Begin Test 3
        //Test that Finish is set to false as level is loaded
        Assertions.Equals(boxScript.finish, false);
        //End Test 3

        //Begin Test 4
        //Test the correct animation is set
        Assertions.Equals(triggerScript.doorOpen, "doorOpen");

        //Test that the door is closed when level is loaded
        Assertions.Equals(triggerScript.isOpen, false);
        //End Test 4

        //Begin Test 5
        //Test that gravity is initialized properly
        Assertions.Equals(grav2, Physics2D.gravity);

        //Test gravity variable is set
        Assertions.Equals(upScript.jumpdir, 0);
        //End Test 5
    }
            public static box operator+(box a, box b) //operator + oveloading
            {
                box c = new box();                    // to sign data in

                c.l = a.l + b.l;
                c.w = a.w + b.w;  // we add the width from both objects and sign it to the Var. in the new object
                c.h = a.h + b.h;
                return(c);
            }
Example #13
0
    public static box operator +(box a, box b)
    {
        box b3 = new box();

        b3.l = a.l + b.l;
        b3.h = a.h + b.h;
        b3.b = a.b + b.b;
        return(b3);
    }
Example #14
0
        public static bool OverlapCapsuleAABB(capsule capsule, box AABB)
        {
            var closestOnCapsule = ClosestPointOnLineSegment(capsule.p1, capsule.p2, AABB.center);

            float  sqDist;
            float3 closestInBox;

            CalculateClosestPointInBox(closestOnCapsule, AABB, out closestInBox, out sqDist);
            return(math.sqrt(sqDist) < capsule.radius);
        }
Example #15
0
    void Start()
    {
        bplay    = new box(play);
        boptions = new box(options);
        bquit    = new box(quit);
        cam      = Camera.main;
        DontDestroyOnLoad(cam.gameObject);

        //asc = Application.LoadLevelAsync(4);
        //asc.allowSceneActivation = false;
    }
Example #16
0
        public async Task <IActionResult> Create([Bind("box_id,box_name,box_row,box_column,box_createddate")] box box)
        {
            if (ModelState.IsValid)
            {
                _context.Add(box);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(box));
        }
Example #17
0
        public static void ReadyForSend(byte[] Message)
        {
            box temp = new box();

            temp.Message = Message;
            queue.Enqueue(temp);
            if (!isRun)
            {
                RunThread = new Thread(new ThreadStart(run));
                RunThread.Start();
            }
        }
        public IActionResult Create(box box, IFormFile image, string returnUrl = null)
        {
            if (ModelState.IsValid)
            {
                this.repository.AddEntity(box, image);
                return(RedirectToLocal(returnUrl));
            }

            ViewData["ParentId"]  = box.boxCategoryId;
            ViewData["ReturnUrl"] = returnUrl;
            return(View(box));
        }
Example #19
0
    static void Main(string[] args)
    {
        double length = double.Parse(Console.ReadLine());
        double width  = double.Parse(Console.ReadLine());
        double height = double.Parse(Console.ReadLine());

        box box = new box(length, width, height);

        Console.WriteLine(box.Getarea());
        Console.WriteLine(box.GetLaterArea());
        Console.WriteLine(box.GetVolume());
    }
        public List <Line> ComputeVoronoi3d(List <Line> x, List <Point3d> y)
        {
            box hu = new box(x);

            hull[] hulls = new hull[y.Count];

            /*
             *    for (int ii = 0;ii < y.Count;ii++){
             *      hull h = new hull(hu, y[ii]);
             *      for(int i = 0;i < y.Count;i++){
             *        if( i != ii && y[i].DistanceTo(y[ii]) < h.R * 2){
             *          Point3d cen = new Point3d(y[ii]);cen += y[i];cen /= 2;
             *          Vector3d v = y[ii] - y[i];
             *          Plane plane = new Plane(cen, v);
             *          h.intersect(plane);}
             *      }
             *      hulls.Add(h);
             *    }
             */
            ///*
            //  System.Threading.Tasks.Parallel.ForEach(y, pt =>
            // {
            System.Threading.Tasks.Parallel.For(0, y.Count, (iii) =>
            {
                Point3d pt = y[iii];
                hull h     = new hull(hu, pt);
                for (int i = 0; i < y.Count; i++)
                {
                    double t = y[i].DistanceTo(pt);
                    if (t > 0.001 && t < h.R * 2)
                    {
                        Point3d cen = new Point3d(pt); cen += y[i]; cen /= 2;
                        Vector3d v  = pt - y[i];
                        Plane plane = new Plane(cen, v);
                        h.intersect(plane);
                    }
                }
                hulls[iii] = h;
            });
            //  */
            List <Line> tree = new List <Line>();

            for (int k = 0; k < hulls.Length; k++)
            {
                hull h = hulls[k];
                for (int i = 0; i < h.edges.Count; i++)
                {
                    tree.Add(new Line(h.edges[i].p1.pos, h.edges[i].p2.pos));
                }
            }
            return(tree);
        }
Example #21
0
    void OnCollisionEnter(Collision collisionInfo)
    {
        box b = collisionInfo.gameObject.GetComponent <box>();

        if (b != null && isOwner && b.OwnerID != -1 && (b.isOwner || players[b.OwnerID].team != team || dm) &&
            !(b is Player) && !(b is Zombie) &&
            collisionInfo.rigidbody.velocity.magnitude > 20
            //&& rigidbody.velocity.magnitude < collisionInfo.rigidbody.velocity.magnitude
            )
        {
            RPCSetLife(-(int)collisionInfo.rigidbody.velocity.magnitude * 2, b.OwnerID);
        }
    }
Example #22
0
        public void Click()
        {
            box currentlySelectedBox = (box)MainWindow.currentlySelectedObject;

            if (!mySelections.Contains(currentlySelectedBox))
            {
                SelectBox(currentlySelectedBox);
            }
            else
            {
                unSelectBox(currentlySelectedBox);
            }
        }
 public hull(box hu, Point3d cen)
 {
     this.center = new Point3d(cen);
     this.pts    = new List <vertex>();
     this.edges  = new List <edge>();
     for (int i = 0; i < hu.pts.Count; i++)
     {
         this.pts.Add(new vertex(hu.pts[i], this.center.DistanceTo(hu.pts[i])));
     }
     for (int i = 0; i < hu.lp1.Count; i++)
     {
         this.edges.Add(new edge(pts[hu.lp1[i]], pts[hu.lp2[i]]));
     }
 }
Example #24
0
        public void Click()
        {
            box currentlySelectedBox = (box)MainWindow.currentlySelectedObject;

            if (!Boxes.Contains(currentlySelectedBox))
            {
                SelectBox(currentlySelectedBox);
                tutorialIndex = currentlySelectedBox.index;
            }
            else
            {
                unSelectBox(currentlySelectedBox);
            }
        }
Example #25
0
 public List<Line> ComputeVoronoi3d(List<Line> x, List<Point3d> y)
 {
     box hu = new box(x);
     hull[] hulls = new hull[y.Count];
     /*
           for (int ii = 0;ii < y.Count;ii++){
             hull h = new hull(hu, y[ii]);
             for(int i = 0;i < y.Count;i++){
               if( i != ii && y[i].DistanceTo(y[ii]) < h.R * 2){
                 Point3d cen = new Point3d(y[ii]);cen += y[i];cen /= 2;
                 Vector3d v = y[ii] - y[i];
                 Plane plane = new Plane(cen, v);
                 h.intersect(plane);}
             }
             hulls.Add(h);
           }
     */
     ///*
     //  System.Threading.Tasks.Parallel.ForEach(y, pt =>
     // {
     System.Threading.Tasks.Parallel.For(0, y.Count, (iii) =>
          {
              Point3d pt = y[iii];
              hull h = new hull(hu, pt);
              for (int i = 0; i < y.Count; i++)
              {
                  double t = y[i].DistanceTo(pt);
                  if (t > 0.001 && t < h.R * 2)
                  {
                      Point3d cen = new Point3d(pt); cen += y[i]; cen /= 2;
                      Vector3d v = pt - y[i];
                      Plane plane = new Plane(cen, v);
                      h.intersect(plane);
                  }
              }
              hulls[iii] = h;
          });
     //  */
     List<Line> tree = new List<Line>();
     for (int k = 0; k < hulls.Length; k++)
     {
         hull h = hulls[k];
         for (int i = 0; i < h.edges.Count; i++)
         {
             tree.Add(new Line(h.edges[i].p1.pos, h.edges[i].p2.pos));
         }
     }
     return tree;
 }
Example #26
0
        public void SelectBox(box Box)
        {
            Box.highlightBox();
            bool tooMuch = Boxes.Count >= 1;

            if (tooMuch)
            {
                unSelectBox(Boxes[0]);
                Boxes.Add(Box);
            }
            else
            {
                Boxes.Add(Box);
            }
        }
        public IActionResult Edit(int id, box box, IFormFile image, string returnUrl = null)
        {
            if (id != box.id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                box = (box)this.repository.UpdateEntity(box, image);
                return(RedirectToLocal(returnUrl));
            }
            ViewData["ReturnUrl"] = returnUrl;
            return(View(box));
        }
Example #28
0
            public SiteInfoResponseType GetSitesByBox(box queryBox, Boolean includeSeries)
            {
                IEnumerable <SiteInfoType> sites  = ODSiteInfo.GetSitesByBox(queryBox);
                SiteInfoResponseType       result = CreateSitesResponse(sites, includeSeries);

                // result.queryInfo = CreateQueryInfo(new string[] { queryBox.ToString() });
                result.queryInfo = CuahsiBuilder.CreateQueryInfoType("GetSitesByBox");
                CuahsiBuilder.AddQueryInfoParameter(result.queryInfo, "north", queryBox.North.ToString());
                CuahsiBuilder.AddQueryInfoParameter(result.queryInfo, "south", queryBox.South.ToString());
                CuahsiBuilder.AddQueryInfoParameter(result.queryInfo, "east", queryBox.East.ToString());
                CuahsiBuilder.AddQueryInfoParameter(result.queryInfo, "west", queryBox.West.ToString());
                CuahsiBuilder.AddQueryInfoParameter(result.queryInfo, "includeSeries", includeSeries.ToString());

                return(result);
            }
Example #29
0
        public void SelectBox(box Box)
        {
            Box.highlightBox();
            bool tooMuch = (_type == "Solo" && mySelections.Count >= 3) || (_type == "Buddy" && mySelections.Count >= 1);

            if (tooMuch)
            {
                unSelectBox(mySelections[0]);
                mySelections.Add(Box);
            }
            else
            {
                mySelections.Add(Box);
            }
        }
Example #30
0
    static void Main()
    {
        //create box object and use setters
        box mybox = new box();

        mybox.setHeight(4);
        mybox.setLength(3);
        mybox.setWidth(2);
        //use getters
        Console.WriteLine(mybox.getHeight());
        Console.WriteLine(mybox.getLength());
        Console.WriteLine(mybox.getWidth());
        Console.WriteLine(mybox.calcVolume());
        Console.ReadLine();
    }
Example #31
0
        /// <summary>
        /// An SQL where clause for an ODM sites table
        /// </summary>
        /// <param name="geom"></param>
        /// <param name="tableName"></param>
        /// <returns></returns>

        public static String GeomToSqlWhere(basicGeometry geom, string tableName)
        {
            if (geom.GetType().Equals(typeof(box)))
            {
                box    queryBox  = (box)geom;
                string sqlClause = string.Format(boxSqlFormat,
                                                 tableName, queryBox.South, queryBox.North,
                                                 queryBox.West, queryBox.East);
                return(sqlClause);
            }
            else
            {
                throw new WaterOneFlowException("Only Box is understood at this time");
            }
        }
Example #32
0
 private static int CompareDinosByLength(box x, box y)
 {
     if (x == null) { if (y == null) { return 0; } else { return -1; } }
     else
     {
         if (y == null) { return 1; }
         else
         {
             if (x.area > y.area) return 1;
             if (x.area == y.area) return 0;
             if (x.area < y.area) return -1;
             else return 0;
         }
     }
 }
            public SiteInfoResponseType GetSitesByBox(box queryBox, Boolean includeSeries)
            {
                IEnumerable<SiteInfoType> sites = ODSiteInfo.GetSitesByBox(queryBox);
                SiteInfoResponseType result = CreateSitesResponse(sites, includeSeries);

                   // result.queryInfo = CreateQueryInfo(new string[] { queryBox.ToString() });
                result.queryInfo = CuahsiBuilder.CreateQueryInfoType("GetSitesByBox");
                  CuahsiBuilder.AddQueryInfoParameter(result.queryInfo, "north", queryBox.North.ToString());
                CuahsiBuilder.AddQueryInfoParameter(result.queryInfo,"south", queryBox.South.ToString());
                CuahsiBuilder.AddQueryInfoParameter(result.queryInfo,"east", queryBox.East.ToString());
                   CuahsiBuilder.AddQueryInfoParameter(result.queryInfo,"west", queryBox.West.ToString());
                CuahsiBuilder.AddQueryInfoParameter(result.queryInfo,"includeSeries", includeSeries.ToString());

                return result;
            }
Example #34
0
        /// <summary>
        /// Find the splittable box with the largest (scaled) volume
        /// Returns null if no splittable boxes remain
        /// </summary>
        private static int find_biggest_volume(box[] boxlist, int numboxes)
        {
            int maxv = 0;
            int which = -1;
            for (int i = 0; i < numboxes; i++)
            {
                if (boxlist[i].volume > maxv)
                {
                    which = i;
                    maxv = boxlist[i].volume;
                }
            }

            return which;
        }
Example #35
0
        /// <summary>
        /// Repeatedly select and split the largest box until we have enough boxes
        /// </summary>
        private int median_cut(box[] boxlist, int numboxes, int desired_colors)
        {
            while (numboxes < desired_colors)
            {
                /* Select box to split.
                 * Current algorithm: by population for first half, then by volume.
                 */
                int foundIndex;
                if (numboxes * 2 <= desired_colors)
                    foundIndex = find_biggest_color_pop(boxlist, numboxes);
                else
                    foundIndex = find_biggest_volume(boxlist, numboxes);

                if (foundIndex == -1)     /* no splittable boxes left! */
                    break;

                /* Copy the color bounds to the new box. */
                boxlist[numboxes].c0max = boxlist[foundIndex].c0max;
                boxlist[numboxes].c1max = boxlist[foundIndex].c1max;
                boxlist[numboxes].c2max = boxlist[foundIndex].c2max;
                boxlist[numboxes].c0min = boxlist[foundIndex].c0min;
                boxlist[numboxes].c1min = boxlist[foundIndex].c1min;
                boxlist[numboxes].c2min = boxlist[foundIndex].c2min;

                /* Choose which axis to split the box on.
                 * Current algorithm: longest scaled axis.
                 * See notes in update_box about scaling distances.
                 */
                int c0 = ((boxlist[foundIndex].c0max - boxlist[foundIndex].c0min) << C0_SHIFT) * R_SCALE;
                int c1 = ((boxlist[foundIndex].c1max - boxlist[foundIndex].c1min) << C1_SHIFT) * G_SCALE;
                int c2 = ((boxlist[foundIndex].c2max - boxlist[foundIndex].c2min) << C2_SHIFT) * B_SCALE;

                /* We want to break any ties in favor of green, then red, blue last.
                 * This code does the right thing for R,G,B or B,G,R color orders only.
                 */
                int cmax = c1;
                int n = 1;

                if (c0 > cmax)
                {
                    cmax = c0;
                    n = 0;
                }

                if (c2 > cmax)
                {
                    n = 2;
                }

                /* Choose split point along selected axis, and update box bounds.
                 * Current algorithm: split at halfway point.
                 * (Since the box has been shrunk to minimum volume,
                 * any split will produce two nonempty subboxes.)
                 * Note that lb value is max for lower box, so must be < old max.
                 */
                int lb;
                switch (n)
                {
                    case 0:
                        lb = (boxlist[foundIndex].c0max + boxlist[foundIndex].c0min) / 2;
                        boxlist[foundIndex].c0max = lb;
                        boxlist[numboxes].c0min = lb + 1;
                        break;
                    case 1:
                        lb = (boxlist[foundIndex].c1max + boxlist[foundIndex].c1min) / 2;
                        boxlist[foundIndex].c1max = lb;
                        boxlist[numboxes].c1min = lb + 1;
                        break;
                    case 2:
                        lb = (boxlist[foundIndex].c2max + boxlist[foundIndex].c2min) / 2;
                        boxlist[foundIndex].c2max = lb;
                        boxlist[numboxes].c2min = lb + 1;
                        break;
                }

                /* Update stats for boxes */
                update_box(boxlist, foundIndex);
                update_box(boxlist, numboxes);
                numboxes++;
            }

            return numboxes;
        }
Example #36
0
        /// <summary>
        /// Compute representative color for a box, put it in colormap[icolor]
        /// </summary>
        private void compute_color(box[] boxlist, int boxIndex, int icolor)
        {
            /* Current algorithm: mean weighted by pixels (not colors) */
            /* Note it is important to get the rounding correct! */
            long total = 0;
            long c0total = 0;
            long c1total = 0;
            long c2total = 0;
            box curBox = boxlist[boxIndex];
            for (int c0 = curBox.c0min; c0 <= curBox.c0max; c0++)
            {
                for (int c1 = curBox.c1min; c1 <= curBox.c1max; c1++)
                {
                    int histogramIndex = c1 * HIST_C2_ELEMS + curBox.c2min;
                    for (int c2 = curBox.c2min; c2 <= curBox.c2max; c2++)
                    {
                        long count = m_histogram[c0][histogramIndex];
                        histogramIndex++;

                        if (count != 0)
                        {
                            total += count;
                            c0total += ((c0 << C0_SHIFT) + ((1 << C0_SHIFT) >> 1)) * count;
                            c1total += ((c1 << C1_SHIFT) + ((1 << C1_SHIFT) >> 1)) * count;
                            c2total += ((c2 << C2_SHIFT) + ((1 << C2_SHIFT) >> 1)) * count;
                        }
                    }
                }
            }

            m_cinfo.m_colormap[0][icolor] = (byte)((c0total + (total >> 1)) / total);
            m_cinfo.m_colormap[1][icolor] = (byte)((c1total + (total >> 1)) / total);
            m_cinfo.m_colormap[2][icolor] = (byte)((c2total + (total >> 1)) / total);
        }
Example #37
0
        /// <summary>
        /// Gets the sites, in XML format [test for SNOW]
        /// </summary>
        public static SiteInfoResponseTypeSite[] GetSitesByBox(box queryBox, bool includeSeries)
        {
            List<SiteInfoResponseTypeSite> siteList = new List<SiteInfoResponseTypeSite>();

            string cnn = GetConnectionString();
            string serviceCode = ConfigurationManager.AppSettings["network"];

            using (SqlConnection conn = new SqlConnection(cnn))
            {
                using (SqlCommand cmd = new SqlCommand())
                {
                    string sqlSites = "SELECT plaveninycz.Stations.st_id, st_name, altitude, location_id, lat, lon FROM plaveninycz.Stations INNER JOIN StationsVariables stv ON Stations.st_id = stv.st_id " +
                    "WHERE var_id in (1, 4, 5, 16) AND lat IS NOT NULL";

                    cmd.CommandText = sqlSites;
                    cmd.Connection = conn;
                    conn.Open();
                    SqlDataReader dr = cmd.ExecuteReader();

                    while (dr.Read())
                    {
                        SiteInfoResponseTypeSite newSite = new SiteInfoResponseTypeSite();
                        SiteInfoType si = new SiteInfoType();

                        if (dr["altitude"] != DBNull.Value)
                        {
                            si.elevation_m = Convert.ToDouble(dr["altitude"]);
                            si.elevation_mSpecified = true;
                        }
                        else
                        {
                            si.elevation_m = 0;
                            si.elevation_mSpecified = true;
                        }
                        si.geoLocation = new SiteInfoTypeGeoLocation();

                        LatLonPointType latLon = new LatLonPointType();
                        latLon.latitude = Convert.ToDouble(dr["Lat"]);
                        latLon.longitude = Convert.ToDouble(dr["lon"]);
                        latLon.srs = "EPSG:4326";
                        si.geoLocation.geogLocation = latLon;
                        si.geoLocation.localSiteXY = new SiteInfoTypeGeoLocationLocalSiteXY[1];
                        si.geoLocation.localSiteXY[0] = new SiteInfoTypeGeoLocationLocalSiteXY();
                        si.geoLocation.localSiteXY[0].X = latLon.longitude;
                        si.geoLocation.localSiteXY[0].Y = latLon.latitude;
                        si.geoLocation.localSiteXY[0].ZSpecified = false;
                        si.geoLocation.localSiteXY[0].projectionInformation = si.geoLocation.geogLocation.srs;
                        si.metadataTimeSpecified = false;
                        si.verticalDatum = "Unknown";

                        si.siteCode = new SiteInfoTypeSiteCode[1];
                        si.siteCode[0] = new SiteInfoTypeSiteCode();
                        si.siteCode[0].network = serviceCode;
                        si.siteCode[0].siteID = Convert.ToInt32(dr["st_id"]);
                        si.siteCode[0].siteIDSpecified = true;
                        si.siteCode[0].Value = Convert.ToString(dr["st_id"]);

                        si.siteName = Convert.ToString(dr["st_name"]);

                        newSite.siteInfo = si;
                        siteList.Add(newSite);
                    }
                }
            }
            return siteList.ToArray();
        }
            public SiteInfoResponseType GetSitesInBox(
                float west, float south, float east, float north,
                Boolean IncludeSeries
                )
            {
                Stopwatch timer = System.Diagnostics.Stopwatch.StartNew();
                GetSiteInfoOD obj = new GetSiteInfoOD();

                box queryBox = new box(west, south, east, north);

                queryLog2.LogStart(Logging.Methods.GetSitesInBoxObject, queryBox.ToString(),
                     appContext.Request.UserHostName);

                SiteInfoResponseType resp = obj.GetSitesByBox(queryBox, IncludeSeries);

                queryLog2.LogEnd(Logging.Methods.GetSitesInBoxObject,
                      queryBox.ToString(),
                     timer.ElapsedMilliseconds.ToString(),
                     resp.site.Length.ToString(),
                     appContext.Request.UserHostName);
                return resp;
            }
Example #39
0
		// Find the splittable box with the largest color population
		// Returns null if no splittable boxes remain
		static box find_biggest_color_pop(box[] boxlist, int numboxes)
		{
			int maxc=0;
			box which=null;

			for(int i=0; i<numboxes; i++)
			{
				box boxp=boxlist[i];
				if(boxp.colorcount>maxc&&boxp.volume>0)
				{
					which=boxp;
					maxc=boxp.colorcount;
				}
			}
			return which;
		}
Example #40
0
 private List<box> cutingY(List<double> item1, List<double> item2)
 {
     List<box> output = new List<box>();
     double t = item1.Sum() / (item.Sum());
     if (item.Sum() == 0) { __out.Add("box cutY error,null intput element"); return output; }
     if (t <= 0 || t > 1) { __out.Add("box cutY error"); return output; }
     box box1 = new box(this.Vertice[0], new Point3d(this.Vertice[2].X, (this.Vertice[2].Y - this.Vertice[0].Y) * t + this.Vertice[0].Y, 0));
     box1.Additem(item1);
     box box2 = new box(new Point3d(this.Vertice[0].X, (this.Vertice[2].Y - this.Vertice[0].Y) * t + this.Vertice[0].Y, 0), this.Vertice[2]);
     box2.Additem(item2);
     output.Add(box1);
     output.Add(box2);
     return output;
 }
Example #41
0
        public List<Polyline> ComputeTreeMap(List<double> x, List<double> y,int type)
        {
            for(int i = 0;i < x.Count;i++){
            x[i] = Math.Abs(x[i]) * Math.Abs(y[0]) * Math.Abs(y[1]);
              }

              List<box> b1 = new List<box>();
              List<box> b2 = new List<box>();
              List<box> temp;
              box boxtemp = new box(Math.Abs(y[0]), Math.Abs(y[1]));
              boxtemp.Additem(x);
              b1.Add(boxtemp);
              if (type == 1)
              {
              for (int k = 0; k < x.Count; k++)
              {
              bool sign = false;
              for (int i = 0; i < b1.Count; i++)
              {
                  if (b1[i].cut(out temp)) { sign = true; }
                  b2.AddRange(temp);
              }

              b1.Clear(); b1.AddRange(b2);
              b2 = new List<box>();
              if (!sign) { break; }
              }
              }
              else
              {
              for (int k = 0; k < x.Count; k++)
              {
              bool sign = false;
              for (int i = 0; i < b1.Count; i++)
              {
                  if (b1[i].cut_random(out temp)) { sign = true; }
                  b2.AddRange(temp);
              }

              b1.Clear(); b1.AddRange(b2);
              b2 = new List<box>();
              if (!sign) { break; }
              }
              }
              List<Polyline> output = new List<Polyline>();
              for(int i = 0;i < b1.Count;i++){
            output.Add(b1[i].drawPolyline());
              }
            return output;
        }
 public static siteInfoDataSet GetSiteInfoDataSet(box geomBox)
 {
     siteInfoDataSet ds = CreateBaseSiteInfoDataset();
     GetSiteInfoDataSet(geomBox, ds);
     return ds;
 }
Example #43
0
		// Compute representative color for a box, put it in colormap[icolor]
		static void compute_color(jpeg_decompress cinfo, box boxp, int icolor)
		{
			// Current algorithm: mean weighted by pixels (not colors)
			// Note it is important to get the rounding correct!
			my_cquantizer2 cquantize=(my_cquantizer2)cinfo.cquantize;
			ushort[, ,] histogram=cquantize.histogram;
			int total=0;
			int c0total=0;
			int c1total=0;
			int c2total=0;

			int c0min=boxp.c0min, c0max=boxp.c0max;
			int c1min=boxp.c1min, c1max=boxp.c1max;
			int c2min=boxp.c2min, c2max=boxp.c2max;

			for(int c0=c0min; c0<=c0max; c0++)
			{
				for(int c1=c1min; c1<=c1max; c1++)
				{
					for(int c2=c2min; c2<=c2max; c2++)
					{
						int count=histogram[c0, c1, c2];
						if(count!=0)
						{
							total+=count;
							c0total+=((c0<<C0_SHIFT)+((1<<C0_SHIFT)>>1))*count;
							c1total+=((c1<<C1_SHIFT)+((1<<C1_SHIFT)>>1))*count;
							c2total+=((c2<<C2_SHIFT)+((1<<C2_SHIFT)>>1))*count;
						}
					}
				}
			}

			cinfo.colormap[0][icolor]=(byte)((c0total+(total>>1))/total);
			cinfo.colormap[1][icolor]=(byte)((c1total+(total>>1))/total);
			cinfo.colormap[2][icolor]=(byte)((c2total+(total>>1))/total);
		}
Example #44
0
		// Shrink the min/max bounds of a box to enclose only nonzero elements,
		// and recompute its volume and population
		static void update_box(jpeg_decompress cinfo, box boxp)
		{
			my_cquantizer2 cquantize=(my_cquantizer2)cinfo.cquantize;
			ushort[, ,] histogram=cquantize.histogram;
			int dist0, dist1, dist2;
			int ccount;

			int c0min=boxp.c0min, c0max=boxp.c0max;
			int c1min=boxp.c1min, c1max=boxp.c1max;
			int c2min=boxp.c2min, c2max=boxp.c2max;

			if(c0max>c0min)
			{
				for(int c0=c0min; c0<=c0max; c0++)
				{
					for(int c1=c1min; c1<=c1max; c1++)
					{
						for(int c2=c2min; c2<=c2max; c2++)
						{
							if(histogram[c0, c1, c2]!=0)
							{
								boxp.c0min=c0min=c0;
								goto have_c0min;
							}
						}
					}
				}
			}
have_c0min:
			if(c0max>c0min)
			{
				for(int c0=c0max; c0>=c0min; c0--)
				{
					for(int c1=c1min; c1<=c1max; c1++)
					{
						for(int c2=c2min; c2<=c2max; c2++)
						{
							if(histogram[c0, c1, c2]!=0)
							{
								boxp.c0max=c0max=c0;
								goto have_c0max;
							}
						}
					}
				}
			}
have_c0max:
			if(c1max>c1min)
			{
				for(int c1=c1min; c1<=c1max; c1++)
				{
					for(int c0=c0min; c0<=c0max; c0++)
					{
						for(int c2=c2min; c2<=c2max; c2++)
						{
							if(histogram[c0, c1, c2]!=0)
							{
								boxp.c1min=c1min=c1;
								goto have_c1min;
							}
						}
					}
				}
			}
have_c1min:
			if(c1max>c1min)
			{
				for(int c1=c1max; c1>=c1min; c1--)
				{
					for(int c0=c0min; c0<=c0max; c0++)
					{
						for(int c2=c2min; c2<=c2max; c2++)
						{
							if(histogram[c0, c1, c2]!=0)
							{
								boxp.c1max=c1max=c1;
								goto have_c1max;
							}
						}
					}
				}
			}
have_c1max:
			if(c2max>c2min)
			{
				for(int c2=c2min; c2<=c2max; c2++)
				{
					for(int c0=c0min; c0<=c0max; c0++)
					{
						for(int c1=c1min; c1<=c1max; c1++)
						{
							if(histogram[c0, c1, c2]!=0)
							{
								boxp.c2min=c2min=c2;
								goto have_c2min;
							}
						}
					}
				}
			}
have_c2min:
			if(c2max>c2min)
			{
				for(int c2=c2max; c2>=c2min; c2--)
				{
					for(int c0=c0min; c0<=c0max; c0++)
					{
						for(int c1=c1min; c1<=c1max; c1++)
						{
							if(histogram[c0, c1, c2]!=0)
							{
								boxp.c2max=c2max=c2;
								goto have_c2max;
							}
						}
					}
				}
			}
have_c2max:

			// Update box volume.
			// We use 2-norm rather than real volume here; this biases the method
			// against making long narrow boxes, and it has the side benefit that
			// a box is splittable iff norm > 0.
			// Since the differences are expressed in histogram-cell units,
			// we have to shift back to byte units to get consistent distances;
			// after which, we scale according to the selected distance scale factors.
			dist0=((c0max-c0min)<<C0_SHIFT)*C0_SCALE;
			dist1=((c1max-c1min)<<C1_SHIFT)*C1_SCALE;
			dist2=((c2max-c2min)<<C2_SHIFT)*C2_SCALE;
			boxp.volume=dist0*dist0+dist1*dist1+dist2*dist2;

			// Now scan remaining volume of box and compute population
			ccount=0;
			for(int c0=c0min; c0<=c0max; c0++)
			{
				for(int c1=c1min; c1<=c1max; c1++)
				{
					for(int c2=c2min; c2<=c2max; c2++)
					{
						if(histogram[c0, c1, c2]!=0) ccount++;
					}
				}
			}
			boxp.colorcount=ccount;
		}
            public SiteInfoResponseType GetSitesInBox(
                float west, float south, float east, float north,
                Boolean IncludeSeries
                )
            {
                Stopwatch timer = System.Diagnostics.Stopwatch.StartNew();

                box queryBox = new box(west, south, east, north);

                queryLog2.LogStart(CustomLogging.Methods.GetSitesInBoxObject, queryBox.ToString(),
                     appContext.Request.UserHostName);

                SiteInfoResponseType resp = new SiteInfoResponseType();
                    resp.site = WebServiceUtils.GetSitesByBox(queryBox, IncludeSeries);

                    //set query info
                    resp.queryInfo = CuahsiBuilder.CreateQueryInfoType("GetSitesInBox");
                    NoteType note = CuahsiBuilder.createNote("box");
                    resp.queryInfo.note = CuahsiBuilder.addNote(null, note);

                queryLog2.LogEnd(CustomLogging.Methods.GetSitesInBoxObject,
                      queryBox.ToString(),
                     timer.ElapsedMilliseconds.ToString(),
                     resp.site.Length.ToString(),
                     appContext.Request.UserHostName);
                return resp;
            }
Example #46
0
		// Repeatedly select and split the largest box until we have enough boxes
		static int median_cut(jpeg_decompress cinfo, box[] boxlist, int numboxes, int desired_colors)
		{
			while(numboxes<desired_colors)
			{
				// Select box to split.
				// Current algorithm: by population for first half, then by volume.
				box b1;
				if(numboxes*2<=desired_colors) b1=find_biggest_color_pop(boxlist, numboxes);
				else b1=find_biggest_volume(boxlist, numboxes);
				if(b1==null) break; // no splittable boxes left!

				box b2=boxlist[numboxes];	// where new box will go

				// Copy the color bounds to the new box.
				b2.c0max=b1.c0max; b2.c1max=b1.c1max; b2.c2max=b1.c2max;
				b2.c0min=b1.c0min; b2.c1min=b1.c1min; b2.c2min=b1.c2min;

				// Choose which axis to split the box on.
				// Current algorithm: longest scaled axis.
				// See notes in update_box about scaling distances.
				int c0=((b1.c0max-b1.c0min)<<C0_SHIFT)*C0_SCALE;
				int c1=((b1.c1max-b1.c1min)<<C1_SHIFT)*C1_SCALE;
				int c2=((b1.c2max-b1.c2min)<<C2_SHIFT)*C2_SCALE;

				// We want to break any ties in favor of green, then red, blue last.
				// This code does the right thing for R,G,B or B,G,R color orders only.
#if !BGR
				int cmax=c1, n=1;
				if(c0>cmax) { cmax=c0; n=0; }
				if(c2>cmax) { n=2; }
#else
				cmax=c1; n=1;
				if(c2>cmax) { cmax=c2; n=2; }
				if(c0>cmax) { n=0; }
#endif

				// Choose split point along selected axis, and update box bounds.
				// Current algorithm: split at halfway point.
				// (Since the box has been shrunk to minimum volume,
				// any split will produce two nonempty subboxes.)
				// Note that lb value is max for lower box, so must be < old max.
				int lb;
				switch(n)
				{
					case 0:
						lb=(b1.c0max+b1.c0min)/2;
						b1.c0max=lb;
						b2.c0min=lb+1;
						break;
					case 1:
						lb=(b1.c1max+b1.c1min)/2;
						b1.c1max=lb;
						b2.c1min=lb+1;
						break;
					case 2:
						lb=(b1.c2max+b1.c2min)/2;
						b1.c2max=lb;
						b2.c2min=lb+1;
						break;
				}
				// Update stats for boxes
				update_box(cinfo, b1);
				update_box(cinfo, b2);
				numboxes++;
			}
			return numboxes;
		}
Example #47
0
 public MessageList(box whichbox)
 {
     _box = whichbox;
     Messages = new ObservableCollection<Message>();
     Refresh();
 }
Example #48
0
        /// <summary>
        /// Master routine for color selection
        /// </summary>
        private void select_colors(int desired_colors)
        {
            /* Allocate workspace for box list */
            box[] boxlist = new box[desired_colors];

            /* Initialize one box containing whole space */
            int numboxes = 1;
            boxlist[0].c0min = 0;
            boxlist[0].c0max = JpegConstants.MAXJSAMPLE >> C0_SHIFT;
            boxlist[0].c1min = 0;
            boxlist[0].c1max = JpegConstants.MAXJSAMPLE >> C1_SHIFT;
            boxlist[0].c2min = 0;
            boxlist[0].c2max = JpegConstants.MAXJSAMPLE >> C2_SHIFT;

            /* Shrink it to actually-used volume and set its statistics */
            update_box(boxlist, 0);

            /* Perform median-cut to produce final box list */
            numboxes = median_cut(boxlist, numboxes, desired_colors);

            /* Compute the representative color for each box, fill colormap */
            for (int i = 0; i < numboxes; i++)
                compute_color(boxlist, i, i);

            m_cinfo.m_actual_number_of_colors = numboxes;
            m_cinfo.TRACEMS(1, J_MESSAGE_CODE.JTRC_QUANT_SELECTED, numboxes);
        }
            public static IEnumerable<SiteInfoType> GetSitesByBox(box queryBox)
            {
                siteInfoDataSet sDS;

                sDS = GetSiteInfoDataSet(queryBox);
                if (sDS.sites.Count == 0)
                {
                    throw new WaterOneFlowException("No Sites found in specified region: " + queryBox.ToString());
                }
                else
                {
                    List<SiteInfoType> sites = new List<SiteInfoType>(sDS.sites.Count);

                    foreach (siteInfoDataSet.sitesRow s in sDS.sites)
                    {
                        SiteInfoType sit = row2SiteInfoElement(s, sDS);
                        yield return sit;
                    }
                }
            }
Example #50
0
        /*
         * Next we have the really interesting routines: selection of a colormap
         * given the completed histogram.
         * These routines work with a list of "boxes", each representing a rectangular
         * subset of the input color space (to histogram precision).
         */

        /// <summary>
        /// Find the splittable box with the largest color population
        /// Returns null if no splittable boxes remain
        /// </summary>
        private static int find_biggest_color_pop(box[] boxlist, int numboxes)
        {
            long maxc = 0;
            int which = -1;
            for (int i = 0; i < numboxes; i++)
            {
                if (boxlist[i].colorcount > maxc && boxlist[i].volume > 0)
                {
                    which = i;
                    maxc = boxlist[i].colorcount;
                }
            }

            return which;
        }
 private static void GetSiteInfoDataSet(box geomBox, siteInfoDataSet ds)
 {
     sitesTableAdapter sitesTableAdapter = CreateSitesTableAdapter();
     try
     {
         sitesTableAdapter.FillByBox(ds.sites,
                                 geomBox.South, geomBox.North, geomBox.West, geomBox.East);
     }
     catch (Exception e)
     {
         log.Fatal("Cannot connect to database " + e.Message);
         //+ sitesTableAdapter.Connection.DataSource
         throw new WaterOneFlowServerException(e.Message);
     }
 }
Example #52
0
        /// <summary>
        /// Shrink the min/max bounds of a box to enclose only nonzero elements,
        /// and recompute its volume and population
        /// </summary>
        private void update_box(box[] boxlist, int boxIndex)
        {
            box curBox = boxlist[boxIndex];
            bool have_c0min = false;

            if (curBox.c0max > curBox.c0min)
            {
                for (int c0 = curBox.c0min; c0 <= curBox.c0max; c0++)
                {
                    for (int c1 = curBox.c1min; c1 <= curBox.c1max; c1++)
                    {
                        int histogramIndex = c1 * HIST_C2_ELEMS + curBox.c2min;
                        for (int c2 = curBox.c2min; c2 <= curBox.c2max; c2++)
                        {
                            if (m_histogram[c0][histogramIndex++] != 0)
                            {
                                curBox.c0min = c0;
                                have_c0min = true;
                                break;
                            }
                        }

                        if (have_c0min)
                            break;
                    }

                    if (have_c0min)
                        break;
                }
            }

            bool have_c0max = false;
            if (curBox.c0max > curBox.c0min)
            {
                for (int c0 = curBox.c0max; c0 >= curBox.c0min; c0--)
                {
                    for (int c1 = curBox.c1min; c1 <= curBox.c1max; c1++)
                    {
                        int histogramIndex = c1 * HIST_C2_ELEMS + curBox.c2min;
                        for (int c2 = curBox.c2min; c2 <= curBox.c2max; c2++)
                        {
                            if (m_histogram[c0][histogramIndex++] != 0)
                            {
                                curBox.c0max = c0;
                                have_c0max = true;
                                break;
                            }
                        }

                        if (have_c0max)
                            break;
                    }

                    if (have_c0max)
                        break;
                }
            }

            bool have_c1min = false;
            if (curBox.c1max > curBox.c1min)
            {
                for (int c1 = curBox.c1min; c1 <= curBox.c1max; c1++)
                {
                    for (int c0 = curBox.c0min; c0 <= curBox.c0max; c0++)
                    {
                        int histogramIndex = c1 * HIST_C2_ELEMS + curBox.c2min;
                        for (int c2 = curBox.c2min; c2 <= curBox.c2max; c2++)
                        {
                            if (m_histogram[c0][histogramIndex++] != 0)
                            {
                                curBox.c1min = c1;
                                have_c1min = true;
                                break;
                            }
                        }

                        if (have_c1min)
                            break;
                    }

                    if (have_c1min)
                        break;
                }
            }

            bool have_c1max = false;
            if (curBox.c1max > curBox.c1min)
            {
                for (int c1 = curBox.c1max; c1 >= curBox.c1min; c1--)
                {
                    for (int c0 = curBox.c0min; c0 <= curBox.c0max; c0++)
                    {
                        int histogramIndex = c1 * HIST_C2_ELEMS + curBox.c2min;
                        for (int c2 = curBox.c2min; c2 <= curBox.c2max; c2++)
                        {
                            if (m_histogram[c0][histogramIndex++] != 0)
                            {
                                curBox.c1max = c1;
                                have_c1max = true;
                                break;
                            }
                        }

                        if (have_c1max)
                            break;
                    }

                    if (have_c1max)
                        break;
                }
            }

            bool have_c2min = false;
            if (curBox.c2max > curBox.c2min)
            {
                for (int c2 = curBox.c2min; c2 <= curBox.c2max; c2++)
                {
                    for (int c0 = curBox.c0min; c0 <= curBox.c0max; c0++)
                    {
                        int histogramIndex = curBox.c1min * HIST_C2_ELEMS + c2;
                        for (int c1 = curBox.c1min; c1 <= curBox.c1max; c1++, histogramIndex += HIST_C2_ELEMS)
                        {
                            if (m_histogram[c0][histogramIndex] != 0)
                            {
                                curBox.c2min = c2;
                                have_c2min = true;
                                break;
                            }
                        }

                        if (have_c2min)
                            break;
                    }

                    if (have_c2min)
                        break;
                }
            }

            bool have_c2max = false;
            if (curBox.c2max > curBox.c2min)
            {
                for (int c2 = curBox.c2max; c2 >= curBox.c2min; c2--)
                {
                    for (int c0 = curBox.c0min; c0 <= curBox.c0max; c0++)
                    {
                        int histogramIndex = curBox.c1min * HIST_C2_ELEMS + c2;
                        for (int c1 = curBox.c1min; c1 <= curBox.c1max; c1++, histogramIndex += HIST_C2_ELEMS)
                        {
                            if (m_histogram[c0][histogramIndex] != 0)
                            {
                                curBox.c2max = c2;
                                have_c2max = true;
                                break;
                            }
                        }

                        if (have_c2max)
                            break;
                    }

                    if (have_c2max)
                        break;
                }
            }

            /* Update box volume.
             * We use 2-norm rather than real volume here; this biases the method
             * against making long narrow boxes, and it has the side benefit that
             * a box is splittable iff norm > 0.
             * Since the differences are expressed in histogram-cell units,
             * we have to shift back to byte units to get consistent distances;
             * after which, we scale according to the selected distance scale factors.
             */
            int dist0 = ((curBox.c0max - curBox.c0min) << C0_SHIFT) * R_SCALE;
            int dist1 = ((curBox.c1max - curBox.c1min) << C1_SHIFT) * G_SCALE;
            int dist2 = ((curBox.c2max - curBox.c2min) << C2_SHIFT) * B_SCALE;
            curBox.volume = dist0 * dist0 + dist1 * dist1 + dist2 * dist2;

            /* Now scan remaining volume of box and compute population */
            long ccount = 0;
            for (int c0 = curBox.c0min; c0 <= curBox.c0max; c0++)
            {
                for (int c1 = curBox.c1min; c1 <= curBox.c1max; c1++)
                {
                    int histogramIndex = c1 * HIST_C2_ELEMS + curBox.c2min;
                    for (int c2 = curBox.c2min; c2 <= curBox.c2max; c2++, histogramIndex++)
                    {
                        if (m_histogram[c0][histogramIndex] != 0)
                            ccount++;
                    }
                }
            }

            curBox.colorcount = ccount;
            boxlist[boxIndex] = curBox;
        }
Example #53
0
 public hull(box hu, Point3d cen)
 {
     this.center = new Point3d(cen);
     this.pts = new List<vertex>();
     this.edges = new List<edge>();
     for (int i = 0; i < hu.pts.Count; i++)
     {
         this.pts.Add(new vertex(hu.pts[i], this.center.DistanceTo(hu.pts[i])));
     }
     for (int i = 0; i < hu.lp1.Count; i++)
     {
         this.edges.Add(new edge(pts[hu.lp1[i]], pts[hu.lp2[i]]));
     }
 }
Example #54
0
		// Master routine for color selection
		static void select_colors(jpeg_decompress cinfo, int desired_colors)
		{
			box[] boxlist=null;

			// Allocate workspace for box list
			try
			{
				boxlist=new box[desired_colors];
				for(int i=0; i<desired_colors; i++) boxlist[i]=new box();
			}
			catch
			{
				ERREXIT1(cinfo, J_MESSAGE_CODE.JERR_OUT_OF_MEMORY, 4);
			}

			// Initialize one box containing whole space
			int numboxes=1;
			boxlist[0].c0min=0;
			boxlist[0].c0max=MAXJSAMPLE>>C0_SHIFT;
			boxlist[0].c1min=0;
			boxlist[0].c1max=MAXJSAMPLE>>C1_SHIFT;
			boxlist[0].c2min=0;
			boxlist[0].c2max=MAXJSAMPLE>>C2_SHIFT;

			// Shrink it to actually-used volume and set its statistics
			update_box(cinfo, boxlist[0]);

			// Perform median-cut to produce final box list
			numboxes=median_cut(cinfo, boxlist, numboxes, desired_colors);

			// Compute the representative color for each box, fill colormap
			for(int i=0; i<numboxes; i++) compute_color(cinfo, boxlist[i], i);
			cinfo.actual_number_of_colors=numboxes;

			TRACEMS1(cinfo, 1, J_MESSAGE_CODE.JTRC_QUANT_SELECTED, numboxes);
		}
Example #55
0
		// Find the splittable box with the largest (scaled) volume
		// Returns null if no splittable boxes remain
		static box find_biggest_volume(box[] boxlist, int numboxes)
		{
			int maxv=0;
			box which=null;

			for(int i=0; i<numboxes; i++)
			{
				box boxp=boxlist[i];
				if(boxp.volume>maxv)
				{
					which=boxp;
					maxv=boxp.volume;
				}
			}
			return which;
		}