draw12.h

0000/******************************************************************
0001  draw12.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   pt.clear();
0265 };
0266
0267 void SetPoint(double x,double y,double z);
0268 void GetSurface(int m,TransAngleMatrix *po,Surface *surf,Point2d *surfPt);
0269 void GetDrawData(int m,TransAngleMatrix *po,
0270     Line2d *seg,StartPTE *blk,StartPTE *cont);
0271 void FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0272
0273
0274};
0275/******************************************************************************
0276 CMPplane.h
0277
0278  part of the concept - plane
0279 ******************************************************************************/
0280
0281class CMPplane : public CMPpart {
0282
0283public:
0284 int  npoint; 
0285 vector<Point2d> pt;
0286 bool  isPolyhed;  // if TRUE surface of a polyhedron
0287 bool  isGroup;  // if TRUE this and the next are a group
0288 CMPplane *otherHalf;  // other half in a group
0289
0290 CMPplane(){};
0291 CMPplane(char *s,int ref,int knd): CMPpart(s,ref,knd){
0292  npoint=0;
0293  isPolyhed=0;
0294  isGroup=0;
0295  otherHalf=0;
0296 };
0297 ~CMPplane(){
0298  pt.clear();
0299 };
0300
0301 void SetPoint(double x,double y);
0302 void GetSurface(TransAngleMatrix *po,Surface *surf,Point2d *surfPt);
0303 void GetDrawData(TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont);
0304 void GetDrawData1(TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont);
0305 void FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0306 bool FacingViewer(Point3d *po);
0307
0308};
0309
0310/******************************************************************************
0311 CMPbox.h
0312
0313  part of the concept - box
0314 ******************************************************************************/
0315
0316class CMPbox : public CMPpart {
0317
0318public:
0319 double lx;
0320 double ly;
0321 double lz;
0322 int  visibleSurface;  // bit set if the surface is visible
0323
0324 CMPbox(){};
0325 CMPbox(char *s,int ref,int knd): CMPpart(s,ref,knd){
0326  visibleSurface=0;  // initialize as all invisible
0327 };
0328 ~CMPbox(){};
0329
0330 void SetSize(double x,double y,double z);
0331 void ClearVisSurface(void);
0332 bool GetSurface(int n,TransAngleMatrix *po,Surface *surf,Point2d *surfPt);
0333 void GetCenter(Point3d *p);
0334 void GetDrawData(TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont);
0335 void FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0336
0337
0338};
0339
0340/******************************************************************************
0341 CMPsphere.h
0342
0343  part of the concept - sphere
0344 ******************************************************************************/
0345
0346class CMPsphere : public CMPpart {
0347
0348public:
0349 double r;
0350 CMPsphere(){};
0351 CMPsphere(char *s,int ref,int knd): CMPpart(s,ref,knd){
0352 };
0353 ~CMPsphere(){};
0354
0355 void SetRadius(double x);
0356 void GetSurface(TransAngleMatrix *p,Surface *surf,Point2d *surfPt);
0357 void GetDrawData(TransAngleMatrix *po,Line2d *seg,StartPTE *blk,StartPTE *cont);
0358 void FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0359
0360};
0361
0362/******************************************************************************
0363 CMPbodyOfRot.h
0364
0365  part of the concept - bodyOfRot
0366 ******************************************************************************/
0367
0368class CMPbodyOfRot : public CMPpart {
0369
0370public:
0371        /** Instance Variables **/
0372 int  npoint; 
0373 Point2d p0;
0374 Point2d p1;
0375 bool  isTube;
0376 bool  oblong;
0377 int  appear;
0378 int visibleSurface;  // used by GetSurface
0379
0380 CMPbodyOfRot(){};
0381 CMPbodyOfRot(char *s,int ref,int knd): CMPpart(s,ref,knd){
0382  color=MPwhite;
0383  showDrawing=true;
0384  npoint=0;
0385  isTube=false;
0386  oblong=false;
0387  visibleSurface=0;
0388 };
0389 ~CMPbodyOfRot(){};
0390
0391 void SetPoint(double x,double z);
0392 void ClearVisSurface(void);
0393 bool GetSurface(int n,bool nearside,TransAngleMatrix *po,
0394    Surface *surf,Point2d *surfPt);
0395 void GetCenter(Point3d *p);
0396 void GetDrawData(int m,TransAngleMatrix *po,
0397     Line2d *seg,StartPTE *blk,StartPTE *cont);
0398 void GetDrawData1(TransAngleMatrix *po,
0399     Line2d *seg,StartPTE *blk,StartPTE *cont);
0400 void  FieldOfView(TransAngleMatrix *vu,Point2d *az,Point2d *el);
0401
0402};
0403
0404/******************************************************************************
0405 CThreeD  Data Processing for Three Dimensional Drawing
0406 ******************************************************************************/
0407
0408class CThreeD{
0409
0410public:
0411 vector<CMPpart*> part;
0412 int npart;
0413 bool   contAll; // if the picture contains all of the target
0414 double  Azi;
0415 double  Ele;
0416 double  Dst;
0417 double  Tgx;
0418 double  Tgy;
0419 double  Tgz;
0420
0421 int   Wid;
0422 int   Hei;
0423 int   Foc;
0424 
0425 int   ContPen;  // contour pen size
0426
0427 TransAngleMatrix thePolar; // the polar coordinate
0428 Point2d  RtBm;    // clip frame right-bottom corner in polar coord
0429 Point2d  TpRt;    // clip frame top-right corner in polar coord
0430 Point2d  LtTp;    // clip frame left-top corner in polar coord
0431 Point2d  BmLt;    // clip frame bottom-left corner in polar coord
0432 AngleMatrix frameRt;   // frame right side
0433 AngleMatrix frameTp;   // frame top side
0434 AngleMatrix frameLt;   // frame left side
0435 AngleMatrix frameBm;   // frame bottom side
0436 double  angFrameRt;   // frame right side span (rad)
0437 double  angFrameTp;   // frame top side
0438 double  angFrameLt;   // frame left side
0439 double  angFrameBm;   // frame bottom side
0440
0441 int  npart1;    // number of parts after no 1 decomposition
0442 StartPTE *partpart1;  // part number coresponding to part1 number
0443         // pte - index beginning 0 within the part
0444 StartPTE *part1part;  // start and end of part1 for a part
0445
0446 int  npart2;    // number of parts after no 2 decomposition
0447 int  npart2m;   // upper limit of nsurf
0448 int  npoin;    // number of point
0449 int  npoinm;    // upper limit of npoin
0450 StartPTE *part2part1;  // part2 surfaces belonging to a part1 object
0451 int  *part1part2;  // part1 number corresponding to part2 number
0452   
0453 Surface  *part2;   // array of surfaces
0454 Point2d  *local;   // points by local coordinate
0455 Point2d  *viewed;   // points by viewing coordinate
0456
0457 int  *sorted;   // sorted order of part1 objects
0458
0459 double  focus;    // focal length
0460
0461 int message;
0462
0463 CThreeD(){
0464  npart=0;
0465  contAll=true;
0466  Tgx=0;
0467  Tgy=0;
0468  Tgz=0;
0469  message=0;
0470 };
0471 ~CThreeD(){};
0472 void Draw(void);
0473 void AlignCoord(void);
0474 void VuControl(void);
0475 void MemorySetUp( void);
0476 void MakePart2(void); // part2 is surfaces to be used in the far-near comp
0477 void NearFarRelations(void);
0478 void DrawView(void);
0479 void ClipSurface(Surface *surf1,Point2d *surfPt1,
0480          Surface *surf2,Point2d *surfPt2);
0481 char *ToDB(int *len);
0482 void FromDB(int len,char *d,double loc[6]);
0483};
0484
0485/******************************************************************************
0486 CFarNear Far-Near relationship of 3D Drawing Objects
0487 ******************************************************************************/
0488
0489class CFarNear { 
0490
0491public:
0492        /** Instance Variables **/
0493 StartPTE *farNear;
0494 long *farNearIndex;
0495 long npart1;
0496 long nmax;
0497 long n;
0498   
0499        /** Instance Methods **/
0500 CFarNear(){};
0501 CFarNear(int numpart1);
0502 ~CFarNear();
0503
0504 void AddFarNear(int far,int near);
0505 bool InferFarNear(int p1,int p2,int *m);
0506 bool RecurseFarNear(int p1,int p2,long depth);
0507 int SetSorted(int *sorted);
0508
0509};
0510
0511/************************************
0512 user interface
0513************************************/
0514int addelm(char * s,int ref,int knd);
0515void setlocal(double x,double y,double z,double theta,double phi,double psi);
0516void setcolor(int c);
0517int setline(int c);
0518int isTube();
0519int oblong();
0520int set1Dpoint(double x);
0521int set2Dpoint(double x,double y);
0522int set3Dpoint(double x,double y,double z);
0523void viewFrom(double a,double b,double r);
0524void drawMessage(int i);
0525void viewFixed(double tgx,double tgy,double tgz,int foc);
0526int draw3D(int wid,int hei);
0527void getCoord(int ref,double x,double y,double z,int *ix,int *iy);
0528char *insert3D(int *len);
0529void select3D(int len,char *d,double x,double y,double z,double theta,double phi,double psi);
0530void parts3D(int style);
0531int setting(double a[],int b[]);
0532int drawobj(int id,double tae[]);
0533#endif
0534