draw17.h
0000/******************************************************************
0001 draw17.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 CMPdeco;
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<CMPdeco*> 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};
0313
0314/******************************************************************************
0315 CMPbox.h
0316
0317 part of the concept - box
0318 ******************************************************************************/
0319
0320class CMPbox : public CMPpart {
0321
0322public:
0323 double lx;
0324 double ly;
0325 double lz;
0326 int visibleSurface; // bit set if the surface is visible
0327
0328 CMPbox(){};
0329 CMPbox(char *s,int ref,int knd): CMPpart(s,ref,knd){
0330 visibleSurface=0; // initialize as all invisible
0331 };
0332 ~CMPbox(){};
0333
0334 void SetSize(double x,double y,double z);
0335 void ClearVisSurface(void);
0336 bool GetSurface(int n,TransAngleMatrix *po,Surface *surf,Point2d *surfPt);
0337 void GetCenter(Point3d *p);
0338 void GetDrawData(TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont);
0339 void FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0340
0341
0342};
0343
0344/******************************************************************************
0345 CMPsphere.h
0346
0347 part of the concept - sphere
0348 ******************************************************************************/
0349
0350class CMPsphere : public CMPpart {
0351
0352public:
0353 double r;
0354 int ndeco;
0355 vector<CMPdeco*> deco;
0356
0357 CMPsphere(){};
0358 CMPsphere(char *s,int ref,int knd): CMPpart(s,ref,knd){
0359 ndeco=0;
0360 };
0361 ~CMPsphere(){
0362 if(ndeco) deco.clear();
0363 };
0364
0365 void SetRadius(double x);
0366 void GetSurface(TransAngleMatrix *p,Surface *surf,Point2d *surfPt);
0367 void GetDrawData(TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont);
0368 void FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0369
0370};
0371
0372/******************************************************************************
0373 CMPbodyOfRot.h
0374
0375 part of the concept - bodyOfRot
0376 ******************************************************************************/
0377
0378class CMPbodyOfRot : public CMPpart {
0379
0380public:
0381 /** Instance Variables **/
0382 int npoint;
0383 Point2d p0;
0384 Point2d p1;
0385 bool isTube;
0386 bool oblong;
0387 int appear;
0388 int visibleSurface; // used by GetSurface
0389 int ndeco;
0390 vector<CMPdeco*> deco;
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 ndeco=0;
0401 };
0402 ~CMPbodyOfRot(){
0403 if(ndeco) deco.clear();
0404 };
0405
0406 void SetPoint(double x,double z);
0407 void ClearVisSurface(void);
0408 bool GetSurface(int n,bool nearside,TransAngleMatrix *po,
0409 Surface *surf,Point2d *surfPt);
0410 void GetCenter(Point3d *p);
0411 void GetDrawData(int m,TransAngleMatrix *po,
0412 Line2d *seg,StartPTE *blk,StartPTE *cont);
0413 void GetDrawData1(TransAngleMatrix *po,
0414 Line2d *seg,StartPTE *blk,StartPTE *cont);
0415 void FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0416
0417};
0418
0419/******************************************************************************
0420 CThreeD Data Processing for Three Dimensional Drawing
0421 ******************************************************************************/
0422
0423class CThreeD{
0424
0425public:
0426 vector<CMPpart*> part;
0427 int npart;
0428 bool contAll; // if the picture contains all of the target
0429 double Azi;
0430 double Ele;
0431 double Dst;
0432 double Tgx;
0433 double Tgy;
0434 double Tgz;
0435
0436 int Wid;
0437 int Hei;
0438 int Foc;
0439
0440 int ContPen; // contour pen size
0441
0442 TransAngleMatrix thePolar; // the polar coordinate
0443 Point2d RtBm; // clip frame right-bottom corner in polar coord
0444 Point2d TpRt; // clip frame top-right corner in polar coord
0445 Point2d LtTp; // clip frame left-top corner in polar coord
0446 Point2d BmLt; // clip frame bottom-left corner in polar coord
0447 AngleMatrix frameRt; // frame right side
0448 AngleMatrix frameTp; // frame top side
0449 AngleMatrix frameLt; // frame left side
0450 AngleMatrix frameBm; // frame bottom side
0451 double angFrameRt; // frame right side span (rad)
0452 double angFrameTp; // frame top side
0453 double angFrameLt; // frame left side
0454 double angFrameBm; // frame bottom side
0455
0456 int npart1; // number of parts after no 1 decomposition
0457 StartPTE *partpart1; // part number coresponding to part1 number
0458 // pte - index beginning 0 within the part
0459 StartPTE *part1part; // start and end of part1 for a part
0460
0461 int npart2; // number of parts after no 2 decomposition
0462 int npart2m; // upper limit of nsurf
0463 int npoin; // number of point
0464 int npoinm; // upper limit of npoin
0465 StartPTE *part2part1; // part2 surfaces belonging to a part1 object
0466 int *part1part2; // part1 number corresponding to part2 number
0467
0468 Surface *part2; // array of surfaces
0469 Point2d *local; // points by local coordinate
0470 Point2d *viewed; // points by viewing coordinate
0471
0472 int *sorted; // sorted order of part1 objects
0473
0474 double focus; // focal length
0475
0476 int message;
0477
0478 CThreeD(){
0479 npart=0;
0480 contAll=true;
0481 Tgx=0;
0482 Tgy=0;
0483 Tgz=0;
0484 message=0;
0485 };
0486 ~CThreeD(){};
0487 void Draw(void);
0488 void AlignCoord(void);
0489 void VuControl(void);
0490 void MemorySetUp( void);
0491 void MakePart2(void); // part2 is surfaces to be used in the far-near comp
0492 void NearFarRelations(void);
0493 void DrawView(void);
0494 void ClipSurface(Surface *surf1,Point2d *surfPt1,
0495 Surface *surf2,Point2d *surfPt2);
0496 char *ToDB(int *len);
0497 void FromDB(int len,char *d,double loc[6]);
0498};
0499
0500/******************************************************************************
0501 CFarNear Far-Near relationship of 3D Drawing Objects
0502 ******************************************************************************/
0503
0504class CFarNear {
0505
0506public:
0507 /** Instance Variables **/
0508 StartPTE *farNear;
0509 long *farNearIndex;
0510 long npart1;
0511 long nmax;
0512 long n;
0513
0514 /** Instance Methods **/
0515 CFarNear(){};
0516 CFarNear(int numpart1);
0517 ~CFarNear();
0518
0519 void AddFarNear(int far,int near);
0520 bool InferFarNear(int p1,int p2,int *m);
0521 bool RecurseFarNear(int p1,int p2,long depth);
0522 int SetSorted(int *sorted);
0523
0524};
0525
0526/*****************************************************************************
0527 CMPdeco Plane Decoration
0528*****************************************************************************/
0529
0530class CMPdeco {
0531
0532 public:
0533 int ncontour;
0534 vector<Point2d> contour;
0535 int nlineseg;
0536 vector<Line2d> lineseg;
0537 int color;
0538 StartPTE blk;
0539 StartPTE cont;
0540 Line2d *seg;
0541 CMPpart *p;
0542
0543 CMPdeco(CMPpart *pl){p=pl;ncontour=nlineseg=0;};
0544 ~CMPdeco(){contour.clear();lineseg.clear();}
0545
0546 int GetDrawData(TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont);
0547};
0548
0549/************************************
0550 user interface
0551************************************/
0552int addelm(char * s,int ref,int knd);
0553void setlocal(double x,double y,double z,double theta,double phi,double psi);
0554void setcolor(int c);
0555int setline(int c);
0556int isTube();
0557int oblong();
0558int set1Dpoint(double x);
0559int set2Dpoint(double x,double y);
0560int set3Dpoint(double x,double y,double z);
0561void adddeco();
0562void decocontxy(double x,double y);
0563void decocontco(int color);
0564void decolinexy(double x0,double y0,double x1, double y1);
0565void viewFrom(double a,double b,double r);
0566void drawMessage(int i);
0567void viewFixed(double tgx,double tgy,double tgz,int foc);
0568int draw3D(int wid,int hei);
0569void getCoord(int ref,double x,double y,double z,int *ix,int *iy);
0570char *insert3D(int *len);
0571void select3D(int len,char *d,double x,double y,double z,double theta,double phi,double psi);
0572void parts3D(int style);
0573int setting(double a[],int b[]);
0574int drawobj(int id,double tae[]);
0575int styleVF16(double scx,double scy,double ang);
0576int drawVF16(double xs,double ys,char *st);
0577#endif
0578