Main Page   Namespace List   Compound List   File List   Compound Members   File Members  

Coordinate.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003 Eric Bohm
00003  *
00004  *This program is free software; you can redistribute it and/or modify
00005  *it under the terms of the GNU General Public License as published by
00006  *the Free Software Foundation version 2 of the License.
00007  * 
00008  *This program is distributed in the hope that it will be useful, but
00009  *WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  *General Public License for more details.
00012  * 
00013  *You should have received a copy of the GNU General Public License along
00014  *with this program; if not, write to the Free Software Foundation, Inc.,
00015  *675 Mass Ave, Cambridge, MA 02139, USA.
00016  *
00017  */
00018 
00019 #ifndef IS_COORDINATE_DEF_SIG
00020 #define IS_COORDINATE_DEF_SIG 1
00021 
00022 #include <fstream.h>
00023 #include <math.h>
00025 
00031 class Coordinate
00032 {
00033 private:
00034   unsigned int id;
00035   GLdouble x, y, z;
00036   GLfloat r, g, b;
00037   char label[30];
00038 public:
00040   Coordinate(unsigned int iid, GLdouble ix, GLdouble iy, GLdouble iz,
00041              GLfloat ir, GLfloat ig, GLfloat ib)
00042     :id(iid), x(ix), y(iy), z(iz), r(ir), g(ig), b(ib)
00043   {
00044     snprintf(label, 30, "%d: %6.3f,%6.3f,%6.3f", id, x, y, z);
00045   }
00046 
00048   Coordinate()
00049   {
00050     id = 0;
00051     x = y = z = 0.0;
00052     snprintf(label, 30, "%d:%6.3f,%6.3f,%6.3f",id, x, y, z);
00053   }
00054 
00056   Coordinate & operator=(const Coordinate & obj)
00057   {
00058     if(this == &obj)
00059       {
00060         return *this;
00061       }
00062     id = obj.id;
00063     x = obj.x;
00064     y = obj.y;
00065     z = obj.z;
00066     r = obj.r;
00067     g = obj.g;
00068     b = obj.b;
00069     snprintf(label, 30, "%d:%6.3f,%6.3f,%6.3f", id, x, y, z);
00070     return *this;
00071   }
00072 
00074   void set(GLdouble ix, GLdouble iy, GLdouble iz)
00075   {
00076     x = ix;
00077     y = iy;
00078     z = iz;
00079     snprintf(label, 30, "%d:%6.3f,%6.3f,%6.3f", id, x, y, z);
00080   }
00081 
00083   void set_rgb(GLfloat ir, GLfloat ig, GLfloat ib)
00084   {
00085     r = ir;
00086     g = ig;
00087     b = ib;
00088   }
00089 
00091   void unsafe_set(GLdouble ix, GLdouble iy, GLdouble iz)
00092   {
00093     x = ix;
00094     y = iy;
00095     z = iz;
00096   }
00097 
00099   GLdouble get_r()
00100   {
00101     return (r);
00102   }
00103 
00105   GLdouble get_g()
00106   {
00107     return (g);
00108   }
00109 
00111   GLdouble get_b()
00112   {
00113     return (b);
00114   }
00115 
00117   GLdouble get_x()
00118   {
00119     return (x);
00120   }
00121 
00123   void set_x(GLdouble ix)
00124   {
00125     x = ix;
00126     snprintf(label, 30, "%d:%6.3f,%6.3f,%6.3f", id, x, y, z);
00127   }
00128 
00130   GLdouble get_y()
00131   {
00132     return (y);
00133   }
00134 
00136   void set_y(GLdouble iy)
00137   {
00138     y = iy;
00139     snprintf(label, 30, "%d:%6.3f,%6.3f,%6.3f", id, x, y, z);
00140   }
00142   GLdouble get_z()
00143   {
00144     return (z);
00145   }
00146 
00148   void set_z(GLdouble iz)
00149   {
00150     z = iz;
00151     snprintf(label, 30, "%d:%6.3f,%6.3f,%6.3f", id, x, y, z);
00152   }
00153 
00155   char *get_label()
00156   {
00157     return label;
00158   }
00159 
00161   unsigned int get_id()
00162   {
00163     return id;
00164   }
00166   bool operator==(const Coordinate & obj) const
00167   {
00168     return ((x == obj.x) && (y == obj.y) && (z == obj.z));
00169   }
00170   
00172   bool idmatch(const Coordinate & obj) const
00173   {
00174     return (id == obj.id);
00175   }
00176 
00178   bool operator<(const Coordinate & obj) const
00179   {
00180 
00181     //start with distance from origin
00182     //    GLdouble sq1=sqrt(x*x+y*y+z*z);
00183     //GLdouble sq2=sqrt(obj.x*obj.x+obj.y*obj.y+obj.z*obj.z);
00184     //    if(sq1==sq2)
00185     //      {
00186         // if same distance try regular compare
00187     //  if((x<obj.x)&&(y<obj.y)&&(z < obj.z))
00188     //    return(true);
00189     //  else
00190           return((x<obj.x)||(y<obj.y)||(z < obj.z));
00191           //      }
00192           //    else
00193           //      return(sq1<sq2);
00194   }
00195   
00197   void dump()
00198   {
00199     printf(" %s\n", label);
00200 
00201   }
00202   void edump()
00203   {
00204     fprintf(stderr, "%s %lf %lf %lf %f %f %f\n", label, x, y, z, r, g, b);
00205 
00206   }
00207 
00209   void fdump(ofstream & outfile)
00210   {
00211     char formed[80];
00212 
00213     snprintf(formed, 80, "%f %f %f %f %f %f\n", x, y, z, r, g, b);
00214     outfile << formed;
00215   }
00216 
00217 };
00218 
00219 
00220 #endif

Generated on Wed Oct 29 10:01:52 2003 for Tetraviewer by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002