home *** CD-ROM | disk | FTP | other *** search
/ Explore the World of Soft…e: Engineering & Science / Explore_the_World_of_Software_Engineering_and_Science_HRS_Software_1998.iso / programs / civil_en / dome350.exe / DXFTOPOV.CPP < prev    next >
C/C++ Source or Header  |  1995-04-08  |  6KB  |  174 lines

  1. //$Id: dxftopov.cpp 1.2 1995/02/06 13:53:42 PONDERMATIC Released PONDERMATIC $
  2.  
  3. /*
  4. DXFTOPOV.CPP - A program utility to convert DXF 3D line data to POV-ray script
  5.                format. This program only converts DXF line entities.
  6.  
  7.      Copyright (C) 1995  Richard J. Bono
  8.  
  9.      This program is free software; you can redistribute it and/or modify
  10.      it under the terms of the GNU General Public License as published by
  11.      the Free Software Foundation; either version 2 of the License, or
  12.      any later version.
  13.  
  14.      This program is distributed in the hope that it will be useful,
  15.      but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.      GNU General Public License for more details.
  18.  
  19.      You should have received a copy of the GNU General Public License
  20.      along with this program; if not, write to the Free Software
  21.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23.      Please direct inquiries, comments and modifications to:
  24.      Richard J. Bono
  25.      44 Augusta Rd.
  26.      Brownsville, TX 78521
  27.  
  28.      email: 70324.1712@compuserve.com
  29.                     -or-
  30.              rjbono@AOL.com
  31.  
  32. Revision history:
  33.  
  34. $Log: dxftopov.cpp $
  35. 'Revision 1.2  1995/02/06  13:53:42  PONDERMATIC
  36. 'Added a few carriage returns and updated revision
  37. 'levels
  38. '
  39. 'Revision 1.1  1995/02/06  13:47:55  PONDERMATIC
  40. 'Initial.
  41. '
  42.  
  43. Acknowledgements & References:
  44. Kirby Urner for subtly guiding my thought processes over a three day-weekend
  45. resulting in this code. Chris Fearnley for providing GNU POV scripts for several
  46. polyhedrons. Most of the POV header sections came from Chris' scripts. POV-ray
  47. is available on most on-line services and through the internet. DXF file format
  48. data is available on Compuserve. Search for file R12DXF.TXT in the Acad forum.
  49.  
  50. Compilation:
  51. This program was complied and tested using Borland C++ 4.5 using the large
  52. memory model on a Gateway 2000 4DX2-50V. The released executables were
  53. compiled using Borland C++ 3.1
  54.  
  55. Comments:
  56. This program is about as quick and dirty as they come. GNU DOME produces DXF
  57. files of a geodesic dome symmetry triangle. This data can be imported into a
  58. CAD program and manipulated to form full spheres, truncations, etc and then
  59. saved back as a DXF file. This program will convert the DXF file into a POV-ray
  60. file for rendering. It is currently the quickest way to generate full sphere
  61. POV scripts. It can be used on any DXF file whice uses LINE primatives. No
  62. other geometry is converted.
  63. */
  64.  
  65. #include<iostream.h>
  66. #include<iomanip.h>
  67. #include<fstream.h>
  68. #include<stdlib.h>
  69. #include<conio.h>
  70. #include<string.h>
  71.  
  72. static char rcsid[]="$Id: dxftopov.cpp 1.2 1995/02/06 13:53:42 PONDERMATIC Released PONDERMATIC $";
  73.  
  74. void main(int argc, char *argv[]);
  75.  
  76. void main(int argc, char *argv[])
  77. {
  78.     char DXFfile[80];
  79.     char POVfile[80];
  80.     char DXF_line[80];
  81.     double sX, sY, sZ, eX, eY, eZ;
  82.     int temp, line_ok;
  83.  
  84.     cout << "DXFtoPOV 1.20, Copyright (C) 1995, Richard J. Bono" << '\n';
  85.     cout << "DXFtoPOV comes with ABSOLUTELY NO WARRANTY. This is free software," << '\n';
  86.     cout << "and you are welcome to redistribute it under certain conditions." << '\n';
  87.     cout << "See GNU Genral Public License for more details." << '\n' << '\n';
  88.  
  89.     if(argc != 3){
  90.         cout << "Usage - DXFTOPOV filename.DXF filename.POV";
  91.         exit(0);
  92.     }
  93.     else if(argc == 3){
  94.         strcpy(DXFfile, argv[1]);
  95.         strcpy(POVfile, argv[2]);
  96.     }
  97.     else{
  98.         cout << "Command line error --- Terminating Execution" << '\n';
  99.         cout << "Type DXFTOPOV for usage" << '\n';
  100.     }
  101.  
  102.     //Open file streams DXF for input POV for output
  103.     ifstream DXF(DXFfile);
  104.     ofstream POV(POVfile);
  105.  
  106.     //set up format for POV file data
  107.     POV << setiosflags(ios::fixed) << setw(8) << setprecision(6);
  108.  
  109.     //set up file header
  110.     POV << "//POV-Ray script" << '\n';
  111.     POV << "#include" << '"' << "colors.inc" << '"' << '\n' << '\n';
  112.     POV << "#declare Cam_factor = 6" << '\n';
  113.     POV << "#declare Camera_X = 1 * Cam_factor" << '\n';
  114.     POV << "#declare Camera_Y = 0.5 * Cam_factor" << '\n';
  115.     POV << "#declare Camera_Z = -0.3 * Cam_factor" << '\n';
  116.  
  117.     POV << "camera { location  <Camera_X, Camera_Y, Camera_Z>" << '\n';
  118.     POV << "        up        <0, 1.0,  0>    right     <-1.33, 0,  0>" << '\n';
  119.     POV << "        direction <0, 0,  3>      look_at   <0, 0, 0> }" << '\n' << '\n';
  120.  
  121.     POV << "light_source { <Camera_X - 2, Camera_Y + 5 , Camera_Z + 5> color White }" << '\n';
  122.     POV << "light_source { <Camera_X - 2, Camera_Y + 5 , Camera_Z - 3> color White }" << '\n';
  123.  
  124.     POV << '\n' << "// Background:" << '\n';
  125.     POV << "background {color Gray70}" << '\n' << '\n';
  126.  
  127.     POV << "// POV script created by DXFTOPOV: " << '\n' << '\n';
  128.  
  129.     POV << "union {" << '\n';
  130.  
  131.     //Get the chord data
  132.     do{
  133.         //get a line and see if says LINE
  134.         DXF >> DXF_line;
  135.         temp = strcmp(DXF_line, "LINE");
  136.         if(temp == 0){
  137.             //found a line...now get 1st point
  138.             do{
  139.                 line_ok = 1;
  140.                 //now look for starting X coordinate
  141.                 DXF >> DXF_line;
  142.                 temp = strcmp(DXF_line, "10");
  143.                 if(temp == 0){
  144.                     //found coordinates, get and store
  145.                     DXF >> sX;
  146.                     DXF >> DXF_line;
  147.                     DXF >> sY;
  148.                     DXF >> DXF_line;
  149.                     DXF >> sZ;
  150.                     DXF >> DXF_line;
  151.                     DXF >> eX;
  152.                     DXF >> DXF_line;
  153.                     DXF >> eY;
  154.                     DXF >> DXF_line;
  155.                     DXF >> eZ;
  156.                     line_ok = 0;
  157.                     //save data to POV script
  158.                     POV << "cylinder{<" << sX << ", " << sY << ", " << sZ << ">, ";
  159.                     POV << "<" << eX << ", " << eY << ", " << eZ << ">,0.015 pigment {Red} no_shadow}" << '\n';
  160.                 }
  161.             }while(line_ok == 1);
  162.         }
  163.     }while(!DXF.eof());    //keep going until there is no more data
  164.     //add a rotation
  165.     POV << "rotate <0, 68, 0> }" << '\n';
  166.  
  167.     //close the data files
  168.     POV.close();
  169.     DXF.close();
  170.  
  171.     cout << "Conversion complete!" << '\n';
  172. }
  173.  
  174.