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

📄 simulatedoc.h

📁 这是关于飞机生存力计算软件
💻 H
字号:
// SimulateDoc.h : interface of the CSimulateDoc class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_SIMULATEDOC_H__86F6D3CC_A48E_11D2_ABDB_444553540000__INCLUDED_)
#define AFX_SIMULATEDOC_H__86F6D3CC_A48E_11D2_ABDB_444553540000__INCLUDED_

#include <assert.h>

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

enum {UPTODOWN, DOWNTOUP};

class CScanIntersectionPoint
//The scan lines are parallel to X axis
//i.e. y = const
{
public:
	CScanIntersectionPoint()
	{
	}

	CScanIntersectionPoint(const CScanIntersectionPoint& Point);
	BOOL operator > (const CScanIntersectionPoint& Point);
	BOOL operator < (const CScanIntersectionPoint& Point);

public:
	float m_fX, m_fY, m_fZ;
	int m_nFlag;
	CString m_sName;
};

template<class T>
class Node
{
public:
	//next is the address of the following node
	Node<T> *m_pNext;

public:
	//the data is public 
	T m_Data;

	//constructor
	Node(const T& Item, Node<T> * pNext=NULL);
	Node();	
	~Node();	
};

//Node implementation
template<class T>
Node<T>::Node(const T& Item, Node<T> * pNext):
			m_Data(Item),m_pNext(pNext)
{
}

template<class T>
Node<T>::Node():m_pNext(NULL)
{
}

template<class T>
Node<T>::~Node()
{
}

template<class T>
class List
{
private:
	Node<T> *m_pHead;
	int m_nCount;

public:
	//constructor
	List();
	~List();

	//list probe methods
	int nItemCount()const
	{
		return m_nCount;
	}

	Node<T> *pGetHead()const
	{
		return m_pHead;
	}

	Node<T> *pFindItem(const T& Item);

	//list modification methods
	void DeleteAfter(Node<T> *p);
	void InsertAfter(Node<T> *p, const T& Item);
	void InsertNewNodeAtTail(const T& Item);
	void InsertNewNodeAtHead(const T& Item);
	void SortLowToHigh(void);
	void SortHighToLow(void);
	void ClearAllNodes(void);
};

//List implementation
template<class T>
List<T>::List()
{
	m_pHead = new Node<T>;
	m_nCount = 0;
}

template<class T>
List<T>::~List()
{
	Node<T>* pCurrentPointer;
	Node<T>* pDelPointer;
	pCurrentPointer = m_pHead->m_pNext;

	while(pCurrentPointer != NULL)
	{
		pDelPointer = pCurrentPointer;
		pCurrentPointer = pCurrentPointer->m_pNext;
		delete pDelPointer;
	}

	delete m_pHead;
	m_pHead = 0;
	m_nCount = 0;
}

template<class T>
void List<T>::ClearAllNodes(void)
{
	Node<T>* pCurrentPointer;
	Node<T>* pDelPointer;
	pCurrentPointer = m_pHead->m_pNext;

	while(pCurrentPointer != NULL)
	{
		pDelPointer = pCurrentPointer;
		pCurrentPointer = pCurrentPointer->m_pNext;
		delete pDelPointer;
	}

	m_nCount = 0;
	m_pHead->m_pNext = NULL;

}

template<class T>
Node<T> * List<T>::pFindItem(const T& Item)
//check if there is an Item in the list
//if true return the Item's previous pointer
//else return NULL
{
	Node<T>* pCurrentPointer;
	Node<T>* pPreviousPointer;
	pCurrentPointer = m_pHead->m_pNext;
	pPreviousPointer = m_pHead;
	
	while(pCurrentPointer != NULL && pCurrentPointer->m_Data != Item)
	{
		pPreviousPointer = pCurrentPointer;
		pCurrentPointer = pCurrentPointer->m_pNext;
	}
	
	if(pCurrentPointer != NULL)
		return pPreviousPointer;
	else
		return NULL;
}

template<class T>
void List<T>::DeleteAfter(Node<T> *p)
{
	Node<T>* pTemp;

	if(p->m_pNext != NULL)
	{
		pTemp = p->m_pNext;
		p->m_pNext = pTemp->m_pNext;
		delete pTemp;
		m_nCount--;
	}
}

template<class T>
void List<T>::InsertAfter(Node<T> *p, const T& Item)
{
	Node<T>* pNewNode = new Node<T>(Item);
	assert(pNewNode != NULL);

	pNewNode->m_pNext = p->m_pNext;
	p->m_pNext = pNewNode;
	m_nCount++;
}

template<class T>
void List<T>::InsertNewNodeAtTail(const T& Item)
{
	Node<T>* pCurrentPointer;
	Node<T>* pPreviousPointer;

	pCurrentPointer = m_pHead->m_pNext;
	pPreviousPointer = m_pHead;

	while(pCurrentPointer != NULL)
	{
		pPreviousPointer = pCurrentPointer;
		pCurrentPointer = pCurrentPointer->m_pNext;
	}

	InsertAfter(pPreviousPointer, Item);
}

template<class T>
void List<T>::InsertNewNodeAtHead(const T& Item)
{
	InsertAfter(m_pHead, Item);

}

template<class T>
void List<T>::SortLowToHigh(void)
{
	Node<T>* t;
	Node<T>* p;
	Node<T>* r;
	Node<T>* q;
	Node<T>* h;

	h = m_pHead->m_pNext;
	if(h != NULL)
	{
		t = h;
		while(t->m_pNext != NULL)
		{
			p = t->m_pNext;
			if((p->m_Data) < (h->m_Data))
			{
				t->m_pNext = p->m_pNext;
				p->m_pNext = h;
				h = p;
			}
 			else
			{
				q = h;
				r = q->m_pNext;
				while((p->m_Data) > (r->m_Data))
				{
					q = r;
					r = q->m_pNext;
				}
				if(p == r)
					t = p;
				else
				{
					t->m_pNext = p->m_pNext;
					p->m_pNext = r;
					q->m_pNext = p;
				}
			}
		}
	}
	m_pHead->m_pNext = h;

}

template<class T>
void List<T>::SortHighToLow(void)
{
	Node<T>* t;
	Node<T>* p;
	Node<T>* r;
	Node<T>* q;
	Node<T>* h;

	h = m_pHead->m_pNext;
	if(h != NULL)
	{
		t = h;
		while(t->m_pNext != NULL)
		{
			p = t->m_pNext;
			if((p->m_Data) > (h->m_Data))
			{
				t->m_pNext = p->m_pNext;
				p->m_pNext = h;
				h = p;
			}
 			else
			{
				q = h;
				r = q->m_pNext;
				while((p->m_Data) < (r->m_Data))
				{
					q = r;
					r = q->m_pNext;
				}
				if(p == r)
					t = p;
				else
				{
					t->m_pNext = p->m_pNext;
					p->m_pNext = r;
					q->m_pNext = p;
				}
			}
		}
	}
	m_pHead->m_pNext = h;

}

class CVertex
{
public:
	CVertex & operator = (const CVertex & Vertex);

public:
	float m_fX, m_fY, m_fZ;

};

class CLine:public CObject
{
public:
	BOOL operator != (const CLine & Line);
	BOOL operator == (const CLine & Line);
	 CLine();
	 CLine(const CLine& Line);

public:
	CVertex m_FirstVertex;
	CVertex m_SecondVertex;
	int m_nFirstPoint, m_nSecondPoint;

};

class CMatrix:public CObject
{
public:
	float & operator()(int nRow, int nColumn);
	void Multiply(CMatrix &Matrix);
	int m_nRow;
	int m_nColumn;
	float *m_pMatrixData;

	CMatrix(int nRow = 0, int nColumn = 0)
	{
		if(nRow < 0) 
			m_nRow = 0;
		else
			m_nRow = nRow;

		if(nColumn < 0) 
			m_nColumn = 0;
		else
			m_nColumn = nColumn;
		
		m_pMatrixData = new float [m_nRow * m_nColumn];
	}

	~CMatrix()
	{
		if (m_pMatrixData != NULL)
			delete [] m_pMatrixData;
	}

};

class CVector
{
public:
	CVector()
	{
		m_fX = 0.0;
		m_fY = 0.0;
		m_fZ = 0.0;
	}

	CVector & operator = (const CVector & Vector);

public:
	void Normalize();
	float fLength();
	void CrossProduct(CVector& Vector);
	float fDotProduct(CVector& Vector);
	float m_fX, m_fY, m_fZ;

};

class CTriangle
{
public:
	void GetWeightCenter(CVertex & Vertex);
	void GetArea(float & fArea);

public:
	int m_nA, m_nB, m_nC;

	CVertex m_VertexA;
	CVertex m_VertexB;
	CVertex m_VertexC;


};

class CEllipseSphere
{
public:
	BOOL bCheckVerexIn(CVertex & Vertex);

public:
	//the equation is:
	//(x - m_VertexCenter.m_fX)*(x - m_VertexCenter.m_fX)/(m_fA*m_fA) + 
	//(y - m_VertexCenter.m_fY)*(y - m_VertexCenter.m_fY)/(m_fB*m_fB) + 
	//(z - m_VertexCenter.m_fZ)*(z - m_VertexCenter.m_fZ)/(m_fC*m_fC) = 1 
	CVertex m_VertexCenter;
	float m_fA, m_fB, m_fC;
};

class CTriangleVisible
{
public:
	CTriangleVisible()
	{
	}

	CTriangleVisible(const CTriangleVisible & TriangleVisible)
	{
		m_VertexA = TriangleVisible.m_VertexA;
		m_VertexB = TriangleVisible.m_VertexB;
		m_VertexC = TriangleVisible.m_VertexC;
	}
	
	//Canculate the Z value of some line defined by x=const and 
	//y=const. if there is no intersect point, return FALSE
	BOOL bIntersectPointByXY(float fX, float fY, float & fZ);

public:
	CVertex m_VertexA;
	CVertex m_VertexB;
	CVertex m_VertexC;

};

class CTriMeshForIntersection:public CObject
{
public:
	CTriMeshForIntersection();
	~CTriMeshForIntersection();
	BOOL bIntersectPointByXY(float fX, float fY, float & fZ);

public:
	//Point to the visible triangle list
	List<CTriangleVisible> * m_pTriangleVisibleList;
	//Point to the boundary line list 
	List<CLine>* m_pBoundaryLineList;
	//The rectangle include the trimesh after projection
	float m_fXMin, m_fXMax, m_fYMin, m_fYMax;
	//The name of the trimesh
	CString m_sName;
};

class CTriMesh:public CObject
{
public:
	int m_nVertices;
	int m_nFaces;
	CString m_sName;
	CVertex* m_pVertexList;
	CTriangle* m_pTriangleList;

public:
	float m_fArea;
	CVertex m_WeightCenter;
	void PreCalculateForIntersection(CTriMeshForIntersection& TriMeshForIntersection,
									   CMatrix& Matrix);
	int nIsPointInMesh(CVertex & Vertex);
	float m_fZMax;
	float m_fYMax;
	float m_fXMax;
	float m_fZMin;
	float m_fYMin;
	float m_fXMin;
	CTriMesh(int nVertices, int nFaces)
	{
		m_pVertexList = new CVertex [nVertices];
		m_pTriangleList = new CTriangle [nFaces];

	}

	~CTriMesh()
	{
		if (m_pVertexList != NULL)
			delete [] m_pVertexList;
		
		if (m_pTriangleList != NULL)
			delete [] m_pTriangleList;

	}

	void Show(BOOL bSmooth=FALSE);
	void CalculateBasicParameter(void);

};

class CMiniArea
{
public:
	CMiniArea()
	{
	}

	CMiniArea(const CMiniArea& MiniArea)
	{
		m_fArea = MiniArea.m_fArea;
		m_fZ = MiniArea.m_fZ;
		m_sName = MiniArea.m_sName;
	}
	
	BOOL operator > (const CMiniArea& MiniArea);
	BOOL operator < (const CMiniArea& MiniArea);

public:
	float m_fArea;
	float m_fZ;
	CString m_sName;
};

class CSimulateArea
{
public:
	CSimulateArea();
	CSimulateArea(const CSimulateArea& SimulateArea);
	~CSimulateArea();
	BOOL bCheckMeshNameListUniform(List<CMiniArea>* pMiniAreaList);
	void CopyFromMiniAreaList(List<CMiniArea>* pMiniAreaList);

public:
	float m_fArea;
	List<CString>* m_pMeshNameList;
};

class CSimulateDoc : public CDocument
{
protected: // create from serialization only
	CSimulateDoc();
	DECLARE_DYNCREATE(CSimulateDoc)

protected: 
	CTypedPtrArray<CObArray, CTriMesh*>m_TriMeshArray;

// Attributes
public:

// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CSimulateDoc)
	public:
	virtual BOOL OnNewDocument();
	virtual void Serialize(CArchive& ar);
	//}}AFX_VIRTUAL

// Implementation
public:
	TCHAR m_szStartDirectory[260];
	CView * GetSimulateView();
	float m_fGlobalZMax;
	float m_fGlobalYMax;
	float m_fGlobalXMax;
	float m_fGlobalZMin;
	float m_fGlobalYMin;
	float m_fGlobalXMin;
	CView * GetToolsPanel();
	int GetNumTriMeshes();
	CTriMesh * GetTriMesh(int Index);
	BOOL AddTriMesh(CTriMesh * TriMesh);
	virtual ~CSimulateDoc();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	//{{AFX_MSG(CSimulateDoc)
	afx_msg void OnFileImport();
	afx_msg void OnFileReset();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SIMULATEDOC_H__86F6D3CC_A48E_11D2_ABDB_444553540000__INCLUDED_)

⌨️ 快捷键说明

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