draw14.h

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