zerotree.cpp

来自「wavlet compression on c++ only cods」· C++ 代码 · 共 52 行

CPP
52
字号
// Copyright (c) 1999 Stephen T. Welstead. All rights reserved.
// File zerotree.cpp Zerotree class

#include "zerotree.h"

void tzerotree::mark_parents (int row,int col,short symbol) {
    // Mark the parents of this position (row,col) as having a
    // significant child.
    // The four "children" of position (i,j) in the subtree
    // are: (2i-1,2j-1),(2i-1,2j),(2i,2j-1) and (2i,2j).
    // Here, we need to move "backward", or up the tree, and
    // determine the parent of a given (row, col) position.
    int ichild = row,jchild = col;
    int iparent = ichild,jparent = jchild;
    while ((iparent > 1)&&(jparent > 1)) {
       if ((ichild/2)*2 == ichild) // even
	  iparent = ichild/2;
       else // odd
	  iparent = (ichild+1)/2;
       if ((jchild/2)*2 == jchild) // even
	  jparent = jchild/2;
       else // odd
	  jparent = (jchild+1)/2;
       set(iparent,jparent,symbol);
       ichild = iparent;
       jchild = jparent;
       }  // end while
    return;
    }

void tzerotree::mark_children (int row,int col,int nrows,
	int ncols,short symbol) {
    int child_end_row,child_end_col,child_rows,child_cols;
    // The four "children" of position (i,j) in the subtree
    // are: (2i-1,2j-1),(2i-1,2j),(2i,2j-1) and (2i,2j).
    child_end_row = 2*row;
    child_end_col = 2*col;
    child_rows = 2;
    child_cols = 2;
    while ((child_end_row<=nrows)&&(child_end_col<=ncols)) {
       for (int i=child_end_row-child_rows+1;i<=child_end_row;i++)
	   for (int j=child_end_col-child_cols+1;j<=child_end_col;j++)
		set(i,j,symbol);
       child_end_row *= 2;
       child_end_col *= 2;
       child_rows *= 2;
       child_cols *= 2;
       }  // end while
    return;
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?