TclVideoPlayer.cpp

Go to the documentation of this file.
00001 /* ****************************************************************** **
00002 **    OpenSees - Open System for Earthquake Engineering Simulation    **
00003 **          Pacific Earthquake Engineering Research Center            **
00004 **                                                                    **
00005 **                                                                    **
00006 ** (C) Copyright 1999, The Regents of the University of California    **
00007 ** All Rights Reserved.                                               **
00008 **                                                                    **
00009 ** Commercial use of this program without express permission of the   **
00010 ** University of California, Berkeley, is strictly prohibited.  See   **
00011 ** file 'COPYRIGHT'  in main directory for information on usage and   **
00012 ** redistribution,  and for a DISCLAIMER OF ALL WARRANTIES.           **
00013 **                                                                    **
00014 ** Developed by:                                                      **
00015 **   Frank McKenna (fmckenna@ce.berkeley.edu)                         **
00016 **   Gregory L. Fenves (fenves@ce.berkeley.edu)                       **
00017 **   Filip C. Filippou (filippou@ce.berkeley.edu)                     **
00018 **                                                                    **
00019 ** ****************************************************************** */
00020                                                                         
00021 // $Revision: 1.7 $
00022 // $Date: 2006/01/13 18:19:43 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/tcl/TclVideoPlayer.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/tcl/TclVideoPlayer.C
00027 // 
00028 // Written: fmk 
00029 // Created: 11/99
00030 // Revision: A
00031 //
00032 // Description: This file contains the class implementation for TclVideoPlayer
00033 // TclVideoPlayer is a class for building a Plane Frame model in an interpreted
00034 // enviroment. The constructor is used to add new commands to the interpreter,
00035 // these commands are also defined in this file.
00036 //
00037 // What: "@(#) TclVideoPlayer.C, revA"
00038 
00039 
00040 #include <stdlib.h>
00041 #include <string.h>
00042 
00043 #ifdef _WGL
00044 #include <OpenGLRenderer.h>
00045 #elif _GLX
00046 #include <OpenGLRenderer.h>
00047 #else
00048 #include <X11Renderer.h>
00049 #endif
00050 
00051 
00052 #include <PlainMap.h>
00053 #include "TclVideoPlayer.h"
00054 #include <Vector.h>
00055 
00056 
00057 #include <iomanip>
00058 using std::ios;
00059 
00060 //
00061 // some static variables used in the functions
00062 //
00063 
00064 #ifdef _NOGRAPHICS
00065 
00066 #else
00067 extern TclVideoPlayer *theTclVideoPlayer;
00068 #endif
00069 
00070 
00071 int
00072 TclVideoPlayer_play(ClientData clientData, Tcl_Interp *interp, int argc, 
00073                     TCL_Char **argv);
00074 
00075 //
00076 // the class constructor, destructor and methods
00077 //
00078 
00079 TclVideoPlayer::TclVideoPlayer(const char *title, const char *fileName, const char *imageName,
00080                                Tcl_Interp *interp, const char *offsetFileName, double fact)
00081   :theMap(0), theRenderer(0), theOffsetFileName(0), factor(fact)
00082 {
00083     // open the file
00084     if (fileName != 0) {
00085 
00086       // make room for copy of filename string and copy it
00087       theFileName = new char[strlen(fileName)]; 
00088       if (theFileName == 0) {
00089         opserr << "FATAL TclVideoPlayer::TclVideoPlayer() - out of memory copy " << fileName << endln;
00090         exit(-1);
00091       }
00092 
00093       strcpy(theFileName, fileName);    
00094       // test we can open the file for when we get to play - 
00095       theFile.open(fileName, ios::in);
00096       if (!theFile) {
00097         opserr << "WARNING TclVideoPlayer::TclVideoPlayer() - could not open file " << fileName << endln;
00098         exit(-1);
00099       } else {
00100 
00101         // read in the window properties from the file
00102         int xLoc, yLoc, width, height;
00103         char newTitle[50];
00104         theFile >> newTitle;
00105         theFile >> xLoc >> yLoc >> width >> height;
00106 
00107         // create the map and renderer
00108         theMap = new PlainMap();
00109 #ifdef _WGL
00110         if (imageName == 0)
00111           theRenderer = new OpenGLRenderer(title, xLoc, yLoc, width, height, *theMap);
00112         else
00113           theRenderer = new OpenGLRenderer(title, xLoc, yLoc, width, height, *theMap,0,imageName);
00114 #elif _GLX
00115 
00116         theRenderer = new OpenGLRenderer(title, xLoc, yLoc, width, height, *theMap);
00117 #else
00118         theRenderer = new X11Renderer(title, xLoc, yLoc, width, height, *theMap);
00119 #endif
00120         if (theMap == 0 || theRenderer == 0) 
00121           opserr << "WARNING TclVideoPlayer::TclVideoPlayer() - could not create renderer\n";
00122 
00123         theFile.close();
00124       }
00125     }
00126 
00127     // see if a file containing rigid offsets has been supplied,
00128     // if so - make space, copy the string and try opeing the file
00129     if (offsetFileName != 0) {
00130       // make copy of offset file name
00131       theOffsetFileName = new char[strlen(offsetFileName)]; 
00132       if (theOffsetFileName == 0) {
00133         opserr << "FATAL TclVideoPlayer::TclVideoPlayer() - out of memory copy " << offsetFileName << endln;
00134         exit(-1);
00135       }
00136       strcpy(theOffsetFileName, offsetFileName);    
00137 
00138       theOffsetFile.open(offsetFileName, ios::in);
00139       if (!theOffsetFile) {
00140         opserr << "WARNING TclVideoPlayer::TclVideoPlayer() - could not open file " << offsetFileName << endln;
00141       }
00142       theOffsetFile.close();
00143     }
00144 
00145     // call Tcl_CreateCommand for class specific commands
00146     Tcl_CreateCommand(interp, "play", TclVideoPlayer_play,
00147                       (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
00148 }
00149 
00150 
00151 TclVideoPlayer::~TclVideoPlayer() {
00152   if (theMap != 0)
00153     delete theMap;
00154 
00155   if (theRenderer != 0)
00156     delete theRenderer;
00157 }
00158 
00159     
00160 int 
00161 TclVideoPlayer::play(void)
00162 {
00163   // rigid body offsets
00164 
00165   double dX, dY, dZ;
00166   dX = 0.0; dY = 0.0; dZ = 0.0;
00167 
00168   // open the file
00169   theFile.open(theFileName, ios::in);
00170   if (!theFile) 
00171     return -1;  // no error printed - print once in constructor
00172 
00173 
00174   // open the offset file
00175   if (theOffsetFileName != 0) {
00176     theOffsetFile.open(theOffsetFileName, ios::in);
00177     if (!theOffsetFile) 
00178       return -1;  // no error printed - print once in constructor
00179   }
00180 
00181   int xLoc, yLoc, width, height;
00182   char newTitle[50];
00183   theFile >> newTitle;
00184   theFile >> xLoc >> yLoc >> width >> height;
00185 
00186   // till we are done
00187   float a,b,c,d;
00188   int mode;
00189   Vector pt(3);
00190   Vector rgb(3);
00191   Vector pt2(3);
00192   Vector rgb2(3);
00193 
00194   int count =1;
00195   char drivel[50];
00196   while (theFile >> drivel) { // reads in StartImage
00197     // read in VRP data and set in renderer
00198 
00199     theFile >> drivel; 
00200     theFile >> a >> b >> c;
00201     theRenderer->setVRP(a,b,c);
00202 
00203     // read in VPN data and set in renderer
00204     theFile >> drivel; 
00205     theFile >> a >> b >> c;
00206     theRenderer->setVPN(a,b,c);
00207 
00208     // read in VUV data and set in renderer
00209     theFile >> drivel; 
00210     theFile >> a >> b >> c;
00211     theRenderer->setVUP(a,b,c);
00212 
00213     // read in COP data and set in renderer
00214     theFile >> drivel; 
00215     theFile >> a >> b >> c;
00216     theRenderer->setPRP(a,b,c);
00217 
00218     // read in projection mode data and set in renderer
00219     theFile >> drivel; 
00220     theFile >> drivel;
00221     theRenderer->setProjectionMode(drivel);
00222 
00223     // read in view data and set in renderer
00224     theFile >> drivel; 
00225     theFile >> a >> b >> c >> d;
00226     theRenderer->setViewWindow(a,b,c,d);
00227 
00228     // read in clipping plane distances and set in renderer
00229     theFile >> drivel; 
00230     theFile >> a >> b;
00231     theRenderer->setPlaneDist(a,b);
00232 
00233     // read in viewport data and set in renderer
00234     theFile >> drivel; 
00235     theFile >> a >> b >> c >> d;
00236     theRenderer->setPortWindow(a,b,c,d);
00237 
00238     theRenderer->startImage();
00239     theRenderer->clearImage();
00240 
00241     // read in the rigid body offsets
00242     if (theOffsetFileName != 0) 
00243       theOffsetFile >> dX >> dY >> dZ;
00244 
00245     int endImage = 0;
00246     while (endImage == 0 && theFile >> drivel) { 
00247       if (strcmp(drivel,"DoneImage") == 0) {
00248         theRenderer->doneImage();
00249         endImage = 1;
00250       }
00251       else if (strcmp(drivel,"Line") == 0) {
00252         theFile >> pt(0) >> pt(1) >> pt(2) >> rgb(0) >> rgb(1) >> rgb(2);
00253         theFile >> pt2(0) >> pt2(1) >> pt2(2) >> rgb2(0) >> rgb2(1) >> rgb2(2);
00254 
00255         // add rigid body offsets
00256         if (theOffsetFileName != 0) {
00257           pt(0) += factor * dX; pt(1) += factor * dY; pt(2) += factor * dZ;
00258           pt2(0) += factor * dX; pt2(1) += factor * dY; pt2(2) += factor * dZ;
00259         }
00260 
00261         theRenderer->drawLine(pt,pt2,rgb,rgb2);
00262       }
00263     }
00264   }
00265 
00266   // close the files
00267   theFile.close();
00268   if (theOffsetFileName != 0) 
00269     theOffsetFile.close();      
00270 
00271   return 0;
00272 }
00273 
00274 int
00275 TclVideoPlayer_play(ClientData clientData, Tcl_Interp *interp, int argc, 
00276                     TCL_Char **argv)
00277 {
00278 #ifdef _NOGRAPHICS
00279 
00280 #else
00281   if (theTclVideoPlayer != 0)
00282     theTclVideoPlayer->play();
00283 #endif
00284   return TCL_OK;
00285 }
00286 

Generated on Mon Oct 23 15:05:31 2006 for OpenSees by doxygen 1.5.0