Commit: 4dc208a489cabb875fc5aaae507f21f718691ce8
Author: Nicholas Bishop
Date:   Wed Feb 11 22:11:40 2015 +0100
Branches: cycles-ptex-49
https://developer.blender.org/rB4dc208a489cabb875fc5aaae507f21f718691ce8

Use BPXRect for internal storage in Ptex layout code

===================================================================

M       extern/ptex/BPX_packed_layout.h
M       extern/ptex/bpx_c_api.cpp

===================================================================

diff --git a/extern/ptex/BPX_packed_layout.h b/extern/ptex/BPX_packed_layout.h
index 082a4c5..c33d0c0 100644
--- a/extern/ptex/BPX_packed_layout.h
+++ b/extern/ptex/BPX_packed_layout.h
@@ -19,16 +19,20 @@
 // power-of-two output texture?
 struct BPXPackedLayout {
        struct Item {
-               Item(const int u_res, const int v_res)
-                       : u_res(u_res), v_res(v_res), id(-1), x(-1), y(-1)
+               Item(const BPXRect &rect, const int id)
+               : rect(rect), id(id)
                {}
 
-               int u_res;
-               int v_res;
+               const int width() const {
+                       return rect.xend - rect.xbegin;
+               }
+
+               const int height() const {
+                       return rect.yend - rect.ybegin;
+               }
 
+               BPXRect rect;
                int id;
-               int x;
-               int y;
        };
 
        typedef std::vector<Item> Items;
@@ -39,12 +43,13 @@ struct BPXPackedLayout {
                items.reserve(count);
        }
 
-       void add_item(const Item &item)
+       void add_rect(const BPXRect &rect)
        {
-               items.push_back(item);
-               items.back().id = items.size() - 1;
-               u_max_res = std::max(u_max_res, item.u_res);
-               v_max_res = std::max(v_max_res, item.v_res);
+               const int id = items.size();
+               items.push_back(Item(rect, id));
+               const Item &item = items.back();
+               u_max_res = std::max(u_max_res, item.width());
+               v_max_res = std::max(v_max_res, item.height());
        }
 
        void finalize()
@@ -72,8 +77,11 @@ struct BPXPackedLayout {
                         iter != items.end(); ++iter) {
                        Item &item = *iter;
 
+                       const int u_res = item.width();
+                       const int v_res = item.height();
+
                        // Check if enough room on this row
-                       if (dst_x + item.u_res + 2 * border > width) {
+                       if (dst_x + u_res + 2 * border > width) {
                                // Move to next row
                                assert(yinc != 0);
                                dst_y += yinc;
@@ -82,14 +90,16 @@ struct BPXPackedLayout {
                        }
 
                        // Write final position
-                       item.x = dst_x + border;
-                       item.y = dst_y + border;
+                       item.rect.xbegin = dst_x + border;
+                       item.rect.ybegin = dst_y + border;
+                       item.rect.xend = item.rect.xbegin + u_res;
+                       item.rect.yend = item.rect.ybegin + v_res;
 
-                       dst_x += item.u_res + (2 * border);
-                       height = std::max(height, dst_y + item.v_res + (2 * 
border));
+                       dst_x += u_res + (2 * border);
+                       height = std::max(height, dst_y + v_res + (2 * border));
                        max_width = std::max(dst_x, max_width);
 
-                       yinc = std::max(yinc, item.v_res + (2 * border));
+                       yinc = std::max(yinc, v_res + (2 * border));
                }
 
                // TODO?
@@ -125,11 +135,11 @@ private:
        // Order *descending* by v_res, then u_res
        static bool sort_res(const Item &a, const Item &b)
        {
-               if (a.v_res == b.v_res) {
-                       return a.u_res > b.u_res;
+               if (a.height() == b.height()) {
+                       return a.width() > b.width();
                }
                else {
-                       return a.v_res > b.v_res;
+                       return a.height() > b.height();
                }
        }
 
diff --git a/extern/ptex/bpx_c_api.cpp b/extern/ptex/bpx_c_api.cpp
index c1178ef..6356c8b 100644
--- a/extern/ptex/bpx_c_api.cpp
+++ b/extern/ptex/bpx_c_api.cpp
@@ -763,16 +763,6 @@ static bool bpx_ptex_mesh_edges_init(BPXPtexMesh &mesh)
        return true;
 }
 
-static BPXRect bpx_rect_from_layout_item(const BPXPackedLayout::Item &item)
-{
-       BPXRect rect;
-       rect.xbegin = item.x;
-       rect.ybegin = item.y;
-       rect.xend = item.x + item.u_res;
-       rect.yend = item.y + item.v_res;
-       return rect;
-}
-
 // TODO(nicholasbishop): still some stupid code, clean this up...
 
 static const BPXMeshEdge *bpx_mesh_edge_find(const BPXPtexMesh &mesh, int v1,
@@ -956,7 +946,7 @@ static bool 
bpx_ptex_filter_borders_update_from_file(ImageBuf &dst,
                        }
 
                        const BPXPackedLayout::Item &item = 
items[cur_layout_item];
-                       const BPXRect dst_rect = 
bpx_rect_from_layout_item(item);
+                       const BPXRect dst_rect = item.rect;
 
                        // TODO
                        BPXRect adj_rect[4];
@@ -975,7 +965,7 @@ static bool 
bpx_ptex_filter_borders_update_from_file(ImageBuf &dst,
                                        return false;
                                }
                                const BPXPackedLayout::Item &adj_item = 
items[adj_layout_item];
-                               adj_rect[side] = 
bpx_rect_from_layout_item(adj_item);
+                               adj_rect[side] = adj_item.rect;
                        }
 
                        if 
(!BPX_rect_borders_update(bpx_image_buf_from_oiio_image_buf(&dst),
@@ -1034,7 +1024,12 @@ static bool bpx_image_buf_ptex_layout(BPXPackedLayout 
&layout, ImageInput &in,
                        }
 
                        // TODO(nicholasbishop): will add adjacency data here
-                       layout.add_item(BPXPackedLayout::Item(w, h));
+                       BPXRect r;
+                       r.xbegin = 0;
+                       r.ybegin = 0;
+                       r.xend = w;
+                       r.yend = h;
+                       layout.add_rect(r);
                }
        }
 
@@ -1073,11 +1068,11 @@ static bool bpx_image_buf_fill_from_layout(ImageBuf 
&all_dst,
                                const BPXPackedLayout::Item &item =
                                        layout.get_items().at(face.vert_index + 
i);
                                ImageSpec spec2 = spec;
-                               spec2.width = item.u_res;
-                               spec2.height = item.v_res;
+                               spec2.width = item.width();
+                               spec2.height = item.height();
                                dsts[i] = new ImageBuf(all_dst.spec(), 
all_dst.localpixels());
-                               dst_roi[i].xbegin = item.x;
-                               dst_roi[i].ybegin = item.y;
+                               dst_roi[i].xbegin = item.rect.xbegin;
+                               dst_roi[i].ybegin = item.rect.ybegin;
                        }
                        const bool r = bpx_image_buf_quad_split(dsts, &tmp, 
dst_roi);
                        for (int i = 0; i < BPX_RECT_NUM_SIDES; i++) {
@@ -1100,8 +1095,8 @@ static bool bpx_image_buf_fill_from_layout(ImageBuf 
&all_dst,
                                ImageBuf tmp(spec);
                                in.read_image(spec.format, tmp.localpixels());
 
-                               const int xbegin = item.x;
-                               const int ybegin = item.y;
+                               const int xbegin = item.rect.xbegin;
+                               const int ybegin = item.rect.ybegin;
                                const int zbegin = 0;
                                const int chbegin = 0;
 
@@ -1167,7 +1162,13 @@ void BPX_packed_layout_add(BPXPackedLayout * const 
layout,
                                                        const int u_res, const 
int v_res,
                                                        const int id)
 {
-       layout->add_item(BPXPackedLayout::Item(u_res, v_res));
+       // TODO, adjacency
+       BPXRect r;
+       r.xbegin = 0;
+       r.ybegin = 0;
+       r.xend = u_res;
+       r.yend = v_res;
+       layout->add_rect(r);
 }
 
 void BPX_packed_layout_finalize(BPXPackedLayout * const layout)
@@ -1191,10 +1192,7 @@ bool BPX_packed_layout_item(const BPXPackedLayout * 
const layout,
        if (layout && r_rect) {
                const BPXPackedLayout::Items &items = layout->get_items();
                if (item_id >= 0 && item_id < items.size()) {
-                       r_rect->xbegin = items[item_id].x;
-                       r_rect->ybegin = items[item_id].y;
-                       r_rect->xend = items[item_id].x + items[item_id].u_res;
-                       r_rect->yend = items[item_id].y + items[item_id].v_res;
+                       (*r_rect) = items[item_id].rect;
                        return true;
                }
        }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to