Пример #1
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);
	}
}
Пример #2
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);
	}
}
Пример #3
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);
		}
	}
Пример #4
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);
}
Пример #5
0
 static void resize( thrust::host_vector< T > &x , const thrust::host_vector< T > &y )
 {
     x.resize( y.size() );
 }
Пример #6
0
 static bool same_size( const thrust::host_vector< T > &x , const thrust::host_vector< T > &y )
 {
     return x.size() == y.size();
 }