📄 simulatedoc.cpp
字号:
// glVertex3f(((LineNode->m_Data).m_SecondVertex).m_fX,
// ((LineNode->m_Data).m_SecondVertex).m_fY,
// 0);
if(((LineNode->m_Data).m_SecondVertex).m_fX < fXMinOfBoundaryLine)
fXMinOfBoundaryLine = ((LineNode->m_Data).m_SecondVertex).m_fX;
if(((LineNode->m_Data).m_SecondVertex).m_fY < fYMinOfBoundaryLine)
fYMinOfBoundaryLine = ((LineNode->m_Data).m_SecondVertex).m_fY;
if(((LineNode->m_Data).m_SecondVertex).m_fX > fXMaxOfBoundaryLine)
fXMaxOfBoundaryLine = ((LineNode->m_Data).m_SecondVertex).m_fX;
if(((LineNode->m_Data).m_SecondVertex).m_fY > fYMaxOfBoundaryLine)
fYMaxOfBoundaryLine = ((LineNode->m_Data).m_SecondVertex).m_fY;
LineNode = LineNode->m_pNext;
}
//Get rectangle which include the projected trimesh
TriMeshForIntersection.m_fXMin = fXMinOfBoundaryLine;
TriMeshForIntersection.m_fYMin = fYMinOfBoundaryLine;
TriMeshForIntersection.m_fXMax = fXMaxOfBoundaryLine;
TriMeshForIntersection.m_fYMax = fYMaxOfBoundaryLine;
//Display the boundary lines
glColor3f(0.0, 0.0, 1.0);
glVertex3f(fXMinOfBoundaryLine,
fYMinOfBoundaryLine,
0);
glVertex3f(fXMinOfBoundaryLine,
fYMaxOfBoundaryLine,
0);
glVertex3f(fXMinOfBoundaryLine,
fYMaxOfBoundaryLine,
0);
glVertex3f(fXMaxOfBoundaryLine,
fYMaxOfBoundaryLine,
0);
glVertex3f(fXMaxOfBoundaryLine,
fYMaxOfBoundaryLine,
0);
glVertex3f(fXMaxOfBoundaryLine,
fYMinOfBoundaryLine,
0);
glVertex3f(fXMaxOfBoundaryLine,
fYMinOfBoundaryLine,
0);
glVertex3f(fXMinOfBoundaryLine,
fYMinOfBoundaryLine,
0);
}
CLine::CLine(const CLine & Line)
{
m_nFirstPoint = Line.m_nFirstPoint;
m_nSecondPoint = Line.m_nSecondPoint;
m_FirstVertex = Line.m_FirstVertex;
m_SecondVertex = Line.m_SecondVertex;
}
CLine::CLine()
{
m_nSecondPoint = m_nFirstPoint = 0;
}
BOOL CLine::operator == (const CLine & Line)
{
if((m_nFirstPoint == Line.m_nFirstPoint && m_nSecondPoint == Line.m_nSecondPoint) ||
(m_nFirstPoint == Line.m_nSecondPoint && m_nSecondPoint == Line.m_nFirstPoint))
return TRUE;
else
return FALSE;
}
BOOL CLine::operator !=(const CLine & Line)
{
if((m_nFirstPoint == Line.m_nFirstPoint && m_nSecondPoint == Line.m_nSecondPoint) ||
(m_nFirstPoint == Line.m_nSecondPoint && m_nSecondPoint == Line.m_nFirstPoint))
return FALSE;
else
return TRUE;
}
CVertex & CVertex::operator = (const CVertex & Vertex)
{
m_fX = Vertex.m_fX;
m_fY = Vertex.m_fY;
m_fZ = Vertex.m_fZ;
return(*this);
}
CScanIntersectionPoint::CScanIntersectionPoint(const CScanIntersectionPoint& Point)
{
m_fX = Point.m_fX;
m_fY = Point.m_fY;
m_fZ = Point.m_fZ;
m_nFlag = Point.m_nFlag;
m_sName = Point.m_sName;
}
BOOL CScanIntersectionPoint::operator > (const CScanIntersectionPoint& Point)
{
if(m_fX > Point.m_fX)
return TRUE;
else
return FALSE;
}
BOOL CScanIntersectionPoint::operator < (const CScanIntersectionPoint& Point)
{
if(m_fX < Point.m_fX)
return TRUE;
else
return FALSE;
}
CTriMeshForIntersection::CTriMeshForIntersection()
{
m_pTriangleVisibleList = new List<CTriangleVisible>;
m_pBoundaryLineList = new List<CLine>;
m_fXMin = 1000000.;
m_fYMin = 1000000.;
m_fXMax = -1000000.;
m_fYMax = -1000000.;
}
CTriMeshForIntersection::~CTriMeshForIntersection()
{
if(m_pTriangleVisibleList != NULL)
delete m_pTriangleVisibleList;
if(m_pBoundaryLineList != NULL)
delete m_pBoundaryLineList;
}
BOOL CTriMeshForIntersection::bIntersectPointByXY(float fX, float fY, float & fZ)
{
Node<CTriangleVisible> * pTriangleVisibleNode;
float fZMax = -1000000.;
BOOL bReturn = FALSE;
pTriangleVisibleNode = m_pTriangleVisibleList->pGetHead();
pTriangleVisibleNode = pTriangleVisibleNode->m_pNext;
while(pTriangleVisibleNode != NULL)
{
if((pTriangleVisibleNode->m_Data).bIntersectPointByXY(fX, fY, fZ))
{
//if intersec with some triangle
//update the fZMax
bReturn = TRUE;
if(fZ > fZMax)
fZMax = fZ;
}
pTriangleVisibleNode = pTriangleVisibleNode->m_pNext;
}
//let fZ take the most Z value
fZ = fZMax;
return bReturn;
}
void CTriangle::GetWeightCenter(CVertex & Vertex)
{
Vertex.m_fX = (m_VertexA.m_fX +
m_VertexB.m_fX +
m_VertexC.m_fX)/3.0;
Vertex.m_fY = (m_VertexA.m_fY +
m_VertexB.m_fY +
m_VertexC.m_fY)/3.0;
Vertex.m_fZ = (m_VertexA.m_fZ +
m_VertexB.m_fZ +
m_VertexC.m_fZ)/3.0;
}
void CTriangle::GetArea(float & fArea)
{
float fLengthAB, fLengthBC, fLengthCA;
float fS;
fLengthAB = sqrt((m_VertexB.m_fX - m_VertexA.m_fX) * (m_VertexB.m_fX - m_VertexA.m_fX) +
(m_VertexB.m_fY - m_VertexA.m_fY) * (m_VertexB.m_fY - m_VertexA.m_fY) +
(m_VertexB.m_fZ - m_VertexA.m_fZ) * (m_VertexB.m_fZ - m_VertexA.m_fZ));
fLengthBC = sqrt((m_VertexC.m_fX - m_VertexB.m_fX) * (m_VertexC.m_fX - m_VertexB.m_fX) +
(m_VertexC.m_fY - m_VertexB.m_fY) * (m_VertexC.m_fY - m_VertexB.m_fY) +
(m_VertexC.m_fZ - m_VertexB.m_fZ) * (m_VertexC.m_fZ - m_VertexB.m_fZ));
fLengthCA = sqrt((m_VertexA.m_fX - m_VertexC.m_fX) * (m_VertexA.m_fX - m_VertexC.m_fX) +
(m_VertexA.m_fY - m_VertexC.m_fY) * (m_VertexA.m_fY - m_VertexC.m_fY) +
(m_VertexA.m_fZ - m_VertexC.m_fZ) * (m_VertexA.m_fZ - m_VertexC.m_fZ));
fS = (fLengthAB + fLengthBC + fLengthCA)/2.0;
fArea = sqrt(fS * (fS - fLengthAB) * (fS - fLengthBC) * (fS - fLengthCA));
}
BOOL CEllipseSphere::bCheckVerexIn(CVertex & Vertex)
{
float fTemp;
fTemp = (Vertex.m_fX - m_VertexCenter.m_fX) * (Vertex.m_fX - m_VertexCenter.m_fX)/(m_fA * m_fA) +
(Vertex.m_fY - m_VertexCenter.m_fY) * (Vertex.m_fY - m_VertexCenter.m_fY)/(m_fB * m_fB) +
(Vertex.m_fZ - m_VertexCenter.m_fZ) * (Vertex.m_fZ - m_VertexCenter.m_fZ)/(m_fC * m_fC);
if(fTemp < 1.00001)
return TRUE;
else
return FALSE;
}
BOOL CTriangleVisible::bIntersectPointByXY(float fX, float fY, float & fZ)
{
CVector VectorA0, VectorB0, VectorC0;
CVector VectorBA, VectorCA, VectorNormal;
CVector VectorTemp, VectorA;
float fA0_B0, fB0_C0, fC0_A0;
int nA0_B0, nB0_C0, nC0_A0;
VectorA0.m_fX = m_VertexA.m_fX - fX;
VectorA0.m_fY = m_VertexA.m_fY - fY;
VectorA0.m_fZ = 0.0;
VectorB0.m_fX = m_VertexB.m_fX - fX;
VectorB0.m_fY = m_VertexB.m_fY - fY;
VectorB0.m_fZ = 0.0;
VectorC0.m_fX = m_VertexC.m_fX - fX;
VectorC0.m_fY = m_VertexC.m_fY - fY;
VectorC0.m_fZ = 0.0;
VectorBA.m_fX = m_VertexB.m_fX - m_VertexA.m_fX;
VectorBA.m_fY = m_VertexB.m_fY - m_VertexA.m_fY;
VectorBA.m_fZ = m_VertexB.m_fZ - m_VertexA.m_fZ;
VectorCA.m_fX = m_VertexC.m_fX - m_VertexA.m_fX;
VectorCA.m_fY = m_VertexC.m_fY - m_VertexA.m_fY;
VectorCA.m_fZ = m_VertexC.m_fZ - m_VertexA.m_fZ;
VectorTemp = VectorA0;
VectorTemp.CrossProduct(VectorB0);
fA0_B0 = VectorTemp.m_fZ;
VectorTemp = VectorB0;
VectorTemp.CrossProduct(VectorC0);
fB0_C0 = VectorTemp.m_fZ;
VectorTemp = VectorC0;
VectorTemp.CrossProduct(VectorA0);
fC0_A0 = VectorTemp.m_fZ;
//Check if fA0_B0 fB0_C0 fC0_A0 have the same sign
if(fabs(fA0_B0) > 0.000001 &&
fabs(fB0_C0) > 0.000001 &&
fabs(fC0_A0) > 0.000001)
{
nA0_B0 = (int)(fA0_B0/fabs(fA0_B0));
nB0_C0 = (int)(fB0_C0/fabs(fB0_C0));
nC0_A0 = (int)(fC0_A0/fabs(fC0_A0));
if(nA0_B0 != nB0_C0 ||
nB0_C0 != nC0_A0 ||
nC0_A0 != nA0_B0)
//There must not exist an intersection point
return FALSE;
}
//Find the intersection point
VectorNormal = VectorBA;
VectorNormal.CrossProduct(VectorCA);
VectorA.m_fX = m_VertexA.m_fX;
VectorA.m_fY = m_VertexA.m_fY;
VectorA.m_fZ = m_VertexA.m_fZ;
// assert(fabs(VectorNormal.m_fZ) > 0.000001);
if(fabs(VectorNormal.m_fZ) < 0.000001)
{
return FALSE;
}
fZ = (VectorNormal.fDotProduct(VectorA) -
fX * VectorNormal.m_fX -
fY * VectorNormal.m_fY)/VectorNormal.m_fZ;
return TRUE;
}
BOOL CMiniArea::operator > (const CMiniArea& MiniArea)
{
if(m_fZ > MiniArea.m_fZ)
return TRUE;
else
return FALSE;
}
BOOL CMiniArea::operator < (const CMiniArea& MiniArea)
{
if(m_fZ < MiniArea.m_fZ)
return TRUE;
else
return FALSE;
}
CSimulateArea::CSimulateArea()
{
m_pMeshNameList = new List<CString>;
}
CSimulateArea::CSimulateArea(const CSimulateArea& SimulateArea)
{
Node<CString> *pStringNode;
CString StringTemp;
m_fArea = SimulateArea.m_fArea;
m_pMeshNameList = new List<CString>;
pStringNode = (SimulateArea.m_pMeshNameList)->pGetHead();
pStringNode = pStringNode->m_pNext;
while(pStringNode != NULL)
{
StringTemp = pStringNode->m_Data;
m_pMeshNameList->InsertNewNodeAtTail(StringTemp);
pStringNode = pStringNode->m_pNext;
}
}
CSimulateArea::~CSimulateArea()
{
if(m_pMeshNameList != NULL)
delete m_pMeshNameList;
}
BOOL CSimulateArea::bCheckMeshNameListUniform(List<CMiniArea>* pMiniAreaList)
{
Node<CMiniArea>* pNodeMiniArea;
Node<CString>* pNodeString;
float fArea = 0.;
pNodeMiniArea = pMiniAreaList->pGetHead();
pNodeMiniArea = pNodeMiniArea->m_pNext;
pNodeString = m_pMeshNameList->pGetHead();
pNodeString = pNodeString->m_pNext;
if(pNodeMiniArea != NULL)
{
fArea = (pNodeMiniArea->m_Data).m_fArea;
}
while(pNodeString != NULL && pNodeMiniArea != NULL)
{
if((pNodeMiniArea->m_Data).m_sName !=
pNodeString->m_Data)
return FALSE;
pNodeString = pNodeString->m_pNext;
pNodeMiniArea = pNodeMiniArea->m_pNext;
}
if(pNodeString == NULL && pNodeMiniArea == NULL)
//if the two list has the same length
//then they must the same mesh name sequence;
{
m_fArea = m_fArea + fArea;
return TRUE;
}
else
return FALSE;
}
void CSimulateArea::CopyFromMiniAreaList(List<CMiniArea>* pMiniAreaList)
{
float fArea = 0.;
Node<CMiniArea>* pMiniAreaNode;
CString StringTemp;
pMiniAreaNode = pMiniAreaList->pGetHead();
pMiniAreaNode = pMiniAreaNode->m_pNext;
if(pMiniAreaNode != NULL)
fArea = (pMiniAreaNode->m_Data).m_fArea;
m_pMeshNameList->ClearAllNodes();
while(pMiniAreaNode != NULL)
{
StringTemp = (pMiniAreaNode->m_Data).m_sName;
m_pMeshNameList->InsertNewNodeAtTail(StringTemp);
pMiniAreaNode = pMiniAreaNode->m_pNext;
}
m_fArea = fArea;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -