Changeset 916 for trunk/source/visualization/OpenGL
- Timestamp:
- Feb 5, 2009, 12:25:30 PM (16 years ago)
- Location:
- trunk/source/visualization/OpenGL
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/visualization/OpenGL/GNUmakefile
r790 r916 21 21 include $(G4INSTALL)/config/interactivity.gmk 22 22 23 CPPFLAGS += -DG4DEBUG_VIS_OGL 23 24 CPPFLAGS += -I$(G4BASE)/visualization/management/include 24 25 CPPFLAGS += -I$(G4BASE)/visualization/modeling/include -
trunk/source/visualization/OpenGL/include/G4OpenGLQtViewer.hh
r915 r916 144 144 void createRadioAction(QAction *,QAction *, const std::string&,unsigned int a=1); 145 145 void rescaleImage(int, int); 146 bool generateEPS2(QString,int,QImage); 147 bool generateVectorEPS (QString,int,int,QImage); 148 bool generatePS_PDF(QString,int,QImage); 146 bool generateVectorEPS (const char *,int,int,QImage); 147 bool generatePS_PDF(const std::string,int,QImage); 149 148 void showMovieParametersDialog(); 150 149 void initMovieParameters(); -
trunk/source/visualization/OpenGL/include/G4OpenGLViewer.hh
r915 r916 85 85 GLdouble getSceneFarWidth(); 86 86 GLdouble getSceneDepth(); 87 G4float pointSize; 88 char print_string[50]; 89 G4bool print_colour; 90 G4bool vectored_ps; 87 std::string fPrintFilename; 88 G4bool fPrintColour; 89 G4bool fVectoredPs; 91 90 92 91 G4OpenGLSceneHandler& fOpenGLSceneHandler; … … 108 107 fDisplayLightFrontT; 109 108 G4double fDisplayLightFrontRed, fDisplayLightFrontGreen, fDisplayLightFrontBlue; 109 110 private : 111 G4float fPointSize; 110 112 }; 111 113 -
trunk/source/visualization/OpenGL/src/G4OpenGLQtViewer.cc
r915 r916 1293 1293 QString* selectedFormat = new QString(); 1294 1294 #if QT_VERSION < 0x040000 1295 QString nomFich= QFileDialog::getSaveFileName ( ".",1295 fPrintFilename = QFileDialog::getSaveFileName ( ".", 1296 1296 filters, 1297 1297 GLWindow, 1298 1298 "Save file dialog", 1299 1299 tr("Save as ..."), 1300 selectedFormat ) ;1301 #else 1302 QString nomFich= QFileDialog::getSaveFileName ( GLWindow,1300 selectedFormat ).ascii(); 1301 #else 1302 fPrintFilename = QFileDialog::getSaveFileName ( GLWindow, 1303 1303 tr("Save as ..."), 1304 1304 ".", 1305 1305 filters, 1306 selectedFormat ) ;1306 selectedFormat ).toStdString().c_str(); 1307 1307 #endif 1308 1308 // bmp jpg jpeg png ppm xbm xpm 1309 if ( nomFich == "") {1309 if (fPrintFilename.empty()) { 1310 1310 return; 1311 1311 } 1312 1312 #if QT_VERSION < 0x040000 1313 nomFich += "."+QString(selectedFormat->ascii());1313 fPrintFilename += "." + selectedFormat->ascii(); 1314 1314 QString format = selectedFormat->lower(); 1315 1315 #else 1316 nomFich += "."+QString(selectedFormat->toStdString().c_str());1316 fPrintFilename += "." + selectedFormat->toStdString(); 1317 1317 QString format = selectedFormat->toLower(); 1318 1318 #endif … … 1348 1348 if (format == QString("eps")) { 1349 1349 if (exportDialog->getVectorEPS()) { 1350 res = generateVectorEPS( nomFich,exportDialog->getWidth(),exportDialog->getHeight(),image);1350 res = generateVectorEPS(fPrintFilename.c_str(),exportDialog->getWidth(),exportDialog->getHeight(),image); 1351 1351 } else { 1352 res = generateEPS 2(nomFich,exportDialog->getNbColor(),image);1352 res = generateEPS(fPrintFilename.c_str(),exportDialog->getNbColor(),(unsigned int)image.width(),(unsigned int)image.height()); 1353 1353 } 1354 1354 } else if ((format == "ps") || (format == "pdf")) { 1355 res = generatePS_PDF( nomFich,exportDialog->getNbColor(),image);1355 res = generatePS_PDF(fPrintFilename,exportDialog->getNbColor(),image); 1356 1356 } else if ((format == "tif") || 1357 1357 (format == "tiff") || … … 1366 1366 (format == "xpm")) { 1367 1367 #if QT_VERSION < 0x040000 1368 res = image.save( nomFich,selectedFormat->ascii(),exportDialog->getSliderValue());1369 #else 1370 res = image.save( nomFich,0,exportDialog->getSliderValue());1368 res = image.save(QString(fPrintFilename.c_str()),selectedFormat->ascii(),exportDialog->getSliderValue()); 1369 #else 1370 res = image.save(QString(fPrintFilename.c_str()),0,exportDialog->getSliderValue()); 1371 1371 #endif 1372 1372 } else { … … 1374 1374 } 1375 1375 if (res == false) { 1376 #if QT_VERSION < 0x040000 1377 G4cerr << "Error while saving file... "<<nomFich.ascii()<<"" << G4endl; 1378 #else 1379 G4cerr << "Error while saving file... "<<nomFich.toStdString().c_str()<< G4endl; 1380 #endif 1376 G4cerr << "Error while saving file... "<<fPrintFilename.c_str()<< G4endl; 1381 1377 } else { 1382 #if QT_VERSION < 0x040000 1383 G4cout << "File "<<nomFich.ascii()<<" has been saved " << G4endl; 1384 #else 1385 G4cout << "File "<<nomFich.toStdString().c_str()<<" has been saved " << G4endl; 1386 #endif 1378 G4cout << "File "<<fPrintFilename.c_str()<<" has been saved " << G4endl; 1387 1379 } 1388 1380 … … 1660 1652 */ 1661 1653 bool G4OpenGLQtViewer::generateVectorEPS ( 1662 QStringaFilename1654 const char * aFilename 1663 1655 ,int aWidth 1664 1656 ,int aHeight … … 1684 1676 1685 1677 1686 #if QT_VERSION < 0x040000 1687 file = fopen (aFilename.ascii(), "w"); 1688 #else 1689 file = fopen (aFilename.toStdString().c_str(), "w"); 1690 #endif 1678 file = fopen (aFilename, "w"); 1691 1679 if (file) { 1692 1680 spewWireframeEPS (file, returned, feedback_buffer, "rendereps"); 1693 1681 } else { 1694 #if QT_VERSION < 0x040000 1695 G4cerr << "Could not open "<< aFilename.ascii() << G4endl; 1696 #else 1697 G4cerr << "Could not open "<< aFilename.toStdString().c_str() << G4endl; 1698 #endif 1682 G4cerr << "Could not open "<< aFilename << G4endl; 1699 1683 } 1700 1684 … … 1704 1688 } 1705 1689 1706 /** 1707 Generate Encapsulated Postscript form image 1708 @param aFilename : name of file 1709 @param aInColor : numbers of colors : 1->BW 2->RGB 3->RGB+Alpha 1710 @param aImage : Image to print 1711 */ 1712 bool G4OpenGLQtViewer::generateEPS2 ( 1713 QString aFilename 1714 ,int aInColor 1715 ,QImage aImage 1716 ) 1717 { 1718 #ifdef G4DEBUG_VIS_OGL 1719 printf("G4OpenGLQtViewer::generateEPS call parent\n"); 1720 #endif 1721 generateEPS((aFilename+"GL").toStdString().c_str(),3,(unsigned int)aImage.width(),(unsigned int)aImage.height()); 1722 #ifdef G4DEBUG_VIS_OGL 1723 printf("G4OpenGLQtViewer::generateEPS\n"); 1724 #endif 1725 // FIXME 1726 1727 FILE* fp; 1728 1729 if (aImage.bits () == NULL) 1730 return false; 1731 1732 #if QT_VERSION < 0x040000 1733 fp = fopen (aFilename.ascii(), "w"); 1734 #else 1735 fp = fopen (aFilename.toStdString().c_str(), "w"); 1736 #endif 1737 if (fp == NULL) { 1738 return false; 1739 } 1740 1741 fprintf (fp, "%%!PS-Adobe-2.0 EPSF-1.2\n"); 1742 #if QT_VERSION < 0x040000 1743 fprintf (fp, "%%%%Title: %s\n", aFilename.ascii()); 1744 #else 1745 fprintf (fp, "%%%%Title: %s\n", aFilename.toStdString().c_str()); 1746 #endif 1747 fprintf (fp, "%%%%Creator: OpenGL pixmap render output\n"); 1748 fprintf (fp, "%%%%BoundingBox: 0 0 %d %d\n", aImage.width(), aImage.height()); 1749 fprintf (fp, "%%%%EndComments\n"); 1750 fprintf (fp, "gsave\n"); 1751 fprintf (fp, "/bwproc {\n"); 1752 fprintf (fp, " rgbproc\n"); 1753 fprintf (fp, " dup length 3 idiv string 0 3 0 \n"); 1754 fprintf (fp, " 5 -1 roll {\n"); 1755 fprintf (fp, " add 2 1 roll 1 sub dup 0 eq\n"); 1756 fprintf (fp, " { pop 3 idiv 3 -1 roll dup 4 -1 roll dup\n"); 1757 fprintf (fp, " 3 1 roll 5 -1 roll } put 1 add 3 0 \n"); 1758 fprintf (fp, " { 2 1 roll } ifelse\n"); 1759 fprintf (fp, " }forall\n"); 1760 fprintf (fp, " pop pop pop\n"); 1761 fprintf (fp, "} def\n"); 1762 fprintf (fp, "systemdict /colorimage known not {\n"); 1763 fprintf (fp, " /colorimage {\n"); 1764 fprintf (fp, " pop\n"); 1765 fprintf (fp, " pop\n"); 1766 fprintf (fp, " /rgbproc exch def\n"); 1767 fprintf (fp, " { bwproc } image\n"); 1768 fprintf (fp, " } def\n"); 1769 fprintf (fp, "} if\n"); 1770 fprintf (fp, "/picstr %d string def\n", aImage.width() * aInColor); 1771 fprintf (fp, "%d %d scale\n", aImage.width(), aImage.height()); 1772 fprintf (fp, "%d %d %d\n", aImage.width(), aImage.height(), 8); 1773 fprintf (fp, "[%d 0 0 %d 0 0]\n", aImage.width(), aImage.height()); 1774 fprintf (fp, "{currentfile picstr readhexstring pop}\n"); 1775 fprintf (fp, "false %d\n", aInColor); 1776 fprintf (fp, "colorimage\n"); 1777 1778 1779 int width = aImage.width(); 1780 int height = aImage.height(); 1781 int depth = aImage.depth(); 1782 int size = width*height; 1783 1784 if (depth == 1) 1785 size = (width+7)/8*height; 1786 else if (aInColor == 1) 1787 size = size*3; 1788 1789 int i = 0; 1790 // if ( aInColor ==1 ) { 1791 // FIXME : L. Garnier. For the moment 10 dec 2007, I could not find a way 1792 // to save correctly grayscale Image. I mean that color or grayscale image 1793 // have the same file save size ! 1794 1795 /* } else*/ if (depth == 8) { 1796 for(int y=height-1; y >=0 ; y--) { 1797 const uchar * s = aImage.scanLine(y); 1798 for(int x=0; x <width; x++) { 1799 QRgb rgb = aImage.color(s[x]); 1800 if (aInColor == 1) { 1801 fprintf (fp, " %02hx ",(unsigned char)qGray(rgb)); 1802 i++; 1803 } else { 1804 fprintf (fp, " %02hx %02hx %02hx", 1805 (unsigned char) qRed(rgb), 1806 (unsigned char) qGreen(rgb), 1807 (unsigned char) qBlue(rgb)); 1808 i += 3; 1809 } 1810 } 1811 fprintf (fp, "\n"); 1812 } 1813 } else { 1814 #if QT_VERSION < 0x040000 1815 bool alpha = aImage.hasAlphaBuffer(); 1816 #else 1817 bool alpha = aImage.hasAlphaChannel(); 1818 #endif 1819 for(int y=height-1; y >=0 ; y--) { 1820 QRgb * s = (QRgb*)(aImage.scanLine(y)); 1821 for(int x=0; x <width; x++) { 1822 QRgb rgb = (*s++); 1823 if (alpha && qAlpha(rgb) < 0x40) // 25% alpha, convert to white - 1824 rgb = qRgb(0xff, 0xff, 0xff); 1825 if (aInColor == 1) { 1826 fprintf (fp, " %02hx ",(unsigned char)qGray(rgb)); 1827 i++; 1828 } else { 1829 fprintf (fp, " %02hx %02hx %02hx", 1830 (unsigned char) qRed(rgb), 1831 (unsigned char) qGreen(rgb), 1832 (unsigned char) qBlue(rgb)); 1833 i += 3; 1834 } 1835 } 1836 fprintf (fp, "\n"); 1837 } 1838 1839 } 1840 1841 fprintf (fp, "grestore\n"); 1842 fprintf (fp, "showpage\n"); 1843 fclose (fp); 1844 1845 return true; 1846 } 1690 1847 1691 /** 1848 1692 Generate Postscript or PDF form image … … 1852 1696 */ 1853 1697 bool G4OpenGLQtViewer::generatePS_PDF ( 1854 QString aFilename1698 const std::string aFilename 1855 1699 ,int aInColor 1856 1700 ,QImage aImage … … 1899 1743 1900 1744 1901 if (aFilename. endsWith(".ps")) {1745 if (aFilename.substr(aFilename.size()-3) == ".ps") { 1902 1746 #if QT_VERSION > 0x040200 1903 1747 printer.setOutputFormat(QPrinter::PostScriptFormat); … … 1909 1753 } 1910 1754 #if QT_VERSION > 0x040100 1911 printer.setOutputFileName( aFilename);1755 printer.setOutputFileName(QString(aFilename.c_str())); 1912 1756 #endif 1913 1757 // printer.setFullPage ( true); -
trunk/source/visualization/OpenGL/src/G4OpenGLViewer.cc
r915 r916 82 82 G4OpenGLViewer::G4OpenGLViewer (G4OpenGLSceneHandler& scene): 83 83 G4VViewer (scene, -1), 84 pointSize (0),85 print_colour (true),86 vectored_ps (true),84 fPrintFilename ("G4OpenGL.eps"), 85 fPrintColour (true), 86 fVectoredPs (true), 87 87 fOpenGLSceneHandler(scene), 88 88 background (G4Colour(0.,0.,0.)), … … 107 107 fDisplayLightFrontRed(0.), 108 108 fDisplayLightFrontGreen(1.), 109 fDisplayLightFrontBlue(0.) 109 fDisplayLightFrontBlue(0.), 110 fPointSize (0) 110 111 { 111 112 // Make changes to view parameters for OpenGL... … … 121 122 // glDisable (GL_POLYGON_SMOOTH); 122 123 123 strcpy (print_string, "G4OpenGL.eps");124 124 } 125 125 … … 405 405 406 406 FILE* file; 407 if ( print_string) {408 file = fopen ( print_string, "w");407 if (!fPrintFilename.empty()) { 408 file = fopen (fPrintFilename.c_str(), "w"); 409 409 if (file) { 410 410 spewWireframeEPS (file, returned, feedback_buffer, "rendereps"); 411 411 } else { 412 printf("Could not open %s\n", print_string);412 printf("Could not open %s\n", fPrintFilename.c_str()); 413 413 } 414 414 } else { … … 442 442 glGetFloatv (GL_COLOR_CLEAR_VALUE, clearColor); 443 443 glGetFloatv (GL_LINE_WIDTH, &lineWidth); 444 glGetFloatv (GL_POINT_SIZE, & pointSize);444 glGetFloatv (GL_POINT_SIZE, &fPointSize); 445 445 446 446 fputs ("%!PS-Adobe-2.0 EPSF-2.0\n", file); … … 539 539 db=vertex[1].blue - vertex[0].blue; 540 540 541 if (! print_colour) {541 if (!fPrintColour) { 542 542 dr+=(dg+db); 543 543 dr/=3.0; … … 575 575 bnext=vertex[0].blue; 576 576 577 if (! print_colour) {577 if (!fPrintColour) { 578 578 rnext+=(gnext+bnext); 579 579 rnext/=3.0; … … 590 590 steps=0; 591 591 } 592 if ( print_colour) {592 if (fPrintColour) { 593 593 fprintf (file, "%g %g %g setrgbcolor\n", 594 594 vertex[0].red, vertex[0].green, vertex[0].blue); … … 627 627 smooth=0; 628 628 629 if (! print_colour) {629 if (!fPrintColour) { 630 630 red+=(green+blue); 631 631 red/=3.0; … … 634 634 } 635 635 636 if ( print_colour) {636 if (fPrintColour) { 637 637 for (i=1; i<nvertices; i++) { 638 638 if (red!=vertex[i].red || green!=vertex[i].green || blue!=vertex[i].blue) { … … 659 659 vertex[0].x, vertex[i+1].x, vertex[i+2].x, 660 660 vertex[0].y, vertex[i+1].y, vertex[i+2].y); 661 if ( print_colour) {661 if (fPrintColour) { 662 662 fprintf (file, " [%g %g %g] [%g %g %g] [%g %g %g] gouraudtriangle\n", 663 663 vertex[0].red, vertex[0].green, vertex[0].blue, … … 694 694 case GL_POINT_TOKEN: 695 695 vertex=(Feedback3Dcolor*)loc; 696 if ( print_colour) {696 if (fPrintColour) { 697 697 fprintf (file, "%g %g %g setrgbcolor\n", vertex[0].red, vertex[0].green, vertex[0].blue); 698 698 } else { … … 701 701 fprintf (file, "%g %g %g setrgbcolor\n", intensity, intensity, intensity); 702 702 } 703 fprintf(file, "%g %g %g 0 360 arc fill\n\n", vertex[0].x, vertex[0].y, pointSize / 2.0);703 fprintf(file, "%g %g %g 0 360 arc fill\n\n", vertex[0].x, vertex[0].y, fPointSize / 2.0); 704 704 loc += 7; /* Each vertex element in the feedback 705 705 buffer is 7 GLfloats. */ -
trunk/source/visualization/OpenGL/src/G4OpenGLViewerMessenger.cc
r911 r916 252 252 if (command == fpCommandPrintEPS) 253 253 { 254 // Keep copy of print_stringto preserve Xm behaviour...255 char* tmp_string = new char[50];256 strcpy (tmp_string, pOGLViewer->print_string); 254 // Keep copy of fPrintFilename to preserve Xm behaviour... 255 std::string tmp_string = pOGLViewer->fPrintFilename; 256 257 257 // Make new print string... 258 258 static G4int file_count = 0; 259 259 std::ostringstream oss; 260 260 oss << "G4OpenGL_" << file_count++ << ".eps"; 261 strcpy (pOGLViewer->print_string,oss.str().c_str());261 pOGLViewer->fPrintFilename = std::string(oss.str().c_str()); 262 262 // Print eps file... 263 263 pOGLViewer->print(); 264 // Restore print_string for Xm... 265 strcpy (pOGLViewer->print_string, tmp_string); 266 delete tmp_string; 264 // Restore fPrintFilename for Xm... 265 pOGLViewer->fPrintFilename = tmp_string; 267 266 return; 268 267 } … … 346 345 if (command == fpCommandPrintMode) 347 346 { 348 if (newValue == "vectored") pViewer-> vectored_ps = true;347 if (newValue == "vectored") pViewer->fVectoredPs = true; 349 348 if (newValue == "pixmap") { 350 pViewer-> vectored_ps = false;349 pViewer->fVectoredPs = false; 351 350 if (pVisManager->GetVerbosity() >= G4VisManager::warnings) { 352 351 G4cout << -
trunk/source/visualization/OpenGL/src/G4OpenGLXViewer.cc
r915 r916 413 413 414 414 //using namespace std; 415 //cout << "print_col_callback requested with file name: " << print_string<< G4endl;416 417 if ( vectored_ps) {415 //cout << "print_col_callback requested with file name: " << fPrintFilename << G4endl; 416 417 if (fVectoredPs) { 418 418 419 419 G4OpenGLViewer::print(); … … 454 454 DrawView (); 455 455 456 generateEPS ( print_string,457 print_colour,456 generateEPS (fPrintFilename.c_str(), 457 fPrintColour, 458 458 fWinSize_x, fWinSize_y); 459 459 -
trunk/source/visualization/OpenGL/src/G4OpenGLXViewerMessenger.cc
r529 r916 96 96 if (command == fpCommandPrintEPS) 97 97 { 98 // Keep copy of print_stringto preserve Xm behaviour...99 char* tmp_string = new char[50];100 strcpy (tmp_string, pViewer->print_string); 98 // Keep copy of fPrintFilename to preserve Xm behaviour... 99 std::string tmp_string = pViewer->fPrintFilename; 100 101 101 // Make new print string... 102 102 static G4int file_count = 0; 103 103 std::ostringstream oss; 104 104 oss << "G4OpenGL_" << file_count++ << ".eps"; 105 strcpy (pViewer->print_string,oss.str().c_str());105 pViewer->fPrintFilename = std::string (oss.str().c_str()); 106 106 // Print eps file... 107 107 pViewer->print(); 108 // Restore print_string for Xm... 109 strcpy (pViewer->print_string, tmp_string); 110 delete tmp_string; 108 // Restore fPrintFilename for Xm... 109 pViewer->fPrintFilename = tmp_string; 111 110 } 112 111 -
trunk/source/visualization/OpenGL/src/G4OpenGLXmMainMenubarCallbacks.cc
r915 r916 452 452 pView->fpprint_col_radio1 = new G4OpenGLXmRadioButton ("Black and white", 453 453 prcol_cb_list, 454 pView-> print_colour==false ? True : False,454 pView->fPrintColour==false ? True : False, 455 455 0); 456 456 457 457 pView->fpprint_col_radio2 = new G4OpenGLXmRadioButton ("Colour", 458 458 prcol_cb_list, 459 pView-> print_colour==true ? True : False,459 pView->fPrintColour==true ? True : False, 460 460 1); 461 461 … … 474 474 pView->fpprint_style_radio1 = new G4OpenGLXmRadioButton ("Screen dump (pixmap)", 475 475 prsty_cb_list, 476 pView-> vectored_ps==false ? True : False,476 pView->fVectoredPs==false ? True : False, 477 477 0); 478 478 479 479 pView->fpprint_style_radio2 = new G4OpenGLXmRadioButton ("PostScript", 480 480 prsty_cb_list, 481 pView-> vectored_ps==true ? True : False,481 pView->fVectoredPs==true ? True : False, 482 482 1); 483 483 … … 486 486 487 487 pView->fpprint_text = new G4OpenGLXmTextField ("Name of .eps file to save", 488 (pView-> print_string));488 (pView->fPrintFilename.c_str())); 489 489 pView->fpprint_box->AddChild (pView->fpprint_text); 490 490 -
trunk/source/visualization/OpenGL/src/G4OpenGLXmWindowHandlingCallbacks.cc
r911 r916 85 85 G4int choice = get_int_userData (w); 86 86 87 pView-> print_colour=(G4bool)choice;88 G4cout << "Print colour set to " << pView-> print_colour;87 pView->fPrintColour=(G4bool)choice; 88 G4cout << "Print colour set to " << pView->fPrintColour; 89 89 90 90 } … … 98 98 G4int choice = get_int_userData (w); 99 99 100 pView-> vectored_ps=(G4bool)choice;101 G4cout << "`Produce vectored PostScript ?' set to : " << pView-> print_colour;100 pView->fVectoredPs=(G4bool)choice; 101 G4cout << "`Produce vectored PostScript ?' set to : " << pView->fPrintColour; 102 102 103 103 }
Note: See TracChangeset
for help on using the changeset viewer.