190 lines
4.0 KiB
C++
190 lines
4.0 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TPGeLandform.cpp
|
|
// = Version : ver2.0
|
|
// = Author : xlc
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: ÀàµÄ¶¨Òå
|
|
// = Maintainers:
|
|
//
|
|
//-----------------------------------------------------------------------------+
|
|
#include "StdAfx.h"
|
|
#include "TPGeLandform.h"
|
|
#include "TPGeGridLine.h"
|
|
|
|
TPGeLandform::TPGeLandform()
|
|
{
|
|
|
|
}
|
|
|
|
TPGeLandform::~TPGeLandform()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
const TPGeCurve2D& TPGeLandform::Outline()const
|
|
{
|
|
return GetPData(0);
|
|
}
|
|
|
|
double TPGeLandform::GetDistX()const
|
|
{
|
|
return m_fDistX;
|
|
}
|
|
|
|
double TPGeLandform::GetDistY()const
|
|
{
|
|
return m_fDistY;
|
|
}
|
|
|
|
double TPGeLandform::GetElev()const
|
|
{
|
|
return Outline().GetElev();
|
|
}
|
|
|
|
bool TPGeLandform::IsValid()const
|
|
{
|
|
if (IsEmpty())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
for (long i = 0; i < GetLength();i++)
|
|
{
|
|
const TPGeCurve2D*pCurve = GetAt(i);
|
|
if (pCurve == NULL || !pCurve->IsValid())
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (!Outline().IsClosed() || Outline().IsSelfCross() || Outline().IsClockwise())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TPGeLandform::Append(TPGeCurve2D* pCurve)
|
|
{
|
|
if (!pCurve->IsValid())
|
|
return false;
|
|
|
|
if (IsEmpty())
|
|
{
|
|
if (!pCurve->IsClosed() || pCurve->IsSelfCross())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (pCurve->IsClockwise())
|
|
{
|
|
pCurve->Reverse();
|
|
}
|
|
}
|
|
|
|
AddTail(pCurve);
|
|
return true;
|
|
}
|
|
|
|
|
|
bool TPGeLandform::CreateGridData(double fDistX,double fDistY,TGObjectList&mlines,int fitType)
|
|
{
|
|
if (!IsValid())
|
|
return false;
|
|
|
|
m_allGridLineX.Clear();
|
|
m_allGridLineY.Clear();
|
|
m_allGridNode.Clear();
|
|
m_allGridCell.Clear();
|
|
m_fDistX = fDistX;
|
|
m_fDistY = fDistY;
|
|
|
|
TPGeExtend2D ext;
|
|
Outline().GetExtend2D(ext);
|
|
|
|
double extHeight = ext.GetHeight();
|
|
double extLength = ext.GetLength();
|
|
double fRowNum = extHeight / m_fDistY;
|
|
double fColNum = extLength / m_fDistX;
|
|
long nRowNum = (long)fRowNum;
|
|
long nColNum = (long)fColNum;
|
|
if (UP_ZERO(fRowNum - nRowNum))
|
|
{
|
|
nRowNum += 1;
|
|
}
|
|
|
|
if (UP_ZERO(fColNum - nColNum))
|
|
{
|
|
nColNum += 1;
|
|
}
|
|
|
|
m_allGridLineX.Realloc(nRowNum + 1);
|
|
for (long i = 0; i <= nRowNum; i++)
|
|
{
|
|
double y = ext.GetYExtend().GetMin() + i * m_fDistY;
|
|
TPGeGridLine &line = m_allGridLineX[i];
|
|
line.SetPoint(TGPoint(ext.GetXExtend().GetMin() - 2 * m_fDistX,y),TGPoint(ext.GetXExtend().GetMax() + 2 * m_fDistX,y));
|
|
line.m_allSeg.Realloc(nColNum);
|
|
line.CreateFrom(this,true,ext.GetXExtend().GetMin());
|
|
}
|
|
|
|
m_allGridLineY.Realloc(nColNum + 1);
|
|
for (i = 0; i <= nColNum; i++)
|
|
{
|
|
double x = ext.GetXExtend().GetMin() + i * m_fDistX;
|
|
TPGeGridLine &line = m_allGridLineY[i];
|
|
line.SetPoint(TGPoint(x,ext.GetYExtend().GetMin() - 2 * m_fDistY),TGPoint(x,ext.GetYExtend().GetMax() + 2 * m_fDistY));
|
|
line.m_allSeg.Realloc(nRowNum);
|
|
line.CreateFrom(this,false,ext.GetYExtend().GetMin());
|
|
}
|
|
|
|
m_allGridNode.Realloc(nRowNum + 1,nColNum + 1,false);
|
|
for (i = 0; i <= nRowNum; i++)
|
|
{
|
|
double y = ext.GetYExtend().GetMin()+i*m_fDistY;
|
|
for (long j = 0; j <= nColNum; j++)
|
|
{
|
|
double x = ext.GetXExtend().GetMin() + j * m_fDistX;
|
|
TPGeGridNode &pt = m_allGridNode[i][j];
|
|
pt.x = x;
|
|
pt.y = y;
|
|
double e1 = m_allGridLineX[i].GetElev(pt.x);
|
|
double e2 = m_allGridLineY[j].GetElev(pt.y);
|
|
|
|
if (fitType==1)
|
|
{
|
|
pt.z = sqrt((e1 * e1 + e2 * e2) / 2);
|
|
}
|
|
else
|
|
{
|
|
pt.z = (e1 + e2) / 2;
|
|
}
|
|
|
|
pt.SetVisible(m_allGridLineX[i].IsVisible(pt.x) && m_allGridLineY[j].IsVisible(pt.y));
|
|
}
|
|
}
|
|
|
|
m_allGridCell.Realloc(nRowNum,nColNum,false);
|
|
for (i = 0;i < nRowNum; i++)
|
|
{
|
|
for (long j = 0;j < nColNum; j++)
|
|
{
|
|
TPGeGridCell& cell = m_allGridCell[i][j];
|
|
cell.m_allNode[0] = &m_allGridNode[i][j];
|
|
cell.m_allNode[1] = &m_allGridNode[i][j+1];
|
|
cell.m_allNode[2] = &m_allGridNode[i+1][j+1];
|
|
cell.m_allNode[3] = &m_allGridNode[i+1][j];
|
|
|
|
cell.m_allSeg[0] = m_allGridLineX[i].m_allSeg[j];
|
|
cell.m_allSeg[1] = m_allGridLineY[j+1].m_allSeg[i];
|
|
cell.m_allSeg[2] = m_allGridLineX[i+1].m_allSeg[j];
|
|
cell.m_allSeg[3] = m_allGridLineY[j].m_allSeg[i];
|
|
|
|
cell.Make3DFace(Outline(),mlines);
|
|
}
|
|
}
|
|
return true;
|
|
} |