talpa/main.cpp
// ---------------------------------------------------------
///
/// Wrapper for El Topo API to mesh integration/collision detection.
///
/// This function is terribly inefficient: it copies the current state of g_surf to buffers, then calls the C API, which internally
/// creates a new SurfTrack object.  This function is only included for demonstrating and testing the C API.
///
// ---------------------------------------------------------
Wrapper for El Topo API to mesh integration/collision detection.
This function is terribly inefficient: it copies the current state of g_surf to buffers, then calls the C API, which internally
creates a new SurfTrack object.  This function is only included for demonstrating and testing the C API.
Wrapper for El Topo API to mesh integration / collision detection . This function is terribly inefficient : it copies the current state of g_surf to buffers then calls the C API which internally creates a new SurfTrack object . This function is only included for demonstrating and testing the C API .
void el_topo_wrapper_integrate( double dt, double& out_dt )
    {
        ElTopoMesh inputs;
        inputs.num_vertices = g_surf->get_num_vertices();
        inputs.vertex_locations = new double[ 3*inputs.num_vertices ];
        memcpy( inputs.vertex_locations, &(g_surf->get_position(0)), 3*inputs.num_vertices*sizeof(double) );   
        inputs.num_triangles = g_surf->m_mesh.num_triangles();
        inputs.triangles = new int[ 3*inputs.num_triangles ];
        memcpy( inputs.triangles, &(g_surf->m_mesh.get_triangles()[0]), 3*inputs.num_triangles*sizeof(int) );
        inputs.vertex_masses = new double[ inputs.num_vertices ];
        memcpy( inputs.vertex_masses, &(g_surf->m_masses[0]), inputs.num_vertices*sizeof(double) );
        assert( g_surf->m_masses.size() == inputs.num_vertices );
        for ( unsigned int i = 0; i < inputs.num_vertices; ++i )
        {
            assert( g_surf->m_masses[i] == g_surf->m_masses[i] );
            assert( g_surf->m_masses[i] != 0.0 );
            assert( inputs.vertex_masses[i] == inputs.vertex_masses[i] );
            assert( inputs.vertex_masses[i] != 0.0  );
        }
        ElTopoGeneralOptions general_options;
        general_options.m_verbose = g_surf->m_verbose;
        general_options.m_collision_safety = g_surf->m_collision_safety;
        general_options.m_proximity_epsilon = g_surf->m_proximity_epsilon;
        ElTopoIntegrationOptions options;
        options.m_dt = dt;
        options.m_friction_coefficient = g_surf->m_collision_pipeline.m_friction_coefficient;
        double* new_vertex_locations = new double[ 3 * g_surf->get_num_vertices() ];
        memcpy( new_vertex_locations, &(g_surf->get_newposition(0)), 3 * g_surf->get_num_vertices() * sizeof(double) );
        double* out_vertex_locations;
        el_topo_integrate( &inputs, new_vertex_locations, &general_options, &options, &out_vertex_locations, &out_dt );
        g_surf->set_all_positions( g_surf->get_num_vertices(), out_vertex_locations );
        g_surf->set_all_newpositions( g_surf->get_num_vertices(), out_vertex_locations );
        delete[] inputs.triangles;
        delete[] inputs.vertex_locations;
        delete[] inputs.vertex_masses;
        delete[] new_vertex_locations;
        el_topo_free_integrate_results( out_vertex_locations );
    }
void el_topo_wrapper_integrate ( double dt , double & out_dt ) { ElTopoMesh inputs ; inputs . num_vertices = g_surf -> get_num_vertices ( ) ; inputs . vertex_locations = new double [ 3 * inputs . num_vertices ] ; memcpy ( inputs . vertex_locations , & ( g_surf -> get_position ( 0 ) ) , 3 * inputs . num_vertices * sizeof ( double ) ) ; inputs . num_triangles = g_surf -> m_mesh . num_triangles ( ) ; inputs . triangles = new int [ 3 * inputs . num_triangles ] ; memcpy ( inputs . triangles , & ( g_surf -> m_mesh . get_triangles ( ) [ 0 ] ) , 3 * inputs . num_triangles * sizeof ( int ) ) ; inputs . vertex_masses = new double [ inputs . num_vertices ] ; memcpy ( inputs . vertex_masses , & ( g_surf -> m_masses [ 0 ] ) , inputs . num_vertices * sizeof ( double ) ) ; assert ( g_surf -> m_masses . size ( ) == inputs . num_vertices ) ; for ( unsigned int i = 0 ; i < inputs . num_vertices ; ++ i ) { assert ( g_surf -> m_masses [ i ] == g_surf -> m_masses [ i ] ) ; assert ( g_surf -> m_masses [ i ] != 0.0 ) ; assert ( inputs . vertex_masses [ i ] == inputs . vertex_masses [ i ] ) ; assert ( inputs . vertex_masses [ i ] != 0.0 ) ; } ElTopoGeneralOptions general_options ; general_options . m_verbose = g_surf -> m_verbose ; general_options . m_collision_safety = g_surf -> m_collision_safety ; general_options . m_proximity_epsilon = g_surf -> m_proximity_epsilon ; ElTopoIntegrationOptions options ; options . m_dt = dt ; options . m_friction_coefficient = g_surf -> m_collision_pipeline . m_friction_coefficient ; double * new_vertex_locations = new double [ 3 * g_surf -> get_num_vertices ( ) ] ; memcpy ( new_vertex_locations , & ( g_surf -> get_newposition ( 0 ) ) , 3 * g_surf -> get_num_vertices ( ) * sizeof ( double ) ) ; double * out_vertex_locations ; el_topo_integrate ( & inputs , new_vertex_locations , & general_options , & options , & out_vertex_locations , & out_dt ) ; g_surf -> set_all_positions ( g_surf -> get_num_vertices ( ) , out_vertex_locations ) ; g_surf -> set_all_newpositions ( g_surf -> get_num_vertices ( ) , out_vertex_locations ) ; delete [ ] inputs . triangles ; delete [ ] inputs . vertex_locations ; delete [ ] inputs . vertex_masses ; delete [ ] new_vertex_locations ; el_topo_free_integrate_results ( out_vertex_locations ) ; }
Wrapper for El Topo API to mesh integration/collision detection.
Wrapper for El Topo API to mesh integration / collision detection .