예제 #1
0
파일: DFT.hpp 프로젝트: nomissretep/codeare
/**
 * @brief         FFT shift
 * 
 * @param   m     TO be shifted
 * @return        Shifted
 */
template <class T> inline Matrix<T>
fftshift (const Matrix<T>& m, const bool& fw = true) {

	assert (isvec(m) || is2d(m) || is3d(m));

	Matrix<size_t> tmp = resize(size(m),ndims(m),1);
	for (size_t i = 0; i<ndims(m); i++)
		if (tmp[i] == 0)
			tmp[i] = 1;

	container<size_t> d = tmp.Container(); // data side lengths
	container<size_t> c = floor(tmp/2).Container(); // center coords

    Matrix<T> res (vsize(m));

    size_t oi[3];
    size_t si[3];

	for (oi[0] = 0; oi[0] < d[0]; oi[0]++) {
		si[0] = (oi[0] + c[0]) % d[0];
		for (oi[1] = 0; oi[1] < d[1]; oi[1]++) {
			si[1] = (oi[1] + c[1]) % d[1];
			for (oi[2] = 0; oi[2] < d[2]; oi[2]++) {
				si[2] = (oi[2] + c[2]) % d[2];
				if (fw)
					res(si[0],si[1],si[2]) = m(oi[0],oi[1],oi[2]);
				else
					res(oi[0],oi[1],oi[2]) = m(si[0],si[1],si[2]);
			}
		}
	}

	return res;

}
예제 #2
0
void kgmMesh::rebound()
{
  m_bound = box3();

  if(!m_vertices)
    return;

  u8 *v = (u8*) m_vertices;
  vec3 max = ((Vertex*)v)->pos,
       min = ((Vertex*)v)->pos;

  u32 i    = 0;
  u32 size = vsize();

  for(i = 1; i < m_vcount; i++)
  {
    v += size;

    min.x = MIN(min.x, ((Vertex*)v)->pos.x);
    min.y = MIN(min.y, ((Vertex*)v)->pos.y);
    min.z = MIN(min.z, ((Vertex*)v)->pos.z);
    max.x = MAX(max.x, ((Vertex*)v)->pos.x);
    max.y = MAX(max.y, ((Vertex*)v)->pos.y);
    max.z = MAX(max.z, ((Vertex*)v)->pos.z);
  }

  m_bound.min = min;
  m_bound.max = max;
}
예제 #3
0
void vflsh()
{
VPAGE *vp;
VPAGE *vlowest;
long addr;
VFILE *vfile;
int x;
for(vfile=vfiles.link.next;
    vfile!=&vfiles;
    vfile=vfile->link.next)
 {
 loop:
 addr= MAXLONG;
 vlowest=0;
 for(x=0;x!=HTSIZE;x++)
  for(vp=htab[x];vp;vp=vp->next)
   if(vp->addr<addr && vp->dirty && vp->vfile==vfile && !vp->count)
    addr=vp->addr, vlowest=vp;
 if(vlowest)
  {
/*  if(!vfile->name) vfile->name=mktmp("/tmp/"); */  /* changed p,w. wong */

  char *pwstring="c:/joe";
  
  if (getenv("JOERC")) pwstring = getenv("JOERC");
  if(!vfile->name) vfile->name=mktmp(pwstring); 
  if(!vfile->fd)
   {
   vfile->fd=Fopen(vfile->name);
   }
  Fseek(vfile->fd,addr);
  if(addr+PGSIZE>vsize(vfile))
   {
   Fwrite(vfile->fd,vlowest->data,(int)(vsize(vfile)-addr));
   vfile->size=vsize(vfile);
   }
  else
   {
   Fwrite(vfile->fd,vlowest->data,PGSIZE);
   if(addr+PGSIZE>vfile->size) vfile->size=addr+PGSIZE;
   }
  vlowest->dirty=0;
  goto loop;
  }
 }
}
예제 #4
0
kgmMesh::kgmMesh(const kgmMesh& msh)
{
  m_rtype = msh.m_rtype;

  m_vcount = msh.m_vcount;
  m_fcount = msh.m_fcount;
  m_fvf    = msh.m_fvf;
  m_fff    = msh.m_fff;
  m_group  = msh.m_group;

  vAlloc(m_vcount, (kgmMesh::FVF)m_fvf);
  fAlloc(m_fcount, (kgmMesh::FFF)m_fff);

  memcpy(m_vertices, msh.m_vertices, m_vcount * vsize());
  memcpy(m_faces, msh.m_faces, m_fcount * fsize());
}
예제 #5
0
void RaspCamMW::_extUISetUp() {
    _vview = new VideoView(ui->videow);
    QSize vsize(ui->videow->size());
    _vview->setSize(vsize);
    ui->btnRecord->setEnabled(false);
    ui->btnStart->setEnabled(false);
    ui->btnStop->setEnabled(false);
    ui->btn_confirm->setEnabled(false);
    ui->le_bright->setEnabled(false);
    ui->le_BitRate->setEnabled(false);
    ui->le_fps->setEnabled(false);
    ui->le_height->setEnabled(false);
    ui->le_width->setEnabled(false);
    ui->btn_remoteRcd->setEnabled(false);
    ui->btn_getrecord->setEnabled(false);
    ui->btnSnap->setEnabled(false);
}
예제 #6
0
void GameChat::draw_player_chat(GameState* gs) const {
	perf_timer_begin(FUNCNAME);
	const ldraw::Font& font = gs->font();
	const int padding = 5;
	int line_sep = font.height() + 2;

	Size vsize(gs->view().size());
	Size chat_size(vsize.w, 100);
	Pos chat_pos(0, 0);
	Pos text_pos(chat_pos.x + padding, chat_pos.y + padding);

	ldraw::draw_rectangle(COL_CONSOLE_BOX.alpha(50 * fade_out),
			BBox(chat_pos, chat_size));

	bool draw_typed_message = is_typing || !typing_field.empty();

	int start_msg = 0;
	int message_space = chat_size.h - padding * 2
			- (draw_typed_message ? line_sep : 0);
	int msgs_in_screen = message_space / line_sep;
	if (messages.size() > msgs_in_screen) {
		start_msg = messages.size() - msgs_in_screen;
	}

	for (int i = start_msg; i < messages.size(); i++) {
		messages[i].draw(font, fade_out, text_pos);
		text_pos.y += line_sep;
	}

	if (draw_typed_message) {
		int type_y = chat_pos.y + chat_size.h - padding - line_sep;

		ldraw::draw_line(Colour(200, 200, 200, fade_out * 180),
				Pos(chat_pos.x, type_y), Pos(chat_pos.x + chat_size.w, type_y));
		ChatMessage typed_message = get_field_as_chat_message(gs, false);
		typed_message.draw(font, fade_out,
				Pos(text_pos.x, type_y + padding - 1));
	}
	perf_timer_end(FUNCNAME);
}
예제 #7
0
파일: DFT.hpp 프로젝트: nomissretep/codeare
	inline Matrix<CT>
	shift (const Matrix<CT>& m, const bool& fw = true) const {

		Matrix<CT> res (vsize(m));

		size_t xi,yi,zi,xs,ys,zs;
		for (zi = 0; zi < d[2]; zi++) {
			zs = (zi + c[2]) % d[2];
			for (yi = 0; yi < d[1]; yi++) {
				ys = (yi + c[1]) % d[1];
				for (xi = 0; xi < d[0]; xi++) {
					xs = (xi + c[0]) % d[0];
					if (fw)
						res(xs,ys,zs) = m(xi,yi,zi);
					else
						res(xi,yi,zi) = m(xs,ys,zs);
				}
			}
		}

		return res;

	}
예제 #8
0
	void Window::drawWindow(Renderer2D &out, IRect rect, FColor color, int outline) {
		FColor lighter(color.rgb() * 1.2f, color.a);
		FColor darker(color.rgb() * 0.8f, color.a);
		int aoutline = fwk::abs(outline);

		if(outline) {
			int2 hsize(rect.width(), aoutline);
			int2 vsize(aoutline, rect.height());

			FColor col1 = outline < 0? darker : lighter;
			out.addFilledRect(IRect(rect.min, rect.min + hsize), col1);
			out.addFilledRect(IRect(rect.min, rect.min + vsize), col1);

			int2 p1(rect.min.x, rect.max.y - aoutline);
			int2 p2(rect.max.x - aoutline, rect.min.y);
			FColor col2 = outline < 0? lighter : darker;
			out.addFilledRect(IRect(p1, p1 + hsize), col2);
			out.addFilledRect(IRect(p2, p2 + vsize), col2);
		}

		int2 off(aoutline, aoutline);
		out.addFilledRect(inset(rect, off, off), color);
	}
예제 #9
0
void kgmMesh::rebuild()
{
  if (m_linked)
    return;

  if(!m_vertices)
    return;

  u8 *v = (u8*) m_vertices;
  vec3 max = ((Vertex*)v)->pos,
       min = ((Vertex*)v)->pos;

  u32 i    = 0;
  u32 size = vsize();

  for(i = 1; i < m_vcount; i++)
  {
    v += size;

    Vertex* vt = (Vertex*)v;

    min.x = MIN(min.x, ((Vertex*)v)->pos.x);
    min.y = MIN(min.y, ((Vertex*)v)->pos.y);
    min.z = MIN(min.z, ((Vertex*)v)->pos.z);
    max.x = MAX(max.x, ((Vertex*)v)->pos.x);
    max.y = MAX(max.y, ((Vertex*)v)->pos.y);
    max.z = MAX(max.z, ((Vertex*)v)->pos.z);
  }

  m_bound.min = min;
  m_bound.max = max;

  u8* f     = (u8*)m_faces;

  if (!f)
    return;

  v = (u8*) m_vertices;

  if (!v)
    return;

  m_normal = vec3(0, 0, 0);

  i = 0;

  for (i = 0; i < m_fcount; i++)
  {
    triangle tr;
    Face*    fc = (Face*)f;

    Vertex *v1, *v2, *v3;
    u32     f1,  f2,  f3;

    if (m_fff == FFF_16) {
      f1 = ((Face_16*)fc)->a;
      f2 = ((Face_16*)fc)->b;
      f3 = ((Face_16*)fc)->c;
    } else {
      f1 = ((Face_32*)fc)->a;
      f2 = ((Face_32*)fc)->b;
      f3 = ((Face_32*)fc)->c;
    }

    v1 = (Vertex*) ((u8*)m_vertices + vsize() * f1);
    v2 = (Vertex*) ((u8*)m_vertices + vsize() * f2);
    v3 = (Vertex*) ((u8*)m_vertices + vsize() * f3);

    tr = triangle(v1->pos, v2->pos, v3->pos);

    vec3 n = tr.normal();

    n.normalize();
    m_normal = m_normal + n;

    f += fsize();
  }

  m_normal.normalize();
}
예제 #10
0
void ParmetisPartitioner::_do_repartition (MeshBase & mesh,
                                           const unsigned int n_sbdmns)
{
  libmesh_assert_greater (n_sbdmns, 0);

  // Check for an easy return
  if (n_sbdmns == 1)
    {
      this->single_partition(mesh);
      return;
    }

  // This function must be run on all processors at once
  libmesh_parallel_only(mesh.comm());

  // What to do if the Parmetis library IS NOT present
#ifndef LIBMESH_HAVE_PARMETIS

  libmesh_here();
  libMesh::err << "ERROR: The library has been built without" << std::endl
               << "Parmetis support.  Using a Metis"          << std::endl
               << "partitioner instead!"                      << std::endl;

  MetisPartitioner mp;

  mp.partition (mesh, n_sbdmns);

  // What to do if the Parmetis library IS present
#else

  // Revert to METIS on one processor.
  if (mesh.n_processors() == 1)
    {
      MetisPartitioner mp;
      mp.partition (mesh, n_sbdmns);
      return;
    }

  LOG_SCOPE("repartition()", "ParmetisPartitioner");

  // Initialize the data structures required by ParMETIS
  this->initialize (mesh, n_sbdmns);

  // Make sure all processors have enough active local elements.
  // Parmetis tends to crash when it's given only a couple elements
  // per partition.
  {
    bool all_have_enough_elements = true;
    for (processor_id_type pid=0; pid<_n_active_elem_on_proc.size(); pid++)
      if (_n_active_elem_on_proc[pid] < MIN_ELEM_PER_PROC)
        all_have_enough_elements = false;

    // Parmetis will not work unless each processor has some
    // elements. Specifically, it will abort when passed a NULL
    // partition array on *any* of the processors.
    if (!all_have_enough_elements)
      {
        // FIXME: revert to METIS, although this requires a serial mesh
        MeshSerializer serialize(mesh);
        MetisPartitioner mp;
        mp.partition (mesh, n_sbdmns);
        return;
      }
  }

  // build the graph corresponding to the mesh
  this->build_graph (mesh);


  // Partition the graph
  std::vector<Parmetis::idx_t> vsize(_pmetis->vwgt.size(), 1);
  Parmetis::real_t itr = 1000000.0;
  MPI_Comm mpi_comm = mesh.comm().get();

  // Call the ParMETIS adaptive repartitioning method.  This respects the
  // original partitioning when computing the new partitioning so as to
  // minimize the required data redistribution.
  Parmetis::ParMETIS_V3_AdaptiveRepart(_pmetis->vtxdist.empty() ? libmesh_nullptr : &_pmetis->vtxdist[0],
                                       _pmetis->xadj.empty()    ? libmesh_nullptr : &_pmetis->xadj[0],
                                       _pmetis->adjncy.empty()  ? libmesh_nullptr : &_pmetis->adjncy[0],
                                       _pmetis->vwgt.empty()    ? libmesh_nullptr : &_pmetis->vwgt[0],
                                       vsize.empty()            ? libmesh_nullptr : &vsize[0],
                                       libmesh_nullptr,
                                       &_pmetis->wgtflag,
                                       &_pmetis->numflag,
                                       &_pmetis->ncon,
                                       &_pmetis->nparts,
                                       _pmetis->tpwgts.empty()  ? libmesh_nullptr : &_pmetis->tpwgts[0],
                                       _pmetis->ubvec.empty()   ? libmesh_nullptr : &_pmetis->ubvec[0],
                                       &itr,
                                       &_pmetis->options[0],
                                       &_pmetis->edgecut,
                                       _pmetis->part.empty()    ? libmesh_nullptr : &_pmetis->part[0],
                                       &mpi_comm);

  // Assign the returned processor ids
  this->assign_partitioning (mesh);

#endif // #ifndef LIBMESH_HAVE_PARMETIS ... else ...

}
예제 #11
0
void vntick(){
  if( pvnscks != NULL ){
    static fd_set rds, wts;
    u32 i, mfd = 0;
    struct timeval tv = { 0, 0 };
    f32 curt = vcurTime();

    mfd = 0;

    for( i = 0; i < pvnconsSize; ++i ){
      if( curt - pvntimes[ i ] > vn_timeout )
        pvnremcon( i );
    }  

    FD_ZERO( &rds );
    for( i = 0; i < pvnscksSize; ++i ){
      if( pvnscks[ i ] > mfd )
        mfd = pvnscks[ i ];
#pragma warning( push )
#pragma warning( disable: 4127 )
      FD_SET( pvnscks[ i ], &rds );
#pragma warning( pop )
    }  
    if( mfd ){ 
      pvncheck( "select failed!", select( mfd + 1, &rds, NULL, NULL, &tv ), NULL, NULL );
      for( i = 0; i < pvnscksSize; ++i ){
        if( FD_ISSET( pvnscks[ i ], &rds ) ){
          SOCKET as = accept( pvnscks[ i ], NULL, NULL );
          pvncheck( "accept failed", as, NULL, NULL );
          pvnaddcon( &as, pvncbs[ i ] );
        }
      }
    }

    FD_ZERO( &rds );
    FD_ZERO( &wts );
    mfd = 0;
    for( i = 0; i < pvnconsSize; ++i ){
      if( pvncons[ i ] > mfd )
        mfd = pvncons[ i ];
#pragma warning( push )
#pragma warning( disable: 4127 )
      FD_SET( pvncons[ i ], &rds );
      FD_SET( pvncons[ i ], &wts );
#pragma warning( pop )
    }  
    if( mfd ){
      pvncheck( "select failed!", select( mfd + 1, &rds, NULL, NULL, &tv ), NULL, NULL );

      for( i = 0; i < pvnconsSize; ++i ){
        u32 qn = ( (u32*)vmem( pvnqs ) )[ i ];
        if( FD_ISSET( pvncons[ i ], &rds ) ){
          static u8 buf[ vnbufsize ];
          int ans = recv( pvncons[ i ], buf, vnbufsize - 1, 0 );
          pvncheck( "recv failed!", ans, NULL, NULL );
          if( ans == SOCKET_ERROR )
            ans = 0;
          if( !ans ){
            pvnremcon( i );
          } else{
            ans = pvnccbs[ i ]( buf, ans, pvncids[ i ], vcurTime() );
            if( !ans )
              pvnremcon( i ); 
            else if( vsize( ans ) ){
              vappend( qn, vmem( ans ), vsize( ans ) );
            }
          }
        }
        if( FD_ISSET( pvncons[ i ], &wts ) && vsize( qn ) ){
          int ans = send( pvncons[ i ], vmem( qn ), vsize( qn ), 0 );
          pvncheck( "send failed!", ans, NULL, NULL );
          if( ans == SOCKET_ERROR )
            ans = 0;
          if( (u32)ans != vsize( qn ) ){
            u32 ns = vsize( qn ) - (u32)ans;
            u8* tb = vsmalloc( ns );
            vmemcpy( tb, ((u8*)vmem( qn )) + ans, ns );
            verase( qn );
            vappend( qn, tb, ns );
            vsfree( tb );
          }else
            verase( qn );
        }
      }
    }
  } 
}
예제 #12
0
    bool ParMetisPartitioner::partition(map<int, double>& elemWeights,
                                        PartitionMode mode)
    {
      FUNCNAME("ParMetisPartitioner::partition()");

      int mpiSize = mpiComm->Get_size();


      // === Create parmetis mesh ===

      if (parMetisMesh)
        delete parMetisMesh;

      TEST_EXIT_DBG(elementInRank.size() != 0)("Should not happen!\n");

      parMetisMesh = new ParMetisMesh(mesh, mpiComm, elementInRank, mapLocalGlobal);

      int nElements = parMetisMesh->getNumElements();


      // === Create weight array ===

      vector<int> wgts(nElements);
      vector<float> floatWgts(nElements);
      unsigned int floatWgtsPos = 0;
      float maxWgt = 0.0;

      TraverseStack stack;
      ElInfo* elInfo = stack.traverseFirst(mesh, 0, Mesh::CALL_EL_LEVEL);
      while (elInfo)
      {
        int index = elInfo->getElement()->getIndex();

        if (elementInRank[index])
        {
          // get weight
          float wgt = static_cast<float>(elemWeights[index]);
          maxWgt = std::max(wgt, maxWgt);

          // write float weight
          TEST_EXIT_DBG(floatWgtsPos < floatWgts.size())("Should not happen!\n");
          floatWgts[floatWgtsPos++] = wgt;
        }
        elInfo = stack.traverseNext(elInfo);
      }

      TEST_EXIT_DBG(floatWgtsPos == floatWgts.size())("Should not happen!\n");

      float tmp;
      mpiComm->Allreduce(&maxWgt, &tmp, 1, MPI_FLOAT, MPI_MAX);
      maxWgt = tmp;


      // === Create dual graph ===

      ParMetisGraph parMetisGraph(parMetisMesh, mpiComm);


      // === Partitioning of dual graph ===

      int wgtflag = 2; // weights at vertices only!
      int numflag = 0; // c numbering style!
      int ncon = 1; // one weight at each vertex!
      int nparts = mpiSize; // number of partitions

      vector<double> tpwgts(mpiSize);
      double ubvec = 1.05;
      int options[4] = {0, 0, 15, PARMETIS_PSR_COUPLED}; // default options
      int edgecut = -1;
      vector<int> part(nElements);

      // set tpwgts
      for (int i = 0; i < mpiSize; i++)
        tpwgts[i] = 1.0 / static_cast<double>(nparts);

      //     float scale = 10000.0 / maxWgt;
      for (int i = 0; i < nElements; i++)
        wgts[i] = floatWgts[i];
      //      wgts[i] = static_cast<int>(floatWgts[i] * scale);


      // === Start ParMETIS. ===

      MPI_Comm tmpComm = MPI_Comm(*mpiComm);

      switch (mode)
      {
      case INITIAL:
        ParMETIS_V3_PartKway(parMetisMesh->getElementDist(),
                             parMetisGraph.getXAdj(),
                             parMetisGraph.getAdjncy(),
                             &(wgts[0]),
                             NULL,
                             &wgtflag,
                             &numflag,
                             &ncon,
                             &nparts,
                             &(tpwgts[0]),
                             &ubvec,
                             options,
                             &edgecut,
                             &(part[0]),
                             &tmpComm);
        break;
      case ADAPTIVE_REPART:
      {
        vector<int> vsize(nElements);
        for (int i = 0; i < nElements; i++)
          vsize[i] = static_cast<int>(floatWgts[i]);

        ParMETIS_V3_AdaptiveRepart(parMetisMesh->getElementDist(),
                                   parMetisGraph.getXAdj(),
                                   parMetisGraph.getAdjncy(),
                                   &(wgts[0]),
                                   NULL,
                                   &(vsize[0]),
                                   &wgtflag,
                                   &numflag,
                                   &ncon,
                                   &nparts,
                                   &(tpwgts[0]),
                                   &ubvec,
                                   &itr,
                                   options,
                                   &edgecut,
                                   &(part[0]),
                                   &tmpComm);
      }
      break;
      case REFINE_PART:
        ParMETIS_V3_RefineKway(parMetisMesh->getElementDist(),
                               parMetisGraph.getXAdj(),
                               parMetisGraph.getAdjncy(),
                               &(wgts[0]),
                               NULL,
                               &wgtflag,
                               &numflag,
                               &ncon,
                               &nparts,
                               &(tpwgts[0]),
                               &ubvec,
                               options,
                               &edgecut,
                               &(part[0]),
                               &tmpComm);

        break;
      default:
        ERROR_EXIT("unknown partitioning mode\n");
      }


      // === Distribute new partition data. ===

      return distributePartitioning(&(part[0]));
    }
예제 #13
0
void 
CTimeSliceView::OnDraw( CDC* pDC )
{
   CTimeSliceDoc* pDoc = GetDocument();
   ASSERT_VALID( pDoc );

   CTimeSliceDoc::CameraInfo& camera = pDoc->m_arCameraInfo[ m_iCamera ];
   
   //
   // Resize the window for the current bitmap size - this takes into account
   // the vertical tweak.
   //
   CRect vsize(
      0,
      0, 
      camera.m_pbitmapinfo32->bmiHeader.biWidth, 
      -camera.m_pbitmapinfo32->bmiHeader.biHeight );
   
   CWnd* pframe = GetParentFrame();
   
   ::AdjustWindowRectEx( &vsize, GetStyle(), FALSE, GetExStyle() );
   ::AdjustWindowRectEx( &vsize, pframe->GetStyle(), FALSE, pframe->GetExStyle() );
   
   pframe->SetWindowPos(
      NULL,
      0,
      0,
      vsize.Width(),
      vsize.Height(),
      SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
   
   switch( m_viewType )
   {
   case CTimeSliceDoc::SINGLE_CAMERA:
      
      drawImage( camera, camera.m_imageProcessed.pData, pDC );
      drawAlignCross( pDoc, pDC );
      break;
      
   case CTimeSliceDoc::PANNING:
      {	 
	 char  pszTitle[ 256 ];
	 sprintf( 
	    pszTitle, 
	    "Panning - %d", 
	    pDoc->m_cameraInfoTimeSlice.m_info.SerialNumber );	 
	 
	 GetParentFrame()->SetWindowText( pszTitle );
	 
         drawImage( 
	    pDoc->m_cameraInfoTimeSlice, 
	    pDoc->m_cameraInfoTimeSlice.m_pTimesliceImageBuffer,
	    pDC );
 
	 //
	 // Update the frame rate in the status bar (do it here since
	 // there's only one panning view.
	 //	 
	 CMainFrame* pFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;
	 pFrame->updateFrameRate( 
            pDoc->m_dFrameRate,
            pDoc->m_uiMissedImages, 
            pDoc->m_uiOutOfSyncImages );

      }
      break;
      
   default:
      ASSERT( FALSE );
   }
}