Changeset 26

Show
Ignore:
Timestamp:
11/20/08 16:01:24 (3 years ago)
Author:
mirko
Message:

Ready for release?

Location:
branches/pdfcube-0.0.3
Files:
3 added
4 modified

Legend:

Unmodified
Added
Removed
  • branches/pdfcube-0.0.3/Makefile.am

    r4 r26  
    11## top-level Makefile.am 
    22 
     3#Include extra macros 
     4ACLOCAL_AMFLAGS = -I m4 
     5 
    36#Build in these directories: 
    4 SUBDIRS = src 
     7SUBDIRS = src m4 
    58 
    69#Distribute these directories: 
    7 DIST_SUBDIRS =  src 
     10DIST_SUBDIRS = src m4 
    811 
    9 EXTRA_DIST=autogen.sh 
     12EXTRA_DIST = autogen.sh 
  • branches/pdfcube-0.0.3/configure.ac

    r4 r26  
    1212AM_INIT_AUTOMAKE(pdfcube, 0.0.2) 
    1313 
     14AC_CONFIG_MACRO_DIR([m4]) 
    1415 
    1516dnl ----------------------------------------------- 
     
    5152AC_CHECK_HEADERS(GL/glut.h) 
    5253 
     54AX_BOOST_BASE([1.33.1]) 
     55AX_BOOST_PROGRAM_OPTIONS() 
     56 
    5357dnl ----------------------------------------------- 
    5458dnl Generates Makefiles. 
     
    5660 
    5761AC_OUTPUT(Makefile \ 
    58           src/Makefile 
     62          src/Makefile \ 
     63          m4/Makefile 
    5964) 
  • branches/pdfcube-0.0.3/src/Makefile.am

    r3 r26  
    22 
    33pdfcube_SOURCES = pdfcube.cc 
    4 pdfcube_CXXFLAGS=-Wall -Weffc++ 
     4pdfcube_CXXFLAGS = -Wall -Weffc++  
    55 
    6 INCLUDES = $(glib_CFLAGS) $(gtk_CFLAGS) $(gtkglext_CFLAGS) $(poppler_CFLAGS) $(poppler_glib_CFLAGS) 
     6LDADD = $(glib_LIBS) $(gtk_LIBS) $(gtkglext_LIBS) $(poppler_LIBS) $(poppler_glib_LIBS) -lglut  
     7INCLUDES = $(glib_CFLAGS) $(gtk_CFLAGS) $(gtkglext_CFLAGS) $(poppler_CFLAGS) $(poppler_glib_CFLAGS) $(BOOST_LDFLAGS) 
    78 
    8 LDADD = $(glib_LIBS) $(gtk_LIBS) $(gtkglext_LIBS) $(poppler_LIBS) $(poppler_glib_LIBS) -lglut 
     9AM_CXXFLAGS = $(BOOST_CPPFLAGS)  
     10AM_LDFLAGS=$(BOOST_LDFLAGS) $(BOOST_PROGRAM_OPTIONS_LIB) 
  • branches/pdfcube-0.0.3/src/pdfcube.cc

    r25 r26  
    4343#include <poppler.h> 
    4444 
     45#include <boost/program_options.hpp> 
     46 
    4547using namespace std; 
     48namespace po = boost::program_options; 
    4649 
    4750////////////////////////////////////////////////////////////////////////// 
     
    6568}; 
    6669 
    67 static gboolean fullscreen = TRUE; 
     70static gboolean fullscreen; 
    6871static gboolean animating = FALSE; 
    6972animation active_animation = ANIM_NONE; 
     
    8891 
    8992static GtkWidget *create_window(GdkGLConfig * glconfig); 
     93 
     94 
     95static GLfloat clear_color[4] = { 0.6, 0.0, 0.0, 0.0 }; 
     96static GLfloat top_color[4] = { 0.7, 0.6, 0.6, 0.0 }; 
     97static double animation_emphasis = 3.0; 
    9098 
    9199static bool 
     
    233241    glPolygonMode(GL_FRONT, GL_FILL); 
    234242    glEdgeFlag(GL_FALSE); 
    235  
    236     glClearColor(0.6, 0.0, 0.0, 0.0); 
     243     
     244    glClearColor(clear_color[0], clear_color[1], clear_color[2], clear_color[3]); 
    237245    glCullFace(GL_FRONT); 
    238246    glDisable(GL_DEPTH_TEST); 
     
    248256    glEnable(GL_AUTO_NORMAL); 
    249257    glEnable(GL_NORMALIZE); 
     258 
     259    glEnable(GL_COLOR_MATERIAL); 
     260 
    250261#ifdef ENABLE_FOG 
    251262    glEnable(GL_FOG); 
     
    336347          glMatrixMode(GL_MODELVIEW); 
    337348          glLoadIdentity(); 
    338           lookposz -= 2.0*zsteps[frame]; 
    339           lookposy = 3.0*xsteps[frame]; 
     349          lookposz -= animation_emphasis*zsteps[frame]; 
     350          lookposy = 1.5*animation_emphasis*xsteps[frame]; 
    340351          gluLookAt(lookposx, lookposy, lookposz, 
    341352                    atx, aty, atz, 0, 1, 0); 
     
    764775  // Initialization of animation vectors 
    765776  void matrix_setup() { 
    766     float step_factor = 0.2 * double(N_FRAMES);        //this is little buggy 
    767     float step = (step_factor) / (double(N_FRAMES)/2.0); 
    768     int i = 0; 
    769     for (i = 0; i < N_FRAMES / 2; i++) { 
    770       steps[i] = i * step; 
    771       if (steps[i] > step_factor) 
    772         steps[i] = step_factor; 
    773     } 
    774     for (i = N_FRAMES / 2; i < N_FRAMES; i++) { 
    775       steps[i] = step_factor - (i - double(N_FRAMES) / 2.0) * step; 
    776       if (steps[i] < 0) 
    777         steps[i] = 0; 
    778     } 
    779     // steps[N_FRAMES - 1] = 0; 
    780 #ifndef NDEBUG 
    781     cout << "Step " << step << endl; 
     777    double sum = 0.; 
     778    for(int i=0; i<N_FRAMES; i++) 
     779      { 
     780        steps[i] =std::pow(::sin(i*M_PI/double(N_FRAMES)), 2); 
     781        sum += steps[i]; 
     782      }  
     783    double factor = 90./sum; 
     784    for(int i=0; i<N_FRAMES; i++) 
     785      { 
     786        steps[i] *= factor; 
     787      } 
     788#ifndef NDEBUG 
    782789    cout << "Matrix "; 
    783     for (i = 0; i < N_FRAMES; i++) 
     790    for (int i = 0; i < N_FRAMES; i++) 
    784791      cout << steps[i] << " "; 
    785792    cout << endl; 
     
    789796    float xstep = 
    790797      double (xstep_ratio) / (double(N_FRAMES-1) / 2.0); 
    791     for (i = 0; i < N_FRAMES / 2; i++) { 
     798    for (int i = 0; i < N_FRAMES / 2; i++) { 
    792799      xsteps[i] = i * xstep; 
    793800      if (xsteps[i] > xstep_ratio) 
    794801        xsteps[i] = xstep_ratio; 
    795802    } 
    796     for (i = N_FRAMES / 2; i < N_FRAMES; i++) { 
     803    for (int i = N_FRAMES / 2; i < N_FRAMES; i++) { 
    797804      xsteps[i] = xstep_ratio - (i - double(N_FRAMES-1) / 2.0) * xstep; 
    798805      if (xsteps[i] < 0.01) 
     
    803810    cout << "Step x " << xstep << endl; 
    804811    cout << "Matrix2 "; 
    805     for (i = 0; i < N_FRAMES; i++) 
     812    for (int i = 0; i < N_FRAMES; i++) 
    806813      cout << xsteps[i] << " "; 
    807814    cout << endl; 
     
    810817    float granular = 0.07; 
    811818    float zstep = granular / (double(N_FRAMES) / 4.0); 
    812     for (i = 0; i < N_FRAMES / 4; i++) { 
     819    for (int i = 0; i < N_FRAMES / 4; i++) { 
    813820      zsteps[i] = -i * zstep; 
    814821    } 
    815     for (i = N_FRAMES / 4; i < N_FRAMES / 2; i++) { 
     822    for (int i = N_FRAMES / 4; i < N_FRAMES / 2; i++) { 
    816823      zsteps[i] = -granular + (i - double(N_FRAMES) / 4.0) * zstep; 
    817824    } 
    818     for (i = N_FRAMES / 2; i < N_FRAMES; i++) { 
     825    for (int i = N_FRAMES / 2; i < N_FRAMES; i++) { 
    819826      zsteps[i] = -zsteps[i - N_FRAMES / 2]; 
    820827    } 
     
    823830    cout << "Step z " << zstep << endl; 
    824831    cout << "Matrix3 "; 
    825     for (i = 0; i < N_FRAMES; i++) 
     832    for (int i = 0; i < N_FRAMES; i++) 
    826833      cout << zsteps[i] << " "; 
    827834    cout << endl; 
     
    830837    float zoomstop = 0.38; 
    831838    float zoomstep = (zoomstop / double (N_FRAMES-1)); 
    832     for (i = 0; i < N_FRAMES; i++) { 
     839    for (int i = 0; i < N_FRAMES; i++) { 
    833840      zoomsteps[i] = i * zoomstep; 
    834841    } 
     
    837844    cout << "Step zoom " << zoomstep << endl; 
    838845    cout << "Matrix4 "; 
    839     for (i = 0; i < N_FRAMES; i++) 
     846    for (int i = 0; i < N_FRAMES; i++) 
    840847      cout << zoomsteps[i] << " "; 
    841848    cout << endl; 
     
    844851    float perspstart = 44.00; 
    845852    float perspstop = 21.00; 
    846     for (i = 0; i < N_FRAMES; i++) { 
     853    for (int i = 0; i < N_FRAMES; i++) { 
    847854      perspsteps[i] = (cos(i*M_PI/(double(N_FRAMES)*2.0)))*(perspstart - perspstop)+perspstop; 
    848855    } 
     
    850857    // cout << "Step persp " << perspstep << endl; 
    851858    cout << "Matrix5 "; 
    852     for (i = 0; i < N_FRAMES; i++) 
     859    for (int i = 0; i < N_FRAMES; i++) 
    853860      cout << perspsteps[i] << " "; 
    854861    cout << endl; 
     
    857864    float perspcstart = 44.00; 
    858865    float perspcstop = 30.00; 
    859     for (i = 0; i < N_FRAMES; i++) { 
     866    for (int i = 0; i < N_FRAMES; i++) { 
    860867      perspstepsc[i] = (1.0+cos(i*M_PI/double(N_FRAMES)))/2.0*(perspcstart - perspcstop)+perspcstop; 
    861868    } 
    862869#ifndef NDEBUG 
    863870    cout << "Matrix6 "; 
    864     for (i = 0; i < N_FRAMES; i++) 
     871    for (int i = 0; i < N_FRAMES; i++) 
    865872      cout << perspstepsc[i] << " "; 
    866873    cout << endl; 
     
    10391046      glNewList(cube_faces+i,GL_COMPILE); 
    10401047      glBegin(GL_QUADS); 
    1041       glMultiTexCoord2f(GL_TEXTURE0_ARB,(1.0 - mapping[i][4]) * tex_width, 
    1042                         mapping[i][5] * tex_height); 
     1048      if(i<4) 
     1049        glMultiTexCoord2f(GL_TEXTURE0_ARB,(1.0 - mapping[i][4]) * tex_width, 
     1050                          mapping[i][5] * tex_height); 
    10431051      glVertex3fv(&v[faces[i][0]][0]); 
    10441052       
    1045       glMultiTexCoord2f(GL_TEXTURE0_ARB,(1.0 - mapping[i][6]) * tex_width, 
    1046                         mapping[i][7] * tex_height); 
     1053      if(i<4) 
     1054        glMultiTexCoord2f(GL_TEXTURE0_ARB,(1.0 - mapping[i][6]) * tex_width, 
     1055                          mapping[i][7] * tex_height); 
    10471056      glVertex3fv(&v[faces[i][1]][0]); 
    10481057       
    1049       glMultiTexCoord2f(GL_TEXTURE0_ARB,(1.0 - mapping[i][0]) * tex_width, 
    1050                         mapping[i][1] * tex_height); 
     1058      if(i<4) 
     1059        glMultiTexCoord2f(GL_TEXTURE0_ARB,(1.0 - mapping[i][0]) * tex_width, 
     1060                          mapping[i][1] * tex_height); 
    10511061      glVertex3fv(&v[faces[i][2]][0]); 
    10521062       
    1053       glMultiTexCoord2f(GL_TEXTURE0_ARB,(1.0 - mapping[i][2]) * tex_width, 
    1054                         mapping[i][3] * tex_height); 
     1063      if(i<4) 
     1064        glMultiTexCoord2f(GL_TEXTURE0_ARB,(1.0 - mapping[i][2]) * tex_width, 
     1065                          mapping[i][3] * tex_height); 
    10551066      glVertex3fv(&v[faces[i][3]][0]); 
    10561067      glEnd(); 
     
    10811092                      textures[texmap[2]]); 
    10821093      } else if (i <= 3) { 
     1094        glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); 
    10831095        glDisable(GL_TEXTURE_RECTANGLE_ARB); 
    1084         glColor4f(0.4, 0.0, 0.0, 1.0); 
     1096        glColor4f(top_color[0], top_color[1], top_color[2], top_color[4]); 
    10851097      } else { 
     1098        glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); 
    10861099        glDisable(GL_TEXTURE_RECTANGLE_ARB); 
    1087         glColor4f(1.0, 1.0, 1.0, 1.0); 
     1100        glColor4f(top_color[0], top_color[1], top_color[2], top_color[4]); 
    10881101      } 
    10891102      glPolygonMode(GL_FRONT, GL_FILL); 
     
    10961109GLfloat 
    10971110pdfcube::n[6][3] = { 
    1098   {0.0, 0.0, -1.0} 
    1099   , {1.0, 0.0, 0.0} 
    1100   , {0.0, 0.0, 1.0} 
    1101   , {-1.0, 0.0, 0.0} 
    1102   , 
    1103   {0.0, 1.0, 0.0} 
    1104   , {0.0, -1.0, 0.0} 
     1111  {0.0, 0.0, -1.0},  
     1112  {1.0, 0.0, 0.0},  
     1113  {0.0, 0.0, 1.0},  
     1114  {-1.0, 0.0, 0.0}, 
     1115  {0.0, 1.0, 0.0}, 
     1116  {0.0, -1.0, 0.0} 
    11051117}; 
    11061118//bcube faces 
    11071119GLint 
    11081120pdfcube::faces[6][4] = { 
    1109   {7, 4, 0, 3} 
    1110   , {7, 6, 5, 4} 
    1111   , {5, 6, 2, 1} 
    1112   , {0, 1, 2, 3} 
    1113   , 
    1114   {3, 2, 6, 7} 
    1115   , {4, 5, 1, 0} 
     1121  {7, 4, 0, 3}, 
     1122  {7, 6, 5, 4}, 
     1123  {5, 6, 2, 1}, 
     1124  {0, 1, 2, 3}, 
     1125  {3, 2, 6, 7}, 
     1126  {4, 5, 1, 0} 
    11161127}; 
    11171128// face mapping 
     
    11331144 
    11341145// the pdf-cube 
    1135 pdfcube * 
    1136 pc; 
     1146pdfcube* pc; 
    11371147 
    11381148////////////////////////////////////////////////////////////////////////// 
     
    18271837////////////////////////////////////////////////////////////////////////// 
    18281838// Main function: should we use getopts? (who doesn't?) 
     1839// (update: we do, let's use boost::program_options ;)) 
    18291840 
    18301841int 
    18311842main(int argc, char *argv[]) 
    18321843{ 
     1844 
     1845  po::options_description opts("Available options"); 
     1846 
     1847  opts.add_options() 
     1848    ("help,h",  
     1849     "This help message.") 
     1850    ("bgcolor,b", po::value<std::string>(), 
     1851     "Background color is 'r,g,b' with real values between 0.0 and 1.0, no spaces.") 
     1852    ("top-color,t", po::value<std::string>(), 
     1853     "Cube top color in 'r,g,b' format again with reals in [0,1].") 
     1854    ("transitions,c", po::value<std::vector<int> >()->multitoken(),  
     1855     "Pages at wich to do a cube transition by default eg. 2 4 7\nMust be the last option on the command line.") 
     1856    ("input-file,i", po::value<std::string>(), "PDF file to show.") 
     1857    ("no-fullscreen,n",  
     1858     "Don't activate full-screen mode by default."); 
     1859 
     1860  po::positional_options_description p; 
     1861  p.add("input-file", -1); 
     1862 
     1863  po::variables_map vm; 
     1864  po::store(po::command_line_parser(argc, argv). 
     1865            options(opts).positional(p).run(), vm); 
     1866  po::notify(vm); 
     1867 
     1868  string input_file; 
     1869 
     1870  if(vm.count("help")) { 
     1871    cout << endl << "PDFCube 0.0.3" << endl; 
     1872    cout << "=============" << endl; 
     1873    cout << "Copyright (C) 2006-2008 Mirko Maischberger <mirko.maischberger@gmail.com>" << endl; 
     1874    cout << "                   2008 Karol Sokolowski   <sokoow@gmail.com>" <<  endl << endl; 
     1875    cout << opts << endl; 
     1876    cout << endl; 
     1877    cout << "Usage examples:" << endl; 
     1878    cout << "  $ pdfcube presentation.pdf" << endl; 
     1879    cout << "  $ pdfcube presentation.pdf --bgcolor 0,0,0 --top-color 0.6,0.2,0.2 --transitions 1 5 7" 
     1880         << endl << endl << endl; 
     1881    return 0; 
     1882  } 
     1883 
     1884  if (vm.count("input-file")) { 
     1885    input_file = vm["input-file"].as<std::string>(); 
     1886  } else { 
     1887    cerr << "You must specify an input PDF file on the command line." << endl; 
     1888    exit(1); 
     1889  } 
     1890 
     1891  if(vm.count("bgcolor")) { 
     1892    vector<double> cc;  
     1893    string v; 
     1894    std::istringstream iss(vm["bgcolor"].as<std::string>()); 
     1895    while(getline(iss, v, ',')) cc.push_back(::atof(v.c_str()));  
     1896    if(cc.size() != 3) 
     1897      { 
     1898        cerr << "You should specify 3 values for background-color." << endl; 
     1899        exit(1); 
     1900      } 
     1901    std::copy(&cc[0], &cc[3], &clear_color[0]); 
     1902  } 
     1903 
     1904  if(vm.count("top-color")) { 
     1905    vector<double> tc;  
     1906    string v; 
     1907    std::istringstream iss(vm["top-color"].as<std::string>()); 
     1908    while(getline(iss, v, ',')) tc.push_back(::atof(v.c_str()));  
     1909    if(tc.size() != 3) 
     1910      { 
     1911        cerr << "You should specify 3 values for top-color." << endl; 
     1912        exit(1); 
     1913      } 
     1914    std::copy(&tc[0], &tc[3], &top_color[0]); 
     1915  } 
     1916 
    18331917  GtkWidget * 
    18341918    window; 
     
    18451929  glconfig = configure_gl(); 
    18461930 
    1847   if (argc < 2) { 
    1848     perror("usage: pdfcube file_uri [cube_page ...]"); 
    1849     exit(1); 
    1850   } 
    18511931  gchar * 
    1852     absoluteFileName = get_absolute_file_name(argv[1]); 
     1932    absoluteFileName = get_absolute_file_name(input_file.c_str()); 
    18531933  gchar * 
    18541934    filename_uri = g_filename_to_uri(absoluteFileName, NULL, NULL); 
    18551935  g_free(absoluteFileName); 
    18561936  if (NULL == filename_uri) { 
    1857     cerr << "Errore nel nome del file" << endl; 
     1937    cerr << "File name error." << endl; 
    18581938  } 
    18591939  PopplerDocument * 
     
    18611941 
    18621942  if (document == NULL) { 
    1863     perror("invaild pdf file"); 
    1864     exit(2); 
     1943    perror("Invaild PDF file."); 
     1944    exit(1); 
    18651945  } 
    18661946 
     
    18681948 
    18691949  page_transition = new bool[pc->pages()]; 
    1870  
    1871   for (int ii = 0; ii < pc->pages(); ii++) { 
    1872     page_transition[ii] = false; 
    1873   } 
    1874  
    1875   for (int ii = 2; ii < argc; ii++) { 
    1876     page_transition[atoi(argv[ii])] = true; 
     1950  if(vm.count("transitions")) { 
     1951    vector<int> tr = vm["transitions"].as<std::vector<int> >(); 
     1952    for(int ii = 0; ii < pc->pages(); ii++) { 
     1953      page_transition[ii] = false; 
     1954    } 
     1955    for (std::vector<int>::iterator ii = tr.begin(); ii != tr.end(); ++ii) { 
     1956      if(*ii > pc->pages())  
     1957        cerr << "Transision after end of file." << endl; 
     1958      else 
     1959        page_transition[*ii-1] = true; 
     1960    } 
    18771961  } 
    18781962 
    18791963  /* Create and show the application window. */ 
    18801964  window = create_window(glconfig); 
    1881  
    1882   if (fullscreen) 
     1965   
     1966  if(vm.count("no-fullscreen")) 
     1967    fullscreen = FALSE; 
     1968  else 
     1969    fullscreen = TRUE; 
     1970 
     1971  if(fullscreen) 
    18831972    gtk_window_fullscreen((GtkWindow *) (window)); 
    1884  
     1973   
    18851974  gtk_widget_show(window); 
    18861975