sg3D.h
Upload User: kairuinn
Upload Date: 2009-02-07
Package Size: 2922k
Code Size: 9k
Category:

Graph program

Development Platform:

Visual C++

  1. #ifndef  __sg3D__
  2. #define  __sg3D__
  3. /************************************************************************/
  4. /* 3DObject                                                                */
  5. /************************************************************************/
  6. typedef struct
  7. {
  8.   unsigned short begin_vertex_index;
  9.   unsigned short end_vertex_index;
  10.   unsigned short edge_type;
  11. }  SG_EDGE;
  12. typedef struct 
  13. {
  14. long   ver_indexes[3];
  15. } SG_INDEX_TRIANGLE;
  16. /* edge_type:*/
  17. #define  SG_EDGE_1_LEVEL          0x0001
  18. #define  SG_EDGE_2_LEVEL          0x0002
  19. #define  SG_EDGE_3_LEVEL          0x0004
  20. typedef enum
  21. {
  22.   SG_UNKNOWN_3D=0,
  23.   SG_BODY,
  24.   SG_SURFACE,
  25. } SG_3DOBJECT_TYPE;
  26. typedef enum
  27. {
  28. SG_VERTEX_TRIANGULATION,
  29. SG_DELAUNAY_TRIANGULATION
  30. } SG_TRIANGULATION_TYPE;
  31. typedef struct
  32. {
  33.   int                nTr;
  34.   SG_POINT*          allVertex;
  35.   SG_VECTOR*         allNormals;
  36.   double*            allUV;
  37. } SG_ALL_TRIANGLES;
  38. typedef  enum
  39. {
  40.   SG_MODULATE_MIX_TYPE=1,
  41.   SG_BLEND_MIX_TYPE   =2,
  42.   SG_REPLACE_MIX_TYPE =3
  43. } SG_MIX_COLOR_TYPE;
  44. typedef  enum
  45. {
  46.   SG_CUBE_UV_TYPE      =1,
  47.   SG_SPHERIC_UV_TYPE   =2,
  48.   SG_CYLINDER_UV_TYPE  =3
  49. } SG_UV_TYPE;
  50. typedef  struct
  51. {
  52.   int       MaterialIndex;
  53.   double    TextureScaleU;
  54.   double    TextureScaleV;
  55.   double    TextureShiftU;
  56.   double    TextureShiftV;
  57.   double    TextureAngle;
  58.   bool      TextureSmooth;
  59.   bool      TextureMult;
  60.   SG_MIX_COLOR_TYPE MixColorType;
  61.   SG_UV_TYPE        TextureUVType;
  62. } SG_MATERIAL;
  63. class sgC3DObject;
  64. class sgCBRep;
  65. /************************************************************************/
  66. /* Boundary representation piece                                        */
  67. /************************************************************************/
  68. class sgCore_API   sgCBRepPiece
  69. {
  70. friend class  sgCBRep;
  71. PRIVATE_ACCESS
  72. private:
  73. void*         m_brep_piece_handle;
  74. SG_POINT*     m_vertexes;
  75. unsigned int  m_vertexes_count;
  76. SG_EDGE*      m_edges;
  77. unsigned int  m_edges_count;
  78. SG_POINT      m_min;
  79. SG_POINT      m_max;
  80. int           m_min_triangle_number;
  81. int           m_max_triangle_number;
  82. sgCBRepPiece();
  83. ~sgCBRepPiece();
  84. public:
  85. void             GetLocalGabarits(SG_POINT& p_min, SG_POINT& p_max) const;
  86. const SG_POINT*  GetVertexes() const;
  87. unsigned int     GetVertexesCount() const;
  88. const SG_EDGE*   GetEdges() const;
  89. unsigned int     GetEdgesCount() const;
  90. void             GetTrianglesRange(int& min_numb, int& max_numb) const;
  91. };
  92. /************************************************************************/
  93. /* Boundary representation                                              */
  94. /************************************************************************/
  95. class sgCore_API   sgCBRep
  96. {
  97. friend class sgC3DObject;
  98. PRIVATE_ACCESS
  99. private:
  100.     sgCBRep();
  101. ~sgCBRep();
  102. sgCBRepPiece**         m_pieces;
  103. unsigned int           m_pieces_count;
  104. public:
  105. sgCBRepPiece*          GetPiece(unsigned int) const;
  106. unsigned int           GetPiecesCount() const;
  107. };
  108. /************************************************************************/
  109. /* 3D object base class                                                 */
  110. /************************************************************************/
  111. class sgCore_API   sgC3DObject : public sgCObject
  112. {
  113. protected:
  114.   sgC3DObject();
  115.   sgC3DObject(SG_OBJ_HANDLE);
  116.   virtual    ~sgC3DObject();
  117. public:
  118.   static     void         AutoTriangulate(bool,SG_TRIANGULATION_TYPE);
  119.   bool                    Triangulate(SG_TRIANGULATION_TYPE);
  120.   SG_3DOBJECT_TYPE        Get3DObjectType() const;
  121.   sgCBRep*                GetBRep()  const;
  122.   const SG_ALL_TRIANGLES* GetTriangles() const;
  123.   virtual  bool           ApplyTempMatrix();
  124.   const double*           GetWorldMatrixData() const;
  125.   void                    SetMaterial(const SG_MATERIAL&);
  126.   const  SG_MATERIAL*     GetMaterial();
  127.   bool                    CalculateOptimalUV(double& optU, double& optV);
  128.   double                  GetVolume();
  129.   double                  GetSquare();
  130. private:
  131.   SG_3DOBJECT_TYPE    m_objectType;
  132.   sgCBRep*            m_brep;
  133.   bool                CopyBRepStructure();
  134.   SG_ALL_TRIANGLES*   m_triangles;
  135.   void                CalcUV();
  136.   sgCMatrix*          m_world_matrix;
  137.   SG_MATERIAL*        m_material;
  138.   PRIVATE_ACCESS
  139. };
  140. /************************************************************************/
  141. /* Box                                                                  */
  142. /************************************************************************/
  143. typedef struct
  144. {
  145.   double  SizeX;
  146.   double  SizeY;
  147.   double  SizeZ;
  148. } SG_BOX;
  149. class sgCore_API   sgCBox : public sgC3DObject
  150. {
  151. private:
  152.   sgCBox();
  153.   sgCBox(SG_OBJ_HANDLE);
  154.   virtual    ~sgCBox();
  155. public:
  156.   static   sgCBox*    Create(double sizeX, double sizeY, double sizeZ);
  157.   void                GetGeometry(SG_BOX& ) const;
  158.   PRIVATE_ACCESS
  159. };
  160. #define  sgCreateBox  sgCBox::Create
  161. /************************************************************************/
  162. /* Sphere                                                                 */
  163. /************************************************************************/
  164. typedef struct
  165. {
  166.   double  Radius;
  167.   short   MeridiansCount;
  168.   short   ParallelsCount;
  169. } SG_SPHERE;
  170. class sgCore_API   sgCSphere : public sgC3DObject
  171. {
  172. private:
  173.   sgCSphere();
  174.   sgCSphere(SG_OBJ_HANDLE);
  175.   virtual    ~sgCSphere();
  176. public:
  177.   static   sgCSphere*    Create(double rad, short merid, short parall);
  178.   void                   GetGeometry(SG_SPHERE&) const;
  179.   PRIVATE_ACCESS
  180. };
  181. #define  sgCreateSphere  sgCSphere::Create
  182. /************************************************************************/
  183. /* Cylinder                                                                 */
  184. /************************************************************************/
  185. typedef struct
  186. {
  187.   double  Radius;
  188.   double  Height;
  189.   short   MeridiansCount;
  190. } SG_CYLINDER;
  191. class sgCore_API   sgCCylinder : public sgC3DObject
  192. {
  193. private:
  194.   sgCCylinder();
  195.   sgCCylinder(SG_OBJ_HANDLE);
  196.   virtual    ~sgCCylinder();
  197. public:
  198.   static   sgCCylinder*    Create(double rad, double heig, short merid);
  199.   void           GetGeometry(SG_CYLINDER&) const;
  200.   PRIVATE_ACCESS
  201. };
  202. #define  sgCreateCylinder  sgCCylinder::Create
  203. /************************************************************************/
  204. /* Cone                                                                 */
  205. /************************************************************************/
  206. typedef struct
  207. {
  208.   double  Radius1;
  209.   double  Radius2;
  210.   double  Height;
  211.   short   MeridiansCount;
  212. } SG_CONE;
  213. class sgCore_API   sgCCone : public sgC3DObject
  214. {
  215. private:
  216.   sgCCone();
  217.   sgCCone(SG_OBJ_HANDLE);
  218.   virtual    ~sgCCone();
  219. public:
  220.   static   sgCCone*    Create(double rad_1,double rad_2,double heig, short merid);
  221.   void         GetGeometry(SG_CONE&) const;
  222.   PRIVATE_ACCESS
  223. };
  224. #define  sgCreateCone  sgCCone::Create
  225. /************************************************************************/
  226. /* Torus                                                                 */
  227. /************************************************************************/
  228. typedef struct
  229. {
  230.   double  Radius1;
  231.   double  Radius2;
  232.   short   MeridiansCount1;
  233.   short   MeridiansCount2;
  234. } SG_TORUS;
  235. class sgCore_API   sgCTorus : public sgC3DObject
  236. {
  237. private:
  238.   sgCTorus();
  239.   sgCTorus(SG_OBJ_HANDLE);
  240.   virtual    ~sgCTorus();
  241. public:
  242.   static   sgCTorus*    Create(double r1,double r2,short m1,short m2);
  243.   void          GetGeometry(SG_TORUS&) const;
  244.   PRIVATE_ACCESS
  245. };
  246. #define  sgCreateTorus  sgCTorus::Create
  247. /************************************************************************/
  248. /* Ellipsoid                                                                 */
  249. /************************************************************************/
  250. typedef struct
  251. {
  252.   double  Radius1;
  253.   double  Radius2;
  254.   double  Radius3;
  255.   short   MeridiansCount;
  256.   short   ParallelsCount;
  257. } SG_ELLIPSOID;
  258. class sgCore_API   sgCEllipsoid : public sgC3DObject
  259. {
  260. private:
  261.   sgCEllipsoid();
  262.   sgCEllipsoid(SG_OBJ_HANDLE);
  263.   virtual    ~sgCEllipsoid();
  264. public:
  265.   static   sgCEllipsoid*    Create(double radius1, double radius2, double radius3,
  266.                     short merid_cnt, short parall_cnt);
  267.   void            GetGeometry(SG_ELLIPSOID&) const;
  268.   PRIVATE_ACCESS
  269. };
  270. #define  sgCreateEllipsoid  sgCEllipsoid::Create
  271. /************************************************************************/
  272. /* SphericBand                                                                 */
  273. /************************************************************************/
  274. typedef struct
  275. {
  276.   double  Radius;
  277.   double  BeginCoef;
  278.   double  EndCoef;
  279.   short   MeridiansCount;
  280. } SG_SPHERIC_BAND;
  281. class sgCore_API   sgCSphericBand : public sgC3DObject
  282. {
  283. private:
  284.   sgCSphericBand();
  285.   sgCSphericBand(SG_OBJ_HANDLE);
  286.   virtual    ~sgCSphericBand();
  287. public:
  288.   static   sgCSphericBand*    Create(double radius, double beg_koef,
  289.                       double end_koef,
  290.                       short merid_cnt);
  291.   void              GetGeometry(SG_SPHERIC_BAND&) const;
  292.   PRIVATE_ACCESS
  293. };
  294. #define  sgCreateSphericBand    sgCSphericBand::Create
  295. #endif