⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 slsdef.h

📁 快速原型制造分层切片源代码,适用于高温合金.
💻 H
字号:
//SlsDef.h
//
///////////////////////////////////////////////////////////

#ifndef __SLSDEF_H__
#define __SLSDEF_H__

#include <math.h>
#include <iostream.h>
///////////////////////////////////////////////////////////
//define constants

#define	PI atan(1.0)*4
#define BUFFERSIZE 1024

enum OUTPUTFILETYPE{ASCIIOUTPUTFILE,BINOUTPUTFILE};
enum STLFILETYPE{ASCIISTLFILE,BINSTLFILE,NONSTLFILE=-1};
enum INTERSECTIONSTATUS{TOBEDEALT,DEALT,NOINTERSECTION=-1};
///////////////////////////////////////////////////////////
//define error message class

class CErrorMsg
{
public:
	//Constructor
	CErrorMsg()	{ m_pErrorMsg=NULL;	}
	//Implementation
	void ShowErrorMsg(void);
	bool WaitForInstruction(void);
	void SetErrorMsg(char* pErrorMsg);
private:
	char* m_pErrorMsg;
};
///////////////////////////////////////////////////////////
//define 2D point class

class C2DPoint
{
public:
	// Constructor 
	C2DPoint()
	{
		m_dX=m_dY=0.;
		m_bStartPoint=FALSE;
		m_bEndPoint=FALSE;
	}
	C2DPoint(double ,double );
	C2DPoint(const C2DPoint& );
	// Implementation
	int Compare(const C2DPoint& );
	bool WriteIntoOutputFile(ostream& , OUTPUTFILETYPE); 
	// operator
	BOOL operator == (const C2DPoint& );
	const C2DPoint& operator=(const C2DPoint& );
	// Attributes
	double m_dX;
	double m_dY;
	BOOL m_bStartPoint;
	BOOL m_bEndPoint;
};
////////////////////////////////////////////////////////////
//define 2D line structure

struct C2DLine
{
	// Constructor 
	C2DLine() {	m_bDealt=FALSE;	}
	// Implementation
	bool WriteIntoOutputFile(ostream& , OUTPUTFILETYPE); 
	const C2DLine& operator=(const C2DLine& srcLine)
	{
		m_startPoint = srcLine.m_startPoint;
		m_endPoint = srcLine.m_endPoint;
		m_bDealt = srcLine.m_bDealt;
		return *this;
	}

	// Attributes
	C2DPoint m_startPoint;
	C2DPoint m_endPoint;
	BOOL m_bDealt; //若线段已被处理,则m_bDealt=TRUE;否则,m_bDealt=FALSE。
};
////////////////////////////////////////////////////////////
//define 2D point array and line array

typedef CArray<C2DPoint, C2DPoint&> planePointArray;
typedef CArray<C2DLine, C2DLine&> planeLineArray;
/////////////////////////////////////////////////////////////
//define 2D ring class

class C2DRing : public CArray<C2DPoint, C2DPoint&>
{
public:
	// Constructor 
	C2DRing(void)
	{
		SetSize(0);
		m_xMin=m_xMax=0;
		m_yMin=m_yMax=0;
		m_GroupNum=-1;
		m_bDealt=FALSE;
		m_bOuterLoop=FALSE;
		m_bOutermostLoop=FALSE;
	}
	C2DRing(const C2DRing&);
	// Implementation
	void Find_Min_Max_Value(void); //搜索平面环的边界尺寸
	bool WriteIntoOutputFile(ostream& , OUTPUTFILETYPE); 
	// operator
	const C2DRing& operator= (const C2DRing& );
	// Attributes
	INT m_GroupNum; //环的分组号
	BOOL m_bDealt;
	BOOL m_bOuterLoop; //内外环标记
	BOOL m_bOutermostLoop; //最外层环
	double m_xMin,m_xMax,m_yMin,m_yMax; 
};
////////////////////////////////////////////////////////////////
//define scan path structure

typedef struct tagScanPath
{
	// Constructor 
	tagScanPath(void)
	{
		polygons.SetSize(0);
		polylines.SetSize(0);
	}
	// Implementation
	bool WriteIntoOutputFile(ostream& , OUTPUTFILETYPE); 
	// Attributes
	CArray<C2DRing, C2DRing&> polygons; //封闭多边形
	planeLineArray polylines;			//不封闭的多折线
} SCANPATH;
/////////////////////////////////////////////////////////////
//define scan line structure

struct scanLine
{
	// Constructor 
	scanLine(void)
	{
		m_uCount=0;
		m_lineSegArray.SetSize(0);
	}
	// Implementation

	const scanLine& operator= (const scanLine& srcScanLine)	
	{
		m_uCount=srcScanLine.m_uCount;
		m_lineSegArray.SetSize(0);
		m_lineSegArray.Copy(srcScanLine.m_lineSegArray);
		return *this;
	}
	// Attributes
	UINT m_uCount;						//记录扫描线上直线段数
	planeLineArray m_lineSegArray;		//存储直线段
};
////////////////////////////////////////////////////////////
//define scan line array

typedef CArray<scanLine, scanLine&> scanLineArray;
/////////////////////////////////////////////////////////////
//define 2D contour class

class C2DContour : public CArray<C2DRing, C2DRing&>
{
public:
	// Constructor 
	C2DContour(void) 
	{
		SetSize(0);
		m_xMin=m_xMax=0;
		m_yMin=m_yMax=0;
		m_ScanWidth=0.2;        
	}
	C2DContour(const C2DContour& ); 
	// Implementation
    void JudgeOuterLoops(void); //判断内外环
	void Find_Min_Max_Value(void); //搜索平面轮廓的边界尺寸
	void ScanPathPerLayer(SCANPATH& path, double angle); //设计单层激光扫描路径
	// operator
	const C2DContour& operator=(const C2DContour& );
	// Attributes
	double	m_ScanWidth;        //扫描间距
	double m_xMin,m_xMax,m_yMin,m_yMax; 
	// Implementation
protected:
	void GroupingFunc(void); //对轮廓中的环进行分组
	void GetIntersections(const C2DRing& ring, planePointArray& pointArray, const C2DPoint& scanLinePos); //扫描线与多边形求交
	void Origin_Circling_Rotation(planePointArray& pointArray, double angle); //坐标系XOY绕原点旋转且逆时针方向为正
	bool DoesFirstRingContainSecondRing(const C2DRing& firstRing, const C2DRing& secondRing);//判断两环间是否存在包容关系
};
////////////////////////////////////////////////////////////////////////
//define STL point class

class CSTLPoint
{
public:
	// Constructor 
	CSTLPoint(void)	{ m_dX=m_dY=m_dZ=0.; }
	CSTLPoint(double ,double ,double);
	CSTLPoint(const CSTLPoint& );
	// Implementation
	void ReadSTLFile(istream& , STLFILETYPE);
	void WriteArchive(CArchive& archive);
	int Compare(const CSTLPoint& );
	// operator
	const CSTLPoint& operator=(const CSTLPoint& );
	// Attributes
	double m_dX;
	double m_dY;
	double m_dZ;
};
////////////////////////////////////////////////////////////////////////
//define STL edge class

class CSTLEdge
{
public:	
	//constructor
	CSTLEdge(void) 
	{
		m_points[0]=m_points[1]=-1;
		m_faces[0]=m_faces[1]=-1;
	}
	CSTLEdge(const CSTLEdge& );
	// Implementation 
	int Compare(const CSTLEdge& );
	//operator
	const CSTLEdge& operator=(const CSTLEdge& );
	// Attributes
	int m_points[2]; //point index
	int m_faces[2];  //face index
};
/////////////////////////////////////////////////////////////////////////
//define STL face class

class CSTLFace
{
public:
	//constructor
	CSTLFace(void) 
	{
		m_points[0]=m_points[1]=m_points[2]=-1;
		m_edges[0]=m_edges[1]=m_edges[2]=-1;
	}
	CSTLFace(const CSTLFace& );
	//operator
	const CSTLFace& operator=(const CSTLFace& );
	// Attributes
	CSTLPoint m_vector;  //normal vector
	int m_points[3];     //point index	
	int m_edges[3];      //edge index
};
////////////////////////////////////////////////////////////////////////
//define object arrays

typedef CArray<CSTLPoint, CSTLPoint&> STLPointArray;
typedef CArray<CSTLEdge, CSTLEdge&> STLEdgeArray;
typedef CArray<CSTLFace, CSTLFace&> STLFaceArray;
////////////////////////////////////////////////////////////////////////
//define STL intersection structure

struct STLIntersection
{
	C2DPoint m_intersection;
	INTERSECTIONSTATUS m_status;
};
////////////////////////////////////////////////////////////////////////   
//define STL solid class

class CSTLSolid
{
public: 
	//constructor and destructor
	CSTLSolid()
	{
		m_bInitialized=FALSE;
		m_pIntersections=NULL;
	}
	~CSTLSolid(void)	{delete[] m_pIntersections;}
	// Implementation
	void WriteArchive(CArchive& archive);
	int Initialize(const char* fileName);	//Succeed if return zero, else return -1.
	int CutSlice(double ,C2DContour&);
	void Find_Min_Max_Value(CSTLPoint&, int );
	// Attributes
	STLPointArray m_points;
	STLEdgeArray m_edges;
	STLFaceArray m_faces;
	BOOL m_bInitialized;	
	STLIntersection* m_pIntersections;         //记录切片所得到的交点
	double m_xMin ,m_xMax ,m_yMin ,m_yMax ,m_zMin ,m_zMax;
protected:
	// Implementation 
	void InitIntersections(void);				//初始化交点矩阵
};

////////////////////////////////////////////////////////////////////////   
//define CFIFO class

class CFIFO
{
public:
	//Constructor
	CFIFO();
	//Implementation
	void InitFIFO(void);				//清空FIFO
	bool ReadFIFO(DWORD& data);			//从FIFO读出一个数据
	bool WriteFIFO(DWORD data);			//向FIFO写入一个数据
	long SizeOfDataInFIFO(void);		//返回FIFO中现有的数据个数
	long SizeOfSpareSpace(void);
protected:
	long m_headPointer;					//头指针
	long m_tailPointer;					//尾指针
	DWORD m_dwDataBuffer[BUFFERSIZE];	//缓冲区

	bool IsFIFOFull(void);				//判断FIFO是否已满
	bool IsFIFOEmpty(void);				//判断FIFO是否为空
};
///////////////////////////////////////////////////////////
//define CPathData class

struct pathParam
{
	double m_ScanWidth;           //扫描间距
	double m_LayerThickness;      //单层厚度
	double m_RotateAngle;         //扫描线层间夹角
	DWORD m_ScanSpeed;			  //扫描速度
	DWORD m_ZeroSpeed;			  //回零速度
	DWORD m_LaserPower;		      //激光功率
	DWORD m_PowderUp;			  //粉桶位移量
	DWORD m_PlatformDown;		  //工作缸位移量
};


class CIPInfo
{
public:
	//Constructor
	CIPInfo()
	{
		m_flag=0;
		m_1thIP=0;
		m_2thIP=0;
		m_3thIP=0;
	}
	//Implementation
	int GetFlagBit(int index);
	void SetFlagBit(int index);
	void ResetFlagBit(int index);
	// Attributes
	INT m_1thIP;
	INT m_2thIP;
	INT m_3thIP;
protected:
	WORD m_flag;	//若bit0=1、bit1=1或bit8=1,则执行辅助指令;
};					//若一层数据全部写入FIFO,则bit2=1;
					//若bit3=1,则计算下一层数据;
					//若bit4=1,则停止加工过程;
					//若已得到所有加工数据,则bit5=1;
					//若bit6=1,则执行铺粉系列动作;
					//若叠层制造,则bit7=1;
					//若制造基底,则bit7、bit9置位。

class CPathData
{
public:
	//Constructor and destructor
	CPathData()
	{
		m_pFIFO = NULL;
	}

	~CPathData() { delete m_pFIFO; }
	//Implementation
	void SetAxisInitPos(void);
	void ClearInstruction( void );	
	void SendDataToController(void);
	void SetPathParam(pathParam& param);
	bool Initialize(const char* inFileName);
	bool CreatePathData(int curLayerNum);
	void WritePathDataIntoFIFO(double centerPosX, double centerPosY);
	// Attributes
	CFIFO* m_pFIFO;
	CIPInfo m_IPInfo;
	CSTLSolid m_Solid; 
	C2DContour m_Contour;
	SCANPATH m_scanPath;
	static DWORD m_axisZPos;
	static DWORD m_axisVPos;
protected:
	pathParam m_pathParam;
	void WriteOneDataIntoFIFO(DWORD data);

	static bool m_bLaserOn;

	void GetExtendedLine(const C2DPoint & p0, 
		const C2DPoint & p1, C2DPoint & p,
		bool dir=true);
};

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -