talpa/iomesh.cpp
// ---------------------------------------------------------
///
/// Write an RIB file for the shadow map for the given light
///
// ---------------------------------------------------------
Write an RIB file for the shadow map for the given light
Write an RIB file for the shadow map for the given light
bool output_shadow_rib( Gluvi::Target3D& light, const std::vector<Vec3d>& positions, const NonDestructiveTriMesh& mesh, const char *filename_format, ...)
{
#ifdef _MSC_VER
    va_list ap;
    va_start(ap, filename_format);
    int len=_vscprintf(filename_format, ap) 
        +1; 
    char *filename=new char[len];
    vsprintf(filename, filename_format, ap);
    std::ofstream out;
    out.open( filename );
    delete[] filename;
    if( out == NULL )
    {
        return false;
    }
    len=_vscprintf("track%04d_shadow.tiff", ap) 
        +1; 
    filename=new char[len];
    vsprintf( filename, "track%04d_shadow.tiff", ap );
    va_end(ap);
#else
    va_list ap;
    va_start(ap, filename_format);
    char *filename;
    vasprintf(&filename, filename_format, ap);   
    std::ofstream out;
    out.open( filename );
    delete[] filename;
    if( out == NULL )
    {
        return false;
    }
    vasprintf( &filename, "track%04d_shadow.tiff", ap );
    va_end(ap);
#endif
    std::vector<float> xs;
    for ( unsigned int i = 0; i < positions.size(); ++i )
    {
        xs.push_back( (float) positions[i][0] );
        xs.push_back( (float) positions[i][1] );
        xs.push_back( (float) positions[i][2] );
    }
    out << "Display \"" << filename << "\" \"file\" \"z\"" << std::endl;
    delete[] filename;
    out << "Format " << "1024 1024 1" << std::endl;
    out << "PixelFilter \"box\" 1 1 " << std::endl;
    light.export_rib(out);
    out << "WorldBegin\n";
    out << "AttributeBegin\n";
    out << "  Color [0.6 0.6 0.2]\n";
    out << "  Opacity [1 1 1]\n";
    out << "  Surface \"matte\" \"Kd\" 1\n";
    const float plane_limit = 50.0f;
    char buf[256];
    sprintf( buf, "  Polygon \"P\" [-%f -%f -%f %f -%f -%f  %f %f -%f  -%f %f -%f]\n", 
            plane_limit, plane_limit, plane_limit, plane_limit, plane_limit, plane_limit, plane_limit, plane_limit, plane_limit, plane_limit, plane_limit, plane_limit );
    out << buf;
    out << "AttributeEnd\n";
    out << "Color [0.7 0.7 0.9]\n";
    out << "Surface \"matte\" \n";
    write_ribfile( mesh, xs, out);
    out << "WorldEnd\n";
    out.flush();
    out.close();
    return true;
}
bool output_shadow_rib ( Gluvi :: Target3D & light , const std :: vector < Vec3d > & positions , const NonDestructiveTriMesh & mesh , const char * filename_format , ... ) { #ifdef _MSC_VER va_list ap ; va_start ( ap , filename_format ) ; int len = _vscprintf ( filename_format , ap ) + 1 ; char * filename = new char [ len ] ; vsprintf ( filename , filename_format , ap ) ; std :: ofstream out ; out . open ( filename ) ; delete [ ] filename ; if ( out == NULL ) { return false ; } len = _vscprintf ( " " , ap ) + 1 ; filename = new char [ len ] ; vsprintf ( filename , " " , ap ) ; va_end ( ap ) ; #else va_list ap ; va_start ( ap , filename_format ) ; char * filename ; vasprintf ( & filename , filename_format , ap ) ; std :: ofstream out ; out . open ( filename ) ; delete [ ] filename ; if ( out == NULL ) { return false ; } vasprintf ( & filename , " " , ap ) ; va_end ( ap ) ; #endif std :: vector < float > xs ; for ( unsigned int i = 0 ; i < positions . size ( ) ; ++ i ) { xs . push_back ( ( float ) positions [ i ] [ 0 ] ) ; xs . push_back ( ( float ) positions [ i ] [ 1 ] ) ; xs . push_back ( ( float ) positions [ i ] [ 2 ] ) ; } out << " \" " << filename << " \" \" \" \" \" " << std :: endl ; delete [ ] filename ; out << " " << " " << std :: endl ; out << " \" \" " << std :: endl ; light . export_rib ( out ) ; out << " \n " ; out << " \n " ; out << " \n " ; out << " \n " ; out << " \" \" \" \" \n " ; const float plane_limit = 50.0f ; char buf [ 256 ] ; sprintf ( buf , " \" \" \n " , plane_limit , plane_limit , plane_limit , plane_limit , plane_limit , plane_limit , plane_limit , plane_limit , plane_limit , plane_limit , plane_limit , plane_limit ) ; out << buf ; out << " \n " ; out << " \n " ; out << " \" \" \n " ; write_ribfile ( mesh , xs , out ) ; out << " \n " ; out . flush ( ) ; out . close ( ) ; return true ; }
Write an RIB file for the shadow map for the given light
Write an RIB file for the shadow map for the given light
// _vscprintf doesn't count // terminating '\0' // _vscprintf doesn't count // terminating '\0' // flatten // next line: image format (width and height in pixels, pixel aspect ratio) // then write out the camera specification // start the scene // finish the scene