コード例 #1
0
ファイル: queue.cpp プロジェクト: javakat/ego
    Queue (std::string filename) {
      head = new Node("H", 0, 0, 0);
      /* Open 'filename' and add the trace elements to the list. */
      Helpers h;
      std::string line;
      std::ifstream f(filename.c_str());
      if (f.is_open()) {
        while (getline(f, line)) {
          std::istringstream iss(line);
          line = "";
          std::string s;
          while(iss >> s){
               if (!line.empty()) line += " " + s;
               else line = s;
          }
          std::vector<std::string> x = h.separate(line, ' ');
          Node *n = new Node(x[0], atol(x[1].c_str()), atol(x[2].c_str()), atol(x[3].c_str()));
//std::cout << x[0] << ", " << atol(x[1].c_str()) << ", " << atol(x[2].c_str()) << ", " << atol(x[3].c_str()) << std::endl;
          number_of_processes = number_of_processes + 1;
          total_number_of_ticks = total_number_of_ticks + atol(x[2].c_str());
          push(n);
        }
        f.close();
      }
      else std::cout << "Unable to open file\n";
コード例 #2
0
  float operator()(const PixelType& a, const PixelType& b) const
  {
    using Helpers::length;
    using ITKHelpers::length;
    using Helpers::index;
    using ITKHelpers::index;
    assert(length(a) == length(b));

    float pixelDifference = 0.0f;
    for(unsigned int component = 0; component < N; ++component)
    {
      float componentDifference = fabs(index(a,component) - index(b,component));
      pixelDifference += componentDifference;
    }
    return pixelDifference;
  }
  float operator()(const PixelType& a, const PixelType& b) const
  {
    using Helpers::length;
    using ITKHelpers::length;
    using Helpers::index;
    using ITKHelpers::index;
    assert(length(a) == length(b));

    //assert(length(a) == Weights.size());
    if(length(a) != Weights.size())
    {
      std::stringstream ss;
      ss << "length(a) != Weights.size(). a is " << length(a) << " and weights is " << Weights.size();
      throw std::runtime_error(ss.str());
    }
    
    float pixelDifference = 0.0f;
    for(unsigned int component = 0; component < length(a); ++component)
      {
      float componentDifference = Weights[component] * fabs(index(a,component) - index(b,component));
      pixelDifference += componentDifference;
      }
    return pixelDifference;
  }
コード例 #4
0
void CannonBall::initScene( InitialCameraData& camera_data )
{
	// Two Rays, on light and one shadow
	m_context->setRayTypeCount( 2 );
	m_context->setEntryPointCount( 1 );
	m_context->setStackSize( 2520 );

	m_context["max_depth"]->setInt( 6 );
    m_context["radiance_ray_type"]->setUint( 0u );
    m_context["shadow_ray_type"]->setUint( 1u );
    m_context["scene_epsilon"]->setFloat( 1.e-3f );

	// Output buffer
	optix::Variable output_buffer = m_context["output_buffer"];

    output_buffer->set(createOutputBuffer(RT_FORMAT_UNSIGNED_BYTE4, WIDTH, HEIGHT ) );

	// Set up camera
    camera_data = InitialCameraData( optix::make_float3( 8.3f, 4.0f, -20.0f ), // eye
                                     optix::make_float3( 0.5f, 0.3f,  1.0f ), // lookat
                                     optix::make_float3( 0.0f, 1.0f,  0.0f ), // up
                                     60.0f );                          // vfov

    // Declare camera variables.  The values do not matter, they will be overwritten in trace.
    m_context["eye"]->setFloat( optix::make_float3( 0.0f, 0.0f, 0.0f ) );
    m_context["U"]->setFloat( optix::make_float3( 0.0f, 0.0f, 0.0f ) );
    m_context["V"]->setFloat( optix::make_float3( 0.0f, 0.0f, 0.0f ) );
    m_context["W"]->setFloat( optix::make_float3( 0.0f, 0.0f, 0.0f ) );

	// Ray generation program
	std::string ptx_path = helpers.getPTXPath( project_name, "pinhole_camera.cu" );
	optix::Program ray_gen_program = m_context->createProgramFromPTXFile( ptx_path, "pinhole_camera" );
	m_context->setRayGenerationProgram( 0, ray_gen_program );

	// Exception program
	optix::Program exception_program = m_context->createProgramFromPTXFile( ptx_path, "exception" );
    m_context->setExceptionProgram( 0, exception_program );
    m_context["bad_color"]->setFloat( 0.0f, 1.0f, 0.0f );

	// Miss program
	m_context->setMissProgram( 0, m_context->createProgramFromPTXFile( helpers.getPTXPath( project_name, "constantbg.cu" ), "miss" ) );
    m_context["bg_color"]->setFloat( optix::make_float3(108.0f/255.0f, 166.0f/255.0f, 205.0f/255.0f) * 0.5f );

	// Setup lights
    m_context["ambient_light_color"]->setFloat(0,0,0);
    BasicLight lights[] = { 
      { { -7.0f, 15.0f, -7.0f }, { .8f, .8f, .8f }, 1 }
    };

    optix::Buffer light_buffer = m_context->createBuffer(RT_BUFFER_INPUT);
    light_buffer->setFormat(RT_FORMAT_USER);
    light_buffer->setElementSize(sizeof(BasicLight));
    light_buffer->setSize( sizeof(lights)/sizeof(lights[0]) );
    memcpy(light_buffer->map(), lights, sizeof(lights));
    light_buffer->unmap();

    m_context["lights"]->set(light_buffer);

	// Create scene geometry
	createGeometry();

	// FInalize
	m_context->validate();
	m_context->compile();
}
コード例 #5
0
void CannonBall::createGeometry()
{
	// Material programs
	const std::string transparency_ptx = helpers.getPTXPath( project_name, "transparent.cu" );
	optix::Program transparent_ch = m_context->createProgramFromPTXFile( transparency_ptx, "closest_hit_radiance" );
	optix::Program transparent_ah = m_context->createProgramFromPTXFile( transparency_ptx, "any_hit_shadow" );

	// Box programs
	const std::string box_ptx = helpers.getPTXPath( project_name, "box.cu" );
	optix::Program box_bounds    = m_context->createProgramFromPTXFile( box_ptx, "box_bounds" );
	optix::Program box_intersect = m_context->createProgramFromPTXFile( box_ptx, "box_intersect" );

	// Box programs
	const std::string sphere_ptx = helpers.getPTXPath( project_name, "sphere.cu" );
	optix::Program sphere_bounds    = m_context->createProgramFromPTXFile( sphere_ptx, "bounds" );
	optix::Program sphere_intersect = m_context->createProgramFromPTXFile( sphere_ptx, "intersect" );

	//////////////////////////////////////////////////////////////
	// Boxes
	//////////////////////////////////////////////////////////////

	std::vector<optix::Geometry> box_geometries;
	std::vector<optix::Material> box_materials;
	for(int i = 0; i < total_boxes; ++i)
	{
		// Geometry
		optix::Geometry box = m_context->createGeometry();
		box->setPrimitiveCount( 1u );
		box->setBoundingBoxProgram( box_bounds );
		box->setIntersectionProgram( box_intersect );

		box["boxmin"]->setFloat( -box_size.x, -box_size.y, -box_size.z );
		box["boxmax"]->setFloat( box_size.x, box_size.y, box_size.z );

		// Material
		optix::Material box_matl = m_context->createMaterial();
		box_matl->setClosestHitProgram( 0, transparent_ch );
		box_matl->setAnyHitProgram( 1, transparent_ah );

		box_matl["Kd"]->setFloat( optix::make_float3( 0.0f, 0.0f, 0.0f ) );
		box_matl["Ks"]->setFloat( optix::make_float3( 0.2f, 0.2f, 0.2f ) );
		box_matl["Ka"]->setFloat( optix::make_float3( 0.05f, 0.05f, 0.05f ) );
		box_matl["phong_exp"]->setFloat(32);
		box_matl["refraction_index"]->setFloat( 1.2f );

		float3 Kd = optix::make_float3( 0.0f, 0.8f, 1.0f );
		box_matl["transmissive_map"]->setTextureSampler( loadTexture( m_context, "", Kd ) );

		box_geometries.push_back(box);
		box_materials.push_back(box_matl);
	}

	//////////////////////////////////////////////////////////////
	// spheres
	//////////////////////////////////////////////////////////////

	std::vector<optix::Geometry> sphere_geometries;
	std::vector<optix::Material> sphere_materials;
	for(int i = 0; i < total_spheres; ++i)
	{
		// Geometry
		optix::Geometry sphere = m_context->createGeometry();
		sphere->setPrimitiveCount( 1u );
		sphere->setBoundingBoxProgram( sphere_bounds );
		sphere->setIntersectionProgram( sphere_intersect );

		sphere["sphere"]->setFloat( 0.0f, 0.0f, 0.0f, sphere_radius );
		sphere["matrix_row_0"]->setFloat( 1.0f, 0.0f, 0.0f );
		sphere["matrix_row_1"]->setFloat( 0.0f, 1.0f, 0.0f );
		sphere["matrix_row_2"]->setFloat( 0.0f, 0.0f, 1.0f );

		// Material
		optix::Material sphere_matl = m_context->createMaterial();
		sphere_matl->setClosestHitProgram( 0, transparent_ch );
		sphere_matl->setAnyHitProgram( 1, transparent_ah );

		sphere_matl["Kd"]->setFloat( optix::make_float3( 0.0f, 0.0f, 0.0f ) );
		sphere_matl["Ks"]->setFloat( optix::make_float3( 0.3f, 0.3f, 0.3f ) );
		sphere_matl["Ka"]->setFloat( optix::make_float3( 0.0f, 0.0f, 0.0f ) );
		float3 Kd = optix::make_float3( 0.0f, 1.0f, 0.8f );
		sphere_matl["transmissive_map"]->setTextureSampler( loadTexture( m_context, "", Kd ) );
		sphere_matl["phong_exp"]->setFloat(64);
		sphere_matl["refraction_index"]->setFloat( 1.0f );

		sphere_geometries.push_back(sphere);
		sphere_materials.push_back(sphere_matl);
	}

	//////////////////////////////////////////////////////////////
	// Floor
	//////////////////////////////////////////////////////////////

	// Geometry
	optix::Geometry parallelogram = m_context->createGeometry();
	parallelogram->setPrimitiveCount( 1u );

	const std::string parellelogram_ptx = helpers.getPTXPath( project_name, "parallelogram.cu" );
	parallelogram->setBoundingBoxProgram( m_context->createProgramFromPTXFile( parellelogram_ptx, "bounds" ) );
	parallelogram->setIntersectionProgram( m_context->createProgramFromPTXFile( parellelogram_ptx, "intersect" ) );
	float3 anchor = optix::make_float3( -20.0f, 0.01f, 20.0f);
	float3 v1 = optix::make_float3( 40, 0, 0);
	float3 v2 = optix::make_float3( 0, 0, -40);
	float3 normal = cross( v1, v2 );
	normal = normalize( normal );
	float d = dot( normal, anchor );
	v1 *= 1.0f/dot( v1, v1 );
	v2 *= 1.0f/dot( v2, v2 );
	optix::float4 plane = optix::make_float4( normal, d );
	parallelogram["plane"]->setFloat( plane );
	parallelogram["v1"]->setFloat( v1 );
	parallelogram["v2"]->setFloat( v2 );
	parallelogram["anchor"]->setFloat( anchor );

	// Material
	optix::Material floor_matl = m_context->createMaterial();
	floor_matl->setClosestHitProgram( 0, transparent_ch );
	floor_matl->setAnyHitProgram( 1, transparent_ah );

	floor_matl["Kd"]->setFloat( optix::make_float3( 0.7f, 0.7f, 0.7f ) );
	floor_matl["Ks"]->setFloat( optix::make_float3( 0.0f, 0.0f, 0.0f ) );
	floor_matl["Ka"]->setFloat( optix::make_float3( 0.05f, 0.05f, 0.05f ) );
	floor_matl["transmissive_map"]->setTextureSampler( loadTexture( m_context, "", optix::make_float3( 0.0f, 0.0f, 0.0f ) ) );
	floor_matl["phong_exp"]->setFloat(32);
	floor_matl["refraction_index"]->setFloat( 1.0f );

	//////////////////////////////////////////////////////////////
	// Groups
	//////////////////////////////////////////////////////////////

	// Boxes Groups
	std::vector<optix::Transform> box_ts;
	for( unsigned int i = 0; i < box_geometries.size(); ++i ) {
		// GeometryInstance
		optix::GeometryInstance gi = m_context->createGeometryInstance(); 
		gi->setGeometry( box_geometries[i] );
		gi->setMaterialCount( 1 );
		gi->setMaterial( 0, box_materials[i] );

		// GeometryGroup
		optix::GeometryGroup box_group = m_context->createGeometryGroup();
		box_group->setChildCount( 1u );
		box_group->setChild( 0, gi );
		box_group->setAcceleration( m_context->createAcceleration("Bvh","Bvh") );

		// Transform
		optix::Transform box_transform = m_context->createTransform();
		box_transform->setChild(box_group);

		box_ts.push_back(box_transform);
	}

	boxes_group = m_context->createGroup();
	boxes_group->setChildCount( static_cast<unsigned int>(box_ts.size()) );
	for ( unsigned int i = 0; i < box_ts.size(); ++i ) { 
		boxes_group->setChild( i, box_ts[i] );
	}
	boxes_group->setAcceleration( m_context->createAcceleration("Bvh","Bvh") );

	// Spheres Groups
	std::vector<optix::Transform> sphere_ts;
	for( unsigned int i = 0; i < sphere_geometries.size(); ++i ) {
		// GeometryInstance
		optix::GeometryInstance gi = m_context->createGeometryInstance(); 
		gi->setGeometry( sphere_geometries[i] );
		gi->setMaterialCount( 1 );
		gi->setMaterial( 0, sphere_materials[i] );

		// GeometryGroup
		optix::GeometryGroup sphere_group = m_context->createGeometryGroup();
		sphere_group->setChildCount( 1u );
		sphere_group->setChild( 0, gi );
		sphere_group->setAcceleration( m_context->createAcceleration("Bvh","Bvh") );

		// Transform
		optix::Transform sphere_transform = m_context->createTransform();
		sphere_transform->setChild(sphere_group);

		sphere_ts.push_back(sphere_transform);
	}

	spheres_group = m_context->createGroup();
	spheres_group->setChildCount( static_cast<unsigned int>(sphere_ts.size()) );
	for ( unsigned int i = 0; i < sphere_ts.size(); ++i ) { 
		spheres_group->setChild( i, sphere_ts[i] );
	}
	spheres_group->setAcceleration( m_context->createAcceleration("Bvh","Bvh") );

	// Floor Group
	optix::GeometryInstance floor_gi = m_context->createGeometryInstance( parallelogram, &floor_matl, &floor_matl+1 );

	optix::GeometryGroup floor_group = m_context->createGeometryGroup();
	floor_group->setChildCount( 1u );
	floor_group->setChild( 0, floor_gi );
	floor_group->setAcceleration( m_context->createAcceleration("Bvh","Bvh") );

	// Main Group
	optix::Group main_group = m_context->createGroup();
	main_group->setChildCount(3u);
	main_group->setChild(0, boxes_group);
	main_group->setChild(1, spheres_group);
	main_group->setChild(2, floor_group);
	main_group->setAcceleration( m_context->createAcceleration("NoAccel","NoAccel") );

	m_context["top_object"]->set( main_group );
	m_context["top_shadower"]->set( main_group );
};