void matrixCreate(SparseMatrix& outMatrix, int n, int mn, IImage& maskImage) {
	cout << "ImageEditingUtils::matrixCreate("<<((intptr_t)(&outMatrix))<<","<<n<<","<<mn<<","<<((intptr_t)(&maskImage))<<")"<<endl;
	for (int pixel = 0; pixel < mn; pixel++) {
		int pxlX = pixel % n;
		int pxlY = (int) floor((float)pixel / (float)n);
		int maskRGB = maskImage.getRGB(pxlX, pxlY);
		if ((maskRGB & 0x00ffffff) == BLACK) {
			outMatrix(pixel,pixel) = 1;
		} else {
			// add 1s in sides
			int numOfNeighbors = 0;
			int neighborsArray[4] = {0};
			neighborsArray[0] = getUpper(pixel, n);
			neighborsArray[1] = getLower(pixel, n, mn);
			neighborsArray[2] = getRight(pixel, n);
			neighborsArray[3] = getLeft(pixel, n);
			for (int j = 0; j < 4; j++) {
				if (neighborsArray[j] >= 0) {
					outMatrix(pixel,neighborsArray[j]) = 1;
					numOfNeighbors++;
				}
			}

			//add -4, -3 or -2 in middle
			outMatrix(pixel,pixel) = (-1) * numOfNeighbors;
		}
	}
}
Esempio n. 2
0
static RECT getSliderRect( HWND hwnd ) {

    RECT rc = getClientRect( hwnd );
    const int pixStart = getHandle( hwnd ) + pixFromSlider( hwnd, getStart( hwnd ) - getLower( hwnd ) );
    const int pixEnd   = getHandle( hwnd ) + pixFromSlider( hwnd, getEnd  ( hwnd ) - getLower( hwnd ) );

    if ( isVertical( hwnd ) ) {
        rc.top    = pixStart;
        rc.bottom = pixEnd  ;
    } else {
        rc.left   = pixStart;
        rc.right  = pixEnd  ;
    }

    return rc;
}
const AbstractVector<T>& BoundedReferenceVector<T>::operator *=(const T& rhs)
{
  for (size_t i = getLower(); i <= getUpper(); i++)
  {
    (*this)[i] *= rhs;
  }
  return *this;
}
Esempio n. 4
0
static void scroll( HWND hwnd, int direction, int timeOut ) {

    LONG page_size = getEnd( hwnd ) - getStart( hwnd );
    if ( page_size <= getGranularity( hwnd ) ) {
        page_size = getGranularity( hwnd );
    }
    if ( page_size <= 0 ) {
        page_size = 1;
    }

    LONG delta = 0;
    if ( -1 == direction ) {
        delta = -page_size;
        if ( getStart( hwnd ) + delta < getLower( hwnd ) ) {
            delta = getLower( hwnd ) - getStart( hwnd );
        }
    } else {
        delta = page_size;
        if ( getUpper( hwnd ) < getEnd( hwnd ) + delta ) {
            delta = getUpper( hwnd ) - getEnd( hwnd );
        }
    }

    int start = adjust( hwnd, getStart( hwnd ) + delta );
    int end   = adjust( hwnd, getEnd  ( hwnd ) + delta );
    if ( start != getStart( hwnd ) || end != getEnd( hwnd ) ) {
        setStart( hwnd, start );
        setEnd  ( hwnd, end   );
        invalidateRect( hwnd );
        invalidateCursor();
        notifyParent( hwnd );
    }

    // TODO: discuss SPI_GETKEYBOARDDELAY
    if ( 0 < timeOut ) {
        SetTimer( hwnd, 1, timeOut, 0 );
    }
}
Esempio n. 5
0
MyConstantRange binaryOr(const MyConstantRange &Other) const {
  if (isEmptySet() || Other.isEmptySet())
    return MyConstantRange(getBitWidth(), /*isFullSet=*/false);

  if (!isWrappedSet() && !Other.isWrappedSet() && !isFullSet() && !Other.isFullSet()) {
    unsigned width1 = ((getUpper() - 1) ^ getLower()).getActiveBits();
    unsigned width2 = ((Other.getUpper() - 1) ^ Other.getLower()).getActiveBits();
    APInt res1 = getLower().lshr(width1) << width1;
    APInt res2 = Other.getLower().lshr(width2) << width2;
    APInt res_high1 = getLower();
    APInt res_high2 = Other.getLower();
    res_high1.setLowBits(width1);
    res_high2.setLowBits(width2);
    if ((res1 | res2).isNullValue() && (res_high1 | res_high2).isAllOnesValue()) {
        return MyConstantRange(getBitWidth(), /*isFullSet=*/true);
    }
    return MyConstantRange(res1 | res2, (res_high1 | res_high2) + 1);
  }

  APInt umax = APIntOps::umax(getUnsignedMin(), Other.getUnsignedMin());
  if (umax.isNullValue())
    return MyConstantRange(getBitWidth(), /*isFullSet=*/true);
  return MyConstantRange(std::move(umax), APInt::getNullValue(getBitWidth()));
}
Esempio n. 6
0
MyConstantRange binaryAnd(const ConstantRange &Other) const {
  if (isEmptySet() || Other.isEmptySet())
    return MyConstantRange(getBitWidth(), /*isFullSet=*/false);

  if (!isWrappedSet() && !Other.isWrappedSet() && !isFullSet() && !Other.isFullSet()) {
    unsigned width1 = ((getUpper() - 1) ^ getLower()).logBase2() + 1;
    unsigned width2 = ((Other.getUpper() - 1) ^ Other.getLower()).logBase2() + 1;
    APInt res1 = getLower().lshr(width1) << width1;
    APInt res2 = Other.getLower().lshr(width2) << width2;
    APInt res_high1 = getLower();
    APInt res_high2 = Other.getLower();
    res_high1.setLowBits(width1);
    res_high2.setLowBits(width2);
    if ((res1 & res2).isNullValue() && (res_high1 & res_high2).isAllOnesValue()) {
        return MyConstantRange(getBitWidth(), /*isFullSet=*/true);
    }
    return MyConstantRange(res1 & res2, (res_high1 & res_high2) + 1);
  }

  APInt umin = APIntOps::umin(Other.getUnsignedMax(), getUnsignedMax());
  if (umin.isAllOnesValue())
    return MyConstantRange(getBitWidth(), /*isFullSet=*/true);
  return MyConstantRange(APInt::getNullValue(getBitWidth()), std::move(umin) + 1);
}
Esempio n. 7
0
static void notifyParent( HWND hwnd, UINT code = 0 ) {         // NM_ code TODO

    NMRANGESLIDER nm = { { 0 } };
    
    nm.hdr.hwndFrom = hwnd;
    nm.hdr.idFrom = GetWindowID( hwnd );
    nm.hdr.code = code;

    nm.rsInfo._lower       = getLower      ( hwnd );
    nm.rsInfo._upper       = getUpper      ( hwnd );
    nm.rsInfo._start       = getStart      ( hwnd );
    nm.rsInfo._end         = getEnd        ( hwnd );
    nm.rsInfo._minRange    = getMinRange   ( hwnd );
    nm.rsInfo._granularity = getGranularity( hwnd );
    
    FORWARD_WM_NOTIFY(
        GetParent( hwnd ), nm.hdr.idFrom, &nm, SNDMSG );
}
Esempio n. 8
0
int normalize(char *buf, /* The character array containing the string to be normalized*/
              int len    /* the size of the original character array */)
{
  //Print initial array	
  int j=0;
  while(j<len){
    
      printf("%c", (char)buf[j]);
      j++;
    }
  printf("\n");


  char *write=buf; 							//points to writer
  char *read=buf;  							//points to reader
  int i;           							//array index
  int ctr=0;       							//number of deleted characters
  
 for (i=0; i<len; i++){ 						//for each element in the array
	
      if(isspace(*read)!=0){					        //if what read is pointing to is a space
          
       	if(write == buf){					       //if nothing has been written yet
    			
      		while(isspace(*read) != 0){		               //while read is still pointing to a blank
        			
          		read++;				               //increment the location of read
           		ctr++;            			       //increment the amount of unused characters
        		}
      		*write =getLower((int) *read); 		        	//break out of loop and assign write its first character
          	}

        if (isspace(buf[i-1])!=0){				        //if there are two consecutive spaces
         
           	while (isspace(*read) != 0){			       //while there is more than one consecutive space
          
            		read++;						//increment read pointer
          	  	ctr++;					       //increment the amount of unused characters
          	}
          }

       if(buf[i+1]==NULL){          					//if there is one extra trailing space
        ctr++;						                //record it to be deleted
          }
       }

      *write = getLower((int)*read);					//write what is in read

      write++;								//increment write
      read++;								//increment read
    }
  
   int temp = ctr;								
   while(temp > 0){							//for each extra space at the end
    
     	read=NULL;							//assign each extra space null to delete them
     	temp--;
    }

  //print normalized array
  int k=0;
  while(k<len){
    
      printf("%c", (char)buf[k]);
      k++;
    }
  printf("\n");

  	return len - ctr; 						//return the size of the normalized array
}
Esempio n. 9
0
static void onKey(
    HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UINT flags )
{
    long start = getStart( hwnd );
    long end   = getEnd( hwnd );

    const BOOL controlKey = GetAsyncKeyState( VK_CONTROL ) < 0;

    if ( VK_ESCAPE == vk ) {
        if ( htNone != getHTCode( hwnd ) ) {
            setHTCode( hwnd, htNone );
            const LONG oldStart = getSaveStart( hwnd );
            const LONG oldEnd   = getSaveEnd  ( hwnd );
            setStart( hwnd, oldStart );
            setEnd  ( hwnd, oldEnd   );
            invalidateRect( hwnd );
            //onLButtonUp( hwnd, 0, 0, 0 ); // TODO retain capture anyway?
            // TODO notify parent
            return; //** FUNCTION EXIT POINT
        }
    }

    const UINT left_key  = isVertical( hwnd ) ? VK_UP   : VK_LEFT ;
    const UINT right_key = isVertical( hwnd ) ? VK_DOWN : VK_RIGHT;

    long granularity = getGranularity( hwnd );
    if ( granularity <= 0 ) {
        granularity = 1;
    }

    if ( left_key == vk ) {
        if ( controlKey ) {
            if ( getMinRange( hwnd ) < end - start ) {
                end -= granularity;
            }
        } else if ( getLower( hwnd ) < start ) {
            start -= granularity;
            end   -= granularity;
        }
    } else if ( right_key == vk ) {
        if ( end < getUpper( hwnd ) ) {
            end += granularity;
            if ( !controlKey ) {
                start += granularity;
            }
        }
    } else if ( VK_PRIOR == vk ) {
        scroll( hwnd, -1, 0 );
        return; //*** FUNCTION EXIT POINT
    } else if ( VK_NEXT == vk ) {
        scroll( hwnd, 1, 0 );
        return; //*** FUNCTION EXIT POINT
    } else if ( VK_HOME == vk ) {
        const long range = abs( getLower( hwnd ) - start );
        start -= range;
        end   -= range;
    } else if ( VK_END == vk ) {
        const long range = abs( getUpper( hwnd ) - end );
        start += range;
        end   += range;
    }

    start = adjust( hwnd, start );
    end   = adjust( hwnd, end   );
    if ( start != getStart( hwnd ) || end != getEnd( hwnd ) ) {
        setStart( hwnd, start );
        setEnd  ( hwnd, end );
        invalidateRect( hwnd );
        invalidateCursor();
        notifyParent( hwnd );
    }
}
Esempio n. 10
0
inline LONG getRange( HWND hwnd ) {

    return getUpper( hwnd ) - getLower( hwnd );
}
Esempio n. 11
0
      void
      ForceBoundary::applyBoundary()
      {

        std::list<Molecule *> mol;
        std::list<Molecule *>::iterator mi;
        Molecule *m;
        double distanceVector[3];
        //double cornerA[3];
        //double cornerB[3];
        double f[3];
        f[0] = 0;

        /*	cornerA[X] = bBoxMin[X];
         cornerA[Y] = bBoxMin[Y];
         cornerA[Z] = bBoxMin[Z];

         cornerB[X] = bBoxMin[X]+_borderSize[X];
         cornerB[Y] = bBoxMax[Y];
         cornerB[Z] = bBoxMax[Z];


         _moleculeContainer->getRegion(cornerA, cornerB,mol);*/
        getLower(X, mol);
        for (mi = mol.begin(); mi != mol.end(); mi++)
          {
            m = (*mi);
            f[X] = calcFm(m->r(X) - bBoxMin[X]) * fmplus;
            f[Y] = 0;
            f[Z] = 0;
            /*	double r =m->r(X)-bBoxMin[X];
             if(r<0.5) {
             std::cout << m->F(0) << " "<<m->F(1) << " "<<m->F(2) << " X"<< std::endl;

             }*/

            m->Fadd(f);
            /*	if(r<0.5) {
             std::cout << r << " " <<m->F(0) << " "<<m->F(1) << " "<<m->F(2) << " X2"<< std::endl;

             }*/
            if (_RBinFB)
              {
                Molecule dummy(*m);
                dummy.move(X, -2 * m->r(X));
                double dd = dummy.dist2(*m, distanceVector);
                if (dd < 2.0)
                  {
                    std::cout << m->F(0) << " " << m->F(1) << " " << m->F(2)
                        << " X" << std::endl;
                    _particlePairsHandler->processPair(*m, dummy,
                        distanceVector, MOLECULE_HALOMOLECULE, dd, (dd
                            < _LJCutoffRadiusSquare));
                    m->calcFM();
                    std::cout << dd << " " << m->F(0) << " " << m->F(1) << " "
                        << m->F(2) << " X2" << std::endl;
                  }

              }

          }

        mol.clear();
        /*cornerA[X] = bBoxMax[X]-_borderSize[X];
         cornerB[X] = bBoxMax[X];

         _moleculeContainer->getRegion(cornerA, cornerB,mol);*/
        getUpper(X, mol);
        for (mi = mol.begin(); mi != mol.end(); mi++)
          {
            m = (*mi);
            f[X] = -calcFm(bBoxMax[X] - m->r(X)) * fmplus;
            if (_streamOutDir == X)
              f[X] *= _fStreamDamping;
            if (!_fStream || _streamOutDir != X)
              m->Fadd(f);
            if (_RBinFB && _streamOutDir != X)
              {
                Molecule dummy(*m);
                dummy.move(X, 2 * (m->r(X) - _domain->getGlobalLength(X)));
                double dd = dummy.dist2(*m, distanceVector);
                _particlePairsHandler->processPair(*m, dummy, distanceVector,
                    MOLECULE_HALOMOLECULE, dd, (dd < _LJCutoffRadiusSquare));
                //std::cout << dummy.F(0) << " "<<dummy.F(1) << " "<<dummy.F(2) << " -X"<< std::endl;

              }
          }

        mol.clear();
        /*	cornerA[X] = bBoxMin[X];
         cornerB[X] = bBoxMax[X];
         cornerB[Y] = bBoxMin[Y]+_borderSize[Y];

         _moleculeContainer->getRegion(cornerA, cornerB,mol);*/
        getLower(Y, mol);
        for (mi = mol.begin(); mi != mol.end(); mi++)
          {
            m = (*mi);
            f[X] = 0;
            f[Y] = calcFm(m->r(Y) - bBoxMin[Y]) * fmplus;
            m->Fadd(f);
            if (_RBinFB)
              {
                Molecule dummy(*m);
                dummy.move(Y, -2 * m->r(Y));
                double dd = dummy.dist2(*m, distanceVector);
                _particlePairsHandler->processPair(*m, dummy, distanceVector,
                    MOLECULE_HALOMOLECULE, dd, (dd < _LJCutoffRadiusSquare));
              }
          }

        mol.clear();
        /*	cornerA[Y] = bBoxMax[Y]-_borderSize[Y];
         cornerB[Y] = bBoxMax[Y];

         _moleculeContainer->getRegion(cornerA, cornerB,mol);*/
        getUpper(Y, mol);
        for (mi = mol.begin(); mi != mol.end(); mi++)
          {
            m = (*mi);
            f[Y] = -calcFm(bBoxMax[Y] - m->r(Y)) * fmplus;
            if (_streamOutDir == Y)
              f[Y] *= _fStreamDamping;
            if (!_fStream || _streamOutDir != Y)
              m->Fadd(f);
            if (_RBinFB && _streamOutDir != Y)
              {
                Molecule dummy(*m);
                dummy.move(Y, 2 * (m->r(Y) - _domain->getGlobalLength(Y)));
                double dd = dummy.dist2(*m, distanceVector);
                _particlePairsHandler->processPair(*m, dummy, distanceVector,
                    MOLECULE_HALOMOLECULE, dd, (dd < _LJCutoffRadiusSquare));
                //	 std::cout << dummy.F(0) << " "<<dummy.F(1) << " "<<dummy.F(2) << " -Y"<< std::endl;

              }
          }
        if (_dim == 3)
          {
            mol.clear();
            /*cornerA[Y] = bBoxMin[Y];
             cornerB[Y] = bBoxMax[Y];
             cornerB[Z] = bBoxMin[Z]+_borderSize[Z];

             _moleculeContainer->getRegion(cornerA, cornerB,mol);*/
            getLower(Z, mol);

            for (mi = mol.begin(); mi != mol.end(); mi++)
              {
                m = (*mi);
                f[Y] = 0;
                f[Z] = calcFm(m->r(Z) - bBoxMin[Z]) * fmplus;
                m->Fadd(f);
                if (_RBinFB)
                  {
                    Molecule dummy(*m);
                    dummy.move(Z, -2 * m->r(Z));
                    double dd = dummy.dist2(*m, distanceVector);
                    _particlePairsHandler->processPair(*m, dummy,
                        distanceVector, MOLECULE_HALOMOLECULE, dd, (dd
                            < _LJCutoffRadiusSquare));
                    // std::cout << dummy.F(0) << " "<<dummy.F(1) << " "<<dummy.F(2) << " "<< std::endl;
                  }
              }

            mol.clear();
            /*cornerA[Z] = bBoxMax[Z]-_borderSize[Z];
             cornerB[Z] = bBoxMax[Z];

             _moleculeContainer->getRegion(cornerA, cornerB,mol);*/
            getUpper(Z, mol);
            for (mi = mol.begin(); mi != mol.end(); mi++)
              {
                m = (*mi);
                f[Z] = -calcFm(bBoxMax[Z] - m->r(Z)) * fmplus;
                if (_streamOutDir == Z)
                  f[Z] *= _fStreamDamping;
                if (!_fStream || _streamOutDir != Z)
                  m->Fadd(f);
                if (_RBinFB && _streamOutDir != Z)
                  {
                    Molecule dummy(*m);
                    dummy.move(Z, 2 * (m->r(Z) - _domain->getGlobalLength(Z)));
                    double dd = dummy.dist2(*m, distanceVector);
                    _particlePairsHandler->processPair(*m, dummy,
                        distanceVector, MOLECULE_HALOMOLECULE, dd, (dd
                            < _LJCutoffRadiusSquare));

                  }
              }
          }

      }