draw13.h

0000/******************************************************************
0001  draw13.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);
0160
0161enum{
0162 MPpoint,
0163 MPlines,
0164 MPplane,
0165 MPbox,
0166 MPsphere,
0167 MPbodyOfRot
0168};
0169
0170enum{
0171 MPwhite,
0172 MPgray,
0173 MPred,
0174 MPyellow,
0175 MPgreen,
0176 MPcyan,
0177 MPblue,
0178 MPmagenta
0179};
0180
0181enum{
0182 MPblack1,
0183 MPblack2,
0184 MPblack3,
0185 MPblack4,
0186 MPred3,
0187 MPred4,
0188 MPblue3,
0189 MPblue4
0190};
0191
0192
0193/******************************************************************************
0194 CMPpart.h
0195
0196  part of the concept
0197 ******************************************************************************/
0198
0199class CMPpart {
0200
0201public:
0202 int  kind;     /* kind of the part     */
0203 string  desc;     /* description of the part   */
0204 int  refPart;    /* reference part number   */
0205 double x0;      /* local coordinate referred to  */
0206 double y0;      /*    refPart    */
0207 double z0;
0208 double theta0;
0209 double phi0;
0210 double psi0;
0211 double  xg;      /* global coordinate referred to */
0212 double  yg;      /*    refPart 0   */
0213 double  zg;
0214 double  thetag;
0215 double  phig;
0216 double  psig;
0217 int  color;
0218 bool  showDrawing;
0219
0220 CMPpart(){};
0221 CMPpart(char *s,int ref,int knd): desc(s),refPart(ref),kind(knd){
0222  color=MPwhite;
0223  showDrawing=true;
0224 };
0225 ~CMPpart(){};
0226 void setCood(double x,double y,double z,double theta,double phi,double psi);
0227 void setColor(int i);
0228 void hide(void);
0229};
0230
0231/******************************************************************************
0232 CMPpoint.h
0233
0234  part of the concept - point
0235 ******************************************************************************/
0236
0237class CMPpoint : public CMPpart {
0238
0239public:
0240 CMPpoint(){};
0241 CMPpoint(char *s,int ref,int knd): CMPpart(s,ref,knd){
0242 };
0243 ~CMPpoint(){};
0244
0245};
0246
0247/******************************************************************************
0248 CMPlines.h
0249
0250  part of the concept - lines
0251 ******************************************************************************/
0252
0253class CMPlines : public CMPpart {
0254
0255public:
0256 int  npoint; 
0257 vector<Point3d> pt;
0258 int line;
0259        /** Instance Methods **/
0260 CMPlines(){};
0261 CMPlines(char *s,int ref,int knd): CMPpart(s,ref,knd){
0262  npoint=0;
0263 };
0264 ~CMPlines(){
0265   pt.clear();
0266 };
0267
0268 void SetPoint(double x,double y,double z);
0269 void GetSurface(int m,TransAngleMatrix *po,Surface *surf,Point2d *surfPt);
0270 void GetDrawData(int m,TransAngleMatrix *po,
0271     Line2d *seg,StartPTE *blk,StartPTE *cont);
0272 void FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0273
0274
0275};
0276/******************************************************************************
0277 CMPplane.h
0278
0279  part of the concept - plane
0280 ******************************************************************************/
0281
0282class CMPplane : public CMPpart {
0283
0284public:
0285 int  npoint; 
0286 vector<Point2d> pt;
0287 bool  isPolyhed;  // if TRUE surface of a polyhedron
0288 bool  isGroup;  // if TRUE this and the next are a group
0289 CMPplane *otherHalf;  // other half in a group
0290 int ndeco;
0291 vector<CMPpldeco*> deco;
0292
0293 CMPplane(){};
0294 CMPplane(char *s,int ref,int knd): CMPpart(s,ref,knd){
0295  npoint=0;
0296  isPolyhed=0;
0297  isGroup=0;
0298  otherHalf=0;
0299  ndeco=0;
0300 };
0301 ~CMPplane(){
0302  pt.clear();
0303  if(ndeco) deco.clear();
0304 };
0305
0306 void SetPoint(double x,double y);
0307 void GetSurface(TransAngleMatrix *po,Surface *surf,Point2d *surfPt);
0308 void GetDrawData(TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont);
0309 void GetDrawData1(TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont);
0310 void FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0311 bool FacingViewer(Point3d *po);
0312 void GetDrawDeco(int id,TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont,int *color);
0313 void AddDeco(CMPpldeco *d);
0314
0315};
0316
0317/******************************************************************************
0318 CMPbox.h
0319
0320  part of the concept - box
0321 ******************************************************************************/
0322
0323class CMPbox : public CMPpart {
0324
0325public:
0326 double lx;
0327 double ly;
0328 double lz;
0329 int  visibleSurface;  // bit set if the surface is visible
0330
0331 CMPbox(){};
0332 CMPbox(char *s,int ref,int knd): CMPpart(s,ref,knd){
0333  visibleSurface=0;  // initialize as all invisible
0334 };
0335 ~CMPbox(){};
0336
0337 void SetSize(double x,double y,double z);
0338 void ClearVisSurface(void);
0339 bool GetSurface(int n,TransAngleMatrix *po,Surface *surf,Point2d *surfPt);
0340 void GetCenter(Point3d *p);
0341 void GetDrawData(TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont);
0342 void FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0343
0344
0345};
0346
0347/******************************************************************************
0348 CMPsphere.h
0349
0350  part of the concept - sphere
0351 ******************************************************************************/
0352
0353class CMPsphere : public CMPpart {
0354
0355public:
0356 double r;
0357 CMPsphere(){};
0358 CMPsphere(char *s,int ref,int knd): CMPpart(s,ref,knd){
0359 };
0360 ~CMPsphere(){};
0361
0362 void SetRadius(double x);
0363 void GetSurface(TransAngleMatrix *p,Surface *surf,Point2d *surfPt);
0364 void GetDrawData(TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont);
0365 void FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0366
0367};
0368
0369/******************************************************************************
0370 CMPbodyOfRot.h
0371
0372  part of the concept - bodyOfRot
0373 ******************************************************************************/
0374
0375class CMPbodyOfRot : public CMPpart {
0376
0377public:
0378        /** Instance Variables **/
0379 int  npoint; 
0380 Point2d p0;
0381 Point2d p1;
0382 bool  isTube;
0383 bool  oblong;
0384 int  appear;
0385 int visibleSurface;  // used by GetSurface
0386
0387 CMPbodyOfRot(){};
0388 CMPbodyOfRot(char *s,int ref,int knd): CMPpart(s,ref,knd){
0389  color=MPwhite;
0390  showDrawing=true;
0391  npoint=0;
0392  isTube=false;
0393  oblong=false;
0394  visibleSurface=0;
0395 };
0396 ~CMPbodyOfRot(){};
0397
0398 void SetPoint(double x,double z);
0399 void ClearVisSurface(void);
0400 bool GetSurface(int n,bool nearside,TransAngleMatrix *po,
0401    Surface *surf,Point2d *surfPt);
0402 void GetCenter(Point3d *p);
0403 void GetDrawData(int m,TransAngleMatrix *po,
0404     Line2d *seg,StartPTE *blk,StartPTE *cont);
0405 void GetDrawData1(TransAngleMatrix *po,
0406     Line2d *seg,StartPTE *blk,StartPTE *cont);
0407 void  FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0408
0409};
0410
0411/******************************************************************************
0412 CThreeD  Data Processing for Three Dimensional Drawing
0413 ******************************************************************************/
0414
0415class CThreeD{
0416
0417public:
0418 vector<CMPpart*> part;
0419 int npart;
0420 bool   contAll; // if the picture contains all of the target
0421 double  Azi;
0422 double  Ele;
0423 double  Dst;
0424 double  Tgx;
0425 double  Tgy;
0426 double  Tgz;
0427
0428 int   Wid;
0429 int   Hei;
0430 int   Foc;
0431 
0432 int   ContPen;  // contour pen size
0433
0434 TransAngleMatrix thePolar; // the polar coordinate
0435 Point2d  RtBm;    // clip frame right-bottom corner in polar coord
0436 Point2d  TpRt;    // clip frame top-right corner in polar coord
0437 Point2d  LtTp;    // clip frame left-top corner in polar coord
0438 Point2d  BmLt;    // clip frame bottom-left corner in polar coord
0439 AngleMatrix frameRt;   // frame right side
0440 AngleMatrix frameTp;   // frame top side
0441 AngleMatrix frameLt;   // frame left side
0442 AngleMatrix frameBm;   // frame bottom side
0443 double  angFrameRt;   // frame right side span (rad)
0444 double  angFrameTp;   // frame top side
0445 double  angFrameLt;   // frame left side
0446 double  angFrameBm;   // frame bottom side
0447
0448 int  npart1;    // number of parts after no 1 decomposition
0449 StartPTE *partpart1;  // part number coresponding to part1 number
0450         // pte - index beginning 0 within the part
0451 StartPTE *part1part;  // start and end of part1 for a part
0452
0453 int  npart2;    // number of parts after no 2 decomposition
0454 int  npart2m;   // upper limit of nsurf
0455 int  npoin;    // number of point
0456 int  npoinm;    // upper limit of npoin
0457 StartPTE *part2part1;  // part2 surfaces belonging to a part1 object
0458 int  *part1part2;  // part1 number corresponding to part2 number
0459   
0460 Surface  *part2;   // array of surfaces
0461 Point2d  *local;   // points by local coordinate
0462 Point2d  *viewed;   // points by viewing coordinate
0463
0464 int  *sorted;   // sorted order of part1 objects
0465
0466 double  focus;    // focal length
0467
0468 int message;
0469
0470 CThreeD(){
0471  npart=0;
0472  contAll=true;
0473  Tgx=0;
0474  Tgy=0;
0475  Tgz=0;
0476  message=0;
0477 };
0478 ~CThreeD(){};
0479 void Draw(void);
0480 void AlignCoord(void);
0481 void VuControl(void);
0482 void MemorySetUp( void);
0483 void MakePart2(void); // part2 is surfaces to be used in the far-near comp
0484 void NearFarRelations(void);
0485 void DrawView(void);
0486 void ClipSurface(Surface *surf1,Point2d *surfPt1,
0487          Surface *surf2,Point2d *surfPt2);
0488 char *ToDB(int *len);
0489 void FromDB(int len,char *d,double loc[6]);
0490};
0491
0492/******************************************************************************
0493 CFarNear Far-Near relationship of 3D Drawing Objects
0494 ******************************************************************************/
0495
0496class CFarNear { 
0497
0498public:
0499        /** Instance Variables **/
0500 StartPTE *farNear;
0501 long *farNearIndex;
0502 long npart1;
0503 long nmax;
0504 long n;
0505   
0506        /** Instance Methods **/
0507 CFarNear(){};
0508 CFarNear(int numpart1);
0509 ~CFarNear();
0510
0511 void AddFarNear(int far,int near);
0512 bool InferFarNear(int p1,int p2,int *m);
0513 bool RecurseFarNear(int p1,int p2,long depth);
0514 int SetSorted(int *sorted);
0515
0516};
0517
0518/*****************************************************************************
0519 CMPpldeco Plane Decoration
0520*****************************************************************************/
0521
0522class CMPpldeco {
0523
0524 public:
0525  int ncontour;
0526  vector<Point2d> contour;
0527  int nlineseg;
0528  vector<Line2d> lineseg;
0529  int color;
0530  StartPTE blk;
0531  StartPTE cont;
0532  Line2d *seg;
0533  CMPplane *p;
0534
0535  CMPpldeco(CMPplane *pl){p=pl;ncontour=nlineseg=0;};
0536  ~CMPpldeco(){contour.clear();lineseg.clear();}
0537  
0538  int GetDrawData(TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont);
0539};
0540
0541/************************************
0542 user interface
0543************************************/
0544int addelm(char * s,int ref,int knd);
0545void setlocal(double x,double y,double z,double theta,double phi,double psi);
0546void setcolor(int c);
0547int setline(int c);
0548int isTube();
0549int oblong();
0550int set1Dpoint(double x);
0551int set2Dpoint(double x,double y);
0552int set3Dpoint(double x,double y,double z);
0553void addpldeco();
0554void decocontxy(double x,double y);
0555void decocontco(int color);
0556void decolinexy(double x0,double y0,double x1, double y1);
0557void viewFrom(double a,double b,double r);
0558void drawMessage(int i);
0559void viewFixed(double tgx,double tgy,double tgz,int foc);
0560int draw3D(int wid,int hei);
0561void getCoord(int ref,double x,double y,double z,int *ix,int *iy);
0562char *insert3D(int *len);
0563void select3D(int len,char *d,double x,double y,double z,double theta,double phi,double psi);
0564void parts3D(int style);
0565int setting(double a[],int b[]);
0566int drawobj(int id,double tae[]);
0567#endif
0568