Beispiel #1
0
static position singleRotateWithRight(position K2){
    position K1;
    K1 = K2->right;
    K2->right = K1->left;
    K1->left = K2;
    K2->height = maxInt(height(K2->left),height(K2->right)) + 1;
    K1->height = maxInt(height(K1->left),height(K1->right)) + 1;
    return K1;
}
Beispiel #2
0
TreeCoord TreeNode::getSibContrib( TreeNode * node, bool & sepInc )
//-----------------------------------------------------------------
{
    TreeCoord ret = 0;

    if( node->getLevel() != getLevel() + 1 ) return 0;

    if( _flags.enabled > Hidden ) {
        int divisor = 0;
        int lvlP1 = getLevel() + 1;

        for( int i = getCount( ChildList ); i > 0; i -= 1 ) {
            TreeNode * chNode = getNode( ChildList, i - 1 );

            if( chNode->_flags.enabled > Hidden &&
                chNode->getLevel() == lvlP1 ) {

                divisor += 1;
            }
        }

        divisor = maxInt( divisor, 1 );

        ret = _sibWidth / divisor;

        if( !sepInc ) {
            sepInc = true;
        } else {
            ret += sibSep / divisor;
        }
    }

    return ret;
}
Beispiel #3
0
avlTree insert(elementType X, avlTree T){
    if( T == NULL ){
        T = malloc(sizeof(struct avlNode));
        if( T == NULL)
            perror("Out of space !");
        else{
            T->content = X;
            T->height = 0;
            T->left = T->right = NULL;
        }
    }else if( X < T->content){
        T->left = insert(X,T->left);
        if(height(T->left) - height(T->right) == 2)
            T = singleRotateWithLeft(T);
        else
            T = doubleRotateWithLeft(T);
    }else if( X > T->content){
        T->right = insert(X,T->right);
        if(height(T->right) - height(T->left) == 2)
            T = singleRotateWithRight(T);
        else
            T = doubleRotateWithRight(T);
    }
    T->height = maxInt(height(T->left),height(T->right)) + 1;
    return T;
}
int InitHeuristic(Task** tasks, Task*** G, Task*** Nplus, int* GSize, int* NplusSize, int first)
{
    int i = 0;
    int minWorkers = 0;

    free(*G);
    free(*Nplus);
    *G = (Task**)malloc(0);
    *Nplus = (Task**)malloc(0);
    *NplusSize = 0;
    *GSize = 0;

    for (i = 0; i < _nbTasks; i++)
    {
        ReinitTask(tasks[i]);

        if (tasks[i]->nbPredecessors == 0)
        {
            *Nplus = (Task**)realloc(*Nplus, ++(*NplusSize) * sizeof(Task*));
            (*Nplus)[*NplusSize - 1] = tasks[i];
            tasks[i]->availabilityTime = 0;
        }
        else
        {
            *G = (Task**)realloc(*G, ++(*GSize) * sizeof(Task*));
            (*G)[*GSize - 1] = tasks[i];
        }

        if (first == 1)
        {
            tasks[i]->nbWorkersToAssign = tasks[i]->workersMin;
            minWorkers = maxInt(minWorkers, tasks[i]->nbWorkersToAssign);
        }
    }

    return minWorkers;
}
Beispiel #5
0
void test_maxInt(void) {
    int actual = maxInt(0, 0);
    TEST_ASSERT_EQUAL(0, actual);

    actual = maxInt(0, 25000);
    TEST_ASSERT_EQUAL(25000, actual);

    actual = maxInt(25000, 0);
    TEST_ASSERT_EQUAL(25000, actual);

    actual = maxInt(-25000, 0);
    TEST_ASSERT_EQUAL(0, actual);

    actual = maxInt(-25000, 100);
    TEST_ASSERT_EQUAL(100, actual);

    actual = maxInt(-25000, 30000);
    TEST_ASSERT_EQUAL(30000, actual);

    actual = maxInt(10, 30000);
    TEST_ASSERT_EQUAL(30000, actual);
}
Beispiel #6
0
unsigned int MO::selectPluralForm(int n)
{
    auto index = onPluralExpression ? onPluralExpression(n) : MO::DEFAULT_PLURAL_EXPRESSION(n);
    return maxInt(0, minInt(index, nplurals-1));
}
Beispiel #7
0
bool TreeNode::resolveChildWard( TreeRect & r )
//---------------------------------------------
{
    bool       vert = _parent->getDirection() == TreeVertical;
    TreeCoord  minSib = vert ? r.x() : r.y();
    TreeCoord  maxSib = 0;
    TreeCoord  childOff = childSep / 2;
    TreeCoord  maxChild = 0;
    bool       minSet = false;
    int        maxLevel;
    int        minLevel;
    int        i;

    for( i = 0; i < getCount( FlatList ); i += 1 ) {
        TreeNode * node = getNode( FlatList, i );

        int tLevel = node->getLevel();
        if( node->_flags.enabled > Hidden && tLevel >= 0 ) {
            if( minSet ) {
                maxLevel = maxInt( maxLevel, tLevel );
                minLevel = minInt( minLevel, tLevel );
            } else {
                maxLevel = tLevel;
                minLevel = tLevel;
                minSet = true;
            }
        }
    }

    if( !minSet ) {
        return false;
    }

    for( int level = minLevel; level <= maxLevel; level += 1 ) {
        maxChild = 0;
        for( i = 0; i < getCount( FlatList ); i += 1 ) {
            TreeNode * node = getNode( FlatList, i );
            if( node->getLevel() == level && node->_flags.enabled > Hidden ) {
                vert ? node->_bounding.y( childOff )
                     : node->_bounding.x( childOff );

                maxChild = maxCoord( maxChild, vert ? node->_bounding.h()
                                                    : node->_bounding.w() );
                maxSib = maxCoord( maxSib, vert ? node->_descend.x() + node->_descend.w()
                                                : node->_descend.y() + node->_descend.h() );
                minSib = minCoord( minSib, vert ? node->_descend.x()
                                                : node->_descend.y() );
            }
        }
        childOff += maxChild + childSep;
    }

    if( vert ) {
        r.x( minSib );
        r.w( maxSib - r.x() );
        r.h( childOff );
        _descend.h( childOff );
    } else {
        r.w( childOff );
        r.y( minSib );
        r.h( maxSib - r.y() );
        _descend.w( childOff );
    }

    return true;
}
/*
 * caller free both sino and newSino
 * 
 * This function prepares a new set of sinograms for the next recursive call.
 * It DOES angularly downsample the sinograms.
 *
 */
sinograms* newSinoForNextIter_forw(sinograms* sino,int newSinoSize,myFloat constShiftingFactor,myFloat* nu_i)
{

  int P = sino->num;
  sinograms* newSino;
  int size = sino->size;
  int newNumSino;
  int m,n,k,p;
  myFloat kk,pp;
  myFloat sum;
  myFloat angle;
  
  myFloat temp1,temp2,temp3;
  myFloat shiftingFactor;
  myFloat radialShift;
  myFloat totalShift;
  myFloat temp;
  
  int n2;
  int lowerPBound,upperPBound,lowerKBound,upperKBound;
  myFloat angularSupport;
  myFloat radialSupport;

  //preparing new sinograms
  newSino = (sinograms*)malloc(1*sizeof(sinograms));
  newSino->T = T;
  newSino->size = newSinoSize; 
  newSino->num = ceilf((myFloat)P/2);

  newNumSino = newSino->num;
  (newSino->sino)  = (myFloat**)malloc(newNumSino*sizeof(myFloat*));
  (newSino->sine) = (myFloat*)malloc(newNumSino*sizeof(myFloat));
  (newSino->cosine) = (myFloat*)malloc(newNumSino*sizeof(myFloat));
  //done preparing spaces for new sinograms


  angularSupport = ANGULAR_SUPPORT;
  radialSupport = RADIAL_SUPPORT;


  for(n=0;n<newNumSino;n++){
    //for each new angle
    n2 = 2*n;                
    (newSino->sino)[n] = (myFloat*)malloc(newSinoSize*sizeof(myFloat));
    (newSino->sine)[n] = (sino->sine)[n2];
    (newSino->cosine)[n] = (sino->cosine)[n2];    
    
    lowerPBound = maxInt(n2-(int)(angularSupport),0);    
    upperPBound = minInt(n2+ceilf(angularSupport),P-1);  


    for(m=0;m<newSinoSize;m++){
      //for each new radial array index
      sum = 0;
      
      for(p=lowerPBound;p<=upperPBound;p++){
	    //for each old angle
	    temp1 = n2-p;
	    temp2 = ANGULAR_INTERP(temp1);

	    radialShift = m+nu_i[n2]-nu_i[p];
	    shiftingFactor = rintf(nu_i[p]) + constShiftingFactor;

	    lowerKBound = (minInt(maxInt(ceilf(radialShift-shiftingFactor-radialSupport),0),size-1));
	    upperKBound = (maxInt(minInt((int)(radialShift-shiftingFactor+radialSupport),size-1),0)); 
	
	    
        //this loop can be optimized more, but i didn't have time.
	    for(k=lowerKBound;k<=upperKBound;k++){ 
	        //for each old radial array index
	        temp3 = (sino->sino)[p][k];
	  
	        kk = k + shiftingFactor; 
	        temp = radialShift-kk;
	        temp1 = RADIAL_INTERP(temp);
	  
	        sum += temp1 * temp2 * temp3;

	    }//end for k
      }//end for p

      (newSino->sino)[n][m] =  sum;
        
    }//end for m
  }//end for n

  return newSino;
}
/*
 * direct_forw(the sinograms,the size of the image, tau's,output image)
 *
 * direct_forw corresponds EXACTLY to the direct_forw method. 
 *
 */
void direct_forw( sinograms* g , int size , myFloat* tau , image* ans )
{
  int m;        //x direct_forwion
  int n;        //y direct_forwion

  myFloat* curRow; 
  myFloat middle = ( ( myFloat )( g->size ) ) / 2 - 0.5;
  myFloat halfSize = 0.5 * size;
  int numSino = g->num;
  myFloat scale = M_PI/numSino;       //scale output by PI/(# of projections)  ; see derivation of inverse radon


  int p;
  int k;
  int P = g->num;
  int sinoSize;

  myFloat i;
  myFloat sum = 0;
  myFloat* curSino;

  myFloat temp;
  
  myFloat realm; 
  myFloat realn;

  myFloat scaledRealm;
  myFloat scaledRealn;

  myFloat lowerXLimit;
  myFloat upperXLimit;
  myFloat lowerYLimit;
  myFloat upperYLimit;
   
  myFloat spXSupport;
  myFloat spYSupport;
  myFloat intpSupport;

  myFloat curr;
  myFloat lowerKBound;
  myFloat upperKBound;

  int lowerKBound2;
  int upperKBound2;

  myFloat theta;

  myFloat exactRadialPosition;

  intpSupport = RADIAL_SUPPORT;


  sinoSize = g->size;   


  //for each pixel in the image
  for(n=0;n<size;n++){
    curRow = (ans->pixel)[n];
    
    for(m=0;m<size;m++){

      //for each sinogram
      sum = 0.0;

      for(p=0;p<P;p++){
        curSino = g->sino[p];
        
        realm = m - halfSize + 0.5; 
        realn = n - halfSize + 0.5;
        scaledRealm = realm * oneOverT;
        scaledRealn = realn * oneOverT;         
        
        exactRadialPosition = scaledRealm*(g->cosine)[p] + scaledRealn*(g->sine)[p];

        exactRadialPosition -= tau[p]-middle; 
        //exactRadialPosition is now in terms of array index! (although it's still a float)

        //since spSupport is zero
        lowerKBound = exactRadialPosition-intpSupport;
        upperKBound = exactRadialPosition+intpSupport;

        lowerKBound2 = maxInt((int)(lowerKBound-ERROR_TOLERANCE)+1,0);
        upperKBound2 = minInt((int)(upperKBound),(g->size)-1);

        //for nearest interpolator, this needs to be checked
        if(upperKBound2<lowerKBound2){
            upperKBound2 = lowerKBound2;
        }

        //for each entry in this sinogram
        for(k=lowerKBound2;k<=upperKBound2;k++){      
            temp = weight_forw( exactRadialPosition , k );
            curSino[k] += curRow[m] * temp * scale;
        }//end for k
      }//end for p     
    } //end for n
  } //end for m
}
Beispiel #10
0
void DTViewSymbol::initialize()
//-----------------------------
// create the detail view of the symbol and size it.
{
    WString         titleText;
    WRect           tmpRect;
    char            fName[_MAX_PATH];
    int             width;
    int             tmpWidth;
    int             height;

    rescale();

    //----------------- "Function initialize" title ----------------

    titleText.printf( "%s %s", SymbolTitleText[ _symbol->symtype() ],
                _symbol->name() );
    setText( titleText.gets() );
    width = getTextExtentX( titleText.gets() ) + CaptionGadgetSize;

    //----------  "Defined: D:\dev\browser\cpp\dtvsym.cpp" line ----------

    if( _symbol->defSourceFile( fName ) ) {
        _fileText.printf( "%s: %s", (_symbol->isDefined()) ? Defined : Declared, fName );
        height = _symbolLineR.r.y();
    } else {
        height = _fileNameR.r.y();
    }
    tmpWidth = _fileNameR.r.x() + abs( _fileNameR.r.w() ) +
                getTextExtentX( _fileText.gets() );

    width = maxInt( width, tmpWidth );

    //------- "void DTViewSymbol::initialize()" line -------

    tmpRect = _symbolLineR.r;
    tmpRect.y( height );

    _descPaint = new DescriptionPaint( this, tmpRect, _symbol );

    height += _symbolBoxR.r.y() - _symbolLineR.r.y();
    tmpWidth = _symbolLineR.r.x() + _descPaint->rect().w() + abs( _symbolLineR.r.w() );
    width = maxInt( width, tmpWidth );

    //------------------ member listbox --------------------
    if( _useBox ) {
        tmpRect = _symbolBoxR.r;
        tmpRect.y( height );

        _symbolBox = new WListBox( this, tmpRect,
                        LStyleNoIntegral | WStyleHScroll | WStyleVScroll );
        _symbolBox->show();
        _symbolBox->setFocus();

        height += __frame.r.h() - _symbolBoxR.r.y();    // this include 2 * dialogFrameHeight
    }


    width += 2 * WSystemMetrics::dialogFrameWidth();
    height += WSystemMetrics::captionSize();

    size( width, height );
    show();
}