VrmlViewer.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.4 $
00022 // $Date: 2003/02/19 15:43:25 $
00023 // $Source: /usr/local/cvs/OpenSees/SRC/renderer/VrmlViewer.cpp,v $
00024                                                                         
00025                                                                         
00026 // File: ~/graphics/VrmlViewer.C
00027 //
00028 // Written: fmk 
00029 // Created: 1/99
00030 // Revision: A
00031 //
00032 // Description: This file contains the class definition for VrmlViewer.
00033 // VrmlViewer is an class which diplays using X11 or openGL.
00034 //
00035 // What: "@(#) VrmlViewer.h, revA"
00036 
00037 #include <VrmlViewer.h>
00038 #include <ColorMap.h>
00039 
00040 #include <OPS_Globals.h>
00041 #include <iomanip>
00042 using std::ios;
00043 
00044 #include <string.h>
00045 
00046 #include <stdlib.h>
00047 #include <stdio.h>
00048 
00049 #include <Vector.h>
00050 
00051 VrmlViewer::VrmlViewer(char *fileName,
00052                        Domain &_theDomain, ColorMap &_theMap)
00053   :Renderer(_theMap)
00054 {
00055     strcpy(vrmlFileName, fileName);
00056     vrmlFile = new fstream(vrmlFileName, ios::out);
00057     if (vrmlFile == 0) {
00058         opserr << "FATAL - VrmlViewer::VrmlViewer() - could not open file ";
00059         opserr << fileName << endln;
00060         exit(-1);
00061     }
00062   (*vrmlFile) << "#VRML V2.0 utf8 \n";        
00063 }
00064 
00065 VrmlViewer::~VrmlViewer()
00066 {
00067     vrmlFile->close();
00068     delete vrmlFile;
00069 }
00070 
00071 int 
00072 VrmlViewer::clearImage(void)
00073 {
00074     // open the file again
00075     vrmlFile = new fstream(vrmlFileName, ios::out);
00076     if (vrmlFile == 0) {
00077         opserr << "FATAL - VrmlViewer::clearImage() - could not open file ";
00078         opserr << vrmlFileName << endln;
00079         return -1;
00080     }
00081   (*vrmlFile) << "#VRML V2.0 utf8 \n";    
00082     return 0;
00083 }
00084 
00085 
00086 int 
00087 VrmlViewer::doneImage(void)
00088 {
00089     vrmlFile->close();
00090     return 0;
00091 }
00092 
00093 int 
00094 VrmlViewer::drawLine(const Vector &pos1, const Vector &pos2, 
00095                        float V1, float V2)
00096 {
00097   float x,y,z, r, g, b;
00098 
00099 
00100     (*vrmlFile) << "Shape { geometry IndexedLineSet ";
00101   (*vrmlFile) << "{ coord Coordinate { \n\t\t point [\n";
00102   
00103   int size = pos1.Size();
00104   if (size == 1) {
00105     x = pos1(0);
00106     y = 0;
00107     z = 0;
00108   } else if (size == 2) {
00109     x = pos1(0);
00110     y = pos1(1);
00111     z = 0;
00112   } else {
00113     x = pos1(0);
00114     y = pos1(1);
00115     z = pos1(2);
00116   }  
00117   (*vrmlFile) << "\t\t\t " << x << "  " << y << "  " << z << ",\n";
00118   
00119 
00120 
00121   size = pos2.Size();
00122   if (size == 1) {
00123     x = pos2(0);
00124     y = 0;
00125     z = 0;
00126   } else if (size == 2) {
00127     x = pos2(0);
00128     y = pos2(1);
00129     z = 0;
00130   } else {
00131     x = pos2(0);
00132     y = pos2(1);
00133     z = pos2(2);
00134   }  
00135 
00136   (*vrmlFile) << "\t\t\t " << x << "  " << y << "  " << z << " ] }\n";  
00137   (*vrmlFile) << "          coordIndex [ 0 1 ]\n";  
00138   (*vrmlFile) << "          colorPerVertex TRUE\n ";    
00139   (*vrmlFile) << "          color Color { \n\t color [\n";  
00140   
00141   r = theMap->getRed(V1);
00142   g = theMap->getGreen(V1);
00143   b = theMap->getBlue(V1);
00144 
00145   (*vrmlFile) << "\t\t\t " << r << "  " << g << "  " << b << ",\n";
00146   
00147   r = theMap->getRed(V2);
00148   g = theMap->getGreen(V2);
00149   b = theMap->getBlue(V2);
00150 
00151   (*vrmlFile) << "\t\t\t " << r << "  " << g << "  " << b << " ] \n }}}\n";
00152   
00153   return 0;
00154 }
00155 
00156 
00157 
00158 
00159 
00160 int 
00161 VrmlViewer::drawTriangle(const Vector &pos1, const Vector &pos2,
00162                            const Vector &pos3,
00163                            float V1, float V2, float V3)
00164 {
00165   int size;
00166   float x,y,z, r, g, b;
00167 
00168   (*vrmlFile) << "Shape { geometry IndexedFaceSet ";
00169   (*vrmlFile) << "{ coord Coordinate { \n\t\t point [\n";  
00170   
00171   size = pos1.Size();
00172   if (size == 1) {
00173     x = pos1(0);
00174     y = 0;
00175     z = 0;
00176   } else if (size == 2) {
00177     x = pos1(0);
00178     y = pos1(1);
00179     z = 0;
00180   } else {
00181     x = pos1(0);
00182     y = pos1(1);
00183     z = pos1(2);
00184   }  
00185 
00186   (*vrmlFile) << "\t\t\t " << x << "  " << y << "  " << z << ",\n";
00187 
00188   size = pos2.Size();
00189   if (size == 1) {
00190     x = pos2(0);
00191     y = 0;
00192     z = 0;
00193   } else if (size == 2) {
00194     x = pos2(0);
00195     y = pos2(1);
00196     z = 0;
00197   } else {
00198     x = pos2(0);
00199     y = pos2(1);
00200     z = pos2(2);
00201   }  
00202 
00203   (*vrmlFile) << "\t\t\t " << x << "  " << y << "  " << z << ",\n";
00204   
00205   size = pos3.Size();
00206   if (size == 1) {
00207     x = pos3(0);
00208     y = 0;
00209     z = 0;
00210   } else if (size == 2) {
00211     x = pos3(0);
00212     y = pos3(1);
00213     z = 0;
00214   } else {
00215     x = pos3(0);
00216     y = pos3(1);
00217     z = pos3(2);
00218   }  
00219 
00220   (*vrmlFile) << "\t\t\t " << x << "  " << y << "  " << z << " ] }\n";  
00221   (*vrmlFile) << "          coordIndex [ 0 1 2 ]\n";  
00222   (*vrmlFile) << "          colorPerVertex TRUE\n ";    
00223   (*vrmlFile) << "          color Color { \n\t color [\n";  
00224   
00225   r = theMap->getRed(V1);
00226   g = theMap->getGreen(V1);
00227   b = theMap->getBlue(V1);
00228   
00229   (*vrmlFile) << "\t\t\t " << r << "  " << g << "  " << b << ",\n";
00230       
00231   r = theMap->getRed(V2);
00232   g = theMap->getGreen(V2);
00233   b = theMap->getBlue(V2);
00234   
00235   (*vrmlFile) << "\t\t\t " << r << "  " << g << "  " << b << ",\n";  
00236 
00237   r = theMap->getRed(V3);
00238   g = theMap->getGreen(V3);
00239   b = theMap->getBlue(V3);
00240 
00241   (*vrmlFile) << "\t\t\t " << r << "  " << g << "  " << b << " ] \n }}}\n";
00242   
00243   return 0;
00244 }
00245 
00246 
00247 int 
00248 VrmlViewer::setVRP(float x, float y, float z)
00249 {
00250   return 0;
00251 }
00252 
00253 
00254 int 
00255 VrmlViewer::setVPN(float x, float y, float z) 
00256 {
00257   return 0;
00258 }
00259 
00260 int 
00261 VrmlViewer::setVUP(float x, float y, float z) 
00262 {
00263   return 0;
00264 }
00265 
00266 int 
00267 VrmlViewer::setViewWindow(float, float, float, float) 
00268 {
00269   return 0;
00270 }
00271 
00272 int 
00273 VrmlViewer::setPlaneDist(float, float) 
00274 {
00275   return 0;
00276 }
00277 
00278 int 
00279 VrmlViewer::setProjectionMode(int) 
00280 {
00281   return 0;
00282 }
00283 
00284 int 
00285 VrmlViewer::setFillMode(int)    
00286 {
00287   return 0;
00288 }
00289 
00290 int 
00291 VrmlViewer::setPRP(float u, float v, float n) 
00292 {
00293   return 0;
00294 }
00295 
00296 int 
00297 VrmlViewer::setPortWindow(float, float, float, float)
00298 {
00299   return 0;
00300 }
00301 

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