You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

573 lines
14 KiB
C++

1 month ago
#include "AppFunc.h"
#include "XJPoint3D.h"
#include "XJOSGView.h"
#include "XJObjectManager.h"
#include "OMPeriodicLattice.h"
#include <thread>
static CXJOSGView* osgView = nullptr;
void Func_InitView(void* hwnd, char* rootPath)
{
if (hwnd == nullptr)
return;
if (osgView == nullptr)
{
osgView = new CXJOSGView(hwnd, 0);
osgView->SetBackGroudBmpPath(rootPath);
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
osgView->InitOSG("OsgView");
//<2F><>ʼ<EFBFBD><CABC><EFBFBD>ӽ<EFBFBD>
osgView->SetCameraLookAt(Point3D(0.0, -200.0, 0.0),
Point3D(0.0, 0.0, 0.0),
Point3D(0.0, 0.0, 1.0));
osgView->ZoomView();
}
}
void Func_InitViewWithColor(void* hwnd, int r, int g, int b)
{
if (hwnd == nullptr)
return;
if (osgView == nullptr)
{
osgView = new CXJOSGView(hwnd, 0);
osgView->SetBackGroudColor(r, g, b, 1);
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
osgView->InitOSG("OsgView");
//<2F><>ʼ<EFBFBD><CABC><EFBFBD>ӽ<EFBFBD>
osgView->SetCameraLookAt(Point3D(0.0, -200.0, 0.0),
Point3D(0.0, 0.0, 0.0),
Point3D(0.0, 0.0, 1.0));
osgView->ZoomView();
}
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->SetInvalidColor(r, g, b);
}
void Func_RenderView()
{
osgView->RequestRedraw();
CXJOSGView::Render(osgView);
}
void Func_ZoomView()
{
osgView->ZoomView();
osgView->SetProjView(OSG_VIEW_TOP);
}
void Func_SetZRange(double zMin, double zMax)
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->SetZRange(zMin, zMax);
}
int Func_CreateMesh(unsigned int numx, unsigned int numy, double x0, double y0, double dx, double dy, double* values)
{
if (numx * numy == 0 || numx == 1 || numy == 1)
return -1;
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
if (pMesh->Create(numx, numy, x0, y0, dx, dy, values))
return -1;
return 0;
}
void Func_SetColorList(const std::vector<ColorItem>& colorList)
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->SetColorList(colorList);
}
void Func_SetContourList(const std::vector<PlineList>& contourList)
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->SetContourList(contourList);
}
void Func_SetFaultList(const std::vector<PlineList>& faultList, bool isOffset)
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->SetFaultList(faultList, isOffset);
}
void Func_SetControlPoint(const std::vector<ControlPoint2d>& pointList)
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->SetControlPointList(pointList);
}
void Func_SetBoundary(const PlineList& bound)
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->SetBound(bound);
}
void Func_SetOtherLines(const PlineList& lines)
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->SetOtherLines(lines);
}
double* Func_GetValue()
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
return pMesh->GetValue();
}
void Func_GetContourList(std::vector<PlineList>& contourList)
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->GetContourList(contourList);
}
void Func_FreeAll()
{
if (osgView)
{
delete osgView;
osgView = nullptr;
}
GetObjectManager()->ClearUndoRedo();
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->Clear();
}
void Func_DrawCircle(int ipx, int ipy, float rad)
{
osgView->DrawCircleOnWindow(ipx, ipy, rad);
}
void Func_ClearCircle()
{
osgView->ClearCircleOnWindow();
}
void Func_StrechUp(int ipx, int ipy, float rad, float per, int type, float wellrad)
{
//<2F><><EFBFBD><EFBFBD><EAB4B0>λ<EFBFBD><CEBB>
Point3D tempPoision0(ipx, ipy, 0);
Point3D tempPoision1(ipx, ipy + rad, 0);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
Point3D NP0, FP0, NP1, FP1;
osgView->TranslatePointW2NFP(tempPoision0, NP0, FP0);
osgView->TranslatePointW2NFP(tempPoision1, NP1, FP1);
float R = (NP0 - NP1).Magnitude();
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->BrushMesh(NP0, R, per, type, wellrad);
osgView->UpdateObjectView(pMesh, UPDATE_WIREFRAME);
}
void Func_PushDown(int ipx, int ipy, float rad, float per, int type, float wellrad)
{
//<2F><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
Point3D tempPoision0(ipx, ipy, 0);
Point3D tempPoision1(ipx, ipy + rad, 0);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
Point3D NP0, FP0, NP1, FP1;
osgView->TranslatePointW2NFP(tempPoision0, NP0, FP0);
osgView->TranslatePointW2NFP(tempPoision1, NP1, FP1);
float R = (NP0 - NP1).Magnitude();
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->BrushMesh(NP0, R, -per, type, wellrad);
osgView->UpdateObjectView(pMesh, UPDATE_WIREFRAME);
}
void Func_DragAway(int startx, int starty, int endx, int endy, float rad, float per, int type, float wellrad)
{
//<2F><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
Point3D tempPoision0(endx, endy, 0);
Point3D tempPoision1(endx, endy + rad, 0);
Point3D tempPoision2(startx, starty, 0);
Point3D NP0, FP0, NP1, FP1;
osgView->TranslatePointW2NFP(tempPoision0, NP0, FP0);
osgView->TranslatePointW2NFP(tempPoision1, NP1, FP1);
float R = (NP0 - NP1).Magnitude();
osgView->TranslatePointW2NFP(tempPoision2, NP1, FP1);
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->DuabMesh(NP1, NP0, R, per, type, wellrad);
osgView->UpdateObjectView(pMesh, UPDATE_WIREFRAME);
}
void Func_Smooth(int ipx, int ipy, float rad, float per, int type, float wellrad)
{
//<2F><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
Point3D tempPoision0(ipx, ipy, 0);
Point3D tempPoision1(ipx, ipy + rad, 0);
Point3D NP0, FP0, NP1, FP1;
osgView->TranslatePointW2NFP(tempPoision0, NP0, FP0);
osgView->TranslatePointW2NFP(tempPoision1, NP1, FP1);
float R = (NP0 - NP1).Magnitude();
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->SmoothMesh(NP0, R, per, type, wellrad);
osgView->UpdateObjectView(pMesh, UPDATE_WIREFRAME);
}
void Func_OffsetFault()
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->OffsetFault();
osgView->UpdateObjectView(pMesh, UPDATE_WIREFRAME);
}
void Func_CutContourByFault()
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->OptimizeIsopleths();
osgView->UpdateObjectView(pMesh, UPDATE_WIREFRAME);
}
void Func_ShowMesh(bool bShow)
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->SetVisibility(bShow);
osgView->UpdateObjectView(pMesh, UPDATE_VISIBLE);
}
void Func_ShowIsopleth(bool bShow)
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->ShowIsopleth(bShow);
osgView->UpdateObjectView(pMesh, UPDATE_VISIBLE);
}
void Func_ShowControlPoint(bool bShow)
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->ShowControlPoint(bShow);
osgView->UpdateObjectView(pMesh, UPDATE_VISIBLE);
}
void Func_ShowFault(bool bShow)
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->ShowFault(bShow);
osgView->UpdateObjectView(pMesh, UPDATE_VISIBLE);
}
void Func_ShowBound(bool bShow)
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->ShowBound(bShow);
osgView->UpdateObjectView(pMesh, UPDATE_VISIBLE);
}
void Func_ShowOtherLines(bool bShow)
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->ShowOtherLines(bShow);
osgView->UpdateObjectView(pMesh, UPDATE_VISIBLE);
}
void Func_ShowMeshVertex(bool bShow)
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->ShowMeshVertex(bShow);
osgView->UpdateObjectView(pMesh, UPDATE_VISIBLE);
}
void Func_SetProperty(double isopStep, int markStep, double minIsop, double maxIsop,
double zMin, double zMax)
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->SetIsoplethProperty(isopStep, markStep, minIsop, maxIsop, zMin, zMax);
pMesh->UpdateIsopleth();
osgView->UpdateObjectView(pMesh, UPDATE_ISOPLETH);
}
void Func_GetProperty(double& isopStep, int& markStep, double& minIsop, double& maxIsop,
double& zMin, double& zMax)
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->GetIsoplethProperty(isopStep, markStep, minIsop, maxIsop, zMin, zMax);
}
void Func_StartCommand()
{
CXJObjectManager::GetInstance()->StartCommand();
}
void Func_EndCommand()
{
CXJObjectManager::GetInstance()->EndCommand();
}
void Func_Undo()
{
CXJObjectManager::GetInstance()->Undo();
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
osgView->UpdateObjectView(pMesh, UPDATE_WIREFRAME);
}
void Func_Redo()
{
CXJObjectManager::GetInstance()->Redo();
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
osgView->UpdateObjectView(pMesh, UPDATE_WIREFRAME);
}
//<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>Գ<EFBFBD><D4B3><EFBFBD>
bool Func_CanUndo()
{
int curStep = CXJObjectManager::GetInstance()->GetUndoCurStep();
return (curStep > 0 ? true : false);
}
//<2F>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
bool Func_CanRedo()
{
int curStep = CXJObjectManager::GetInstance()->GetUndoCurStep();
int stepCount = CXJObjectManager::GetInstance()->GetUndoCount();
return (curStep < stepCount ? true : false);
}
/*******************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*******************/
void Func_WellAdaptiveAdjust(float rad, float range, float miu)
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->AdjuestWithWellPoint(rad, range, miu);
osgView->UpdateObjectView(pMesh, UPDATE_WIREFRAME);
}
void Func_EnablePickMeshZ(bool bEnable)
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
if (pMesh)
{
if (bEnable)
osgView->EnablePickZValue(pMesh, true);
else
osgView->EnablePickZValue(pMesh, false);
}
}
void Func_SetWellColor(int r, int g, int b)
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->SetWellColor(r, g, b);
osgView->UpdateObjectView(pMesh, UPDATE_WELL);
}
void Func_SetWellTxtSize(float size)
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->SetWellTxtSize(size);
osgView->UpdateObjectView(pMesh, UPDATE_WELL);
}
void Func_EnableFillFault(bool bEnable)
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
if (pMesh)
{
if (bEnable)
pMesh->ShowFilledFault(true);
else
pMesh->ShowFilledFault(false);
osgView->UpdateObjectView(pMesh, UPDATE_FAULT);
}
}
void Func_FilterMesh(float throld)
{
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
if (pMesh)
{
pMesh->FilterIsopleths(throld);
osgView->UpdateObjectView(pMesh, UPDATE_WIREFRAME);
}
}
void Func_EnableDrawPolygon(bool bEnable)
{
osgView->EnableOpDrawPolygon(bEnable);
}
void Func_StretchlUpPolygon(float per, bool state, float wellRad)
{
std::vector<Point2D> polygen;
osgView->GetOpDrawPolygon(polygen);
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->StretchlUpPolygon(polygen, per, wellRad, state);
osgView->UpdateObjectView(pMesh, UPDATE_WIREFRAME);
}
void Func_PushDownPolygon(float per, bool state, float wellRad)
{
std::vector<Point2D> polygen;
osgView->GetOpDrawPolygon(polygen);
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->StretchlUpPolygon(polygen, -per, wellRad, state);
osgView->UpdateObjectView(pMesh, UPDATE_WIREFRAME);
}
void Func_SmoothPolygon(float per, bool state, float wellRad)
{
std::vector<Point2D> polygen;
osgView->GetOpDrawPolygon(polygen);
OMPeriodicLattice* pMesh = CXJObjectManager::GetInstance()->GetPeriodicLattice();
pMesh->SmoothPolygon(polygen, per, wellRad, state);
osgView->UpdateObjectView(pMesh, UPDATE_WIREFRAME);
}
void Func_OptimizeMesh(int startx, int starty, int endx, int endy, float rad, float per)
{
//<2F><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>
Point3D tempPoision0(endx, endy, 0);
Point3D tempPoision1(endx, endy + rad, 0);
Point3D tempPoision2(startx, starty, 0);
Point3D NP0, FP0, NP1, FP1;
osgView->TranslatePointW2NFP(tempPoision0, NP0, FP0);
osgView->TranslatePointW2NFP(tempPoision1, NP1, FP1);
float R = (NP0 - NP1).Magnitude();
osgView->TranslatePointW2NFP(tempPoision2, NP1, FP1);
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->TransitFault(NP1, NP0, R, per);
osgView->UpdateObjectView(pMesh, UPDATE_WIREFRAME);
}
void Func_GetViewPos(double& px, double& py, double& scale)
{
Point2D pt;
double s = 1.0;
osgView->GetViewPos(pt, s);
px = pt.x();
py = pt.y();
scale = s;
}
void Func_SetViewPos(double px, double py, double scale)
{
osgView->SetViewPos(px, py, scale);
}
void Func_GetMousePos(double& px, double& py)
{
int cx = 0, cy = 0;
osgView->GetMousePos(cx, cy);
Point3D pt(cx, cy, 0);
Point3D np, fp;
osgView->TranslatePointW2NFP(pt, np, fp);
px = np.x();
py = np.y();
}
void Func_SetMousePos(double px, double py)
{
Point3D pt(px, py, 0);
int cx=0, cy = 0;
osgView->ProjectObjectToWindow(pt, cx, cy);
osgView->ShowMouse(cx, cy);
}
bool Func_CalculateZByExpression(char* expressionStr)
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
bool state = pMesh->CalculateZByExpression(expressionStr);
osgView->UpdateObjectView(pMesh, UPDATE_ALL);
return state;
}
double Func_GetZMin()
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
return pMesh->GetZMin();
}
double Func_GetZMax()
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
return pMesh->GetZMax();
}
void Func_SetDecimalNumber(int num)
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->SetDecimalNumber(num);
osgView->UpdateObjectView(pMesh, UPDATE_ALL);
}
int Func_GetDecimalNumber()
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
return pMesh->GetDecimalNumber();
}
void Func_SetFaultControlState(bool state)
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->SetFaultControlState(state);
}
bool Func_GetFaultControlState()
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
return pMesh->GetFaultControlState();
}
bool Func_RectificationMeshWellCompute(double deltaz, int type, double factor)
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
bool state = pMesh->RectificationMeshWellCompute(deltaz, type, factor);
//osgView->UpdateObjectView(pMesh, UPDATE_ALL);
return state;
}
void Func_MeshWellThreadStop()
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->MeshWellThreadStop();
}
int Func_GetWellRectificationProgress()
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
return pMesh->GetMeshWellRectificationProgress();
}
void Func_UpdateObjectView()
{
OMPeriodicLattice* pMesh = GetObjectManager()->GetPeriodicLattice();
pMesh->UpdataMeshWellRectificationView();
osgView->UpdateObjectView(pMesh, UPDATE_ALL);
}