void MeshScene::saveAccelCache() { // If accel caching on, marshallize the accel if( m_accel_caching_on && !m_accel_cache_loaded ) { const std::string cachefile = getCacheFileName(); // Get data from accel Acceleration accel = m_geometry_group->getAcceleration(); RTsize size = accel->getDataSize(); char* data = new char[size]; accel->getData( data ); // Write to file std::ofstream out( cachefile.c_str(), std::ofstream::out | std::ofstream::binary ); if( !out ) { delete[] data; std::cerr << "could not open acceleration cache file '" << cachefile << "'" << std::endl; return; } out.write( data, size ); delete[] data; std::cerr << "acceleration cache written: '" << cachefile << "'" << std::endl; } }
void MeshScene::loadAccelCache() { // If acceleration caching is turned on and a cache file exists, load it. if( m_accel_caching_on ) { const std::string cachefile = getCacheFileName(); std::ifstream in( cachefile.c_str(), std::ifstream::in | std::ifstream::binary ); if ( in ) { unsigned long long int size = 0ull; #ifdef WIN32 // This is to work around a bug in Visual Studio where a pos_type is cast to an int before being cast to the requested type, thus wrapping file sizes at 2 GB. WTF? To be fixed in VS2011. FILE *fp = fopen(cachefile.c_str(), "rb"); _fseeki64(fp, 0L, SEEK_END); size = _ftelli64(fp); fclose(fp); #else // Read data from file in.seekg (0, std::ios::end); std::ifstream::pos_type szp = in.tellg(); in.seekg (0, std::ios::beg); size = static_cast<unsigned long long int>(szp); #endif std::cerr << "acceleration cache file found: '" << cachefile << "' (" << size << " bytes)\n"; if(sizeof(size_t) <= 4 && size >= 0x80000000ULL) { std::cerr << "[WARNING] acceleration cache file too large for 32-bit application.\n"; m_accel_cache_loaded = false; return; } char* data = new char[static_cast<size_t>(size)]; in.read( data, static_cast<std::streamsize>(size) ); // Load data into accel Acceleration accel = m_geometry_group->getAcceleration(); try { accel->setData( data, static_cast<RTsize>(size) ); m_accel_cache_loaded = true; } catch( optix::Exception& e ) { // Setting the acceleration cache failed, but that's not a problem. Since the acceleration // is marked dirty and builder and traverser are both set already, it will simply build as usual, // without using the cache. So we just warn the user here, but don't do anything else. std::cerr << "[WARNING] could not use acceleration cache, reason: " << e.getErrorString() << std::endl; m_accel_cache_loaded = false; } delete[] data; } else { m_accel_cache_loaded = false; std::cerr << "no acceleration cache file found\n"; } } }
void SolveAccelerationProblems2() { //1. In 0.5 seconds, a projectile goes from 0 to 300 m/s. What is the acceleration of the // projectile? Acceleration const rep1 = Velocity( 300. ) / Second( .5 ); Scalar const _rep1 = rep1.GetValue(); Assert( fequal( _rep1, 600. ) ); //2. A meteoroid changed velocity from 1.0 km/s to 1.8 km/s in 0.03 seconds. What is // the acceleration of the meteoroid? Acceleration const rep2 = (Kilovelocity( 1.8 ) - Kilovelocity( 1. )) / Second( .03 ); Scalar const _rep2 = rep2.GetValue(); Assert( fequal( _rep2, 26666.6666666666667 ) ); //3. The space shuttle releases a space telescope into orbit around the earth. The // telescope goes from being stationary to traveling at a speed of 1700 m/s in 25 // seconds. What is the acceleration of the satellite? Acceleration const rep3 = Velocity( 1700. ) / Second( 25. ); Scalar const _rep3 = rep3.GetValue(); Assert( fequal( _rep3, 68. ) ); //4. A dragster in a race accelerated from stop to 60 m/s by the time it reached the // finish line. The dragster moved in a straight line and traveled from the starting line to // the finish line in 8.0 sec. What was the acceleration of the dragster? Acceleration const rep4 = Velocity( 60. ) / Second( 8. ); Scalar const _rep4 = rep4.GetValue(); Assert( fequal( _rep4, 7.5 ) ); }
TEST(DriveTest, DistDriven) { Length distance = 5*ft; TrapezoidalMotionProfile<Length> motion_profile(distance, maxHighRobotSpeed, maxHighRobotSpeed / (2*s)); Time t; Velocity last_speed = motion_profile.calculate_speed(0*s); for (t = 0; !motion_profile.finished(t); t+=.05*s) { Velocity cur_speed = motion_profile.calculate_speed(t); Acceleration accel = (cur_speed - last_speed) / (.05*s); EXPECT_LE(cur_speed, maxHighRobotSpeed); EXPECT_LE(accel.to(ft/s/s), (maxHighRobotSpeed / (2*s)).to(ft/s/s) + .0001) << "Robot accelerating too quickly"; EXPECT_GE(accel.to(ft/s/s), (-maxHighRobotSpeed / (2*s)).to(ft/s/s) - .0001) << "Robot deccelerating too quickly"; last_speed = cur_speed; } EXPECT_NEAR(motion_profile.calculate_distance(t).to(ft), distance.to(ft), 0.00001); }
void TestClassDefinition() { Femtoacceleration const femtoacceleration( 1. ); Assert( fequal( femtoacceleration.GetValue(), 1. ) ); Assert( fequal( femtoacceleration.GetFactor(), 1.e-15 ) ); Picoacceleration const picoacceleration( 1. ); Assert( fequal( picoacceleration.GetValue(), 1. ) ); Assert( fequal( picoacceleration.GetFactor(), 1.e-12 ) ); Nanoacceleration const nanoacceleration( 1. ); Assert( fequal( nanoacceleration.GetValue(), 1. ) ); Assert( fequal( nanoacceleration.GetFactor(), 1.e-9 ) ); Microacceleration const microacceleration( 1. ); Assert( fequal( microacceleration.GetValue(), 1. ) ); Assert( fequal( microacceleration.GetFactor(), 1.e-6 ) ); Milliacceleration const milliacceleration( 1. ); Assert( fequal( milliacceleration.GetValue(), 1. ) ); Assert( fequal( milliacceleration.GetFactor(), 1.e-3 ) ); Centiacceleration const centiacceleration( 1. ); Assert( fequal( centiacceleration.GetValue(), 1. ) ); Assert( fequal( centiacceleration.GetFactor(), 1.e-2 ) ); Deciacceleration const deciacceleration( 1. ); Assert( fequal( deciacceleration.GetValue(), 1. ) ); Assert( fequal( deciacceleration.GetFactor(), 1.e-1 ) ); Acceleration const acceleration( 1. ); Assert( fequal( acceleration.GetValue(), 1. ) ); Assert( fequal( acceleration.GetFactor(), 1. ) ); Dekaacceleration const dekaacceleration( 1. ); Assert( fequal( dekaacceleration.GetValue(), 1. ) ); Assert( fequal( dekaacceleration.GetFactor(), 1.e1 ) ); Hectoacceleration const hectoacceleration( 1. ); Assert( fequal( hectoacceleration.GetValue(), 1. ) ); Assert( fequal( hectoacceleration.GetFactor(), 1.e2 ) ); Kiloacceleration const kiloacceleration( 1. ); Assert( fequal( kiloacceleration.GetValue(), 1. ) ); Assert( fequal( kiloacceleration.GetFactor(), 1.e3 ) ); Megaacceleration const megaacceleration( 1. ); Assert( fequal( megaacceleration.GetValue(), 1. ) ); Assert( fequal( megaacceleration.GetFactor(), 1.e6 ) ); Gigaacceleration const gigaacceleration( 1. ); Assert( fequal( gigaacceleration.GetValue(), 1. ) ); Assert( fequal( gigaacceleration.GetFactor(), 1.e9 ) ); Teraacceleration const teraacceleration( 1. ); Assert( fequal( teraacceleration.GetValue(), 1. ) ); Assert( fequal( teraacceleration.GetFactor(), 1.e12 ) ); Petaacceleration const petaacceleration( 1. ); Assert( fequal( petaacceleration.GetValue(), 1. ) ); Assert( fequal( petaacceleration.GetFactor(), 1.e15 ) ); CarAccel const caracceleration( 1. ); Assert( fequal( caracceleration.GetValue(), 1. ) ); //Assert( fequal( caracceleration.GetFactor(), .27777777777777777777777777777778 ) ); }
void SeeClassDefinition() { OutputLine( L"-- Acceleration --" ); Femtoacceleration const femtoacceleration; OutputLine( femtoacceleration.GetSuffix() ); Picoacceleration const picoacceleration; OutputLine( picoacceleration.GetSuffix() ); Nanoacceleration const nanoacceleration; OutputLine( nanoacceleration.GetSuffix() ); Microacceleration const microacceleration; OutputLine( microacceleration.GetSuffix() ); Milliacceleration const milliacceleration; OutputLine( milliacceleration.GetSuffix() ); Centiacceleration const centiacceleration; OutputLine( centiacceleration.GetSuffix() ); Deciacceleration const deciacceleration; OutputLine( deciacceleration.GetSuffix() ); Acceleration const acceleration; OutputLine( acceleration.GetSuffix() ); Dekaacceleration const dekaacceleration; OutputLine( dekaacceleration.GetSuffix() ); Hectoacceleration const hectoacceleration; OutputLine( hectoacceleration.GetSuffix() ); Kiloacceleration const kiloacceleration; OutputLine( kiloacceleration.GetSuffix() ); Megaacceleration const megaacceleration; OutputLine( megaacceleration.GetSuffix() ); Gigaacceleration const gigaacceleration; OutputLine( gigaacceleration.GetSuffix() ); Teraacceleration const teraacceleration; OutputLine( teraacceleration.GetSuffix() ); Petaacceleration const petaacceleration; OutputLine( petaacceleration.GetSuffix() ); Femtoacceleration2 const femtoacceleration2; OutputLine( femtoacceleration2.GetSuffix() ); Picoacceleration2 const picoacceleration2; OutputLine( picoacceleration2.GetSuffix() ); Nanoacceleration2 const nanoacceleration2; OutputLine( nanoacceleration2.GetSuffix() ); Microacceleration2 const microacceleration2; OutputLine( microacceleration2.GetSuffix() ); Milliacceleration2 const milliacceleration2; OutputLine( milliacceleration2.GetSuffix() ); Centiacceleration2 const centiacceleration2; OutputLine( centiacceleration2.GetSuffix() ); Deciacceleration2 const deciacceleration2; OutputLine( deciacceleration2.GetSuffix() ); Dekaacceleration2 const dekaacceleration2; OutputLine( dekaacceleration2.GetSuffix() ); Hectoacceleration2 const hectoacceleration2; OutputLine( hectoacceleration2.GetSuffix() ); Kiloacceleration2 const kiloacceleration2; OutputLine( kiloacceleration2.GetSuffix() ); Megaacceleration2 const megaacceleration2; OutputLine( megaacceleration2.GetSuffix() ); Gigaacceleration2 const gigaacceleration2; OutputLine( gigaacceleration2.GetSuffix() ); Teraacceleration2 const teraacceleration2; OutputLine( teraacceleration2.GetSuffix() ); Petaacceleration2 const petaacceleration2; OutputLine( petaacceleration2.GetSuffix() ); CarAccel const caraccel; OutputLine( caraccel.GetSuffix() ); Acceleration3 const accel3; OutputLine( accel3.GetSuffix() ); Acceleration4 const accel4; OutputLine( accel4.GetSuffix() ); }
void ObjLoader::createGeometryInstances( GLMmodel* model, Program mesh_intersect, Program mesh_bbox ) { std::vector<GeometryInstance> instances; // Loop over all groups -- grab the triangles and material props from each group unsigned int triangle_count = 0u; unsigned int group_count = 0u; for ( GLMgroup* obj_group = model->groups; obj_group != 0; obj_group = obj_group->next, group_count++ ) { unsigned int num_triangles = obj_group->numtriangles; if ( num_triangles == 0 ) continue; // Create vertex index buffers Buffer vindex_buffer = _context->createBuffer( RT_BUFFER_INPUT, RT_FORMAT_INT3, num_triangles ); int3* vindex_buffer_data = static_cast<int3*>( vindex_buffer->map() ); Buffer tindex_buffer = _context->createBuffer( RT_BUFFER_INPUT, RT_FORMAT_INT3, num_triangles ); int3* tindex_buffer_data = static_cast<int3*>( tindex_buffer->map() ); Buffer nindex_buffer = _context->createBuffer( RT_BUFFER_INPUT, RT_FORMAT_INT3, num_triangles ); int3* nindex_buffer_data = static_cast<int3*>( nindex_buffer->map() ); // TODO: Create empty buffer for mat indices, have obj_material check for zero length Buffer mbuffer = _context->createBuffer( RT_BUFFER_INPUT, RT_FORMAT_UNSIGNED_INT, num_triangles ); unsigned int* mbuffer_data = static_cast<unsigned int*>( mbuffer->map() ); // Create the mesh object Geometry mesh = _context->createGeometry(); mesh->setPrimitiveCount( num_triangles ); mesh->setIntersectionProgram( mesh_intersect); mesh->setBoundingBoxProgram( mesh_bbox ); mesh[ "vertex_buffer" ]->setBuffer( _vbuffer ); mesh[ "normal_buffer" ]->setBuffer( _nbuffer ); mesh[ "texcoord_buffer" ]->setBuffer( _tbuffer ); mesh[ "vindex_buffer" ]->setBuffer( vindex_buffer ); mesh[ "tindex_buffer" ]->setBuffer( tindex_buffer ); mesh[ "nindex_buffer" ]->setBuffer( nindex_buffer ); mesh[ "material_buffer" ]->setBuffer( mbuffer ); // Create the geom instance to hold mesh and material params GeometryInstance instance = _context->createGeometryInstance( mesh, &_material, &_material+1 ); loadMaterialParams( instance, obj_group->material ); instances.push_back( instance ); for ( unsigned int i = 0; i < obj_group->numtriangles; ++i, ++triangle_count ) { unsigned int tindex = obj_group->triangles[i]; int3 vindices; vindices.x = model->triangles[ tindex ].vindices[0] - 1; vindices.y = model->triangles[ tindex ].vindices[1] - 1; vindices.z = model->triangles[ tindex ].vindices[2] - 1; assert( vindices.x <= static_cast<int>(model->numvertices) ); assert( vindices.y <= static_cast<int>(model->numvertices) ); assert( vindices.z <= static_cast<int>(model->numvertices) ); int3 nindices; nindices.x = model->triangles[ tindex ].nindices[0] - 1; nindices.y = model->triangles[ tindex ].nindices[1] - 1; nindices.z = model->triangles[ tindex ].nindices[2] - 1; assert( nindices.x <= static_cast<int>(model->numnormals) ); assert( nindices.y <= static_cast<int>(model->numnormals) ); assert( nindices.z <= static_cast<int>(model->numnormals) ); int3 tindices; tindices.x = model->triangles[ tindex ].tindices[0] - 1; tindices.y = model->triangles[ tindex ].tindices[1] - 1; tindices.z = model->triangles[ tindex ].tindices[2] - 1; assert( tindices.x <= static_cast<int>(model->numtexcoords) ); assert( tindices.y <= static_cast<int>(model->numtexcoords) ); assert( tindices.z <= static_cast<int>(model->numtexcoords) ); vindex_buffer_data[ i ] = vindices; nindex_buffer_data[ i ] = nindices; tindex_buffer_data[ i ] = tindices; mbuffer_data[ i ] = 0; // See above TODO } vindex_buffer->unmap(); tindex_buffer->unmap(); nindex_buffer->unmap(); mbuffer->unmap(); } assert( triangle_count == model->numtriangles ); // Set up group _geometrygroup->setChildCount( static_cast<unsigned int>(instances.size()) ); Acceleration acceleration = _context->createAcceleration("Sbvh","Bvh"); acceleration->setProperty( "vertex_buffer_name", "vertex_buffer" ); acceleration->setProperty( "index_buffer_name", "vindex_buffer" ); _geometrygroup->setAcceleration( acceleration ); acceleration->markDirty(); for ( unsigned int i = 0; i < instances.size(); ++i ) _geometrygroup->setChild( i, instances[i] ); }
void MeshViewer::initGeometry() { m_geometry_group = m_context->createGeometryGroup(); if( ObjLoader::isMyFile( m_filename.c_str() ) ) { // Load OBJ model ObjLoader* loader = 0; if( m_shade_mode == SM_NORMAL || m_shade_mode == SM_AO ) { loader = new ObjLoader( m_filename.c_str(), m_context, m_geometry_group, m_material ); } else if ( m_shade_mode == SM_ONE_BOUNCE_DIFFUSE ) { loader = new ObjLoader( m_filename.c_str(), m_context, m_geometry_group, m_material, true ); } else { loader = new ObjLoader( m_filename.c_str(), m_context, m_geometry_group ); } const std::string geom_ptx = ptxpath( "displacement", "geometry_programs.cu" ); loader->setIntersectProgram(m_context->createProgramFromPTXFile( geom_ptx, "mesh_intersect" ) ); loader->setBboxProgram(m_context->createProgramFromPTXFile( geom_ptx, "mesh_bounds" ) ); loader->load(); m_aabb = loader->getSceneBBox(); delete loader; } else if( PlyLoader::isMyFile( m_filename ) ) { // Load PLY model PlyLoader loader( m_filename, m_context, m_geometry_group, m_material ); loader.load(); m_aabb = loader.getSceneBBox(); } else { std::cerr << "Unrecognized model file extension '" << m_filename << "'" << std::endl; exit( 0 ); } // Override acceleration structure builder. The default used by the ObjLoader is Sbvh. if( !m_accel_builder.empty() ) { Acceleration accel = m_geometry_group->getAcceleration(); accel->setBuilder( m_accel_builder ); } Acceleration accel = m_geometry_group->getAcceleration(); accel->setBuilder("Bvh"); // Override traverer if one is given. if( !m_accel_traverser.empty() ) { Acceleration accel = m_geometry_group->getAcceleration(); accel->setTraverser( m_accel_traverser ); } if( m_accel_builder == "TriangleKdTree" || m_accel_traverser == "KdTree") { Acceleration accel = m_geometry_group->getAcceleration(); accel->setProperty( "vertex_buffer_name", "vertex_buffer" ); accel->setProperty( "index_buffer_name", "vindex_buffer" ); } // Load acceleration structure from a file if that was enabled on the // command line, and if we can find a cache file. Note that the type of // acceleration used will be overridden by what is found in the file. loadAccelCache(); m_context[ "top_object" ]->set( m_geometry_group ); m_context[ "top_shadower" ]->set( m_geometry_group ); }