Exemplo n.º 1
0
int traits::run( const comma::command_line_options& options )
{
    comma::csv::options csv( options );
    csv.full_xpath = true;
    bool discard_collinear = options.exists( "--discard-collinear" );
    line_t first_default = comma::csv::ascii< line_t >().get( options.value< std::string >( "--first", "0,0,0,0,0,0" ) );
    line_t second_default = comma::csv::ascii< line_t >().get( options.value< std::string >( "--second", "0,0,0,0,0,0" ) );
    comma::csv::input_stream< lines_t > istream( std::cin, csv, std::make_pair( first_default, second_default ) );
    comma::csv::output_stream < output_t > ostream( std::cout, csv.binary(), false, csv.flush );
    comma::csv::tied< lines_t, output_t > tied( istream, ostream );
    while( istream.ready() || ( std::cin.good() && !std::cin.eof() ) )
    {
        const lines_t* r = istream.read();
        if( !r ) { break; }
        const Eigen::Vector3d& f = ( r->first.second - r->first.first ).normalized();
        const Eigen::Vector3d& s = ( r->second.second - r->second.first ).normalized();
        if( comma::math::equal( f.dot( s ), f.norm() * s.norm() ) )
        {
            if( discard_collinear ) { continue; }
            std::cerr << "points-calc: lines-nearest: got collinear lines (" << r->first.first.transpose() << " , " << r->first.second.transpose() << ") and (" << r->second.first.transpose() << " , " << r->second.second.transpose() << "), please use --discard collinear to discard" << std::endl;
            return 1;
        }
        const Eigen::Vector3d& m = s.cross( f ).normalized();
        const Eigen::Vector3d& n = s.cross( m ).normalized();
        const Eigen::Vector3d& d = r->second.first - r->first.first;
        const Eigen::Vector3d& a = r->first.first + f * n.dot( d ) / n.dot( f );
        const Eigen::Vector3d& b = a + m * m.dot( d );
        tied.append( output_t( a, b ) );
    }
    return 0;
}
Exemplo n.º 2
0
int main( int ac, char** av )
{
    try
    {
        comma::command_line_options options( ac, av, usage );
        bool const is_inplace = options.exists( "--replace" );

        std::vector< std::string > unnamed = options.unnamed( "", "--binary,-b,--format,--fields,-f,--period,--threshold,--reset,--replace" );
        if( unnamed.empty() ) { std::cerr << comma::verbose.app_name() << ": please specify operations" << std::endl; exit( 1 ); }
        if( 1 < unnamed.size() ) { std::cerr << comma::verbose.app_name() << ": Only one operation allowed. Got multiple: " << comma::join( unnamed, ',' ) << std::endl; }
        bool const is_clocked_else_periodic = check_mode_clocked_else_periodic( unnamed.front() );

        boost::optional< snark::timing::clocked_time_stamp > clocked_timestamp;
        boost::optional< snark::timing::periodic_time_stamp > periodic_timestamp;

        if( is_clocked_else_periodic )
        {
            clocked_timestamp = snark::timing::clocked_time_stamp( boost::posix_time::microseconds( to_microseconds( options.value< double >("--period" ) ) ) );
        }
        else
        {
            periodic_timestamp = snark::timing::periodic_time_stamp( boost::posix_time::microseconds( to_microseconds( options.value< double >("--period" ) ) )
                                                                   , boost::posix_time::microseconds( to_microseconds( options.value< double >("--threshold" ) ) )
                                                                   , boost::posix_time::microseconds( to_microseconds( options.value< double >("--reset" ) ) ) );
        }

        comma::csv::options csv( options );
#ifdef WIN32
        if( csv.binary() ) { _setmode( _fileno( stdin ), _O_BINARY ); _setmode( _fileno( stdout ), _O_BINARY ); }
#endif
        comma::csv::input_stream< timestamp_io > istream( std::cin, csv );
        comma::csv::output_stream< timestamp_io > ostream( std::cout, csv );
        comma::csv::tied< timestamp_io, timestamp_io > tied( istream, ostream );
        while( std::cin.good() && !std::cin.eof() )
        {
            const timestamp_io* p = istream.read();
            if( !p ) { break; }
            timestamp_io q = *p;
            q.timestamp =  is_clocked_else_periodic  ? clocked_timestamp->adjusted( p->timestamp ) : periodic_timestamp->adjusted( p->timestamp );
            if( is_inplace )
            {
                if( csv.binary() ) { ostream.write( q, istream.binary().last() ); }
                else { ostream.write( q, istream.ascii().last() ); }
            }
            else { tied.append( q ); }
        }
        return 0;
    }
    catch( std::exception& ex ) { std::cerr << "csv-time-adjust: " << ex.what() << std::endl; }
    catch( ... ) { std::cerr << "csv-time-adjust: unknown exception" << std::endl; }
    return 1;
} 
Exemplo n.º 3
0
Arquivo: main.cpp Projeto: CCJY/coliru
 bool operator==(CommonVersionKey const& o) const { return tied() == o.tied(); }