draw5.h

0000/******************************************************************
0001  draw5.h
0002  3D Geometry and Classes
0003******************************************************************/
0004#ifndef DRAW5
0005#define DRAW5
0006#include <vector>
0007#include <string>
0008#include "draw6.h"
0009using namespace std;
0010
0011struct Point2d{
0012 double x;
0013 double y;
0014};
0015
0016struct Point3d{
0017 double x;
0018 double y;
0019 double z;
0020};
0021
0022struct Line2d{
0023 double sx;
0024 double sy;
0025 double ex;
0026 double ey;
0027};
0028
0029struct Line3d{
0030 double sx;
0031 double sy;
0032 double sz;
0033 double ex;
0034 double ey;
0035 double ez;
0036};
0037
0038struct TransAngleEuler{
0039 double x;
0040 double y;
0041 double z;
0042 double theta;
0043 double phi;
0044 double psi;
0045};
0046
0047struct TransAngleMatrix{
0048 double x;
0049 double y;
0050 double z;
0051 double c[3][3];
0052};
0053
0054struct AngleEuler{
0055 double theta;
0056 double phi;
0057 double psi;
0058};
0059
0060struct AngleMatrix{
0061 double c[3][3];
0062};
0063
0064enum whichAxis{
0065 xAxis,
0066 yAxis,
0067 zAxis,
0068 yzAxis,
0069 zxAxis,
0070 xyAxis
0071};
0072
0073struct Surface2D{
0074 int n;
0075 Point2d p[1];
0076};
0077
0078struct Surface3D{
0079 int n;
0080 Point3d p[1];
0081};
0082
0083struct PointPerspectve{
0084 double az;  // measured clockwise from upward direction
0085 double el;  // measured radially from boresight
0086 double r;  // radius in the real unit
0087 double h;  // horizontal coordinte in Gnomonic projection
0088 double v;  // vertical coordinate in Gnomonic projection
0089};
0090
0091struct ClipByFrame{
0092 double az;  // measured clockwise from upward direction
0093 double el;  // measured radially from boresight
0094 double r;  // radius in the real unit
0095 double h;  // horizontal coordinte in Gnomonic projection
0096 double v;  // vertical coordinate in Gnomonic projection
0097};
0098
0099struct StartPTE{   // start and past-the-end indices
0100 int start;
0101 int pte;
0102};
0103
0104struct Surface{
0105 double x0;    // coordinate where the surface is on x-y plane
0106 double y0;
0107 double z0;
0108 double theta0;
0109 double phi0;
0110 double psi0;
0111 int start;   // start index of x-y coordinate array
0112 int pte;   // past-the-end index of x-y coordinate array
0113};
0114
0115
0116void DegreeToTAE(double theta,double phi,double psi,TransAngleEuler *dest);
0117void DegreeToAE(double theta,double phi,double psi,AngleEuler *dest);
0118void LinesToTAM(Line3d *a,Line3d *b,int w,TransAngleMatrix *dest);
0119void LinesToTAE(Line3d *a,Line3d *b,int w,TransAngleEuler *dest);
0120void PointsToAM(Point3d *a,Point3d *b,int w,AngleMatrix *dest);
0121void PointsToAE(Point3d *a,Point3d *b,int w,AngleEuler *dest);
0122void NormLine3d(Line3d *source,Point3d *dest,double *norm);
0123void NormPoint3d(Point3d *source,Point3d *dest,double *norm);
0124void NormLine2d(Line2d *source,Point2d *dest,double *norm);
0125void NormPoint2d(Point2d *source,Point2d *dest,double *norm);
0126void TAEtoTAM(TransAngleEuler *source,TransAngleMatrix *dest);
0127void TAMtoTAE(TransAngleMatrix *source,TransAngleEuler *dest);
0128void InverseTAM(TransAngleMatrix *source,TransAngleMatrix *dest);
0129void BodyToFrameTAM(Point3d *source,TransAngleMatrix *m,Point3d *dest);
0130void FrameToBodyTAM(Point3d *source,TransAngleMatrix *m,Point3d *dest);
0131void MoveTwiceTAE(TransAngleEuler *src1,TransAngleEuler *src2,TransAngleEuler *dest);
0132void AEtoAM(AngleEuler *source,AngleMatrix *dest);
0133void BodyToFrameAM(Point3d *source,AngleMatrix *m,Point3d *dest);
0134void FrameToBodyAM(Point3d *source,AngleMatrix *m,Point3d *dest);
0135void BodyToFrameAMP(Point2d *source,AngleMatrix *m,Point2d *dest);
0136void FrameToBodyAMP(Point2d *source,AngleMatrix *m,Point2d *dest);
0137void ToPolar3d(Point3d *source,Point2d *dest);
0138void ToCartesian3d(Point2d *source,Point3d *dest);
0139void VectorProduct(Point3d *u,Point3d *v,Point3d *w);
0140bool AcuteAngle(Point3d *u,Point3d *v,Point3d *w);
0141void MakeThePolar(Line3d *sight,TransAngleMatrix *polar);
0142void WorldToPolarCnv(Point3d *s,TransAngleMatrix *polar,Point3d *d);
0143void WorldToPerspCnv(Point3d *s,TransAngleMatrix *polar,PointPerspectve *d);
0144void ClipAngleMatrix(double azi,double inc,AngleMatrix *m,double *ang);
0145void SurfthePolarTAM(TransAngleEuler *s,TransAngleMatrix *p,TransAngleMatrix *sp);
0146void SurfToPolar(Point2d *s,TransAngleMatrix *sp,Point2d *p);
0147void PolarToSurf(Point2d *p,TransAngleMatrix *sp,Point2d *s);
0148int CrossClipSide(AngleMatrix *frame,double arc,Point2d *p1,
0149          Point2d *p2,Point2d *p,double *ang);
0150//void compactFarNear(StartPTE *farNear,int *n);
0151bool inferFarNear(StartPTE *farNear,long n,int p1,int p2,int *near);
0152bool recursFarNear(StartPTE *farNear,long n,int p1,int p2,long depth);
0153bool Overlap(Point2d *p,StartPTE *s1,StartPTE *s2,Point2d *p0);
0154void FarNearDist(TransAngleMatrix *s1,TransAngleMatrix *s2,Point2d *p,double *d);
0155void PolarToGnomo(Point2d *p,Point2d *g);
0156void GnomoToPolar(Point2d *g,Point2d *p);
0157double ArgDif(double x0,double y0,double x1,double y1,double x2,double y2);
0158bool SameSideOfSurface(Surface *s,Point3d *p1,Point3d *p2);
0159
0160enum{
0161 MPpoint,
0162 MPlines,
0163 MPplane,
0164 MPbox,
0165 MPsphere,
0166 MPbodyOfRot
0167};
0168
0169enum{
0170 MPwhite,
0171 MPgray,
0172 MPred,
0173 MPyellow,
0174 MPgreen,
0175 MPcyan,
0176 MPblue,
0177 MPmagenta
0178};
0179
0180enum{
0181 MPblack1,
0182 MPblack2,
0183 MPblack3,
0184 MPblack4,
0185 MPred3,
0186 MPred4,
0187 MPblue3,
0188 MPblue4
0189};
0190
0191
0192/******************************************************************************
0193 CMPpart.h
0194
0195  part of the concept
0196 ******************************************************************************/
0197
0198class CMPpart {
0199
0200public:
0201 int  kind;     /* kind of the part     */
0202 string  desc;     /* description of the part   */
0203 int  refPart;    /* reference part number   */
0204 double x0;      /* local coordinate referred to  */
0205 double y0;      /*    refPart    */
0206 double z0;
0207 double theta0;
0208 double phi0;
0209 double psi0;
0210 double  xg;      /* global coordinate referred to */
0211 double  yg;      /*    refPart 0   */
0212 double  zg;
0213 double  thetag;
0214 double  phig;
0215 double  psig;
0216 int  color;
0217 bool  showDrawing;
0218
0219 CMPpart(){};
0220 CMPpart(char *s,int ref,int knd): desc(s),refPart(ref),kind(knd){
0221  color=MPwhite;
0222  showDrawing=true;
0223 };
0224 ~CMPpart(){};
0225 void setCood(double x,double y,double z,double theta,double phi,double psi);
0226 void setColor(int i);
0227 void hide(void);
0228};
0229
0230/******************************************************************************
0231 CMPpoint.h
0232
0233  part of the concept - point
0234 ******************************************************************************/
0235
0236class CMPpoint : public CMPpart {
0237
0238public:
0239 CMPpoint(){};
0240 CMPpoint(char *s,int ref,int knd): CMPpart(s,ref,knd){
0241 };
0242 ~CMPpoint(){};
0243
0244};
0245
0246/******************************************************************************
0247 CMPlines.h
0248
0249  part of the concept - lines
0250 ******************************************************************************/
0251
0252class CMPlines : public CMPpart {
0253
0254public:
0255 int  npoint; 
0256 vector<Point3d> pt;
0257 int line;
0258        /** Instance Methods **/
0259 CMPlines(){};
0260 CMPlines(char *s,int ref,int knd): CMPpart(s,ref,knd){
0261  npoint=0;
0262 };
0263 ~CMPlines(){};
0264
0265 void SetPoint(double x,double y,double z);
0266 void GetSurface(int m,TransAngleMatrix *po,Surface *surf,Point2d *surfPt);
0267 void GetDrawData(int m,TransAngleMatrix *po,
0268     Line2d *seg,StartPTE *blk,StartPTE *cont);
0269 void FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0270
0271
0272};
0273/******************************************************************************
0274 CMPplane.h
0275
0276  part of the concept - plane
0277 ******************************************************************************/
0278
0279class CMPplane : public CMPpart {
0280
0281public:
0282 int  npoint; 
0283 vector<Point2d> pt;
0284 bool  isPolyhed;  // if TRUE surface of a polyhedron
0285 bool  isGroup;  // if TRUE this and the next are a group
0286 CMPplane *otherHalf;  // other half in a group
0287
0288 CMPplane(){};
0289 CMPplane(char *s,int ref,int knd): CMPpart(s,ref,knd){
0290  npoint=0;
0291  isPolyhed=0;
0292  isGroup=0;
0293  otherHalf=0;
0294 };
0295 ~CMPplane(){};
0296
0297 void SetPoint(double x,double y);
0298 void GetSurface(TransAngleMatrix *po,Surface *surf,Point2d *surfPt);
0299 void GetDrawData(TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont);
0300 void GetDrawData1(TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont);
0301 void FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0302 bool FacingViewer(Point3d *po);
0303
0304};
0305
0306/******************************************************************************
0307 CMPbox.h
0308
0309  part of the concept - box
0310 ******************************************************************************/
0311
0312class CMPbox : public CMPpart {
0313
0314public:
0315 double lx;
0316 double ly;
0317 double lz;
0318 int  visibleSurface;  // bit set if the surface is visible
0319 int objid; // object supplied throgh a file if not 0
0320
0321 CMPbox(){};
0322 CMPbox(char *s,int ref,int knd): CMPpart(s,ref,knd){
0323  visibleSurface=0;  // initialize as all invisible
0324  objid=0;
0325 };
0326 ~CMPbox(){};
0327
0328 void SetSize(double x,double y,double z);
0329 void ClearVisSurface(void);
0330 bool GetSurface(int n,TransAngleMatrix *po,Surface *surf,Point2d *surfPt);
0331 void GetCenter(Point3d *p);
0332 void GetDrawData(TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont);
0333 void FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0334
0335
0336};
0337
0338/******************************************************************************
0339 CMPsphere.h
0340
0341  part of the concept - sphere
0342 ******************************************************************************/
0343
0344class CMPsphere : public CMPpart {
0345
0346public:
0347 double r;
0348 CMPsphere(){};
0349 CMPsphere(char *s,int ref,int knd): CMPpart(s,ref,knd){
0350 };
0351 ~CMPsphere(){};
0352
0353 void SetRadius(double x);
0354 void GetSurface(TransAngleMatrix *p,Surface *surf,Point2d *surfPt);
0355 void GetDrawData(TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont);
0356 void FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0357
0358};
0359
0360/******************************************************************************
0361 CMPbodyOfRot.h
0362
0363  part of the concept - bodyOfRot
0364 ******************************************************************************/
0365
0366class CMPbodyOfRot : public CMPpart {
0367
0368public:
0369        /** Instance Variables **/
0370 int  npoint; 
0371 Point2d p0;
0372 Point2d p1;
0373 bool  isTube;
0374 bool  oblong;
0375 int  appear;
0376 int visibleSurface;  // used by GetSurface
0377
0378 CMPbodyOfRot(){};
0379 CMPbodyOfRot(char *s,int ref,int knd): CMPpart(s,ref,knd){
0380  color=MPwhite;
0381  showDrawing=true;
0382  npoint=0;
0383  isTube=false;
0384  oblong=false;
0385  visibleSurface=0;
0386 };
0387 ~CMPbodyOfRot(){};
0388
0389 void SetPoint(double x,double z);
0390 void ClearVisSurface(void);
0391 bool GetSurface(int n,bool nearside,TransAngleMatrix *po,
0392    Surface *surf,Point2d *surfPt);
0393 void GetCenter(Point3d *p);
0394 void GetDrawData(int m,TransAngleMatrix *po,
0395     Line2d *seg,StartPTE *blk,StartPTE *cont);
0396 void GetDrawData1(TransAngleMatrix *po,
0397     Line2d *seg,StartPTE *blk,StartPTE *cont);
0398 void  FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0399
0400};
0401
0402/******************************************************************************
0403 CThreeD  Data Processing for Three Dimensional Drawing
0404 ******************************************************************************/
0405
0406class CThreeD{
0407
0408public:
0409 vector<CMPpart*> part;
0410 int npart;
0411 bool   contAll; // if the picture contains all of the target
0412 double  Azi;
0413 double  Ele;
0414 double  Dst;
0415 double  Tgx;
0416 double  Tgy;
0417 double  Tgz;
0418
0419 int   Wid;
0420 int   Hei;
0421 int   Foc;
0422 
0423 int   ContPen;  // contour pen size
0424
0425 TransAngleMatrix thePolar; // the polar coordinate
0426 Point2d  RtBm;    // clip frame right-bottom corner in polar coord
0427 Point2d  TpRt;    // clip frame top-right corner in polar coord
0428 Point2d  LtTp;    // clip frame left-top corner in polar coord
0429 Point2d  BmLt;    // clip frame bottom-left corner in polar coord
0430 AngleMatrix frameRt;   // frame right side
0431 AngleMatrix frameTp;   // frame top side
0432 AngleMatrix frameLt;   // frame left side
0433 AngleMatrix frameBm;   // frame bottom side
0434 double  angFrameRt;   // frame right side span (rad)
0435 double  angFrameTp;   // frame top side
0436 double  angFrameLt;   // frame left side
0437 double  angFrameBm;   // frame bottom side
0438
0439 int  npart1;    // number of parts after no 1 decomposition
0440 StartPTE *partpart1;  // part number coresponding to part1 number
0441         // pte - index beginning 0 within the part
0442 StartPTE *part1part;  // start and end of part1 for a part
0443
0444 int  npart2;    // number of parts after no 2 decomposition
0445 int  npart2m;   // upper limit of nsurf
0446 int  npoin;    // number of point
0447 int  npoinm;    // upper limit of npoin
0448 StartPTE *part2part1;  // part2 surfaces belonging to a part1 object
0449 int  *part1part2;  // part1 number corresponding to part2 number
0450   
0451 Surface  *part2;   // array of surfaces
0452 Point2d  *local;   // points by local coordinate
0453 Point2d  *viewed;   // points by viewing coordinate
0454
0455 int  *sorted;   // sorted order of part1 objects
0456
0457 double  focus;    // focal length
0458
0459 int message;
0460 int postscript;
0461 int omni;
0462
0463 CThreeD(){
0464  npart=0;
0465  contAll=true;
0466  Tgx=0;
0467  Tgy=0;
0468  Tgz=0;
0469  message=0;
0470  postscript=0;
0471  omni=0;
0472 };
0473 ~CThreeD(){};
0474 void Draw(void);
0475 void AlignCoord(void);
0476 void VuControl(void);
0477 void MemorySetUp( void);
0478 void MakePart2(void); // part2 is surfaces to be used in the far-near comp
0479 void NearFarRelations(void);
0480 void DrawView(void);
0481 void ClipSurface(Surface *surf1,Point2d *surfPt1,
0482          Surface *surf2,Point2d *surfPt2);
0483 void ClipSegments(StartPTE *blk,StartPTE *cont,Line2d *seg);
0484 char *ToDB(int *len);
0485 void FromDB(int len,char *d,double loc[6]);
0486};
0487
0488/******************************************************************************
0489 CFarNear Far-Near relationship of 3D Drawing Objects
0490 ******************************************************************************/
0491
0492class CFarNear { 
0493
0494public:
0495        /** Instance Variables **/
0496 StartPTE *farNear;
0497 long *farNearIndex;
0498 long npart1;
0499 long nmax;
0500 long n;
0501   
0502        /** Instance Methods **/
0503 CFarNear(){};
0504 CFarNear(int numpart1);
0505 ~CFarNear();
0506
0507 void AddFarNear(int far,int near);
0508 bool InferFarNear(int p1,int p2,int *m);
0509 bool RecurseFarNear(int p1,int p2,long depth);
0510 int SetSorted(int *sorted);
0511
0512};
0513
0514/************************************
0515 user interface
0516************************************/
0517int addelm(char * s,int ref,int knd);
0518void setlocal(double x,double y,double z,double theta,double phi,double psi);
0519void setcolor(int c);
0520int setline(int c);
0521int isTube();
0522int set1Dpoint(double x);
0523int set2Dpoint(double x,double y);
0524int set3Dpoint(double x,double y,double z);
0525void viewFrom(double a,double b,double r);
0526void drawMessage(int i);
0527void postscript3D(int i);
0528void viewFixed(double tgx,double tgy,double tgz,int foc);
0529int draw3D(int wid,int hei);
0530void getCoord(int ref,double x,double y,double z,int *ix,int *iy);
0531char *insert3D(int *len);
0532void select3D(int len,char *d,double x,double y,double z,double theta,double phi,double psi);
0533void parts3D(int style);
0534void omnidirect(int omni);
0535#endif
0536