예제 #1
0
파일: bst.hpp 프로젝트: VincentXWD/ds_exp
	void bst<type>::_insert(np cur, const type& x) {
		if (x > cur->_data) {
			if (cur->right == NULL) {
				np tmp = new nt();
				cur->right = tmp;
				tmp->_data = x;
			}
			else {
				_insert(cur->right, x);
			}
		}
		if (x < cur->_data) {
			if (cur->left == NULL) {
				np tmp = new nt();
				cur->left = tmp;
				cur->height++;
				tmp->_data = x;
			}
			else {
				_insert(cur->left, x);
			}
		}
		cur->height = (
			_height(cur->left) > _height(cur->right) ?
			_height(cur->left) : _height(cur->right)
		) + 1;
	}
예제 #2
0
IPTR Register__MUIM_Layout(struct IClass *cl, Object *obj, struct MUIP_Layout *msg)
{
    struct Register_DATA *data = INST_DATA(cl, obj);
    ULONG retval = 1;
    IPTR active;

    get(obj, MUIA_Group_ActivePage, &active);

    if (active != data->active)
    {
        data->oldactive = data->active;
        data->active = active;
    }
    SetHardCoord(obj,data);
    DoMethod(obj, MUIM_UpdateInnerSizes);

    DoSuperMethodA(cl, obj, (Msg)msg);

    data->left        = _left(obj);
    data->top         = _top(obj);
    data->framewidth  = _width(obj);
    data->frameheight = _height(obj) - data->tab_height;

    LayoutTabItems(obj,data);

    /*      D(bug("Register_Layout : left=%d, top=%d / framewidth=%d, frameheight=%d\n", */
    /*   	  data->left, data->top, data->framewidth, data->frameheight)); */

    return retval;
}
예제 #3
0
파일: avl_tree.hpp 프로젝트: jashook/ev6
      void _rotate_with_right_child( avl_node< __Key, __Value, __Compare >*& _Node)
      {
         if (_Node == 0) return;

         avl_node< __Key, __Value, __Compare >* _TempNode = _Node->m_right_child;

         _Node->m_right_child = _TempNode->m_left_child;
         if (_TempNode->m_left_child != 0) _TempNode->m_left_child->m_parent = _Node;
         
         _TempNode->m_left_child = _Node;

         std::pair< int, int > _NodePair, _TempNodePair;

         _NodePair = _height(_Node->m_left_child, _Node->m_right_child);

         _Node->m_height = _max(_NodePair) + 1;

         _TempNodePair = _height(_TempNode->m_left_child, _TempNode->m_right_child);
         
         _TempNode->m_height = _max(_TempNodePair) + 1;
         
         _TempNode->m_parent = _Node->m_parent;
         _Node->m_parent = _TempNode;

         _Node = _TempNode;
         
         if (_Node->m_parent != 0)
         {
            if (_Node->m_key < _Node->m_parent->m_key) _Node->m_parent->m_left_child = _Node;
            else _Node->m_parent->m_right_child = _Node;
         }
         
         else
         {
            _m_root = _Node;
         }
         
      }
예제 #4
0
/**************************************************************************
 Layout Tab Items
**************************************************************************/
static void LayoutTabItems(Object *obj, struct Register_DATA *data)
{
    WORD extra_space;
    WORD fitwidth;
    WORD x = 0;
    WORD y = - data->tab_height;
    WORD item_width; /* from vertical line left to v l right */
    int i;
    int tabs_on_bottom = 0;

    item_width  = (_width(obj) - data->total_hspacing) / data->columns;//data->numitems;
    extra_space = (_width(obj) - data->total_hspacing) % data->columns;//data->numitems;

    D(bug("LayoutTabItems(%lx) : width = %d, mwidth = %d, max item width = %d, remainder = %d\n",
          obj, _width(obj), _mwidth(obj), item_width, extra_space));

    for (i = 0; i < data->numitems; i++)
    {
        struct RegisterTabItem *ri = &data->items[i];

        if (i % data->columns == 0)
        {
            x = INTERTAB - 1;
            if (i > data->active && !tabs_on_bottom)
            {
                y = _height(obj) - muiAreaData(obj)->mad_InnerBottom;
                tabs_on_bottom = 1;
            } else y += data->tab_height;
        }

        ri->x1 = x;
        ri->x2 = ri->x1 + item_width - 1;
        if (extra_space > 0)
        {
            ri->x2++;
            extra_space--;
        }
        fitwidth = ri->x2 - ri->x1 + 1 - TEXTSPACING;
        x += fitwidth + TEXTSPACING + INTERTAB;

        ri->y1 = y;
        ri->y2 = y + data->tab_height - 1;
    }
}
예제 #5
0
파일: mlayout.c 프로젝트: dlecorfec/zune99
    /*
    ** Layout function. Here, we have to call MUI_Layout() for each
    ** our children. MUI wants us to place them in a rectangle
    ** defined by (0,0,lm->lm_Layout.Width-1,lm->lm_Layout.Height-1)
    ** You are free to put the children anywhere in this rectangle.
    */
BOOL MUI_Layout (Object *obj, LONG left, LONG top, LONG width, LONG height,
		 ULONG flags)
{
    static ULONG method = MUIM_Layout;
    Object *parent = _parent(obj);

/*
 * Called only by groups, never by windows
 */
    g_assert(parent != NULL);

    _left(obj) = left + _mleft(parent);
    _top(obj) = top + _mtop(parent);
    _width(obj) = width;
    _height(obj) = height;

    DoMethodA(obj, (Msg)&method);

    return TRUE;
}
예제 #6
0
void Ambix_directional_loudnessAudioProcessor::calcParams()
{
    if (!_initialized)
    {
        
        sph_h.Init(AMBI_ORDER);
        
        const String t_design_txt (t_design::des_3_240_21_txt);
        
        // std::cout << t_design_txt << std::endl;
        
        String::CharPointerType lineChar = t_design_txt.getCharPointer();
        
        int n = 0; // how many characters been read
        int numsamples = 0;
        int i = 0;
        
        int curr_n = 0;
        int max_n = lineChar.length();
        
        while (curr_n < max_n) { // check how many coordinates we have
            double value;
            sscanf(lineChar, "%lf\n%n", &value, &n);
            lineChar += n;
            curr_n += n;
            numsamples++;
        } // end parse numbers
        
        numsamples = numsamples/3; // xyz
        
        Carth_coord.resize(numsamples,3); // positions in cartesian coordinates
        
        curr_n = 0;
        lineChar = t_design_txt.getCharPointer();
        
        // parse line for numbers again and copy to carth coordinate matrix
        while (i < numsamples) {
            
            double x,y,z;
            
            sscanf(lineChar, "%lf%lf%lf%n", &x, &y, &z, &n);
            
            Carth_coord(i,0) = x;
            Carth_coord(i,1) = y;
            Carth_coord(i,2) = z;
            
            lineChar += n;
            
            curr_n += n;
            i++;
            
        } // end parse numbers
        
        // std::cout << "Coordinate size: " << Carth_coord.rows() << " x " << Carth_coord.cols() << std::endl;
        // std::cout << Carth_coord << std::endl;
        
        Sph_coord.resize(numsamples,2); // positions in spherical coordinates
        
        
        Sh_matrix.setZero(numsamples,AMBI_CHANNELS);
        
        for (int i=0; i < numsamples; i++)
        {
            Eigen::VectorXd Ymn(AMBI_CHANNELS); // Ymn result
            
            Sph_coord(i,0) = atan2(Carth_coord(i,1),Carth_coord(i,0)); // azimuth
            Sph_coord(i,1) = atan2(Carth_coord(i,2),sqrt(Carth_coord(i,0)*Carth_coord(i,0) + Carth_coord(i,1)*Carth_coord(i,1))); // elevation
            
            sph_h.Calc(Sph_coord(i,0),Sph_coord(i,1)); // phi theta
            sph_h.Get(Ymn);
            
            // std::cout << "Size: " << Ymn.size() << ": " << Ymn << std::endl;
            
            //Sh_matrix.row(i) = Ymn;
            Sh_matrix.block(i,0,1,AMBI_CHANNELS) = Ymn.transpose();
            // std::cout << "Size: " << Sh_matrix.block(i,0,1,in_ambi_channels).size() << ": " << Sh_matrix.block(i,0,1,in_ambi_channels) << std::endl;
        }
        
        // Sh_matrix_inv.setZero();
        
        //Sh_matrix_inv = (Sh_matrix.transpose()*Sh_matrix).inverse()*Sh_matrix.transpose(); // not working for dynamic input order
        // if input order is different a better solving has to be used for the inverse:
        Sh_matrix_inv = (Sh_matrix.transpose()*Sh_matrix).colPivHouseholderQr().inverse()*Sh_matrix.transpose();
        
        // std::cout << "Size: " << Sh_matrix_inv.rows() << " x " << Sh_matrix_inv.cols() << std::endl;
        // std::cout << Sh_matrix_inv << std::endl;
        
        _initialized = true;
        
    }
    
    if (_param_changed)
    {
        // convert parameters to values for the filter
        // ArrayIntParam _shape = shape;
        
        ArrayParam _width = width * (float)M_PI; // 0...pi
        ArrayParam _height = height * (float)M_PI;
        
        ArrayParam _gain;
        
        for (int i=0; i < gain.rows();i++)
        {
            _gain(i) = ParamToRMS(gain(i));
        }
        
        SphCoordParam _center_sph = (center_sph - 0.5f)*2.f*(float)M_PI;
        
        // std::cout << _center_sph << std::endl;
        
        CarthCoordParam _center_carth;
        
        // convert center spherical coordinates to carthesian
        for (int i=0; i < _center_sph.rows(); i++)
        {
            _center_carth(i,0) = cos(_center_sph(i,0))*cos(_center_sph(i,1)); // x
            _center_carth(i,1) = sin(_center_sph(i,0))*cos(_center_sph(i,1)); // y
            _center_carth(i,2) = sin(_center_sph(i,1)); // z
        }
        
        // scale the SH_matrix and save as Sh_matrix_mod
        Sh_matrix_mod = Sh_matrix;
        
        // iterate over all sample points
        for (int i=0; i < Sh_matrix_mod.rows(); i++)
        {
            double multipl = 1.f;
            
            // iterate over all filters
            for (int k=0; k < NUM_FILTERS; k++)
            {
                Eigen::Vector2d Sph_coord_vec = Sph_coord.row(i);
                Eigen::Vector2d _center_sph_vec = _center_sph.row(k);
                
                multipl *= (double)sph_filter.GetWeight(&Sph_coord_vec, Carth_coord.row(i), &_center_sph_vec, _center_carth.row(k), (int)shape(k), _width(k), _height(k), _gain(k), (window(k) > 0.5f), transition(k));
            }
            
            Sh_matrix_mod.row(i) *= multipl;
            
        }
        
        // calculate new transformation matrix
        Sh_transf = Sh_matrix_inv * Sh_matrix_mod;
        
        // threshold coefficients
        for (int i = 0; i < Sh_transf.size(); i++)
        {
            if (abs(Sh_transf(i)) < 0.00001f)
                Sh_transf(i) = 0.f;
        }
        
        _param_changed = false;
    }
    
    
}
예제 #7
0
/* utility function to compute the balance factor of a node
 * computed as rght - left
 * */
int _bf(struct AVLNode *cur) {
   return _height(cur->rght) - _height(cur->left);
}
예제 #8
0
/* utility function to set the height of a node */
void _setHeight(struct AVLNode *cur) {
   int lh = _height(cur->left);
   int rh = _height(cur->rght);
   if (lh < rh) cur->hght = rh + 1;
      else cur->hght = lh + 1;
}
예제 #9
0
파일: avl_tree.hpp 프로젝트: jashook/ev6
      void _insert(__Key& _Key, __Value& _Value)
      {
         if (_m_root == 0)
         {
            _m_root = new avl_node<__Key, __Value, __Compare>(_Key, _Value);
            _m_left_leaf_node = _m_root;
            _m_right_leaf_node = new avl_node<__Key, __Value, __Compare>(_Key, _Value);
            _m_right_leaf_node->m_parent = _m_root;
            _m_root->m_right_child = _m_right_leaf_node;
            ++_m_size;
         }

         else
         {
            avl_node< __Key, __Value, __Compare >* _ParentPtr = _descend(_Key);

            if ( _Key < _ParentPtr->m_key )
            {
               _ParentPtr->m_left_child = new avl_node< __Key, __Value, __Compare >(_Key, _Value, 0, 0, _ParentPtr);
               ++_m_size;

               if (_ParentPtr == _m_left_leaf_node) _m_left_leaf_node = _ParentPtr->m_left_child;
            }

            else if ( _Key > _ParentPtr->m_key) 
            {
               _ParentPtr->m_right_child = new avl_node< __Key, __Value, __Compare >(_Key, _Value, 0, 0, _ParentPtr);
               ++_m_size;

               if (_ParentPtr == _m_right_leaf_node->m_parent) 
               {
            
                  _ParentPtr->m_right_child->m_right_child = _m_right_leaf_node;
                  _m_right_leaf_node->m_parent = _ParentPtr->m_right_child;   
               
               }

            }

            else
            {
               return;
            }
            
            std::pair< int, int > _Heights = _height(_ParentPtr->m_left_child, _ParentPtr->m_right_child);
            _ParentPtr->m_height = _max(_Heights) + 1;

            while (_ParentPtr != NULL)
            {
                _ParentPtr = _ParentPtr->m_parent;
   
               if (_ParentPtr == NULL) break;
               std::pair< int, int > _Heights = _height(_ParentPtr->m_left_child, _ParentPtr->m_right_child);
 
               _ParentPtr->m_height = _max(_Heights) + 1;

               if (_are_not_balanced(_Heights))
               {
                  
                  if (_Value < _ParentPtr->m_value)
                  {
                     // if the value is less than the value of the node
                     // then it would have had to have been inserted to the left
                     // therefore m_left_child cannot to be null

                     if (_Value < _ParentPtr->m_left_child->m_value) _rotate_with_left_child(_ParentPtr);
                     else _double_with_left_child(_ParentPtr);
                  }

                  else if (_Value > _ParentPtr->m_value)
                  {
                     if (_ParentPtr->m_right_child->m_value < _Value) _rotate_with_right_child(_ParentPtr);
                     else _double_with_right_child(_ParentPtr);
                  }
               }              
            }
         }
      }
예제 #10
0
void Ambix_vmicAudioProcessor::calcParams()
{
    if (!_initialized)
    {
        
        sph_h.Init(AMBI_ORDER);
        
        const String t_design_txt (t_design::des_3_240_21_txt);
        
        // std::cout << t_design_txt << std::endl;
        
        String::CharPointerType lineChar = t_design_txt.getCharPointer();
        
        int n = 0; // how many characters been read
        int numsamples = 0;
        int i = 0;
        
        int curr_n = 0;
        int max_n = lineChar.length();
        
        while (curr_n < max_n) { // check how many coordinates we have
            double value;
            sscanf(lineChar, "%lf\n%n", &value, &n);
            lineChar += n;
            curr_n += n;
            numsamples++;
        } // end parse numbers
        
        numsamples = numsamples/3; // xyz
        
        Carth_coord.resize(numsamples,3); // positions in cartesian coordinates
        
        curr_n = 0;
        lineChar = t_design_txt.getCharPointer();
        
        // parse line for numbers again and copy to carth coordinate matrix
        while (i < numsamples) {
            
            double x,y,z;
            
            sscanf(lineChar, "%lf%lf%lf%n", &x, &y, &z, &n);
            
            Carth_coord(i,0) = x;
            Carth_coord(i,1) = y;
            Carth_coord(i,2) = z;
            
            lineChar += n;
            
            curr_n += n;
            i++;
            
        } // end parse numbers
        
        // std::cout << "Coordinate size: " << Carth_coord.rows() << " x " << Carth_coord.cols() << std::endl;
        // std::cout << Carth_coord << std::endl;
        
        Sph_coord.resize(numsamples,2); // positions in spherical coordinates
        
        
        Sh_matrix.setZero(numsamples,AMBI_CHANNELS);
        
        for (int i=0; i < numsamples; i++)
        {
            Eigen::VectorXd Ymn(AMBI_CHANNELS); // Ymn result
            
            Sph_coord(i,0) = atan2(Carth_coord(i,1),Carth_coord(i,0)); // azimuth
            Sph_coord(i,1) = atan2(Carth_coord(i,2),sqrt(Carth_coord(i,0)*Carth_coord(i,0) + Carth_coord(i,1)*Carth_coord(i,1))); // elevation
            
            sph_h.Calc(Sph_coord(i,0),Sph_coord(i,1)); // phi theta
            sph_h.Get(Ymn);
            
            Sh_matrix.block(i,0,1,AMBI_CHANNELS) = Ymn.transpose();
        }
        
        
        _initialized = true;
        
    }
    
    if (_param_changed)
    {
        // convert parameters to values for the filter
        // ArrayIntParam _shape = shape;
        
        ArrayParam _width = width * (float)M_PI; // 0...pi
        ArrayParam _height = height * (float)M_PI;
        
        ArrayParam _gain;
        
        for (int i=0; i < gain.rows();i++)
        {
            _gain(i) = ParamToRMS(gain(i));
        }
        
        SphCoordParam _center_sph = (center_sph - 0.5f)*2.f*M_PI;
        
        // std::cout << _center_sph << std::endl;
        
        CarthCoordParam _center_carth;
        
        // convert center spherical coordinates to carthesian
        for (int i=0; i < _center_sph.rows(); i++)
        {
            _center_carth(i,0) = cos(_center_sph(i,0))*cos(_center_sph(i,1)); // x
            _center_carth(i,1) = sin(_center_sph(i,0))*cos(_center_sph(i,1)); // y
            _center_carth(i,2) = sin(_center_sph(i,1)); // z
        }
        
        Sh_matrix_mod.setZero();
        
        // iterate over all filters
        for (int k=0; k < NUM_FILTERS_VMIC; k++)
        {
            // copy the SH_matrix to 
            Eigen::MatrixXd Sh_matrix_temp = Sh_matrix;
            
            // iterate over all sample points
            for (int i=0; i < Sh_matrix_temp.rows(); i++)
            {
                
                Eigen::Vector2d Sph_coord_vec = Sph_coord.row(i);
                Eigen::Vector2d _center_sph_vec = _center_sph.row(k);
                
                
                double multipl = sph_filter.GetWeight(&Sph_coord_vec, Carth_coord.row(i), &_center_sph_vec, _center_carth.row(k), (int)floor(shape(k)+0.5f), _width(k), _height(k), 1, true, transition(k));
                
                if (multipl < 0.f) // -1.f in case of outside region
                    multipl = 0.f;
                
                Sh_matrix_temp.row(i) *= multipl;
            }
            
            // Sh_matrix_mod row is the sum over the columns
            Sh_matrix_mod.row(k) = Sh_matrix_temp.colwise().sum();
            
            // normalize and apply gain
            if (Sh_matrix_mod.row(k)(0) > 0.f)
                Sh_matrix_mod.row(k) *= 1/Sh_matrix_mod.row(k)(0)*_gain(k); 
        }
        
        // std::cout << "Size Sh_matrix_mod : " << Sh_matrix_mod.rows() << " x " << Sh_matrix_mod.cols() << std::endl;
        
        // std::cout << Sh_matrix_mod << std::endl;
        
        
        // this is the new transformation matrix
        Sh_transf = Sh_matrix_mod;
        
        // threshold coefficients
        for (int i = 0; i < Sh_transf.size(); i++)
        {
            if (abs(Sh_transf(i)) < 0.00001f)
                Sh_transf(i) = 0.f;
        }
        
        _param_changed = false;
    }
    
    
}