eltopo3d/surftrack.cpp
// ---------------------------------------------------------
///
/// Create a SurfTrack object from a set of vertices and triangles using the specified paramaters
///
// ---------------------------------------------------------
Create a SurfTrack object from a set of vertices and triangles using the specified paramaters
Create a SurfTrack object from a set of vertices and triangles using the specified paramaters
SurfTrack::SurfTrack( const std::vector<Vec3d>& vs, 
                     const std::vector<Vec3st>& ts, 
                     const std::vector<double>& masses,
                     const SurfTrackInitializationParameters& initial_parameters ) :
    DynamicSurface(vs, 
                   ts,
                   masses,
                   initial_parameters.m_proximity_epsilon, 
                   initial_parameters.m_friction_coefficient,
                   initial_parameters.m_collision_safety ),
    m_collapser( *this, initial_parameters.m_use_curvature_when_collapsing, initial_parameters.m_min_curvature_multiplier ),
    m_splitter( *this, initial_parameters.m_use_curvature_when_splitting, initial_parameters.m_max_curvature_multiplier ),
    m_flipper( *this, initial_parameters.m_edge_flip_min_length_change ),
    m_smoother( *this ),
    m_merger( *this ),
    m_pincher( *this ),
    m_improve_collision_epsilon( initial_parameters.m_improve_collision_epsilon ),
    m_edge_flip_min_length_change( initial_parameters.m_edge_flip_min_length_change ),
    m_max_volume_change( UNINITIALIZED_DOUBLE ),   
    m_min_edge_length( UNINITIALIZED_DOUBLE ),
    m_max_edge_length( UNINITIALIZED_DOUBLE ),
    m_merge_proximity_epsilon( initial_parameters.m_merge_proximity_epsilon ),   
    m_min_triangle_area( initial_parameters.m_min_triangle_area ),
    m_min_triangle_angle( initial_parameters.m_min_triangle_angle ),
    m_max_triangle_angle( initial_parameters.m_max_triangle_angle ),
    m_subdivision_scheme( initial_parameters.m_subdivision_scheme ),
    should_delete_subdivision_scheme_object( m_subdivision_scheme == NULL ? true : false ),
    m_dirty_triangles(0),   
    m_allow_topology_changes( initial_parameters.m_allow_topology_changes ),
    m_allow_non_manifold( initial_parameters.m_allow_non_manifold ),
    m_perform_improvement( initial_parameters.m_perform_improvement ),
    m_allow_vertex_movement( initial_parameters.m_allow_vertex_movement ),
    m_vertex_change_history(),
    m_triangle_change_history()
{
    if ( m_verbose )
    {
        std::cout << " ======== SurfTrack ======== " << std::endl;   
        std::cout << "m_allow_topology_changes: " << m_allow_topology_changes << std::endl;
        std::cout << "m_perform_improvement: " << m_perform_improvement << std::endl;   
        std::cout << "m_min_triangle_area: " << m_min_triangle_area << std::endl;
        std::cout << "initial_parameters.m_use_fraction: " << initial_parameters.m_use_fraction << std::endl;
    }
    if ( m_collision_safety )
    {
        rebuild_static_broad_phase();
    }
    assert( initial_parameters.m_min_edge_length != UNINITIALIZED_DOUBLE );
    assert( initial_parameters.m_max_edge_length != UNINITIALIZED_DOUBLE );
    assert( initial_parameters.m_max_volume_change != UNINITIALIZED_DOUBLE );
    if ( initial_parameters.m_use_fraction )
    {
        double avg_length = DynamicSurface::get_average_non_solid_edge_length();   
        m_collapser.m_min_edge_length = initial_parameters.m_min_edge_length * avg_length;
        m_splitter.m_max_edge_length = initial_parameters.m_max_edge_length * avg_length;
        m_min_edge_length = initial_parameters.m_min_edge_length * avg_length;
        m_max_edge_length = initial_parameters.m_max_edge_length * avg_length;
        m_max_volume_change = initial_parameters.m_max_volume_change * avg_length * avg_length * avg_length;        
    }
    else
    {
        m_collapser.m_min_edge_length = initial_parameters.m_min_edge_length;
        m_splitter.m_max_edge_length = initial_parameters.m_max_edge_length;
        m_min_edge_length = initial_parameters.m_min_edge_length;
        m_max_edge_length = initial_parameters.m_max_edge_length;
        m_max_volume_change = initial_parameters.m_max_volume_change;  
    }
    if ( m_verbose )
    {
        std::cout << "m_min_edge_length: " << m_min_edge_length << std::endl;
        std::cout << "m_max_edge_length: " << m_max_edge_length << std::endl;
        std::cout << "m_max_volume_change: " << m_max_volume_change << std::endl;
    }
    if ( m_subdivision_scheme == NULL )
    {
        m_subdivision_scheme = new MidpointScheme();
        should_delete_subdivision_scheme_object = true;
    }
    else
    {
        should_delete_subdivision_scheme_object = false;
    }
    if ( false == m_allow_topology_changes )
    {
        if ( m_allow_non_manifold )
        {
            std::cerr << "WARNING: Topology changes disallowed, but non-manifold allowed.  Must disallow non-manifold surfaces ";
            std::cerr << "if topology changes are disallowed.  Setting allow_non_manifold to false." << std::endl;
            m_allow_non_manifold = false;
        }
    }
}
SurfTrack :: SurfTrack ( const std :: vector < Vec3d > & vs , const std :: vector < Vec3st > & ts , const std :: vector < double > & masses , const SurfTrackInitializationParameters & initial_parameters ) : DynamicSurface ( vs , ts , masses , initial_parameters . m_proximity_epsilon , initial_parameters . m_friction_coefficient , initial_parameters . m_collision_safety ) , m_collapser ( * this , initial_parameters . m_use_curvature_when_collapsing , initial_parameters . m_min_curvature_multiplier ) , m_splitter ( * this , initial_parameters . m_use_curvature_when_splitting , initial_parameters . m_max_curvature_multiplier ) , m_flipper ( * this , initial_parameters . m_edge_flip_min_length_change ) , m_smoother ( * this ) , m_merger ( * this ) , m_pincher ( * this ) , m_improve_collision_epsilon ( initial_parameters . m_improve_collision_epsilon ) , m_edge_flip_min_length_change ( initial_parameters . m_edge_flip_min_length_change ) , m_max_volume_change ( UNINITIALIZED_DOUBLE ) , m_min_edge_length ( UNINITIALIZED_DOUBLE ) , m_max_edge_length ( UNINITIALIZED_DOUBLE ) , m_merge_proximity_epsilon ( initial_parameters . m_merge_proximity_epsilon ) , m_min_triangle_area ( initial_parameters . m_min_triangle_area ) , m_min_triangle_angle ( initial_parameters . m_min_triangle_angle ) , m_max_triangle_angle ( initial_parameters . m_max_triangle_angle ) , m_subdivision_scheme ( initial_parameters . m_subdivision_scheme ) , should_delete_subdivision_scheme_object ( m_subdivision_scheme == NULL ? true : false ) , m_dirty_triangles ( 0 ) , m_allow_topology_changes ( initial_parameters . m_allow_topology_changes ) , m_allow_non_manifold ( initial_parameters . m_allow_non_manifold ) , m_perform_improvement ( initial_parameters . m_perform_improvement ) , m_allow_vertex_movement ( initial_parameters . m_allow_vertex_movement ) , m_vertex_change_history ( ) , m_triangle_change_history ( ) { if ( m_verbose ) { std :: cout << " " << std :: endl ; std :: cout << " " << m_allow_topology_changes << std :: endl ; std :: cout << " " << m_perform_improvement << std :: endl ; std :: cout << " " << m_min_triangle_area << std :: endl ; std :: cout << " " << initial_parameters . m_use_fraction << std :: endl ; } if ( m_collision_safety ) { rebuild_static_broad_phase ( ) ; } assert ( initial_parameters . m_min_edge_length != UNINITIALIZED_DOUBLE ) ; assert ( initial_parameters . m_max_edge_length != UNINITIALIZED_DOUBLE ) ; assert ( initial_parameters . m_max_volume_change != UNINITIALIZED_DOUBLE ) ; if ( initial_parameters . m_use_fraction ) { double avg_length = DynamicSurface :: get_average_non_solid_edge_length ( ) ; m_collapser . m_min_edge_length = initial_parameters . m_min_edge_length * avg_length ; m_splitter . m_max_edge_length = initial_parameters . m_max_edge_length * avg_length ; m_min_edge_length = initial_parameters . m_min_edge_length * avg_length ; m_max_edge_length = initial_parameters . m_max_edge_length * avg_length ; m_max_volume_change = initial_parameters . m_max_volume_change * avg_length * avg_length * avg_length ; } else { m_collapser . m_min_edge_length = initial_parameters . m_min_edge_length ; m_splitter . m_max_edge_length = initial_parameters . m_max_edge_length ; m_min_edge_length = initial_parameters . m_min_edge_length ; m_max_edge_length = initial_parameters . m_max_edge_length ; m_max_volume_change = initial_parameters . m_max_volume_change ; } if ( m_verbose ) { std :: cout << " " << m_min_edge_length << std :: endl ; std :: cout << " " << m_max_edge_length << std :: endl ; std :: cout << " " << m_max_volume_change << std :: endl ; } if ( m_subdivision_scheme == NULL ) { m_subdivision_scheme = new MidpointScheme ( ) ; should_delete_subdivision_scheme_object = true ; } else { should_delete_subdivision_scheme_object = false ; } if ( false == m_allow_topology_changes ) { if ( m_allow_non_manifold ) { std :: cerr << " " ; std :: cerr << " " << std :: endl ; m_allow_non_manifold = false ; } } }
Create a SurfTrack object from a set of vertices and triangles using the specified paramaters
Create a SurfTrack object from a set of vertices and triangles using the specified paramaters