Exemple #1
0
int main(int argc, char *argv[]) {
    hs_init(&argc,&argv);

    // load test input
    int n1 = 5;
    TPoint proto[5] = {{0,0},{0.5,0},{1,0},{1,1},{0,1}};
    
    int n2 = 4;
    TPoint target[4] = {{1.1,0.1},{1.1,0.9},{-0.1,0.9},{-0.1,0.1}};
    
    // output
    int m;
    TPoint *res;
    double h[3][3];

    hfun(n1,proto,n2,target,&m,&res,h);
        
    printf("%d\n", m);
    int k;
    for (k=0; k<m; k++) {
        printf("px=%f  py=%f\n",res[k].x,res[k].y);
    }
    int j;
    for (j=0; j<3; j++) {
        for (k=0; k<3; k++) {
            printf("%f\n",h[j][k]);
         }
    }
    free(res);
    
    hs_exit();
    return 0;
}
/**
 * @brief constructor for QUProfileController
 * @param parent
 * @param wcsHelper - coordinate/value formatter
 * @param id
 * @param title
 * @param willDoFitting
 */
QUProfileController::QUProfileController(QObject * parent,
                                         const QString & id,
                                         const QString & title)
    : QObject(parent)
{
    m_myId = id;
    m_pwPrefix = QString( "/quprofile-%1/").arg( m_myId);
    m_viewName = QString( "quprofile-%1").arg( m_myId);
    m_initialized = false;

    // create a render buffer
    m_buffer = QImage( 2, 2, QImage::QImage::Format_RGB888);

    // setup fonts
    m_labelFont = QFont( "Helvetica", 8);
    m_captionFont = QFont( "Helvetica", 10, QFont::Normal);
    m_labelFontMetrics.reset( new QFontMetricsF( m_labelFont));
    m_captionFontMetrics.reset( new QFontMetricsF( m_captionFont));

    // register a view with pureweb
    CSI::PureWeb::Server::ViewImageFormat viewImageFormat;
    viewImageFormat.PixelFormat = CSI::PureWeb::PixelFormat::Rgb24;
    viewImageFormat.ScanLineOrder = CSI::PureWeb::ScanLineOrder::TopDown;
    viewImageFormat.Alignment = 4;
    GetStateManager().ViewManager().RegisterView(
                m_viewName.toStdString(), this);
    GetStateManager().ViewManager().SetViewImageFormat(
                m_viewName.toStdString(), viewImageFormat);
    GetStateManager ().ViewManager ().SetViewInteracting(
                m_viewName.toStdString(), false);

    // register PureWeb callback for all commands
    GetStateManager().CommandManager().AddUiHandler(
                ("quprofile-" + m_myId).toStdString(),
                CSI::Bind(this, & QUProfileController::commandDispatcher ));

    // cursor requests are arriving as state changes
    GetStateManager().XmlStateManager().AddValueChangedHandler(
                QString("/requests/quprofile-%1/mouseHover").arg(m_myId).toStdString(),
                CSI::Bind(this, &QUProfileController::mouseHoverRequestCB));

    // set some defaults
    m_total = 0;
    m_cursorIndex = -1;
    m_autoZoom = true;

    // setup the colormap function (cached)
    {
        ColormapFunction cmap = ColormapFunction::sunbow();
        cmap.setRgbScales( 0.5, 0.5, 0.5);
        HistogramColormapFunctor hfun( 0, 1, cmap);
        m_cmap.reset( new CachedRgbFunction( hfun, 0, 1, 256, Rgb(0,0,0)));
    }

    m_updateTimer = new QTimer( this);
    m_updateTimer->setSingleShot( true);
    m_updateTimer->setInterval(1);

    // set up the graph labelers
    m_vertLabeler = std::make_shared< Plot2dLabelers::BasicLabeler >();
//    m_vertLabeler-> setDual( false);
    m_horizLabeler = std::make_shared< Plot2dLabelers::BasicLabeler >();
//    m_horizLabeler-> setDual( false);

    // connect our update timer to callback
    connect( m_updateTimer, SIGNAL(timeout()), this, SLOT(updateTimerCB()));

    // create global variables reflecting the state of the object
    m_ignoreVarCallbacks = true;
    binder( this, m_vars.dotSize, "dotSize", 2.5);
    binder( this, m_vars.transparency, "transparency", 0.5);
    binder( this, m_vars.showCursor, "showCursor", true);
    binder( this, m_vars.showMean, "showMean", true);
    binder( this, m_vars.showGrid, "showGrid", true);
    binder( this, m_vars.showSunbow, "showSunbow", true);
    binder( this, m_vars.showConnectingLines, "showConnect", false);
    binder( this, m_vars.visibleOnClient, "visibleOnClient", false);

    // outgoing variables (no need to assign callbacks to these)
    m_vars.qVal.reset( new GlobalState::StringVar( m_pwPrefix + "q"));
    m_vars.uVal.reset( new GlobalState::StringVar( m_pwPrefix + "u"));
    m_vars.qMean.reset( new GlobalState::StringVar( m_pwPrefix + "qmean"));
    m_vars.uMean.reset( new GlobalState::StringVar( m_pwPrefix + "umean"));
    m_vars.frame.reset( new GlobalState::StringVar( m_pwPrefix + "frame"));
    m_vars.title.reset( new GlobalState::StringVar( m_pwPrefix + "title"));
    m_vars.title-> set( title);

    // unsuspend callback
    m_ignoreVarCallbacks = false;

    markDirty();
}
Exemple #3
0
void part2grid(struct PART *part, struct CPUINFO *cpu,int npart){

  int i;
  struct OCT *nextoct;
  struct OCT *curoct;
  struct PART *curp;

  for(i=0;i<npart;i++){
    unsigned long long key;
    unsigned long long hidx;
    
    int found=0;
    key=pos2key(part[i].x,part[i].y,part[i].z,part[i].level);
    hidx=hfun(key,cpu->maxhash);
    nextoct=cpu->htable[hidx];
    if(nextoct!=NULL){
      do{ // resolving collisions
	curoct=nextoct;
	nextoct=curoct->nexthash;
	found=((oct2key(curoct,curoct->level)==key)&&(part[i].level==curoct->level));
      }while((nextoct!=NULL)&&(!found));
    }
    
    if(found){ // the reception oct has been found
      
      REAL dxcur=POW(0.5,part[i].level);
      
      int xp=(int)((part[i].x-curoct->x)/dxcur);//xp=(xp>1?1:xp);xp=(xp<0?0:xp);
      int yp=(int)((part[i].y-curoct->y)/dxcur);//yp=(yp>1?1:yp);yp=(yp<0?0:yp);
      int zp=(int)((part[i].z-curoct->z)/dxcur);//zp=(zp>1?1:zp);zp=(zp<0?0:zp);
      int ip=xp+yp*2+zp*4;
      
      
      // the reception cell 
      struct CELL *newcell=&(curoct->cell[ip]);
      struct OCT *newoct;
      REAL dxcur2;

      // if refined we assign the particle to a refined cell
      if(newcell->child!=NULL){
	newoct=newcell->child;
	dxcur2=1./POW(2.,newoct->level);

	// new cell coordinates
	xp=(int)(DFACT*(part[i].x-newoct->x)/dxcur2);

	/* if(xp>1){ */
	/*   printf("WEIRDA !!\n"); */
	/*   printf("px=%e ox=%e dxcur2=%e xp=%d\n",part[i].x,newoct->x,dxcur2,xp); */
	/*   abort(); */
	/* } */
	xp=(xp>1?1:xp);
	xp=(xp<0?0:xp);
	yp=(int)(DFACT*(part[i].y-newoct->y)/dxcur2);yp=(yp>1?1:yp);yp=(yp<0?0:yp);
	zp=(int)(DFACT*(part[i].z-newoct->z)/dxcur2);zp=(zp>1?1:zp);zp=(zp<0?0:zp);
	ip=xp+yp*2+zp*4;
	
	newcell=&(newoct->cell[ip]);

      }
      // ready to assign part to cell

      curp=findlastpart(newcell->phead);
      if(curp!=NULL){
	curp->next=part+i;
	part[i].next=NULL;
	part[i].prev=curp;
      }
      else{
	newcell->phead=part+i;
	part[i].next=NULL;
	part[i].prev=NULL;
      }
    }
  }
}