Exemplo n.º 1
0
void testAABB()
{

   static const math::Vector3<real_t> ZERO( real_t( 0 ), real_t( 0 ), real_t( 0 ) );
   static const math::Vector3<real_t> UNIT( real_t( 1 ), real_t( 1 ), real_t( 1 ) );
   static const real_t EPSILON = real_t(1e-4);

   boost::random::mt19937 randomEngine;

   std::vector<math::AABB> testAABBs;
   testAABBs.push_back( math::AABB( -UNIT, UNIT ) );
   testAABBs.push_back( math::AABB(  ZERO, UNIT ) );
   testAABBs.push_back( math::AABB( -UNIT, ZERO ) );

   for( auto aabbIt = testAABBs.begin(); aabbIt != testAABBs.end(); ++aabbIt )
   {
      const math::AABB outerAABB = aabbIt->getScaled( real_t( 2 ) );
      std::vector< std::pair< Vector3<real_t>, Vector3<real_t> > > testPoints;

      for( int i = 0; i < 100; ++i )
      {
         Vector3<real_t> outerPoint, innerPoint;
         do { outerPoint = outerAABB.randomPoint( randomEngine ); } while( aabbIt->contains( outerPoint ) );
         innerPoint = aabbIt->randomPoint( randomEngine );
         testPoints.push_back( std::make_pair( outerPoint, innerPoint - outerPoint ) );
      }
      
      for( auto pointIt = testPoints.begin(); pointIt != testPoints.end(); ++pointIt )
      {
         const Vector3<real_t> & fluidPoint = pointIt->first;
         const Vector3<real_t> & direction  = pointIt->second;

         real_t q = lbm::intersectionRatio( *aabbIt, fluidPoint, direction, EPSILON );
         Vector3<real_t> intersectionPoint = fluidPoint + direction * q;
         WALBERLA_CHECK_LESS( std::fabs( aabbIt->sqSignedDistance( intersectionPoint ) ), EPSILON * EPSILON );

         q = lbm::intersectionRatioBisection( *aabbIt, fluidPoint, direction, EPSILON );
         intersectionPoint = fluidPoint + direction * q;
         WALBERLA_CHECK_LESS( std::fabs( aabbIt->sqSignedDistance( intersectionPoint ) ), EPSILON * EPSILON );
      }
   }

}
Exemplo n.º 2
0
void testAABBDistance( const Vector3<real_t> & translationVector = Vector3<real_t>() )
{
   auto mesh = make_shared<MeshType>();
   mesh::readAndBroadcast( "cube.obj", *mesh);

   translate( *mesh, translationVector );

   auto aabb = computeAABB( *mesh ); // works since the mesh is a cube

   auto testVolume = aabb.getScaled( real_t(2) ); // AABB containing the test points

   TriangleDistance<MeshType> triDist( mesh );

   std::mt19937 rng;

   for( int i = 0; i < 10000; ++i )
   {
      auto p = testVolume.randomPoint( rng );
      WALBERLA_CHECK_FLOAT_EQUAL( triDist.sqSignedDistance( toOpenMesh(p) ), aabb.sqSignedDistance( p ) );
   }

}