Пример #1
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);
}
Пример #2
0
	void
	fill_host(thrust::host_vector<TType> &v)
	{
		int s = size();
		v.resize(s);
		thrust::copy(mBuffer.begin(), mBuffer.begin() + s, v.begin());
	}
Пример #3
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);
}