Example #1
0
	void
	fill_host(thrust::host_vector<TType> &v)
	{
		int s = size();
		v.resize(s);
		thrust::copy(mBuffer.begin(), mBuffer.begin() + s, v.begin());
	}
Example #2
0
void writeVectorToFile_CPU(thrust::host_vector< thrust::pair<unsigned int, unsigned int> > h_pairVector, thrust::host_vector< float > h_distVector, string pairFileName, string distFileName, unsigned long long count, int fileId) {
	FILE * pairFile, * distFile; 
	string tempStr;	
	char buf[1000];
					
	sprintf(buf, "_%d", fileId);

	tempStr = pairFileName;
	tempStr.append(buf);
	pairFile = fopen(tempStr.c_str(), "wb");
	if (pairFile == NULL){
		printf("cannot open pairFile: %s\n", tempStr.c_str());
		exit(-1);
	}	
	tempStr = distFileName;
	tempStr.append(buf);
	distFile = fopen(tempStr.c_str(), "wb");
	if (distFile == NULL){
		printf("cannot open distFile: %s\n", tempStr.c_str());
		exit(-1);
	}
			
				
	thrust::sort_by_key(h_distVector.begin(), h_distVector.end(), h_pairVector.begin());				
								
	int pairArray[BUF_SIZE*2];
	float distArray[BUF_SIZE];	

	int h = 0;
	thrust::pair<unsigned int, unsigned int> aPair;						
	
	cout << "write to : " << tempStr << " " << count << " pairs" << endl; 
				
	for (unsigned int i = 0; i < count; ++i)
	{					
		aPair = h_pairVector[i];	
		distArray[h] = h_distVector[i];
		pairArray[h*2] = aPair.first;
		pairArray[h*2+1] = aPair.second;		
		++h;		
	/*
		if (i <= 100)
			cout << aPair.first << "\t" << aPair.second << "\t" << distArray[i] << endl;	
	*/
		if (h == BUF_SIZE) {					
			fwrite(pairArray, sizeof(unsigned int), BUF_SIZE * 2, pairFile);		
			fwrite(distArray, sizeof(float), BUF_SIZE, distFile);		
			h = 0;
		}	
	}
	
	if (h > 0) {					
		fwrite(pairArray, sizeof(unsigned int), h * 2, pairFile);		
		fwrite(distArray, sizeof(float), h, distFile);
		h = 0;
	}	
		
	fclose(pairFile);
	fclose(distFile);
}
void LoadBCE_fromFile(thrust::host_vector<Real3> &posRadBCE, // do not set the
                                                             // size here since
                                                             // you are using
                                                             // push back later
                      std::string fileName) {
  std::string ddSt;
  char buff[256];
  int numBce = 0;
  const int cols = 3;
  std::cout << "  reading BCE data from: " << fileName << " ...\n";
  std::ifstream inMarker;
  inMarker.open(fileName);
  if (!inMarker) {
    std::cout << "   Error! Unable to open file: " << fileName << std::endl;
  }
  getline(inMarker, ddSt);
  Real q[cols];
  while (getline(inMarker, ddSt)) {
    std::stringstream linestream(ddSt);
    for (int i = 0; i < cols; i++) {
      linestream.getline(buff, 50, ',');
      q[i] = atof(buff);
    }
    posRadBCE.push_back(mR3(q[0], q[1], q[2]));
    numBce++;
  }

  std::cout << "  Loaded BCE data from: " << fileName << std::endl;
}
Example #4
0
void interactRays(thrust::host_vector<Ray> &h_rays) {
	int n = h_rays.size();
	for (int i = 0; i < n; i++) {
		Ray &r = h_rays[i];
		interact(r);
	}
}
Example #5
0
void traceRays(thrust::host_vector<Ray> &h_rays, Scene &scene) {
	int n = h_rays.size();
	for (int i = 0; i < n; i++) {
		Ray &r = h_rays[i];
		trace(r, scene);
	}
}
Example #6
0
// copy scoring data to host, converting to io::AlignmentResult
void GPUOutputBatch::readback_scores(thrust::host_vector<io::AlignmentResult>& output,
                                     const AlignmentMate mate,
                                     const AlignmentScore score) const
{
    // copy alignment data into a staging buffer
    thrust::host_vector<io::BestAlignments> best_data_staging;
    nvbio::cuda::thrust_copy_vector(best_data_staging, best_data_dvec, count);

    // convert the contents of the staging buffer into io::AlignmentResult
    output.resize(count);
    for(uint32 c = 0; c < count; c++)
    {
        io::BestAlignments&      old_best_aln = best_data_staging[c];
        io::Alignment&           old_aln = (score == BEST_SCORE ? old_best_aln.m_a1 : old_best_aln.m_a2);
        io::AlignmentResult&    new_aln = output[c];

        if (score == BEST_SCORE)
        {
            new_aln.best[mate] = old_aln;
        } else {
            new_aln.second_best[mate] = old_aln;
        }

        if (mate == MATE_2)
        {
            new_aln.is_paired_end = true;
        }
    }
}
// =============================================================================
// note, the function in the current implementation creates boundary BCE (zero
// velocity)
// x=1, y=2, z =3; therefore 12 means creating markers on the top surface
// parallel to xy plane,
// similarly -12 means bottom face paralel to xy. similarly 13, -13, 23, -23
void CreateBCE_On_Box(thrust::host_vector<Real3> &posRadBCE, const Real3 &hsize,
                      int face, SimParams *paramsH) {
  Real initSpace0 = paramsH->MULT_INITSPACE * paramsH->HSML;
  int nFX = ceil(hsize.x / (initSpace0));
  int nFY = ceil(hsize.y / (initSpace0));
  int nFZ = ceil(hsize.z / (initSpace0));

  Real initSpaceX = hsize.x / nFX;
  Real initSpaceY = hsize.y / nFY;
  Real initSpaceZ = hsize.z / nFZ;

  int2 iBound = mI2(-nFX, nFX);
  int2 jBound = mI2(-nFY, nFY);
  int2 kBound = mI2(-nFZ, nFZ);

  switch (face) {
  case 12:
    kBound = mI2(nFZ - paramsH->NUM_BOUNDARY_LAYERS + 1, nFZ);
    break;
  case -12:
    kBound = mI2(-nFZ, -nFZ + paramsH->NUM_BOUNDARY_LAYERS - 1);
    break;
  case 13:
    jBound = mI2(nFY - paramsH->NUM_BOUNDARY_LAYERS + 1, nFY);
    break;
  case -13:
    jBound = mI2(-nFY, -nFY + paramsH->NUM_BOUNDARY_LAYERS - 1);
    break;
  case 23:
    iBound = mI2(nFX - paramsH->NUM_BOUNDARY_LAYERS + 1, nFX);
    break;
  case -23:
    iBound = mI2(-nFX, -nFX + paramsH->NUM_BOUNDARY_LAYERS - 1);
    break;
  default:
    printf("wrong argument box bce initialization\n");
    break;
  }

  for (int i = iBound.x; i <= iBound.y; i++) {
    for (int j = jBound.x; j <= jBound.y; j++) {
      for (int k = kBound.x; k <= kBound.y; k++) {
        Real3 relMarkerPos =
            mR3(i * initSpaceX, j * initSpaceY, k * initSpaceZ);

        if ((relMarkerPos.x < paramsH->cMin.x ||
             relMarkerPos.x > paramsH->cMax.x) ||
            (relMarkerPos.y < paramsH->cMin.y ||
             relMarkerPos.y > paramsH->cMax.y) ||
            (relMarkerPos.z < paramsH->cMin.z ||
             relMarkerPos.z > paramsH->cMax.z)) {
          continue;
        }
        posRadBCE.push_back(relMarkerPos);
      }
    }
  }
}
void CreateBCE_On_Cylinder(thrust::host_vector<Real3> &posRadBCE, Real cyl_rad,
                           Real cyl_h, SimParams *paramsH) {
  // Arman : take care of velocity and w stuff for BCE
  Real spacing = paramsH->MULT_INITSPACE * paramsH->HSML;
  for (Real s = -0.5 * cyl_h; s <= 0.5 * cyl_h; s += spacing) {
    Real3 centerPointLF = mR3(0, s, 0);
    posRadBCE.push_back(centerPointLF);
    for (Real r = spacing; r < cyl_rad - paramsH->solidSurfaceAdjust;
         r += spacing) {
      Real deltaTeta = spacing / r;
      for (Real teta = .1 * deltaTeta;
           teta < 2 * chrono::CH_C_PI - .1 * deltaTeta; teta += deltaTeta) {
        Real3 BCE_Pos_local =
            mR3(r * cos(teta), 0, r * sin(teta)) + centerPointLF;
        posRadBCE.push_back(BCE_Pos_local);
      }
    }
  }
}
// =============================================================================
void CreateBCE_On_Sphere(thrust::host_vector<Real3> &posRadBCE, Real rad,
                         SimParams *paramsH) {
  Real spacing = paramsH->MULT_INITSPACE * paramsH->HSML;

  for (Real r = spacing; r < rad - paramsH->solidSurfaceAdjust; r += spacing) {
    Real deltaTeta = spacing / r;
    Real deltaPhi = deltaTeta;

    for (Real phi = .1 * deltaPhi; phi < chrono::CH_C_PI - .1 * deltaPhi;
         phi += deltaPhi) {
      for (Real teta = .1 * deltaTeta;
           teta < 2 * chrono::CH_C_PI - .1 * deltaTeta; teta += deltaTeta) {
        Real3 BCE_Pos_local = mR3(r * sin(phi) * cos(teta),
                                  r * sin(phi) * sin(teta), r * cos(phi));
        posRadBCE.push_back(BCE_Pos_local);
      }
    }
  }
}
Example #10
0
	void initRays() {
		int n = h_rays.size();
		int w = width, h = height;
		for (int i = 0; i < n; i++) {
			Ray &r = h_rays[i];
			r.done = false;
			r.color = Vector3(0, 0, 0);
			
			int ix = i%w;
			int iy = i/w;
			Number px = ((Number)ix + (Number)0.5)/w;
			Number py = ((Number)iy + (Number)0.5)/h;
			r.pos = frustum.pointOnNearPlane(px, py);
			r.dir = r.pos - eye;
			r.dir.normalize();
			addVector(eye, r.pos);
			addVectorDir(r.pos, r.dir);
		}
	}
Example #11
0
void GLWindow::paintGL()
{
    timer->stop();

    if (frame_count == 0) gettimeofday(&begin, 0);

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    if (wireframe) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective( cameraFOV, 1.0, 1.0, grid_size*4.0);

    // set view matrix for 3D scene
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();

    qrot.getRotMat(rotationMatrix);
    glMultMatrixf(rotationMatrix);

//    glTranslatef(-(grid_size-1)/2, -(grid_size-1)/2, -(grid_size-1)/2);
    size_t num_bytes;  GLenum drawType = GL_TRIANGLES;

#ifdef TANGLE
    #ifdef USE_INTEROP
        isosurface->vboResources[0] = quads_pos_res;  isosurface->vboResources[1] = quads_color_res;  isosurface->vboResources[2] = quads_normal_res;
        isosurface->minIso = 31.0f;  isosurface->maxIso = 500.0f;  isosurface->useInterop = true;
        isosurface->vboSize = buffer_size;
    #endif
        (*isosurface)();
    #ifndef USE_INTEROP
        vertices.assign(isosurface->vertices_begin(), isosurface->vertices_end());
        normals.assign(isosurface->normals_begin(), isosurface->normals_end());
        colors.assign(thrust::make_transform_iterator(isosurface->scalars_begin(), color_map<float>(31.0f, 500.0f)),
                      thrust::make_transform_iterator(isosurface->scalars_end(), color_map<float>(31.0f, 500.0f)));
     #endif
#endif

#ifdef CUTPLANE
    #ifdef USE_INTEROP
        cutplane->vboResources[0] = quads_pos_res;  cutplane->vboResources[1] = quads_color_res;  cutplane->vboResources[2] = quads_normal_res;
        cutplane->minIso = 0.0f;  cutplane->maxIso = 1.0f;  cutplane->useInterop = true;
        cutplane->vboSize = buffer_size;
    #endif
    (*cutplane)();
    #ifndef USE_INTEROP
        vertices.assign(cutplane->vertices_begin(), cutplane->vertices_end());
        normals.assign(cutplane->normals_begin(), cutplane->normals_end());
        colors.assign(thrust::make_transform_iterator(cutplane->scalars_begin(), color_map<float>(0.0f, 1.0f)),
                      thrust::make_transform_iterator(cutplane->scalars_end(), color_map<float>(0.0f, 1.0f)));
    #endif
#endif

#ifdef THRESHOLD
    #ifdef USE_INTEROP
        threshold->vboResources[0] = quads_pos_res;  threshold->vboResources[1] = quads_color_res;  threshold->vboResources[2] = quads_normal_res;
        threshold->minThresholdRange = 4.0f;  threshold->maxThresholdRange = 1600.0f;  threshold->useInterop = true;
        threshold->vboSize = buffer_size;
    #endif
    (*threshold)();
    #ifndef USE_INTEROP
        vertices.resize(threshold->vertices_end() - threshold->vertices_begin());
        normals.resize(threshold->normals_end() - threshold->normals_begin());
        thrust::device_vector<float4> device_colors(vertices.size());
//        thrust::copy(thrust::make_transform_iterator(threshold->vertices_begin(), tuple2float4()),
//                     thrust::make_transform_iterator(threshold->vertices_end(), tuple2float4()), vertices.begin());
        thrust::copy(threshold->vertices_begin(),
                     threshold->vertices_end(),
                     vertices.begin());
        thrust::copy(threshold->normals_begin(), threshold->normals_end(), normals.begin());
        thrust::transform(threshold->scalars_begin(), threshold->scalars_end(), device_colors.begin(), color_map<float>(4.0f, 1600.0f));
        colors = device_colors;
    #endif
    drawType = GL_QUADS;
#endif

#ifdef USE_INTEROP
    glBindBuffer(GL_ARRAY_BUFFER, quads_vbo[0]);
    glVertexPointer(4, GL_FLOAT, 0, 0);

    glBindBuffer(GL_ARRAY_BUFFER, quads_vbo[1]);
    glNormalPointer(GL_FLOAT, 0, 0);

    glBindBuffer(GL_ARRAY_BUFFER, quads_vbo[2]);
    glColorPointer(4, GL_FLOAT, 0, 0);

    glDrawArrays(drawType, 0, buffer_size/sizeof(float4));
#else
    glColorPointer(4, GL_FLOAT, 0, &colors[0]);
    glNormalPointer(GL_FLOAT, 0, &normals[0]);
    glVertexPointer(4, GL_FLOAT, 0, &vertices[0]);
    glDrawArrays(drawType, 0, vertices.size());
#endif

    glPopMatrix();

    gettimeofday(&end, 0);
    timersub(&end, &begin, &diff);
    frame_count++;
    float seconds = diff.tv_sec + 1.0E-6*diff.tv_usec;
    if (seconds > 0.5f)
    {
      char title[256];
      sprintf(title, "Marching Cube, fps: %2.2f", float(frame_count)/seconds);
      std::cout << title << std::endl;
      seconds = 0.0f;
      frame_count = 0;
    }

    timer->start(1);
}
Example #12
0
 static void resize( thrust::host_vector< T > &x , const thrust::host_vector< T > &y )
 {
     x.resize( y.size() );
 }
Example #13
0
 static bool same_size( const thrust::host_vector< T > &x , const thrust::host_vector< T > &y )
 {
     return x.size() == y.size();
 }