Exemplo n.º 1
0
/**Assumed that vector W is of a valid length such that # of elements = # of elements in Up-Trig portion of dxd matrix*/
SEXP theta2w(SEXP W){	
	
	int p;
	int *Wdims;
	double *Wptr;
	
	Wdims = getDims(W); //extract dimensions of W
	p = Wdims[0]; //number of entries
	PROTECT(W = coerceVector(W,REALSXP));
	Wptr = REAL(W);	
	
	int d = (sqrt(8*p+1) + 1)/2;	
		
	SEXP ans = identity(&d); //initialize
	SEXP interm; //intermediate matrix 
	int k = 0; //index for W
	
	for(int j=2;j<=d;j++){
		for(int i=j-1;i>=1;i--){			
			
			interm = subs(&d,&i,&j,&Wptr[k]);
			ans = matProd(interm,ans);			
	
			k++;
			
			}//end inner for		
		}//end outer for 	
		
		UNPROTECT(1);		
		return ans;
}//end function theta2w
Exemplo n.º 2
0
bool Cell::operator==(const InternalType& it)
{
    if (const_cast<InternalType &>(it).isCell() == false)
    {
        return false;
    }

    Cell* pC = const_cast<InternalType &>(it).getAs<Cell>();

    for (int i = 0 ; i < getDims() ; i++)
    {
        if (pC->getDimsArray()[i] != getDimsArray()[i])
        {
            return false;
        }
    }

    for (int i = 0 ; i < getSize() ; i++)
    {
        if (get(i) != pC->get(i))
        {
            return false;
        }
    }
    return true;
}
Exemplo n.º 3
0
/**Functions takes in nxd matrix x and generates a 1xd matrix with means of each column in x*/
SEXP genMean(SEXP x) {

    int n, d;
    int *xdims;
    double sum;
    double *ansptr, *xptr;
    SEXP ans;

    xdims = getDims(x);
    n = xdims[0];
    d = xdims[1];

    PROTECT(x = coerceVector(x, REALSXP)); //protect 1
    xptr = REAL(x);

    PROTECT(ans = allocMatrix(REALSXP,1,d)); //protect 2
    ansptr = REAL(ans);

    int k =0; //index for ans

    for(int i=0; i<=(d-1)*n; i=i+n) {
        sum = 0;

        for(int j=i; j<=i+n-1; j++) {
            sum = sum+xptr[j];
        }//end inner for

        ansptr[k] = sum/n;	//calculate mean and store value
        k++;
    }//end outer for

    UNPROTECT(2);
    return(ans);

}//end genMean
Exemplo n.º 4
0
template <typename Derived> void BALPSolverInterface<Derived>::getStates(BAFlagVector<variableState> &s) {
	const BADimensions &dims = getDims();

	int nscen = dims.numScenarios();
	int nvar1 = dims.numFirstStageVars();
	int ncons1 = dims.numFirstStageCons();
	denseFlagVector<variableState> &s1 = s.getFirstStageVec();
	for (int i = 0; i < nvar1; i++) {
		s1[i] = static_cast<Derived*>(this)->getFirstStageColState(i);
	}
	for (int i = 0; i < ncons1; i++) {
		s1[i+nvar1] = static_cast<Derived*>(this)->getFirstStageRowState(i);
	}
	for (int scen = 0; scen < nscen; scen++) {
		if (!s.hasScenario(scen)) continue;
		int nvar2 = dims.numSecondStageVars(scen);
		int ncons2 = dims.numSecondStageCons(scen);
		denseFlagVector<variableState> &s2 = s.getSecondStageVec(scen);
		for (int i = 0; i < nvar2; i++) {
			s2[i] = static_cast<Derived*>(this)->getSecondStageColState(scen,i);
		}
		for (int i = 0; i < ncons2; i++) {
			s2[i+nvar2] = static_cast<Derived*>(this)->getSecondStageRowState(scen,i);
		}
	}

}
Exemplo n.º 5
0
SEXP center(SEXP RA){
    int *dimA;
    double *A;
    
    dimA = getDims(RA);
    if(dimA[0] <= 1) error("er, first dimension is 1? that's weird.");
    if(dimA[1] <= 1) error("er, second dimension is 1? that's weird.");
    PROTECT(RA=coerceVector(RA, REALSXP));
    A = REAL(RA);

    SEXP Rret = PROTECT(duplicate(RA));
    double *ret = REAL(Rret);
    
    int i, j, ind;
    double m;
    for(i = 0; i < dimA[0]; i++){
        ind = i;
        m = mean(A+i, dimA[1], dimA[0]);
        
/*        if( i ==0) {
            printf("%f %f\n", m, s);
        }*/
        
        for(j = 0; j < dimA[1]; j++){
            ret[ind] = A[ind] - m;
            ind += dimA[0];
        }
    }
    
    UNPROTECT(2);
    return Rret;
}
Exemplo n.º 6
0
void Projector::setImage(vector<unsigned char>&  Im, int width, int height, int size) {
  if(width == 0 || height == 0) {
    cerr << "zero image" << endl;
    return;
  }
  if(_width ==0) {
    int tmpw,tmph;
    getDims(&tmpw,&tmph);
  }
  if(width > _width || height > _height) {
    cerr << "image too large" << endl;
    return;
  }
  
  
  if(Im.size() <= size) {
    buff = &Im[0];
    //std::copy(Im.begin(),Im.end(),buff);
  } else {
    cerr << "size doesn't match" << endl;
    return;
  }
  
  int st = am7xxx_send_image(dev,AM7XXX_IMAGE_FORMAT_JPEG,width, height,buff,size);
  if(st<0) {
    cerr << "error displaying image" << endl;

    return;
  }

}
Exemplo n.º 7
0
SEXP R_colSums(SEXP X)
{
  int    *xdims, ii, jj, nrx, ncx;
  double *xptr, *ansptr, sum;
  SEXP ans;
  xdims = getDims(X);
  nrx = xdims[0];
  ncx = xdims[1];

  PROTECT(X = coerceVector(X, REALSXP));
  xptr  = REAL(X);
  PROTECT(ans = allocVector(REALSXP, ncx));
  ansptr = REAL(ans);

  for (jj = 0; jj < ncx; jj++){
    sum = 0;
    for (ii = 0; ii < nrx; ii++){
      sum=sum + xptr[ii + nrx * jj];
    }
    ansptr[jj] = sum;
  }

  UNPROTECT(2);
  return(ans);
}
Exemplo n.º 8
0
 double Point::getValue(int dim) const{
     if(dim <= getDims()){
         return __values[dim];
     }else {
         return 0;
     }
 }
bool TouchScreenSlider::process(){
    unsigned int x, y, w, h;
    getDims(&x, &y, &w, &h);
    
    bool hit=false;
    bool wasChanged = false;
    //do{
        Point p = _controller->getTouchScreen()->getPoint();
        
        if (p.z > _controller->getTouchScreen()->pressureThreshhold) {
            p.x = map(p.x, TS_MINX, TS_MAXX, _controller->getScreenWidth(), 0);
            p.y = map(p.y, TS_MINY, TS_MAXY, _controller->getScreenHeight(), 0);
            hit = checkForHit(p.x , p.y);
            if(hit){
                wasChanged=true;
                if(_layout==HORIZONTAL){
                    unsigned int value = map(p.x, x, x+w-1, 0, 100);
                    setValue((float)value/100);
                    draw(true);
                }else if(_layout==VERTICAL){
                    unsigned int value = map(p.y, y+h-1, y, 0, 100);
                    setValue((float)value/100);
                    draw(true);
                }
            }
        }
    //}while(hit==true);
    return wasChanged;
}
Exemplo n.º 10
0
//This function seeks to do the following lines of R code:
//    mean_x = apply(x,1,mean)
//    sd_x = apply(x,1,sd)
//    z = (z*sd_x) + mean_x
//    z = z/2
//except be really efficient by taking full advantage of passing by
//reference.
SEXP lfa_scaling(SEXP RX, SEXP RZ){
    int *dimX, n, i, ind;
    double *X, *Z, mean, sd;
    
    dimX = getDims(RX);
    PROTECT(RX = coerceVector(RX, REALSXP));
    X = REAL(RX);
    
    PROTECT(RZ = coerceVector(RZ, REALSXP));
    Z = REAL(RZ);
    
    for(n = 0; n < dimX[0]; n++){
        mean = 0;
        sd = 0;
        
        ind = n;
        for(i = 0; i < dimX[1]; i++){
            mean += X[ind];
            ind += dimX[0]; //looping over rows...
        }
        mean = mean/dimX[1];
        
        ind=n;
        for(i = 0; i < dimX[1]; i++){
            Z[ind] *= sd;
            Z[ind] += mean;
            Z[ind] /= 2;
            ind += dimX[0]; //looping over rows...
        }
    }
    
    UNPROTECT(2);
    return R_NilValue;
}
Exemplo n.º 11
0
bool Cell::isEmpty()
{
    if (getDims() == 2 && getRows() == 0 && getCols() == 0)
    {
        return true;
    }
    return false;
}
Exemplo n.º 12
0
ArmaContext* getArma(SEXP x_) {
    ArmaContext* ap;
    switch(TYPEOF(x_)) {
    case REALSXP:
        switch(getDims(x_).size()) {
        case 0:
            ap = new ArmaDouble(x_);
            break;
        case 1:
            ap = new ArmaVec(x_);
            break;
        case 2:
            ap = new ArmaMat(x_);
            break;
        default:
            throw std::logic_error("ERROR: tensor conversion not supported yet.");
        }
        break;
    case LGLSXP:
    case INTSXP:
        switch(getDims(x_).size()) {
        case 0:
            ap = new ArmaInt(x_);
            break;
        case 1:
            ap = new ArmaiVec(x_);
            break;
        case 2:
            ap = new ArmaiMat(x_);
            break;
        default:
            throw std::logic_error("ERROR: tensor conversion not supported yet.");
        }
        break;
    default:
        std::stringstream error_ss;
        error_ss << "ERROR: (getArma) conversion not supported ";
        error_ss << "TYPEOF: " << TYPEOF(x_);
        // if(PRINTNAME(x_) != R_NilValue) {
        //   error_ss << "variable: " << CHAR(PRINTNAME(x_));
        // }
        throw std::logic_error(error_ss.str());
    }
    return ap;
}
Exemplo n.º 13
0
void replaceOptsJob(Json::Value &options, const std::string &jobString) {
  std::map<std::string,std::string> reps;
  reps["$(JOBNUM)"] = jobString;
  Point2D dims = getDims(options);
  std::string size = boost::lexical_cast<std::string>(dims.x) + "x" + boost::lexical_cast<std::string>(dims.y);
  reps["$(SIZE)"] = size;

  jsonReplaceStrings(options,reps);
}
bool TouchScreenArea::checkForHit(unsigned int tx, unsigned int ty){
    unsigned int x, y, w, h;
    getDims(&x, &y, &w, &h);
    
    if(tx>=x && tx<=x+w-1){
        if(ty>=y && ty<=y+h-1){
            draw(true);
            return true;
        }
    }
    return false;
}
Exemplo n.º 15
0
/*
 * Returns a list of arrays given a declarator. 
 */
Type *
getDims(AstNode * n)
{
  if (n == NULL)
    return NULL;

  switch (n->type) {
  case ARRAY_NODE:
    return (Type *) makeArrayType(getDims(((Array *) n)->child));
  default:
    return NULL;
  }
}
Exemplo n.º 16
0
/**Cross Mean. Function takes in nxd matrix x and generates a dxd matrix with means of each column in x*/
SEXP crossMean(SEXP x){	
	int n, d;
	int *xdims;
	double sum;
	double *meanptr, *xptr;
	SEXP mean; 
	
	xdims = getDims(x);
	n = xdims[0];
	d = xdims[1];
	
	PROTECT(x = coerceVector(x, REALSXP)); //PROTECT 1
	xptr = REAL(x);	
	PROTECT(mean = allocMatrix(REALSXP,1,d)); //PROTECT 2
	meanptr = REAL(mean);
	
	int k =0; //index for mean	
	for(int i=0;i<=(d-1)*n;i=i+n){
		sum = 0;		
		for(int j=i;j<=i+n-1;j++){			
			sum = sum+xptr[j];			
			}//end inner for		
		meanptr[k] = sum/n;	//calculate mean and store value
		k++;	
	}//end outer for
			
	/**Mean vector completed. Now generate crossMean vector.*/
	
	SEXP crossM;
	double *crossMptr;
	PROTECT(crossM = allocMatrix(REALSXP,d,d)); //PROTECT 3
	crossMptr = REAL(crossM);
	double prod;
	
	int c = 0; //index for crossMean	
	/**Calculates the mean. First fills the diagonal, then fills the upper and lower triangular portions using symmetry.*/
	for(int i=0; i<d;i++){		
		c = i*(d+1);
		crossMptr[c] = meanptr[i] * meanptr[i];		
		for(int j=i+1;j<d;j++){			
			prod = meanptr[i] * meanptr[j];					
			c = i + j*d;			
			crossMptr[c] = prod;			
			c = j + i*d;
			crossMptr[c] = prod; 
		}//end inner for
	}//end outer for		
	UNPROTECT(3);
	return(crossM);		
}//end crossMean
void TouchScreenButton::draw(bool pressed){
    unsigned int x, y, w, h;
    getDims(&x, &y, &w, &h);
    
    if(pressed){
        _controller->drawRectangle(x, y, w, h, getForeColor(),true);
        _controller->drawRectangle(x, y, w, h, getBackColor(),false);
        _controller->drawString(getText(), x + _padding, y + _padding, _fontSize, getBackColor());
    }else{
        _controller->drawRectangle(x, y, w, h, getBackColor(),true);
        _controller->drawRectangle(x, y, w, h, getForeColor(),false);
        _controller->drawString(getText(), x + _padding, y + _padding, _fontSize, getForeColor());
    }
}
Exemplo n.º 18
0
size_t VsVariableWithMesh::getNumComps() {
  std::vector<int> dims = getDims();
  if (dims.size() <= 0) {
    VsLog::errorLog() << __CLASS__ << __FUNCTION__ << "  " << __LINE__ << "  "
                      << "Unable to get dimensions of variable?" << std::endl;
    return 0;
  }

  size_t lastDim = 0;
  if (isCompMinor())
    lastDim = dims[dims.size()-1];
  else lastDim = dims[0];
  
  return lastDim;
}
Exemplo n.º 19
0
void StickyNoteActor::onRender(uint flags)
{
	if (!isActorType(Invisible))
	{
		if (_stickyNoteTextureId == 0)
			syncStickyNoteWithFileContents();
		
		setTextureID("icon.custom.stickyNote");
		Actor::onRender(flags);
#ifdef DXRENDER
		dxr->device->SetRenderState(D3DRS_ZENABLE, false);
		dxr->renderSideLessBox(getGlobalPosition(), getGlobalOrientation(), getDims(), _stickyNoteTextureId);
		dxr->device->SetRenderState(D3DRS_ZENABLE, true);
#endif
	}
}
Exemplo n.º 20
0
/**logCosh substitution function*/
SEXP logCosh(SEXP X, double *c){
	int nrx, ncx;
	int *xdims;
	double *xptr;

	xdims = getDims(X);
	nrx = xdims[0]; ncx = xdims[1];
	PROTECT(X= coerceVector(X, REALSXP));
	xptr = REAL(X);
	
	for(int i =0; i< nrx*ncx;i++){		
		xptr[i] = 1/(*c) * log10(cosh(*c * xptr[i]));		
		}//end for 
				
		UNPROTECT(1);
		return(X);	
}//end logCosh
Exemplo n.º 21
0
 void MinProblemSolver::Function::getGradient(const double* x, double* grad)
 {
     double eps = getGradientEps();
     int i, n = getDims();
     AutoBuffer<double> x_buf(n);
     double* x_ = x_buf;
     for( i = 0; i < n; i++ )
         x_[i] = x[i];
     for( i = 0; i < n; i++ )
     {
         x_[i] = x[i] + eps;
         double y1 = calc(x_);
         x_[i] = x[i] - eps;
         double y0 = calc(x_);
         grad[i] = (y1 - y0)/(2*eps);
         x_[i] = x[i];
     }
 }
void TouchScreenArrowButton::drawRight(bool pressed){
    unsigned int x, y, w, h;
    getDims(&x, &y, &w, &h);
    
    if(pressed){
        _controller->drawRectangle(x, y, w, h, getForeColor(),true);
        _controller->drawRectangle(x, y, w, h, getBackColor(),false);
        _controller->drawLine(x + _padding, y + _padding, x + w -1 - _padding, y + (h/2), getBackColor()); //top side
        _controller->drawLine(x + _padding, y + h - 1 - _padding, x + w - 1 - _padding, y + (h/2), getBackColor()); //bottom side
        _controller->drawLine(x + _padding, y + _padding, x + _padding, y + h - 1 - _padding, getBackColor()); //left side
    }else{
        _controller->drawRectangle(x, y, w, h, getBackColor(),true);
        _controller->drawRectangle(x, y, w, h, getForeColor(),false);
        _controller->drawLine(x + _padding, y + _padding, x + w -1 - _padding, y + (h/2), getForeColor()); //top side
        _controller->drawLine(x + _padding, y + h - 1 - _padding, x + w - 1 - _padding, y + (h/2), getForeColor()); //bottom side
        _controller->drawLine(x + _padding, y + _padding, x + _padding, y + h - 1 - _padding, getForeColor()); //left side
    }
}
Exemplo n.º 23
0
	void drawText(Bitmap& scr, gvl::cell const& str, int x, int y, int color)
	{
		if (str.buffer.empty())
			return;

		if (str.text_placement != gvl::cell::left)
		{
			int w = getDims(
				reinterpret_cast<char const*>(&str.buffer[0]),
				str.buffer.size());

			if (str.text_placement == gvl::cell::center)
				x -= w / 2;
			else if (str.text_placement == gvl::cell::right)
				x -= w;
		}

		drawText(scr, reinterpret_cast<char const*>(&str.buffer[0]), str.buffer.size(), x, y, color);
	}
Exemplo n.º 24
0
void StickyNoteActor::calculateDialogPoseDims(Mat34& poseOut, Vec3& dimsOut)
{
	POINT windowPos = {0, 0};
	ClientToScreen(winOS->GetWindowsHandle(), &windowPos);
	float dist = 0.0f;
	Vec3 v, w, dir, centroidPt, cornerPt;
	Ray ray;
	NxPlane plane(cam->getDir(), -80.0f);

	// get the centroid point on the plane
	window2world(_editDialog->pos().x() - windowPos.x + _editDialog->width() / 2.0f,
		_editDialog->pos().y() - windowPos.y + _editDialog->height() / 2.0f, v, w);
	dir = w - v;
	dir.normalize();
	ray = Ray(v, dir);
	NxRayPlaneIntersect(ray, plane, dist, centroidPt);

	// get the corner point
	window2world(_editDialog->pos().x() - windowPos.x + _editDialog->width() - _editDialog->getNoteInset(),
		_editDialog->pos().y() - windowPos.y + _editDialog->height() - _editDialog->getNoteInset(), v, w);
	dir = w - v;
	dir.normalize();
	ray = Ray(v, dir);
	NxRayPlaneIntersect(ray, plane, dist, cornerPt);

	// calculate the final dims
	Vec3 diff = centroidPt - cornerPt;
	dimsOut = Vec3 (diff.x, diff.z, getDims().z);
			
	// calculate the final orientation/position
	Mat33 ori;
	Vec3 zaxis = cam->getDir() - cam->getEye();
	zaxis.normalize();
	Vec3 xaxis = cam->getUp().cross(zaxis);
	xaxis.normalize();
	Vec3 yaxis = zaxis.cross(xaxis);
	
	ori.setColumn(0, xaxis);
	ori.setColumn(1, yaxis);
	ori.setColumn(2, zaxis);
	poseOut = Mat34(ori, centroidPt);
}
Exemplo n.º 25
0
void StickyNoteActor::finishedEditing()
{
	// update the file
	if (_stickyNoteText.isModified())
	{
		writeStickyNote(getFullPath(), _stickyNoteText.toPlainText());
		
		// notify the user with a little animation
		setFreshnessAlphaAnim(1.0f, 25);
	}

	// animate back and then finish up the visuals
	if (_tmpAnimationActor)
	{
		Mat34 startPose;
		Vec3 startDims;
		int numTempActorSteps = StickyNoteActorNumTempActorSteps;
		int numStickySteps = StickyNoteActorNumStickySteps;
		if (_tmpAnimationActor->isAnimating())
		{
			animManager->removeAnimation(_tmpAnimationActor);
			startPose = _tmpAnimationActor->getGlobalPose();
			startDims = _tmpAnimationActor->getDims();
			numTempActorSteps = max(1, (int)((_tmpAnimationActor->getAlpha() / 1.0f) * numTempActorSteps));
			numStickySteps = max(1, (int)(((1.0f - getAlpha()) / 1.0f) * numStickySteps));
		}
		else
		{
			calculateDialogPoseDims(startPose, startDims);
		}
		
		_tmpAnimationActor->popActorType(Invisible);
		_tmpAnimationActor->setAlphaAnim(_tmpAnimationActor->getAlpha(), 0.0f, numTempActorSteps);
		_tmpAnimationActor->setSizeAnim(lerpRange(startDims, getDims(), numTempActorSteps, SoftEase));
		_tmpAnimationActor->setPoseAnim(slerpPose(startPose, getGlobalPose(), numTempActorSteps, SoftEase), (FinishedCallBack) FinishEditStickyNoteAfterAnim, NULL);
		_tmpAnimationActor = NULL;
		setAlphaAnim(getAlpha(), 1.0f, numStickySteps);
	}
}
Exemplo n.º 26
0
SEXP lfa_threshold(SEXP RX, SEXP Rthresh){
    int *dimX, n, i, ind;
    double *X, max, min;
    double thresh = (double)(*REAL(Rthresh));
    
    dimX = getDims(RX);
    PROTECT(RX = coerceVector(RX, REALSXP));
    X = REAL(RX);

    if(dimX[1] <1) 
        Rprintf("dimension problem in lfa_threshold...");

    SEXP Rret; //returns boolean list of valid rows
    double *ret;
    PROTECT(Rret = allocVector(REALSXP, dimX[0]));
    ret = REAL(Rret);

    for(n = 0; n < dimX[0]; n++){
        min = X[n]; //set min/max to first element
        max = X[n];
        ind = n + dimX[0]; //start from second element
        for(i = 1; i < dimX[1]; i++){
            if(X[ind] > max)
                max = X[ind];
            else if(X[ind] < min)
                min = X[ind];
            ind += dimX[0]; //iterate across loops of course
        }
        //Rprintf("%f %f\n", max, min);
        if((max < (1-thresh)) && (min > thresh))
            ret[n] = 1;
        else
            ret[n] = 0;
    }
    
    UNPROTECT(2);
    return Rret;
}
void TouchScreenSlider::draw(bool pressed){
    unsigned int x, y, w, h;
    getDims(&x, &y, &w, &h);
    
    if(pressed){
        _controller->drawRectangle(x, y, w, h, getForeColor(),true);
        _controller->drawRectangle(x, y, w, h, getBackColor(),false);
        if(_layout==HORIZONTAL){
            unsigned int thumbSize = map((int)(_value*100), 0, 100, 1, w - (_padding*2));
            _controller->drawRectangle(x + _padding, y + _padding, thumbSize, h - (_padding*2), getBackColor(),true);
            for(int lx=x+_padding+10;lx<w - (_padding*2) + x;lx+=10){ 
                _controller->drawVerticalLine(lx, y + _padding, h - (_padding*2), getForeColor());
            }
        }else if(_layout==VERTICAL){
            unsigned int thumbSize = map((int)(_value*100), 0, 100, 1, h - (_padding*2));
            _controller->drawRectangle(x + _padding, y + _padding + ((h - (_padding*2))-thumbSize), w - (_padding*2), thumbSize,  getBackColor(),true);
            for(int ly=y+_padding+10;ly<h - (_padding*2) + y;ly+=10){ 
                _controller->drawHorizontalLine(x + _padding, ly, w - (_padding*2), getForeColor());
            }
        }
    }else{
        _controller->drawRectangle(x, y, w, h, getBackColor(),true);
        _controller->drawRectangle(x, y, w, h, getForeColor(),false);
        if(_layout==HORIZONTAL){
            unsigned int thumbSize = map((int)(_value*100), 0, 100, 1, w - (_padding*2));
            _controller->drawRectangle(x + _padding, y + _padding, thumbSize, h - (_padding*2), getForeColor(),true);
            for(int lx=x+_padding+10;lx<w - (_padding*2) + x;lx+=10){ 
                _controller->drawVerticalLine(lx, y + _padding, h - (_padding*2), getBackColor());
            }
        }else if(_layout==VERTICAL){
            unsigned int thumbSize = map((int)(_value*100), 0, 100, 1, h - (_padding*2));
            _controller->drawRectangle(x + _padding, y + _padding + ((h - (_padding*2))-thumbSize), w - (_padding*2), thumbSize,  getForeColor(),true);
            for(int ly=y+_padding+10;ly<h - (_padding*2) + y;ly+=10){ 
                _controller->drawHorizontalLine(x + _padding, ly, w - (_padding*2), getBackColor());
            }
        }
    }
}
Exemplo n.º 28
0
SEXP R_colwiseProd(SEXP V, SEXP X)
{

  int    *xdims, nrx, ncx, ii, jj, kk, len_V;
  double *xptr, *vptr;
  xdims = getDims(X);
  nrx = xdims[0];
  ncx = xdims[1];
  len_V = length(V);

  PROTECT(X = coerceVector(X, REALSXP));
  xptr  = REAL(X);

  PROTECT(V = coerceVector(V, REALSXP));
  vptr = REAL(V);

  double *ansptr;
  SEXP ans;
  PROTECT(ans = allocMatrix(REALSXP, nrx, ncx));
  ansptr = REAL(ans);
  
  kk = 0;
  for (jj = 0; jj < ncx; jj++){
    //Rprintf("kk=%i len_V=%i\n", kk, len_V);
    for (ii=0; ii<nrx; ii++){
      ansptr[ii + nrx * jj] = vptr[kk] * xptr[ii + nrx * jj];
    }
    kk++;
    if (kk == len_V){
      //Rprintf("HERE: kk=%i len_V=%i\n", kk, len_V);
      kk=0;
    }
  }
  
  UNPROTECT(3);
  return(ans);
}
Exemplo n.º 29
0
// Takes a codestream and decompresses band at a time.
bool ossim::copyRegionToTile(kdu_core::kdu_codestream& codestream,
                             int discard_levels,
                             kdu_core::kdu_thread_env* threadEnv,
                             kdu_core::kdu_thread_queue* threadQueue,
                             ossimImageData* destTile)
{
   bool result = true;

   if ( destTile && codestream.exists())// && threadEnv && threadQueue )
   {
      try // Kakadu throws exceptions...
      {
         kdu_core::kdu_dims region;
         getDims(destTile->getImageRectangle(), region);

         kdu_core::kdu_dims clipRegion;
         if ( clipRegionToImage(codestream,
                                region,
                                discard_levels,
                                clipRegion) )
         {
            if (region != clipRegion)
            {
               // Not filling whole tile.
               destTile->makeBlank();
            }
            
            const ossimScalarType SCALAR = destTile->getScalarType();
            const ossim_uint32 BANDS = destTile->getNumberOfBands();
            
            kdu_supp::kdu_channel_mapping* mapping = 0;
            int max_layers = INT_MAX;
            kdu_core::kdu_coords expand_numerator(1,1);
            kdu_core::kdu_coords expand_denominator(1,1);
            bool precise = true;
            kdu_core::kdu_component_access_mode access_mode =
               kdu_core::KDU_WANT_OUTPUT_COMPONENTS;
            bool fastest = false;
            
            //---
            // band loop:
            // Note: At some point we may want to be a band selector;
            // in which case, we would loop through the band list.
            // For now just go through all bands and let the ossimBandSelector
            // weed them out.
            //---
            for (ossim_uint32 band = 0; band < BANDS; ++band)
            {
               int single_component = band;
            
               // Start the kdu_region_decompressor.
               kdu_supp::kdu_region_decompressor krd;
               
               if ( krd.start( codestream,
                               mapping,
                               single_component,
                               discard_levels,
                               max_layers,
                               clipRegion,
                               expand_numerator,
                               expand_denominator,
                               precise,
                               access_mode,
                               fastest,
                               threadEnv,
                               threadQueue )
                    == false)
               {
                  std::string e = "kdu_region_decompressor::start error!";
                  throw(ossimException(e));
               }
               
               vector<int> channel_offsets(1);
               channel_offsets[0] = 0;
               int pixel_gap = 1;
               kdu_core::kdu_coords buffer_origin;
               buffer_origin.x = destTile->getImageRectangle().ul().x;
               buffer_origin.y = destTile->getImageRectangle().ul().y;
               int row_gap = region.size.x;
               int suggested_increment = static_cast<int>(destTile->getSize());
               int max_region_pixels = suggested_increment;
               kdu_core::kdu_dims incomplete_region = clipRegion;
               kdu_core::kdu_dims new_region;
               bool measure_row_gap_in_pixels = true;
               
               // For signed int set precision bit to 0 for kakadu.
               int precision_bits = (SCALAR != OSSIM_SINT16) ? codestream.get_bit_depth(0, true) : 0;
               
               switch (SCALAR)
               {
                  case OSSIM_UINT8:
                  {
                     // Get pointer to the tile buffer.
                     kdu_core::kdu_byte* buffer = destTile->getUcharBuf(band);
                     
                     while ( !incomplete_region.is_empty() )
                     {
                        if ( krd.process( buffer,
                                          &channel_offsets.front(),
                                          pixel_gap,
                                          buffer_origin,
                                          row_gap,
                                          suggested_increment,
                                          max_region_pixels,
                                          incomplete_region,
                                          new_region,
                                          precision_bits,
                                          measure_row_gap_in_pixels ) )
                        {
                           break;
                        }
                     }

                     if( threadEnv && threadQueue)
                     {
                        //---
                        // Wait for all queues descended from `root_queue' to identify themselves
                        // as "finished" via the `kdu_thread_queue::all_done' function.
                        //---
                        threadEnv->join(threadQueue, true);
                     }
                     
                     // Validate the tile.
                     destTile->validate();

                     break;
                  }
                  case OSSIM_USHORT11:
                  case OSSIM_UINT16:
                  case OSSIM_SINT16:   
                  {
                     // Get pointer to the tile buffer.
                     kdu_core::kdu_uint16* buffer =
                        static_cast<kdu_core::kdu_uint16*>(destTile->getBuf(band));
                     
                     while ( !incomplete_region.is_empty() )
                     {
                        //---
                        // Note: precision_bits set to 0 to indicate "signed" data
                        // for the region decompressor.
                        //---
                        if ( krd.process( buffer,
                                          &channel_offsets.front(),
                                          pixel_gap,
                                          buffer_origin,
                                          row_gap,
                                          suggested_increment,
                                          max_region_pixels,
                                          incomplete_region,
                                          new_region,
                                          precision_bits,
                                          measure_row_gap_in_pixels ) == false )
                        {
                           break;
                        }
                     }
                     
                     //---
                     // Wait for all queues descended from `root_queue' to identify themselves
                     // as "finished" via the `kdu_thread_queue::all_done' function.
                     //---
                     if( threadEnv && threadQueue)
                     {
                        threadEnv->join(threadQueue, true);
                     }
                     
                     // Validate the tile.
                     destTile->validate();
                  
                     break;
                  }
                  case OSSIM_SINT32:
                  case OSSIM_FLOAT32:
                  {
                     //---
                     // NOTES:
                     // 1) Signed 32 bit integer data gets normalized when compressed
                     //    so use the same code path as float data.
                     // 2) Cannot call "ossimImageData::getFloatBuf" as it will return a
                     //    null pointer if the destination tile is OSSIM_SINT32 scalar type.
                     //---
                     
                     // Get pointer to the tile buffer.
                     ossim_float32* buffer = static_cast<ossim_float32*>(destTile->getBuf(band));
                     
                     while ( !incomplete_region.is_empty() )
                     {
                        //---
                        // Note: precision_bits set to 0 to indicate "signed" data
                        // for the region decompressor.
                        //---
                        if ( krd.process( buffer,
                                          &channel_offsets.front(),
                                          pixel_gap,
                                          buffer_origin,
                                          row_gap,
                                          suggested_increment,
                                          max_region_pixels,
                                          incomplete_region,
                                          new_region,
                                          true, // normalize
                                          measure_row_gap_in_pixels ) == false )
                        {
                           break;
                        }
                     }
               
                     if( threadEnv && threadQueue)
                     {
                        //---
                        // Wait for all queues descended from `root_queue' to identify themselves
                        // as "finished" via the `kdu_thread_queue::all_done' function.
                        //---
                        threadEnv->join(threadQueue, true);
                     }
               
                     // Un-normalize.
                     ossim::unNormalizeTile(destTile);
                     
                     // Validate the tile.
                     destTile->validate();
                     
                     break;
                  }
                  
                  default:
                  {
                     ossimNotify(ossimNotifyLevel_WARN)
                        << __FILE__ << " " << __LINE__ << " Unhandle scalar: "
                        << destTile->getScalarType() << "\n";
                     result = false;
                     break;
                  }
         
               } // End of:  switch (theScalarType)
            
               // Every call to kdu_region_decompressor::start has a finish.
               if ( krd.finish() == false )
               {
                  result = false;
                  ossimNotify(ossimNotifyLevel_WARN)
                     << __FILE__ << " " << __LINE__
                     << " kdu_region_decompressor::proces error!" << std::endl;
               }
               
         
            } // End of band loop.
         }
         else // No region intersect with image.
         {
            destTile->makeBlank();
         }
         
      } // Matches: try{ ...

      // Catch and rethrow exceptions.
      catch( const ossimException& /* e */ )
      {
         throw;
      }
      catch ( kdu_core::kdu_exception exc )
      {
         // kdu_exception is an int typedef.
         if ( threadEnv != 0 )
         {
            threadEnv->handle_exception(exc);
         }
         ostringstream e;
         e << "Caught exception from kdu_region_decompressor: " << exc << "\n";
         throw ossimException( e.str() );
         
      }
      catch ( std::bad_alloc& )
      {
         if ( threadEnv != 0 )
         {
            threadEnv->handle_exception(KDU_MEMORY_EXCEPTION);
         }
         std::string e =
            "Caught exception from kdu_region_decompressor: std::bad_alloc";
         throw ossimException( e );
      }
      catch( ... )
      {
         std::string e =
            "Caught unhandled exception from kdu_region_decompressor";
         throw ossimException(e);
      }
   }
   else  // no codestream
   {
      result = false;
   }

#if 0  /* Please leave for serious debug. (drb) */
   if (destTile)
   {
      static int tileNumber = 0;
      if (destTile)
      {
         ossimFilename f = "tile-dump";
         f += ossimString::toString(tileNumber);
         f += ".ras";
         if (destTile->write(f))
         {
            ossimNotify(ossimNotifyLevel_DEBUG)
               << "wrote: " << f << std::endl;
            ++tileNumber;
         }
      }
   }
#endif
   
   return result;

} // End: ossim::copyRegionToTile
Exemplo n.º 30
0
    // Assign values to an array
    array::array_proxy&
    af::array::array_proxy::operator=(const array &other)
    {
        unsigned nd = numDims(impl->parent_->get());
        const dim4 this_dims = getDims(impl->parent_->get());
        const dim4 other_dims = other.dims();
        int dim = gforDim(impl->indices_);
        af_array other_arr = other.get();

        bool batch_assign = false;
        bool is_reordered = false;
        if (dim >= 0) {
            //FIXME: Figure out a faster, cleaner way to do this
            dim4 out_dims = seqToDims(impl->indices_, this_dims, false);

            batch_assign = true;
            for (int i = 0; i < AF_MAX_DIMS; i++) {
                if (this->impl->indices_[i].isBatch) batch_assign &= (other_dims[i] == 1);
                else                          batch_assign &= (other_dims[i] == out_dims[i]);
            }

            if (batch_assign) {
                af_array out;
                AF_THROW(af_tile(&out, other_arr,
                                 out_dims[0] / other_dims[0],
                                 out_dims[1] / other_dims[1],
                                 out_dims[2] / other_dims[2],
                                 out_dims[3] / other_dims[3]));
                other_arr = out;

            } else if (out_dims != other_dims) {
                // HACK: This is a quick check to see if other has been reordered inside gfor
                // TODO: Figure out if this breaks and implement a cleaner method
                other_arr = gforReorder(other_arr, dim);
                is_reordered = true;
            }
        }

        af_array par_arr = 0;

        if (impl->is_linear_) {
            AF_THROW(af_flat(&par_arr, impl->parent_->get()));
            nd = 1;
        } else {
            par_arr = impl->parent_->get();
        }

        af_array tmp = 0;
        AF_THROW(af_assign_gen(&tmp, par_arr, nd, impl->indices_, other_arr));

        af_array res = 0;
        if (impl->is_linear_) {
            AF_THROW(af_moddims(&res, tmp, this_dims.ndims(), this_dims.get()));
            AF_THROW(af_release_array(par_arr));
            AF_THROW(af_release_array(tmp));
        } else {
            res = tmp;
        }

        impl->parent_->set(res);

        if (dim >= 0 && (is_reordered || batch_assign)) {
            if (other_arr) AF_THROW(af_release_array(other_arr));
        }
        return *this;
    }