stl transform program source code...// cstlfiletransferapp initialization bool...
TRANSCRIPT
STL Transform Program – Source Code
// STLFileTransfer.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "MainFrm.h"
#include "STLFileTransferDoc.h"
#include "STLFileTransferView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferApp
BEGIN_MESSAGE_MAP(CSTLFileTransferApp, CWinApp)
//{{AFX_MSG_MAP(CSTLFileTransferApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferApp construction
CSTLFileTransferApp::CSTLFileTransferApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CSTLFileTransferApp object
CSTLFileTransferApp theApp;
/////////////////////////////////////////////////////////////////////////////
Nature Biotechnology: doi:10.1038/nbt.3413
// CSTLFileTransferApp initialization
BOOL CSTLFileTransferApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CSTLFileTransferDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CSTLFileTransferView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
Nature Biotechnology: doi:10.1038/nbt.3413
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
Nature Biotechnology: doi:10.1038/nbt.3413
void CSTLFileTransferApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferApp message handlers
// MainFrm.h : interface of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_MAINFRM_H__4BA94D58_D9F8_482A_A072_837E80A29C2F__INCLUDED_)
#define AFX_MAINFRM_H__4BA94D58_D9F8_482A_A072_837E80A29C2F__INCLUDED_
#include "STLFileTransferDoc.h" // Added by ClassView
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMainFrame : public CFrameWnd
{
protected: // create from serialization only
CMainFrame();
DECLARE_DYNCREATE(CMainFrame)
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMainFrame)
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
//}}AFX_VIRTUAL
// Implementation
public:
CSTLFileTransferDoc* GetDocument();
virtual ~CMainFrame();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
Nature Biotechnology: doi:10.1038/nbt.3413
protected: // control bar embedded members
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
// Generated message map functions
protected:
//{{AFX_MSG(CMainFrame)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnDoSlice();
afx_msg void OnDoLineOffset();
afx_msg void OnMakeBeamLine();
afx_msg void OnMenuExportCodeFile();
afx_msg void OnRotandMag();
afx_msg void OnGenDMDBeam();
afx_msg void OnRotation();
afx_msg void OnMagnification();
afx_msg void OnGen3DObject();
afx_msg void OnSTLFileOpen();
afx_msg void OnRangeslice();
afx_msg void OnGenVerticalPath();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MAINFRM_H__4BA94D58_D9F8_482A_A072_837E80A29C2F__INCLUDED_)
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "STLFileTransferDoc.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
Nature Biotechnology: doi:10.1038/nbt.3413
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(ID_DOSLICE, OnDoSlice)
ON_COMMAND(ID_DOLINEOFFSET, OnDoLineOffset)
ON_COMMAND(ID_MAKEBEAMLINE, OnMakeBeamLine)
ON_COMMAND(ID_MENUEXPORTCODEFILE, OnMenuExportCodeFile)
ON_COMMAND(ID_ROTANDMAG, OnRotandMag)
ON_COMMAND(ID_GENDMDBEAM, OnGenDMDBeam)
ON_COMMAND(ID_MENUITEM32779, OnRotation)
ON_COMMAND(ID_MAGNIFICATION, OnMagnification)
ON_COMMAND(ID_GEN3DOBJECT, OnGen3DObject)
ON_COMMAND(ID_STLFILEOPEN, OnSTLFileOpen)
ON_COMMAND(ID_RANGESLICE, OnRangeslice)
ON_COMMAND(ID_GENVERTICALPATH, OnGenVerticalPath)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
static UINT indicators[] =
{
ID_SEPARATOR, // status line indicator
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
};
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
}
CMainFrame::~CMainFrame()
{
}
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
Nature Biotechnology: doi:10.1038/nbt.3413
{
TRACE0("Failed to create toolbar\n");
return -1; // fail to create
}
if (!m_wndStatusBar.Create(this) ||
!m_wndStatusBar.SetIndicators(indicators,
sizeof(indicators)/sizeof(UINT)))
{
TRACE0("Failed to create status bar\n");
return -1; // fail to create
}
// TODO: Delete these three lines if you don't want the toolbar to
// be dockable
m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
EnableDocking(CBRS_ALIGN_ANY);
DockControlBar(&m_wndToolBar);
return 0;
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
Nature Biotechnology: doi:10.1038/nbt.3413
// CMainFrame message handlers
void CMainFrame::OnDoSlice()
{
// TODO: Add your command handler code here
CSTLFileTransferDoc* pDoc=GetDocument();
pDoc->SliceSTLFile();
}
CSTLFileTransferDoc* CMainFrame::GetDocument()
{
CDocument* m_pDocument = GetActiveDocument();
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSTLFileTransferDoc)));
return (CSTLFileTransferDoc*)m_pDocument;
}
void CMainFrame::OnDoLineOffset()
{
// TODO: Add your command handler code here
CSTLFileTransferDoc* pDoc=GetDocument();
pDoc->DoOffsetSlicedProfile();
}
void CMainFrame::OnMakeBeamLine()
{
// TODO: Add your command handler code here
CSTLFileTransferDoc* pDoc=GetDocument();
pDoc->DoGenerationBeamLine();
}
void CMainFrame::OnMenuExportCodeFile()
{
// TODO: Add your command handler code here
CSTLFileTransferDoc* pDoc=GetDocument();
pDoc->ExportCodeFile();
}
void CMainFrame::OnRotandMag()
{
// TODO: Add your command handler code here
CSTLFileTransferDoc* pDoc=GetDocument();
pDoc->RotAndMag();
}
void CMainFrame::OnGenDMDBeam()
{
Nature Biotechnology: doi:10.1038/nbt.3413
// TODO: Add your command handler code here
CSTLFileTransferDoc* pDoc=GetDocument();
pDoc->GenDMDBeamPath();
}
void CMainFrame::OnRotation()
{
// TODO: Add your command handler code here
CSTLFileTransferDoc* pDoc=GetDocument();
pDoc->Rotation();
}
void CMainFrame::OnMagnification()
{
// TODO: Add your command handler code here
CSTLFileTransferDoc* pDoc=GetDocument();
pDoc->DoMagnification();
}
void CMainFrame::OnGen3DObject()
{
// TODO: Add your command handler code here
CSTLFileTransferDoc* pDoc=GetDocument();
pDoc->Generation3DObject();
}
void CMainFrame::OnSTLFileOpen()
{
// TODO: Add your command handler code here
CSTLFileTransferDoc* pDoc=GetDocument();
pDoc->STLFileOpen();
}
void CMainFrame::OnRangeslice()
{
// TODO: Add your command handler code here
CSTLFileTransferDoc* pDoc=GetDocument();
pDoc->RangeSliceSTLFile();
}
void CMainFrame::OnGenVerticalPath()
{
// TODO: Add your command handler code here
CSTLFileTransferDoc* pDoc=GetDocument();
pDoc->GenVerticalPath();
}
Nature Biotechnology: doi:10.1038/nbt.3413
// STLFileTransfer.h : main header file for the STLFILETRANSFER application
//
#if !defined(AFX_STLFILETRANSFER_H__157B8FF2_61CA_4E2E_90A1_C1D6E5EC8E5A__INCLUDED_)
#define AFX_STLFILETRANSFER_H__157B8FF2_61CA_4E2E_90A1_C1D6E5EC8E5A__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#ifndef __AFXWIN_H__
#error include 'stdafx.h' before including this file for PCH
#endif
#include "resource.h" // main symbols
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferApp:
// See STLFileTransfer.cpp for the implementation of this class
//
class CSTLFileTransferApp : public CWinApp
{
public:
CSTLFileTransferApp();
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSTLFileTransferApp)
public:
virtual BOOL InitInstance();
//}}AFX_VIRTUAL
// Implementation
//{{AFX_MSG(CSTLFileTransferApp)
afx_msg void OnAppAbout();
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
Nature Biotechnology: doi:10.1038/nbt.3413
#endif // !defined(AFX_STLFILETRANSFER_H__157B8FF2_61CA_4E2E_90A1_C1D6E5EC8E5A__INCLUDED_)
// STLFileTransfer.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "MainFrm.h"
#include "STLFileTransferDoc.h"
#include "STLFileTransferView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferApp
BEGIN_MESSAGE_MAP(CSTLFileTransferApp, CWinApp)
//{{AFX_MSG_MAP(CSTLFileTransferApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferApp construction
CSTLFileTransferApp::CSTLFileTransferApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CSTLFileTransferApp object
CSTLFileTransferApp theApp;
/////////////////////////////////////////////////////////////////////////////
Nature Biotechnology: doi:10.1038/nbt.3413
// CSTLFileTransferApp initialization
BOOL CSTLFileTransferApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CSTLFileTransferDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CSTLFileTransferView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
Nature Biotechnology: doi:10.1038/nbt.3413
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
// No message handlers
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
Nature Biotechnology: doi:10.1038/nbt.3413
void CSTLFileTransferApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferApp message handlers
// STLFileTransferDoc.h : interface of the CSTLFileTransferDoc class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_STLFILETRANSFERDOC_H__40500064_D244_4BBC_B347_4DF5B8687F79__INCLUDED_)
#define AFX_STLFILETRANSFERDOC_H__40500064_D244_4BBC_B347_4DF5B8687F79__INCLUDED_
#include "MultiFacets.h" // Added by ClassView
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CSTLFileTransferDoc : public CDocument
{
protected: // create from serialization only
CSTLFileTransferDoc();
DECLARE_DYNCREATE(CSTLFileTransferDoc)
// Attributes
public:
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSTLFileTransferDoc)
public:
virtual BOOL OnNewDocument();
virtual void Serialize(CArchive& ar);
//}}AFX_VIRTUAL
// Implementation
public:
void GenVerticalPath();
int RepeatingIndex;
void RangeSliceSTLFile();
void STLFileOpen();
void DataSaveOrLoad(BOOL Save, CArchive &ar);
void Generation3DObject();
Nature Biotechnology: doi:10.1038/nbt.3413
void DoMagnification();
void Rotation();
int NumOfEmptyLine;
int NumOfSolidLine;
double IlluminationTime;
double ImageSize[2];
UINT DMDPixelNum[2];
void GenDMDBeamPath();
int BeamPathGenMode;
void RotAndMag();
int NumOfDirectionOverlap;
double FabErrorOffsetValue;
double DifCWRotAngle;
double LinePitch;
UINT Feedrate;
UINT LaserPower;
void ExportCodeFile();
int NumOfOffset;
double MaxMoveDis;
double MinMoveDis;
void DoGenerationBeamLine();
BOOL IsBeamLineView;
double OffsetValue;
void DoOffsetSlicedProfile();
double DataMagnificationFactor;
BOOL RotationIsPositive;
int RotationAxisNum;
void STLFileFacetPerpendicularRotation();
double SliceThickness;
BOOL IsSectionView;
BOOL IsSTLFileView;
void SliceSTLFile();
int LoadableMaxNumOfFacet;
CMultiFacets STLFile;
virtual ~CSTLFileTransferDoc();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CSTLFileTransferDoc)
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
Nature Biotechnology: doi:10.1038/nbt.3413
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STLFILETRANSFERDOC_H__40500064_D244_4BBC_B347_4DF5B8687F79__INCLUDED_)
// STLFileTransferDoc.cpp : implementation of the CSTLFileTransferDoc class
//
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "Product.h"
#include "STLFileTransferDoc.h"
#include "RotAndMagDialog.h"
#include "InsertSliceThickness.h"
#include "InsertOffsetValue.h"
#include "InsertBeamGenParDial.h"
#include "InsertFabInfDialog.h"
#include "STLFileRotation.h"
#include "Magnification.h"
#include "InputHeightDialog.h"
#include "RangeSlice.h"
#define PI 3.141592653589793
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferDoc
IMPLEMENT_DYNCREATE(CSTLFileTransferDoc, CDocument)
BEGIN_MESSAGE_MAP(CSTLFileTransferDoc, CDocument)
//{{AFX_MSG_MAP(CSTLFileTransferDoc)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferDoc construction/destruction
Nature Biotechnology: doi:10.1038/nbt.3413
CSTLFileTransferDoc::CSTLFileTransferDoc()
{
// TODO: add one-time construction code here
LoadableMaxNumOfFacet=1000000;
SliceThickness=1.0;
OffsetValue=1.0;
FabErrorOffsetValue=0.0;
NumOfOffset=0;
MinMoveDis=0.3;
MaxMoveDis=OffsetValue*3.0;
RotationAxisNum=1;
RotationIsPositive=true;
DataMagnificationFactor=1.0f;
IsSTLFileView=true;
IsSectionView=false;
IsBeamLineView=false;
LaserPower=100;
Feedrate=40;
DifCWRotAngle=0.0;
LinePitch=0.5;
NumOfDirectionOverlap=4;
BeamPathGenMode=3;
DMDPixelNum[0]=1024; //X-axis
DMDPixelNum[1]=768; //Y-axis
IlluminationTime=1000; //msec
ImageSize[0]=10.24; //X-axis
ImageSize[1]=7.68; //Y-axis
NumOfSolidLine=30;
NumOfEmptyLine=100;
RepeatingIndex=3;
}
CSTLFileTransferDoc::~CSTLFileTransferDoc()
{
}
Nature Biotechnology: doi:10.1038/nbt.3413
BOOL CSTLFileTransferDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferDoc serialization
void CSTLFileTransferDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
CFile* tempFile = ar.GetFile();
if(tempFile->GetFileName().Right(4) == ".SFT" || tempFile->GetFileName().Right(4) == ".Sft" || tempFile-
>GetFileName().Right(4) == ".sft")
DataSaveOrLoad(true,ar);
}
else
{
// TODO: add loading code here
CFile* tempFile = ar.GetFile();
if(tempFile->GetFileName().Right(4) == ".SFT" || tempFile->GetFileName().Right(4) == ".Sft" || tempFile-
>GetFileName().Right(4) == ".sft")
DataSaveOrLoad(false,ar);
}
}
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferDoc diagnostics
#ifdef _DEBUG
void CSTLFileTransferDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CSTLFileTransferDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
Nature Biotechnology: doi:10.1038/nbt.3413
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferDoc commands
void CSTLFileTransferDoc::SliceSTLFile()
{
if(STLFile.GetNumOfFacet()==0) return;
CInsertSliceThickness InsertDial(this);
if( InsertDial.DoModal() == IDOK )
{
STLFile.GenerationCrossProfile(SliceThickness);
AfxMessageBox("Slicing is Completed");
IsSTLFileView=false;
IsSectionView=true;
UpdateAllViews(NULL);
}
}
void CSTLFileTransferDoc::STLFileFacetPerpendicularRotation()
{
STLFile.FacetPerpendicularRotaionXYZ(RotationAxisNum,RotationIsPositive);
}
void CSTLFileTransferDoc::DoOffsetSlicedProfile()
{
if(STLFile.GetNumOfLoops()==0) return;
CInsertOffsetValue InsertDialog(this);
if( InsertDialog.DoModal() == IDOK )
{
STLFile.DoOffset(OffsetValue);
AfxMessageBox("Offset is Completed");
IsSTLFileView=false;
IsSectionView=true;
IsBeamLineView=false;
UpdateAllViews(NULL);
}
}
void CSTLFileTransferDoc::DoGenerationBeamLine()
{
Nature Biotechnology: doi:10.1038/nbt.3413
if(STLFile.GetNumOfLoops()==0) return;
CInsertBeamGenParDial ParDial(this);
if( ParDial.DoModal() == IDOK )
{
if( ParDial.m_IsMoldGeneration )
{
STLFile.GenerationMoldBeamLine(DifCWRotAngle,LinePitch,MinMoveDis,FabErrorOffsetValue,NumOfDirectionOv
erlap,ParDial.m_MoldOffsetSize);
}
else
{
if( BeamPathGenMode == 1 )
STLFile.GenerationBeamLine(OffsetValue/(double)NumOfOffset, NumOfOffset,
MinMoveDis,MaxMoveDis,FabErrorOffsetValue);
else if( BeamPathGenMode == 2 )
STLFile.GenerationBeamLine2(DifCWRotAngle,LinePitch,OffsetValue/(double)NumOfOffset,NumOfOffset,MinMove
Dis,FabErrorOffsetValue,NumOfDirectionOverlap);
else if( BeamPathGenMode == 3 )
STLFile.GenerationBeamLine3(DifCWRotAngle,LinePitch,OffsetValue/(double)NumOfOffset,NumOfOffset,MinMove
Dis,FabErrorOffsetValue,NumOfDirectionOverlap);
else if( BeamPathGenMode == 4 )
STLFile.GenerationBeamLine4(DifCWRotAngle,LinePitch,OffsetValue/(double)NumOfOffset,NumOfOffset,MinMove
Dis,FabErrorOffsetValue,NumOfDirectionOverlap,RepeatingIndex);
else
return;
}
AfxMessageBox("Beam Line Generation is Completed");
IsSTLFileView=false;
IsSectionView=false;
IsBeamLineView=true;
UpdateAllViews(NULL);
}
}
void CSTLFileTransferDoc::ExportCodeFile()
{
CProduct TmpProduct;
CInsertFabInfDialog FabInfDiolog(this);
if( FabInfDiolog.DoModal() == IDOK )
Nature Biotechnology: doi:10.1038/nbt.3413
{
if( BeamPathGenMode == 1 || BeamPathGenMode == 2 )
TmpProduct=STLFile.GetBeamProduct(LaserPower,Feedrate,BeamPathGenMode);
//GenerationBeamLine 과 GenerationBeamLine2의 경우 사용
else if( BeamPathGenMode == 3 )
TmpProduct=STLFile.GetBeamProduct3(LaserPower,Feedrate); //GenerationBeamLine3의
경우 사용
else if( BeamPathGenMode == 4 )
TmpProduct=STLFile.GetBeamProduct4(LaserPower,Feedrate,RepeatingIndex);
//GenerationBeamLine4의 경우 사용
else
return;
CString SaveFile;
char szFilter[]="Code files (*.Code)|*.Code|모든 파일(*.*)|*.*||";
CFileDialog fileDlg(FALSE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,szFilter);
if(fileDlg.DoModal() == IDOK)
SaveFile = fileDlg.GetPathName();
SaveFile.MakeLower();
if(SaveFile.GetLength()!=0)
{
if(SaveFile.Find(".code")==-1)
SaveFile+=".Code";
CFile fsave;
char buf[512];
if( !fsave.Open(SaveFile,CFile::modeCreate|CFile::modeWrite) )
{
#ifdef _DEBUG
afxDump<<"Unable to open file"<<"\n";
exit(-1);
#endif
}
CArchive ar(&fsave,CArchive::store,512,buf);
CFile* tmpFile = ar.GetFile();
TmpProduct.ProductSaveOrLoad(true,ar);
}
AfxMessageBox("Export is Completed");
}
Nature Biotechnology: doi:10.1038/nbt.3413
}
void CSTLFileTransferDoc::RotAndMag()
{
CRotAndMagDialog RMDial(this);
if( RMDial.DoModal()==IDOK)
{
STLFileFacetPerpendicularRotation();
STLFile.DataMagnification(DataMagnificationFactor);
UpdateAllViews(NULL);
}
}
void CSTLFileTransferDoc::GenDMDBeamPath()
{
if(STLFile.GetNumOfLoops()==0) return;
double PixelPitch=ImageSize[0]/(double)DMDPixelNum[0];
BeamPathGenMode=2;
STLFile.GenerationDMDBeamLine(DifCWRotAngle,NumOfSolidLine,NumOfEmptyLine,PixelPitch,OffsetValue/(dou
ble)NumOfOffset,NumOfOffset,MinMoveDis,FabErrorOffsetValue,NumOfDirectionOverlap);
AfxMessageBox("DMD Beam Line Generation is Completed");
IsSTLFileView=false;
IsSectionView=false;
IsBeamLineView=true;
UpdateAllViews(NULL);
}
void CSTLFileTransferDoc::Rotation()
{
CSTLFileRotation RotationDia;
if(RotationDia.DoModal()==IDOK)
{
STLFile.FacetRotaionXYZ(RotationDia.GetRotationAxisNum(),RotationDia.GetCCWRotationAngle());
UpdateAllViews(NULL);
}
}
void CSTLFileTransferDoc::DoMagnification()
{
CMagnification MagDia;
Nature Biotechnology: doi:10.1038/nbt.3413
if(MagDia.DoModal()==IDOK)
{
STLFile.DataMagnification(MagDia.GetMagnificationValue());
UpdateAllViews(NULL);
}
}
void CSTLFileTransferDoc::Generation3DObject()
{
CInputHeightDialog HDia;
if(HDia.DoModal()==IDOK)
{
STLFile.GenerationFrom2DTo3D_FlatSurface(HDia.m_Height);
UpdateAllViews(NULL);
}
}
void CSTLFileTransferDoc::DataSaveOrLoad(BOOL Save, CArchive &ar)
{
if(Save)
{
ar<<NumOfEmptyLine<<NumOfSolidLine<<IlluminationTime<<ImageSize[0]<<ImageSize[1]<<DMDPixelNum[0]<<
DMDPixelNum[1];
ar<<BeamPathGenMode<<NumOfDirectionOverlap<<FabErrorOffsetValue<<DifCWRotAngle<<LinePitch<<Feedrat
e<<LaserPower;
ar<<NumOfOffset<<MaxMoveDis<<MinMoveDis<<IsBeamLineView<<OffsetValue<<DataMagnificationFactor<<Rot
ationIsPositive;
ar<<RotationAxisNum<<SliceThickness<<IsSectionView<<IsSTLFileView<<LoadableMaxNumOfFacet;
STLFile.SaveOrLoad(Save,ar);
}
else
{
ar>>NumOfEmptyLine>>NumOfSolidLine>>IlluminationTime>>ImageSize[0]>>ImageSize[1]>>DMDPixelNum[0]>>
DMDPixelNum[1];
ar>>BeamPathGenMode>>NumOfDirectionOverlap>>FabErrorOffsetValue>>DifCWRotAngle>>LinePitch>>Feedrat
e>>LaserPower;
ar>>NumOfOffset>>MaxMoveDis>>MinMoveDis>>IsBeamLineView>>OffsetValue>>DataMagnificationFactor>>Rot
ationIsPositive;
ar>>RotationAxisNum>>SliceThickness>>IsSectionView>>IsSTLFileView>>LoadableMaxNumOfFacet;
STLFile.SaveOrLoad(Save,ar);
}
Nature Biotechnology: doi:10.1038/nbt.3413
UpdateAllViews(NULL);
}
void CSTLFileTransferDoc::STLFileOpen()
{
CString szFilter="STL Files(*.stl)|*.stl|All Files(*.*)|*.*||";
CString TmpFileName;
CFileDialog fileDlg(false,"stl",NULL,OFN_HIDEREADONLY,szFilter);
if(IDOK==fileDlg.DoModal())
TmpFileName=fileDlg.GetFileName();
else
return;
CFile file;
if( !file.Open(TmpFileName,CFile::modeRead) )
return;
CArchive ar(&file, CArchive::load);
TmpFileName.MakeLower();
if(TmpFileName.Find(".stl")!=-1)
{
STLFile.LoadForBinay(ar,LoadableMaxNumOfFacet,DataMagnificationFactor);
IsSTLFileView=true;
IsSectionView=false;
IsBeamLineView=false;
}
UpdateAllViews(NULL);
}
void CSTLFileTransferDoc::RangeSliceSTLFile()
{
if(STLFile.GetNumOfFacet()==0) return;
CRangeSlice InsertDial;
if( InsertDial.DoModal() == IDOK )
{
STLFile.GenerationCrossProfile(InsertDial.m_LayerThickness,InsertDial.m_RangeFrom,InsertDial.m_RangeTo);
AfxMessageBox("Slicing is Completed");
Nature Biotechnology: doi:10.1038/nbt.3413
IsSTLFileView=false;
IsSectionView=true;
UpdateAllViews(NULL);
}
}
void CSTLFileTransferDoc::GenVerticalPath()
{
if(STLFile.GetNumOfFacet()==0) return;
STLFile.GenVerticalPath();
AfxMessageBox("Verticla path generation is Completed");
IsSTLFileView=false;
IsSectionView=true;
UpdateAllViews(NULL);
}
// STLFileTransferView.h : interface of the CSTLFileTransferView class
//
/////////////////////////////////////////////////////////////////////////////
#if !defined(AFX_STLFILETRANSFERVIEW_H__34769573_BFD9_4EBE_9A08_975699EAB85B__INCLUDED_)
#define AFX_STLFILETRANSFERVIEW_H__34769573_BFD9_4EBE_9A08_975699EAB85B__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CSTLFileTransferView : public CView
{
protected: // create from serialization only
CSTLFileTransferView();
DECLARE_DYNCREATE(CSTLFileTransferView)
// Attributes
public:
CSTLFileTransferDoc* GetDocument();
// Operations
public:
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CSTLFileTransferView)
public:
Nature Biotechnology: doi:10.1038/nbt.3413
virtual void OnDraw(CDC* pDC); // overridden to draw this view
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
//}}AFX_VIRTUAL
// Implementation
public:
void RenderSceneBeamLine();
void DrawLine(float Point1[2], float Point2[2], float ZValue);
void RenderSceneSectionView();
double ReturnPointAngle(float Point[2]);
double ReturnAngle(float Start[2],float End[2]);
void DrawArrow(float DirX, float DirY, float DirZ, float Ra);
void DrawAxis();
void ViewFormat3D();
void DrawTriangle(float Point1[3], float Point2[3], float Point3[3]);
GLdouble m_zRotate;
GLdouble m_yRotate;
GLdouble m_xRotate;
CPoint m_RDownPos;
CPoint m_LDownPos;
BOOL m_RButtonDown;
BOOL m_LButtonDown;
GLdouble m_yTranslate;
GLdouble m_xTranslate;
GLdouble m_view_distance;
void RenderSceneSTLFile();
void RenderScene();
BOOL SetupPixelFormat();
BOOL InitializeOpenGL();
HGLRC m_hRC; //Rendering Context
CDC* m_pDC; //Device Context
virtual ~CSTLFileTransferView();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
protected:
// Generated message map functions
protected:
//{{AFX_MSG(CSTLFileTransferView)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnDestroy();
afx_msg void OnSize(UINT nType, int cx, int cy);
Nature Biotechnology: doi:10.1038/nbt.3413
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
afx_msg void OnZView();
afx_msg void OnXView();
afx_msg void OnYView();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
int ViewSizeX;
int ViewSizeY;
};
#ifndef _DEBUG // debug version in STLFileTransferView.cpp
inline CSTLFileTransferDoc* CSTLFileTransferView::GetDocument()
{ return (CSTLFileTransferDoc*)m_pDocument; }
#endif
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STLFILETRANSFERVIEW_H__34769573_BFD9_4EBE_9A08_975699EAB85B__INCLUDED_)
// STLFileTransferView.cpp : implementation of the CSTLFileTransferView class
//
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "STLFileTransferDoc.h"
#include "STLFileTransferView.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferView
Nature Biotechnology: doi:10.1038/nbt.3413
IMPLEMENT_DYNCREATE(CSTLFileTransferView, CView)
BEGIN_MESSAGE_MAP(CSTLFileTransferView, CView)
//{{AFX_MSG_MAP(CSTLFileTransferView)
ON_WM_CREATE()
ON_WM_DESTROY()
ON_WM_SIZE()
ON_WM_ERASEBKGND()
ON_WM_MOUSEWHEEL()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_COMMAND(ID_ZVIEW, OnZView)
ON_COMMAND(ID_XVIEW, OnXView)
ON_COMMAND(ID_YVIEW, OnYView)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferView construction/destruction
CSTLFileTransferView::CSTLFileTransferView()
{
// TODO: add construction code here
ViewSizeX=0;
ViewSizeY=0;
m_view_distance = -3.4;
m_xTranslate = 0.0;
m_yTranslate = 0.0;
m_RButtonDown=false;
m_LButtonDown=false;
m_xRotate = -70.0; //45.;// -37.0;
m_yRotate = -15.0; //30.; //-15.0;
m_zRotate = 0.0;
}
CSTLFileTransferView::~CSTLFileTransferView()
{
}
BOOL CSTLFileTransferView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
Nature Biotechnology: doi:10.1038/nbt.3413
// the CREATESTRUCT cs
//An OpenGL Window must be created with the following flags
cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferView drawing
void CSTLFileTransferView::OnDraw(CDC* pDC)
{
CSTLFileTransferDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
// Clear out the color & depth buffers
::glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
RenderScene();
// Tell OpenGL to flush its pipeline
::glFinish();
// Now Swap the buffers
::SwapBuffers( m_pDC->GetSafeHdc() );
}
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferView printing
BOOL CSTLFileTransferView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CSTLFileTransferView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CSTLFileTransferView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
Nature Biotechnology: doi:10.1038/nbt.3413
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferView diagnostics
#ifdef _DEBUG
void CSTLFileTransferView::AssertValid() const
{
CView::AssertValid();
}
void CSTLFileTransferView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CSTLFileTransferDoc* CSTLFileTransferView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CSTLFileTransferDoc)));
return (CSTLFileTransferDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CSTLFileTransferView message handlers
int CSTLFileTransferView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
InitializeOpenGL();
return 0;
}
void CSTLFileTransferView::OnDestroy()
{
CView::OnDestroy();
// TODO: Add your message handler code here
//Make the RC non-current
if(::wglMakeCurrent (0,0) == FALSE)
{
MessageBox("Could not make RC non-current");
}
//Delete the rendering context
if(::wglDeleteContext (m_hRC)==FALSE)
Nature Biotechnology: doi:10.1038/nbt.3413
{
MessageBox("Could not delete RC");
}
//Delete the DC
if(m_pDC)
{
delete m_pDC;
}
//Set it to NULL
m_pDC = NULL;
}
void CSTLFileTransferView::OnSize(UINT nType, int cx, int cy)
{
CView::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
ViewSizeX=cx;
ViewSizeY=cy;
ViewFormat3D();
}
BOOL CSTLFileTransferView::OnEraseBkgnd(CDC* pDC)
{
// TODO: Add your message handler code here and/or call default
//comment out the original call
//return CView::OnEraseBkgnd(pDC);
//Tell Windows not to erase the background
return TRUE;
}
BOOL CSTLFileTransferView::InitializeOpenGL()
{
//Get a DC for the Client Area
m_pDC=new CClientDC(this);
//Failure to Get DC
if(m_pDC==NULL)
{
MessageBox("Error Obtaining DC");
return FALSE;
}
//Failure to set the pixel format
if(!SetupPixelFormat())
{
Nature Biotechnology: doi:10.1038/nbt.3413
return FALSE;
}
//Create Rendering Context
m_hRC=::wglCreateContext(m_pDC->GetSafeHdc());
//Failure to Create Rendering Context
if(m_hRC==0)
{
MessageBox("Error Creating RC");
return FALSE;
}
//Make the RC Current
if(::wglMakeCurrent(m_pDC->GetSafeHdc(), m_hRC)==FALSE)
{
MessageBox("Error making RC Current");
return FALSE;
}
//Specify Black as the clear color
// 배경 색깔
::glClearColor(0.0f,0.0f,0.0f,0.5f);
// ::glClearColor(1.0f,1.0f,1.0f,0.5f);
//Specify the back of the buffer as clear depth
::glClearDepth(1.0f);
//Enable Depth Testing
::glEnable(GL_DEPTH_TEST);
return true;
}
BOOL CSTLFileTransferView::SetupPixelFormat()
{
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER, // double buffered
PFD_TYPE_RGBA, // RGBA type
24, // 24-bit color depth
0, 0, 0, 0, 0, 0, // color bits ignored
0, // no alpha buffer
0, // shift bit ignored
Nature Biotechnology: doi:10.1038/nbt.3413
0, // no accumulation buffer
0, 0, 0, 0, // accumulation bits ignored
16, // 16-bit z-buffer
0, // no stencil buffer
0, // no auxiliary buffer
PFD_MAIN_PLANE, // main layer
0, // reserved
0, 0, 0 // layer masks ignored
};
int m_nPixelFormat = ::ChoosePixelFormat(m_pDC->GetSafeHdc(), &pfd);
if ( m_nPixelFormat == 0 )
{
return FALSE;
}
if ( ::SetPixelFormat(m_pDC->GetSafeHdc(), m_nPixelFormat, &pfd) == FALSE)
{
return FALSE;
}
return TRUE;
}
void CSTLFileTransferView::RenderScene()
{
CSTLFileTransferDoc *pDoc=GetDocument();
DrawAxis();
//IsSTLFileView; //IsSectionView; //IsBeamLineView;
if(pDoc->IsSTLFileView && !pDoc->IsSectionView && !pDoc->IsBeamLineView )
RenderSceneSTLFile();
else if(!pDoc->IsSTLFileView && pDoc->IsSectionView && !pDoc->IsBeamLineView)
RenderSceneSectionView();
else if(!pDoc->IsSTLFileView && !pDoc->IsSectionView && pDoc->IsBeamLineView)
RenderSceneBeamLine();
}
void CSTLFileTransferView::RenderSceneSTLFile()
{
CSTLFileTransferDoc *pDoc=GetDocument();
int NumOfLine=pDoc->STLFile.GetNumOfFacet();
if(NumOfLine<1) return;
Nature Biotechnology: doi:10.1038/nbt.3413
double Center[3];
float CenterLineLength=100.0;
pDoc->STLFile.GetMultiFacetCenterPosition(Center);
int i;
float R,G,B,Vertex1[3],Vertex2[3],Vertex3[3];
COneFacet TmpFacet;
R=0.2f; G=0.8f; B=0.2f; /// 선의 색깔 지정
// R=0.0f; G=0.0f; B=0.0f; /// 선의 색깔 지정
glPushMatrix();
glTranslated(0.0, 0.0, m_view_distance);
glTranslated(m_xTranslate, m_yTranslate, 0.0);
glColor3f(1.0f, 0.0f, 1.0f);
glPushMatrix();
glRotated(m_xRotate, 1.0, 0.0, 0.0);
glRotated(m_yRotate, 0.0, 1.0, 0.0);
glRotated(m_zRotate, 0.0, 0.0, 1.0);
glDisable(GL_LINE_STIPPLE);
glLineWidth(0.5f);
glColor3f(0,0,1);
glBegin(GL_LINES);
glVertex3f((float)Center[0],(float)Center[1],(float)Center[2]+CenterLineLength);
glVertex3f((float)Center[0],(float)Center[1],(float)Center[2]);
glEnd();
glColor3f(1,0,0);
glBegin(GL_LINES);
glVertex3f((float)Center[0]+CenterLineLength,(float)Center[1],(float)Center[2]);
glVertex3f((float)Center[0],(float)Center[1],(float)Center[2]);
glEnd();
glColor3f(0,1,0);
glBegin(GL_LINES);
glVertex3f((float)Center[0],(float)Center[1]+CenterLineLength,(float)Center[2]);
glVertex3f((float)Center[0],(float)Center[1],(float)Center[2]);
glEnd();
glColor3f(R,G,B);
// 선폭 결정
glLineWidth(0.3f);
// glLineWidth(2.0f);
Nature Biotechnology: doi:10.1038/nbt.3413
for(i=0;i<NumOfLine;++i)
{
if(!pDoc->STLFile.GetFacet(TmpFacet,i)) return;
TmpFacet.GetVertex123_Float(Vertex1,Vertex2,Vertex3);
DrawTriangle(Vertex1,Vertex2,Vertex3);
}
glPopMatrix();
glPopMatrix();
}
void CSTLFileTransferView::DrawTriangle(float Point1[], float Point2[], float Point3[])
{
glBegin(GL_LINES);
glVertex3f(Point1[0],Point1[1],Point1[2]);
glVertex3f(Point2[0],Point2[1],Point2[2]);
glEnd();
glBegin(GL_LINES);
glVertex3f(Point2[0],Point2[1],Point2[2]);
glVertex3f(Point3[0],Point3[1],Point3[2]);
glEnd();
glBegin(GL_LINES);
glVertex3f(Point3[0],Point3[1],Point3[2]);
glVertex3f(Point1[0],Point1[1],Point1[2]);
glEnd();
}
BOOL CSTLFileTransferView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
// TODO: Add your message handler code here and/or call default
m_view_distance +=(double)zDelta/100.;
InvalidateRect(NULL, FALSE);
return CView::OnMouseWheel(nFlags, zDelta, pt);
}
void CSTLFileTransferView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_LButtonDown = TRUE;
m_LDownPos = point;
CView::OnLButtonDown(nFlags, point);
}
void CSTLFileTransferView::OnLButtonUp(UINT nFlags, CPoint point)
Nature Biotechnology: doi:10.1038/nbt.3413
{
// TODO: Add your message handler code here and/or call default
m_LButtonDown = FALSE;
InvalidateRect(NULL, FALSE);
CView::OnLButtonUp(nFlags, point);
}
void CSTLFileTransferView::ViewFormat3D()
{
GLdouble aspect_ratio; // width/height ratio
if ( 0>=ViewSizeX || 0>=ViewSizeY )
{
return;
}
// select the full client area
::glViewport(0,0,ViewSizeX,ViewSizeY);
// compute the aspect ratio
// this will keep all dimension scales equal
aspect_ratio=(GLdouble)ViewSizeX/(GLdouble)ViewSizeY;
// select the projection matrix and clear it
::glMatrixMode(GL_PROJECTION);
::glLoadIdentity();
// select the viewing volume
::gluPerspective(45.0f, aspect_ratio, .01f, 1000.0f);
// switch back to the modelview matrix and clear it
::glMatrixMode(GL_MODELVIEW);
::glLoadIdentity();
}
void CSTLFileTransferView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(m_LButtonDown)
{
CSize rotate = m_LDownPos - point;
m_LDownPos = point;
m_yRotate -= rotate.cx/2;
m_xRotate -= rotate.cy/2;
InvalidateRect(NULL, FALSE);
}
Nature Biotechnology: doi:10.1038/nbt.3413
if(m_RButtonDown)
{
CSize translate = m_RDownPos - point;
m_RDownPos = point;
m_xTranslate -= translate.cx/50.;
m_yTranslate += translate.cy/50.;
InvalidateRect(NULL, FALSE);
}
CView::OnMouseMove(nFlags, point);
}
void CSTLFileTransferView::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_RButtonDown = TRUE;
m_RDownPos = point;
CView::OnRButtonDown(nFlags, point);
}
void CSTLFileTransferView::OnRButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_RButtonDown = FALSE;
InvalidateRect(NULL, FALSE);
CView::OnRButtonUp(nFlags, point);
}
void CSTLFileTransferView::DrawAxis()
{
glPushMatrix();
glTranslated(-2.9f,-1.8f,-5.0f);
glRotated(m_xRotate, 1.0, 0.0, 0.0);
glRotated(m_yRotate, 0.0, 1.0, 0.0);
glColor3f(1.0f,0.0f,0.0f);
DrawArrow(1.0f,0.0f,0.0f,0.05f);
glColor3f(0.0f,1.0f,0.0f);
DrawArrow(0.0f,1.0f,0.0f,0.05f);
glColor3f(0.0f,0.0f,1.0f);
DrawArrow(0.0f,0.0f,1.0f,0.05f);
glPopMatrix();
}
Nature Biotechnology: doi:10.1038/nbt.3413
void CSTLFileTransferView::DrawArrow(float DirX, float DirY, float DirZ, float Ra)
{
float Axis[2];
float Direction[2],Angle;
glPushMatrix();
Axis[0]=1.0f;
Axis[1]=0.0f;
Direction[0]=DirX;
Direction[1]=DirY;
Angle=(float)ReturnAngle(Axis,Direction);
if(Angle>0.0f && Angle<360.0f)
glRotated( Angle, 0.0, 0.0, -1.0);
Axis[0]=0.0f;
Axis[1]=1.0f;
// Direction[0]=Direction[0]*(float)cos((double)Angle)+Direction[1]*(float)sin((double)Angle);
Direction[0]=(float)(sqrt((double)(DirX*DirX+DirY*DirY)));
Direction[1]=DirZ;
Angle=(float)ReturnAngle(Axis,Direction);
if(Angle>0.0f && Angle<360.0f)
glRotated( Angle , 0.0, 1.0, 0.0);
// glColor3f(0.0f,0.0f,1.0f);
glPushMatrix();
glTranslated(0.0f,0.0f,Ra*3);
auxSolidCone(Ra,Ra*2);
glPopMatrix();
glRotated(-90, 1.0, 0.0, 0.0);
glTranslated(0.0f,-1.0f,0.0f);
auxSolidCylinder(Ra/3.0,Ra*3.0);
glPopMatrix();
}
double CSTLFileTransferView::ReturnAngle(float TmpStart[], float TmpEnd[])
{
if((int)(TmpStart[0]*1000.0f)==(int)(TmpEnd[0]*1000.0f) && (int)(TmpStart[1]*1000.0f)==(int)(TmpEnd[1]*1000.0f) )
{
return 0.0;
}
else
{
double StartAngle,EndAngle;
StartAngle=ReturnPointAngle(TmpStart);
EndAngle=ReturnPointAngle(TmpEnd);
if(StartAngle>=EndAngle)
{
return (StartAngle-EndAngle)*180.0/3.141592;
Nature Biotechnology: doi:10.1038/nbt.3413
}
else
{
return (2.0*3.141592+StartAngle-EndAngle)*180.0/3.141592;
}
}
}
double CSTLFileTransferView::ReturnPointAngle(float Point[])
{
double TmpPoint[2];
TmpPoint[0]=(double)((int)(Point[0]*1000.0f))/1000.0;
TmpPoint[1]=(double)((int)(Point[1]*1000.0f))/1000.0;
if(TmpPoint[1]>=0)
{
return acos(TmpPoint[0]/sqrt(TmpPoint[0]*TmpPoint[0]+TmpPoint[1]*TmpPoint[1]));
}
else
{
return (2.0*3.141592-acos(TmpPoint[0]/sqrt(TmpPoint[0]*TmpPoint[0]+TmpPoint[1]*TmpPoint[1])));
}
}
void CSTLFileTransferView::RenderSceneSectionView()
{
CSTLFileTransferDoc *pDoc=GetDocument();
int NumOfCrossSection=pDoc->STLFile.GetNumOfLoops();
if(NumOfCrossSection==0) return;
int i,j,k,NumOfLine,NumOfOffsetLine,NumOfClosedLoop;
float R,G,B,R2,G2,B2,R3,G3,B3,Vertex1[2],Vertex2[2],TmpZValue;
/////////////////////////임시로 넣는것 NorVec 보기 위한 곳
// float NorVec[2],Tmp1,Tmp2;
//////////////////////////
CMultiLoops TmpLoops;
CTwoDLine TmpOneLine;
CClosedLoop TmpClosedLoop;
R=1.0f; G=0.0f; B=0.0f; // 선의 색깔 지정
// R=0.0f; G=0.0f; B=0.0f;
R2=0.0f; G2=1.0f; B2=0.0f;
R3=1.0f; G3=1.0f; B3=1.0f;
Nature Biotechnology: doi:10.1038/nbt.3413
glPushMatrix();
glTranslated(0.0, 0.0, m_view_distance);
glTranslated(m_xTranslate, m_yTranslate, 0.0);
glColor3f(1.0f, 0.0f, 1.0f);
glPushMatrix();
glRotated(m_xRotate, 1.0, 0.0, 0.0);
glRotated(m_yRotate, 0.0, 1.0, 0.0);
glLineWidth(0.3f);
// glLineWidth(2.0f);
glDisable(GL_LINE_STIPPLE);
for(i=0;i<NumOfCrossSection;++i)
{
TmpLoops=pDoc->STLFile.GetLoops(i);
TmpZValue=(float)(TmpLoops.GetZValue());
NumOfClosedLoop=TmpLoops.GetNumOfClosedLoop();
for(k=0;k<NumOfClosedLoop;k++)
{
TmpClosedLoop=TmpLoops.GetClosedLoop(k);
NumOfLine=TmpClosedLoop.GetNumOfLine();
NumOfOffsetLine=TmpClosedLoop.GetNumOfOffsetLine();
glColor3f(R,G,B);
for(j=0;j<NumOfLine;j++)
{
TmpOneLine=TmpClosedLoop.GetLine(j);
TmpOneLine.GetTwoPositionFloat(Vertex1,Vertex2);
DrawLine(Vertex1,Vertex2,TmpZValue);
}
glColor3f(R2,G2,B2);
for(j=0;j<NumOfOffsetLine;j++)
{
if( j%2 == 0)
glColor3f(R2,G2,B2);
else
glColor3f(R3,G3,B3);
TmpOneLine=TmpClosedLoop.GetOffsetLine(j);
Nature Biotechnology: doi:10.1038/nbt.3413
TmpOneLine.GetTwoPositionFloat(Vertex1,Vertex2);
DrawLine(Vertex1,Vertex2,TmpZValue);
}
}
}
glPopMatrix();
glPopMatrix();
}
void CSTLFileTransferView::DrawLine(float Point1[], float Point2[], float ZValue)
{
glBegin(GL_LINES);
glVertex3f(Point1[0],Point1[1],ZValue);
glVertex3f(Point2[0],Point2[1],ZValue);
glEnd();
}
void CSTLFileTransferView::RenderSceneBeamLine()
{
CSTLFileTransferDoc *pDoc=GetDocument();
int NumOfCrossSection=pDoc->STLFile.GetNumOfLoops();
if(NumOfCrossSection==0) return;
int i,j,k,NumOfClosedLoop,NumOfContourBeamLine,NumOfContourOffsetBeamLine,NumOfCrossBeamLine;
float R,G,B,R2,G2,B2,R3,G3,B3,Vertex1[2],Vertex2[2],TmpZValue;
CMultiLoops TmpLoops;
CTwoDLine TmpOneLine;
CClosedLoop TmpClosedLoop;
BOOL IsMaxOffsetLoop;
R=1.0f; G=1.0f; B=0.0f; // 선의 색깔 지정
R2=0.0f; G2=1.0f; B2=1.0f;
R3=1.0f; G3=0.0f; B3=1.0f;
glPushMatrix();
glTranslated(0.0, 0.0, m_view_distance);
glTranslated(m_xTranslate, m_yTranslate, 0.0);
glColor3f(1.0f, 0.0f, 1.0f);
glPushMatrix();
glRotated(m_xRotate, 1.0, 0.0, 0.0);
glRotated(m_yRotate, 0.0, 1.0, 0.0);
glLineWidth(0.3f);
glDisable(GL_LINE_STIPPLE);
Nature Biotechnology: doi:10.1038/nbt.3413
for(i=0;i<NumOfCrossSection;++i)
{
TmpLoops=pDoc->STLFile.GetLoops(i);
TmpZValue=(float)(TmpLoops.GetZValue());
NumOfClosedLoop=TmpLoops.GetNumOfClosedLoop();
for(k=0;k<NumOfClosedLoop;k++)
{
TmpClosedLoop=TmpLoops.GetClosedLoop(k);
NumOfContourBeamLine=TmpClosedLoop.GetNumOfContourBeamLine();
NumOfContourOffsetBeamLine=TmpClosedLoop.GetNumOfContourOffsetBeamLine();
NumOfCrossBeamLine=TmpClosedLoop.GetNumOfCrossBeamLine();
IsMaxOffsetLoop=TmpClosedLoop.IsMaxOffLoop();
if(IsMaxOffsetLoop)
{
glColor3f(R,G,B);
for(j=0;j<NumOfContourBeamLine;j++)
{
if(j%2==0)
glColor3f(R3,G3,B3);
else
glColor3f(R2,G2,B2);
TmpOneLine=TmpClosedLoop.GetContourBeamLine(j);
TmpOneLine.GetTwoPositionFloat(Vertex1,Vertex2);
DrawLine(Vertex1,Vertex2,TmpZValue);
}
glColor3f(R3,G3,B3);
for(j=0;j<NumOfCrossBeamLine;j++)
{
TmpOneLine=TmpClosedLoop.GetCrossBeamLine(j);
TmpOneLine.GetTwoPositionFloat(Vertex1,Vertex2);
DrawLine(Vertex1,Vertex2,TmpZValue);
}
}
Nature Biotechnology: doi:10.1038/nbt.3413
glColor3f(R2,G2,B2);
for(j=0;j<NumOfContourOffsetBeamLine;j++)
{
if(j%2==0)
glColor3f(R3,G3,B3);
else
glColor3f(R2,G2,B2);
TmpOneLine=TmpClosedLoop.GetContourOffsetBeamLine(j);
TmpOneLine.GetTwoPositionFloat(Vertex1,Vertex2);
DrawLine(Vertex1,Vertex2,TmpZValue);
}
}
}
glPopMatrix();
glPopMatrix();
}
void CSTLFileTransferView::OnZView()
{
// TODO: Add your command handler code here
m_xRotate = 0.0;
m_yRotate = 0.0;
m_zRotate = 0.0;
m_xTranslate = 0.0;
m_yTranslate = 0.0;
InvalidateRect(NULL, FALSE);
}
void CSTLFileTransferView::OnXView()
{
// TODO: Add your command handler code here
m_xRotate = 0.0;
m_yRotate = -90.0;
m_zRotate = 0.0;
m_xTranslate = 0.0;
m_yTranslate = 0.0;
InvalidateRect(NULL, FALSE);
}
void CSTLFileTransferView::OnYView()
{
// TODO: Add your command handler code here
Nature Biotechnology: doi:10.1038/nbt.3413
m_xRotate = 90.0;
m_yRotate = 0.0;
m_zRotate = 0.0;
m_xTranslate = 0.0;
m_yTranslate = 0.0;
InvalidateRect(NULL, FALSE);
}
// TwoDLine.h: interface for the CTwoDLine class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_TWODLINE_H__B5A19DE9_A29D_416F_930B_A94658FFDD36__INCLUDED_)
#define AFX_TWODLINE_H__B5A19DE9_A29D_416F_930B_A94658FFDD36__INCLUDED_
#include "Path.h" // Added by ClassView
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CTwoDLine
{
public:
double CalculationVectorCCWAngle(double Vector[2]);
void SaveOrLoad(BOOL Save, CArchive &ar);
double ReturnMinXVal();
double ReturnMaxXVal();
BOOL IsSamePositionWithVertex2(double TmpVertex[2]);
BOOL IsSamePositionWithVertex1(double TmpVertex[2]);
BOOL IsThereSamePosition(double TmpVertex[2], BOOL &IsVertex1);
void MakeYPositiveDirection();
void InverseLineDirection();
BOOL IsOnePointInnerBoxIncludeBoard(double TmpPoint[2]);
BOOL IsTwoLineOverLap(CTwoDLine TmpLine, BOOL &IsInverse);
BOOL GetXAxisJoinPositionWithLine(double JoinXPositions[2], int &JoinNum);
BOOL IsTheComparedLineConnected(CTwoDLine BeforeLine, CTwoDLine AfterLine, int &DisConnectingPos);
BOOL IsTheComparedPointConnected(double Point[2], int ConnectCheckMode);
double DistanceOfTwoPosition(double Pos1[2],double Pos2[2]);
BOOL IsTwoPositionSame(double Point1[2],double Point2[2]);
BOOL IsTheComparedLineConnected(CTwoDLine TmpLine, int ConnectCheckMode);
BOOL GetIsInsertedLine();
void SetIsInsertedLine();
BOOL IsPointBeamLine();
void GetCenterOfLine(double Center[2]);
double GetCenterYValue();
double ReturnMaxYVal();
double ReturnMinYVal();
CPath GetBeamPath(UINT Feedrate);
void GetVertex2(double TmpVertex[2]);
Nature Biotechnology: doi:10.1038/nbt.3413
double GetCenterXValue();
BOOL GetXAxisJoinPositionWithLine(double &JoinXPosition);
double GetNorVecCCWAngle();
void GetNorVec(double TmpNorVec[2]);
void LineCWRotation(double Center[2], double CWAngle);
void GetVertex1(double TmpVertex1[2]);
double GetLength();
void LineTranslation(double Distance[2]);
void PointCWRotation(double Position[], double CenterX, double CenterY, double CWAngle);
void LineCWVectorRotation(double CWAngle);
double GetLineCCWAngle();
BOOL IsOnePointInnerBox(double TmpPoint[2]);
BOOL IsPointLine();
void GetNorVecFloat(float TmpNorVec[2]);
void SetVertex2(double TmpVertex[2]);
void SetVertex1(double TmpVertex[2]);
void DoOffsetLineUsingNorVec(double OffsetValue);
void DirectionChange();
void GetTwoPosition(double TmpVer1[2],double TmpVer2[2]);
void GetTwoPositionFloat(float TmpVer1[2], float TmpVer2[2]);
BOOL InsertVertex(int VertexNum, double TmpVertex[2]);
BOOL InsertNorVec(double TmpVector[2]);
BOOL InsertOneLine(double TmpVer1[2], double TmpVer2[2], double TmpNorVec[2]);
double NorVector[2];
double Vertex1[2];
double Vertex2[2];
CTwoDLine();
virtual ~CTwoDLine();
private:
BOOL IsInsertedLine;
};
#endif // !defined(AFX_TWODLINE_H__B5A19DE9_A29D_416F_930B_A94658FFDD36__INCLUDED_)
// TwoDLine.cpp: implementation of the CTwoDLine class.
//
// TwoDLine.cpp: implementation of the CTwoDLine class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "TwoDLine.h"
#include "math.h"
#define NumErrorFindDouble 10000000.0
#define NumErrorFindInt 10000000
#define PI 3.141592653589793
Nature Biotechnology: doi:10.1038/nbt.3413
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CTwoDLine::CTwoDLine()
{
NorVector[0]=0.0;
NorVector[1]=1.0;
IsInsertedLine=false;
}
CTwoDLine::~CTwoDLine()
{
}
BOOL CTwoDLine::InsertOneLine(double TmpVer1[], double TmpVer2[], double TmpNorVec[])
{
if( InsertVertex(1,TmpVer1) * InsertVertex(2,TmpVer2) * InsertNorVec(TmpNorVec) )
{
if( IsTwoPositionSame(TmpVer1,TmpVer2) ) //두 점이 같은 점인지 확인
return false;
else
return true;
}
else
return false;
}
BOOL CTwoDLine::InsertNorVec(double TmpVector[])
{
double Length=sqrt( TmpVector[0]*TmpVector[0] + TmpVector[1]*TmpVector[1] );
if( (int)(Length*NumErrorFindDouble)==0 )
return false;
else if( (int)(Length*NumErrorFindDouble)!=NumErrorFindInt )
{
TmpVector[0]/=Length;
TmpVector[1]/=Length;
}
Nature Biotechnology: doi:10.1038/nbt.3413
NorVector[0]=TmpVector[0];
NorVector[1]=TmpVector[1];
return true;
}
BOOL CTwoDLine::InsertVertex(int VertexNum, double TmpVertex[])
{
switch (VertexNum)
{
case 1:
Vertex1[0]=TmpVertex[0];
Vertex1[1]=TmpVertex[1];
return true;
case 2:
Vertex2[0]=TmpVertex[0];
Vertex2[1]=TmpVertex[1];
return true;
default:
return false;
}
}
void CTwoDLine::GetTwoPositionFloat(float TmpVer1[], float TmpVer2[])
{
TmpVer1[0]=(float)Vertex1[0];
TmpVer1[1]=(float)Vertex1[1];
TmpVer2[0]=(float)Vertex2[0];
TmpVer2[1]=(float)Vertex2[1];
}
void CTwoDLine::GetTwoPosition(double TmpVer1[], double TmpVer2[])
{
TmpVer1[0]=Vertex1[0];
TmpVer1[1]=Vertex1[1];
TmpVer2[0]=Vertex2[0];
TmpVer2[1]=Vertex2[1];
}
void CTwoDLine::DirectionChange()
{
double TmpVer[2];
TmpVer[0]=Vertex1[0];
TmpVer[1]=Vertex1[1];
Nature Biotechnology: doi:10.1038/nbt.3413
Vertex1[0]=Vertex2[0];
Vertex1[1]=Vertex2[1];
Vertex2[0]=TmpVer[0];
Vertex2[1]=TmpVer[1];
}
void CTwoDLine::DoOffsetLineUsingNorVec(double OffsetValue)
{
Vertex1[0]+=NorVector[0]*OffsetValue;
Vertex1[1]+=NorVector[1]*OffsetValue;
Vertex2[0]+=NorVector[0]*OffsetValue;
Vertex2[1]+=NorVector[1]*OffsetValue;
}
void CTwoDLine::SetVertex1(double TmpVertex[])
{
Vertex1[0]=TmpVertex[0];
Vertex1[1]=TmpVertex[1];
}
void CTwoDLine::SetVertex2(double TmpVertex[])
{
Vertex2[0]=TmpVertex[0];
Vertex2[1]=TmpVertex[1];
}
void CTwoDLine::GetNorVecFloat(float TmpNorVec[])
{
TmpNorVec[0]=(float)NorVector[0];
TmpNorVec[1]=(float)NorVector[1];
}
BOOL CTwoDLine::IsPointLine()
{
if( (int)(Vertex1[0]*NumErrorFindDouble) == (int)(Vertex2[0]*NumErrorFindDouble)
&& (int)(Vertex1[1]*NumErrorFindDouble) == (int)(Vertex2[1]*NumErrorFindDouble) )
return true;
else
return false;
}
BOOL CTwoDLine::IsOnePointInnerBox(double TmpPoint[])
{
double RightX,LeftX,UpperY,LowerY;
Nature Biotechnology: doi:10.1038/nbt.3413
if(Vertex1[0]>Vertex2[0])
{
RightX=Vertex1[0]; LeftX=Vertex2[0];
}
else
{
RightX=Vertex2[0]; LeftX=Vertex1[0];
}
if(Vertex1[1]>Vertex2[1])
{
UpperY=Vertex1[1]; LowerY=Vertex2[1];
}
else
{
UpperY=Vertex2[1]; LowerY=Vertex1[1];
}
if( (int)(RightX*NumErrorFindDouble) == (int)(LeftX*NumErrorFindDouble) )
{
if( ( (int)(TmpPoint[0]*NumErrorFindDouble) == (int)(RightX*NumErrorFindDouble) ) &&
(TmpPoint[1]<UpperY && TmpPoint[1]>LowerY) )
return true;
}
if( (int)(UpperY*NumErrorFindDouble) == (int)(LowerY*NumErrorFindDouble) )
{
if( ( (int)(TmpPoint[1]*NumErrorFindDouble) == (int)(UpperY*NumErrorFindDouble) ) &&
(TmpPoint[0]<RightX && TmpPoint[0]>LeftX) )
return true;
}
if( TmpPoint[0]<RightX && TmpPoint[0]>LeftX
&& TmpPoint[1]<UpperY && TmpPoint[1]>LowerY )
return true;
else
return false;
}
double CTwoDLine::GetLineCCWAngle()
{
double TmpPoint[2];
TmpPoint[0]=Vertex2[0]-Vertex1[0];
TmpPoint[1]=Vertex2[1]-Vertex1[1];
return CalculationVectorCCWAngle(TmpPoint);
}
Nature Biotechnology: doi:10.1038/nbt.3413
void CTwoDLine::LineCWVectorRotation(double CWAngle)
{
PointCWRotation(Vertex2,Vertex1[0],Vertex1[1],CWAngle);
PointCWRotation(NorVector,0.0,0.0,CWAngle);
}
void CTwoDLine::PointCWRotation(double Position[], double CenterX, double CenterY, double CWAngle)
{
double Angle=CWAngle;
Position[0]-=CenterX;
Position[1]-=CenterY;
double Tmp0=Position[0];
double Tmp1=Position[1];
Position[0]=Tmp0*cos(Angle)+Tmp1*sin(Angle);
Position[1]=Tmp1*cos(Angle)-Tmp0*sin(Angle);
Position[0]+=CenterX;
Position[1]+=CenterY;
}
void CTwoDLine::LineTranslation(double Distance[])
{
Vertex1[0]+=Distance[0];
Vertex1[1]+=Distance[1];
Vertex2[0]+=Distance[0];
Vertex2[1]+=Distance[1];
}
double CTwoDLine::GetLength()
{
return DistanceOfTwoPosition(Vertex1,Vertex2);
}
void CTwoDLine::GetVertex1(double TmpVertex1[])
{
TmpVertex1[0]=Vertex1[0];
TmpVertex1[1]=Vertex1[1];
}
void CTwoDLine::LineCWRotation(double Center[], double CWAngle)
{
PointCWRotation(Vertex1,Center[0],Center[1],CWAngle);
PointCWRotation(Vertex2,Center[0],Center[1],CWAngle);
PointCWRotation(NorVector,0.0,0.0,CWAngle);
Nature Biotechnology: doi:10.1038/nbt.3413
}
void CTwoDLine::GetNorVec(double TmpNorVec[])
{
TmpNorVec[0]=NorVector[0];
TmpNorVec[1]=NorVector[1];
}
double CTwoDLine::GetNorVecCCWAngle()
{
return CalculationVectorCCWAngle(NorVector);
}
double CTwoDLine::CalculationVectorCCWAngle(double Vector[])
{
double Angle,TmpPoint[2];
TmpPoint[0]=Vector[0];
TmpPoint[1]=Vector[1];
double Length=sqrt(TmpPoint[0]*TmpPoint[0]+TmpPoint[1]*TmpPoint[1]);
if(Length<=0.0)
return -1.0;
if(TmpPoint[1]>=0)
{
Angle=acos(TmpPoint[0]/Length);
}
else
{
Angle=(2.0*PI-acos(TmpPoint[0]/Length));
}
return Angle;
}
BOOL CTwoDLine::GetXAxisJoinPositionWithLine(double &JoinXPosition)
{
if( (Vertex1[1]>0.0 && Vertex2[1]>0.0) || (Vertex1[1]<0.0 && Vertex2[1]<0.0) )
return false;
double LineVector[2],LineLength;
LineLength=GetLength();
if( (int)(LineLength*NumErrorFindDouble) == 0 )
return false;
Nature Biotechnology: doi:10.1038/nbt.3413
LineVector[0]=( Vertex2[0]-Vertex1[0] ) / LineLength;
LineVector[1]=( Vertex2[1]-Vertex1[1] ) / LineLength;
if( (int)(LineVector[1]*NumErrorFindDouble) == 0 )
{
if( (int)(Vertex1[1]*NumErrorFindDouble) == 0 )
{
JoinXPosition=Vertex1[0];
return true;
}
else
return false;
}
JoinXPosition=Vertex1[0]-LineVector[0]*Vertex1[1]/LineVector[1];
return true;
}
double CTwoDLine::GetCenterXValue()
{
return ( Vertex1[0]+Vertex2[0] ) / 2.0 ;
}
void CTwoDLine::GetVertex2(double TmpVertex[])
{
TmpVertex[0]=Vertex2[0];
TmpVertex[1]=Vertex2[1];
}
CPath CTwoDLine::GetBeamPath(UINT Feedrate)
{
CPath BeamPath;
float Start[2],End[2];
Start[0]=(float)Vertex1[0];
Start[1]=(float)Vertex1[1];
End[0]=(float)Vertex2[0];
End[1]=(float)Vertex2[1];
BeamPath.SetLineValue(true,Start,End,Feedrate);
return BeamPath;
}
double CTwoDLine::ReturnMinYVal()
{
Nature Biotechnology: doi:10.1038/nbt.3413
if(Vertex1[1]<Vertex2[1])
return Vertex1[1];
else
return Vertex2[1];
}
double CTwoDLine::ReturnMaxYVal()
{
if(Vertex1[1]>Vertex2[1])
return Vertex1[1];
else
return Vertex2[1];
}
double CTwoDLine::GetCenterYValue()
{
return ( Vertex1[1]+Vertex2[1] ) / 2.0 ;
}
void CTwoDLine::GetCenterOfLine(double Center[])
{
Center[0]=GetCenterXValue();
Center[1]=GetCenterYValue();
}
BOOL CTwoDLine::IsPointBeamLine()
{
if( (int)(Vertex1[0]*1000.0) == (int)(Vertex2[0]*1000.0)
&& (int)(Vertex1[1]*1000.0) == (int)(Vertex2[1]*1000.0) )
return true;
else
return false;
}
void CTwoDLine::SetIsInsertedLine()
{
IsInsertedLine=true;
}
BOOL CTwoDLine::GetIsInsertedLine()
{
return IsInsertedLine;
}
BOOL CTwoDLine::IsTheComparedLineConnected(CTwoDLine TmpLine, int ConnectCheckMode)
{
double TmpVertex1[2],TmpVertex2[2];
TmpLine.GetTwoPosition(TmpVertex1,TmpVertex2);
Nature Biotechnology: doi:10.1038/nbt.3413
switch ( ConnectCheckMode )
{
case 21 :
if( IsTwoPositionSame(Vertex2,TmpVertex1) )
return true;
else
return false;
case 22 :
if( IsTwoPositionSame(Vertex2,TmpVertex2) )
return true;
else
return false;
case 12 :
if( IsTwoPositionSame(Vertex1,TmpVertex2) )
return true;
else
return false;
case 11 :
if( IsTwoPositionSame(Vertex1,TmpVertex1) )
return true;
else
return false;
default :
return false;
}
}
BOOL CTwoDLine::IsTwoPositionSame(double Point1[], double Point2[])
{
if( ((int)(Point1[0]*NumErrorFindDouble)==(int)(Point2[0]*NumErrorFindDouble))
&& ((int)(Point1[1]*NumErrorFindDouble)==(int)(Point2[1]*NumErrorFindDouble)) )
return true;
else
return false;
}
double CTwoDLine::DistanceOfTwoPosition(double Pos1[], double Pos2[])
{
return sqrt( (Pos2[0]-Pos1[0])*(Pos2[0]-Pos1[0])+(Pos2[1]-Pos1[1])*(Pos2[1]-Pos1[1]) );
}
BOOL CTwoDLine::IsTheComparedPointConnected(double Point[], int ConnectCheckMode)
{
switch ( ConnectCheckMode )
{
case 1 :
if( IsTwoPositionSame(Vertex1,Point) )
Nature Biotechnology: doi:10.1038/nbt.3413
return true;
case 2 :
if( IsTwoPositionSame(Vertex2,Point) )
return true;
default :
return false;
}
}
BOOL CTwoDLine::IsTheComparedLineConnected(CTwoDLine BeforeLine, CTwoDLine AfterLine, int &DisConnectingPos)
{
BOOL BeforeConnect,AfterConnect;
BeforeConnect=IsTheComparedLineConnected(BeforeLine,12);
AfterConnect=IsTheComparedLineConnected(AfterLine,21);
if( BeforeConnect*AfterConnect )
return true;
else if( BeforeConnect && !AfterConnect )
{
DisConnectingPos=2;
return false;
}
else if( !BeforeConnect && AfterConnect )
{
DisConnectingPos=1;
return false;
}
else
{
DisConnectingPos=3;
return false;
}
}
BOOL CTwoDLine::GetXAxisJoinPositionWithLine(double JoinXPositions[], int &JoinNum)
{
if( (Vertex1[1]>0.0 && Vertex2[1]>0.0) || (Vertex1[1]<0.0 && Vertex2[1]<0.0) )
return false;
double LineVector[2],LineLength;
LineLength=GetLength();
if( (int)(LineLength*NumErrorFindDouble) == 0 )
return false;
Nature Biotechnology: doi:10.1038/nbt.3413
LineVector[0]=( Vertex2[0]-Vertex1[0] ) / LineLength;
LineVector[1]=( Vertex2[1]-Vertex1[1] ) / LineLength;
if( (int)(Vertex1[1]*NumErrorFindDouble) == 0 && (int)(Vertex2[1]*NumErrorFindDouble) == 0 )
{
JoinXPositions[0]=Vertex1[0];
JoinXPositions[1]=Vertex2[0];
JoinNum=2;
return true;
}
if( (int)(Vertex1[1]*NumErrorFindDouble) == 0 )
{
JoinXPositions[0]=Vertex1[0];
JoinNum=1;
return true;
}
if( (int)(Vertex2[1]*NumErrorFindDouble) == 0 )
{
JoinXPositions[0]=Vertex2[0];
JoinNum=1;
return true;
}
JoinXPositions[0]=Vertex1[0]-LineVector[0]*Vertex1[1]/LineVector[1];
JoinNum=1;
return true;
}
BOOL CTwoDLine::IsTwoLineOverLap(CTwoDLine TmpLine, BOOL &IsInverse)
{
double TmpVer1[2],TmpVer2[2];
TmpLine.GetTwoPosition(TmpVer1,TmpVer2);
if( IsTwoPositionSame(Vertex2,TmpVer1) && IsTwoPositionSame(Vertex1,TmpVer2) )
{
IsInverse=true;
return true;
}
if( IsTwoPositionSame(Vertex1,TmpVer1) && IsTwoPositionSame(Vertex2,TmpVer2) )
{
IsInverse=false;
Nature Biotechnology: doi:10.1038/nbt.3413
return true;
}
return false;
}
BOOL CTwoDLine::IsOnePointInnerBoxIncludeBoard(double TmpPoint[])
{
double RightX,LeftX,UpperY,LowerY;
if(Vertex1[0]>Vertex2[0])
{
RightX=Vertex1[0]; LeftX=Vertex2[0];
}
else
{
RightX=Vertex2[0]; LeftX=Vertex1[0];
}
if(Vertex1[1]>Vertex2[1])
{
UpperY=Vertex1[1]; LowerY=Vertex2[1];
}
else
{
UpperY=Vertex2[1]; LowerY=Vertex1[1];
}
if( TmpPoint[0]<=RightX && TmpPoint[0]>=LeftX
&& TmpPoint[1]<=UpperY && TmpPoint[1]>=LowerY )
return true;
else
return false;
}
void CTwoDLine::InverseLineDirection()
{
double TmpVertex1[2];
TmpVertex1[0]=Vertex1[0];
TmpVertex1[1]=Vertex1[1];
Vertex1[0]=Vertex2[0];
Vertex1[1]=Vertex2[1];
Vertex2[0]=TmpVertex1[0];
Vertex2[1]=TmpVertex1[1];
}
void CTwoDLine::MakeYPositiveDirection()
Nature Biotechnology: doi:10.1038/nbt.3413
{
if(Vertex1[1]>Vertex2[1])
InverseLineDirection();
}
BOOL CTwoDLine::IsThereSamePosition(double TmpVertex[], BOOL &IsVertex1)
{
if( IsTwoPositionSame(TmpVertex,Vertex1) )
{
IsVertex1=true;
return true;
}
else if( IsTwoPositionSame(TmpVertex,Vertex2) )
{
IsVertex1=false;
return true;
}
else
return false;
}
BOOL CTwoDLine::IsSamePositionWithVertex1(double TmpVertex[])
{
if( IsTwoPositionSame(TmpVertex,Vertex1) )
return true;
else
return false;
}
BOOL CTwoDLine::IsSamePositionWithVertex2(double TmpVertex[])
{
if( IsTwoPositionSame(TmpVertex,Vertex2) )
return true;
else
return false;
}
double CTwoDLine::ReturnMaxXVal()
{
if(Vertex1[0]>Vertex2[0])
return Vertex1[0];
else
return Vertex2[0];
}
double CTwoDLine::ReturnMinXVal()
{
if(Vertex1[0]<Vertex2[0])
Nature Biotechnology: doi:10.1038/nbt.3413
return Vertex1[0];
else
return Vertex2[0];
}
void CTwoDLine::SaveOrLoad(BOOL Save, CArchive &ar)
{
if(Save)
{
ar<<IsInsertedLine;
ar<<NorVector[0]<<NorVector[1];
ar<<Vertex1[0]<<Vertex1[1];
ar<<Vertex2[0]<<Vertex2[1];
}
else
{
ar>>IsInsertedLine;
ar>>NorVector[0]>>NorVector[1];
ar>>Vertex1[0]>>Vertex1[1];
ar>>Vertex2[0]>>Vertex2[1];
}
}#if !defined(AFX_STLFILEROTATION_H__D106A9E5_2EFA_43C2_8887_F0C0A118D0CE__INCLUDED_)
#define AFX_STLFILEROTATION_H__D106A9E5_2EFA_43C2_8887_F0C0A118D0CE__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// STLFileRotation.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// STLFileRotation dialog
class CSTLFileRotation : public CDialog
{
// Construction
public:
double GetCCWRotationAngle();
int GetRotationAxisNum();
CSTLFileRotation(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(STLFileRotation)
enum { IDD = IDD_ROT };
double m_RotationCCWAngle;
int m_RotationAxis;
Nature Biotechnology: doi:10.1038/nbt.3413
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(STLFileRotation)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(STLFileRotation)
// NOTE: the ClassWizard will add member functions here
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STLFILEROTATION_H__D106A9E5_2EFA_43C2_8887_F0C0A118D0CE__INCLUDED_)
// STLFileRotation.cpp : implementation file
//
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "STLFileRotation.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// STLFileRotation dialog
CSTLFileRotation::CSTLFileRotation(CWnd* pParent /*=NULL*/)
: CDialog(CSTLFileRotation::IDD, pParent)
{
//{{AFX_DATA_INIT(STLFileRotation)
m_RotationCCWAngle = 0.0;
m_RotationAxis = 0;
//}}AFX_DATA_INIT
Nature Biotechnology: doi:10.1038/nbt.3413
}
void CSTLFileRotation::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(STLFileRotation)
DDX_Text(pDX, IDC_MAGFAC, m_RotationCCWAngle);
DDX_Radio(pDX, IDC_ROTXAXIS, m_RotationAxis);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSTLFileRotation, CDialog)
//{{AFX_MSG_MAP(STLFileRotation)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// STLFileRotation message handlers
int CSTLFileRotation::GetRotationAxisNum()
{
//x축 : 1, Y축 : 2, Z축 : 3
return m_RotationAxis+1;
}
double CSTLFileRotation::GetCCWRotationAngle()
{
if( (m_RotationAxis+1) == 2 )
return m_RotationCCWAngle*-1.0;
else
return m_RotationCCWAngle;
}
// RotAndMagDialog.h : header file
//
#include "STLFileTransferDoc.h"
/////////////////////////////////////////////////////////////////////////////
// CRotAndMagDialog dialog
class CRotAndMagDialog : public CDialog
{
// Construction
public:
CRotAndMagDialog(CSTLFileTransferDoc* TmppDoc, CWnd* pParent = NULL); // standard constructor
Nature Biotechnology: doi:10.1038/nbt.3413
// Dialog Data
//{{AFX_DATA(CRotAndMagDialog)
enum { IDD = IDD_ROTMAG };
int m_SelectRotAxis;
int m_SelectRotAng;
double m_MagFactor;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CRotAndMagDialog)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CRotAndMagDialog)
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
CSTLFileTransferDoc* pDoc;
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_ROTANDMAGDIALOG_H__60584E15_C6DA_468D_8980_D404BA6E8C6E__INCLUDED_)
// RotAndMagDialog.cpp : implementation file
//
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "RotAndMagDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRotAndMagDialog dialog
Nature Biotechnology: doi:10.1038/nbt.3413
CRotAndMagDialog::CRotAndMagDialog(CSTLFileTransferDoc* TmppDoc,CWnd* pParent /*=NULL*/)
: CDialog(CRotAndMagDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CRotAndMagDialog)
pDoc=TmppDoc;
m_SelectRotAxis = TmppDoc->RotationAxisNum-1;
m_SelectRotAng = TmppDoc->RotationIsPositive-1;
m_MagFactor = TmppDoc->DataMagnificationFactor;
//}}AFX_DATA_INIT
}
void CRotAndMagDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRotAndMagDialog)
DDX_Radio(pDX, IDC_ROTXAXIS, m_SelectRotAxis);
DDX_Radio(pDX, IDC_ROTPLUSANGLE, m_SelectRotAng);
DDX_Text(pDX, IDC_MAGFAC, m_MagFactor);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRotAndMagDialog, CDialog)
//{{AFX_MSG_MAP(CRotAndMagDialog)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRotAndMagDialog message handlers
void CRotAndMagDialog::OnOK()
{
// TODO: Add extra validation here
UpdateData(true);
pDoc->RotationAxisNum = m_SelectRotAxis+1;
pDoc->RotationIsPositive = m_SelectRotAng+1;
pDoc->DataMagnificationFactor = m_MagFactor;
CDialog::OnOK();
}
#if !defined(AFX_RANGESLICE_H__7A8ACE59_7355_4E34_9506_F59BC77060EF__INCLUDED_)
#define AFX_RANGESLICE_H__7A8ACE59_7355_4E34_9506_F59BC77060EF__INCLUDED_
#if _MSC_VER > 1000
#pragma once
Nature Biotechnology: doi:10.1038/nbt.3413
#endif // _MSC_VER > 1000
// RangeSlice.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CRangeSlice dialog
class CRangeSlice : public CDialog
{
// Construction
public:
CRangeSlice(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CRangeSlice)
enum { IDD = IDD_RANGESLICE };
double m_LayerThickness;
double m_RangeFrom;
double m_RangeTo;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CRangeSlice)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CRangeSlice)
// NOTE: the ClassWizard will add member functions here
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_RANGESLICE_H__7A8ACE59_7355_4E34_9506_F59BC77060EF__INCLUDED_)
// RangeSlice.cpp : implementation file
//
#include "stdafx.h"
#include "STLFileTransfer.h"
Nature Biotechnology: doi:10.1038/nbt.3413
#include "RangeSlice.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRangeSlice dialog
CRangeSlice::CRangeSlice(CWnd* pParent /*=NULL*/)
: CDialog(CRangeSlice::IDD, pParent)
{
//{{AFX_DATA_INIT(CRangeSlice)
m_LayerThickness = 0.0;
m_RangeFrom = 0.0;
m_RangeTo = 0.0;
//}}AFX_DATA_INIT
}
void CRangeSlice::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRangeSlice)
DDX_Text(pDX, IDC_EDIT1, m_LayerThickness);
DDX_Text(pDX, IDC_EDIT2, m_RangeFrom);
DDX_Text(pDX, IDC_EDIT3, m_RangeTo);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRangeSlice, CDialog)
//{{AFX_MSG_MAP(CRangeSlice)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRangeSlice message handlers
#if !defined(AFX_PROGRESSBAR_H__5FB385E1_E412_11D1_994B_444553540000__INCLUDED_)
#define AFX_PROGRESSBAR_H__5FB385E1_E412_11D1_994B_444553540000__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
Nature Biotechnology: doi:10.1038/nbt.3413
// ProgressBar.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CProgressBar command target
class CProgressBar: public CProgressCtrl
{
DECLARE_DYNCREATE(CProgressBar)
public:
CProgressBar();
CProgressBar(LPCTSTR strMessage, int TmpNumOfCal, int nSize=100, int MaxValue=100);
~CProgressBar();
BOOL Create(LPCTSTR strMessage, int nSize=100, int MaxValue=100);
// operations
public:
void ExpressResidue();
void ProgressBarExpress();
void SetText(LPCTSTR strMessage);
void Clear();
// Overrides
//{{AFX_VIRTUAL(CProgressBar)
//}}AFX_VIRTUAL
// implementation
protected:
int m_nSize;
CString m_strMessage;
CRect m_Rect;
CStatusBar *GetStatusBar();
void Resize();
// Generated message map functions
protected:
//{{AFX_MSG(CProgressBar)
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
int CumulatedHit;
double OneOfHundredofNumOfCalDoubleValue;
int BarStepNum;
int CalledNum;
int OneOfHundredofNumOfCal;
int NumOfCal;
Nature Biotechnology: doi:10.1038/nbt.3413
};
#endif
/////////////////////////////////////////////////////////////////////////////
// ProgressBar.cpp : implementation file
#include "stdafx.h"
#include "ProgressBar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
IMPLEMENT_DYNCREATE(CProgressBar, CProgressCtrl)
BEGIN_MESSAGE_MAP(CProgressBar, CProgressCtrl)
//{{AFX_MSG_MAP(CProgressBar)
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CProgressBar::CProgressBar()
{
m_Rect.SetRect(0,0,0,0);
}
CProgressBar::CProgressBar(LPCTSTR strMessage, int TmpNumOfCal, int nSize, int MaxValue)
{
NumOfCal=TmpNumOfCal;
CumulatedHit=0;
OneOfHundredofNumOfCalDoubleValue=(double)(NumOfCal)/100.0;
CalledNum=0;
BarStepNum=0;
Create(strMessage, nSize, MaxValue);
}
CProgressBar::~CProgressBar()
{
Clear();
}
Nature Biotechnology: doi:10.1038/nbt.3413
CStatusBar* CProgressBar::GetStatusBar()
{
CFrameWnd *pFrame = (CFrameWnd*)AfxGetMainWnd();
if (!pFrame || !pFrame->IsKindOf(RUNTIME_CLASS(CFrameWnd)))
return NULL;
CStatusBar* pBar = (CStatusBar*) pFrame->GetMessageBar();
if (!pBar || !pBar->IsKindOf(RUNTIME_CLASS(CStatusBar)))
return NULL;
return pBar;
}
BOOL CProgressBar::Create(LPCTSTR strMessage, int nSize, int MaxValue)
{
CStatusBar *pStatusBar = GetStatusBar();
if (!pStatusBar) return FALSE;
if(!CProgressCtrl::Create(WS_CHILD|WS_VISIBLE, CRect(0,0,0,0),
pStatusBar, 1)) return FALSE;
SetRange(0, MaxValue);
SetStep(1);
m_strMessage = strMessage;
m_nSize = nSize;
Resize();
return TRUE;
}
void CProgressBar::Clear()
{
ModifyStyle(WS_VISIBLE, 0);
CString str;
str.LoadString(AFX_IDS_IDLEMESSAGE);
CStatusBar *pStatusBar = GetStatusBar();
if (pStatusBar) pStatusBar->SetWindowText(str);
}
void CProgressBar::SetText(LPCTSTR strMessage)
{
m_strMessage = strMessage;
Resize();
}
Nature Biotechnology: doi:10.1038/nbt.3413
void CProgressBar::Resize()
{
CStatusBar *pStatusBar = GetStatusBar();
if (!pStatusBar) return;
if (::IsWindow(m_hWnd) && IsWindowVisible()) {
pStatusBar->SetWindowText(m_strMessage);
pStatusBar->UpdateWindow();
}
CClientDC dc(pStatusBar);
CFont *pOldFont = dc.SelectObject(pStatusBar->GetFont());
CSize size = dc.GetTextExtent(m_strMessage);
int margin = dc.GetTextExtent(_T(" ")).cx * 2;
dc.SelectObject(pOldFont);
CRect rc;
pStatusBar->GetItemRect (0, rc);
rc.left = size.cx + 2*margin;
rc.right = rc.left + (rc.right - rc.left) * m_nSize / 100;
if (rc.right < rc.left) rc.right = rc.left;
int Height = rc.bottom - rc.top;
rc.bottom -= Height/10;
rc.top += Height/10;
if (::IsWindow(m_hWnd) && (rc != m_Rect))
MoveWindow(&rc);
m_Rect = rc;
}
BOOL CProgressBar::OnEraseBkgnd(CDC* pDC)
{
Resize();
return CProgressCtrl::OnEraseBkgnd(pDC);
}
void CProgressBar::ProgressBarExpress()
{
int TmpCumulatedHit=(int)((double)CalledNum/OneOfHundredofNumOfCalDoubleValue+0.5);
if( CumulatedHit<TmpCumulatedHit && CalledNum!=0 )
{
CumulatedHit=TmpCumulatedHit;
StepIt();
++BarStepNum;
}
Nature Biotechnology: doi:10.1038/nbt.3413
++CalledNum;
if(CalledNum==NumOfCal)
ExpressResidue();
}
void CProgressBar::ExpressResidue()
{
for(int i=BarStepNum; i<100; i++)
{
StepIt();
Sleep(0);
}
}
// Product.h: interface for the CProduct class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_PRODUCT_H__5FFAE1B3_D2F0_436D_B47A_D9B364A4893F__INCLUDED_)
#define AFX_PRODUCT_H__5FFAE1B3_D2F0_436D_B47A_D9B364A4893F__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Layer.h"
#include "Gate.h"
class CProduct : public CLayer
{
public:
double ExportFDM(CString &Code,UINT DwellingTimeBeforeOn,UINT DrawingFeedPer);
void OutputFile_ForNewport(CString FileName, CString Code, double Time, int Num);
BOOL ExportOrNot(CString Code);
float TransratFeedrateToNewportScale(int Feedrate);
double ExportNewport(CString &Code,UINT DwellingTimeBeforeOn,UINT DrawingFeedPer);
void InputGate(CGate TmpGate);
void CriterionFeedrate(BOOL Draw,UINT OldFeed,UINT NewFeed);
void MakeGatePipe(float Radius, float Length);
void MakeVPipe(float Width,float Length,float Height);
void MakeHPipe(float Width, float Height, float Length );
void InputJointGate(int Type,float Width,float Length,float Height, float Step);
void MakeJoint(int Type,float Width,float Length,float Height,float TopHole,float BottomHole);
void DoMoveOptimize();
CString GetName();
void SetName(CString TmpName);
Nature Biotechnology: doi:10.1038/nbt.3413
CString Name;
BOOL ChangePower(UINT ChangedPower);
void ReturnMinAndMaxYValue(float MinMax[2]);
void ReturnMinAndMaxXValue(float MinMax[2]);
void InverseLayer();
void Translation(UINT Num1, UINT Num2, float TransX, float TransY,float TransZ);
void SetZValue(float Z);
float GetZValue();
UINT GetDwellingTime2();
void ReplaceGate(UINT GateNum,BOOL Circle,float Pos[3],float Unit[3],float Radius,float Length[2]);
CGate GetGate(UINT GateNum);
UINT ReturnNumOfGate();
void DeleteGate(UINT GateNum);
void InputGate(BOOL Circle,float TmpPos[3],float TmpUnitVector[3],float Radius,float Length[2]);
UINT GetUpFeedrate();
UINT GetDownFeedrate();
double ExportAerotec(CString &Code,UINT DwellingTimeBeforeOn,UINT DrawingFeedPer);
BOOL IsAnyPathPoint();
BOOL IsZeroLayer();
BOOL IsOutOfRange(float Range);
BOOL IsAnyFeedrateZero();
BOOL IsAllPathLinked();
BOOL OptimizeProduct();
CLayer ReturnLastLayer();
void ProductSaveOrLoad(BOOL Save, CArchive& ar);
void InitializeProduct();
float GetDownDepth();
UINT GetDwellingTime();
UINT GetPower();
void SetPower(UINT Pow);
void Translation(UINT Num1,UINT Num2,float TransX,float TransY);
void Rotation(UINT Num1,UINT Num2,float CenterX,float CenterY,double CWAngle);
void SetZCode(float Down, UINT Time,UINT DownFeed,UINT UpFeed,UINT Time2);
CLayer ReturnLayer(UINT LayerNum);
BOOL ReplaceLayer(UINT LayerNum, CLayer TmpLayer);
float ReturnAbsZValue(UINT LayerNum);
void EraseLayer(UINT LayerNum1, UINT LayerNUM2);
void EraseLayer(UINT LayerNum);
void InsertLayer(UINT BehindLayerNum, CLayer TmpLayer);
UINT ReturnNumOfLayer();
void PopBack();
void PushBackLayer(CLayer TmpLayer);
CProduct();
virtual ~CProduct();
private:
float ZValue;
UINT DwellingTime2;
UINT UpFeedrate;
Nature Biotechnology: doi:10.1038/nbt.3413
UINT DownFeedrate;
UINT Power;
float DownDepth;
UINT DwellingTime;
std::vector<CLayer> Layer;
std::vector<CGate> Gate;
};
#endif // !defined(AFX_PRODUCT_H__5FFAE1B3_D2F0_436D_B47A_D9B364A4893F__INCLUDED_)
// Product.cpp: implementation of the CProduct class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "Product.h"
#include "Gate.h"
#include "math.h"
#include "MoveOptimize.h"
#include "fstream.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CProduct::CProduct()
{
DwellingTime=7;
DwellingTime2=10;
DownDepth=3.000f;
Power=100;
UpFeedrate=5;
DownFeedrate=5;
ZValue=0.0f;
}
CProduct::~CProduct()
{
Layer.clear();
}
void CProduct::PushBackLayer(CLayer TmpLayer)
Nature Biotechnology: doi:10.1038/nbt.3413
{
if( TmpLayer.ReturnNumOfPath() > 0)
Layer.push_back(TmpLayer);
}
void CProduct::PopBack()
{
if(Layer.size()!=0)
{
Layer.pop_back();
}
}
UINT CProduct::ReturnNumOfLayer()
{
return Layer.size();
}
void CProduct::InsertLayer(UINT BehindLayerNum, CLayer TmpLayer)
{
if(TmpLayer.ReturnNumOfPath() > 0)
Layer.insert(&Layer.at(BehindLayerNum-1),TmpLayer);
}
void CProduct::EraseLayer(UINT LayerNum)
{
if(LayerNum>0 && Layer.size()!=0 && LayerNum<=Layer.size())
{
--LayerNum;
Layer.erase(&Layer.at(LayerNum));
}
}
void CProduct::EraseLayer(UINT LayerNum1, UINT LayerNum2)
{
if(LayerNum1>0 && Layer.size()!=0 && LayerNum2>=LayerNum1 && LayerNum2<=Layer.size())
{
--LayerNum1;
--LayerNum2;
Layer.erase(&Layer.at(LayerNum1),&Layer.at(LayerNum2));
}
else
{
AfxMessageBox("Layer Number Error");
}
}
Nature Biotechnology: doi:10.1038/nbt.3413
float CProduct::ReturnAbsZValue(UINT LayerNum)
{
float AbsZValue=ZValue;
if( LayerNum>0 && LayerNum<=Layer.size() )
{
for(int i=0;i<LayerNum;++i)
{
AbsZValue+=Layer[i].GetLayerThickness();
}
return AbsZValue;
}
else
return 0.0f;
}
BOOL CProduct::ReplaceLayer(UINT LayerNum, CLayer TmpLayer)
{
if(LayerNum>Layer.size() || TmpLayer.ReturnNumOfPath() <= 0)
{
return false;
}
else
{
Layer[--LayerNum]=TmpLayer;
return true;
}
}
CLayer CProduct::ReturnLayer(UINT LayerNum)
{
if(LayerNum>Layer.size() || LayerNum==0 )
{
AfxMessageBox("Over Range");
exit(-1);
}
return Layer[LayerNum-1];
}
void CProduct::SetZCode(float Down, UINT Time,UINT DownFeed,UINT UpFeed, UINT Time2)
{
DownDepth=Down;
DwellingTime=Time;
DownFeedrate=DownFeed;
UpFeedrate=UpFeed;
DwellingTime2=Time2;
}
Nature Biotechnology: doi:10.1038/nbt.3413
void CProduct::Rotation(UINT Num1, UINT Num2, float CenterX, float CenterY, double CWAngle)
{
if( Num1<0 || Num1>Num2 || Num1>Layer.size() || Layer.size()<1 )
return;
if(Num2>Layer.size())
Num2=Layer.size();
for(UINT i=Num1;i<=Num2;++i)
Layer[i-1].Rotation(CenterX,CenterY,CWAngle);
if(Num1==1 && Num2>=Layer.size() )
{
float Pos[3],Unit[3];
double Angle=CWAngle*3.141592/180.0;
float Tmp0,Tmp1,UTmp0,UTmp1;
for(i=0;i<Gate.size();++i)
{
Gate[i].GetPosition(Pos);
Gate[i].GetUnitVector(Unit);
Pos[0]-=CenterX;
Pos[1]-=CenterY;
Tmp0=Pos[0];
Tmp1=Pos[1];
UTmp0=Unit[0];
UTmp1=Unit[1];
Pos[0]=Tmp0*(float)cos(Angle)+Tmp1*(float)sin(Angle);
Pos[1]=Tmp1*(float)cos(Angle)-Tmp0*(float)sin(Angle);
Unit[0]=UTmp0*(float)cos(Angle)+UTmp1*(float)sin(Angle);
Unit[1]=UTmp1*(float)cos(Angle)-UTmp0*(float)sin(Angle);
Pos[0]+=CenterX;
Pos[1]+=CenterY;
Gate[i].SetPosition(Pos[0],Pos[1],Pos[2]);
Gate[i].SetUnitVector(Unit[0],Unit[1],Unit[2]);
}
}
}
void CProduct::Translation(UINT Num1, UINT Num2, float TransX, float TransY)
{
if( Num1<0 || Num1>Num2 || Num1>Layer.size() || Layer.size()<1 )
Nature Biotechnology: doi:10.1038/nbt.3413
return;
if(Num2>Layer.size())
Num2=Layer.size();
for(UINT i=Num1;i<=Num2;++i)
Layer[i-1].Translation(TransX,TransY);
float Pos[3];
for(i=0;i<Gate.size();++i)
{
Gate[i].GetPosition(Pos);
Pos[0]+=TransX;
Pos[1]+=TransY;
Gate[i].SetPosition(Pos[0],Pos[1],Pos[2]);
}
}
void CProduct::SetPower(UINT Pow)
{
if(Pow<1)
return;
Power=Pow;
}
UINT CProduct::GetPower()
{
return Power;
}
UINT CProduct::GetDwellingTime()
{
return DwellingTime;
}
float CProduct::GetDownDepth()
{
return DownDepth;
}
void CProduct::InitializeProduct()
{
if( Layer.size()>0 )
{
UINT LayerNum=Layer.size();
for(UINT i=0;i<LayerNum;++i)
Nature Biotechnology: doi:10.1038/nbt.3413
Layer[i].InitializeLayer(0.03);
Layer.clear();
}
if(Gate.size()>0)
Gate.clear();
DwellingTime=7;
DwellingTime2=10;
DownFeedrate=5;
UpFeedrate=5;
ZValue=0.0f;
DownDepth=3.000f;
Power=100;
}
void CProduct::ProductSaveOrLoad(BOOL Save, CArchive &ar)
{
UINT NumOfLayer=0;
UINT i;
UINT NumOfGate=Gate.size();
if(Save)
{
CFile* tempFile = ar.GetFile();
SetName(tempFile->GetFileName());
NumOfLayer=Layer.size();
ar<<Name<<ZValue<<Power<<DownDepth<<DwellingTime<<DwellingTime2;
ar<<NumOfLayer<<NumOfGate;
for(i=0;i<NumOfLayer;++i)
Layer[i].LayerSaveOrLoad(true,ar);
for(i=0;i<NumOfGate;++i)
Gate[i].GateSaveOrLoad(true,ar);
}
else
{
InitializeProduct();
ar>>Name>>ZValue>>Power>>DownDepth>>DwellingTime>>DwellingTime2;
ar>>NumOfLayer>>NumOfGate;
Layer.resize(NumOfLayer);
Gate.resize(NumOfGate);
for(i=0;i<NumOfLayer;i++)
Layer[i].LayerSaveOrLoad(false,ar);
for(i=0;i<NumOfGate;++i)
Gate[i].GateSaveOrLoad(false,ar);
}
}
CLayer CProduct::ReturnLastLayer()
Nature Biotechnology: doi:10.1038/nbt.3413
{
return Layer.back();
}
BOOL CProduct::OptimizeProduct()
{
UINT TmpFeedrate=10;
UINT i;
CPath Start,End,TmpPath;
float StartPos[2],EndPos[2];
if(Layer.size()<1)
return false;
Start=Layer[0].ReturnFirstPath();
Start.GetStartPos(EndPos);
if( (int)(EndPos[0]*1000.0f)!=0 || (int)(EndPos[1]*1000.0f)!=0 )
{
CPath TmpPath;
StartPos[0]=0.0f;StartPos[1]=0.0f;
TmpPath.SetLineValue(false,StartPos,EndPos,TmpFeedrate);
Layer[0].InsertPath(1,TmpPath);
}
for(i=0;i<Layer.size()-1;++i)
{
Start=Layer[i].ReturnLastPath();
End=Layer[i+1].ReturnFirstPath();
Start.GetEndPos(StartPos);
End.GetStartPos(EndPos);
TmpPath.SetStartPos(StartPos);
TmpPath.SetEndPos(EndPos);
if(!TmpPath.IsSameStartEnd())
Layer[i].PushBackPath(TmpPath);
}
for(i=0;i<Layer.size()-1;++i)
{
Start=Layer[i].ReturnLastPath();
End=Layer[i+1].ReturnFirstPath();
if( !Start.GetDrawingOrMove() && !End.GetDrawingOrMove() && End.GetDwellingTime()<=0.0f )
{
End.GetEndPos(EndPos);
Start.SetEndPos(EndPos);
Layer[i+1].ErasePath(1);
Layer[i].ErasePath(Layer[i].ReturnNumOfPath());
if(!Start.IsSameStartEnd())
Layer[i].PushBackPath(Start);
}
Nature Biotechnology: doi:10.1038/nbt.3413
}
for(i=0;i<Layer.size();++i)
{
if(!Layer[i].OptimizeLayer())
{
EraseLayer(i);
if(i!=0) --i;
}
}
if(Layer.size()<1)
return false;
return true;
}
BOOL CProduct::IsAllPathLinked()
{
UINT i;
for(i=0;i<Layer.size();++i)
{
if(!Layer[i].IsAllPathLinked())
return false;
}
for(i=0;i<Layer.size()-1;++i)
{
CPath Start,End;
float StartPos[2],EndPos[2];
Start=Layer[i].ReturnLastPath();
End=Layer[i+1].ReturnFirstPath();
Start.GetEndPos(StartPos);
End.GetStartPos(EndPos);
if( (int)(StartPos[0]*1000.0f)!=(int)(EndPos[0]*1000.0f) ||
(int)(StartPos[1]*1000.0f)!=(int)(EndPos[1]*1000.0f) )
return false;
}
return true;
}
BOOL CProduct::IsAnyFeedrateZero()
{
UINT i;
for(i=0;i<Layer.size();++i)
{
if(Layer[i].IsAnyFeedrateZero())
Nature Biotechnology: doi:10.1038/nbt.3413
return true;
}
return false;
}
BOOL CProduct::IsOutOfRange(float Range)
{
UINT i;
for(i=0;i<Layer.size();++i)
{
if(Layer[i].IsOutOfRange(Range))
return true;
}
return false;
}
BOOL CProduct::IsZeroLayer()
{
UINT i;
for(i=0;i<Layer.size();++i)
{
if(Layer[i].IsPathNumberZero())
return true;
}
return false;
}
BOOL CProduct::IsAnyPathPoint()
{
UINT i;
for(i=0;i<Layer.size();++i)
{
if(Layer[i].IsAnyPathPoint())
return true;
}
return false;
}
double CProduct::ExportAerotec(CString &Code,UINT DwellingTimeBeforeOn,UINT DrawingFeedPer)
{
if(Layer.size()<1)
{
Code.Format("출력할 Code가 없습니다.");
return 0.0;
}
UINT Dwelling=DwellingTimeBeforeOn;
UINT i;
int Hours,Min;
Nature Biotechnology: doi:10.1038/nbt.3413
Hours=0;
Min=0;
CString TmpCode;
double Time=0.0;
float UpDistance;
//초기화
TmpCode.Format("G71 ;USE METRIC MODE\nG91 ;USE INCREMENTAL MODE\nG8
;VELOCITY PROFILING\n");
Code+=TmpCode;
TmpCode.Empty();
for(i=0;i<Layer.size()-1;++i)
{
Time+=Layer[i].ExportAerotec(TmpCode,Dwelling,DrawingFeedPer);
Code+=TmpCode;
TmpCode.Empty();
//층간의 이동.
TmpCode.Format(";----------------\n");
Code+=TmpCode;
TmpCode.Empty();
TmpCode.Format("G1 Z%.3f F%d\n",DownDepth,DownFeedrate);
Time+=((double)DownDepth*60.0/(double)DownFeedrate);
Code+=TmpCode;
TmpCode.Empty();
if(DwellingTime>0)
{
TmpCode.Format("G4 %d\n",DwellingTime*1000);
Time+=(double)(DwellingTime);
Code+=TmpCode;
TmpCode.Empty();
}
UpDistance=DownDepth-Layer[i+1].GetLayerThickness();
TmpCode.Format("G1 Z-%.3f F%d\n",UpDistance,UpFeedrate);
Time+=((double)UpDistance*60.0/(double)UpFeedrate);
Code+=TmpCode;
TmpCode.Empty();
if(DwellingTime2>0)
{
TmpCode.Format("G4 %d\n",DwellingTime2*1000);
Time+=(double)(DwellingTime2);
Code+=TmpCode;
TmpCode.Empty();
}
Nature Biotechnology: doi:10.1038/nbt.3413
//층간의 이동.
TmpCode.Format(";----------------\n");
Code+=TmpCode;
TmpCode.Empty();
}
Time+=Layer[i].ExportAerotec(TmpCode,Dwelling,DrawingFeedPer);
Code+=TmpCode;
TmpCode.Empty();
//종료
TmpCode.Format("EXIT\n");
Code+=TmpCode;
TmpCode.Empty();
Hours=(int)(Time/3600.0);
Min=(int)((Time-(double)Hours*3600.0)/60.0);
TmpCode.Format(";Fabrication Time About %d:%d \n",Hours,Min);
Code+=TmpCode;
TmpCode.Empty();
TmpCode.Format(";Power %dμW\n",Power);
Code+=TmpCode;
TmpCode.Empty();
return Time;
}
UINT CProduct::GetDownFeedrate()
{
return DownFeedrate;
}
UINT CProduct::GetUpFeedrate()
{
return UpFeedrate;
}
void CProduct::InputGate(BOOL Circle,float TmpPos[3],float TmpUnitVector[3],float Radius,float Length[2])
{
CGate TmpGate;
if(Circle)
TmpGate.SetCircleGate(TmpPos,TmpUnitVector,Radius);
else
TmpGate.SetRectGate(TmpPos,TmpUnitVector,Length);
Gate.push_back(TmpGate);
}
Nature Biotechnology: doi:10.1038/nbt.3413
void CProduct::DeleteGate(UINT GateNum)
{
if(GateNum>0 && Gate.size()!=0 && GateNum<=Gate.size())
{
--GateNum;
Gate.erase(&Gate.at(GateNum));
}
}
UINT CProduct::ReturnNumOfGate()
{
return Gate.size();
}
CGate CProduct::GetGate(UINT GateNum)
{
--GateNum;
return Gate[GateNum];
}
void CProduct::ReplaceGate(UINT GateNum, BOOL Circle, float Pos[], float Unit[], float Radius, float Length[])
{
CGate TmpGate;
if(Circle)
TmpGate.SetCircleGate(Pos,Unit,Radius);
else
TmpGate.SetRectGate(Pos,Unit,Length);
Gate[GateNum-1]=TmpGate;
}
UINT CProduct::GetDwellingTime2()
{
return DwellingTime2;
}
float CProduct::GetZValue()
{
return ZValue;
}
void CProduct::SetZValue(float Z)
{
ZValue=Z;
}
void CProduct::Translation(UINT Num1, UINT Num2, float TransX, float TransY, float TransZ)
Nature Biotechnology: doi:10.1038/nbt.3413
{
Translation(Num1,Num2,TransX,TransY);
ZValue+=TransZ;
float Pos[3];
for(UINT i=0;i<Gate.size();++i)
{
Gate[i].GetPosition(Pos);
Pos[2]+=TransZ;
Gate[i].SetPosition(Pos[0],Pos[1],Pos[2]);
}
}
void CProduct::InverseLayer()
{
CLayer *TmpLayer;
TmpLayer = new CLayer [Layer.size()];
UINT Size=Layer.size();
for(UINT i=0;i<Size;++i)
TmpLayer[i]=Layer[i];
for(i=0;i<Size;++i)
Layer[i]=TmpLayer[Size-i-1];
if(Gate.size()>0)
{
float Height=ReturnAbsZValue(Layer.size());
float Pos[3],Unit[3];
for(i=0;i<Gate.size();++i)
{
Gate[i].GetPosition(Pos);
Pos[2]=Height-Pos[2];
Gate[i].SetPosition(Pos[0],Pos[1],Pos[2]);
Gate[i].GetUnitVector(Unit);
Unit[2]*=(-1.0f);
Gate[i].SetUnitVector(Unit[0],Unit[1],Unit[2]);
}
}
delete [] TmpLayer;
}
void CProduct::ReturnMinAndMaxXValue(float MinMax[])
{
MinMax[0]=0.0f;
MinMax[1]=0.0f;
if(Layer.size()==0)
Nature Biotechnology: doi:10.1038/nbt.3413
return;
float TmpMinMax[2],TmpMinMax2[2];
TmpMinMax[0]=0.0f;
TmpMinMax[1]=0.0f;
TmpMinMax2[0]=0.0f;
TmpMinMax2[1]=0.0f;
Layer[0].ReturnMaxAndMinXValue(TmpMinMax);
for(UINT i=0;i<Layer.size();++i)
{
Layer[i].ReturnMaxAndMinXValue(TmpMinMax2);
if(TmpMinMax[0]>TmpMinMax2[0])
TmpMinMax[0]=TmpMinMax2[0];
if(TmpMinMax[1]<TmpMinMax2[1])
TmpMinMax[1]=TmpMinMax2[1];
}
MinMax[0]=TmpMinMax[0];
MinMax[1]=TmpMinMax[1];
}
void CProduct::ReturnMinAndMaxYValue(float MinMax[])
{
MinMax[0]=0.0f;
MinMax[1]=0.0f;
if(Layer.size()==0)
return;
float TmpMinMax[2],TmpMinMax2[2];
TmpMinMax[0]=0.0f;
TmpMinMax[1]=0.0f;
TmpMinMax2[0]=0.0f;
TmpMinMax2[1]=0.0f;
Layer[0].ReturnMaxAndMinYValue(TmpMinMax);
for(UINT i=0;i<Layer.size();++i)
{
Layer[i].ReturnMaxAndMinYValue(TmpMinMax2);
if(TmpMinMax[0]>TmpMinMax2[0])
TmpMinMax[0]=TmpMinMax2[0];
if(TmpMinMax[1]<TmpMinMax2[1])
TmpMinMax[1]=TmpMinMax2[1];
}
MinMax[0]=TmpMinMax[0];
MinMax[1]=TmpMinMax[1];
Nature Biotechnology: doi:10.1038/nbt.3413
}
BOOL CProduct::ChangePower(UINT ChangedPower)
{
for(UINT i=0;i<Layer.size();++i)
if(!Layer[i].ChangePower((float)ChangedPower/(float)Power))
return false;
Power=ChangedPower;
return true;
}
void CProduct::SetName(CString TmpName)
{
if(TmpName.GetLength()<1)
return;
int Num;
Num=TmpName.ReverseFind('.');
Name.Empty();
for(UINT i=0;i<Num;++i)
Name+=TmpName.GetAt(i);
}
CString CProduct::GetName()
{
return Name;
}
//추가된 부분.
void CProduct::DoMoveOptimize()
{
CMoveOptimize Op;
CLayer TmpLayer;
for(UINT i=0;i<Layer.size();++i)
{
TmpLayer=Layer[i];
Layer[i].InitializeLayer(Layer[i].GetLayerThickness());
Layer[i]=Op.DoMoveOptimize(TmpLayer);
Op.Initialize();
TmpLayer.InitializeLayer(TmpLayer.GetLayerThickness());
}
OptimizeProduct();
}
//여기서 부터 형상 추가.
void CProduct::MakeJoint(int Type, float Width, float Length, float Height, float TopHole, float BottomHole)
Nature Biotechnology: doi:10.1038/nbt.3413
{
Power=50;
float Step=0.076;
float LayerThickness=0.1f;
float Pos[3],UnitVector[3];
CGate TmpGate;
UINT LayerNum=(UINT)(Height*10.5f)+1;
CLayer TmpLayer;
TmpLayer.InitializeLayer(LayerThickness);
TmpLayer.MakeJointHole(Width,Length,BottomHole);
PushBackLayer(TmpLayer);
if(BottomHole>0.2f)
{
Pos[0]=0.0f; Pos[1]=0.0f; Pos[2]=0.0f;
UnitVector[0]=0.0f; UnitVector[1]=0.0f; UnitVector[2]=-1.0f;
TmpGate.SetCircleGate(Pos,UnitVector,0.0f);
Gate.push_back(TmpGate);
}
for(UINT i=0;i<LayerNum;++i)
{
TmpLayer.InitializeLayer(LayerThickness);
switch(Type)
{
case 1 :
TmpLayer.MakeJointType1(Width,Length);
break;
case 2:
TmpLayer.MakeJointType2(Width,Length);
break;
case 3:
TmpLayer.MakeJointType3(Width,Length);
break;
case 4 :
TmpLayer.MakeJointType4(Width,Length);
break;
case 5:
TmpLayer.MakeJointType5(Width,Length);
break;
case 6:
TmpLayer.MakeJointType6(Width,Length);
break;
case 7:
TmpLayer.MakeJointType7(Width,Length);
}
PushBackLayer(TmpLayer);
Nature Biotechnology: doi:10.1038/nbt.3413
}
InputJointGate(Type,Width,Length,Height,Step);
TmpLayer.InitializeLayer(LayerThickness);
TmpLayer.MakeJointHole(Width,Length,TopHole);
PushBackLayer(TmpLayer);
if(TopHole>0.2f)
{
Pos[0]=0.0f; Pos[1]=0.0f; Pos[2]=ReturnAbsZValue(Layer.size());
UnitVector[0]=0.0f; UnitVector[1]=0.0f; UnitVector[2]=1.0f;
TmpGate.SetCircleGate(Pos,UnitVector,0.0f);
Gate.push_back(TmpGate);
}
}
void CProduct::InputJointGate(int Type, float Width, float Length, float Height, float Step)
{
float Pos[3],UnitVector[3];
CGate TmpGate;
if(Type!=4 && Type!=7)
{
Pos[0]=Width/(-2.0f)-Step*3.0f; Pos[1]=0.0f; Pos[2]=Height/2.0f+0.1f;
UnitVector[0]=-1.0f; UnitVector[1]=0.0f; UnitVector[2]=0.0f;
TmpGate.SetCircleGate(Pos,UnitVector,0.0f);
Gate.push_back(TmpGate);
}
if(Type!=1 && Type!=2 && Type!=7)
{
Pos[0]=Width/2.0f+Step*3.0f; Pos[1]=0.0f; Pos[2]=Height/2.0f+0.1f;
UnitVector[0]=1.0f; UnitVector[1]=0.0f; UnitVector[2]=0.0f;
TmpGate.SetCircleGate(Pos,UnitVector,0.0f);
Gate.push_back(TmpGate);
}
if(Type!=1 && Type!=3 && Type!=7)
{
Pos[0]=0.0f; Pos[1]=Length/(-2.0f)-Step*3.0f; Pos[2]=Height/2.0f+0.1f;
UnitVector[0]=0.0f; UnitVector[1]=-1.0f; UnitVector[2]=0.0f;
TmpGate.SetCircleGate(Pos,UnitVector,0.0f);
Gate.push_back(TmpGate);
}
if(Type==6)
Nature Biotechnology: doi:10.1038/nbt.3413
{
Pos[0]=0.0f; Pos[1]=Length/2.0f+Step*3.0f; Pos[2]=Height/2.0f+0.1f;
UnitVector[0]=0.0f; UnitVector[1]=1.0f; UnitVector[2]=0.0f;
TmpGate.SetCircleGate(Pos,UnitVector,0.0f);
Gate.push_back(TmpGate);
}
}
void CProduct::MakeHPipe(float Width, float Height, float Length )
{
Power=50;
float Step=0.076;
float LayerThickness=0.1f;
float TmpLength;
TmpLength=Length;
Length=Width;
Width=TmpLength;
CGate TmpGate;
UINT LayerNum=(UINT)(Height*10.5f)+1;
CLayer TmpLayer;
TmpLayer.InitializeLayer(LayerThickness);
TmpLayer.MakeJointHole(Width-Step*6.0f,Length-Step*2.0f,0.0f);
PushBackLayer(TmpLayer);
for(UINT i=0;i<LayerNum;++i)
{
TmpLayer.InitializeLayer(LayerThickness);
TmpLayer.MakeHPipe(Width,Length);
PushBackLayer(TmpLayer);
}
InputJointGate(3,Width-Step*6.0f,Length-Step*2.0f,Height,Step);
TmpLayer.InitializeLayer(LayerThickness);
TmpLayer.MakeJointHole(Width-Step*6.0f,Length-Step*2.0f,0.0f);
PushBackLayer(TmpLayer);
}
void CProduct::MakeVPipe(float Width, float Length, float Height)
{
if(Width<0.2f || Length<0.2f || Height<0.2f)
return;
Power=50;
Nature Biotechnology: doi:10.1038/nbt.3413
CLayer TmpLayer;
CGate TmpGate;
UINT LayerNum=(UINT)(Height*10.5f);
float LayerThickness=0.1f;
float Pos[3],UnitVector[3];
for(UINT i=0;i<LayerNum;++i)
{
TmpLayer.InitializeLayer(LayerThickness);
TmpLayer.MakeVPipe(Width,Length);
PushBackLayer(TmpLayer);
}
Pos[0]=0.0f; Pos[1]=0.0f; Pos[2]=0.0f;
UnitVector[0]=0.0f; UnitVector[1]=0.0f; UnitVector[2]=-1.0f;
TmpGate.SetCircleGate(Pos,UnitVector,0.0f);
Gate.push_back(TmpGate);
Pos[0]=0.0f; Pos[1]=0.0f; Pos[2]=ReturnAbsZValue(Layer.size());
UnitVector[0]=0.0f; UnitVector[1]=0.0f; UnitVector[2]=1.0f;
TmpGate.SetCircleGate(Pos,UnitVector,0.0f);
Gate.push_back(TmpGate);
}
void CProduct::MakeGatePipe(float Radius, float Length)
{
if(Radius<0.25f)
return;
Power=50;
float LayerThickness=0.1f;
UINT LayerNum=(UINT)(Length*10.5f);
CLayer TmpLayer;
TmpLayer.InitializeLayer(LayerThickness);
for(UINT i=0;i<LayerNum;++i)
{
TmpLayer.MakeGatePipe(Radius,3);
PushBackLayer(TmpLayer);
TmpLayer.InitializeLayer(LayerThickness);
}
while(Radius>=(0.25f+0.05f-0.001f))
{
Radius-=0.04f;
TmpLayer.MakeGatePipe(Radius,3);
Nature Biotechnology: doi:10.1038/nbt.3413
PushBackLayer(TmpLayer);
TmpLayer.InitializeLayer(LayerThickness);
}
while(Radius<=0.45f+0.001f)
{
Radius+=0.05f;
TmpLayer.MakeGatePipe(Radius,3);
PushBackLayer(TmpLayer);
TmpLayer.InitializeLayer(LayerThickness);
}
for(i=0;i<3;++i)
PushBackLayer(ReturnLastLayer());
while(Radius>=(0.28f-0.001f))
{
Radius-=0.04f;
TmpLayer.MakeGatePipe(Radius,3);
PushBackLayer(TmpLayer);
TmpLayer.InitializeLayer(LayerThickness);
}
for(i=0;i<3;++i)
PushBackLayer(ReturnLastLayer());
float Pos[3],UnitVector[3];
CGate TmpGate;
Pos[0]=0.0f; Pos[1]=0.0f; Pos[2]=0.0f;
UnitVector[0]=0.0f; UnitVector[1]=0.0f; UnitVector[2]=-1.0f;
TmpGate.SetCircleGate(Pos,UnitVector,0.0f);
Gate.push_back(TmpGate);
Pos[0]=0.0f; Pos[1]=0.0f; Pos[2]=ReturnAbsZValue(Layer.size());
UnitVector[0]=0.0f; UnitVector[1]=0.0f; UnitVector[2]=1.0f;
TmpGate.SetCircleGate(Pos,UnitVector,0.0f);
Gate.push_back(TmpGate);
}
void CProduct::CriterionFeedrate(BOOL Draw, UINT OldFeed, UINT NewFeed)
{
for(UINT i=0;i<Layer.size();++i)
Layer[i].CriterionFeedrate(Draw,OldFeed,NewFeed);
}
void CProduct::InputGate(CGate TmpGate)
{
Gate.push_back(TmpGate);
Nature Biotechnology: doi:10.1038/nbt.3413
}
double CProduct::ExportNewport(CString &Code,UINT DwellingTimeBeforeOn,UINT DrawingFeedPer)
{
if(Layer.size()<1)
{
Code.Format("출력할 Code가 없습니다.");
return 0.0;
}
UINT Dwelling=DwellingTimeBeforeOn;
UINT i;
int Hours,Min;
Hours=0;
Min=0;
CString TmpCode;
double Time=0.0;
float UpDistance;
TmpCode.Format("G71\nG91\nG8\n");
Code+=TmpCode;
TmpCode.Empty();
for(i=0;i<Layer.size()-1;++i)
{
Time+=Layer[i].ExportNewport(TmpCode,Dwelling,DrawingFeedPer);
Code+=TmpCode;
TmpCode.Empty();
TmpCode.Format("G1 Z%.3f F%d\n",DownDepth,DownFeedrate);
Time+=((double)DownDepth*60.0/(double)DownFeedrate);
Code+=TmpCode;
TmpCode.Empty();
if(DwellingTime>0)
{
TmpCode.Format("G4 X%d\n",DwellingTime*1000);
Time+=(double)(DwellingTime);
Code+=TmpCode;
TmpCode.Empty();
}
UpDistance=DownDepth-Layer[i+1].GetLayerThickness();
TmpCode.Format("G1 Z-%.3f F%d\n",UpDistance,UpFeedrate);
Time+=((double)UpDistance*60.0/(double)UpFeedrate);
Code+=TmpCode;
TmpCode.Empty();
Nature Biotechnology: doi:10.1038/nbt.3413
if(DwellingTime2>0)
{
TmpCode.Format("G4 X%d\n",DwellingTime2*1000);
Time+=(double)(DwellingTime2);
Code+=TmpCode;
TmpCode.Empty();
}
}
Time+=Layer[i].ExportNewport(TmpCode,Dwelling,DrawingFeedPer);
Code+=TmpCode;
TmpCode.Empty();
//종료
TmpCode.Format("M30\n");
Code+=TmpCode;
TmpCode.Empty();
Hours=(int)(Time/3600.0);
Min=(int)((Time-(double)Hours*3600.0)/60.0);
TmpCode.Format(";Fabrication Time About %d:%d \n",Hours,Min);
Code+=TmpCode;
TmpCode.Empty();
TmpCode.Format(";Power %dμW\n",Power);
Code+=TmpCode;
TmpCode.Empty();
return Time;
}
float CProduct::TransratFeedrateToNewportScale(int Feedrate)
{
return (float)Feedrate/60.0;
}
BOOL CProduct::ExportOrNot(CString Code)
{
if(Code.GetLength()>24660)
return true;
else
return false;
}
void CProduct::OutputFile_ForNewport(CString FileName, CString Code, double Time, int Num)
{
CString Tmp;
Nature Biotechnology: doi:10.1038/nbt.3413
Tmp.Empty();
Tmp.Format("%2d_%dmin",Num,(int)(Time/60.0)+1);
FileName+=Tmp;
if(FileName.Find(".newpcode")==-1)
FileName+=".NewpCode";
ofstream fout(FileName);
fout<<Code;
fout.close();
}
double CProduct::ExportFDM(CString &Code, UINT DwellingTimeBeforeOn, UINT DrawingFeedPer)
{
if(Layer.size()<1)
{
Code.Format("출력할 NC Code가 없습니다.");
return 0.0;
}
UINT Dwelling=DwellingTimeBeforeOn;
UINT i;
int Hours,Min;
Hours=0;
Min=0;
CString TmpCode;
double Time=0.0;
for(i=0;i<Layer.size()-1;++i)
{
Time+=Layer[i].ExportFDM(TmpCode,Dwelling,DrawingFeedPer);
Code+=TmpCode;
TmpCode.Empty();
//층간의 이동.
TmpCode.Format(";----------------\n");
Code+=TmpCode;
TmpCode.Empty();
TmpCode.Format("G1 A-%.3f F%d\n",Layer[i+1].GetLayerThickness(),UpFeedrate);
Time+=((double)Layer[i+1].GetLayerThickness()*60.0/(double)UpFeedrate);
Code+=TmpCode;
TmpCode.Empty();
//층간의 이동.
TmpCode.Format(";----------------\n");
Code+=TmpCode;
TmpCode.Empty();
Nature Biotechnology: doi:10.1038/nbt.3413
}
Time+=Layer[i].ExportFDM(TmpCode,Dwelling,DrawingFeedPer);
Code+=TmpCode;
TmpCode.Empty();
//종료
TmpCode.Format("EXIT\n");
Code+=TmpCode;
TmpCode.Empty();
Hours=(int)(Time/3600.0);
Min=(int)((Time-(double)Hours*3600.0)/60.0);
TmpCode.Format(";Fabrication Time About %d:%d \n",Hours,Min);
Code+=TmpCode;
TmpCode.Empty();
return Time;
}
// Path.h: interface for the CPath class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_PATH_H__0386514B_6E87_4D3E_BB68_A56B601B3DE9__INCLUDED_)
#define AFX_PATH_H__0386514B_6E87_4D3E_BB68_A56B601B3DE9__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CPath
{
public:
double ExportFDM(CString &Code,UINT DrawingFeedPer);
double ReturnSlopeAngleOfCircleStartPoint();
double ReturnSlopeAngle();
double ExportNewport(CString &Code,UINT DrawingFeedPer);
void SetFeedrate(UINT Feed);
BOOL ChangePower(float Factor);
void ReturnYValue(float Y[2]);
void ReturnXValue(float X[2]);
void SetDrawingOrMoving(int TmpMoveOrDraw);
void SetDwellingValue(BOOL IsDraw, float IsTime);
float GetDwellingTime();
void SetDwellingValue(BOOL IsDraw,float Point[2],float IsTime);
float DwellingTime;
double ReturnPointAngle(float Point[2]);
Nature Biotechnology: doi:10.1038/nbt.3413
double ReturnCircleAngle(BOOL IsCW,float Start[2],float End[2],float Center[2]);
double ExportAerotec(CString &Code,UINT DrawingFeedPer);
float MakePlus(float Num);
BOOL IsOutOfRange(float Range);
BOOL IsFeedrateZero();
void SetStartPos(float StartPos[]);
BOOL IsSameStartEnd();
void SetEndPos(float EndPos[2]);
void SetLine();
BOOL GetLine();
BOOL GetCWOrCCW();
BOOL GetCircle();
BOOL GetDrawingOrMove();
void GetCenterPos(float Center[]);
UINT GetFeedrate();
void PathSaveOrLoad(BOOL Save,CArchive& ar);
void PathTranslation(float TransX,float TransY);
void Rotation(float Position[2],float CenterX,float CenterY,double CWAngle);
void PathRotation(float CenterX,float CenterY,double CWAngle);
void PathEdit(UINT TmpFeedrate,int TmpMoveOrDraw);
void TransPath(float TransX,float TransY);
void GetStartPos(float Start[2]);
void InitializePath();
void ReturnInformation(float TmpStart[2], float TmpEnd[2], float TmpCenter[2], BOOL &TmpDrawing,BOOL
&TmpCircle,BOOL &TmpCW,BOOL &TmpLine,UINT &TmpFeedrate,float &TmpDwellingTime);
void GetEndPos(float AbsEnd[2]);
void SetCircleValue(BOOL IsDraw ,BOOL IsCW,float AbsStart[] ,float AbsEnd[] ,float AbsCenter[] ,UINT Feed);
void SetLineValue(BOOL IsDraw,float Start[2],float End[2],UINT Feed);
CPath();
virtual ~CPath();
private:
float AbsCenterPos[2];
float AbsEndPos[2];
float AbsStartPos[2];
BOOL Drawing;
BOOL Circle;
BOOL CW;
BOOL Line;
UINT Feedrate;
};
#endif // !defined(AFX_PATH_H__0386514B_6E87_4D3E_BB68_A56B601B3DE9__INCLUDED_)
// Path.cpp: implementation of the CPath class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
Nature Biotechnology: doi:10.1038/nbt.3413
#include "STLFileTransfer.h"
#include "Path.h"
#include "math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CPath::CPath()
{
Line=true;
Circle=false;
Drawing=false;
CW=true;
Feedrate=10;
AbsCenterPos[0]=0.0f;
AbsCenterPos[1]=0.0f;
AbsStartPos[0]=0.0f;
AbsStartPos[1]=0.0f;
AbsEndPos[0]=0.0f;
AbsEndPos[1]=0.0f;
DwellingTime=0.0f;
}
CPath::~CPath()
{
}
void CPath::SetLineValue(BOOL IsDraw,float AbsStart[], float AbsEnd[], UINT Feed)
{
Line=true;
Drawing=IsDraw;
AbsStartPos[0]=AbsStart[0];
AbsStartPos[1]=AbsStart[1];
AbsEndPos[0]=AbsEnd[0];
AbsEndPos[1]=AbsEnd[1];
Feedrate=Feed;
AbsCenterPos[0]=0.0f;
AbsCenterPos[1]=0.0f;
Circle=false;
CW=true;
Nature Biotechnology: doi:10.1038/nbt.3413
DwellingTime=0.0f;
}
void CPath::SetCircleValue(BOOL IsDraw,BOOL IsCW, float AbsStart[], float AbsEnd[], float AbsCenter[], UINT Feed)
{
Circle=true;
Drawing=IsDraw;
AbsStartPos[0]=AbsStart[0];
AbsStartPos[1]=AbsStart[1];
AbsEndPos[0]=AbsEnd[0];
AbsEndPos[1]=AbsEnd[1];
AbsCenterPos[0]=AbsCenter[0];
AbsCenterPos[1]=AbsCenter[1];
Feedrate=Feed;
CW=IsCW;
DwellingTime=0.0f;
Line=false;
}
void CPath::GetEndPos(float AbsEnd[])
{
AbsEnd[0]=AbsEndPos[0];
AbsEnd[1]=AbsEndPos[1];
}
void CPath::ReturnInformation(float TmpStart[], float TmpEnd[], float TmpCenter[], BOOL &TmpDrawing,BOOL
&TmpCircle,BOOL &TmpCW,BOOL &TmpLine,UINT &TmpFeedrate,float &TmpDwellingTime)
{
TmpStart[0]=AbsStartPos[0];
TmpStart[1]=AbsStartPos[1];
TmpEnd[0]=AbsEndPos[0];
TmpEnd[1]=AbsEndPos[1];
TmpCenter[0]=AbsCenterPos[0];
TmpCenter[1]=AbsCenterPos[1];
TmpDrawing=Drawing;
TmpCircle=Circle;
TmpCW=CW;
TmpLine=Line;
TmpFeedrate=Feedrate;
TmpDwellingTime=DwellingTime;
}
void CPath::InitializePath()
{
Nature Biotechnology: doi:10.1038/nbt.3413
Line=true;
Circle=false;
Drawing=false;
CW=true;
Feedrate=10;
AbsCenterPos[0]=0.0f;
AbsCenterPos[1]=0.0f;
AbsStartPos[0]=AbsEndPos[0];
AbsStartPos[1]=AbsEndPos[1];
AbsEndPos[0]=0.0f;
AbsEndPos[1]=0.0f;
DwellingTime=0.0f;
}
void CPath::GetStartPos(float Start[])
{
Start[0]=AbsStartPos[0];
Start[1]=AbsStartPos[1];
}
void CPath::TransPath(float TransX, float TransY)
{
AbsStartPos[0]+=TransX;
AbsStartPos[1]+=TransY;
AbsEndPos[0]+=TransX;
AbsEndPos[1]+=TransY;
if(Circle)
{
AbsCenterPos[0]+=TransX;
AbsCenterPos[1]+=TransX;
}
return;
}
void CPath::PathEdit(UINT TmpFeedrate, int TmpMoveOrDraw)
{
Feedrate=TmpFeedrate;
if(TmpMoveOrDraw==0)
Drawing=false;
else
Drawing=true;
}
void CPath::PathRotation(float CenterX, float CenterY, double CWAngle)
{
Rotation(AbsStartPos,CenterX,CenterY,CWAngle);
Nature Biotechnology: doi:10.1038/nbt.3413
Rotation(AbsEndPos,CenterX,CenterY,CWAngle);
if(Circle)
Rotation(AbsCenterPos,CenterX,CenterY,CWAngle);
}
void CPath::Rotation(float Position[], float CenterX, float CenterY, double CWAngle)
{
double Angle=CWAngle*3.141592/180.0;
Position[0]-=CenterX;
Position[1]-=CenterY;
float Tmp0=Position[0];
float Tmp1=Position[1];
Position[0]=Tmp0*(float)cos(Angle)+Tmp1*(float)sin(Angle);
Position[1]=Tmp1*(float)cos(Angle)-Tmp0*(float)sin(Angle);
Position[0]+=CenterX;
Position[1]+=CenterY;
}
void CPath::PathTranslation(float TransX, float TransY)
{
AbsStartPos[0]+=TransX;
AbsStartPos[1]+=TransY;
AbsEndPos[0]+=TransX;
AbsEndPos[1]+=TransY;
if(Circle)
{
AbsCenterPos[0]+=TransX;
AbsCenterPos[1]+=TransY;
}
}
void CPath::PathSaveOrLoad(BOOL Save, CArchive &ar)
{
if(Save)
{
ar<<AbsStartPos[0]<<AbsStartPos[1];
ar<<AbsEndPos[0]<<AbsEndPos[1];
ar<<AbsCenterPos[0]<<AbsCenterPos[1];
ar<<Feedrate<<Circle<<CW<<Drawing<<Line<<DwellingTime;
}
else
{
ar>>AbsStartPos[0]>>AbsStartPos[1];
Nature Biotechnology: doi:10.1038/nbt.3413
ar>>AbsEndPos[0]>>AbsEndPos[1];
ar>>AbsCenterPos[0]>>AbsCenterPos[1];
ar>>Feedrate>>Circle>>CW>>Drawing>>Line>>DwellingTime;
}
}
UINT CPath::GetFeedrate()
{
return Feedrate;
}
void CPath::GetCenterPos(float Center[])
{
Center[0]=AbsCenterPos[0];
Center[1]=AbsCenterPos[1];
}
BOOL CPath::GetDrawingOrMove()
{
return Drawing;
}
BOOL CPath::GetCircle()
{
return Circle;
}
BOOL CPath::GetCWOrCCW()
{
return CW;
}
BOOL CPath::GetLine()
{
return Line;
}
void CPath::SetLine()
{
Line=true;
Circle=false;
AbsCenterPos[0]=0.0f;
AbsCenterPos[1]=0.0f;
}
void CPath::SetEndPos(float EndPos[])
{
AbsEndPos[0]=EndPos[0];
Nature Biotechnology: doi:10.1038/nbt.3413
AbsEndPos[1]=EndPos[1];
}
BOOL CPath::IsSameStartEnd()
{
if(Circle)
{
if( (int)(AbsStartPos[0]*1000.0f)==(int)(AbsCenterPos[0]*1000.0f) &&
(int)(AbsStartPos[1]*1000.0f)==(int)(AbsCenterPos[1]*1000.0f) )
return true;
else
return false;
}
if( (int)(AbsStartPos[0]*1000.0f)==(int)(AbsEndPos[0]*1000.0f) &&
(int)(AbsStartPos[1]*1000.0f)==(int)(AbsEndPos[1]*1000.0f) )
return true;
return false;
}
void CPath::SetStartPos(float StartPos[])
{
AbsStartPos[0]=StartPos[0];
AbsStartPos[1]=StartPos[1];
}
BOOL CPath::IsFeedrateZero()
{
if(Feedrate==0)
return true;
return false;
}
BOOL CPath::IsOutOfRange(float Range)
{
if(MakePlus(AbsStartPos[0])>Range)
return true;
if(MakePlus(AbsStartPos[1])>Range)
return true;
if(MakePlus(AbsEndPos[0])>Range)
return true;
if(MakePlus(AbsEndPos[1])>Range)
return true;
Nature Biotechnology: doi:10.1038/nbt.3413
if(Circle)
{
float radius=(float)sqrt((double)((AbsStartPos[0]-AbsCenterPos[0])*(AbsStartPos[0]-
AbsCenterPos[0])+(AbsStartPos[1]-AbsCenterPos[1])*(AbsStartPos[1]-AbsCenterPos[1])));
if( (MakePlus(AbsCenterPos[0])+radius) > Range )
return true;
if( (MakePlus(AbsCenterPos[1])+radius) > Range )
return true;
}
return false;
}
float CPath::MakePlus(float Num)
{
if(Num<0)
return -1.0f*Num;
return Num;
}
double CPath::ExportAerotec(CString &Code,UINT DrawingFeedPer)
{
CString TmpCode;
double Length=0.0;
float End[2];
End[0]=AbsEndPos[0]-AbsStartPos[0];
End[1]=AbsEndPos[1]-AbsStartPos[1];
float RealFeedrate;
if(Drawing)
RealFeedrate=(float)Feedrate*(float)DrawingFeedPer/100.0f;
else
RealFeedrate=(float)Feedrate;
if(Line)
{
if(DwellingTime>0.0f)
{
TmpCode.Format(" G4 %d\n",(int)(DwellingTime*(float)DrawingFeedPer*10.0f));
}
else
{
Length=sqrt( (double)((AbsStartPos[0]-AbsEndPos[0])*(AbsStartPos[0]-
AbsEndPos[0])+(AbsStartPos[1]-AbsEndPos[1])*(AbsStartPos[1]-AbsEndPos[1])) );
if( (int)(End[0]*1000.0f)!=0 && (int)(End[1]*1000.0f)!=0 )
Nature Biotechnology: doi:10.1038/nbt.3413
TmpCode.Format(" G1 X%.3f Y%.3f F%.3f\n",End[0],End[1],RealFeedrate);
else if( (int)(End[0]*1000.0f)==0 )
TmpCode.Format(" G1 Y%.3f F%.3f\n",End[1],RealFeedrate);
else if( (int)(End[1]*1000.0f)==0 )
TmpCode.Format(" G1 X%.3f F%.3f\n",End[0],RealFeedrate);
else
AfxMessageBox("Export Error : Path Error ");
}
}
else
{
if(Circle)
{
float Center[2],Radius;
Radius=sqrt( (double)((AbsStartPos[0]-AbsCenterPos[0])*(AbsStartPos[0]-
AbsCenterPos[0])+(AbsStartPos[1]-AbsCenterPos[1])*(AbsStartPos[1]-AbsCenterPos[1])) );
Length=Radius*ReturnCircleAngle(CW,AbsStartPos,AbsEndPos,AbsCenterPos);
Center[0]=AbsCenterPos[0]-AbsStartPos[0];
Center[1]=AbsCenterPos[1]-AbsStartPos[1];
if(CW)
TmpCode.Format(" G2 X%.3f Y%.3f C%.3f,%.3f
F%.3f\n",End[0],End[1],Center[0],Center[1],RealFeedrate);
else
TmpCode.Format(" G3 X%.3f Y%.3f C%.3f,%.3f
F%.3f\n",End[0],End[1],Center[0],Center[1],RealFeedrate);
}
}
Code+=TmpCode;
if(DwellingTime>0.0f)
return (double)DwellingTime*(double)DrawingFeedPer/100.0;
else
return Length*60.0/(double)RealFeedrate;
}
double CPath::ReturnCircleAngle(BOOL IsCW,float Start[],float End[],float Center[])
{
if((int)(Start[0]*1000.0f)==(int)(End[0]*1000.0f) && (int)(Start[1]*1000.0f)==(int)(End[1]*1000.0f) )
{
return (2.0*3.141592);
}
else
{
float TmpStart[2],TmpEnd[2];
double StartAngle,EndAngle;
TmpStart[0]=Start[0]-Center[0];
TmpStart[1]=Start[1]-Center[1];
Nature Biotechnology: doi:10.1038/nbt.3413
TmpEnd[0]=End[0]-Center[0];
TmpEnd[1]=End[1]-Center[1];
StartAngle=ReturnPointAngle(TmpStart);
EndAngle=ReturnPointAngle(TmpEnd);
if(IsCW)
{
if(StartAngle>=EndAngle)
{
return (StartAngle-EndAngle);
}
else
{
return (2.0*3.141592+StartAngle-EndAngle);
}
}
else
{
if(StartAngle<=EndAngle)
{
return (EndAngle-StartAngle);
}
else
{
return (2.0*3.141592-StartAngle+EndAngle);
}
}
}
}
double CPath::ReturnPointAngle(float Point[])
{
double TmpPoint[2];
TmpPoint[0]=(double)((int)(Point[0]*1000.0f))/1000.0;
TmpPoint[1]=(double)((int)(Point[1]*1000.0f))/1000.0;
if(TmpPoint[1]>=0)
{
return acos(TmpPoint[0]/sqrt(TmpPoint[0]*TmpPoint[0]+TmpPoint[1]*TmpPoint[1]));
}
else
{
return (2.0*3.141592-acos(TmpPoint[0]/sqrt(TmpPoint[0]*TmpPoint[0]+TmpPoint[1]*TmpPoint[1])));
}
}
Nature Biotechnology: doi:10.1038/nbt.3413
void CPath::SetDwellingValue(BOOL IsDraw, float Point[], float IsTime)
{
Line=true;
Drawing=IsDraw;
AbsStartPos[0]=Point[0];
AbsStartPos[1]=Point[1];
AbsEndPos[0]=Point[0];
AbsEndPos[1]=Point[1];
Feedrate=0;
AbsCenterPos[0]=0.0f;
AbsCenterPos[1]=0.0f;
Circle=false;
CW=true;
DwellingTime=IsTime;
}
float CPath::GetDwellingTime()
{
return DwellingTime;
}
void CPath::SetDwellingValue(BOOL IsDraw, float IsTime)
{
Line=true;
Drawing=IsDraw;
AbsStartPos[0]=AbsEndPos[0];
AbsStartPos[1]=AbsEndPos[1];
Feedrate=0;
AbsCenterPos[0]=0.0f;
AbsCenterPos[1]=0.0f;
Circle=false;
CW=true;
DwellingTime=IsTime;
}
void CPath::SetDrawingOrMoving(int TmpMoveOrDraw)
{
if(TmpMoveOrDraw==0)
Drawing=false;
else
Drawing=true;
}
void CPath::ReturnXValue(float X[])
{
if(Circle)
{
Nature Biotechnology: doi:10.1038/nbt.3413
float radius=(float)sqrt((double)((AbsStartPos[0]-AbsCenterPos[0])*(AbsStartPos[0]-
AbsCenterPos[0])+(AbsStartPos[1]-AbsCenterPos[1])*(AbsStartPos[1]-AbsCenterPos[1])));
X[0]=AbsCenterPos[0]-radius;
X[1]=AbsCenterPos[0]+radius;
}
else
{
if(AbsStartPos[0]<AbsEndPos[0])
{
X[0]=AbsStartPos[0];
X[1]=AbsEndPos[0];
}
else
{
X[1]=AbsStartPos[0];
X[0]=AbsEndPos[0];
}
}
}
void CPath::ReturnYValue(float Y[])
{
if(Circle)
{
float radius=(float)sqrt((double)((AbsStartPos[0]-AbsCenterPos[0])*(AbsStartPos[0]-
AbsCenterPos[0])+(AbsStartPos[1]-AbsCenterPos[1])*(AbsStartPos[1]-AbsCenterPos[1])));
Y[0]=AbsCenterPos[1]-radius;
Y[1]=AbsCenterPos[1]+radius;
}
else
{
if(AbsStartPos[1]<AbsEndPos[1])
{
Y[0]=AbsStartPos[1];
Y[1]=AbsEndPos[1];
}
else
{
Y[1]=AbsStartPos[1];
Y[0]=AbsEndPos[1];
}
}
}
BOOL CPath::ChangePower(float Factor)
{
float TmpFeed;
TmpFeed=Factor*(float)Feedrate;
Nature Biotechnology: doi:10.1038/nbt.3413
Feedrate=(UINT)TmpFeed;
if( (TmpFeed*10.0f-(float)((int)TmpFeed*10))>=5.0f )
Feedrate+=1;
if(Feedrate<1)
return false;
return true;
}
void CPath::SetFeedrate(UINT Feed)
{
DwellingTime=0.0f;
Feedrate=Feed;
}
double CPath::ExportNewport(CString &Code,UINT DrawingFeedPer)
{
CString TmpCode;
double Length=0.0;
float End[2];
End[0]=AbsEndPos[0]-AbsStartPos[0];
End[1]=AbsEndPos[1]-AbsStartPos[1];
float RealFeedrate;
if(Drawing)
RealFeedrate=(float)Feedrate*(float)DrawingFeedPer/100.0f;
else
RealFeedrate=(float)Feedrate;
if(Line)
{
if(DwellingTime>0.0f)
{
TmpCode.Format("G4 X%d\n",(int)(DwellingTime*(float)DrawingFeedPer*10.0f));
}
else
{
Length=sqrt( (double)((AbsStartPos[0]-AbsEndPos[0])*(AbsStartPos[0]-
AbsEndPos[0])+(AbsStartPos[1]-AbsEndPos[1])*(AbsStartPos[1]-AbsEndPos[1])) );
if( (int)(End[0]*1000.0f)!=0 && (int)(End[1]*1000.0f)!=0 )
TmpCode.Format("G1 X%.3f Y%.3f F%.3f\n",End[0],End[1],RealFeedrate);
else if( (int)(End[0]*1000.0f)==0 )
TmpCode.Format("G1 Y%.3f F%.3f\n",End[1],RealFeedrate);
else if( (int)(End[1]*1000.0f)==0 )
TmpCode.Format("G1 X%.3f F%.3f\n",End[0],RealFeedrate);
else
Nature Biotechnology: doi:10.1038/nbt.3413
AfxMessageBox("Export Error : Path Error ");
}
}
else
{
if(Circle)
{
float Center[2],Radius;
Radius=sqrt( (double)((AbsStartPos[0]-AbsCenterPos[0])*(AbsStartPos[0]-
AbsCenterPos[0])+(AbsStartPos[1]-AbsCenterPos[1])*(AbsStartPos[1]-AbsCenterPos[1])) );
Length=Radius*ReturnCircleAngle(CW,AbsStartPos,AbsEndPos,AbsCenterPos);
Center[0]=AbsCenterPos[0]-AbsStartPos[0];
Center[1]=AbsCenterPos[1]-AbsStartPos[1];
if(CW)
TmpCode.Format("G2 X%.3f Y%.3f I%.3f J%.3f
F%.3f\n",End[0],End[1],Center[0],Center[1],RealFeedrate);
else
TmpCode.Format("G3 X%.3f Y%.3f I%.3f J%.3f
F%.3f\n",End[0],End[1],Center[0],Center[1],RealFeedrate);
}
}
Code+=TmpCode;
if(DwellingTime>0.0f)
return (double)DwellingTime*(double)DrawingFeedPer/100.0;
else
return Length*60.0/(double)RealFeedrate;
}
double CPath::ReturnSlopeAngle()
{
float TempMove[2];
if(Circle)
{
float TmpValue[2];
TempMove[0]=AbsEndPos[0]-AbsCenterPos[0];
TempMove[1]=AbsEndPos[1]-AbsCenterPos[1];
if(CW)
{
TmpValue[0]=TempMove[1];
TmpValue[1]=TempMove[0]*(-1.0f);
}
else
{
TmpValue[0]=TempMove[1]*(-1.0f);
Nature Biotechnology: doi:10.1038/nbt.3413
TmpValue[1]=TempMove[0];
}
TempMove[0]=TmpValue[0];
TempMove[1]=TmpValue[1];
}
else
{
TempMove[0]=AbsEndPos[0]-AbsStartPos[0];
TempMove[1]=AbsEndPos[1]-AbsStartPos[1];
}
return ReturnPointAngle(TempMove);
}
double CPath::ReturnSlopeAngleOfCircleStartPoint()
{
if(Circle)
{
float TempMove[2];
float TmpValue[2];
TempMove[0]=AbsStartPos[0]-AbsCenterPos[0];
TempMove[1]=AbsStartPos[1]-AbsCenterPos[1];
if(CW)
{
TmpValue[0]=TempMove[1];
TmpValue[1]=TempMove[0]*(-1.0f);
}
else
{
TmpValue[0]=TempMove[1]*(-1.0f);
TmpValue[1]=TempMove[0];
}
TempMove[0]=TmpValue[0];
TempMove[1]=TmpValue[1];
return ReturnPointAngle(TempMove);
}
else
{
AfxMessageBox("Export Error : Angle Calcuration Error ");
return -1.0;
Nature Biotechnology: doi:10.1038/nbt.3413
}
}
double CPath::ExportFDM(CString &Code, UINT DrawingFeedPer)
{
CString TmpCode;
double Length=0.0;
float End[2];
End[0]=AbsEndPos[0]-AbsStartPos[0];
End[1]=AbsEndPos[1]-AbsStartPos[1];
float RealFeedrate;
if(Drawing)
RealFeedrate=(float)Feedrate*(float)DrawingFeedPer/100.0f;
else
RealFeedrate=(float)Feedrate;
if(Line)
{
if(DwellingTime>0.0f)
{
TmpCode.Format(" p%d\n",(int)(DwellingTime*(float)DrawingFeedPer*10.0f));
}
else
{
Length=sqrt( (double)((AbsStartPos[0]-AbsEndPos[0])*(AbsStartPos[0]-
AbsEndPos[0])+(AbsStartPos[1]-AbsEndPos[1])*(AbsStartPos[1]-AbsEndPos[1])) );
if( (int)(End[0]*1000.0f)!=0 && (int)(End[1]*1000.0f)!=0 )
TmpCode.Format(" G1 X%.3f Y%.3f F%.3f\n",End[0],End[1],RealFeedrate);
else if( (int)(End[0]*1000.0f)==0 )
TmpCode.Format(" G1 Y%.3f F%.3f\n",End[1],RealFeedrate);
else if( (int)(End[1]*1000.0f)==0 )
TmpCode.Format(" G1 X%.3f F%.3f\n",End[0],RealFeedrate);
else
AfxMessageBox("Export Error : Path Error ");
}
}
else
{
if(Circle)
{
float Center[2],Radius;
Radius=sqrt( (double)((AbsStartPos[0]-AbsCenterPos[0])*(AbsStartPos[0]-
AbsCenterPos[0])+(AbsStartPos[1]-AbsCenterPos[1])*(AbsStartPos[1]-AbsCenterPos[1])) );
Length=Radius*ReturnCircleAngle(CW,AbsStartPos,AbsEndPos,AbsCenterPos);
Center[0]=AbsCenterPos[0]-AbsStartPos[0];
Nature Biotechnology: doi:10.1038/nbt.3413
Center[1]=AbsCenterPos[1]-AbsStartPos[1];
if(CW)
TmpCode.Format(" G2 X%.3f Y%.3f R%.3f
F%.3f\n",End[0],End[1],Radius,RealFeedrate);
else
TmpCode.Format(" G3 X%.3f Y%.3f R%.3f
F%.3f\n",End[0],End[1],Radius,RealFeedrate);
}
}
Code+=TmpCode;
if(DwellingTime>0.0f)
return (double)DwellingTime*(double)DrawingFeedPer/100.0;
else
return Length*60.0/(double)RealFeedrate;
}
// OneFacetLine.h: interface for the COneFacetLine class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_ONEFACETLINE_H__4FC518B1_AA0B_4D5E_9F82_C1587CF15514__INCLUDED_)
#define AFX_ONEFACETLINE_H__4FC518B1_AA0B_4D5E_9F82_C1587CF15514__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class COneFacetLine
{
public:
void SetThisLineIsValid();
BOOL ReturnIsValidLine();
void GetCenterVertex(double TmpCenterVertex[3]);
void GetVertex(double TmpVer1[3], double TmpVer2[3]);
BOOL IsTwoLineSame(COneFacetLine TmpLine);
void SetVertex(double TmpVer1[3],double TmpVer2[3]);
COneFacetLine();
virtual ~COneFacetLine();
private:
BOOL IsValidLine;
double CenterVertex[3];
double Vertex1[3];
double Vertex2[3];
};
#endif // !defined(AFX_ONEFACETLINE_H__4FC518B1_AA0B_4D5E_9F82_C1587CF15514__INCLUDED_)
Nature Biotechnology: doi:10.1038/nbt.3413
// OneFacetLine.cpp: implementation of the COneFacetLine class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "OneFacetLine.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
COneFacetLine::COneFacetLine()
{
Vertex1[0]=0.0;Vertex1[1]=0.0;Vertex1[2]=0.0;
Vertex2[0]=0.0;Vertex2[1]=0.0;Vertex2[2]=0.0;
CenterVertex[0]=0.0;CenterVertex[1]=0.0;CenterVertex[2]=0.0;
IsValidLine=false;
}
COneFacetLine::~COneFacetLine()
{
}
void COneFacetLine::SetVertex(double TmpVer1[], double TmpVer2[])
{
Vertex1[0]=TmpVer1[0]; Vertex1[1]=TmpVer1[1]; Vertex1[2]=TmpVer1[2];
Vertex2[0]=TmpVer2[0]; Vertex2[1]=TmpVer2[1]; Vertex2[2]=TmpVer2[2];
CenterVertex[0]=(TmpVer1[0]+TmpVer2[0])/2.0;
CenterVertex[1]=(TmpVer1[1]+TmpVer2[1])/2.0;
CenterVertex[0]=(TmpVer1[2]+TmpVer2[2])/2.0;
IsValidLine=false;
}
BOOL COneFacetLine::IsTwoLineSame(COneFacetLine TmpLine)
{
double TmpLineCenterVertex[3];
TmpLine.GetCenterVertex(TmpLineCenterVertex);
if( (int)((CenterVertex[0]-TmpLineCenterVertex[0])*1000.0) != 0 )
Nature Biotechnology: doi:10.1038/nbt.3413
return false;
else if( (int)((CenterVertex[1]-TmpLineCenterVertex[1])*1000.0) != 0 )
return false;
else if( (int)((CenterVertex[2]-TmpLineCenterVertex[2])*1000.0) != 0 )
return false;
else
return true;
}
void COneFacetLine::GetVertex(double TmpVer1[], double TmpVer2[])
{
TmpVer1[0]=Vertex1[0]; TmpVer1[1]=Vertex1[1]; TmpVer1[2]=Vertex1[2];
TmpVer2[0]=Vertex2[0]; TmpVer2[1]=Vertex2[1]; TmpVer2[2]=Vertex2[2];
}
void COneFacetLine::GetCenterVertex(double TmpCenterVertex[])
{
TmpCenterVertex[0]=CenterVertex[0];
TmpCenterVertex[1]=CenterVertex[1];
TmpCenterVertex[2]=CenterVertex[2];
}
BOOL COneFacetLine::ReturnIsValidLine()
{
return IsValidLine;
}
void COneFacetLine::SetThisLineIsValid()
{
IsValidLine=true;
}
// OneFacet.h: interface for the COneFacet class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_ONEFACET_H__84E258FC_6C5B_4763_BA6A_CFDAC2F7FACE__INCLUDED_)
#define AFX_ONEFACET_H__84E258FC_6C5B_4763_BA6A_CFDAC2F7FACE__INCLUDED_
#include "TwoDLine.h"
#include "OneFacetLine.h" // Added by ClassView
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class COneFacet
{
public:
Nature Biotechnology: doi:10.1038/nbt.3413
void TransferZValue(double Value);
void SaveOrLoad(BOOL Save, CArchive &ar);
double ReturnMinYValue();
double ReturnMinXValue();
double ReturnMaxYValue();
double ReturnMaxXValue();
void GetMinAndMaxZValue(double &MinZValue, double &MaxZValue);
void SetZHeight(double ZHeight);
double ReturnCenterZValue();
void FacetZDirectOffset(double ZOffsetValue);
BOOL InsertOneFacet(double TmpVer1[3], double TmpVer2[3], double TmpVer3[3]);
COneFacetLine ReturnALineOfFacet(int LineNumber);
void GetFacetCenterPosition(double Center[3]);
void FacetTransformation(double Value[3]);
void PointRotationOnXYZ(double Point[3],int AxisNum, double CCWRotationAngle);
void PointRotationOnXY(double Point[2], double CCWRotationAngle);
void RotationXYZ(int AxisNum, double CCWRotationAngle);
void DataMagnification(double DataMagnificationFactor);
void PointPerpendicularRotationXYZ(double Point[3], int AxisNum, BOOL IsPositiveDir);
void PerpendicularRotationXYZ(int AxisNum, BOOL IsPositiveDir);
double ReturnMinZValue();
double ReturnMaxZValue();
double ReturnMax(double Tmp1, double Tmp2);
double ReturnMin(double Tmp1, double Tmp2);
BOOL InnerXY(double TmpVertex1[3], double TmpVertex2[3], double LineVertex[3]);
BOOL CalLineIntersectionValue(double TmpPoint1[3], double TmpPoint2[3], double ZPlane, double ReturnValue[3]);
BOOL CalFacetAndPlane(double ZPlane, CTwoDLine &Line);
void GetVertex123(double TmpVer1[3], double TmpVer2[3], double TmpVer3[3]);
void GetVertex123_Float(float TmpVer1[3],float TmpVer2[3],float TmpVer3[3]);
BOOL IsTwoPointsSame(double TmpVer1[3],double TmpVer2[3]);
BOOL InsertNorVec(double TmpVector[3]);
BOOL InsertVertex(int VertexNum, double TmpVertex[3]);
BOOL InsertOneFacet(double TmpVer1[3],double TmpVer2[3],double TmpVer3[3], double TmpNorVec[3]);
COneFacet();
virtual ~COneFacet();
private:
double NorVector[3];
double Vertex1[3];
double Vertex2[3];
double Vertex3[3];
};
#endif // !defined(AFX_ONEFACET_H__84E258FC_6C5B_4763_BA6A_CFDAC2F7FACE__INCLUDED_)
// OneFacet.cpp: implementation of the COneFacet class.
//
//////////////////////////////////////////////////////////////////////
Nature Biotechnology: doi:10.1038/nbt.3413
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "OneFacet.h"
#include "math.h"
#define NumErrorFindDouble 10000000.0
#define NumErrorFindInt 10000000
#define PI 3.141592
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
COneFacet::COneFacet()
{
Vertex1[0]=0.0;
Vertex1[1]=0.0;
Vertex1[2]=0.0;
Vertex2[0]=0.0;
Vertex2[1]=0.0;
Vertex2[2]=0.0;
Vertex3[0]=0.0;
Vertex3[1]=0.0;
Vertex3[2]=0.0;
NorVector[0]=0.0;
NorVector[1]=0.0;
NorVector[2]=0.0;
}
COneFacet::~COneFacet()
{
}
BOOL COneFacet::InsertOneFacet(double TmpVer1[], double TmpVer2[], double TmpVer3[], double TmpNorVec[])
{
if( InsertVertex(1,TmpVer1) * InsertVertex(2,TmpVer2) * InsertVertex(3,TmpVer3) * InsertNorVec(TmpNorVec) )
{
if( IsTwoPointsSame(TmpVer1,TmpVer2) || IsTwoPointsSame(TmpVer1,TmpVer3) ||
Nature Biotechnology: doi:10.1038/nbt.3413
IsTwoPointsSame(TmpVer2,TmpVer3) ) //세 점중 두 점이 같은 점인지 확인
return false;
else
return true;
}
else
return false;
}
BOOL COneFacet::InsertVertex(int VertexNum, double TmpVertex[])
{
switch (VertexNum)
{
case 1:
Vertex1[0]=TmpVertex[0];
Vertex1[1]=TmpVertex[1];
Vertex1[2]=TmpVertex[2];
return true;
case 2:
Vertex2[0]=TmpVertex[0];
Vertex2[1]=TmpVertex[1];
Vertex2[2]=TmpVertex[2];
return true;
case 3:
Vertex3[0]=TmpVertex[0];
Vertex3[1]=TmpVertex[1];
Vertex3[2]=TmpVertex[2];
return true;
default:
return false;
}
}
BOOL COneFacet::InsertNorVec(double TmpVector[])
{
double Length=sqrt( TmpVector[0]*TmpVector[0] + TmpVector[1]*TmpVector[1] + TmpVector[2]*TmpVector[2] );
if( (int)(Length*NumErrorFindDouble)==0 )
return false;
else if( (int)(Length*NumErrorFindDouble)!=NumErrorFindInt )
{
TmpVector[0]/=Length;
TmpVector[1]/=Length;
TmpVector[2]/=Length;
}
NorVector[0]=TmpVector[0];
NorVector[1]=TmpVector[1];
NorVector[2]=TmpVector[2];
Nature Biotechnology: doi:10.1038/nbt.3413
return true;
}
BOOL COneFacet::IsTwoPointsSame(double TmpVer1[], double TmpVer2[])
{
if( (int)(TmpVer1[0]*NumErrorFindDouble) == (int)(TmpVer2[0]*NumErrorFindDouble) &&
(int)(TmpVer1[1]*NumErrorFindDouble) == (int)(TmpVer2[1]*NumErrorFindDouble) && (int)(TmpVer1[2]*NumErrorFindDouble)
== (int)(TmpVer2[2]*NumErrorFindDouble) )
return true;
else
return false;
}
void COneFacet::GetVertex123_Float(float TmpVer1[], float TmpVer2[], float TmpVer3[])
{
for(int i=0;i<3;i++)
{
TmpVer1[i]=(float)Vertex1[i];
TmpVer2[i]=(float)Vertex2[i];
TmpVer3[i]=(float)Vertex3[i];
}
}
void COneFacet::GetVertex123(double TmpVer1[], double TmpVer2[], double TmpVer3[])
{
for(int i=0;i<3;i++)
{
TmpVer1[i]=Vertex1[i];
TmpVer2[i]=Vertex2[i];
TmpVer3[i]=Vertex3[i];
}
}
BOOL COneFacet::CalFacetAndPlane(double ZPlane, CTwoDLine &Line)
{
double TmpNumErrorFindDouble=1000.0;
double TmpVertex1[2],TmpVertex2[2],TmpVertex3[2];
double TmpNormalVector[2];
BOOL Cal1,Cal2,Cal3;
TmpVertex1[0]=Vertex1[0]; TmpVertex1[1]=Vertex1[1];
TmpVertex2[0]=Vertex2[0]; TmpVertex2[1]=Vertex2[1];
TmpVertex3[0]=Vertex3[0]; TmpVertex3[1]=Vertex3[1];
TmpNormalVector[0]=NorVector[0];
TmpNormalVector[1]=NorVector[1];
Nature Biotechnology: doi:10.1038/nbt.3413
if( (int)(ReturnMinZValue()*TmpNumErrorFindDouble+0.5)>(int)(ZPlane*TmpNumErrorFindDouble+0.5)
|| (int)(ReturnMaxZValue()*TmpNumErrorFindDouble+0.5)<(int)(ZPlane*TmpNumErrorFindDouble+0.5) )
return false;
if( (int)(Vertex1[2]*TmpNumErrorFindDouble+0.5)==(int)(ZPlane*TmpNumErrorFindDouble+0.5)
&& (int)(Vertex2[2]*TmpNumErrorFindDouble+0.5)==(int)(ZPlane*TmpNumErrorFindDouble+0.5)
&& (int)(Vertex3[2]*TmpNumErrorFindDouble+0.5)==(int)(ZPlane*TmpNumErrorFindDouble+0.5) )
return false;
if( (int)(Vertex1[2]*TmpNumErrorFindDouble+0.5)==(int)(ZPlane*TmpNumErrorFindDouble+0.5)
&& (int)(Vertex2[2]*TmpNumErrorFindDouble+0.5)==(int)(ZPlane*TmpNumErrorFindDouble+0.5) )
{
Line.InsertOneLine(TmpVertex1,TmpVertex2,TmpNormalVector);
return true;
}
if( (int)(Vertex2[2]*TmpNumErrorFindDouble+0.5)==(int)(ZPlane*TmpNumErrorFindDouble+0.5)
&& (int)(Vertex3[2]*TmpNumErrorFindDouble+0.5)==(int)(ZPlane*TmpNumErrorFindDouble+0.5) )
{
Line.InsertOneLine(TmpVertex2,TmpVertex3,TmpNormalVector);
return true;
}
if( (int)(Vertex3[2]*TmpNumErrorFindDouble+0.5)==(int)(ZPlane*TmpNumErrorFindDouble+0.5)
&& (int)(Vertex1[2]*TmpNumErrorFindDouble+0.5)==(int)(ZPlane*TmpNumErrorFindDouble+0.5) )
{
Line.InsertOneLine(TmpVertex3,TmpVertex1,TmpNormalVector);
return true;
}
Cal1=CalLineIntersectionValue(Vertex1,Vertex2,ZPlane,TmpVertex1);
Cal2=CalLineIntersectionValue(Vertex2,Vertex3,ZPlane,TmpVertex2);
Cal3=CalLineIntersectionValue(Vertex3,Vertex1,ZPlane,TmpVertex3);
if(Cal1*Cal2)
{
Line.InsertOneLine(TmpVertex1,TmpVertex2,TmpNormalVector);
return true;
}
else if(Cal2*Cal3)
{
Line.InsertOneLine(TmpVertex2,TmpVertex3,TmpNormalVector);
return true;
}
else if(Cal3*Cal1)
{
Nature Biotechnology: doi:10.1038/nbt.3413
Line.InsertOneLine(TmpVertex3,TmpVertex1,TmpNormalVector);
return true;
}
else
return false;
}
BOOL COneFacet::CalLineIntersectionValue(double TmpPoint1[], double TmpPoint2[], double ZPlane, double ReturnValue[])
{
if( (int)(TmpPoint1[2]*NumErrorFindDouble)==(int)(TmpPoint2[2]*NumErrorFindDouble) )
return false;
if(ReturnMin(TmpPoint1[2],TmpPoint2[2])>ZPlane)
return false;
if(ReturnMax(TmpPoint1[2],TmpPoint2[2])<ZPlane)
return false;
ReturnValue[0] = ( ( (TmpPoint2[0]-TmpPoint1[0]) * (ZPlane-TmpPoint1[2]) ) / (TmpPoint2[2] - TmpPoint1[2]) ) +
TmpPoint1[0];
ReturnValue[1] = ( ( (TmpPoint2[1]-TmpPoint1[1]) * (ZPlane-TmpPoint1[2]) ) / (TmpPoint2[2] - TmpPoint1[2]) ) +
TmpPoint1[1];
if( InnerXY(TmpPoint1,TmpPoint2,ReturnValue) )
return true;
else
return false;
}
BOOL COneFacet::InnerXY(double TmpVertex1[], double TmpVertex2[], double LineVertex[])
{
double MinX, MinY, MaxX, MaxY;
MinX = ReturnMin(TmpVertex1[0], TmpVertex2[0]);
MinY = ReturnMin(TmpVertex1[1], TmpVertex2[1]);
MaxX = ReturnMax(TmpVertex1[0], TmpVertex2[0]);
MaxY = ReturnMax(TmpVertex1[1], TmpVertex2[1]);
if( (LineVertex[0] >= MinX) && (LineVertex[0] <= MaxX) && (LineVertex[1] >= MinY) && (LineVertex[1] <= MaxY) )
return true;
else
return false;
}
double COneFacet::ReturnMin(double Tmp1, double Tmp2)
{
if(Tmp1>Tmp2)
return Tmp2;
Nature Biotechnology: doi:10.1038/nbt.3413
return Tmp1;
}
double COneFacet::ReturnMax(double Tmp1, double Tmp2)
{
if(Tmp1>Tmp2)
return Tmp1;
return Tmp2;
}
double COneFacet::ReturnMaxZValue()
{
double MaxZ;
MaxZ = ReturnMax(Vertex1[2], Vertex2[2]);
MaxZ = ReturnMax(MaxZ, Vertex3[2]);
return MaxZ;
}
double COneFacet::ReturnMinZValue()
{
double MinZ;
MinZ = ReturnMin(Vertex1[2], Vertex2[2]);
MinZ = ReturnMin(MinZ, Vertex3[2]);
return MinZ;
}
void COneFacet::PerpendicularRotationXYZ(int AxisNum, BOOL IsPositiveDir)
{
if(AxisNum<1 || AxisNum>3)
return;
PointPerpendicularRotationXYZ(NorVector,AxisNum,IsPositiveDir);
PointPerpendicularRotationXYZ(Vertex1,AxisNum,IsPositiveDir);
PointPerpendicularRotationXYZ(Vertex2,AxisNum,IsPositiveDir);
PointPerpendicularRotationXYZ(Vertex3,AxisNum,IsPositiveDir);
}
void COneFacet::PointPerpendicularRotationXYZ(double Point[], int AxisNum, BOOL IsPositiveDir)
{
double TmpPoint[2];
int i,j;
double MultiplyX,MultiplyY;
if(IsPositiveDir)
{
Nature Biotechnology: doi:10.1038/nbt.3413
MultiplyX=-1.0;
MultiplyY=1.0;
}
else
{
MultiplyX=1.0;
MultiplyY=-1.0;
}
if(AxisNum==1)
{
i=2; j=3;
}
else if(AxisNum==2)
{
i=3; j=1;
}
else if(AxisNum==3)
{
i=1; j=2;
}
else
return;
--i; --j;
TmpPoint[0]=Point[i];
TmpPoint[1]=Point[j];
Point[i]=TmpPoint[1]*MultiplyX;
Point[j]=TmpPoint[0]*MultiplyY;
}
void COneFacet::DataMagnification(double DataMagnificationFactor)
{
int i;
for(i=0;i<3;i++)
{
Vertex1[i]*=DataMagnificationFactor;
Vertex2[i]*=DataMagnificationFactor;
Vertex3[i]*=DataMagnificationFactor;
}
}
void COneFacet::RotationXYZ(int AxisNum, double CCWRotationAngle)
{
if(AxisNum<1 || AxisNum>3)
return;
Nature Biotechnology: doi:10.1038/nbt.3413
PointRotationOnXYZ(NorVector,AxisNum,CCWRotationAngle);
PointRotationOnXYZ(Vertex1,AxisNum,CCWRotationAngle);
PointRotationOnXYZ(Vertex2,AxisNum,CCWRotationAngle);
PointRotationOnXYZ(Vertex3,AxisNum,CCWRotationAngle);
}
void COneFacet::PointRotationOnXY(double Point[], double CCWRotationAngle)
{
double RotMat00,RotMat01,RotMat10,RotMat11;
double PaiCCWRotationAngle=CCWRotationAngle*PI/180.0;
RotMat00=cos(PaiCCWRotationAngle);
RotMat01=sin(PaiCCWRotationAngle)*-1.0;
RotMat10=sin(PaiCCWRotationAngle);
RotMat11=cos(PaiCCWRotationAngle);
double TmpPoint[2];
TmpPoint[0]=Point[0];
TmpPoint[1]=Point[1];
Point[0]=RotMat00*TmpPoint[0]+RotMat01*TmpPoint[1];
Point[1]=RotMat10*TmpPoint[0]+RotMat11*TmpPoint[1];
}
void COneFacet::PointRotationOnXYZ(double Point[], int AxisNum, double CCWRotationAngle)
{
double XYPoint[2];
if(AxisNum==1)
{
XYPoint[0]=Point[1];
XYPoint[1]=Point[2];
PointRotationOnXY(XYPoint,CCWRotationAngle);
Point[1]=XYPoint[0];
Point[2]=XYPoint[1];
}
else if(AxisNum==2)
{
XYPoint[0]=Point[0];
XYPoint[1]=Point[2];
PointRotationOnXY(XYPoint,CCWRotationAngle);
Point[0]=XYPoint[0];
Point[2]=XYPoint[1];
}
Nature Biotechnology: doi:10.1038/nbt.3413
else if(AxisNum==3)
{
XYPoint[0]=Point[0];
XYPoint[1]=Point[1];
PointRotationOnXY(XYPoint,CCWRotationAngle);
Point[0]=XYPoint[0];
Point[1]=XYPoint[1];
}
}
void COneFacet::FacetTransformation(double Value[])
{
Vertex1[0]+=Value[0];
Vertex1[1]+=Value[1];
Vertex1[2]+=Value[2];
Vertex2[0]+=Value[0];
Vertex2[1]+=Value[1];
Vertex2[2]+=Value[2];
Vertex3[0]+=Value[0];
Vertex3[1]+=Value[1];
Vertex3[2]+=Value[2];
}
void COneFacet::GetFacetCenterPosition(double Center[])
{
Center[0]=(Vertex1[0]+Vertex2[0]+Vertex3[0])/3.0;
Center[1]=(Vertex1[1]+Vertex2[1]+Vertex3[1])/3.0;
Center[2]=(Vertex1[2]+Vertex2[2]+Vertex3[2])/3.0;
}
COneFacetLine COneFacet::ReturnALineOfFacet(int LineNumber)
{
COneFacetLine TmpLine;
if(LineNumber==1)
TmpLine.SetVertex(Vertex1,Vertex2);
else if(LineNumber==2)
TmpLine.SetVertex(Vertex2,Vertex3);
else if(LineNumber==3)
TmpLine.SetVertex(Vertex3,Vertex1);
return TmpLine;
}
BOOL COneFacet::InsertOneFacet(double TmpVer1[], double TmpVer2[], double TmpVer3[])
Nature Biotechnology: doi:10.1038/nbt.3413
{
double TmpNorVec[3];
TmpNorVec[0]=1.0;TmpNorVec[1]=0.0;TmpNorVec[2]=0.0;
if( InsertVertex(1,TmpVer1) * InsertVertex(2,TmpVer2) * InsertVertex(3,TmpVer3) * InsertNorVec(TmpNorVec) )
{
if( IsTwoPointsSame(TmpVer1,TmpVer2) || IsTwoPointsSame(TmpVer1,TmpVer3) ||
IsTwoPointsSame(TmpVer2,TmpVer3) ) //세 점중 두 점이 같은 점인지 확인
return false;
else
return true;
}
else
return false;
}
void COneFacet::FacetZDirectOffset(double ZOffsetValue)
{
Vertex1[2]+=ZOffsetValue;
Vertex2[2]+=ZOffsetValue;
Vertex3[2]+=ZOffsetValue;
}
double COneFacet::ReturnCenterZValue()
{
return (Vertex1[2]+Vertex2[2]+Vertex3[2])/3.0f;
}
void COneFacet::SetZHeight(double ZHeight)
{
Vertex1[2]=ZHeight;
Vertex2[2]=ZHeight;
Vertex3[2]=ZHeight;
}
void COneFacet::GetMinAndMaxZValue(double &MinZValue, double &MaxZValue)
{
double Z1,Z2,Z3,Z4,Z5;
Z1=Vertex1[2];
Z2=Vertex2[2];
Z3=Vertex3[2];
MinZValue=min(Z1,Z2);
MinZValue=min(MinZValue,Z3);
if(MinZValue==Z1)
{
Nature Biotechnology: doi:10.1038/nbt.3413
Z4=Z2;Z5=Z3;
}
else if(MinZValue==Z2)
{
Z4=Z1;Z5=Z3;
}
else
{
Z4=Z1;Z5=Z2;
}
MaxZValue=max(Z4,Z5);
}
double COneFacet::ReturnMaxXValue()
{
double MaxX;
MaxX = ReturnMax(Vertex1[0], Vertex2[0]);
MaxX = ReturnMax(MaxX, Vertex3[0]);
return MaxX;
}
double COneFacet::ReturnMaxYValue()
{
double MaxY;
MaxY = ReturnMax(Vertex1[1], Vertex2[1]);
MaxY = ReturnMax(MaxY, Vertex3[1]);
return MaxY;
}
double COneFacet::ReturnMinXValue()
{
double MinX;
MinX = ReturnMin(Vertex1[0], Vertex2[0]);
MinX = ReturnMin(MinX, Vertex3[0]);
return MinX;
}
double COneFacet::ReturnMinYValue()
{
Nature Biotechnology: doi:10.1038/nbt.3413
double MinY;
MinY = ReturnMin(Vertex1[1], Vertex2[1]);
MinY = ReturnMin(MinY, Vertex3[1]);
return MinY;
}
void COneFacet::SaveOrLoad(BOOL Save, CArchive &ar)
{
int i;
if(Save)
{
for(i=0;i<3;i++)
ar<<NorVector[i]<<Vertex1[i]<<Vertex2[i]<<Vertex3[i];
}
else
{
for(i=0;i<3;i++)
ar>>NorVector[i]>>Vertex1[i]>>Vertex2[i]>>Vertex3[i];
}
}
void COneFacet::TransferZValue(double Value)
{
Vertex1[2]+=Value;
Vertex2[2]+=Value;
Vertex3[2]+=Value;
}
// MultiLoops.h: interface for the CMultiLoops class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MULTILOOPS_H__64CA1DDD_E463_4761_8980_E6ABD8DB3D13__INCLUDED_)
#define AFX_MULTILOOPS_H__64CA1DDD_E463_4761_8980_E6ABD8DB3D13__INCLUDED_
#include "TwoDLine.h" // Added by ClassView
#include "ClosedLoop.h"
#include <vector>
#include "Layer.h" // Added by ClassView
#include "Path.h" // Added by ClassView
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
Nature Biotechnology: doi:10.1038/nbt.3413
class CMultiLoops
{
public:
CLayer GetBeamLayerForContourLines(double LayerThickness, UINT Feedrate, BOOL IsContourBeamOn);
void Initialize();
void SaveOrLoad(BOOL Save, CArchive &ar);
double ReturnMinXValInBeamLines();
double ReturnMaxXValInBeamLines();
void GenMoldBeamLine(double Center[2], double CWRotAngle, double LinePitch, double MinMoveDis, double
ErrorOffsetValue, double MaxXForMold, double MaxYForMold, double MinXForMold, double MinYForMold);
void GenerationCrossDMDBeamLine(double Center[], double CWRotAngle, int NumOfSolidLine, int
NumOfEmptyLine, double PixelPitch);
void GenMultiOffsetDMDBeamLine(double Center[], double CWRotAngle, int NumOfSolidLine, int NumOfEmptyLine,
double PixelPitch , double OffsetStep, int NumOfOffset, double MinMoveDis, double ErrorOffsetValue);
void GenerationContourErrorOffsetBeamLine(double ErrorOffset, double MinMoveDis);
void FindOneScanPathUsingResidualTmpOtherBeamLineFromStart(double TmpVertex[2]);
void FindResidualLinesUsingTmpOtherBeamLine();
CLayer GetBeamLayer3(double LayerThickness, UINT Feedrate, BOOL IsContourBeamOn);
void FindOneScanPathUsingResidualTmpOtherBeamLine(double TmpVertex[2]);
void FindOneScanPathFromOnePoint(double TmpVertex[2]);
void GenerationOneScanBeamLine();
BOOL GenerationBeamLineAtY2(double YValue, BOOL IsRight);
void GenerationCrossBeamLine3(double Center[2], double CWRotAngle, double LinePitch);
void GenMultiOffsetBeamLine3(double Center[2], double CWRotAngle, double LinePitch, double OffsetStep, int
NumOfOffset, double MinMoveDis, double ErrorOffsetValue);
void GenerationContourBeamLine(double MinMoveDis);
void GenerationContourOffsetBeamLine(double MinMoveDis);
void DeleteOverlapOffsetLines();
void ClosedLoopLineValueRefine();
void RemoveOverLapOffsetLine();
void RemovePointOffsetLine();
void ConnetingOffsetLoops();
void GetCenterOfMultiLoops(double Center[2], int &NumOfLine);
void GenMultiOffsetBeamLine2(double Center[2], double CWRotAngle, double LinePitch, double OffsetStep, int
NumOfOffset, double MinMoveDis, double ErrorOffsetValue);
double ReturnMinYValInBeamLines();
double ReturnMaxYValInBeamLines();
void GenerationCrossBeamLine2(double Center[2], double CWRotAngle, double LinePitch);
BOOL GenerationBeamLineAtY(double YValue, BOOL IsRight);
void MultiLoopsCWRotation(double Center[2], double CWAngle);
CLayer GetBeamLayer(double LayerThickness, UINT Feedrate, BOOL IsContourBeamOn);
void GenMultiOffsetBeamLine(double OffsetStep, int NumOfOffset, double MinMoveDis, double MaxMoveDis,
double ErrorOffsetValue);
void GenerationBeamLine(double MinMoveDis, double MaxMoveDis);
void InnerOffsetDelete();
void MergeOffsetLines(double OffsetValue);
BOOL IsClosedLoopInnerOffset(CClosedLoop TestLoop);
void RemoveLoopInLoop();
BOOL LoopInLoopTest(CClosedLoop TargetLoop, CClosedLoop TestLoop);
Nature Biotechnology: doi:10.1038/nbt.3413
BOOL VectorGunTest(CTwoDLine TestLine, CClosedLoop TestLoop);
void RemovePointLine();
BOOL DoOffsetClosedLoops(double OffsetValue);
CClosedLoop GetClosedLoop(int LoopNum);
int GetNumOfClosedLoop();
void ChangeLine(int Num1,int Num2);
void ArrangeMultiLines();
BOOL ClosedLoopDistribution();
CTwoDLine GetLine(int LineNum);
double GetZValue();
int GetNumOfLine();
void PushBackLine(CTwoDLine TmpLine);
void SetZValue(double TmpZValue);
CMultiLoops();
virtual ~CMultiLoops();
private:
CLayer BeamLayer;
double ZValue;
std::vector<CTwoDLine> TmpCrossBeamLine;
std::vector<CTwoDLine> TmpOtherBeamLine;
std::vector<CTwoDLine> CrossBeamLine;
std::vector<CTwoDLine> TmpOffLines;
std::vector<CTwoDLine> Line;
std::vector<CClosedLoop> ClosedLoop;
};
#endif // !defined(AFX_MULTILOOPS_H__64CA1DDD_E463_4761_8980_E6ABD8DB3D13__INCLUDED_)
// MultiLoops.cpp: implementation of the CMultiLoops class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "MultiLoops.h"
#include "math.h"
#define NumErrorFindDouble 10000000.0
#define NumErrorFindInt 10000000
#define PI 3.141592653589793
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
Nature Biotechnology: doi:10.1038/nbt.3413
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMultiLoops::CMultiLoops()
{
ZValue=-NumErrorFindDouble;
}
CMultiLoops::~CMultiLoops()
{
TmpOffLines.clear();
Line.clear();
ClosedLoop.clear();
TmpCrossBeamLine.clear();
TmpOtherBeamLine.clear();
}
void CMultiLoops::SetZValue(double TmpZValue)
{
ZValue=TmpZValue;
}
void CMultiLoops::PushBackLine(CTwoDLine TmpLine)
{
Line.push_back(TmpLine);
}
int CMultiLoops::GetNumOfLine()
{
return Line.size();
}
double CMultiLoops::GetZValue()
{
return ZValue;
}
CTwoDLine CMultiLoops::GetLine(int LineNum)
{
return Line.at(LineNum);
}
BOOL CMultiLoops::ClosedLoopDistribution()
{
if(Line.size()<3) return false;
ArrangeMultiLines();
Nature Biotechnology: doi:10.1038/nbt.3413
int i,j;
std::vector<CTwoDLine> TmpLine;
CClosedLoop TmpClosedLoop;
double Ver1[2],Ver2[2];
int IntVer1[2],IntVer2[2],TestIntVer1[2],TestIntVer2[2];
int NumOfTmpLine;
for(i=0;i<Line.size();i++)
TmpLine.push_back(Line.at(i));
TmpLine.at(0).GetTwoPosition(Ver1,Ver2);
TmpClosedLoop.PushBackLine(TmpLine.at(0));
TmpLine.erase(&TmpLine.at(0));
for(i=0;i<2;i++)
{
IntVer1[i]=(int)(Ver1[i]*NumErrorFindDouble+0.5f);
IntVer2[i]=(int)(Ver2[i]*NumErrorFindDouble+0.5f);
}
NumOfTmpLine=TmpLine.size();
for(j=0;j<NumOfTmpLine;j++)
{
if(TmpLine.size()==0) break;
TmpLine.at(0).GetTwoPosition(Ver1,Ver2);
TmpClosedLoop.PushBackLine(TmpLine.at(0));
TmpLine.erase(&TmpLine.at(0));
for(i=0;i<2;i++)
{
TestIntVer1[i]=(int)(Ver1[i]*NumErrorFindDouble+0.5f);
TestIntVer2[i]=(int)(Ver2[i]*NumErrorFindDouble+0.5f);
}
if( IntVer1[0]==TestIntVer2[0] && IntVer1[1]==TestIntVer2[1] )
{
ClosedLoop.push_back(TmpClosedLoop);
TmpClosedLoop.Initialization();
if(NumOfTmpLine-1==j)
break;
else
j=-1;
TmpLine.at(0).GetTwoPosition(Ver1,Ver2);
TmpClosedLoop.PushBackLine(TmpLine.at(0));
TmpLine.erase(&TmpLine.at(0));
Nature Biotechnology: doi:10.1038/nbt.3413
for(i=0;i<2;i++)
{
IntVer1[i]=(int)(Ver1[i]*NumErrorFindDouble+0.5f);
IntVer2[i]=(int)(Ver2[i]*NumErrorFindDouble+0.5f);
}
NumOfTmpLine=TmpLine.size();
}
}
return true;
}
void CMultiLoops::ArrangeMultiLines()
{
int i,j,k;
int NumOfLine=Line.size();
double Ver1[2],Ver2[2],TestVer1[2],TestVer2[2];
int IntVer1[2],IntVer2[2],TestIntVer1[2],TestIntVer2[2];
for(i=0;i<NumOfLine-1;i++)
{
Line.at(i).GetTwoPosition(Ver1,Ver2);
for(k=0;k<2;k++)
{
IntVer1[k]=(int)(Ver1[k]*NumErrorFindDouble);
IntVer2[k]=(int)(Ver2[k]*NumErrorFindDouble);
}
for(j=i+1;j<NumOfLine;j++)
{
Line.at(j).GetTwoPosition(TestVer1,TestVer2);
for(k=0;k<2;k++)
{
TestIntVer1[k]=(int)(TestVer1[k]*NumErrorFindDouble);
TestIntVer2[k]=(int)(TestVer2[k]*NumErrorFindDouble);
}
if( IntVer2[0]==TestIntVer1[0] && IntVer2[1]==TestIntVer1[1] )
{
ChangeLine(i+1,j);
break;
}
if( IntVer2[0]==TestIntVer2[0] && IntVer2[1]==TestIntVer2[1] )
{
Line.at(j).DirectionChange();
Nature Biotechnology: doi:10.1038/nbt.3413
ChangeLine(i+1,j);
break;
}
}
}
}
void CMultiLoops::ChangeLine(int Num1, int Num2)
{
if( Num1>=Line.size() || Num1<0 || Num2>=Line.size() || Num2<0 )
return;
if(Num1==Num2) return;
CTwoDLine TmpLine;
TmpLine=Line.at(Num1);
Line.at(Num1)=Line.at(Num2);
Line.at(Num2)=TmpLine;
}
int CMultiLoops::GetNumOfClosedLoop()
{
return ClosedLoop.size();
}
CClosedLoop CMultiLoops::GetClosedLoop(int LoopNum)
{
return ClosedLoop.at(LoopNum);
}
BOOL CMultiLoops::DoOffsetClosedLoops(double OffsetValue)
{
BOOL IsOffsetLinePerfect=true;
int i;
for(i=0;i<ClosedLoop.size();i++)
IsOffsetLinePerfect*=ClosedLoop.at(i).DoOffsetLoop(OffsetValue);
InnerOffsetDelete();
RemoveLoopInLoop();
DeleteOverlapOffsetLines();
MergeOffsetLines(OffsetValue);
Nature Biotechnology: doi:10.1038/nbt.3413
ConnetingOffsetLoops();
return IsOffsetLinePerfect;
}
void CMultiLoops::RemovePointLine()
{
if(Line.size()==0) return;
for(int i=0;i<Line.size();i++)
{
if(Line.at(i).IsPointLine())
{
Line.erase(&Line.at(i));
i--;
}
}
}
BOOL CMultiLoops::VectorGunTest(CTwoDLine TestLine, CClosedLoop TestLoop)
{
if(TestLoop.GetNumOfLine()<3)
return false;
double Pos1[2],Pos2[2],TargetLinePos1[2],TargetLinePos2[2],TestLineNorVecCCWAngle,
LineCenter[2],RotCenter[2],JoinXPosition;
int i;
CTwoDLine TargetLine;
RotCenter[0]=0.0;
RotCenter[1]=0.0;
TestLine.GetTwoPosition(Pos1,Pos2);
TestLineNorVecCCWAngle=TestLine.GetNorVecCCWAngle();
LineCenter[0]=(Pos1[0]+Pos2[0])/(-2.0);
LineCenter[1]=(Pos1[1]+Pos2[1])/(-2.0);
for(i=0;i<TestLoop.GetNumOfLine();i++)
{
TargetLine=TestLoop.GetLine(i);
TargetLine.LineTranslation(LineCenter);
TargetLine.LineCWRotation(RotCenter,TestLineNorVecCCWAngle);
TargetLine.GetTwoPosition(TargetLinePos1,TargetLinePos2);
if( TargetLine.GetXAxisJoinPositionWithLine(JoinXPosition) )
{
Nature Biotechnology: doi:10.1038/nbt.3413
if( JoinXPosition > 0.0 ) return true;
}
}
return false;
}
BOOL CMultiLoops::LoopInLoopTest(CClosedLoop TargetLoop, CClosedLoop TestLoop)
{
BOOL IsLoopInLoop=true;
int i;
for(i=0;i<TestLoop.GetNumOfLine();i++)
{
IsLoopInLoop*=VectorGunTest(TestLoop.GetLine(i),TargetLoop);
}
return IsLoopInLoop;
}
void CMultiLoops::RemoveLoopInLoop()
{
if( ClosedLoop.size() < 2 ) return;
int i,j;
for(i=0;i<ClosedLoop.size();i++)
{
for(j=0;j<ClosedLoop.size();j++)
{
if( i!=j )
{
if(LoopInLoopTest(ClosedLoop.at(i),ClosedLoop.at(j)))
{
ClosedLoop.erase(&ClosedLoop.at(j));
if( ClosedLoop.size() < 2 ) return;
--j;
}
}
}
}
}
BOOL CMultiLoops::IsClosedLoopInnerOffset(CClosedLoop TestLoop)
{
return LoopInLoopTest(TestLoop,TestLoop);
}
Nature Biotechnology: doi:10.1038/nbt.3413
void CMultiLoops::MergeOffsetLines(double OffsetValue)
{
std::vector<CClosedLoop> TmpClosedLoop;
int i,j,NumOfClosedLoop;
NumOfClosedLoop=ClosedLoop.size();
for(i=0;i<NumOfClosedLoop;i++)
TmpClosedLoop.push_back(ClosedLoop.at(i));
for(i=0;i<NumOfClosedLoop;i++)
{
for(j=0;j<NumOfClosedLoop;j++)
{
if(i!=j)
TmpClosedLoop.at(i).OffsetLineEAreaTWithOtherClosedLoop(ClosedLoop.at(j),OffsetValue);
}
}
for(i=0;i<NumOfClosedLoop;i++)
{
ClosedLoop.at(i)=TmpClosedLoop.at(i);
ClosedLoop.at(i).OffsetLineRefineAfterMerge();
}
TmpClosedLoop.clear();
}
void CMultiLoops::InnerOffsetDelete()
{
int i;
for(i=0;i<ClosedLoop.size();i++)
{
if( IsClosedLoopInnerOffset(ClosedLoop.at(i)) )
{
ClosedLoop.erase(&ClosedLoop.at(i));
i--;
}
}
}
void CMultiLoops::GenerationBeamLine(double MinMoveDis, double MaxMoveDis)
{
int i;
Nature Biotechnology: doi:10.1038/nbt.3413
GenerationContourBeamLine(MinMoveDis);
GenerationContourOffsetBeamLine(MinMoveDis);
for(i=0;i<ClosedLoop.size();i++)
ClosedLoop.at(i).GenerationCrossBeamLine(MaxMoveDis);
}
void CMultiLoops::GenMultiOffsetBeamLine(double OffsetStep, int NumOfOffset, double MinMoveDis, double MaxMoveDis,
double ErrorOffsetValue)
{
GenerationContourBeamLine(MinMoveDis);
}
CLayer CMultiLoops::GetBeamLayer(double LayerThickness, UINT Feedrate, BOOL IsContourBeamOn)
{
int i,j;
CLayer BeamLayer;
BeamLayer.SetLayerThickness(LayerThickness);
// Contour beam을 만들어 주는 부분
for(i=0;i<ClosedLoop.size();i++)
{
if(ClosedLoop.at(i).IsMaxOffLoop() && IsContourBeamOn )
{
for(j=0;j<ClosedLoop.at(i).GetNumOfContourBeamLine();j++)
BeamLayer.PushBackPath(ClosedLoop.at(i).GetContourBeamLine(j).GetBeamPath(Feedrate));
}
if( IsContourBeamOn )
{
for(j=0;j<ClosedLoop.at(i).GetNumOfContourOffsetBeamLine();j++)
BeamLayer.PushBackPath(ClosedLoop.at(i).GetContourOffsetBeamLine(j).GetBeamPath(Feedrate));
}
}
// Cross Beam을 만들어 주는 부분
for(i=0;i<ClosedLoop.size();i++)
{
ClosedLoop.at(i).RemovePointBeamLine();
if(ClosedLoop.at(i).IsMaxOffLoop())
{
for(j=0;j<ClosedLoop.at(i).GetNumOfCrossBeamLine();j++)
BeamLayer.PushBackPath(ClosedLoop.at(i).GetCrossBeamLine(j).GetBeamPath(Feedrate));
Nature Biotechnology: doi:10.1038/nbt.3413
}
}
return BeamLayer;
}
void CMultiLoops::MultiLoopsCWRotation(double Center[], double CWAngle)
{
int i;
for(i=0;i<ClosedLoop.size();i++)
ClosedLoop.at(i).ClosedLoopCWRotation(Center,CWAngle);
}
BOOL CMultiLoops::GenerationBeamLineAtY(double YValue, BOOL IsRight)
{
std::vector<CTwoDLine> TmpLines;
std::vector<double> XValue;
int i,j,NumOfJoin;
double YDirTrans[2],Tmp1,Tmp2,TmpValue1[2],TmpValue2[2],TmpXValue[2];
CTwoDLine TmpLine;
YDirTrans[0]=0.0;
YDirTrans[1]=YValue*(-1.0);
for(i=0;i<ClosedLoop.size();i++)
{
for(j=0;j<ClosedLoop.at(i).GetNumOfContourBeamLine();j++)
TmpLines.push_back(ClosedLoop.at(i).GetContourBeamLine(j));
for(j=0;j<ClosedLoop.at(i).GetNumOfContourOffsetBeamLine();j++)
TmpLines.push_back(ClosedLoop.at(i).GetContourOffsetBeamLine(j));
}
double TmpMaxLengthForCrossLine=10.0;
for(i=0;i<TmpLines.size();i++)
{
TmpLines.at(i).LineTranslation(YDirTrans);
if(TmpLines.at(i).GetXAxisJoinPositionWithLine(TmpXValue,NumOfJoin))
{
XValue.push_back(TmpXValue[0]);
if(NumOfJoin==2)
XValue.push_back(TmpXValue[1]);
}
}
Nature Biotechnology: doi:10.1038/nbt.3413
if(IsRight)
{
for(i=0; i<XValue.size(); ++i)
for(j=i; j<XValue.size(); ++j)
{
if(XValue.at(i)>XValue.at(j))
{
Tmp1=XValue.at(i);
Tmp2=XValue.at(j);
XValue.insert(&XValue.at(i),Tmp2);
XValue.erase(&XValue.at(i+1));
XValue.insert(&XValue.at(j),Tmp1);
XValue.erase(&XValue.at(j+1));
}
}
}
else
{
for(i=0; i<XValue.size(); ++i)
for(j=i; j<XValue.size(); ++j)
{
if(XValue.at(i)<XValue.at(j))
{
Tmp1=XValue.at(i);
Tmp2=XValue.at(j);
XValue.insert(&XValue.at(i),Tmp2);
XValue.erase(&XValue.at(i+1));
XValue.insert(&XValue.at(j),Tmp1);
XValue.erase(&XValue.at(j+1));
}
}
}
if(XValue.size()%2==0)
{
for(i=0;i<XValue.size();i+=2)
{
TmpValue1[0]=XValue.at(i);
TmpValue1[1]=YValue;
TmpValue2[0]=XValue.at(i+1);
TmpValue2[1]=YValue;
TmpLine.SetVertex1(TmpValue1);
TmpLine.SetVertex2(TmpValue2);
CrossBeamLine.push_back( TmpLine );
}
TmpLines.clear();
Nature Biotechnology: doi:10.1038/nbt.3413
XValue.clear();
return true;
}
else
{
/////////////////////
for(i=0;i<XValue.size()-1;i+=2)
{
TmpValue1[0]=XValue.at(i);
TmpValue1[1]=YValue;
TmpValue2[0]=XValue.at(i+1);
TmpValue2[1]=YValue;
TmpLine.SetVertex1(TmpValue1);
TmpLine.SetVertex2(TmpValue2);
CrossBeamLine.push_back( TmpLine );
}
TmpValue1[0]=XValue.at(i);
TmpValue1[1]=YValue;
TmpLines.clear();
XValue.clear();
return true;
}
}
void CMultiLoops::GenerationCrossBeamLine2(double Center[], double CWRotAngle, double LinePitch)
{
std::vector<CClosedLoop> TmpClosedLoop;
int i,Num;
BOOL IsRight;
double MinY,MaxY,TmpY;
// 쉽게 최 외곽 offset만 나두고 지우기.
for(i=0;i<ClosedLoop.size();i++)
{
if(!ClosedLoop.at(i).IsMaxOffLoop())
{
ClosedLoop.erase(&ClosedLoop.at(i));
i--;
}
}
if(ClosedLoop.size()==0)
return;
for(i=0;i<ClosedLoop.size();i++)
Nature Biotechnology: doi:10.1038/nbt.3413
{
ClosedLoop.at(i).InitializationCrossBeamLine();
TmpClosedLoop.push_back(ClosedLoop.at(i));
ClosedLoop.at(i).ClosedLoopCWRotation(Center,CWRotAngle);
}
MinY=ReturnMinYValInBeamLines();
MaxY=ReturnMaxYValInBeamLines();
Num=0;
double TotalLength=fabs(MaxY-MinY);
int NumOfPitch=(int)(TotalLength/LinePitch); // Center에서 시작하게 하기 위해서 추가되 코드 20090210
double CompensationValue=0.0;
if ( TotalLength-LinePitch*(double)NumOfPitch < 0.0001f )
CompensationValue=LinePitch/2.0;
else
CompensationValue=(LinePitch+(TotalLength-LinePitch*(double)NumOfPitch))/2.0;
for(TmpY=MinY+CompensationValue;TmpY<MaxY;TmpY+=LinePitch)
{
if(Num%2==0)
IsRight=true;
else
IsRight=false;
GenerationBeamLineAtY(TmpY,IsRight);
Num++;
}
for(i=0;i<CrossBeamLine.size();i++)
{
CrossBeamLine.at(i).LineCWRotation(Center,CWRotAngle*(-1.0));
TmpClosedLoop.at(0).InsertCrossBeamLine(CrossBeamLine.at(i));
}
ClosedLoop.clear();
for(i=0;i<TmpClosedLoop.size();i++)
ClosedLoop.push_back(TmpClosedLoop.at(i));
TmpClosedLoop.clear();
}
double CMultiLoops::ReturnMaxYValInBeamLines()
{
double ReturnYVal=NumErrorFindDouble*(-1.0);
int i;
Nature Biotechnology: doi:10.1038/nbt.3413
for(i=0;i<ClosedLoop.size();i++)
{
if(ReturnYVal<ClosedLoop.at(i).ReturnMaxYValInBeamLines())
ReturnYVal=ClosedLoop.at(i).ReturnMaxYValInBeamLines();
}
return ReturnYVal;
}
double CMultiLoops::ReturnMinYValInBeamLines()
{
double ReturnYVal=NumErrorFindDouble;
int i;
for(i=0;i<ClosedLoop.size();i++)
{
if(ReturnYVal>ClosedLoop.at(i).ReturnMinYValInBeamLines())
ReturnYVal=ClosedLoop.at(i).ReturnMinYValInBeamLines();
}
return ReturnYVal;
}
void CMultiLoops::GenMultiOffsetBeamLine2(double Center[], double CWRotAngle, double LinePitch, double OffsetStep, int
NumOfOffset, double MinMoveDis, double ErrorOffsetValue)
{
// 각도에 따라 수평으로 Crossbeam을 만듦
int i,j;
std::vector<CClosedLoop> TmpClosedLoop;
GenerationContourErrorOffsetBeamLine(ErrorOffsetValue,MinMoveDis);
for(j=0;j<ClosedLoop.size();j++)
ClosedLoop.at(j).InitializationWithoutLineOffsetBeamLine();
GenerationCrossBeamLine2(Center,CWRotAngle,LinePitch);
for(j=0;j<ClosedLoop.size();j++)
{
ClosedLoop.at(j).SetIsMaxOffsetLoop(true);
TmpClosedLoop.push_back(ClosedLoop.at(j));
}
ClosedLoop.clear();
Nature Biotechnology: doi:10.1038/nbt.3413
for(i=0;i<TmpClosedLoop.size();i++)
ClosedLoop.push_back(TmpClosedLoop.at(i));
TmpClosedLoop.clear();
}
void CMultiLoops::GetCenterOfMultiLoops(double Center[], int &NumOfLine)
{
int i,TotalNumOfLine;
double TmpCenter[2],SumX,SumY;
SumX=0.0;
SumY=0.0;
TotalNumOfLine=0;
for(i=0;i<ClosedLoop.size();i++)
TotalNumOfLine+=ClosedLoop.at(i).GetNumOfLine();
for(i=0;i<ClosedLoop.size();i++)
{
ClosedLoop.at(i).GetCenterOfClosedLoop(TmpCenter);
SumX+=(TmpCenter[0]*(double)ClosedLoop.at(i).GetNumOfLine());
SumY+=(TmpCenter[1]*(double)ClosedLoop.at(i).GetNumOfLine());
}
if(TotalNumOfLine!=0)
{
Center[0]=SumX/(double)TotalNumOfLine;
Center[1]=SumY/(double)TotalNumOfLine;
}
else
{
Center[0]=0.0;
Center[1]=0.0;
}
NumOfLine=TotalNumOfLine;
}
void CMultiLoops::ConnetingOffsetLoops()
{
// ClosedLoop들 간에 OffsetLine을 연결시켜 주는 역할.
if(ClosedLoop.size()<2)
return ;
int i,j,k,SEOffsetMode,SEOffsetNum,ConnecttedClosedLoopNum,SEOffSetValNum,TmpSEOffSetValNum;
double SEOffsetValues[2], SEOffValNorVec[2],TmpMinLength;
Nature Biotechnology: doi:10.1038/nbt.3413
CTwoDLine TmpLine,MinLengthLine;
BOOL IsConnected=false;
int ttt;
for(i=0;i<ClosedLoop.size();i++)
ClosedLoop.at(i).FindSEXYOffsetVal();
for(i=0;i<ClosedLoop.size();i++)
{
for(j=0;j<ClosedLoop.at(i).GetNumOfSEOffsetVal();j++)
{
ttt=ClosedLoop.at(i).GetNumOfSEOffsetVal();
ClosedLoop.at(i).GetSEOffsetValuesAndNorVec(j,SEOffsetValues,SEOffValNorVec,SEOffsetNum,SEOffsetMode);
TmpMinLength=10000000.0;
IsConnected=true;
for(k=i+1;k<ClosedLoop.size();k++)
{
if( ClosedLoop.at(k).CheckConnectingWithOffsetLines(SEOffsetValues,SEOffValNorVec,TmpLine,TmpSEOffSetVal
Num) )
{
if(ClosedLoop.at(k).GetNumOfSEOffsetVal()!=0)
{
IsConnected=true;
ClosedLoop.at(k).EraseSEXYOffsetVal(TmpSEOffSetValNum);
break;
}
}
else
{
IsConnected=false;
if(TmpMinLength>TmpLine.GetLength())
{
ConnecttedClosedLoopNum=k;
TmpMinLength=TmpLine.GetLength();
MinLengthLine=TmpLine;
SEOffSetValNum=TmpSEOffSetValNum;
}
}
}
if(!IsConnected)
{
if(SEOffsetMode==1)
Nature Biotechnology: doi:10.1038/nbt.3413
{
ClosedLoop.at(i).InsertOffsetLine(SEOffsetNum,MinLengthLine);
ClosedLoop.at(i).UsedSEOffsetNumForConnecting(SEOffsetNum);
}
else
{
ClosedLoop.at(i).InsertOffsetLine(SEOffsetNum+1,MinLengthLine);
ClosedLoop.at(i).UsedSEOffsetNumForConnecting(SEOffsetNum+1);
}
ClosedLoop.at(ConnecttedClosedLoopNum).EraseSEXYOffsetVal(SEOffSetValNum);
}
}
}
}
void CMultiLoops::RemovePointOffsetLine()
{
for(int i=0;i<ClosedLoop.size();i++)
ClosedLoop.at(i).RemovePointOffsetLine();
}
void CMultiLoops::RemoveOverLapOffsetLine()
{
for(int i=0;i<ClosedLoop.size();i++)
ClosedLoop.at(i).RemoveOverLapOffsetLine();
}
void CMultiLoops::ClosedLoopLineValueRefine()
{
int i;
for(i=0;i<ClosedLoop.size();i++)
ClosedLoop.at(i).LineValueRefine();
}
void CMultiLoops::DeleteOverlapOffsetLines()
{
int i,j;
for(i=0;i<ClosedLoop.size();i++)
{
for(j=0;j<ClosedLoop.size();j++)
{
if(i!=j)
ClosedLoop.at(i).DeleteOverlapOffsetLines(ClosedLoop.at(j));
}
}
}
Nature Biotechnology: doi:10.1038/nbt.3413
void CMultiLoops::GenerationContourOffsetBeamLine(double MinMoveDis)
{
int i;
for(i=0;i<ClosedLoop.size();i++)
{
ClosedLoop.at(i).GenerationContourOffsetBeamLine(MinMoveDis);
ClosedLoop.at(i).ArrangeContourOffsetBeamLine();
}
}
void CMultiLoops::GenerationContourBeamLine(double MinMoveDis)
{
int i;
RemoveLoopInLoop();
for(i=0;i<ClosedLoop.size();i++)
{
ClosedLoop.at(i).GenerationContourBeamLine(MinMoveDis);
}
}
void CMultiLoops::GenMultiOffsetBeamLine3(double Center[], double CWRotAngle, double LinePitch, double OffsetStep, int
NumOfOffset, double MinMoveDis, double ErrorOffsetValue)
{
// Path의 한붓 그리기 실행
int i,j;
std::vector<CClosedLoop> TmpClosedLoop;
GenerationContourErrorOffsetBeamLine(ErrorOffsetValue,MinMoveDis);
for(j=0;j<ClosedLoop.size();j++)
ClosedLoop.at(j).InitializationWithoutLineOffsetBeamLine();
DoOffsetClosedLoops(OffsetStep*(double)NumOfOffset+ErrorOffsetValue);
GenerationContourOffsetBeamLine(MinMoveDis);
GenerationCrossBeamLine3(Center,CWRotAngle,LinePitch); /// path를 한 붓 그리기 하기 위한 함수 내부에 포함.
for(j=0;j<ClosedLoop.size();j++)
{
ClosedLoop.at(j).SetIsMaxOffsetLoop(true);
TmpClosedLoop.push_back(ClosedLoop.at(j));
}
for(i=1;i<NumOfOffset;i++)
{
Nature Biotechnology: doi:10.1038/nbt.3413
for(j=0;j<ClosedLoop.size();j++)
ClosedLoop.at(j).InitializationWithoutLine();
DoOffsetClosedLoops(OffsetStep*(double)(i)+ErrorOffsetValue);
// GenerationContourBeamLine(MinMoveDis);
GenerationContourOffsetBeamLine(MinMoveDis);
for(j=0;j<ClosedLoop.size();j++)
{
ClosedLoop.at(j).SetIsMaxOffsetLoop(false);
TmpClosedLoop.push_back(ClosedLoop.at(j));
}
}
ClosedLoop.clear();
for(i=0;i<TmpClosedLoop.size();i++)
ClosedLoop.push_back(TmpClosedLoop.at(i));
TmpClosedLoop.clear();
}
void CMultiLoops::GenerationCrossBeamLine3(double Center[], double CWRotAngle, double LinePitch)
{
int i,Num;
BOOL IsRight;
double MinY,MaxY,TmpY;
// 쉽게 최 외곽 offset만 나두고 지우기.
for(i=0;i<ClosedLoop.size();i++)
{
if(!ClosedLoop.at(i).IsMaxOffLoop())
{
ClosedLoop.erase(&ClosedLoop.at(i));
i--;
}
}
if(ClosedLoop.size()==0)
return;
for(i=0;i<ClosedLoop.size();i++)
{
ClosedLoop.at(i).InitializationCrossBeamLine();
ClosedLoop.at(i).ClosedLoopCWRotation(Center,CWRotAngle);
}
MinY=ReturnMinYValInBeamLines();
Nature Biotechnology: doi:10.1038/nbt.3413
MaxY=ReturnMaxYValInBeamLines();
Num=0;
/////////// 층간 선 중첩을 위한 MinY 수정
MinY=(double)((int)(MinY/LinePitch))*LinePitch;
if(MinY>0)
MinY+=LinePitch;
///////////
double CompensationValue=0.0; //LinePitch/2.0; // Cell Path 만들기 위한 부분
for(TmpY=MinY+CompensationValue;TmpY<MaxY;TmpY+=LinePitch)
{
if(Num%2==0)
IsRight=true;
else
IsRight=false;
GenerationBeamLineAtY2(TmpY,IsRight);
Num++;
}
for(i=0;i<CrossBeamLine.size();i++)
ClosedLoop.at(0).InsertCrossBeamLine(CrossBeamLine.at(i));
// 한붓 그리기 위한 알고리즘 추가.
GenerationOneScanBeamLine();
CrossBeamLine.clear();
for(i=0;i<ClosedLoop.size();i++)
ClosedLoop.at(i).ClosedLoopCWRotation(Center,CWRotAngle*(-1.0));
}
BOOL CMultiLoops::GenerationBeamLineAtY2(double YValue, BOOL IsRight)
{
std::vector<double> XValue;
int i,j,NumOfJoin;
double YDirTrans[2],InterSectionPoint[2],Tmp1,Tmp2,TmpValue1[2],TmpValue2[2],TmpXValue[2];
CTwoDLine TmpLine;
YDirTrans[0]=0.0;
YDirTrans[1]=YValue*(-1.0);
InterSectionPoint[0]=0.0;
InterSectionPoint[1]=YValue;
Nature Biotechnology: doi:10.1038/nbt.3413
for(i=0;i<ClosedLoop.size();i++)
{
for(j=0;j<ClosedLoop.at(i).GetNumOfContourBeamLine();j++)
{
TmpLine=ClosedLoop.at(i).GetContourBeamLine(j);
TmpLine.LineTranslation(YDirTrans);
if(TmpLine.GetXAxisJoinPositionWithLine(TmpXValue,NumOfJoin))
{
XValue.push_back(TmpXValue[0]);
if(NumOfJoin==2)
XValue.push_back(TmpXValue[1]);
else
{
InterSectionPoint[0]=TmpXValue[0];
if( ClosedLoop.at(i).DivideLineOfContourBeamLine(j,InterSectionPoint) )
j++;
}
}
}
for(j=0;j<ClosedLoop.at(i).GetNumOfContourOffsetBeamLine();j++)
{
TmpLine=ClosedLoop.at(i).GetContourOffsetBeamLine(j);
TmpLine.LineTranslation(YDirTrans);
if(TmpLine.GetXAxisJoinPositionWithLine(TmpXValue,NumOfJoin))
{
XValue.push_back(TmpXValue[0]);
if(NumOfJoin==2)
XValue.push_back(TmpXValue[1]);
else
{
InterSectionPoint[0]=TmpXValue[0];
if( ClosedLoop.at(i).DivideLineOfContourOffsetBeamLine(j,InterSectionPoint) )
j++;
}
}
}
}
if(IsRight)
{
for(i=0; i<XValue.size(); ++i)
Nature Biotechnology: doi:10.1038/nbt.3413
for(j=i; j<XValue.size(); ++j)
{
if(XValue.at(i)>XValue.at(j))
{
Tmp1=XValue.at(i);
Tmp2=XValue.at(j);
XValue.insert(&XValue.at(i),Tmp2);
XValue.erase(&XValue.at(i+1));
XValue.insert(&XValue.at(j),Tmp1);
XValue.erase(&XValue.at(j+1));
}
}
}
else
{
for(i=0; i<XValue.size(); ++i)
for(j=i; j<XValue.size(); ++j)
{
if(XValue.at(i)<XValue.at(j))
{
Tmp1=XValue.at(i);
Tmp2=XValue.at(j);
XValue.insert(&XValue.at(i),Tmp2);
XValue.erase(&XValue.at(i+1));
XValue.insert(&XValue.at(j),Tmp1);
XValue.erase(&XValue.at(j+1));
}
}
}
if(XValue.size()%2==0)
{
for(i=0;i<XValue.size();i+=2)
{
TmpValue1[0]=XValue.at(i);
TmpValue1[1]=YValue;
TmpValue2[0]=XValue.at(i+1);
TmpValue2[1]=YValue;
TmpLine.SetVertex1(TmpValue1);
TmpLine.SetVertex2(TmpValue2);
CrossBeamLine.push_back( TmpLine );
}
XValue.clear();
return true;
Nature Biotechnology: doi:10.1038/nbt.3413
}
else
{
XValue.clear();
return false;
}
}
void CMultiLoops::GenerationOneScanBeamLine()
{
if(ClosedLoop.size()<1)
return;
CTwoDLine TmpLine,TmpLine2;
double TmpVertex2[2];
int i,j;
TmpCrossBeamLine.clear();
TmpOtherBeamLine.clear();
for(i=0;i<ClosedLoop.at(0).GetNumOfCrossBeamLine();i++)
TmpCrossBeamLine.push_back(ClosedLoop.at(0).GetCrossBeamLine(i));
for(i=0;i<ClosedLoop.size();i++)
{
for(j=0;j<ClosedLoop.at(i).GetNumOfContourBeamLine();j++)
TmpOtherBeamLine.push_back(ClosedLoop.at(i).GetContourBeamLine(j));
for(j=0;j<ClosedLoop.at(i).GetNumOfContourOffsetBeamLine();j++)
TmpOtherBeamLine.push_back(ClosedLoop.at(i).GetContourOffsetBeamLine(j));
}
for(i=0;i<TmpOtherBeamLine.size();i++)
TmpOtherBeamLine.at(i).MakeYPositiveDirection();
while(TmpCrossBeamLine.size()!=0)
{
TmpLine=TmpCrossBeamLine.at(0);
TmpCrossBeamLine.erase(&TmpCrossBeamLine.at(0));
ClosedLoop.at(0).PushBackOneScanBeamLine(TmpLine);
TmpLine.GetVertex2(TmpVertex2);
// TmpVertex2를 기점으로 해서 끝까지 찾아가는 함수를 만들자.
FindOneScanPathFromOnePoint(TmpVertex2); // Y + 방향만 찾아 가도록 만들었음.
}
// 찾아진 path를 바탕으로 다른 방향의 새로운 선들을 찾아서 넣자.
Nature Biotechnology: doi:10.1038/nbt.3413
FindResidualLinesUsingTmpOtherBeamLine();
ClosedLoop.at(0).ArrangeOneScanBeamLine();
}
void CMultiLoops::FindOneScanPathFromOnePoint(double TmpVertex[])
{
int i;
BOOL IsVertex1;
double TmpVertex2[2];
CTwoDLine TmpLine;
for(i=0;i<TmpCrossBeamLine.size();i++)
{
if( TmpCrossBeamLine.at(i).IsThereSamePosition(TmpVertex,IsVertex1) )
{
TmpLine=TmpCrossBeamLine.at(i);
TmpCrossBeamLine.erase(&TmpCrossBeamLine.at(i));
if(!IsVertex1)
TmpLine.InverseLineDirection();
ClosedLoop.at(0).PushBackOneScanBeamLine(TmpLine);
TmpLine.GetVertex2(TmpVertex2);
TmpVertex[0]=TmpVertex2[0];
TmpVertex[1]=TmpVertex2[1];
break;
}
}
for(i=0;i<TmpOtherBeamLine.size();i++)
{
if( TmpOtherBeamLine.at(i).IsSamePositionWithVertex1(TmpVertex) )
{
TmpLine=TmpOtherBeamLine.at(i);
TmpOtherBeamLine.erase(&TmpOtherBeamLine.at(i));
ClosedLoop.at(0).PushBackOneScanBeamLine(TmpLine);
TmpLine.GetVertex2(TmpVertex2);
FindOneScanPathFromOnePoint(TmpVertex2);
break;
}
}
}
void CMultiLoops::FindOneScanPathUsingResidualTmpOtherBeamLine(double TmpVertex[])
{
// 꼬리에서 찾기 시작하는 것.
int i;
Nature Biotechnology: doi:10.1038/nbt.3413
BOOL IsVertex1;
double TmpVertex2[2];
CTwoDLine TmpLine;
for(i=0;i<TmpOtherBeamLine.size();i++)
{
if( TmpOtherBeamLine.at(i).IsThereSamePosition(TmpVertex,IsVertex1) )
{
TmpLine=TmpOtherBeamLine.at(i);
TmpOtherBeamLine.erase(&TmpOtherBeamLine.at(i));
if(!IsVertex1)
TmpLine.InverseLineDirection();
ClosedLoop.at(0).PushBackOneScanBeamLine(TmpLine);
TmpLine.GetVertex2(TmpVertex2);
FindOneScanPathUsingResidualTmpOtherBeamLine(TmpVertex2);
}
}
}
CLayer CMultiLoops::GetBeamLayer3(double LayerThickness, UINT Feedrate, BOOL IsContourBeamOn)
{
// 한붓 그리기 한기 위하여 만들어진 것을 출력
int i,j;
CLayer BeamLayer;
BeamLayer.SetLayerThickness(LayerThickness);
if(ClosedLoop.size()==0)
return BeamLayer;
// 한붓 그리기 한기 위하여 만들어진 것을 출력
for(j=0;j<ClosedLoop.at(0).GetNumOfOneScanBeamLine();j++)
BeamLayer.PushBackPath(ClosedLoop.at(0).GetOneScanBeamLine(j).GetBeamPath(Feedrate));
// 다른 Offset Line들을 출력
for(i=0;i<ClosedLoop.size();i++)
{
if( !ClosedLoop.at(i).IsMaxOffLoop() && IsContourBeamOn )
{
for(j=0;j<ClosedLoop.at(i).GetNumOfContourOffsetBeamLine();j++)
BeamLayer.PushBackPath(ClosedLoop.at(i).GetContourOffsetBeamLine(j).GetBeamPath(Feedrate));
}
}
return BeamLayer;
Nature Biotechnology: doi:10.1038/nbt.3413
}
void CMultiLoops::FindResidualLinesUsingTmpOtherBeamLine()
{
if( ClosedLoop.at(0).GetNumOfOneScanBeamLine()==0 || TmpOtherBeamLine.size()==0 )
return;
int i,TmpNumOfOneScanBeamLine;
CTwoDLine TmpLine,TmpLine2;
double TmpVertex1[2],TmpVertex2[2];
TmpLine=ClosedLoop.at(0).GetOneScanBeamLine(0);
TmpLine.GetVertex1(TmpVertex1);
FindOneScanPathUsingResidualTmpOtherBeamLineFromStart(TmpVertex1);
for(i=0;i<ClosedLoop.at(0).GetNumOfOneScanBeamLine()-1;i++)
{
TmpNumOfOneScanBeamLine=ClosedLoop.at(0).GetNumOfOneScanBeamLine();
TmpLine=ClosedLoop.at(0).GetOneScanBeamLine(i);
TmpLine2=ClosedLoop.at(0).GetOneScanBeamLine(i+1);
if(!TmpLine.IsTheComparedLineConnected(TmpLine2,21))
{
TmpLine.GetVertex2(TmpVertex2);
FindOneScanPathUsingResidualTmpOtherBeamLine(TmpVertex2);
TmpLine2.GetVertex1(TmpVertex1);
FindOneScanPathUsingResidualTmpOtherBeamLineFromStart(TmpVertex1);
i+=(ClosedLoop.at(0).GetNumOfOneScanBeamLine()-TmpNumOfOneScanBeamLine);
}
}
TmpLine=ClosedLoop.at(0).GetOneScanBeamLine(ClosedLoop.at(0).GetNumOfOneScanBeamLine()-1);
TmpLine.GetVertex2(TmpVertex2);
FindOneScanPathUsingResidualTmpOtherBeamLine(TmpVertex2);
}
void CMultiLoops::FindOneScanPathUsingResidualTmpOtherBeamLineFromStart(double TmpVertex[])
{
// 머리에서 찾기 시작하는 것.
int i;
double TmpVertex2[2];
CTwoDLine TmpLine;
for(i=0;i<TmpOtherBeamLine.size();i++)
Nature Biotechnology: doi:10.1038/nbt.3413
{
if(TmpOtherBeamLine.at(i).IsSamePositionWithVertex2(TmpVertex))
{
TmpLine=TmpOtherBeamLine.at(i);
TmpOtherBeamLine.erase(&TmpOtherBeamLine.at(i));
TmpLine.InverseLineDirection();
ClosedLoop.at(0).PushBackOneScanBeamLine(TmpLine);
TmpLine.GetVertex2(TmpVertex2);
FindOneScanPathUsingResidualTmpOtherBeamLine(TmpVertex2);
}
}
}
void CMultiLoops::GenerationContourErrorOffsetBeamLine(double ErrorOffset, double MinMoveDis)
{
int i;
for(i=0;i<ClosedLoop.size();i++)
ClosedLoop.at(i).InitializationWithoutLine();
if(ErrorOffset==0.0)
GenerationContourBeamLine(MinMoveDis);
else
{
DoOffsetClosedLoops(ErrorOffset);
GenerationContourOffsetBeamLine(MinMoveDis);
for(i=0;i<ClosedLoop.size();i++)
ClosedLoop.at(i).OverWriteOffsetCBLToCBL();
}
}
void CMultiLoops::GenMultiOffsetDMDBeamLine(double Center[], double CWRotAngle, int NumOfSolidLine, int
NumOfEmptyLine, double PixelPitch , double OffsetStep, int NumOfOffset, double MinMoveDis, double ErrorOffsetValue)
{
// 각도에 따라 수평으로 Crossbeam을 만듦
if(NumOfSolidLine <= 0 || PixelPitch <= 0 )
return;
int i,j;
std::vector<CClosedLoop> TmpClosedLoop;
if( MinMoveDis < 0.001 ) MinMoveDis=0.0;
GenerationContourErrorOffsetBeamLine(ErrorOffsetValue,MinMoveDis);
Nature Biotechnology: doi:10.1038/nbt.3413
for(j=0;j<ClosedLoop.size();j++)
ClosedLoop.at(j).InitializationWithoutLineOffsetBeamLine();
DoOffsetClosedLoops(OffsetStep*(double)NumOfOffset+ErrorOffsetValue);
GenerationContourOffsetBeamLine(MinMoveDis);
GenerationCrossDMDBeamLine(Center,CWRotAngle,NumOfSolidLine,NumOfEmptyLine, PixelPitch);
for(j=0;j<ClosedLoop.size();j++)
{
ClosedLoop.at(j).SetIsMaxOffsetLoop(true);
TmpClosedLoop.push_back(ClosedLoop.at(j));
}
for(i=1;i<NumOfOffset;i++)
{
for(j=0;j<ClosedLoop.size();j++)
ClosedLoop.at(j).InitializationWithoutLine();
DoOffsetClosedLoops(OffsetStep*(double)(i)+ErrorOffsetValue);
GenerationContourOffsetBeamLine(MinMoveDis);
for(j=0;j<ClosedLoop.size();j++)
{
ClosedLoop.at(j).SetIsMaxOffsetLoop(false);
TmpClosedLoop.push_back(ClosedLoop.at(j));
}
}
ClosedLoop.clear();
for(i=0;i<TmpClosedLoop.size();i++)
ClosedLoop.push_back(TmpClosedLoop.at(i));
TmpClosedLoop.clear();
}
void CMultiLoops::GenerationCrossDMDBeamLine(double Center[], double CWRotAngle, int NumOfSolidLine, int
NumOfEmptyLine, double PixelPitch)
{
std::vector<CClosedLoop> TmpClosedLoop;
int i;
double MinY,MaxY,TmpY;
for(i=0;i<ClosedLoop.size();i++)
{
if(!ClosedLoop.at(i).IsMaxOffLoop())
Nature Biotechnology: doi:10.1038/nbt.3413
{
ClosedLoop.erase(&ClosedLoop.at(i));
i--;
}
}
if(ClosedLoop.size()==0)
return;
for(i=0;i<ClosedLoop.size();i++)
{
ClosedLoop.at(i).InitializationCrossBeamLine();
TmpClosedLoop.push_back(ClosedLoop.at(i));
ClosedLoop.at(i).ClosedLoopCWRotation(Center,CWRotAngle);
}
MinY=ReturnMinYValInBeamLines();
MaxY=ReturnMaxYValInBeamLines();
for(TmpY=MinY;TmpY<MaxY;TmpY+=PixelPitch*(double)(NumOfSolidLine+NumOfEmptyLine))
{
for(i=0;i<NumOfSolidLine;i++)
{
GenerationBeamLineAtY(TmpY+PixelPitch*(double)i,true);
}
}
for(i=0;i<CrossBeamLine.size();i++)
{
CrossBeamLine.at(i).LineCWRotation(Center,CWRotAngle*(-1.0));
TmpClosedLoop.at(0).InsertCrossBeamLine(CrossBeamLine.at(i));
}
ClosedLoop.clear();
for(i=0;i<TmpClosedLoop.size();i++)
ClosedLoop.push_back(TmpClosedLoop.at(i));
TmpClosedLoop.clear();
}
void CMultiLoops::GenMoldBeamLine(double Center[], double CWRotAngle, double LinePitch, double MinMoveDis, double
ErrorOffsetValue, double MaxXForMold, double MaxYForMold, double MinXForMold, double MinYForMold)
{
int i,j;
std::vector<CClosedLoop> TmpClosedLoop;
Nature Biotechnology: doi:10.1038/nbt.3413
GenerationContourErrorOffsetBeamLine(ErrorOffsetValue,MinMoveDis);
for(j=0;j<ClosedLoop.size();j++)
ClosedLoop.at(j).InitializationWithoutLineOffsetBeamLine();
ClosedLoop.at(0).InsertRecMoldLineToContourOffsetBeamLine(MaxXForMold,MaxYForMold,MinXForMold,MinYFo
rMold);
GenerationContourOffsetBeamLine(MinMoveDis);
GenerationCrossBeamLine3(Center,CWRotAngle,LinePitch);
for(j=0;j<ClosedLoop.size();j++)
{
ClosedLoop.at(j).SetIsMaxOffsetLoop(true);
TmpClosedLoop.push_back(ClosedLoop.at(j));
}
ClosedLoop.clear();
for(i=0;i<TmpClosedLoop.size();i++)
ClosedLoop.push_back(TmpClosedLoop.at(i));
TmpClosedLoop.clear();
}
double CMultiLoops::ReturnMaxXValInBeamLines()
{
double ReturnXVal=NumErrorFindDouble*(-1.0);
double TmpXVal;
int i;
for(i=0;i<ClosedLoop.size();i++)
{
TmpXVal=ClosedLoop.at(i).ReturnMaxXValInBeamLines();
if(ReturnXVal<TmpXVal)
ReturnXVal=TmpXVal;
}
return ReturnXVal;
}
double CMultiLoops::ReturnMinXValInBeamLines()
{
double ReturnXVal=NumErrorFindDouble;
int i;
Nature Biotechnology: doi:10.1038/nbt.3413
for(i=0;i<ClosedLoop.size();i++)
{
if(ReturnXVal>ClosedLoop.at(i).ReturnMinXValInBeamLines())
ReturnXVal=ClosedLoop.at(i).ReturnMinXValInBeamLines();
}
return ReturnXVal;
}
void CMultiLoops::SaveOrLoad(BOOL Save, CArchive &ar)
{
int i,TmpNum;
BeamLayer.LayerSaveOrLoad(Save,ar);
if(Save)
{
ar<<ZValue;
TmpNum=TmpCrossBeamLine.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
TmpCrossBeamLine.at(i).SaveOrLoad(Save,ar);
TmpNum=TmpOtherBeamLine.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
TmpOtherBeamLine.at(i).SaveOrLoad(Save,ar);
TmpNum=CrossBeamLine.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
CrossBeamLine.at(i).SaveOrLoad(Save,ar);
TmpNum=TmpOffLines.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
TmpOffLines.at(i).SaveOrLoad(Save,ar);
TmpNum=Line.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
Line.at(i).SaveOrLoad(Save,ar);
TmpNum=ClosedLoop.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
ClosedLoop.at(i).SaveOrLoad(Save,ar);
Nature Biotechnology: doi:10.1038/nbt.3413
}
else
{
Initialize();
CTwoDLine TmpLine;
CClosedLoop TmpClosedLoop;
ar>>ZValue;
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
{
TmpLine.SaveOrLoad(Save,ar);
TmpCrossBeamLine.push_back(TmpLine);
}
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
{
TmpLine.SaveOrLoad(Save,ar);
TmpOtherBeamLine.push_back(TmpLine);
}
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
{
TmpLine.SaveOrLoad(Save,ar);
CrossBeamLine.push_back(TmpLine);
}
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
{
TmpLine.SaveOrLoad(Save,ar);
TmpOffLines.push_back(TmpLine);
}
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
{
TmpLine.SaveOrLoad(Save,ar);
Line.push_back(TmpLine);
}
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
{
Nature Biotechnology: doi:10.1038/nbt.3413
TmpClosedLoop.Initialization();
TmpClosedLoop.SaveOrLoad(Save,ar);
ClosedLoop.push_back(TmpClosedLoop);
}
}
}
void CMultiLoops::Initialize()
{
BeamLayer.InitializeLayer(0.1);
ZValue=0.0;
TmpCrossBeamLine.clear();
TmpOtherBeamLine.clear();
CrossBeamLine.clear();
TmpOffLines.clear();
Line.clear();
ClosedLoop.clear();
}
CLayer CMultiLoops::GetBeamLayerForContourLines(double LayerThickness, UINT Feedrate, BOOL IsContourBeamOn)
{
int i,j;
CLayer BeamLayer;
BeamLayer.SetLayerThickness(LayerThickness);
// Contour beam을 만들어 주는 부분
for(i=0;i<ClosedLoop.size();i++)
{
if(ClosedLoop.at(i).IsMaxOffLoop() && IsContourBeamOn )
{
for(j=0;j<ClosedLoop.at(i).GetNumOfContourBeamLine();j++)
BeamLayer.PushBackPath(ClosedLoop.at(i).GetContourBeamLine(j).GetBeamPath(Feedrate));
}
if( IsContourBeamOn )
{
for(j=0;j<ClosedLoop.at(i).GetNumOfContourOffsetBeamLine();j++)
BeamLayer.PushBackPath(ClosedLoop.at(i).GetContourOffsetBeamLine(j).GetBeamPath(Feedrate));
}
}
return BeamLayer;
}
Nature Biotechnology: doi:10.1038/nbt.3413
// MultiFacets.h: interface for the CMultiFacets class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MULTIFACETS_H__8107EE5D_FBF6_4A28_BD0A_C69AEEDB2737__INCLUDED_)
#define AFX_MULTIFACETS_H__8107EE5D_FBF6_4A28_BD0A_C69AEEDB2737__INCLUDED_
#include "OneFacet.h" // Added by ClassView
#include <vector>
#include <fstream.h>
#include "MultiLoops.h"
#include "Product.h" // Added by ClassView
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMultiFacets
{
public:
void GenVerticalPath();
CProduct GetBeamProduct4(UINT Power, UINT Feedrate, int RepeatingIndex);
void GenerationBeamLine4(double DifCWRotAngle, double LinePitch, double OffsetStep, int NumOfOffset, double
MinMoveDis, double ErrorOffsetValue, int NumOfDirectionOverLab, int RepeatingIndex);
void GenerationCrossProfile(double TmpLayThick, double StartZValue, double EndZValue);
void MakeMinZToZero();
void Initialize();
void SaveOrLoad(BOOL Save, CArchive &ar);
double GetMinYValueInSTLFile();
double GetMinXValueInSTLFile();
double GetMaxYValueInSTLFile();
double GetMaxXValueInSTLFile();
double ReturnMinYValInBeamLines();
double ReturnMaxYValInBeamLines();
double ReturnMinXValInBeamLines();
double ReturnMaxXValInBeamLines();
void GenerationMoldBeamLine(double DifCWRotAngle, double LinePitch, double MinMoveDis, double
ErrorOffsetValue, int NumOfDirectionOverLab, double MoldOffsetSize);
void Smoothing2DSurface();
void GenerationFrom2DTo3D_FlatSurface(double ZOffsetThickness);
void GenerationFrom2DTo3D(double ZOffsetThickness);
void MoveToCenterPosition();
void GetMultiFacetCenterPosition(double Center[3]);
void FacetTransformation(double Value[3]);
void FacetRotaionXYZ(int AxisNum, double CCWRotationAngle);
BOOL ReturnThreeNumberOfSTLOneLine(CString OneLine, double ReturnNum[3]);
BOOL LoadForAscii(CArchive &ar, int MaxNumOfFacet, double DataMagnificationFactor);
void GenerationDMDBeamLine(double DifCWRotAngle, int NumOfSolidLine, int NumOfEmptyLine, double
Nature Biotechnology: doi:10.1038/nbt.3413
PixelPitch , double OffsetStep, int NumOfOffset, double MinMoveDis, double ErrorOffsetValue, int NumOfDirectionOverLab);
void DataMagnification(double DataMagnificationFactor);
CProduct GetBeamProduct3(UINT Power, UINT Feedrate);
void GenerationBeamLine3(double DifCWRotAngle, double LinePitch, double OffsetStep, int NumOfOffset, double
MinMoveDis, double ErrorOffsetValue, int NumOfDirectionOverLab);
void GenerationBeamLine2(double DifCWRotAngle, double LinePitch, double OffsetStep, int NumOfOffset, double
MinMoveDis, double ErrorOffsetValue, int NumOfDirectionOverLab);
void GetRotationCenter(double Center[2]);
void LoopsRotaton(double Center[2], double CWAngle);
CProduct GetBeamProduct(UINT Power, UINT Feedrate, int Mode);
void GenerationBeamLine(double OffsetStep, int NumOfOffset, double MinMoveDis, double MaxMoveDis, double
ErrorOffsetValue);
void DoOffset(double OffsetValue);
void NormalVectorCorrection(double TmpNorVec[3]);
void FacetPerpendicularRotaionXYZ(int AxisNum, BOOL IsPositiveDirection);
void Initialization();
CMultiLoops GetLoops(int LoopsNum);
int GetNumOfLoops();
double GetMinZValueInSTLFile();
double GetMaxZValueInSTLFile();
void GenerationCrossProfile(double LayerThickness);
void PushBackMultiLoops(CMultiLoops TmpLoops);
BOOL CalCrossProfileAtZ(double ZValue);
BOOL GetFacet(COneFacet &TmpFacet,int FacetNumber);
int GetNumOfFacet();
void PushBackFacet(COneFacet TmpFacet);
BOOL LoadForBinay(CArchive &ar, int MaxNumOfFacet, double DataMagnificationFactor);
CMultiFacets();
virtual ~CMultiFacets();
private:
double LayerThickness;
std::vector<COneFacet> Facet;
std::vector<CMultiLoops> Loops;
};
#endif // !defined(AFX_MULTIFACETS_H__8107EE5D_FBF6_4A28_BD0A_C69AEEDB2737__INCLUDED_)
// MultiFacets.cpp: implementation of the CMultiFacets class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "MultiFacets.h"
#include "OneFacet.h"
#include "ProgressBar.h"
#include "OneFacetLine.h"
Nature Biotechnology: doi:10.1038/nbt.3413
#define NumErrorFindDouble 10000000.0
#define NumErrorFindInt 10000000
#define PI 3.141592653589793
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMultiFacets::CMultiFacets()
{
}
CMultiFacets::~CMultiFacets()
{
Facet.clear();
Loops.clear();
}
BOOL CMultiFacets::LoadForBinay(CArchive &ar, int MaxNumOfFacet, double DataMagnificationFactor)
{
Initialization();
COneFacet TmpFacet;
int j;
unsigned int Tmp;
float Value0[3],Value1[3],Value2[3],Value3[3];
double DoubleVal0[3],DoubleVal1[3],DoubleVal2[3],DoubleVal3[3];
unsigned long int NumOfFacet;
char tmp[80];
ar.Read(tmp,80);
ar.Read(&NumOfFacet,sizeof(unsigned long int));
// if(NumOfFacet>MaxNumOfFacet) return false;
for(unsigned long int i=0;i<NumOfFacet;i++)
{
ar.Read(Value0,sizeof(float)*3);
ar.Read(Value1,sizeof(float)*3);
ar.Read(Value2,sizeof(float)*3);
ar.Read(Value3,sizeof(float)*3);
Nature Biotechnology: doi:10.1038/nbt.3413
ar.Read(&Tmp,2);
for(j=0;j<3;j++)
{
DoubleVal0[j]=(double)Value0[j]*DataMagnificationFactor;
DoubleVal1[j]=(double)Value1[j]*DataMagnificationFactor;
DoubleVal2[j]=(double)Value2[j]*DataMagnificationFactor;
DoubleVal3[j]=(double)Value3[j]*DataMagnificationFactor;
// DoubleVal0[j]=((double)((int)(DoubleVal0[j]*NumErrorFindDouble)))/NumErrorFindDouble;
// DoubleVal1[j]=((double)((int)(DoubleVal1[j]*NumErrorFindDouble)))/NumErrorFindDouble;
// DoubleVal2[j]=((double)((int)(DoubleVal2[j]*NumErrorFindDouble)))/NumErrorFindDouble;
// DoubleVal3[j]=((double)((int)(DoubleVal3[j]*NumErrorFindDouble)))/NumErrorFindDouble;
}
// NormalVectorCorrection(DoubleVal0); // 치아의 stl 파일 땜시 넣었음.
/* if( !TmpFacet.InsertOneFacet(DoubleVal1,DoubleVal2,DoubleVal3,DoubleVal0) )
return false;
PushBackFacet(TmpFacet);
*/
if( TmpFacet.InsertOneFacet(DoubleVal1,DoubleVal2,DoubleVal3,DoubleVal0) )
// TmpFacet.InsertOneFacet(DoubleVal1,DoubleVal2,DoubleVal3,DoubleVal0);
PushBackFacet(TmpFacet);
}
MoveToCenterPosition();
MakeMinZToZero();
return true;
}
void CMultiFacets::PushBackFacet(COneFacet TmpFacet)
{
Facet.push_back(TmpFacet);
}
int CMultiFacets::GetNumOfFacet()
{
return Facet.size();
}
BOOL CMultiFacets::GetFacet(COneFacet &TmpFacet,int FacetNumber)
{
if( FacetNumber<0 || FacetNumber>=Facet.size() )
return false;
Nature Biotechnology: doi:10.1038/nbt.3413
else
{
TmpFacet=Facet.at(FacetNumber);
return true;
}
}
BOOL CMultiFacets::CalCrossProfileAtZ(double ZValue)
{
CMultiLoops TmpMultiLoops;
CTwoDLine TmpLine;
TmpMultiLoops.SetZValue(ZValue);
for(int i=0;i<Facet.size();++i)
{
if( Facet.at(i).CalFacetAndPlane(ZValue,TmpLine) )
{
TmpMultiLoops.PushBackLine(TmpLine);
}
}
// if(!TmpMultiLine.RemoveRedundantLines() && TmpMultiLine.ReturnNumOfLine()!=0)
// return false;
if( TmpMultiLoops.GetNumOfLine() != 0)
PushBackMultiLoops(TmpMultiLoops);
// 임시로 stop 한것.
// if(!TmpMultiLine.CloseLoopTest() && TmpMultiLine.ReturnNumOfLine()!=0)
// return false;
return true;
}
void CMultiFacets::PushBackMultiLoops(CMultiLoops TmpLoops)
{
Loops.push_back(TmpLoops);
}
void CMultiFacets::GenerationCrossProfile(double TmpLayThick)
{
int i;
if(Facet.size()==0) return;
LayerThickness=TmpLayThick;
Loops.clear();
Nature Biotechnology: doi:10.1038/nbt.3413
double MaxZ,MinZ,TmpZValue;
MaxZ=GetMaxZValueInSTLFile();
MinZ=GetMinZValueInSTLFile();
CProgressBar Bar(_T("Slice CAD Model"),(int)((MaxZ-MinZ)/TmpLayThick+0.5));
for(TmpZValue=MinZ+TmpLayThick;TmpZValue<=MaxZ;TmpZValue+=TmpLayThick)
{
if(!CalCrossProfileAtZ(TmpZValue))
{
AfxMessageBox("단면 Loop 생성에 문제가 있습니다.");
return;
}
Bar.ProgressBarExpress();
}
/*
for(i=0;i<Loops.size();i++)
{
Loops.at(i).RemovePointLine();
if(Loops.at(i).GetNumOfLine()<3)
{
Loops.erase(&Loops.at(i));
--i;
}
}
*/
for(i=0;i<Loops.size();i++)
{
if(!Loops.at(i).ClosedLoopDistribution())
{
// Loops.erase(&Loops.at(i));
// --i;
}
}
/*
for(i=0;i<Loops.size();i++)
{
Loops.at(i).ClosedLoopLineValueRefine();
}
*/
}
Nature Biotechnology: doi:10.1038/nbt.3413
double CMultiFacets::GetMaxZValueInSTLFile()
{
int NumOfFacet=Facet.size();
if(NumOfFacet==0) return 0.0;
float MaxZ=Facet.at(0).ReturnMaxZValue();
for(int i=1;i<NumOfFacet;i++)
MaxZ=max(MaxZ,Facet.at(i).ReturnMaxZValue());
return MaxZ;
}
double CMultiFacets::GetMinZValueInSTLFile()
{
int NumOfFacet=Facet.size();
if(Facet.size()==0) return 0.0f;
float MinZ=Facet.at(0).ReturnMinZValue();
for(int i=1;i<NumOfFacet;i++)
MinZ=min(MinZ,Facet.at(i).ReturnMinZValue());
return MinZ;
}
int CMultiFacets::GetNumOfLoops()
{
return Loops.size();
}
CMultiLoops CMultiFacets::GetLoops(int LoopsNum)
{
return Loops.at(LoopsNum);
}
void CMultiFacets::Initialization()
{
Facet.clear();
Loops.clear();
}
void CMultiFacets::FacetPerpendicularRotaionXYZ(int AxisNum, BOOL IsPositiveDirection)
{
int i;
for(i=0;i<Facet.size();i++)
Nature Biotechnology: doi:10.1038/nbt.3413
Facet.at(i).PerpendicularRotationXYZ(AxisNum, IsPositiveDirection);
}
void CMultiFacets::NormalVectorCorrection(double TmpNorVec[])
{
double Factor[3];
Factor[0]=-1.0;
Factor[1]=1.0; // 치아 data가 이상해서 넣음 부부임.(다른 것에서는 필요 없을것 같음)
Factor[2]=1.0;
for(int i=0;i<3;i++)
TmpNorVec[i]*=Factor[i];
}
void CMultiFacets::DoOffset(double OffsetValue)
{
BOOL IsOffsetLinePerfect=true;
CProgressBar Bar(_T("Profile Offset"),Loops.size());
for(int i=0;i<Loops.size();i++)
{
IsOffsetLinePerfect*=Loops.at(i).DoOffsetClosedLoops(OffsetValue);
Bar.ProgressBarExpress();
}
// if(!IsOffsetLinePerfect)
// AfxMessageBox("Offset 선이 연속적이 못하여, 끊어진 부분이 자동으로 연결되었습니다. or Line
Crosspoint Caculation Error");
}
void CMultiFacets::GenerationBeamLine(double OffsetStep, int NumOfOffset, double MinMoveDis, double MaxMoveDis,
double ErrorOffsetValue)
{
CProgressBar Bar(_T("Beam Generation"),Loops.size());
for(int i=0;i<Loops.size();i++)
{
Loops.at(i).GenMultiOffsetBeamLine(OffsetStep,NumOfOffset,MinMoveDis,MaxMoveDis,ErrorOffsetValue);
Bar.ProgressBarExpress();
}
}
CProduct CMultiFacets::GetBeamProduct(UINT Power, UINT Feedrate, int Mode)
{
Nature Biotechnology: doi:10.1038/nbt.3413
CProduct BeamProduct;
BOOL IsContourBeamOn=true; // outline 빼려면 false 지정 할것.
if(Mode==1)
IsContourBeamOn=true;
else
IsContourBeamOn=false;
BeamProduct.InitializeProduct();
BeamProduct.SetPower(Power);
///////////////////// 2010.12.31 Unit-Based CAM 을 위하여 추가
double TmpLayerThickness;
//////////////////////
for(int i=0;i<Loops.size();i++)
{
/* if(i%2==0)
IsContourBeamOn=true;
else
IsContourBeamOn=false;
*/
// if(i==0)
// TmpLayerThickness=LayerThickness/2.0;
// else
TmpLayerThickness=LayerThickness;
//GenerationBeamLine 과 GenerationBeamLine2의 경우 사용
BeamProduct.PushBackLayer(Loops.at(i).GetBeamLayer(TmpLayerThickness,Feedrate,IsContourBeamOn));
}
return BeamProduct;
}
void CMultiFacets::LoopsRotaton(double Center[], double CWAngle)
{
int i;
for(i=0;i<Loops.size();i++)
Loops.at(i).MultiLoopsCWRotation(Center, CWAngle);
}
void CMultiFacets::GetRotationCenter(double Center[])
{
Nature Biotechnology: doi:10.1038/nbt.3413
int i,TmpNumOfLine,TotalNumOfLine;
double TmpCenter[2],SumX,SumY;
TotalNumOfLine=0;
SumX=0.0;
SumY=0.0;
for(i=0;i<Loops.size();i++)
{
Loops.at(i).GetCenterOfMultiLoops(TmpCenter,TmpNumOfLine);
TotalNumOfLine+=TmpNumOfLine;
SumX+=TmpCenter[0];
SumY+=TmpCenter[1];
}
Center[0]=SumX/(double)TotalNumOfLine;
Center[1]=SumY/(double)TotalNumOfLine;
}
void CMultiFacets::GenerationBeamLine2(double DifCWRotAngle, double LinePitch, double OffsetStep, int NumOfOffset,
double MinMoveDis, double ErrorOffsetValue, int NumOfDirectionOverLab)
{
double TotalCenter[2];
int i,MultiplyRotAng;
MultiplyRotAng=-1;
GetRotationCenter(TotalCenter);
CProgressBar Bar(_T("Beam Generation"),Loops.size());
for(i=0;i<Loops.size();i++)
{
if(i%NumOfDirectionOverLab==0)
MultiplyRotAng++;
Loops.at(i).GenMultiOffsetBeamLine2(TotalCenter,DifCWRotAngle*(double)MultiplyRotAng,LinePitch,OffsetStep,Nu
mOfOffset,MinMoveDis,ErrorOffsetValue);
Bar.ProgressBarExpress();
}
}
void CMultiFacets::GenerationBeamLine3(double DifCWRotAngle, double LinePitch, double OffsetStep, int NumOfOffset,
double MinMoveDis, double ErrorOffsetValue, int NumOfDirectionOverLab)
{
double TotalCenter[2];
int i,MultiplyRotAng;
Nature Biotechnology: doi:10.1038/nbt.3413
MultiplyRotAng=-1;
GetRotationCenter(TotalCenter);
CProgressBar Bar(_T("Beam Generation"),Loops.size());
for(i=0;i<Loops.size();i++)
{
if(i%NumOfDirectionOverLab==0)
MultiplyRotAng++;
Loops.at(i).GenMultiOffsetBeamLine3(TotalCenter,DifCWRotAngle*(double)MultiplyRotAng,LinePitch,OffsetStep,Nu
mOfOffset,MinMoveDis,ErrorOffsetValue);
Bar.ProgressBarExpress();
}
}
CProduct CMultiFacets::GetBeamProduct3(UINT Power, UINT Feedrate)
{
CProduct BeamProduct;
BOOL IsContourBeamOn=true;
BeamProduct.InitializeProduct();
BeamProduct.SetPower(Power);
for(int i=0;i<Loops.size();i++)
{
/* if(i%2==0)
IsContourBeamOn=true;
else
IsContourBeamOn=false;
*/
//GenerationBeamLine3의 경우 사용
BeamProduct.PushBackLayer(Loops.at(i).GetBeamLayer3(LayerThickness,Feedrate,IsContourBeamOn));
}
return BeamProduct;
}
void CMultiFacets::DataMagnification(double DataMagnificationFactor)
{
int NumOfFacet=Facet.size();
int i;
double TmpRotCenter[3];
Nature Biotechnology: doi:10.1038/nbt.3413
GetMultiFacetCenterPosition(TmpRotCenter);
for(i=0;i<3;i++)
TmpRotCenter[i]*=(-1.0);
FacetTransformation(TmpRotCenter);
for(i=0;i<NumOfFacet;i++)
Facet.at(i).DataMagnification(DataMagnificationFactor);
for(i=0;i<3;i++)
TmpRotCenter[i]*=(-1.0);
FacetTransformation(TmpRotCenter);
}
void CMultiFacets::GenerationDMDBeamLine(double DifCWRotAngle, int NumOfSolidLine, int NumOfEmptyLine, double
PixelPitch ,double OffsetStep, int NumOfOffset, double MinMoveDis, double ErrorOffsetValue, int NumOfDirectionOverLab)
{
double TotalCenter[2];
int i,MultiplyRotAng;
MultiplyRotAng=-1;
GetRotationCenter(TotalCenter);
CProgressBar Bar(_T("Beam Generation"),Loops.size());
for(i=0;i<Loops.size();i++)
{
if(i%NumOfDirectionOverLab==0)
MultiplyRotAng++;
Loops.at(i).GenMultiOffsetDMDBeamLine(TotalCenter,DifCWRotAngle*(double)MultiplyRotAng,NumOfSolidLine,Nu
mOfEmptyLine,PixelPitch,OffsetStep,NumOfOffset,MinMoveDis,ErrorOffsetValue);
Bar.ProgressBarExpress();
}
}
BOOL CMultiFacets::LoadForAscii(CArchive &ar, int MaxNumOfFacet, double DataMagnificationFactor)
{
DataMagnificationFactor=1.0; // 임시.
Initialization();
CString TmpString;
double TmpNum[3];
// int j;
COneFacet TmpFacet;
Nature Biotechnology: doi:10.1038/nbt.3413
ar.ReadString(TmpString); // 첫줄 비우기
TmpString.Empty();
ar.ReadString(TmpString);
while( ReturnThreeNumberOfSTLOneLine(TmpString, TmpNum) )
{
// for(j=0;j<3;j++)
// {
// TmpNum[j]=((double)((int)(TmpNum[j]*NumErrorFindDouble)))/NumErrorFindDouble;
// }
TmpFacet.InsertNorVec(TmpNum);
TmpString.Empty();
ar.ReadString(TmpString);
// TmpFacet.SetOuterLoop(TmpString);
TmpString.Empty();
ar.ReadString(TmpString);
ReturnThreeNumberOfSTLOneLine(TmpString, TmpNum );
// for(j=0;j<3;j++)
// {
// TmpNum[j]*=DataMagnificationFactor;
// TmpNum[j]=((double)((int)(TmpNum[j]*NumErrorFindDouble)))/NumErrorFindDouble;
// }
TmpFacet.InsertVertex(1,TmpNum);
TmpString.Empty();
ar.ReadString(TmpString);
ReturnThreeNumberOfSTLOneLine( TmpString, TmpNum );
// for(j=0;j<3;j++)
// {
// TmpNum[j]*=DataMagnificationFactor;
// TmpNum[j]=((double)((int)(TmpNum[j]*NumErrorFindDouble)))/NumErrorFindDouble;
// }
TmpFacet.InsertVertex(2,TmpNum);
TmpString.Empty();
ar.ReadString(TmpString);
ReturnThreeNumberOfSTLOneLine( TmpString, TmpNum );
// for(j=0;j<3;j++)
// {
// TmpNum[j]*=DataMagnificationFactor;
// TmpNum[j]=((double)((int)(TmpNum[j]*NumErrorFindDouble)))/NumErrorFindDouble;
// }
TmpFacet.InsertVertex(3,TmpNum);
TmpString.Empty();
ar.ReadString(TmpString); // 마지말 두 줄 지우기
Nature Biotechnology: doi:10.1038/nbt.3413
TmpString.Empty();
ar.ReadString(TmpString);
TmpString.Empty();
PushBackFacet(TmpFacet);
ar.ReadString(TmpString);
}
if( Facet.size()==0 )
{
AfxMessageBox("STL파일을 확인 바랍니다.");
return false;
}
MoveToCenterPosition();
MakeMinZToZero();
return true;
}
BOOL CMultiFacets::ReturnThreeNumberOfSTLOneLine(CString OneLine, double ReturnNum[])
{
CString EndString=OneLine.Left(3);
EndString.MakeLower();
CString ThreeNum,Left,Mid,Right;
int NumPos;
if(EndString=="end")
return false;
OneLine.TrimRight();
NumPos=OneLine.ReverseFind(' ');
Right=OneLine.Right(OneLine.GetLength()-NumPos);
OneLine=OneLine.Left(NumPos);
OneLine.TrimRight();
NumPos=OneLine.ReverseFind(' ');
Mid=OneLine.Right(OneLine.GetLength()-NumPos);
OneLine=OneLine.Left(NumPos);
OneLine.TrimRight();
NumPos=OneLine.ReverseFind(' ');
Left=OneLine.Right(OneLine.GetLength()-NumPos);
OneLine=OneLine.Left(NumPos);
ReturnNum[0]=atof(Left);
ReturnNum[1]=atof(Mid);
ReturnNum[2]=atof(Right)*-1.0; // -1.0은 임시 경신이 CAD 파일 땜시 넣어 놓았음.
Nature Biotechnology: doi:10.1038/nbt.3413
if(ReturnNum[2]>30.0)
ReturnNum[0]=ReturnNum[0];
return true;
}
void CMultiFacets::FacetRotaionXYZ(int AxisNum, double CCWRotationAngle)
{
int i;
double TmpRotCenter[3];
GetMultiFacetCenterPosition(TmpRotCenter);
for(i=0;i<3;i++)
TmpRotCenter[i]*=(-1.0);
FacetTransformation(TmpRotCenter);
for(i=0;i<Facet.size();i++)
Facet.at(i).RotationXYZ(AxisNum, CCWRotationAngle);
for(i=0;i<3;i++)
TmpRotCenter[i]*=(-1.0);
FacetTransformation(TmpRotCenter);
}
void CMultiFacets::FacetTransformation(double Value[])
{
int i;
for(i=0;i<Facet.size();i++)
Facet.at(i).FacetTransformation(Value);
}
void CMultiFacets::GetMultiFacetCenterPosition(double Center[])
{
double TmpCenter[3];
Center[0]=0.0;
Center[1]=0.0;
Center[2]=0.0;
int i;
Nature Biotechnology: doi:10.1038/nbt.3413
for(i=0;i<Facet.size();i++)
{
Facet.at(i).GetFacetCenterPosition(TmpCenter);
Center[0]+=TmpCenter[0];
Center[1]+=TmpCenter[1];
Center[2]+=TmpCenter[2];
}
Center[0]/=Facet.size();
Center[1]/=Facet.size();
Center[2]/=Facet.size();
}
void CMultiFacets::MoveToCenterPosition()
{
int i;
double Center[3];
GetMultiFacetCenterPosition(Center);
for(i=0;i<3;i++)
Center[i]*=(-1.0);
for(i=0;i<Facet.size();i++)
Facet.at(i).FacetTransformation(Center);
}
void CMultiFacets::GenerationFrom2DTo3D(double ZOffsetThickness)
{
if(Facet.size()==0)
return;
// 외부 선인지를 체크하기 위한 함수 추가. 하나의 선은 꼭 두번씩만 사용되어야 한다.
std::vector<COneFacetLine> Line;
std::vector<COneFacetLine> Line2;
int i,j,MaxSearchNumberOfLine;
double SearchPercent=5.0;
for(i=0;i<Facet.size();i++)
{
for(j=1;j<=3;j++)
Line.push_back(Facet.at(i).ReturnALineOfFacet(j));
}
MaxSearchNumberOfLine=3;
for(i=0;i<Line.size();i++)
Nature Biotechnology: doi:10.1038/nbt.3413
{
for(j=i+1;j<Line.size();j++)
{
if(j>i+MaxSearchNumberOfLine)
break;
if(Line.at(i).ReturnIsValidLine())
break;
if(!Line.at(j).ReturnIsValidLine())
{
if(Line.at(i).IsTwoLineSame(Line.at(j)))
{
Line.at(i).SetThisLineIsValid();
Line.at(j).SetThisLineIsValid();
break;
}
}
}
}
for(i=0;i<Line.size();i++)
{
if(!Line.at(i).ReturnIsValidLine())
Line2.push_back(Line.at(i));
}
Line.clear();
MaxSearchNumberOfLine=(int)(Line2.size()*SearchPercent/100.0);
CProgressBar Bar(_T("Construction 3-D Object Model"),Line2.size());
for(i=0;i<Line2.size();i++)
{
for(j=i+1;j<Line2.size();j++)
{
if(j>i+MaxSearchNumberOfLine)
break;
if(Line2.at(i).ReturnIsValidLine())
break;
if(!Line2.at(j).ReturnIsValidLine())
{
if(Line2.at(i).IsTwoLineSame(Line2.at(j)))
{
Line2.at(i).SetThisLineIsValid();
Line2.at(j).SetThisLineIsValid();
break;
Nature Biotechnology: doi:10.1038/nbt.3413
}
}
}
Bar.ProgressBarExpress();
}
for(i=0;i<Line2.size();i++)
{
if(!Line2.at(i).ReturnIsValidLine())
Line.push_back(Line2.at(i));
}
Line2.clear();
for(i=0;i<Line.size();i++)
{
for(j=i+1;j<Line.size();j++)
{
if(Line.at(i).ReturnIsValidLine())
break;
if(!Line.at(j).ReturnIsValidLine())
{
if(Line.at(i).IsTwoLineSame(Line.at(j)))
{
Line.at(i).SetThisLineIsValid();
Line.at(j).SetThisLineIsValid();
break;
}
}
}
}
for(i=0;i<Line.size();i++)
{
if(!Line.at(i).ReturnIsValidLine())
Line2.push_back(Line.at(i));
}
Line.clear();
for(i=0;i<Line2.size();i++)
Line.push_back(Line2.at(i));
Line2.clear();
// 기존 Surface의 Offseting이 필요 (윗쪽 방향으로 Offset)
COneFacet TmpFacet;
Nature Biotechnology: doi:10.1038/nbt.3413
std::vector<COneFacet> TmpFacetArray;
for(i=0;i<Facet.size();i++)
{
TmpFacet=Facet.at(i);
TmpFacet.FacetZDirectOffset(ZOffsetThickness);
TmpFacetArray.push_back(TmpFacet);
}
for(i=0;i<TmpFacetArray.size();i++)
Facet.push_back(TmpFacetArray.at(i));
TmpFacetArray.clear();
// 외부 선을 바탕으로 3차원 Facet을 추가하기 위한 함수 추가. (Facet 생성 및 임시 저장)
double TmpVer1[3],TmpVer2[3],NewTmpVer1[3],NewTmpVer2[3];
for(i=0;i<Line.size();i++)
{
Line.at(i).GetVertex(TmpVer1,TmpVer2);
NewTmpVer1[0]=TmpVer1[0];NewTmpVer1[1]=TmpVer1[1];NewTmpVer1[2]=TmpVer1[2]+ZOffsetThickness;
NewTmpVer2[0]=TmpVer2[0];NewTmpVer2[1]=TmpVer2[1];NewTmpVer2[2]=TmpVer2[2]+ZOffsetThickness;
TmpFacet.InsertOneFacet(TmpVer1,TmpVer2,NewTmpVer1);
Facet.push_back(TmpFacet);
TmpFacet.InsertOneFacet(NewTmpVer2,NewTmpVer1,TmpVer2);
Facet.push_back(TmpFacet);
}
}
void CMultiFacets::GenerationFrom2DTo3D_FlatSurface(double ZOffsetThickness)
{
if(Facet.size()==0)
return;
// 외부 선인지를 체크하기 위한 함수 추가. 하나의 선은 꼭 두번씩만 사용되어야 한다.
std::vector<COneFacetLine> Line;
std::vector<COneFacetLine> Line2;
int i,j,MaxSearchNumberOfLine;
double SearchPercent=5.0;
Nature Biotechnology: doi:10.1038/nbt.3413
for(i=0;i<Facet.size();i++)
{
for(j=1;j<=3;j++)
Line.push_back(Facet.at(i).ReturnALineOfFacet(j));
}
MaxSearchNumberOfLine=3;
for(i=0;i<Line.size();i++)
{
for(j=i+1;j<Line.size();j++)
{
if(j>i+MaxSearchNumberOfLine)
break;
if(Line.at(i).ReturnIsValidLine())
break;
if(!Line.at(j).ReturnIsValidLine())
{
if(Line.at(i).IsTwoLineSame(Line.at(j)))
{
Line.at(i).SetThisLineIsValid();
Line.at(j).SetThisLineIsValid();
break;
}
}
}
}
for(i=0;i<Line.size();i++)
{
if(!Line.at(i).ReturnIsValidLine())
Line2.push_back(Line.at(i));
}
Line.clear();
MaxSearchNumberOfLine=(int)(Line2.size()*SearchPercent/100.0);
CProgressBar Bar(_T("Construction 3-D Object Model"),Line2.size());
for(i=0;i<Line2.size();i++)
{
for(j=i+1;j<Line2.size();j++)
{
if(j>i+MaxSearchNumberOfLine)
break;
if(Line2.at(i).ReturnIsValidLine())
Nature Biotechnology: doi:10.1038/nbt.3413
break;
if(!Line2.at(j).ReturnIsValidLine())
{
if(Line2.at(i).IsTwoLineSame(Line2.at(j)))
{
Line2.at(i).SetThisLineIsValid();
Line2.at(j).SetThisLineIsValid();
break;
}
}
}
Bar.ProgressBarExpress();
}
for(i=0;i<Line2.size();i++)
{
if(!Line2.at(i).ReturnIsValidLine())
Line.push_back(Line2.at(i));
}
Line2.clear();
for(i=0;i<Line.size();i++)
{
for(j=i+1;j<Line.size();j++)
{
if(Line.at(i).ReturnIsValidLine())
break;
if(!Line.at(j).ReturnIsValidLine())
{
if(Line.at(i).IsTwoLineSame(Line.at(j)))
{
Line.at(i).SetThisLineIsValid();
Line.at(j).SetThisLineIsValid();
break;
}
}
}
}
for(i=0;i<Line.size();i++)
{
if(!Line.at(i).ReturnIsValidLine())
Line2.push_back(Line.at(i));
}
Nature Biotechnology: doi:10.1038/nbt.3413
Line.clear();
for(i=0;i<Line2.size();i++)
Line.push_back(Line2.at(i));
Line2.clear();
COneFacet TmpFacet;
std::vector<COneFacet> TmpFacetArray;
double TmpMinZValue,TmpMaxZValue,MinZValue,MaxZValue,ZHeightForNewLayer;
Facet.at(0).GetMinAndMaxZValue(TmpMinZValue,TmpMaxZValue);
MinZValue=TmpMinZValue;
MaxZValue=TmpMaxZValue;
for(i=1;i<Facet.size();i++)
{
Facet.at(i).GetMinAndMaxZValue(TmpMinZValue,TmpMaxZValue);
MinZValue=min(MinZValue,TmpMinZValue);
MaxZValue=max(MaxZValue,TmpMaxZValue);
}
if( (MaxZValue-MinZValue) > ZOffsetThickness )
ZOffsetThickness=(MaxZValue-MinZValue);
ZHeightForNewLayer=MinZValue+ZOffsetThickness;
for(i=0;i<Facet.size();i++)
{
TmpFacet=Facet.at(i);
TmpFacet.SetZHeight(ZHeightForNewLayer);
TmpFacetArray.push_back(TmpFacet);
}
for(i=0;i<TmpFacetArray.size();i++)
Facet.push_back(TmpFacetArray.at(i));
TmpFacetArray.clear();
double TmpVer1[3],TmpVer2[3],NewTmpVer1[3],NewTmpVer2[3];
for(i=0;i<Line.size();i++)
{
Line.at(i).GetVertex(TmpVer1,TmpVer2);
NewTmpVer1[0]=TmpVer1[0];NewTmpVer1[1]=TmpVer1[1];NewTmpVer1[2]=ZHeightForNewLayer;//TmpVer1[2]+Z
Nature Biotechnology: doi:10.1038/nbt.3413
OffsetThickness;
NewTmpVer2[0]=TmpVer2[0];NewTmpVer2[1]=TmpVer2[1];NewTmpVer2[2]=ZHeightForNewLayer;//TmpVer2[2]+Z
OffsetThickness;
TmpFacet.InsertOneFacet(TmpVer1,TmpVer2,NewTmpVer1);
Facet.push_back(TmpFacet);
TmpFacet.InsertOneFacet(NewTmpVer2,NewTmpVer1,TmpVer2);
Facet.push_back(TmpFacet);
}
}
void CMultiFacets::Smoothing2DSurface()
{
if(Facet.size()==0)
return;
}
void CMultiFacets::GenerationMoldBeamLine(double DifCWRotAngle, double LinePitch, double MinMoveDis, double
ErrorOffsetValue, int NumOfDirectionOverLab, double MoldOffsetSize)
{
double TotalCenter[2];
int i,MultiplyRotAng;
MultiplyRotAng=-1;
GetRotationCenter(TotalCenter);
CProgressBar Bar(_T("Beam Generation"),Loops.size());
double MaxX,MaxY,MinX,MinY;
MaxX=GetMaxXValueInSTLFile()+MoldOffsetSize;
MaxY=GetMaxYValueInSTLFile()+MoldOffsetSize;
MinX=GetMinXValueInSTLFile()-MoldOffsetSize;
MinY=GetMinYValueInSTLFile()-MoldOffsetSize;
for(i=0;i<Loops.size();i++)
{
if(i%NumOfDirectionOverLab==0)
MultiplyRotAng++;
Loops.at(i).GenMoldBeamLine(TotalCenter,DifCWRotAngle*(double)MultiplyRotAng,LinePitch,MinMoveDis,ErrorOff
setValue,MaxX,MaxY,MinX,MinY);
Bar.ProgressBarExpress();
}
Nature Biotechnology: doi:10.1038/nbt.3413
}
double CMultiFacets::ReturnMaxXValInBeamLines()
{
double ReturnXVal=NumErrorFindDouble*(-1.0);
double TmpXVal;
for(int i=0;i<Loops.size();i++)
{
TmpXVal=Loops.at(i).ReturnMaxXValInBeamLines();
if(TmpXVal>ReturnXVal)
ReturnXVal=TmpXVal;
}
return ReturnXVal;
}
double CMultiFacets::ReturnMinXValInBeamLines()
{
double ReturnXVal=NumErrorFindDouble;
double TmpXVal;
for(int i=0;i<Loops.size();i++)
{
TmpXVal=Loops.at(i).ReturnMinXValInBeamLines();
if(TmpXVal<ReturnXVal)
ReturnXVal=TmpXVal;
}
return ReturnXVal;
}
double CMultiFacets::ReturnMaxYValInBeamLines()
{
double ReturnYVal=NumErrorFindDouble*(-1.0);
double TmpYVal;
for(int i=0;i<Loops.size();i++)
{
TmpYVal=Loops.at(i).ReturnMaxYValInBeamLines();
if(TmpYVal>ReturnYVal)
ReturnYVal=TmpYVal;
}
return ReturnYVal;
}
Nature Biotechnology: doi:10.1038/nbt.3413
double CMultiFacets::ReturnMinYValInBeamLines()
{
double ReturnYVal=NumErrorFindDouble;
double TmpYVal;
for(int i=0;i<Loops.size();i++)
{
TmpYVal=Loops.at(i).ReturnMinYValInBeamLines();
if(TmpYVal<ReturnYVal)
ReturnYVal=TmpYVal;
}
return ReturnYVal;
}
double CMultiFacets::GetMaxXValueInSTLFile()
{
int NumOfFacet=Facet.size();
if(NumOfFacet==0) return 0.0;
float MaxX=Facet.at(0).ReturnMaxXValue();
for(int i=1;i<NumOfFacet;i++)
MaxX=max(MaxX,Facet.at(i).ReturnMaxXValue());
return MaxX;
}
double CMultiFacets::GetMaxYValueInSTLFile()
{
int NumOfFacet=Facet.size();
if(NumOfFacet==0) return 0.0;
float MaxY=Facet.at(0).ReturnMaxYValue();
for(int i=1;i<NumOfFacet;i++)
MaxY=max(MaxY,Facet.at(i).ReturnMaxYValue());
return MaxY;
}
double CMultiFacets::GetMinXValueInSTLFile()
{
int NumOfFacet=Facet.size();
Nature Biotechnology: doi:10.1038/nbt.3413
if(Facet.size()==0) return 0.0f;
float MinX=Facet.at(0).ReturnMinXValue();
for(int i=1;i<NumOfFacet;i++)
MinX=min(MinX,Facet.at(i).ReturnMinXValue());
return MinX;
}
double CMultiFacets::GetMinYValueInSTLFile()
{
int NumOfFacet=Facet.size();
if(Facet.size()==0) return 0.0f;
float MinY=Facet.at(0).ReturnMinYValue();
for(int i=1;i<NumOfFacet;i++)
MinY=min(MinY,Facet.at(i).ReturnMinYValue());
return MinY;
}
void CMultiFacets::SaveOrLoad(BOOL Save, CArchive &ar)
{
int i,TmpNum;
if(Save)
{
ar<<LayerThickness;
TmpNum=Facet.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
Facet.at(i).SaveOrLoad(Save,ar);
TmpNum=Loops.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
Loops.at(i).SaveOrLoad(Save,ar);
}
else
{
Initialize();
COneFacet TmpFacet;
CMultiLoops TmpLoops;
Nature Biotechnology: doi:10.1038/nbt.3413
ar>>LayerThickness;
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
{
TmpFacet.SaveOrLoad(Save,ar);
Facet.push_back(TmpFacet);
}
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
{
TmpLoops.Initialize();
TmpLoops.SaveOrLoad(Save,ar);
Loops.push_back(TmpLoops);
}
}
}
void CMultiFacets::Initialize()
{
Facet.clear();
Loops.clear();
LayerThickness=0.0;
}
void CMultiFacets::MakeMinZToZero()
{
if(Facet.size()==0)
return;
double MinZ=GetMinZValueInSTLFile()*(-1.0);
for(int i=0;i<Facet.size();i++)
Facet.at(i).TransferZValue(MinZ);
}
void CMultiFacets::GenerationCrossProfile(double TmpLayThick, double StartZValue, double EndZValue)
{
int i;
if(Facet.size()==0) return;
MakeMinZToZero();
Nature Biotechnology: doi:10.1038/nbt.3413
LayerThickness=TmpLayThick;
Loops.clear();
double MaxZ,MinZ,TmpZValue;
MaxZ=GetMaxZValueInSTLFile();
MinZ=GetMinZValueInSTLFile();
if(StartZValue<MinZ)
StartZValue=MinZ+TmpLayThick;
if(EndZValue>MaxZ)
EndZValue=MaxZ;
CProgressBar Bar(_T("Slice CAD Model"),(int)((EndZValue-StartZValue)/TmpLayThick+0.5));
for(TmpZValue=MinZ+StartZValue;TmpZValue<=EndZValue;TmpZValue+=TmpLayThick)
{
if(!CalCrossProfileAtZ(TmpZValue))
{
AfxMessageBox("단면 Loop 생성에 문제가 있습니다.");
return;
}
Bar.ProgressBarExpress();
}
for(i=0;i<Loops.size();i++)
{
if(!Loops.at(i).ClosedLoopDistribution())
{
}
}
}
void CMultiFacets::GenerationBeamLine4(double DifCWRotAngle, double LinePitch, double OffsetStep, int NumOfOffset,
double MinMoveDis, double ErrorOffsetValue, int NumOfDirectionOverLab, int RepeatingIndex)
{
double TotalCenter[2];
int i,MultiplyRotAng;
MultiplyRotAng=-1;
GetRotationCenter(TotalCenter);
Nature Biotechnology: doi:10.1038/nbt.3413
CProgressBar Bar(_T("Beam Generation"),Loops.size());
for(i=0;i<Loops.size();i++)
{
if(i%NumOfDirectionOverLab==0)
MultiplyRotAng++;
if(i%RepeatingIndex == 0)
Loops.at(i).GenMultiOffsetBeamLine2(TotalCenter,DifCWRotAngle*(double)MultiplyRotAng,LinePitch,OffsetStep,Nu
mOfOffset,MinMoveDis,ErrorOffsetValue);
else
Loops.at(i).GenMultiOffsetBeamLine3(TotalCenter,DifCWRotAngle*(double)MultiplyRotAng,LinePitch,OffsetStep,Nu
mOfOffset,MinMoveDis,ErrorOffsetValue);
Bar.ProgressBarExpress();
}
}
CProduct CMultiFacets::GetBeamProduct4(UINT Power, UINT Feedrate, int RepeatingIndex)
{
CProduct BeamProduct;
BOOL IsContourBeamOn=true;
if(RepeatingIndex<=0)
RepeatingIndex=1;
BeamProduct.InitializeProduct();
BeamProduct.SetPower(Power);
for(int i=0;i<Loops.size();i++)
{
if(i%RepeatingIndex==0)
BeamProduct.PushBackLayer(Loops.at(i).GetBeamLayer(LayerThickness,Feedrate,true));
else
BeamProduct.PushBackLayer(Loops.at(i).GetBeamLayer3(LayerThickness,Feedrate,IsContourBeamOn));
}
return BeamProduct;
}
void CMultiFacets::GenVerticalPath()
{
Nature Biotechnology: doi:10.1038/nbt.3413
double OffsetValue=0.1;
double Pitch=0.5;
FacetPerpendicularRotaionXYZ(1, true);
GenerationCrossProfile(Pitch);
DoOffset(OffsetValue);
}
// MoveOptimizeEle.h: interface for the CMoveOptimizeEle class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MOVEOPTIMIZEELE_H__9C7349EA_4769_427E_BFF3_463900CD96A6__INCLUDED_)
#define AFX_MOVEOPTIMIZEELE_H__9C7349EA_4769_427E_BFF3_463900CD96A6__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMoveOptimizeEle
{
public:
float GetY();
float GetX();
int GetEndNum();
int GetStartNum();
void SetElement(int Start,int End,float TmpX,float TmpY);
CMoveOptimizeEle();
virtual ~CMoveOptimizeEle();
private:
int StartNum;
int EndNum;
float X;
float Y;
};
#endif // !defined(AFX_MOVEOPTIMIZEELE_H__9C7349EA_4769_427E_BFF3_463900CD96A6__INCLUDED_)
// MoveOptimizeEle.cpp: implementation of the CMoveOptimizeEle class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "MoveOptimizeEle.h"
#ifdef _DEBUG
Nature Biotechnology: doi:10.1038/nbt.3413
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMoveOptimizeEle::CMoveOptimizeEle()
{
StartNum=-1;
EndNum=-1;
X=0.0f;
Y=0.0f;
}
CMoveOptimizeEle::~CMoveOptimizeEle()
{
}
void CMoveOptimizeEle::SetElement(int Start, int End, float TmpX, float TmpY)
{
StartNum=Start;
EndNum=End;
X=TmpX;
Y=TmpY;
}
int CMoveOptimizeEle::GetStartNum()
{
return StartNum;
}
int CMoveOptimizeEle::GetEndNum()
{
return EndNum;
}
float CMoveOptimizeEle::GetX()
{
return X;
}
float CMoveOptimizeEle::GetY()
{
return Y;
}
Nature Biotechnology: doi:10.1038/nbt.3413
// MoveOptimize.h: interface for the CMoveOptimize class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_MOVEOPTIMIZE_H__EBA16966_5FC2_49BF_ACAF_6C1A85FE55AA__INCLUDED_)
#define AFX_MOVEOPTIMIZE_H__EBA16966_5FC2_49BF_ACAF_6C1A85FE55AA__INCLUDED_
#include <vector>
#include "MoveOptimizeEle.h"
#include "Layer.h"
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMoveOptimize
{
public:
void Initialize();
CLayer DoMoveOptimize(CLayer Layer);
CLayer OptimizeLayer(CLayer TmpLayer);
void SetLayer(CLayer TmpLayer);
CMoveOptimizeEle GetEle(UINT Num);
void PushBack(CMoveOptimizeEle TmpEle);
CMoveOptimize();
virtual ~CMoveOptimize();
private:
std::vector<CMoveOptimizeEle> Element;
};
#endif // !defined(AFX_MOVEOPTIMIZE_H__EBA16966_5FC2_49BF_ACAF_6C1A85FE55AA__INCLUDED_)
// MoveOptimize.cpp: implementation of the CMoveOptimize class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "MoveOptimize.h"
#include "Path.h"
#include "MoveOptimizeEle.h"
#include "math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
Nature Biotechnology: doi:10.1038/nbt.3413
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CMoveOptimize::CMoveOptimize()
{
}
CMoveOptimize::~CMoveOptimize()
{
}
void CMoveOptimize::PushBack(CMoveOptimizeEle TmpEle)
{
Element.push_back(TmpEle);
}
CMoveOptimizeEle CMoveOptimize::GetEle(UINT Num)
{
return Element[Num-1];
}
void CMoveOptimize::SetLayer(CLayer TmpLayer)
{
CMoveOptimizeEle TmpEle;
CPath TmpPath;
int Start,End;
float Position[2];
UINT i;
for(i=1;i<=TmpLayer.ReturnNumOfPath();++i)
{
TmpPath=TmpLayer.ReturnPath(i);
if( TmpPath.GetDrawingOrMove() || TmpPath.GetDwellingTime()>0.0f )
{
Start=(int)i;
TmpPath.GetStartPos(Position);
while( TmpPath.GetDrawingOrMove() || TmpPath.GetDwellingTime()>0.0f )
{
++i;
if(i>TmpLayer.ReturnNumOfPath())
break;
TmpPath=TmpLayer.ReturnPath(i);
}
End=(int)i-1;
Nature Biotechnology: doi:10.1038/nbt.3413
TmpEle.SetElement(Start,End,Position[0],Position[1]);
Element.push_back(TmpEle);
}
}
}
CLayer CMoveOptimize::OptimizeLayer(CLayer Layer)
{
UINT i,j,k;
int Start,End;
double Distance1,Distance2;
CLayer TmpLayer;
CMoveOptimizeEle TmpEle;
TmpLayer.InitializeLayer(Layer.GetLayerThickness());
k=0;
for(i=0;i<Element.size();++i)
{
Distance1=-1.0;
for(j=i+1;j<Element.size();++j)
{
if(Distance1<0.0)
Distance1=sqrt( (Element[j].GetX()-Element[i].GetX())*(Element[j].GetX()-
Element[i].GetX()) + (Element[j].GetY()-Element[i].GetY())*(Element[j].GetY()-Element[i].GetY()) );
else
{
Distance2=sqrt( (Element[j].GetX()-Element[i].GetX())*(Element[j].GetX()-
Element[i].GetX()) + (Element[j].GetY()-Element[i].GetY())*(Element[j].GetY()-Element[i].GetY()) );
if(Distance1>Distance2)
{
Distance1=Distance2;
k=j;
}
}
}
if(i<Element.size()-1 && k!=0)
{
TmpEle=Element[k];
Element.erase(&Element.at(k));
Element.insert(&Element.at(i+1),TmpEle);
k=0;
}
}
for(i=0;i<Element.size();++i)
{
Start=Element[i].GetStartNum();
Nature Biotechnology: doi:10.1038/nbt.3413
End=Element[i].GetEndNum();
for(;Start<=End;++Start)
TmpLayer.PushBackPath(Layer.ReturnPath(Start));
}
return TmpLayer;
}
CLayer CMoveOptimize::DoMoveOptimize(CLayer Layer)
{
SetLayer(Layer);
return OptimizeLayer(Layer);
}
void CMoveOptimize::Initialize()
{
if(Element.size()>0)
Element.clear();
}
#if !defined(AFX_MAGNIFICATION_H__88ACFAFA_7129_4E6B_8DE8_9153233FFC69__INCLUDED_)
#define AFX_MAGNIFICATION_H__88ACFAFA_7129_4E6B_8DE8_9153233FFC69__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Magnification.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CMagnification dialog
class CMagnification : public CDialog
{
// Construction
public:
double GetMagnificationValue();
CMagnification(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CMagnification)
enum { IDD = IDD_MAGNIFICATION };
double m_Magnification;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CMagnification)
Nature Biotechnology: doi:10.1038/nbt.3413
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CMagnification)
// NOTE: the ClassWizard will add member functions here
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_MAGNIFICATION_H__88ACFAFA_7129_4E6B_8DE8_9153233FFC69__INCLUDED_)
// Magnification.cpp : implementation file
//
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "Magnification.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMagnification dialog
CMagnification::CMagnification(CWnd* pParent /*=NULL*/)
: CDialog(CMagnification::IDD, pParent)
{
//{{AFX_DATA_INIT(CMagnification)
m_Magnification = 1.0;
//}}AFX_DATA_INIT
}
void CMagnification::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMagnification)
Nature Biotechnology: doi:10.1038/nbt.3413
DDX_Text(pDX, IDC_EDIT1, m_Magnification);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMagnification, CDialog)
//{{AFX_MSG_MAP(CMagnification)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMagnification message handlers
double CMagnification::GetMagnificationValue()
{
return m_Magnification;
}
// Layer.h: interface for the CLayer class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_LAYER_H__B6B23874_4C6C_4382_85AD_94C5C10ED56E__INCLUDED_)
#define AFX_LAYER_H__B6B23874_4C6C_4382_85AD_94C5C10ED56E__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "Path.h"
#include <vector>
class CLayer : public CPath
{
public:
double ExportFDM(CString &Code,UINT Dwelling,UINT DrawingFeedPer);
BOOL CompareTwoPath(int First, int Second);
double ExportNewport(CString &Code,UINT Dwelling,UINT DrawingFeedPer);
void CriterionFeedrate(BOOL Draw,UINT CriterionFeed,UINT NewFeed);
void MakeHPipe(float Width, float Length);
void MakeJointType7(float Width, float Length);
void MakeGatePipe(float Radius, UINT Num);
void MakeVPipe(float Width,float Length);
void InputDrawRelPath(float RelX, float RelY, UINT Feed);
void InputDrawPath(float StartX,float StartY,float EndX,float EndY,UINT Feed);
void MakeJointType1(float Width,float Length);
void MakeJointType2(float Width,float Length);
void MakeJointType3(float Width,float Length);
Nature Biotechnology: doi:10.1038/nbt.3413
void MakeJointType4(float Width,float Length);
void MakeJointType5(float Width,float Length);
void MakeJointType6(float Width,float Length);
void DrawRectangle(float Width,float Length,UINT DrawFeed);
void MakeJointHole(float Width, float Length, float HoleSize);
BOOL ChangePower(float Factor);
void ReturnMaxAndMinYValue(float MinMax[2]);
void ReturnMaxAndMinXValue(float MinMax[2]);
void SetDrawingOrMoving(int PathNum,int TmpMoveOrDraw);
void DwellingEdit(UINT PathNum, UINT DwellingT, int MoveOrDraw);
double ExportAerotec(CString &Code,UINT Dwelling,UINT DrawingFeedPer);
BOOL IsAnyPathPoint();
BOOL IsPathNumberZero();
BOOL IsOutOfRange(float Range);
BOOL IsAnyFeedrateZero();
BOOL IsAllPathLinked();
BOOL OptimizeLayer();
void LayerSaveOrLoad(BOOL Save , CArchive& ar);
void Translation(float TransX,float TransY);
void Rotation(float CenterX,float CenterY,double CWAngle);
void PathEdit(UINT PathNum,UINT Feedrate,int MoveOrDraw);
CPath ReturnPath(UINT PathNum);
void SetLayerThickness(float Thickness);
CPath ReturnLastPath();
CPath ReturnFirstPath();
void ReturnInformationOfNum(UINT PosNum,float Start[2], float End[2], float Center[2], BOOL &TmpDrawing,BOOL
&TmpCircle,BOOL &TmpCW,BOOL &TmpLine,UINT &TmpFeedrate,float &TmpDwellingTime);
void InitializeLayer(float Thickness);
void PushBackPath(CPath TmpPath);
void InsertPath(UINT BehindPos, CPath TmpPath);
float GetLayerThickness();
UINT ReturnNumOfPath();
void ErasePath(UINT PosNum1,UINT PosNum2);
void ErasePath(UINT PosNum);
void PopBack();
CLayer();
virtual ~CLayer();
private:
float LayerThickness;
std::vector<CPath> Path;
};
#endif // !defined(AFX_LAYER_H__B6B23874_4C6C_4382_85AD_94C5C10ED56E__INCLUDED_)
// Layer.cpp: implementation of the CLayer class.
//
//////////////////////////////////////////////////////////////////////
Nature Biotechnology: doi:10.1038/nbt.3413
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "Layer.h"
#include "Path.h"
#include "math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CLayer::CLayer()
{
LayerThickness=0.030f;
CPath TmpPath;
Path.push_back(TmpPath);
}
CLayer::~CLayer()
{
Path.clear();
}
void CLayer::PopBack()
{
if(Path.size()!=0)
{
Path.pop_back();
}
}
void CLayer::ErasePath(UINT PosNum)
{
if(PosNum>0 && Path.size()!=0)
{
--PosNum;
Path.erase(&Path.at(PosNum));
}
}
void CLayer::ErasePath(UINT PosNum1, UINT PosNum2)
{
Nature Biotechnology: doi:10.1038/nbt.3413
if(PosNum1>0 && Path.size()!=0 && PosNum2>=PosNum1)
{
--PosNum1;
if(PosNum2>=Path.size())
{
PosNum2=Path.size()-1;
Path.erase(&Path.at(PosNum1),&Path.at(PosNum2));
Path.pop_back();
}
else
{
Path.erase(&Path.at(PosNum1),&Path.at(PosNum2));
}
return;
}
else
{
AfxMessageBox("Position Number Error");
}
}
UINT CLayer::ReturnNumOfPath()
{
return Path.size();
}
float CLayer::GetLayerThickness()
{
return LayerThickness;
}
void CLayer::InsertPath(UINT BehindPos, CPath TmpPath)
{
--BehindPos;
Path.insert(&Path.at(BehindPos),TmpPath);
}
void CLayer::PushBackPath(CPath TmpPath)
{
Path.push_back(TmpPath);
}
void CLayer::InitializeLayer(float Thickness)
{
LayerThickness=Thickness;
if(Path.size()>0)
Nature Biotechnology: doi:10.1038/nbt.3413
Path.clear();
}
void CLayer::ReturnInformationOfNum(UINT PosNum,float Start[], float End[], float Center[], BOOL &TmpDrawing,BOOL
&TmpCircle,BOOL &TmpCW,BOOL &TmpLine,UINT &TmpFeedrate,float &TmpDwellingTime)
{
Path[PosNum].ReturnInformation(Start, End, Center, TmpDrawing, TmpCircle, TmpCW, TmpLine, TmpFeedrate,
TmpDwellingTime);
}
CPath CLayer::ReturnFirstPath()
{
return Path.front();
}
CPath CLayer::ReturnLastPath()
{
return Path.back();
}
void CLayer::SetLayerThickness(float Thickness)
{
LayerThickness=Thickness;
}
CPath CLayer::ReturnPath(UINT PathNum)
{
return Path[PathNum-1];
}
void CLayer::PathEdit(UINT PathNum, UINT Feedrate, int MoveOrDraw)
{
Path[PathNum-1].PathEdit(Feedrate,MoveOrDraw);
}
void CLayer::Rotation(float CenterX, float CenterY, double CWAngle)
{
for(UINT i=0;i<Path.size();++i)
Path[i].PathRotation(CenterX,CenterY,CWAngle);
}
void CLayer::Translation(float TransX, float TransY)
{
for(UINT i=0;i<Path.size();++i)
Path[i].PathTranslation(TransX,TransY);
}
void CLayer::LayerSaveOrLoad(BOOL Save, CArchive &ar)
{
Nature Biotechnology: doi:10.1038/nbt.3413
UINT PathNum=0;
UINT i;
if(Save)
{
PathNum=Path.size();
ar<<PathNum;
ar<<LayerThickness;
for(i=0;i<PathNum;i++)
Path[i].PathSaveOrLoad(true,ar);
}
else
{
InitializeLayer(0.03);
ar>>PathNum;
ar>>LayerThickness;
Path.resize(PathNum);
for(i=0;i<PathNum;i++)
Path[i].PathSaveOrLoad(false,ar);
}
}
BOOL CLayer::OptimizeLayer()
{
UINT TmpFeedrate=10;
if(Path.size()<1)
return false;
UINT i,j,k;
float Start[2],End[2];
for(i=0;i<Path.size();++i)
{
if(Path[i].GetFeedrate()<1 && Path[i].GetDwellingTime()<=0.0f)
{
ErasePath(i+1);
--i;
}
}
if(Path.size()<1) return false;
for(i=0;i<Path.size();++i)
{
if(Path[i].IsSameStartEnd() && Path[i].GetLine() && Path[i].GetDwellingTime()<=0.0f )
{
ErasePath(i+1);
--i;
Nature Biotechnology: doi:10.1038/nbt.3413
}
}
if(Path.size()<1) return false;
for(i=0;i<Path.size();++i)
{
if(Path[i].GetCircle() && !Path[i].GetDrawingOrMove() )
Path[i].SetLine();
}
float Tmp[2];
for(i=0;i<Path.size()-1;++i)
{
Path[i].GetEndPos(End);
Path[i+1].GetStartPos(Start);
Path[i+1].GetEndPos(Tmp);
if( (int)(Start[0]*1000.0f)!=(int)(End[0]*1000.0f) || (int)(Start[1]*1000.0f)!=(int)(End[1]*1000.0f) )
{
CPath TmpPath;
if(!Path[i+1].GetDrawingOrMove())
TmpFeedrate=Path[i].GetFeedrate();
if(!Path[i].GetDrawingOrMove())
TmpFeedrate=Path[i].GetFeedrate();
if(TmpFeedrate==0)
TmpFeedrate=10;
TmpPath.SetLineValue(false,End,Start,TmpFeedrate);
InsertPath(i+2,TmpPath);
TmpFeedrate=10;
}
}
for(i=0;i<Path.size()-1;++i)
{
if(!Path[i].GetDrawingOrMove() && Path[i].GetDwellingTime()<=0.0f )
{
j=i+1;
while(!Path[j].GetDrawingOrMove() && Path[j].GetDwellingTime()<=0.0f)
{
if(j==(Path.size()-1))
{
++j;
break;
}
Nature Biotechnology: doi:10.1038/nbt.3413
++j;
}
if(j>i+1)
{
BOOL SameFeed=true;
for(k=i;k<j-1;++k)
{
if(Path[k].GetFeedrate()==Path[k+1].GetFeedrate())
SameFeed*=true;
else
SameFeed*=false;
}
if(SameFeed)
{
float EndPos[2];
Path[j-1].GetEndPos(EndPos);
Path[i].SetEndPos(EndPos);
ErasePath(i+2,j);
}
else
{
float StartPos[2],EndPos[2],TmpStart[2],TmpEnd[2],LengthX,LengthY;
double TotalLength=0.0;
double* WeightNumber=new double[j-i];
Path[i].GetStartPos(StartPos);
Path[j-1].GetEndPos(EndPos);
LengthX=EndPos[0]-StartPos[0];
LengthY=EndPos[1]-StartPos[1];
for(k=i;k<j;++k)
{
Path[k].GetStartPos(TmpStart);
Path[k].GetEndPos(TmpEnd);
WeightNumber[k-i]=sqrt((double)((TmpStart[0]-
TmpEnd[0])*(TmpStart[0]-TmpEnd[0])+(TmpStart[1]-TmpEnd[1])*(TmpStart[1]-TmpEnd[1])));
TotalLength+=WeightNumber[k-i];
}
for(k=i;k<j;++k)
WeightNumber[k-i]/=TotalLength;
Path[i].GetStartPos(TmpStart);
TmpEnd[0]=TmpStart[0]+LengthX*(float)WeightNumber[0];
TmpEnd[1]=TmpStart[1]+LengthY*(float)WeightNumber[0];
Path[i].SetEndPos(TmpEnd);
for(k=i+1;k<j-1;++k)
{
Path[k-1].GetEndPos(TmpStart);
Nature Biotechnology: doi:10.1038/nbt.3413
TmpEnd[0]=TmpStart[0]+LengthX*(float)WeightNumber[k-i];
TmpEnd[1]=TmpStart[1]+LengthY*(float)WeightNumber[k-i];
Path[k].SetStartPos(TmpStart);
Path[k].SetEndPos(TmpEnd);
}
Path[k-1].GetEndPos(TmpStart);
Path[k].SetStartPos(TmpStart);
delete WeightNumber;
}
}
}
}
if(Path.size()<1)
return false;
return true;
}
BOOL CLayer::IsAllPathLinked()
{
UINT i;
float Start[2],End[2];
for(i=0;i<Path.size()-1;++i)
{
Path[i].GetEndPos(Start);
Path[i+1].GetStartPos(End);
if( (int)(Start[0]*1000.0f)!=(int)(End[0]*1000.0f) || (int)(Start[1]*1000.0f)!=(int)(End[1]*1000.0f) )
return false;
}
return true;
}
BOOL CLayer::IsAnyFeedrateZero()
{
UINT i;
for(i=0;i<Path.size();++i)
{
if(Path[i].IsFeedrateZero() && Path[i].GetDwellingTime()<=0.0f)
return true;
}
return false;
}
Nature Biotechnology: doi:10.1038/nbt.3413
BOOL CLayer::IsOutOfRange(float Range)
{
UINT i;
for(i=0;i<Path.size();++i)
{
if(Path[i].IsOutOfRange(Range))
return true;
}
return false;
}
BOOL CLayer::IsPathNumberZero()
{
if(Path.size()<1)
return true;
return false;
}
BOOL CLayer::IsAnyPathPoint()
{
UINT i;
for(i=0;i<Path.size();++i)
{
if(Path[i].IsSameStartEnd() && Path[i].GetDwellingTime()<=0.0f)
return true;
}
return false;
}
double CLayer::ExportAerotec(CString &Code,UINT Dwelling,UINT DrawingFeedPer)
{
UINT i;
CString TmpCode1,TmpCode2;
double Time=0.0;
if(Path[0].GetDrawingOrMove())
{
if(Dwelling>0)
TmpCode2.Format("G4 %d\nOUT 0\n",Dwelling*1000);
else
TmpCode2.Format("OUT 0\n");
Code+=TmpCode2;
TmpCode2.Empty();
Time+=(double)Dwelling;
}
Nature Biotechnology: doi:10.1038/nbt.3413
Time+=Path[0].ExportAerotec(TmpCode1,DrawingFeedPer);
Code+=TmpCode1;
TmpCode1.Empty();
for(i=1;i<Path.size();++i)
{
if( Path[i-1].GetDrawingOrMove() && !Path[i].GetDrawingOrMove() )
{
TmpCode2.Format("OUT 1\n");
Code+=TmpCode2;
TmpCode2.Empty();
}
if( !Path[i-1].GetDrawingOrMove() && Path[i].GetDrawingOrMove() )
{
if(Dwelling>0)
TmpCode2.Format("G4 %d\nOUT 0\n",Dwelling*1000);
else
TmpCode2.Format("OUT 0\n");
Code+=TmpCode2;
TmpCode2.Empty();
Time+=(double)Dwelling;
}
Time+=Path[i].ExportAerotec(TmpCode1,DrawingFeedPer);
Code+=TmpCode1;
TmpCode1.Empty();
}
if(Path[Path.size()-1].GetDrawingOrMove())
{
TmpCode2.Format("OUT 1\n");
Code+=TmpCode2;
TmpCode2.Empty();
}
return Time;
}
void CLayer::DwellingEdit(UINT PathNum, UINT DwellingT, int MoveOrDraw)
{
switch(MoveOrDraw)
{
case 0:
Path[PathNum-1].SetDwellingValue(false,DwellingT);
break;
case 1:
Path[PathNum-1].SetDwellingValue(true,DwellingT);
Nature Biotechnology: doi:10.1038/nbt.3413
break;
}
}
void CLayer::SetDrawingOrMoving(int PathNum, int TmpMoveOrDraw)
{
Path[PathNum-1].SetDrawingOrMoving(TmpMoveOrDraw);
}
void CLayer::ReturnMaxAndMinXValue(float MinMax[])
{
if(Path.size()==0)
return;
float TmpMinMax[2],TmpMinMax2[2];
TmpMinMax[0]=0.0f;
TmpMinMax[1]=0.0f;
TmpMinMax2[0]=0.0f;
TmpMinMax2[1]=0.0f;
Path[0].ReturnXValue(TmpMinMax);
for(UINT i=0;i<Path.size();++i)
{
Path[i].ReturnXValue(TmpMinMax2);
if(TmpMinMax[0]>TmpMinMax2[0])
TmpMinMax[0]=TmpMinMax2[0];
if(TmpMinMax[1]<TmpMinMax2[1])
TmpMinMax[1]=TmpMinMax2[1];
}
MinMax[0]=TmpMinMax[0];
MinMax[1]=TmpMinMax[1];
}
void CLayer::ReturnMaxAndMinYValue(float MinMax[])
{
if(Path.size()==0)
return;
float TmpMinMax[2],TmpMinMax2[2];
TmpMinMax[0]=0.0f;
TmpMinMax[1]=0.0f;
TmpMinMax2[0]=0.0f;
TmpMinMax2[1]=0.0f;
Path[0].ReturnYValue(TmpMinMax);
for(UINT i=0;i<Path.size();++i)
{
Nature Biotechnology: doi:10.1038/nbt.3413
Path[i].ReturnYValue(TmpMinMax2);
if(TmpMinMax[0]>TmpMinMax2[0])
TmpMinMax[0]=TmpMinMax2[0];
if(TmpMinMax[1]<TmpMinMax2[1])
TmpMinMax[1]=TmpMinMax2[1];
}
MinMax[0]=TmpMinMax[0];
MinMax[1]=TmpMinMax[1];
}
BOOL CLayer::ChangePower(float Factor)
{
for(UINT i=0;i<Path.size();++i)
if(!Path[i].ChangePower(Factor))
return false;
return true;
}
void CLayer::MakeJointHole(float Width, float Length, float HoleSize)
{
int RepeatNum=4;
CPath TmpPath;
float Step;
UINT DrawFeed,MoveFeed;
Step=0.076f;
DrawFeed=29;
MoveFeed=200;
float TmpWidth,TmpLength;
float Start[2],End[2];
TmpWidth=Width+(float)(Step*(RepeatNum-1)*2);
TmpLength=Length+(float)(Step*(RepeatNum-1)*2);
DrawRectangle(TmpWidth,TmpLength,DrawFeed);
Start[0]=TmpWidth/2.0f*(-1.0f);
Start[1]=TmpLength/2.0f*(-1.0f);
End[0]=Start[0]+Step;
End[1]=Start[1]+Step;
TmpPath.SetLineValue(true,Start,End,MoveFeed);
PushBackPath(TmpPath);
while(TmpWidth>HoleSize || TmpLength>HoleSize)
{
TmpWidth-=Step*2.0f;
Nature Biotechnology: doi:10.1038/nbt.3413
TmpLength-=Step*2.0f;
if(TmpWidth<=0.0f || TmpLength<=0.0f)
break;
DrawRectangle(TmpWidth,TmpLength,DrawFeed);
Start[0]=TmpWidth/2.0f*(-1.0f);
Start[1]=TmpLength/2.0f*(-1.0f);
End[0]=Start[0]+Step;
End[1]=Start[1]+Step;
TmpPath.SetLineValue(true,Start,End,MoveFeed);
PushBackPath(TmpPath);
}
PopBack();
}
void CLayer::DrawRectangle(float Width, float Length,UINT DrawFeed)
{
CPath TmpPath;
float Start[2],End[2];
Start[0]=Width/2.0f*(-1.0f);
Start[1]=Length/2.0f*(-1.0f);
End[0]=Start[0];
End[1]=Start[1]*(-1.0f);
TmpPath.SetLineValue(true,Start,End,DrawFeed);
PushBackPath(TmpPath);
Start[0]=End[0];
Start[1]=End[1];
End[0]=Start[0]*(-1.0f);
End[1]=Start[1];
TmpPath.SetLineValue(true,Start,End,DrawFeed);
PushBackPath(TmpPath);
Start[0]=End[0];
Start[1]=End[1];
End[0]=Start[0];
End[1]=Start[1]*(-1.0f);
TmpPath.SetLineValue(true,Start,End,DrawFeed);
PushBackPath(TmpPath);
Start[0]=End[0];
Start[1]=End[1];
Nature Biotechnology: doi:10.1038/nbt.3413
End[0]=Start[0]*(-1.0f);
End[1]=Start[1];
TmpPath.SetLineValue(true,Start,End,DrawFeed);
PushBackPath(TmpPath);
}
void CLayer::MakeJointType1(float Width, float Length)
{
int RepeatNum=4;
CPath TmpPath;
float Step;
UINT DrawFeed,MoveFeed;
Step=0.076f; //자칭 95%
DrawFeed=29;
MoveFeed=200;
float X,Y,TmpWidth,TmpLength;
TmpWidth=Width+Step*6.0f;
TmpLength=Length+Step*6.0f;
X=TmpWidth/2.0f;
Y=TmpLength/2.0f;
InputDrawPath(X*(-1.0f),Y,X,Y,DrawFeed);
InputDrawRelPath(0.0f,TmpLength*(-1.0f),DrawFeed);
InputDrawRelPath(TmpWidth*(-1.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step,MoveFeed);
InputDrawRelPath(TmpWidth-Step,0.0f,DrawFeed);
InputDrawRelPath(0.0f,TmpLength-Step*2.0f,DrawFeed);
InputDrawRelPath((-1.0f)*(TmpWidth-Step),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),MoveFeed);
InputDrawRelPath(TmpWidth-Step*2.0f,0.0f,DrawFeed);
InputDrawRelPath(0.0f,(-1.0f)*(TmpLength-Step*4.0f),DrawFeed);
InputDrawRelPath((-1.0f)*(TmpWidth-Step*2.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step,MoveFeed);
InputDrawRelPath(TmpWidth-Step*3.0f,0.0f,DrawFeed);
InputDrawRelPath(0.0f,Length,DrawFeed);
InputDrawRelPath((-1.0f)*(TmpWidth-Step*3.0f),0.0f,DrawFeed);
}
void CLayer::MakeJointType2(float Width, float Length)
{
CPath TmpPath;
float Step;
UINT DrawFeed,MoveFeed;
Step=0.076f; //자칭 95%
Nature Biotechnology: doi:10.1038/nbt.3413
DrawFeed=29;
MoveFeed=200;
float X,Y;
X=Width/2.0f+Step*3.0f;
Y=Length/2.0f+Step*3.0f;
InputDrawPath(X*(-1.0f),Y,X,Y,DrawFeed);
InputDrawRelPath(0.0f,(-1.0f)*(Length+Step*6.0f),DrawFeed);
InputDrawRelPath(Step*(-1.0f),0.0f,MoveFeed);
InputDrawRelPath(0.0f,Length+Step*5.0f,DrawFeed);
InputDrawRelPath((-1.0f)*(Width+Step*5.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),MoveFeed);
InputDrawRelPath(Width+Step*4.0f,0.0f,DrawFeed);
InputDrawRelPath(0.0f,(-1.0f)*(Length+Step*4.0f),DrawFeed);
InputDrawRelPath(Step*(-1.0f),0.0f,MoveFeed);
InputDrawRelPath(0.0f,Length+Step*3.0f,DrawFeed);
InputDrawRelPath((-1.0f)*(Width+Step*3.0f),0.0f,DrawFeed);
InputDrawPath(Width/(-2.0f),Length/(-2.0f),Width/(-2.0f),Length/(-2.0f)-Step*3.0f,DrawFeed);
InputDrawRelPath(Step*(-3.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*3.0f,DrawFeed);
InputDrawRelPath(Step*3.0f,0.0f,DrawFeed);
InputDrawRelPath(Step*(-1.0f),Step*(-1.0f),MoveFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),DrawFeed);
InputDrawRelPath(Step*(-1.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step,DrawFeed);
InputDrawRelPath(Step,0.0f,DrawFeed);
}
void CLayer::MakeJointType3(float Width, float Length)
{
CPath TmpPath;
float Step;
UINT DrawFeed,MoveFeed;
Step=0.076f; //자칭 95%
DrawFeed=29;
MoveFeed=200;
float X,Y;
X=Width/2.0f+Step*3.0f;
Y=Length/2.0f+Step*3.0f;
InputDrawPath(X*(-1.0f),Y,X,Y,DrawFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),MoveFeed);
InputDrawRelPath((-1.0f)*(Width+Step*6.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),MoveFeed);
InputDrawRelPath(Width+Step*6.0f,0.0f,DrawFeed);
Nature Biotechnology: doi:10.1038/nbt.3413
InputDrawRelPath(0.0f,Step*(-1.0f),MoveFeed);
InputDrawRelPath((-1.0f)*(Width+Step*6.0f),0.0f,DrawFeed);
InputDrawPath(X*(-1.0f),Y*(-1.0f),X,Y*(-1.0f),DrawFeed);
InputDrawRelPath(0.0f,Step,MoveFeed);
InputDrawRelPath((-1.0f)*(Width+Step*6.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step,MoveFeed);
InputDrawRelPath(Width+Step*6.0f,0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step,MoveFeed);
InputDrawRelPath((-1.0f)*(Width+Step*6.0f),0.0f,DrawFeed);
}
void CLayer::MakeJointType4(float Width, float Length)
{
CPath TmpPath;
float Step;
UINT DrawFeed,MoveFeed;
Step=0.076f; //자칭 95%
DrawFeed=29;
MoveFeed=200;
float X,Y;
X=Width/2.0f+Step*3.0f;
Y=Length/2.0f+Step*3.0f;
InputDrawPath(X*(-1.0f),Y*(-1.0f),X*(-1.0f),Y,DrawFeed);
InputDrawRelPath(Width+Step*6.0f,0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),MoveFeed);
InputDrawRelPath((-1.0f)*(Width+Step*5.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,(-1.0f)*(Length+Step*5.0f),DrawFeed);
InputDrawRelPath(Step,0.0f,MoveFeed);
InputDrawRelPath(0.0f,Length+Step*4.0f,DrawFeed);
InputDrawRelPath(Width+Step*4.0f,0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),MoveFeed);
InputDrawRelPath((-1.0f)*(Width+Step*3.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,(-1.0f)*(Length+Step*3.0f),DrawFeed);
InputDrawPath(Width/2.0f+Step*3.0f,Length/(-2.0f),Width/2.0f+Step*3.0f,Length/(-2.0f)-Step*3.0f,DrawFeed);
InputDrawRelPath(Step*(-3.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*3.0f,DrawFeed);
InputDrawRelPath(Step*3.0f,0.0f,DrawFeed);
InputDrawRelPath(Step*(-1.0f),Step*(-1.0f),MoveFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),DrawFeed);
InputDrawRelPath(Step*(-1.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step,DrawFeed);
InputDrawRelPath(Step,0.0f,DrawFeed);
}
Nature Biotechnology: doi:10.1038/nbt.3413
void CLayer::MakeJointType5(float Width, float Length)
{
CPath TmpPath;
float Step;
UINT DrawFeed,MoveFeed;
Step=0.076f;
DrawFeed=29;
MoveFeed=200;
float X,Y;
X=Width/2.0f+Step*3.0f;
Y=Length/2.0f+Step*3.0f;
InputDrawPath(X*(-1.0f),Y,X,Y,DrawFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),MoveFeed);
InputDrawRelPath((-1.0f)*(Width+Step*6.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),MoveFeed);
InputDrawRelPath(Width+Step*6.0f,0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),MoveFeed);
InputDrawRelPath((-1.0f)*(Width+Step*6.0f),0.0f,DrawFeed);
InputDrawPath(Width/(-2.0f),Length/(-2.0f),Width/(-2.0f),Length/(-2.0f)-Step*3.0f,DrawFeed);
InputDrawRelPath(Step*(-3.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*3.0f,DrawFeed);
InputDrawRelPath(Step*3.0f,0.0f,DrawFeed);
InputDrawRelPath(Step*(-1.0f),Step*(-1.0f),MoveFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),DrawFeed);
InputDrawRelPath(Step*(-1.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step,DrawFeed);
InputDrawRelPath(Step,0.0f,DrawFeed);
InputDrawPath(Width/2.0f+Step*3.0f,Length/(-2.0f),Width/2.0f+Step*3.0f,Length/(-2.0f)-Step*3.0f,DrawFeed);
InputDrawRelPath(Step*(-3.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*3.0f,DrawFeed);
InputDrawRelPath(Step*3.0f,0.0f,DrawFeed);
InputDrawRelPath(Step*(-1.0f),Step*(-1.0f),MoveFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),DrawFeed);
InputDrawRelPath(Step*(-1.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step,DrawFeed);
InputDrawRelPath(Step,0.0f,DrawFeed);
}
void CLayer::MakeJointType6(float Width, float Length)
{
CPath TmpPath;
float Step;
UINT DrawFeed,MoveFeed;
Nature Biotechnology: doi:10.1038/nbt.3413
Step=0.076f;
DrawFeed=29;
MoveFeed=200;
float X,Y;
X=Width/2.0f+Step*3.0f;
Y=Length/2.0f+Step*3.0f;
InputDrawPath(Width/(-2.0f),Y,Width/(-2.0f),Length/2.0f,DrawFeed);
InputDrawRelPath(Step*(-3.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*3.0f,DrawFeed);
InputDrawRelPath(Step*3.0f,0.0f,DrawFeed);
InputDrawRelPath(Step*(-1.0f),Step*(-1.0f),MoveFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),DrawFeed);
InputDrawRelPath(Step*(-1.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step,DrawFeed);
InputDrawRelPath(Step,0.0f,DrawFeed);
InputDrawPath(X,Y,X,Length/2.0f,DrawFeed);
InputDrawRelPath(Step*(-3.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*3.0f,DrawFeed);
InputDrawRelPath(Step*3.0f,0.0f,DrawFeed);
InputDrawRelPath(Step*(-1.0f),Step*(-1.0f),MoveFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),DrawFeed);
InputDrawRelPath(Step*(-1.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step,DrawFeed);
InputDrawRelPath(Step,0.0f,DrawFeed);
InputDrawPath(Width/(-2.0f),Length/(-2.0f),Width/(-2.0f),Length/(-2.0f)-Step*3.0f,DrawFeed);
InputDrawRelPath(Step*(-3.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*3.0f,DrawFeed);
InputDrawRelPath(Step*3.0f,0.0f,DrawFeed);
InputDrawRelPath(Step*(-1.0f),Step*(-1.0f),MoveFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),DrawFeed);
InputDrawRelPath(Step*(-1.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step,DrawFeed);
InputDrawRelPath(Step,0.0f,DrawFeed);
InputDrawPath(Width/2.0f+Step*3.0f,Length/(-2.0f),Width/2.0f+Step*3.0f,Length/(-2.0f)-Step*3.0f,DrawFeed);
InputDrawRelPath(Step*(-3.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*3.0f,DrawFeed);
InputDrawRelPath(Step*3.0f,0.0f,DrawFeed);
InputDrawRelPath(Step*(-1.0f),Step*(-1.0f),MoveFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),DrawFeed);
InputDrawRelPath(Step*(-1.0f),0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step,DrawFeed);
InputDrawRelPath(Step,0.0f,DrawFeed);
}
Nature Biotechnology: doi:10.1038/nbt.3413
void CLayer::InputDrawPath(float StartX, float StartY, float EndX, float EndY, UINT Feed)
{
CPath TmpPath;
float Start[2],End[2];
Start[0]=StartX;
Start[1]=StartY;
End[0]=EndX;
End[1]=EndY;
TmpPath.SetLineValue(true,Start,End,Feed);
PushBackPath(TmpPath);
}
void CLayer::InputDrawRelPath(float RelX, float RelY, UINT Feed)
{
CPath LastPath,TmpPath;
float Start[2],End[2];
LastPath=ReturnLastPath();
LastPath.GetEndPos(Start);
End[0]=Start[0]+RelX;
End[1]=Start[1]+RelY;
TmpPath.SetLineValue(true,Start,End,Feed);
PushBackPath(TmpPath);
}
void CLayer::MakeVPipe(float Width, float Length)
{
CPath TmpPath;
float Step;
UINT DrawFeed,MoveFeed;
Step=0.076f;
DrawFeed=29;
MoveFeed=200;
DrawRectangle(Width+Step*4.0f,Length+Step*4.0f,DrawFeed);
InputDrawRelPath(Step,Step,MoveFeed);
DrawRectangle(Width+Step*2.0f,Length+Step*2.0f,DrawFeed);
InputDrawRelPath(Step,Step,MoveFeed);
DrawRectangle(Width,Length,DrawFeed);
}
void CLayer::MakeGatePipe(float Radius, UINT Num)
{
if(Radius<0.2 || Num<3 )
return;
CPath TmpPath;
Nature Biotechnology: doi:10.1038/nbt.3413
float Step;
UINT DrawFeed,MoveFeed;
Step=0.076f;
DrawFeed=29;
MoveFeed=200;
Radius+=Step*(float)(Num-1);
float Start[2],End[2],Center[2];
Start[0]=0.0f;
End[0]=0.0f;
Center[0]=0.0f;
Center[1]=0.0f;
for(UINT i=0;i<(Num-1);++i)
{
Start[1]=Radius;
End[1]=Start[1];
TmpPath.SetCircleValue(true,true,Start,End,Center,DrawFeed);
PushBackPath(TmpPath);
Radius-=Step;
End[1]=Radius;
TmpPath.SetLineValue(true,Start,End,MoveFeed);
PushBackPath(TmpPath);
}
Start[1]=Radius;
End[1]=Start[1];
TmpPath.SetCircleValue(true,true,Start,End,Center,DrawFeed);
PushBackPath(TmpPath);
}
void CLayer::MakeJointType7(float Width, float Length)
{
CPath TmpPath;
float Step;
UINT DrawFeed,MoveFeed;
Step=0.076f;
DrawFeed=29;
MoveFeed=200;
DrawRectangle(Width+Step*6.0f,Length+Step*6.0f,DrawFeed);
InputDrawRelPath(Step,Step,MoveFeed);
DrawRectangle(Width+Step*4.0f,Length+Step*4.0f,DrawFeed);
InputDrawRelPath(Step,Step,MoveFeed);
DrawRectangle(Width+Step*2.0f,Length+Step*2.0f,DrawFeed);
Nature Biotechnology: doi:10.1038/nbt.3413
InputDrawRelPath(Step,Step,MoveFeed);
DrawRectangle(Width,Length,DrawFeed);
}
void CLayer::MakeHPipe(float Width, float Length)
{
CPath TmpPath;
float Step;
UINT DrawFeed,MoveFeed;
Step=0.076f;
DrawFeed=29;
MoveFeed=200;
InputDrawPath(Width/(-2.0f),Length/2.0f+Step*2.0f,Width/2.0f,Length/2.0f+Step*2.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),MoveFeed);
InputDrawRelPath((-1.0f)*Width,0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step*(-1.0f),MoveFeed);
InputDrawRelPath(Width,0.0f,DrawFeed);
InputDrawPath(Width/(-2.0f),(-1.0f)*(Length/2.0f+Step*2.0f),Width/2.0f,(-1.0f)*(Length/2.0f+Step*2.0f),DrawFeed);
InputDrawRelPath(0.0f,Step,MoveFeed);
InputDrawRelPath((-1.0f)*Width,0.0f,DrawFeed);
InputDrawRelPath(0.0f,Step,MoveFeed);
InputDrawRelPath(Width,0.0f,DrawFeed);
}
void CLayer::CriterionFeedrate(BOOL Draw, UINT CriterionFeed, UINT NewFeed)
{
for(UINT i=0;i<Path.size();++i)
{
if(Path[i].GetDrawingOrMove()==Draw && CriterionFeed==Path[i].GetFeedrate() &&
Path[i].GetDwellingTime()<0.001f)
Path[i].SetFeedrate(NewFeed);
}
}
double CLayer::ExportNewport(CString &Code, UINT Dwelling,UINT DrawingFeedPer)
{
UINT i;
CString TmpCode1,TmpCode2;
double Time=0.0;
if(Path[0].GetDrawingOrMove())
{
if(Dwelling>0)
TmpCode2.Format("G4 X%d\nM01\n",Dwelling*1000);
else
Nature Biotechnology: doi:10.1038/nbt.3413
TmpCode2.Format("M01\n");
Code+=TmpCode2;
TmpCode2.Empty();
Time+=(double)Dwelling;
}
Time+=Path[0].ExportNewport(TmpCode1,DrawingFeedPer);
Code+=TmpCode1;
TmpCode1.Empty();
for(i=1;i<Path.size();++i)
{
if( Path[i-1].GetDrawingOrMove() && !Path[i].GetDrawingOrMove() )
{
TmpCode2.Format("M02\n");
Code+=TmpCode2;
TmpCode2.Empty();
}
if( !Path[i-1].GetDrawingOrMove() && Path[i].GetDrawingOrMove() )
{
if(Dwelling>0)
TmpCode2.Format("G4 X%d\nM01\n",Dwelling*1000);
else
TmpCode2.Format("M01\n");
Code+=TmpCode2;
TmpCode2.Empty();
Time+=(double)Dwelling;
}
Time+=Path[i].ExportNewport(TmpCode1,DrawingFeedPer);
Code+=TmpCode1;
TmpCode1.Empty();
}
//마지막 Path가 drawing이면 out 1명령
if(Path[Path.size()-1].GetDrawingOrMove())
{
TmpCode2.Format("M02\n");
Code+=TmpCode2;
TmpCode2.Empty();
}
return Time;
}
BOOL CLayer::CompareTwoPath(int First, int Second)
{
double FirstAngle, SecondAngle;
Nature Biotechnology: doi:10.1038/nbt.3413
FirstAngle=Path[First].ReturnSlopeAngle();
if(Path[Second].GetCircle())
SecondAngle=Path[Second].ReturnSlopeAngleOfCircleStartPoint();
else
SecondAngle=Path[Second].ReturnSlopeAngle();
if( (int)(FirstAngle*1000.0)==(int)(SecondAngle*1000.0) )
{
return true;
}
else
{
return false;
}
}
double CLayer::ExportFDM(CString &Code, UINT Dwelling, UINT DrawingFeedPer)
{
UINT i;
CString TmpCode1,TmpCode2;
double Time=0.0;
BOOL IsFirstDraw=false;
int TimeForFirstShutterOn=5;
if(Path[0].GetDrawingOrMove())
{
if(Dwelling>0)
TmpCode2.Format("p%d\nv01\n",Dwelling*1000);
else
TmpCode2.Format("v01\n");
Code+=TmpCode2;
TmpCode2.Empty();
Time+=(double)Dwelling;
if(!IsFirstDraw)
{
TmpCode2.Format("p%d\n",TimeForFirstShutterOn*1000);
Code+=TmpCode2;
TmpCode2.Empty();
Time+=TimeForFirstShutterOn;
IsFirstDraw=true;
}
}
Nature Biotechnology: doi:10.1038/nbt.3413
Time+=Path[0].ExportFDM(TmpCode1,DrawingFeedPer);
Code+=TmpCode1;
TmpCode1.Empty();
for(i=1;i<Path.size();++i)
{
if( Path[i-1].GetDrawingOrMove() && !Path[i].GetDrawingOrMove() )
{
TmpCode2.Format("w01\n");
Code+=TmpCode2;
TmpCode2.Empty();
}
if( !Path[i-1].GetDrawingOrMove() && Path[i].GetDrawingOrMove() )
{
if(Dwelling>0)
TmpCode2.Format("p%d\nv01\n",Dwelling*1000);
else
TmpCode2.Format("v01\n");
Code+=TmpCode2;
TmpCode2.Empty();
Time+=(double)Dwelling;
if(!IsFirstDraw)
{
TmpCode2.Format("p%d\n",TimeForFirstShutterOn*1000);
Code+=TmpCode2;
TmpCode2.Empty();
Time+=TimeForFirstShutterOn;
IsFirstDraw=true;
}
}
Time+=Path[i].ExportFDM(TmpCode1,DrawingFeedPer);
Code+=TmpCode1;
TmpCode1.Empty();
}
if(Path[Path.size()-1].GetDrawingOrMove())
{
TmpCode2.Format("w01\n");
Code+=TmpCode2;
TmpCode2.Empty();
}
return Time;
Nature Biotechnology: doi:10.1038/nbt.3413
}
// InsertSliceThickness.h : header file
//
#include "STLFileTransferDoc.h"
/////////////////////////////////////////////////////////////////////////////
// CInsertSliceThickness dialog
class CInsertSliceThickness : public CDialog
{
// Construction
public:
CInsertSliceThickness(CSTLFileTransferDoc* TmppDoc, CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CInsertSliceThickness)
enum { IDD = IDD_INSERTSLTHICK };
double m_SliceThickness;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CInsertSliceThickness)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CInsertSliceThickness)
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
CSTLFileTransferDoc* pDoc;
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_INSERTSLICETHICKNESS_H__AA060D7B_B1BD_45D7_94EF_FA80B3EA4C3C__INCLUDED_)
// InsertSliceThickness.cpp : implementation file
//
Nature Biotechnology: doi:10.1038/nbt.3413
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "InsertSliceThickness.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CInsertSliceThickness dialog
CInsertSliceThickness::CInsertSliceThickness(CSTLFileTransferDoc* TmppDoc,CWnd* pParent /*=NULL*/)
: CDialog(CInsertSliceThickness::IDD, pParent)
{
//{{AFX_DATA_INIT(CInsertSliceThickness)
pDoc=TmppDoc;
m_SliceThickness = TmppDoc->SliceThickness;
//}}AFX_DATA_INIT
}
void CInsertSliceThickness::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CInsertSliceThickness)
DDX_Text(pDX, IDC_EDIT1, m_SliceThickness);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CInsertSliceThickness, CDialog)
//{{AFX_MSG_MAP(CInsertSliceThickness)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInsertSliceThickness message handlers
void CInsertSliceThickness::OnOK()
{
// TODO: Add extra validation here
UpdateData(true);
pDoc->SliceThickness = m_SliceThickness;
CDialog::OnOK();
}
Nature Biotechnology: doi:10.1038/nbt.3413
#if !defined(AFX_INSERTOFFSETVALUE_H__EC26C9F3_6754_49BF_B5EE_4395B56A4C1A__INCLUDED_)
#define AFX_INSERTOFFSETVALUE_H__EC26C9F3_6754_49BF_B5EE_4395B56A4C1A__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// InsertOffsetValue.h : header file
//
#include "STLFileTransferDoc.h"
/////////////////////////////////////////////////////////////////////////////
// CInsertOffsetValue dialog
class CInsertOffsetValue : public CDialog
{
// Construction
public:
CInsertOffsetValue(CSTLFileTransferDoc* TmppDoc,CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CInsertOffsetValue)
enum { IDD = IDD_INSERTSLICETHICK };
double m_OffsetValue;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CInsertOffsetValue)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CInsertOffsetValue)
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
CSTLFileTransferDoc* pDoc;
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
Nature Biotechnology: doi:10.1038/nbt.3413
#endif // !defined(AFX_INSERTOFFSETVALUE_H__EC26C9F3_6754_49BF_B5EE_4395B56A4C1A__INCLUDED_)
// InsertOffsetValue.cpp : implementation file
//
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "InsertOffsetValue.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CInsertOffsetValue dialog
CInsertOffsetValue::CInsertOffsetValue(CSTLFileTransferDoc* TmppDoc,CWnd* pParent /*=NULL*/)
: CDialog(CInsertOffsetValue::IDD, pParent)
{
//{{AFX_DATA_INIT(CInsertOffsetValue)
pDoc=TmppDoc;
m_OffsetValue = TmppDoc->OffsetValue;
//}}AFX_DATA_INIT
}
void CInsertOffsetValue::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CInsertOffsetValue)
DDX_Text(pDX, IDC_OFFSETVAL, m_OffsetValue);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CInsertOffsetValue, CDialog)
//{{AFX_MSG_MAP(CInsertOffsetValue)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInsertOffsetValue message handlers
void CInsertOffsetValue::OnOK()
{
// TODO: Add extra validation here
Nature Biotechnology: doi:10.1038/nbt.3413
UpdateData(true);
pDoc->OffsetValue = m_OffsetValue;
CDialog::OnOK();
}
#if !defined(AFX_INSERTFABINFDIALOG_H__9791FAAA_6AA0_4B7F_8E40_2FFEEF0FD138__INCLUDED_)
#define AFX_INSERTFABINFDIALOG_H__9791FAAA_6AA0_4B7F_8E40_2FFEEF0FD138__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// InsertFabInfDialog.h : header file
//
#include "STLFileTransferDoc.h"
/////////////////////////////////////////////////////////////////////////////
// CInsertFabInfDialog dialog
class CInsertFabInfDialog : public CDialog
{
// Construction
public:
CInsertFabInfDialog(CSTLFileTransferDoc* TmppDoc, CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CInsertFabInfDialog)
enum { IDD = IDD_INSERTFABINF };
UINT m_LaserPower;
UINT m_Feedrate;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CInsertFabInfDialog)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CInsertFabInfDialog)
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
CSTLFileTransferDoc* pDoc;
Nature Biotechnology: doi:10.1038/nbt.3413
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_INSERTFABINFDIALOG_H__9791FAAA_6AA0_4B7F_8E40_2FFEEF0FD138__INCLUDED_)
// InsertFabInfDialog.cpp : implementation file
//
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "InsertFabInfDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CInsertFabInfDialog dialog
CInsertFabInfDialog::CInsertFabInfDialog(CSTLFileTransferDoc* TmppDoc, CWnd* pParent /*=NULL*/)
: CDialog(CInsertFabInfDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CInsertFabInfDialog)
pDoc=TmppDoc;
m_LaserPower = TmppDoc->LaserPower;
m_Feedrate = TmppDoc->Feedrate;
//}}AFX_DATA_INIT
}
void CInsertFabInfDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CInsertFabInfDialog)
DDX_Text(pDX, IDC_LASERPOW, m_LaserPower);
DDX_Text(pDX, IDC_FEEDRATE, m_Feedrate);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CInsertFabInfDialog, CDialog)
//{{AFX_MSG_MAP(CInsertFabInfDialog)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
Nature Biotechnology: doi:10.1038/nbt.3413
/////////////////////////////////////////////////////////////////////////////
// CInsertFabInfDialog message handlers
void CInsertFabInfDialog::OnOK()
{
// TODO: Add extra validation here
UpdateData(true);
pDoc->LaserPower = m_LaserPower;
pDoc->Feedrate = m_Feedrate;
CDialog::OnOK();
}
#if !defined(AFX_INSERTDMDBEMAPAR_H__11DB81AB_0DCE_4D78_A9D3_3BBAA31A170E__INCLUDED_)
#define AFX_INSERTDMDBEMAPAR_H__11DB81AB_0DCE_4D78_A9D3_3BBAA31A170E__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// InsertDMDBemaPar.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CInsertDMDBemaPar dialog
class CInsertDMDBemaPar : public CDialog
{
// Construction
public:
CInsertDMDBemaPar(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CInsertDMDBemaPar)
enum { IDD = IDD_INSERTDMDBEAMDIAL };
UINT m_DMDPixelX;
UINT m_DMDPixelY;
double m_OneImageSizeX;
double m_OneImageSizeY;
UINT m_IlluminationTime;
double m_OffsetValue;
double m_ErrorOffsetValue;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CInsertDMDBemaPar)
protected:
Nature Biotechnology: doi:10.1038/nbt.3413
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CInsertDMDBemaPar)
// NOTE: the ClassWizard will add member functions here
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_INSERTDMDBEMAPAR_H__11DB81AB_0DCE_4D78_A9D3_3BBAA31A170E__INCLUDED_)
// InsertDMDBemaPar.cpp : implementation file
//
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "InsertDMDBemaPar.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CInsertDMDBemaPar dialog
CInsertDMDBemaPar::CInsertDMDBemaPar(CWnd* pParent /*=NULL*/)
: CDialog(CInsertDMDBemaPar::IDD, pParent)
{
//{{AFX_DATA_INIT(CInsertDMDBemaPar)
m_DMDPixelX = 0;
m_DMDPixelY = 0;
m_OneImageSizeX = 0.0;
m_OneImageSizeY = 0.0;
m_IlluminationTime = 0;
m_OffsetValue = 0.0;
m_ErrorOffsetValue = 0.0;
//}}AFX_DATA_INIT
}
Nature Biotechnology: doi:10.1038/nbt.3413
void CInsertDMDBemaPar::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CInsertDMDBemaPar)
DDX_Text(pDX, IDC_EDIT1, m_DMDPixelX);
DDX_Text(pDX, IDC_EDIT2, m_DMDPixelY);
DDX_Text(pDX, IDC_EDIT3, m_OneImageSizeX);
DDX_Text(pDX, IDC_EDIT4, m_OneImageSizeY);
DDX_Text(pDX, IDC_EDIT6, m_IlluminationTime);
DDX_Text(pDX, IDC_EDIT7, m_OffsetValue);
DDX_Text(pDX, IDC_EDIT8, m_ErrorOffsetValue);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CInsertDMDBemaPar, CDialog)
//{{AFX_MSG_MAP(CInsertDMDBemaPar)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInsertDMDBemaPar message handlers
#if !defined(AFX_INSERTBEAMGENPARDIAL_H__3196957C_6CF1_445C_9867_E57F32B8CEF5__INCLUDED_)
#define AFX_INSERTBEAMGENPARDIAL_H__3196957C_6CF1_445C_9867_E57F32B8CEF5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// InsertBeamGenParDial.h : header file
//
#include "STLFileTransferDoc.h"
/////////////////////////////////////////////////////////////////////////////
// CInsertBeamGenParDial dialog
class CInsertBeamGenParDial : public CDialog
{
// Construction
public:
CInsertBeamGenParDial(CSTLFileTransferDoc* TmppDoc, CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CInsertBeamGenParDial)
enum { IDD = IDD_INSERTPATHPAR };
double m_OffsetValue;
double m_FabErrorOffsetValue;
int m_NumOfOffset;
Nature Biotechnology: doi:10.1038/nbt.3413
double m_MinMoveDis;
double m_MaxMoveDis;
double m_DifCWRotAngle;
double m_LinePitch;
int m_NumOfDirectionOverlap;
int m_GenMode;
double m_MoldOffsetSize;
BOOL m_IsMoldGeneration;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CInsertBeamGenParDial)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CInsertBeamGenParDial)
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
CSTLFileTransferDoc* pDoc;
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_INSERTBEAMGENPARDIAL_H__3196957C_6CF1_445C_9867_E57F32B8CEF5__INCLUDED_)
// InsertBeamGenParDial.cpp : implementation file
//
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "InsertBeamGenParDial.h"
#define PI 3.141592653589793
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
Nature Biotechnology: doi:10.1038/nbt.3413
/////////////////////////////////////////////////////////////////////////////
// CInsertBeamGenParDial dialog
CInsertBeamGenParDial::CInsertBeamGenParDial(CSTLFileTransferDoc* TmppDoc, CWnd* pParent /*=NULL*/)
: CDialog(CInsertBeamGenParDial::IDD, pParent)
{
//{{AFX_DATA_INIT(CInsertBeamGenParDial)
m_OffsetValue = TmppDoc->OffsetValue;
m_FabErrorOffsetValue = TmppDoc->FabErrorOffsetValue;
m_NumOfOffset = TmppDoc->NumOfOffset;
m_MinMoveDis = TmppDoc->MinMoveDis;
m_MaxMoveDis = TmppDoc->MaxMoveDis;
m_DifCWRotAngle = TmppDoc->DifCWRotAngle*180.0/PI;
m_LinePitch = TmppDoc->LinePitch;
m_NumOfDirectionOverlap = TmppDoc->NumOfDirectionOverlap;
m_GenMode = TmppDoc->BeamPathGenMode-1;
m_MoldOffsetSize = 3.0;
pDoc=TmppDoc;
m_IsMoldGeneration = FALSE;
//}}AFX_DATA_INIT
}
void CInsertBeamGenParDial::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CInsertBeamGenParDial)
DDX_Text(pDX, IDC_OFFSETVALUE, m_OffsetValue);
DDX_Text(pDX, IDC_ERROROFFSETVAL, m_FabErrorOffsetValue);
DDX_Text(pDX, IDC_NUMOFOFFSET, m_NumOfOffset);
DDX_Text(pDX, IDC_MINMOVEDIS, m_MinMoveDis);
DDX_Text(pDX, IDC_MAXMOVEDIS, m_MaxMoveDis);
DDX_Text(pDX, IDC_ROTANG, m_DifCWRotAngle);
DDX_Text(pDX, IDC_LINEPITCH, m_LinePitch);
DDX_Text(pDX, IDC_NUMOFDIROVERLAP, m_NumOfDirectionOverlap);
DDX_Radio(pDX, IDC_MODE1, m_GenMode);
DDX_Text(pDX, IDC_NUMOFDIROVERLAP2, m_MoldOffsetSize);
DDX_Check(pDX, IDC_CHECK1, m_IsMoldGeneration);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CInsertBeamGenParDial, CDialog)
//{{AFX_MSG_MAP(CInsertBeamGenParDial)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
Nature Biotechnology: doi:10.1038/nbt.3413
/////////////////////////////////////////////////////////////////////////////
// CInsertBeamGenParDial message handlers
void CInsertBeamGenParDial::OnOK()
{
// TODO: Add extra validation here
UpdateData(true);
pDoc->OffsetValue = m_OffsetValue;
pDoc->FabErrorOffsetValue = m_FabErrorOffsetValue;
pDoc->NumOfOffset = m_NumOfOffset;
pDoc->MinMoveDis = m_MinMoveDis;
pDoc->MaxMoveDis = m_MaxMoveDis;
pDoc->DifCWRotAngle = m_DifCWRotAngle*PI/180.0;
pDoc->LinePitch = m_LinePitch;
pDoc->NumOfDirectionOverlap = m_NumOfDirectionOverlap;
pDoc->BeamPathGenMode = m_GenMode + 1;
CDialog::OnOK();
}
#if !defined(AFX_INPUTHEIGHTDIALOG_H__89DD7001_B887_4B1C_8E70_04460CF10BB4__INCLUDED_)
#define AFX_INPUTHEIGHTDIALOG_H__89DD7001_B887_4B1C_8E70_04460CF10BB4__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// InputHeightDialog.h : header file
//
/////////////////////////////////////////////////////////////////////////////
// CInputHeightDialog dialog
class CInputHeightDialog : public CDialog
{
// Construction
public:
CInputHeightDialog(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CInputHeightDialog)
enum { IDD = IDD_INPUTHEIGHT };
double m_Height;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CInputHeightDialog)
protected:
Nature Biotechnology: doi:10.1038/nbt.3413
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CInputHeightDialog)
// NOTE: the ClassWizard will add member functions here
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_INPUTHEIGHTDIALOG_H__89DD7001_B887_4B1C_8E70_04460CF10BB4__INCLUDED_)
// InputHeightDialog.cpp : implementation file
//
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "InputHeightDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CInputHeightDialog dialog
CInputHeightDialog::CInputHeightDialog(CWnd* pParent /*=NULL*/)
: CDialog(CInputHeightDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CInputHeightDialog)
m_Height = 1.0;
//}}AFX_DATA_INIT
}
void CInputHeightDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CInputHeightDialog)
DDX_Text(pDX, IDC_HEIGHTVALUE, m_Height);
Nature Biotechnology: doi:10.1038/nbt.3413
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CInputHeightDialog, CDialog)
//{{AFX_MSG_MAP(CInputHeightDialog)
// NOTE: the ClassWizard will add message map macros here
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInputHeightDialog message handlers
// Gate.h: interface for the CGate class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_GATE_H__785A67EE_AAF0_4ADA_9640_C849D5296122__INCLUDED_)
#define AFX_GATE_H__785A67EE_AAF0_4ADA_9640_C849D5296122__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CGate
{
public:
BOOL IsSameGate(CGate TmpGate);
void GateSaveOrLoad(BOOL Save, CArchive &ar);
void SetRectGate(float TmpPos[3],float TmpUnit[3],float Length[2]);
void SetCircleGate(float TmpPos[3],float TmpUnit[3],float TmpRadius);
BOOL IsCircle();
void GetRectLength(float Length[2]);
float GetRadius();
void SetRectLength(float Length[2]);
void SetRadius(float TmpRadius);
void GetUnitVector(float TmpUnit[3]);
void GetPosition(float TmpPos[3]);
void SetUnitVector(float UnitX,float UnitY,float UnitZ);
void SetPosition(float X,float Y,float Z);
CGate();
virtual ~CGate();
private:
float RectLength[2];
BOOL Circle;
float Radius;
float UnitVector[3];
float Position[3];
Nature Biotechnology: doi:10.1038/nbt.3413
};
#endif // !defined(AFX_GATE_H__785A67EE_AAF0_4ADA_9640_C849D5296122__INCLUDED_)
// Gate.cpp: implementation of the CGate class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "Gate.h"
#include "math.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CGate::CGate()
{
for(UINT i=0;i<3;++i)
{
Position[i]=0.0f;
UnitVector[i]=0.0f;
}
Radius=0.0f;
Circle=false;
RectLength[0]=0.0f;
RectLength[1]=0.0f;
}
CGate::~CGate()
{
}
void CGate::SetPosition(float X, float Y, float Z)
{
Position[0]=X;
Position[1]=Y;
Position[2]=Z;
}
void CGate::SetUnitVector(float UnitX, float UnitY, float UnitZ)
Nature Biotechnology: doi:10.1038/nbt.3413
{
float Length;
if( (int)(UnitX*1000.0f)==0 && (int)(UnitY*1000.0f)==0 && (int)(UnitZ*1000.0f)==0 )
Length=1.0f;
else
Length=(float)sqrt((double)(UnitX*UnitX+UnitY*UnitY+UnitZ*UnitZ));
UnitVector[0]=UnitX/Length;
UnitVector[1]=UnitY/Length;
UnitVector[2]=UnitZ/Length;
if( (int)(UnitVector[0]*1000.0f)==0 && (int)(UnitVector[1]*1000.0f)==0 && (int)(UnitVector[2]*1000.0f)==0 )
UnitVector[2]=1.0f;
}
void CGate::GetPosition(float TmpPos[])
{
TmpPos[0]=Position[0];
TmpPos[1]=Position[1];
TmpPos[2]=Position[2];
}
void CGate::GetUnitVector(float TmpUnit[])
{
TmpUnit[0]=UnitVector[0];
TmpUnit[1]=UnitVector[1];
TmpUnit[2]=UnitVector[2];
}
void CGate::SetRadius(float TmpRadius)
{
Circle=true;
RectLength[0]=0.0f;
RectLength[1]=0.0f;
if(TmpRadius<0.0f)
TmpRadius*=(-1.0f);
if((int)(TmpRadius*1000.0f)==0)
TmpRadius=1.0;
Radius=TmpRadius;
}
void CGate::SetRectLength(float Length[])
{
Circle=false;
Radius=0.0f;
if(Length[0]<0.0f)
Length[0]*=(-1.0f);
if(Length[1]<0.0f)
Length[1]*=(-1.0f);
Nature Biotechnology: doi:10.1038/nbt.3413
RectLength[0]=Length[0];
RectLength[1]=Length[1];
}
float CGate::GetRadius()
{
return Radius;
}
void CGate::GetRectLength(float Length[])
{
Length[0]=RectLength[0];
Length[1]=RectLength[1];
}
BOOL CGate::IsCircle()
{
return Circle;
}
void CGate::SetCircleGate(float TmpPos[], float TmpUnit[], float TmpRadius)
{
SetPosition(TmpPos[0],TmpPos[1],TmpPos[2]);
SetUnitVector(TmpUnit[0],TmpUnit[1],TmpUnit[2]);
SetRadius(TmpRadius);
}
void CGate::SetRectGate(float TmpPos[], float TmpUnit[], float Length[])
{
SetPosition(TmpPos[0],TmpPos[1],TmpPos[2]);
SetUnitVector(TmpUnit[0],TmpUnit[1],TmpUnit[2]);
SetRectLength(Length);
}
void CGate::GateSaveOrLoad(BOOL Save, CArchive &ar)
{
if(Save)
{
ar<<Circle;
ar<<Position[0]<<Position[1]<<Position[2];
ar<<Radius;
ar<<RectLength[0]<<RectLength[1];
ar<<UnitVector[0]<<UnitVector[1]<<UnitVector[2];
}
else
{
ar>>Circle;
ar>>Position[0]>>Position[1]>>Position[2];
ar>>Radius;
Nature Biotechnology: doi:10.1038/nbt.3413
ar>>RectLength[0]>>RectLength[1];
ar>>UnitVector[0]>>UnitVector[1]>>UnitVector[2];
if( (int)(UnitVector[0]*1000.0f)==0 && (int)(UnitVector[1]*1000.0f)==0 && (int)(UnitVector[2]*1000.0f)==0 )
UnitVector[2]=1.0f;
}
}
BOOL CGate::IsSameGate(CGate TmpGate)
{
float TmpRectLength[2],TmpRadius,TmpUnitVector[3],TmpPosition[3];
BOOL TmpCircle;
TmpGate.GetPosition(TmpPosition);
TmpRadius=TmpGate.GetRadius();
TmpGate.GetRectLength(TmpRectLength);
TmpGate.GetUnitVector(TmpUnitVector);
TmpCircle=TmpGate.IsCircle();
for(UINT i=0;i<3;++i)
{
if( (int)(TmpPosition[i]*1000.0f)!=(int)(Position[i]*1000.0f))
return false;
if( (int)(TmpUnitVector[i]*1000.0f)!=(int)(UnitVector[i]*1000.0f))
return false;
}
for(i=0;i<2;++i)
{
if( (int)(TmpRectLength[i]*1000.0f)!=(int)(RectLength[i]*1000.0f))
return false;
}
if( (int)(TmpRadius*1000.0f)!=(int)(Radius*1000.0f))
return false;
if(TmpCircle!=Circle)
return false;
return true;
}
// DMDOneImage.h: interface for the CDMDOneImage class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_DMDONEIMAGE_H__66229191_CBFF_488D_B861_9EBA15DAF5C9__INCLUDED_)
#define AFX_DMDONEIMAGE_H__66229191_CBFF_488D_B861_9EBA15DAF5C9__INCLUDED_
Nature Biotechnology: doi:10.1038/nbt.3413
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include "DMDOneImage.h"
#include <vector>
class CDMDOneImage
{
public:
double CenterPos[2];
BOOL Image[1024][768];
CDMDOneImage();
virtual ~CDMDOneImage();
};
#endif // !defined(AFX_DMDONEIMAGE_H__66229191_CBFF_488D_B861_9EBA15DAF5C9__INCLUDED_)
// DMDOneImage.cpp: implementation of the CDMDOneImage class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "DMDOneImage.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDMDOneImage::CDMDOneImage()
{
}
CDMDOneImage::~CDMDOneImage()
{
}
//////////////////////////////////////////////////////////////////////
Nature Biotechnology: doi:10.1038/nbt.3413
#if !defined(AFX_DMDLAYERIMAGE_H__4AF0B0B0_A63A_4E67_BD48_13E69EAD6455__INCLUDED_)
#define AFX_DMDLAYERIMAGE_H__4AF0B0B0_A63A_4E67_BD48_13E69EAD6455__INCLUDED_
#include "DMDOneImage.h" // Added by ClassView
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CDMDLayerImage
{
public:
UINT IlluminationTime;
double LayerThickness;
std::vector<CDMDOneImage> ImageVec;
CDMDLayerImage();
virtual ~CDMDLayerImage();
};
#endif // !defined(AFX_DMDLAYERIMAGE_H__4AF0B0B0_A63A_4E67_BD48_13E69EAD6455__INCLUDED_)
// DMDLayerImage.cpp: implementation of the CDMDLayerImage class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "DMDLayerImage.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDMDLayerImage::CDMDLayerImage()
{
IlluminationTime=1000; //1000 msec
LayerThickness=0.1; //0.1mm
}
CDMDLayerImage::~CDMDLayerImage()
{
}
Nature Biotechnology: doi:10.1038/nbt.3413
// ClosedLoop.h: interface for the CClosedLoop class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CLOSEDLOOP_H__504DDC78_4C32_432D_96E0_0EA2978CF7E4__INCLUDED_)
#define AFX_CLOSEDLOOP_H__504DDC78_4C32_432D_96E0_0EA2978CF7E4__INCLUDED_
#include "TwoDLine.h" // Added by ClassView
#include <vector>
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CClosedLoop
{
public:
void DeleteInvalidOffsetLine();
void Initialize();
void SaveOrLoad(BOOL Save, CArchive &ar);
void InsertRecMoldLineToContourBeamLine(double MaxX, double MaxY, double MinX, double MinY);
double ReturnMinXValInBeamLines();
double ReturnMaxXValInBeamLines();
void InsertRecMoldLineToContourOffsetBeamLine(double MaxX, double MaxY, double MinX, double MinY);
void ArrangeOneScanBeamLine();
void ArrangeContourOffsetBeamLine();
void ArrangeContourBeamLine();
void CalAveNorVecOfOffsetLine(int StartNum, int EndNum, double AveNorVec[2]);
void InitializationWithoutLineOffsetBeamLine();
void OverWriteOffsetCBLToCBL();
void InsertOneScanBeamLine(int Num, CTwoDLine TmpLine);
int GetNumOfOneScanBeamLine();
CTwoDLine GetOneScanBeamLine(int Num);
void PushBackOneScanBeamLine(CTwoDLine TmpLine);
BOOL DivideLineOfContourOffsetBeamLine(int LineNum, double Point[]);
BOOL DivideLineOfContourBeamLine(int LineNum, double Point[2]);
void SetContourOffsetBeamLine(int Num, CTwoDLine TmpLine);
void SetContourBeamLine(int Num, CTwoDLine TmpLine);
void OffsetLineRefineAfterMerge();
void UsedSEOffsetNumForConnecting(int InsertedNum);
void EraseSEXYOffsetVal(int Num);
void DeleteOverlapOffsetLines(CClosedLoop TmpClosedLoop);
void OffsetLineValueRefine();
void LineValueRefine();
void MinErrorBoundOffset();
void RemoveOverLapOffsetLine();
void InsertOffsetLine(int Index, CTwoDLine TmpOffsetLine);
BOOL GetSEOffsetValuesAndNorVec(int Index, double SEOffsetValues[2], double SEOffValNorVec[2], int
&SEOffsetNum, BOOL &SEOffMode);
Nature Biotechnology: doi:10.1038/nbt.3413
int GetNumOfSEOffsetVal();
void FindSEXYOffsetVal();
BOOL IsTwoPositionSame(double Point1[2], double Point2[2]);
double DistanceOfTwoPosition(double Pos1[2], double Pos2[2]);
BOOL CheckConnectingWithOffsetLines(double CLoopSEPosition[2], double CLoopSENorVec[2], CTwoDLine
&MinDistConnectingLine, int &SEXOffsetValNum);
void ConnectingOffsetLines(double OffsetValue);
void RemovePointCrossBeamLine();
void RemovePointContourOffsetBeamLine();
void RemovePointContourBeamLine();
void RemovePointBeamLine();
void GetCenterOfClosedLoop(double Center[2]);
void InsertCrossBeamLine(CTwoDLine TmpLine);
void InitializationCrossBeamLine();
double ReturnMaxYValInBeamLines();
double ReturnMinYValInBeamLines();
void ClosedLoopCWRotation(double Center[2], double CWAngle);
BOOL IsMaxOffLoop();
void SetIsMaxOffsetLoop(BOOL IsMax);
void InitializationWithoutLine();
void DeleteOverlapOffsetLines();
void OffsetLineOverLapTestAndDevide();
void LineDivideInMaxLength(double MaxLength);
void CalAveNorVecOfLine(int StartNum, int EndNum, double AveNorVec[2]);
CTwoDLine GetCrossBeamLine(int Num);
int GetNumOfCrossBeamLine();
CTwoDLine GetContourOffsetBeamLine(int Num);
int GetNumOfContourOffsetBeamLine();
CTwoDLine GetContourBeamLine(int Num);
int GetNumOfContourBeamLine();
BOOL VectorGunCalTargetOffsetBeamLine(double MaxMoveDis, CTwoDLine GunLine, CTwoDLine
&ReturnCrossBeamLine);
void GenerationCrossBeamLine(double MaxMoveDis);
BOOL OffsetLineLinkageTest(int StartNum, int EndNum);
void GenerationContourOffsetBeamLine(double MinMoveDis);
BOOL LineLinkageTest(int StartNum, int EndNum);
double CalTwoPointLength(double Pos1[2],double Pos2[2]);
void GenerationContourBeamLine(double MinMoveDis);
void OffsetLineCompareAndDivide(CClosedLoop TmpClosedLoop);
void OffsetLineEAreaTWithOtherClosedLoop(CClosedLoop TmpClosedLoop, double OffsetValue);
void RemovePointOffsetLine();
BOOL IsInnerOffset();
BOOL OffsetLineContinuousTest();
BOOL IsOffsetLineEffectiveAreaTest1(CTwoDLine TmpOffsetLine, double OffsetValue);
BOOL IsPointInTheCircle(double Center[2], double Radius, double Point[2], BOOL IsLeftCheck);
BOOL IsPointInTheRect(double HalfHeight, double Length, double Point[2]);
BOOL IsPointsOfLineInTheEffectiveArea(double CCWAngle, double Center[2], double Length, CTwoDLine
TmpLine, double OffsetValue, BOOL IsInsertedLine);
BOOL LeastJoinCondition(CTwoDLine Line1, CTwoDLine Line2);
Nature Biotechnology: doi:10.1038/nbt.3413
CTwoDLine GetOffsetLine(int LineNum);
int GetNumOfOffsetLine();
BOOL CalCrossOfTwoLines(CTwoDLine Line1, CTwoDLine Line2, double CrossPos[2] );
BOOL DoOffsetLoop(double OffsetValue);
int GetNumOfLine();
CTwoDLine GetLine(int LineNum);
void Initialization();
void PushBackLine(CTwoDLine TmpLine);
CClosedLoop();
virtual ~CClosedLoop();
private:
BOOL IsMaxOffsetLoop;
std::vector<int> SEOffsetMode;
std::vector<int> SEOffsetNumber;
std::vector<double> SEXOffsetVal;
std::vector<double> SEYOffsetVal;
std::vector<CTwoDLine> OneScanBeamLine;
std::vector<CTwoDLine> CrossBeamLine;
std::vector<CTwoDLine> ContourOffsetBeamLine;
std::vector<CTwoDLine> ContourBeamLine;
std::vector<CTwoDLine> OffsetLine;
std::vector<CTwoDLine> Line;
};
#endif // !defined(AFX_CLOSEDLOOP_H__504DDC78_4C32_432D_96E0_0EA2978CF7E4__INCLUDED_)
// ClosedLoop.cpp: implementation of the CClosedLoop class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "STLFileTransfer.h"
#include "ClosedLoop.h"
#include "math.h"
#define NumErrorFindDouble 10000000.0
#define NumErrorFindInt 10000000
#define PI 3.141592653589793
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
Nature Biotechnology: doi:10.1038/nbt.3413
CClosedLoop::CClosedLoop()
{
IsMaxOffsetLoop=true;
}
CClosedLoop::~CClosedLoop()
{
CrossBeamLine.clear();
ContourOffsetBeamLine.clear();
ContourBeamLine.clear();
OffsetLine.clear();
Line.clear();
SEXOffsetVal.clear();
SEYOffsetVal.clear();
SEOffsetNumber.clear();
SEOffsetMode.clear();
OneScanBeamLine.clear();
}
void CClosedLoop::PushBackLine(CTwoDLine TmpLine)
{
Line.push_back(TmpLine);
}
void CClosedLoop::Initialization()
{
Line.clear();
InitializationWithoutLine();
}
CTwoDLine CClosedLoop::GetLine(int LineNum)
{
return Line.at(LineNum);
}
int CClosedLoop::GetNumOfLine()
{
return Line.size();
}
BOOL CClosedLoop::DoOffsetLoop(double OffsetValue)
{
if(OffsetLine.size()>0) OffsetLine.clear();
// LineDivideInMaxLength(OffsetValue/2.0);
int i;
CTwoDLine TmpLine;
Nature Biotechnology: doi:10.1038/nbt.3413
BOOL IsOffsetLineCotinuous=true;
// offset 선들을 만들어 주는 부분 - 듬성듬성 있는 선들을 만듦
for(i=0;i<Line.size();i++)
{
OffsetLine.push_back(Line.at(i));
OffsetLine.at(i).DoOffsetLineUsingNorVec(OffsetValue);
}
// offset 선들을 연장 시켜 주는 부분
ConnectingOffsetLines(OffsetValue);
// offset 선들끼리 만나는 점을 찾아서 선을 분할 해주는 부분
OffsetLineOverLapTestAndDevide();
//03252015 보강.
DeleteInvalidOffsetLine();
// 두점중 한점이 내부에 있는지 확인 - Effective Area Test 1 => 아직 완벽 하지 못함. 라인이 자꾸 끊어짐.
for(i=0;i<OffsetLine.size();i++)
{
if( IsOffsetLineEffectiveAreaTest1(OffsetLine.at(i),OffsetValue) )
{
OffsetLine.erase(&OffsetLine.at(i));
--i;
}
}
// 점 혹은 짧은 선으로 된 Offset 선을 지워 주기
RemovePointOffsetLine();
// Offset 선의 연속성 테스트 및 끊어져 있을 때는 연결도 시켜줌.
IsOffsetLineCotinuous=OffsetLineContinuousTest();
// 같은 방향 벡터를 가지는 선들을 비교하여 서로 끊어 주는 역할
DeleteOverlapOffsetLines(); // 거의 필요가 없는 듯 ???
// OffsetLine을 위한 refine함수
OffsetLineValueRefine();
return IsOffsetLineCotinuous;
}
BOOL CClosedLoop::CalCrossOfTwoLines(CTwoDLine Line1, CTwoDLine Line2, double CrossPos[])
{
Nature Biotechnology: doi:10.1038/nbt.3413
double Pos1[2],Pos2[2],Pos3[2],Pos4[2],NorVec1[2],NorVec2[2];
double Alpa1,Beta1,Alpa2,Beta2;
Line1.GetTwoPosition(Pos1,Pos2);
Line2.GetTwoPosition(Pos3,Pos4);
Line1.GetNorVec(NorVec1);
Line2.GetNorVec(NorVec2);
if( fabs(Pos2[0]-Pos3[0])<0.00001 && fabs(Pos2[1]-Pos3[1])<0.00001 ) // mm 스케일에서 10nm 근처의 점은 한점.
// if( (int)(Pos2[0]*NumErrorFindDouble)==(int)(Pos3[0]*NumErrorFindDouble)
// && (int)(Pos2[1]*NumErrorFindDouble)==(int)(Pos3[1]*NumErrorFindDouble) )
{
CrossPos[0]=Pos2[0];
CrossPos[1]=Pos2[1];
return true;
}
if( fabs(Pos1[0]-Pos4[0])<0.00001 && fabs(Pos1[1]-Pos4[1])<0.00001 ) // mm 스케일에서 10nm 근처의 점은 한점.
// if( (int)(Pos1[0]*NumErrorFindDouble)==(int)(Pos4[0]*NumErrorFindDouble)
// && (int)(Pos1[1]*NumErrorFindDouble)==(int)(Pos4[1]*NumErrorFindDouble) )
{
CrossPos[0]=Pos1[0];
CrossPos[1]=Pos1[1];
return true;
}
if( (int)(NorVec1[0]*NumErrorFindDouble)==(int)(NorVec2[0]*NumErrorFindDouble)
&& (int)(NorVec1[1]*NumErrorFindDouble)==(int)(NorVec2[1]*NumErrorFindDouble) )
return false;
if( (int)(fabs(Pos1[0]-Pos2[0])*NumErrorFindDouble) == 0 )
{
if( (int)(fabs(Pos3[0]-Pos4[0])*NumErrorFindDouble) == 0 )
{
CrossPos[0]=0.0f;
CrossPos[1]=0.0f;
return false;
}
else
{
Alpa1=Pos1[0];
Alpa2=( Pos3[1]-Pos4[1] ) / ( Pos3[0]-Pos4[0] );
Beta2=( Pos3[0]*Pos4[1] - Pos4[0]*Pos3[1] ) / ( Pos3[0]-Pos4[0] );
CrossPos[0]=Alpa1;
CrossPos[1]=Alpa2 * Alpa1 + Beta2;
return true;
}
Nature Biotechnology: doi:10.1038/nbt.3413
}
else if( (int)(fabs(Pos3[0]-Pos4[0])*NumErrorFindDouble) ==0 )
{
Alpa1=( Pos1[1]-Pos2[1] ) / ( Pos1[0]-Pos2[0] );
Beta1=( Pos1[0]*Pos2[1] - Pos2[0]*Pos1[1] ) / ( Pos1[0]-Pos2[0] );
Alpa2=Pos3[0];
CrossPos[0]=Alpa2;
CrossPos[1]=Alpa1 * Alpa2 + Beta1;
return true;
}
else
{
Alpa1=( Pos1[1]-Pos2[1] ) / ( Pos1[0]-Pos2[0] );
Beta1=( Pos1[0]*Pos2[1] - Pos2[0]*Pos1[1] ) / ( Pos1[0]-Pos2[0] );
Alpa2=( Pos3[1]-Pos4[1] ) / ( Pos3[0]-Pos4[0] );
Beta2=( Pos3[0]*Pos4[1] - Pos4[0]*Pos3[1] ) / ( Pos3[0]-Pos4[0] );
CrossPos[0]=( Beta2 - Beta1 ) / ( Alpa1 - Alpa2 );
CrossPos[1]=( Alpa1 * Beta2 - Alpa2 * Beta1 ) / ( Alpa1 - Alpa2 );
return true; // 일반 적인 경우
}
}
int CClosedLoop::GetNumOfOffsetLine()
{
return OffsetLine.size();
}
CTwoDLine CClosedLoop::GetOffsetLine(int LineNum)
{
return OffsetLine.at(LineNum);
}
BOOL CClosedLoop::LeastJoinCondition(CTwoDLine Line1, CTwoDLine Line2)
{
double Pos1_1[2],Pos1_2[2],Pos2_1[2],Pos2_2[2];
double RightX,LeftX,UpperY,LowerY;
Line1.GetTwoPosition(Pos1_1,Pos1_2);
Line2.GetTwoPosition(Pos2_1,Pos2_2);
if(Pos1_1[0]>Pos1_2[0])
{
RightX=Pos1_1[0]; LeftX=Pos1_2[0];
}
Nature Biotechnology: doi:10.1038/nbt.3413
else
{
RightX=Pos1_2[0]; LeftX=Pos1_1[0];
}
if(Pos1_1[1]>Pos1_2[1])
{
UpperY=Pos1_1[1]; LowerY=Pos1_2[1];
}
else
{
UpperY=Pos1_2[1]; LowerY=Pos1_1[1];
}
if( Pos2_1[1] >= UpperY && Pos2_2[1] >= UpperY )
return false;
else if( Pos2_1[1] <= LowerY && Pos2_2[1] <= LowerY )
return false;
else if( Pos2_1[0] >= RightX && Pos2_2[0] >= RightX )
return false;
else if( Pos2_1[0] <= LeftX && Pos2_2[0] <= LeftX )
return false;
else
return true;
}
BOOL CClosedLoop::IsPointsOfLineInTheEffectiveArea(double CCWAngle, double Center[2], double Length, CTwoDLine
TmpLine, double OffsetValue, BOOL IsInsertedLine)
{
double Pos1[2],Pos2[2],TmpCenter[2];
TmpLine.LineCWRotation(Center,CCWAngle);
TmpCenter[0]=Center[0]*(-1.0);
TmpCenter[1]=Center[1]*(-1.0);
TmpLine.LineTranslation(TmpCenter);
TmpLine.GetTwoPosition(Pos1,Pos2);
if(!IsInsertedLine)
{
if( IsPointInTheRect(OffsetValue,Length,Pos1) || IsPointInTheRect(OffsetValue,Length,Pos2) )
return true;
}
TmpCenter[0]=0.0;
TmpCenter[1]=0.0;
if( IsPointInTheCircle(TmpCenter,OffsetValue,Pos1,true) || IsPointInTheCircle(TmpCenter,OffsetValue,Pos2,true) )
return true;
Nature Biotechnology: doi:10.1038/nbt.3413
TmpCenter[0]=Length;
TmpCenter[1]=0.0;
if( IsPointInTheCircle(TmpCenter,OffsetValue,Pos1,false) || IsPointInTheCircle(TmpCenter,OffsetValue,Pos2,false) )
return true;
return false;
}
BOOL CClosedLoop::IsPointInTheRect(double HalfHeight, double Length, double Point[])
{
if( (Point[1]<HalfHeight && Point[1]>(HalfHeight*(-1.0)))
&& (Point[0]>=0.0 && Point[0]<=Length) )
return true;
else
return false;
}
BOOL CClosedLoop::IsPointInTheCircle(double Center[], double Radius, double Point[], BOOL IsLeftCheck)
{
if( ((Point[0]-Center[0])*(Point[0]-Center[0])+(Point[1]-Center[1])*(Point[1]-Center[1])) < Radius*Radius )
return true;
else
return false;
}
BOOL CClosedLoop::IsOffsetLineEffectiveAreaTest1(CTwoDLine TmpOffsetLine, double OffsetValue)
{
// 두점중 한점이 내부에 있는지 확인 - 내부에 한점이 있으면 true 반환
double CCWAngle, Center[2], Length;
int i;
CCWAngle=TmpOffsetLine.GetLineCCWAngle();
TmpOffsetLine.GetVertex1(Center);
Length=TmpOffsetLine.GetLength();
OffsetValue-=1.0/NumErrorFindDouble; //0.00001; //임시
for(i=0;i<Line.size();i++)
{
if( IsPointsOfLineInTheEffectiveArea(CCWAngle,Center,Length,Line.at(i),OffsetValue,TmpOffsetLine.GetIsInsertedL
ine()) )
return true;
}
return false;
}
Nature Biotechnology: doi:10.1038/nbt.3413
BOOL CClosedLoop::OffsetLineContinuousTest()
{
// 연속성 테스트 및 끊어져 있을 때는 연결도 시켜줌.
if(OffsetLine.size()==0) return true;
double Vertex1_2[2],Vertex2_1[2],NorVec1[2],NorVec2[2],TmpNorVec[2];
int i,j;
CTwoDLine TmpLine;
BOOL IsOffsetLineContinuousPerfect=true;
for(i=0;i<OffsetLine.size();i++)
{
if( i+1 == OffsetLine.size() )
j=0;
else
j=i+1;
OffsetLine.at(i).GetVertex2(Vertex1_2);
OffsetLine.at(j).GetVertex1(Vertex2_1);
if( (int)(Vertex1_2[0]*NumErrorFindDouble)!=(int)(Vertex2_1[0]*NumErrorFindDouble)
|| (int)(Vertex1_2[1]*NumErrorFindDouble)!=(int)(Vertex2_1[1]*NumErrorFindDouble) )
{
OffsetLine.at(i).GetNorVec(NorVec1);
OffsetLine.at(j).GetNorVec(NorVec2);
TmpNorVec[0]=(NorVec1[0]+NorVec2[0])/2.0;
TmpNorVec[1]=(NorVec1[1]+NorVec2[1])/2.0;
TmpLine.InsertOneLine(Vertex1_2,Vertex2_1,TmpNorVec);
if(j==0)
{
OffsetLine.push_back(TmpLine);
i++;
}
else
{
OffsetLine.insert(&OffsetLine.at(j),TmpLine);
i++;
}
IsOffsetLineContinuousPerfect*=false;
}
else
IsOffsetLineContinuousPerfect*=true;
}
return IsOffsetLineContinuousPerfect;
Nature Biotechnology: doi:10.1038/nbt.3413
}
BOOL CClosedLoop::IsInnerOffset()
{
/*
//길이를 이용한 offset
double LengthOfLine,LengthOfOffsetLine;
int i;
LengthOfLine=0.0;
LengthOfOffsetLine=0.0;
for(i=0;i<Line.size();i++)
LengthOfLine+=Line.at(i).GetLength();
for(i=0;i<OffsetLine.size();i++)
LengthOfOffsetLine+=OffsetLine.at(i).GetLength();
if(LengthOfLine>LengthOfOffsetLine)
return true;
else
return false;
*/
return false; // 임시
}
void CClosedLoop::RemovePointOffsetLine()
{
for(int i=0;i<OffsetLine.size();i++)
{
if(OffsetLine.at(i).GetLength()<0.000001)
{
OffsetLine.erase(&OffsetLine.at(i));
--i;
}
}
}
void CClosedLoop::OffsetLineEAreaTWithOtherClosedLoop(CClosedLoop TmpClosedLoop, double OffsetValue)
{
int i;
// 두개의 다른 TmpClosdedLoop간에 Offset 선들을 비교 후 교차되는 선을 분해해 주는 역할
OffsetLineCompareAndDivide(TmpClosedLoop);
for(i=0;i<OffsetLine.size();i++)
{
if( TmpClosedLoop.IsOffsetLineEffectiveAreaTest1(OffsetLine.at(i),OffsetValue) )
{
Nature Biotechnology: doi:10.1038/nbt.3413
OffsetLine.erase(&OffsetLine.at(i));
--i;
}
}
}
void CClosedLoop::OffsetLineCompareAndDivide(CClosedLoop TmpClosedLoop)
{
// 두개의 다른 TmpClosdedLoop간에 Offset 선들을 비교 후 교차되는 선을 분해해 주는 역할
int i,j,NumOfOffLineinTmpLoop;
CTwoDLine TmpLine;
double TmpCrossPos[2];
NumOfOffLineinTmpLoop=TmpClosedLoop.GetNumOfOffsetLine();
for(i=0;i<OffsetLine.size();i++)
{
for(j=0;j<NumOfOffLineinTmpLoop;j++)
{
if( LeastJoinCondition(OffsetLine.at(i),TmpClosedLoop.GetOffsetLine(j)) )
{
if( CalCrossOfTwoLines(OffsetLine.at(i),TmpClosedLoop.GetOffsetLine(j),TmpCrossPos) )
{
if( OffsetLine.at(i).IsOnePointInnerBox(TmpCrossPos) &&
TmpClosedLoop.GetOffsetLine(j).IsOnePointInnerBoxIncludeBoard(TmpCrossPos) )
{
TmpLine=OffsetLine.at(i);
OffsetLine.at(i).SetVertex2(TmpCrossPos);
TmpLine.SetVertex1(TmpCrossPos);
if( i+1 == OffsetLine.size() )
OffsetLine.push_back(TmpLine);
else
OffsetLine.insert(&OffsetLine.at(i+1),TmpLine);
}
}
}
}
}
}
void CClosedLoop::GenerationContourBeamLine(double MinMoveDis)
{
int i,j,NumOfLine;
double TmpLength,Pos1[2],Pos2[2],AveNorVec[2];
Nature Biotechnology: doi:10.1038/nbt.3413
CTwoDLine TmpLine;
NumOfLine=Line.size();
TmpLength=0.0;
for(i=0;i<NumOfLine;i++)
{
Line.at(i).GetVertex1(Pos1);
for(j=i;j<NumOfLine;j++)
{
Line.at(j).GetVertex2(Pos2);
TmpLength=CalTwoPointLength(Pos1,Pos2);
if( !LineLinkageTest(i,j) )
{
Line.at(j-1).GetVertex2(Pos2);
CalAveNorVecOfLine(i,j-1,AveNorVec);
TmpLine.InsertOneLine(Pos1,Pos2,AveNorVec);
ContourBeamLine.push_back(TmpLine);
i=j-1;
break;
}
if( j+1==NumOfLine )
{
CalAveNorVecOfLine(i,j,AveNorVec);
TmpLine.InsertOneLine(Pos1,Pos2,AveNorVec);
ContourBeamLine.push_back(TmpLine);
return;
}
if( TmpLength>=MinMoveDis && LineLinkageTest(i,j) )
{
CalAveNorVecOfLine(i,j,AveNorVec);
TmpLine.InsertOneLine(Pos1,Pos2,AveNorVec);
ContourBeamLine.push_back(TmpLine);
i=j;
break;
}
}
}
}
double CClosedLoop::CalTwoPointLength(double Pos1[], double Pos2[])
{
return sqrt( (Pos1[0]-Pos2[0])*(Pos1[0]-Pos2[0])+(Pos1[1]-Pos2[1])*(Pos1[1]-Pos2[1]) );
}
BOOL CClosedLoop::LineLinkageTest(int StartNum, int EndNum)
Nature Biotechnology: doi:10.1038/nbt.3413
{
if( EndNum>=Line.size() || StartNum>EndNum )
return false;
if(StartNum==EndNum)
return true;
int i,j,TestIntVer1[2],TestIntVer2[2];
double Pos1_2[2],Pos2_1[2];
for(i=StartNum;i<EndNum;i++)
{
Line.at(i).GetVertex2(Pos1_2);
Line.at(i+1).GetVertex1(Pos2_1);
for(j=0;j<2;j++)
{
TestIntVer1[j]=(int)(Pos1_2[j]*NumErrorFindDouble);
TestIntVer2[j]=(int)(Pos2_1[j]*NumErrorFindDouble);
}
if( TestIntVer1[0]!=TestIntVer2[0] || TestIntVer1[1]!=TestIntVer2[1] )
return false;
}
return true;
}
void CClosedLoop::GenerationContourOffsetBeamLine(double MinMoveDis)
{
int i,j,NumOfOffsetLine;
double Pos1[2],Pos2[2],TmpLength,AveNorVec[2];
CTwoDLine TmpOffsetLine;
NumOfOffsetLine=OffsetLine.size();
TmpLength=0.0;
for(i=0;i<NumOfOffsetLine;i++)
{
OffsetLine.at(i).GetVertex1(Pos1);
for(j=i;j<NumOfOffsetLine;j++)
{
OffsetLine.at(j).GetVertex2(Pos2);
TmpLength=CalTwoPointLength(Pos1,Pos2);
if( !OffsetLineLinkageTest(i,j) )
{
Nature Biotechnology: doi:10.1038/nbt.3413
OffsetLine.at(j-1).GetVertex2(Pos2);
CalAveNorVecOfOffsetLine(i,j-1,AveNorVec);
TmpOffsetLine.InsertOneLine(Pos1,Pos2,AveNorVec);
ContourOffsetBeamLine.push_back(TmpOffsetLine);
i=j-1;
break;
}
if( j+1==NumOfOffsetLine )
{
CalAveNorVecOfOffsetLine(i,j,AveNorVec);
TmpOffsetLine.InsertOneLine(Pos1,Pos2,AveNorVec);
ContourOffsetBeamLine.push_back(TmpOffsetLine);
return;
}
if( TmpLength>=MinMoveDis && OffsetLineLinkageTest(i,j) )
{
CalAveNorVecOfOffsetLine(i,j,AveNorVec);
TmpOffsetLine.InsertOneLine(Pos1,Pos2,AveNorVec);
ContourOffsetBeamLine.push_back(TmpOffsetLine);
i=j;
break;
}
}
}
}
BOOL CClosedLoop::OffsetLineLinkageTest(int StartNum, int EndNum)
{
if( EndNum>=OffsetLine.size() || StartNum>EndNum )
return false;
if( StartNum==EndNum)
return true;
int i,j,TestIntVer1[2],TestIntVer2[2];
double Pos1_2[2],Pos2_1[2];
for(i=StartNum;i<EndNum;i++)
{
OffsetLine.at(i).GetVertex2(Pos1_2);
OffsetLine.at(i+1).GetVertex1(Pos2_1);
for(j=0;j<2;j++)
{
TestIntVer1[j]=(int)(Pos1_2[j]*NumErrorFindDouble);
Nature Biotechnology: doi:10.1038/nbt.3413
TestIntVer2[j]=(int)(Pos2_1[j]*NumErrorFindDouble);
}
if( TestIntVer1[0]!=TestIntVer2[0] || TestIntVer1[1]!=TestIntVer2[1] )
return false;
}
return true;
}
void CClosedLoop::GenerationCrossBeamLine(double MaxMoveDis)
{
int i;
CTwoDLine TmpCrossBeamLine;
for(i=0;i<ContourBeamLine.size();i++)
{
if( VectorGunCalTargetOffsetBeamLine(MaxMoveDis, ContourBeamLine.at(i), TmpCrossBeamLine) )
CrossBeamLine.push_back(TmpCrossBeamLine);
}
}
BOOL CClosedLoop::VectorGunCalTargetOffsetBeamLine(double MaxMoveDis, CTwoDLine GunLine, CTwoDLine
&ReturnCrossBeamLine)
{
if( ContourBeamLine.size()==0 || ContourOffsetBeamLine.size()==0 )
return false;
double Pos1[2],Pos2[2],GunLineNorVecCCWAngle,LineCenter[2],RotCenter[2],JoinXPosition,GunLineNorVec[2];
double TmpCrossBeamLineVertex2[2],TmpLength;
std::vector<CTwoDLine> TmpCrossBeamLineList;
int i,j;
CTwoDLine TargetLine,TmpCrossBeamLine;
RotCenter[0]=0.0;
RotCenter[1]=0.0;
TmpCrossBeamLineVertex2[0]=0.0;
TmpLength=1000000.0;
TmpCrossBeamLine.SetVertex1(RotCenter);
GunLine.GetTwoPosition(Pos1,Pos2);
GunLineNorVecCCWAngle=GunLine.GetNorVecCCWAngle();
LineCenter[0]=(Pos1[0]+Pos2[0])/(-2.0);
LineCenter[1]=(Pos1[1]+Pos2[1])/(-2.0);
for(i=0;i<ContourOffsetBeamLine.size();i++)
{
Nature Biotechnology: doi:10.1038/nbt.3413
TargetLine=ContourOffsetBeamLine.at(i);
TargetLine.LineTranslation(LineCenter);
TargetLine.LineCWRotation(RotCenter,GunLineNorVecCCWAngle);
if( TargetLine.GetXAxisJoinPositionWithLine(JoinXPosition) )
{
if( JoinXPosition > 0.0 && JoinXPosition<=MaxMoveDis )
{
LineCenter[0]*=-1.0;
LineCenter[1]*=-1.0;
GunLine.GetNorVec(GunLineNorVec);
TmpCrossBeamLineVertex2[0]=LineCenter[0]+JoinXPosition*GunLineNorVec[0];
TmpCrossBeamLineVertex2[1]=LineCenter[1]+JoinXPosition*GunLineNorVec[1];
TmpCrossBeamLine.SetVertex1(LineCenter);
TmpCrossBeamLine.SetVertex2(TmpCrossBeamLineVertex2);
TmpCrossBeamLineList.push_back(TmpCrossBeamLine);
LineCenter[0]*=-1.0;
LineCenter[1]*=-1.0;
}
}
}
if( TmpCrossBeamLineList.size() >1 )
i=0;
if(TmpCrossBeamLineList.size() >0 )
{
for(i=0;i<TmpCrossBeamLineList.size();i++)
{
if(TmpLength>TmpCrossBeamLineList.at(i).GetLength())
{
j=i;
TmpLength=TmpCrossBeamLineList.at(i).GetLength();
}
}
ReturnCrossBeamLine=TmpCrossBeamLineList.at(j);
TmpCrossBeamLineList.clear();
return true;
}
else
return false;
}
Nature Biotechnology: doi:10.1038/nbt.3413
int CClosedLoop::GetNumOfContourBeamLine()
{
return ContourBeamLine.size();
}
CTwoDLine CClosedLoop::GetContourBeamLine(int Num)
{
return ContourBeamLine.at(Num);
}
int CClosedLoop::GetNumOfContourOffsetBeamLine()
{
return ContourOffsetBeamLine.size();
}
CTwoDLine CClosedLoop::GetContourOffsetBeamLine(int Num)
{
return ContourOffsetBeamLine.at(Num);
}
int CClosedLoop::GetNumOfCrossBeamLine()
{
return CrossBeamLine.size();
}
CTwoDLine CClosedLoop::GetCrossBeamLine(int Num)
{
return CrossBeamLine.at(Num);
}
void CClosedLoop::CalAveNorVecOfLine(int StartNum, int EndNum, double AveNorVec[])
{
if( StartNum>EndNum || EndNum>=Line.size() )
return;
int i;
double TmpNorVec[2],SumNorVec[2];
SumNorVec[0]=0.0;
SumNorVec[1]=0.0;
for(i=StartNum;i<=EndNum;i++)
{
Line.at(i).GetNorVec(TmpNorVec);
SumNorVec[0]+=TmpNorVec[0];
SumNorVec[1]+=TmpNorVec[1];
}
Nature Biotechnology: doi:10.1038/nbt.3413
AveNorVec[0]=SumNorVec[0]/(double)(EndNum-StartNum+1);
AveNorVec[1]=SumNorVec[1]/(double)(EndNum-StartNum+1);
}
void CClosedLoop::LineDivideInMaxLength(double MaxLength)
{
std::vector<CTwoDLine> TmpLine;
CTwoDLine TmpOneLine;
double Length,TmpPos1[2],TmpPos2[2],TmpNewPos1[2],TmpNewPos2[2];
int i,j,NumOfDividedLine;
for(i=0;i<Line.size();i++)
TmpLine.push_back(Line.at(i));
Line.clear();
for(i=0;i<TmpLine.size();i++)
{
Length=TmpLine.at(i).GetLength();
if( Length>MaxLength )
{
NumOfDividedLine=(int)(Length/MaxLength+1.0);
TmpOneLine=TmpLine.at(i);
TmpOneLine.GetTwoPosition(TmpPos1,TmpPos2);
TmpNewPos1[0]=TmpPos1[0];
TmpNewPos1[1]=TmpPos1[1];
for(j=NumOfDividedLine;j>1;j--)
{
TmpNewPos2[0]=( TmpPos2[0]-TmpPos1[0] ) / (double)j + TmpPos1[0];
TmpNewPos2[1]=( TmpPos2[1]-TmpPos1[1] ) / (double)j + TmpPos1[1];
TmpOneLine.SetVertex1(TmpNewPos1);
TmpOneLine.SetVertex2(TmpNewPos2);
Line.push_back(TmpOneLine);
TmpNewPos1[0]=TmpNewPos2[0];
TmpNewPos1[1]=TmpNewPos2[1];
}
TmpOneLine.SetVertex1(TmpNewPos1);
TmpOneLine.SetVertex2(TmpPos2);
Line.push_back(TmpOneLine);
}
else
Line.push_back(TmpLine.at(i));
}
TmpLine.clear();
}
Nature Biotechnology: doi:10.1038/nbt.3413
void CClosedLoop::OffsetLineOverLapTestAndDevide()
{
// offset 선들끼리 만나는 점을 찾아서 선을 분할 해주는 부분
int i,j;
double TmpCrossPos[2];
CTwoDLine TmpLine;
CTwoDLine TmpLine2; //added on 03252015
double tmpver1_1[2],tmpver1_2[2],tmpver2_1[2],tmpver2_2[2];
for(i=0;i<OffsetLine.size();i++)
{
for(j=0;j<OffsetLine.size();j++)
{
if( i!=j && LeastJoinCondition(OffsetLine.at(i),OffsetLine.at(j)) )
{
if( !CalCrossOfTwoLines(OffsetLine.at(i),OffsetLine.at(j),TmpCrossPos) )
break;
if( OffsetLine.at(i).IsOnePointInnerBox(TmpCrossPos) &&
OffsetLine.at(j).IsOnePointInnerBoxIncludeBoard(TmpCrossPos) )
{
OffsetLine.at(i).GetVertex1(tmpver1_1);
OffsetLine.at(i).GetVertex2(tmpver1_2);
OffsetLine.at(j).GetVertex1(tmpver2_1);
OffsetLine.at(j).GetVertex2(tmpver2_2);
TmpLine=OffsetLine.at(i);
OffsetLine.at(i).SetVertex2(TmpCrossPos);
TmpLine.SetVertex1(TmpCrossPos);
TmpLine2=OffsetLine.at(j); //added on 03252015
OffsetLine.at(j).SetVertex1(TmpCrossPos); //added on 03252015
TmpLine.SetVertex2(TmpCrossPos); //added on 03252015
if(i+1 == OffsetLine.size() )
OffsetLine.push_back(TmpLine);
else
OffsetLine.insert(&OffsetLine.at(i+1),TmpLine);
OffsetLine.insert(&OffsetLine.at(j),TmpLine2); //added on 03252015
if(i+1<=j)
j++;
}
}
}
Nature Biotechnology: doi:10.1038/nbt.3413
}
}
void CClosedLoop::DeleteOverlapOffsetLines()
{
//Offset선의 내부에 있는 선들을 지워주는 역할
int i,j;
double NorVec1[2],NorVec2[2],Pos1_1[2],Pos2_1[2],Pos2_2[2],LineCCWAngle,Length,TmpCenter[2],MinX,MaxX;
double TmpVertex1[2],TmpVertex2[2];
CTwoDLine TmpLine,TmpLine2;
BOOL IsPlusDir;
TmpCenter[0]=0.0;
TmpCenter[1]=0.0;
for(i=0;i<OffsetLine.size();i++)
{
for(j=i+1;j<OffsetLine.size();j++)
{
OffsetLine.at(i).GetNorVec(NorVec1);
OffsetLine.at(j).GetNorVec(NorVec2);
if( (int)(NorVec1[0]*NumErrorFindDouble)==(int)(NorVec2[0]*NumErrorFindDouble)
&&
(int)(NorVec1[1]*NumErrorFindDouble)==(int)(NorVec2[1]*NumErrorFindDouble) )
{
TmpLine=OffsetLine.at(j);
LineCCWAngle=OffsetLine.at(i).GetLineCCWAngle();
Length=OffsetLine.at(i).GetLength();
OffsetLine.at(i).GetVertex1(Pos1_1);
Pos1_1[0]*=-1.0;
Pos1_1[1]*=-1.0;
TmpLine.LineTranslation(Pos1_1);
TmpLine.LineCWRotation(TmpCenter,LineCCWAngle);
Pos1_1[0]*=-1.0;
Pos1_1[1]*=-1.0;
LineCCWAngle*=-1.0;
TmpLine.GetTwoPosition(Pos2_1,Pos2_2);
if( (int)(Pos2_1[1]*NumErrorFindDouble)==0 )
{
if( Pos2_1[0]<Pos2_2[0] )
{
MinX=Pos2_1[0];
Nature Biotechnology: doi:10.1038/nbt.3413
MaxX=Pos2_2[0];
IsPlusDir=true;
}
else
{
MinX=Pos2_2[0];
MaxX=Pos2_1[0];
IsPlusDir=false;
}
if( MinX>=0.0 && MaxX<=Length )
{
OffsetLine.erase(&OffsetLine.at(j));
--j;
}
else if( MinX<0.0 && MaxX>0.0 && MaxX<=Length )
{
if(IsPlusDir)
Pos2_2[0]=0.0;
else
Pos2_1[0]=0.0;
Pos2_1[1]=0.0; Pos2_2[1]=0.0;
TmpLine.SetVertex1(Pos2_1);
TmpLine.SetVertex2(Pos2_2);
TmpLine.LineCWRotation(TmpCenter,LineCCWAngle);
TmpLine.LineTranslation(Pos1_1);
OffsetLine.at(j)=TmpLine;
}
else if( MaxX>Length && MinX<Length && MinX>=0.0 )
{
if(IsPlusDir)
Pos2_1[0]=Length;
else
Pos2_2[0]=Length;
Pos2_1[1]=0.0; Pos2_2[1]=0.0;
TmpLine.SetVertex1(Pos2_1);
TmpLine.SetVertex2(Pos2_2);
TmpLine.LineCWRotation(TmpCenter,LineCCWAngle);
TmpLine.LineTranslation(Pos1_1);
OffsetLine.at(j)=TmpLine;
}
else if( MinX<0.0 && MaxX>Length)
{
if(IsPlusDir)
{
Nature Biotechnology: doi:10.1038/nbt.3413
TmpVertex2[0]=0.0;
TmpVertex2[1]=0.0;
TmpVertex1[0]=Length;
TmpVertex1[1]=0.0;
}
else
{
TmpVertex2[0]=Length;
TmpVertex2[1]=0.0;
TmpVertex1[0]=0.0;
TmpVertex1[1]=0.0;
}
TmpLine2=TmpLine;
TmpLine.SetVertex2(TmpVertex2);
TmpLine2.SetVertex1(TmpVertex1);
TmpLine.LineCWRotation(TmpCenter,LineCCWAngle);
TmpLine.LineTranslation(Pos1_1);
TmpLine2.LineCWRotation(TmpCenter,LineCCWAngle);
TmpLine2.LineTranslation(Pos1_1);
OffsetLine.at(j)=TmpLine;
OffsetLine.insert(&OffsetLine.at(j+1),TmpLine2);
j++;
}
}
}
}
}
}
void CClosedLoop::InitializationWithoutLine()
{
OffsetLine.clear();
CrossBeamLine.clear();
ContourOffsetBeamLine.clear();
ContourBeamLine.clear();
}
void CClosedLoop::SetIsMaxOffsetLoop(BOOL IsMax)
{
IsMaxOffsetLoop=IsMax;
}
BOOL CClosedLoop::IsMaxOffLoop()
Nature Biotechnology: doi:10.1038/nbt.3413
{
return IsMaxOffsetLoop;
}
void CClosedLoop::ClosedLoopCWRotation(double Center[], double CWAngle)
{
int i;
for(i=0;i<Line.size();i++)
Line.at(i).LineCWRotation(Center,CWAngle);
for(i=0;i<OffsetLine.size();i++)
OffsetLine.at(i).LineCWRotation(Center,CWAngle);
for(i=0;i<ContourBeamLine.size();i++)
ContourBeamLine.at(i).LineCWRotation(Center,CWAngle);
for(i=0;i<ContourOffsetBeamLine.size();i++)
ContourOffsetBeamLine.at(i).LineCWRotation(Center,CWAngle);
for(i=0;i<CrossBeamLine.size();i++)
CrossBeamLine.at(i).LineCWRotation(Center,CWAngle);
for(i=0;i<OneScanBeamLine.size();i++)
OneScanBeamLine.at(i).LineCWRotation(Center,CWAngle);
}
double CClosedLoop::ReturnMinYValInBeamLines()
{
double ReturnYVal=NumErrorFindDouble;
int i;
for(i=0;i<ContourBeamLine.size();i++)
{
if(ReturnYVal>ContourBeamLine.at(i).ReturnMinYVal())
ReturnYVal=ContourBeamLine.at(i).ReturnMinYVal();
}
for(i=0;i<ContourOffsetBeamLine.size();i++)
{
if(ReturnYVal>ContourOffsetBeamLine.at(i).ReturnMinYVal())
ReturnYVal=ContourOffsetBeamLine.at(i).ReturnMinYVal();
}
return ReturnYVal;
}
double CClosedLoop::ReturnMaxYValInBeamLines()
Nature Biotechnology: doi:10.1038/nbt.3413
{
double ReturnYVal=NumErrorFindDouble*(-1.0);
int i;
for(i=0;i<ContourBeamLine.size();i++)
{
if(ReturnYVal<ContourBeamLine.at(i).ReturnMaxYVal())
ReturnYVal=ContourBeamLine.at(i).ReturnMaxYVal();
}
for(i=0;i<ContourOffsetBeamLine.size();i++)
{
if(ReturnYVal<ContourOffsetBeamLine.at(i).ReturnMaxYVal())
ReturnYVal=ContourOffsetBeamLine.at(i).ReturnMaxYVal();
}
return ReturnYVal;
}
void CClosedLoop::InitializationCrossBeamLine()
{
CrossBeamLine.clear();
}
void CClosedLoop::InsertCrossBeamLine(CTwoDLine TmpLine)
{
CrossBeamLine.push_back(TmpLine);
}
void CClosedLoop::GetCenterOfClosedLoop(double Center[])
{
int i;
double SumOfX,SumOfY,TmpLineCenter[2];
SumOfX=0.0;
SumOfY=0.0;
for(i=0;i<Line.size();i++)
{
Line.at(i).GetCenterOfLine(TmpLineCenter);
SumOfX+=TmpLineCenter[0];
SumOfY+=TmpLineCenter[1];
}
Center[0]=SumOfX/(double)Line.size();
Center[1]=SumOfY/(double)Line.size();
}
Nature Biotechnology: doi:10.1038/nbt.3413
void CClosedLoop::RemovePointBeamLine()
{
RemovePointContourBeamLine();
RemovePointContourOffsetBeamLine();
RemovePointCrossBeamLine();
}
void CClosedLoop::RemovePointContourBeamLine()
{
for(int i=0;i<ContourBeamLine.size();i++)
{
if(ContourBeamLine.at(i).IsPointBeamLine())
{
ContourBeamLine.erase(&ContourBeamLine.at(i));
--i;
}
}
}
void CClosedLoop::RemovePointContourOffsetBeamLine()
{
for(int i=0;i<ContourOffsetBeamLine.size();i++)
{
if(ContourOffsetBeamLine.at(i).IsPointBeamLine())
{
ContourOffsetBeamLine.erase(&ContourOffsetBeamLine.at(i));
--i;
}
}
}
void CClosedLoop::RemovePointCrossBeamLine()
{
for(int i=0;i<CrossBeamLine.size();i++)
{
if(CrossBeamLine.at(i).IsPointBeamLine())
{
CrossBeamLine.erase(&CrossBeamLine.at(i));
--i;
}
}
}
void CClosedLoop::ConnectingOffsetLines(double OffsetValue)
{
/* // offset 선들을 연장 시켜 주는 부분 3 - 하나의 선으로 표현
int i,j;
double Vertex1_2[2],Vertex2_1[2],Nor1[2],Nor2[2],CenterNor[2];
CTwoDLine TmpNewLine;
Nature Biotechnology: doi:10.1038/nbt.3413
for(i=0;i<OffsetLine.size();i++)
{
if( (i+1)==OffsetLine.size() )
j=0;
else
j=i+1;
OffsetLine.at(i).GetVertex2(Vertex1_2);
OffsetLine.at(j).GetVertex1(Vertex2_1);
// if( (int)(Vertex1_2[0]*NumErrorFindDouble)!=(int)(Vertex2_1[0]*NumErrorFindDouble)
// || (int)(Vertex1_2[1]*NumErrorFindDouble)!=(int)(Vertex2_1[1]*NumErrorFindDouble) )
if( Vertex1_2[0]!=Vertex2_1[0] || Vertex1_2[1]!=Vertex2_1[1] )
{
OffsetLine.at(i).GetNorVec(Nor1);
OffsetLine.at(j).GetNorVec(Nor2);
CenterNor[0]=(Nor1[0]+Nor2[0])/2.0;
CenterNor[1]=(Nor1[1]+Nor2[1])/2.0;
TmpNewLine.InsertOneLine(Vertex1_2,Vertex2_1,CenterNor);
TmpNewLine.SetIsInsertedLine();
if(j==0)
OffsetLine.push_back(TmpNewLine);
else
OffsetLine.insert(&OffsetLine.at(j),TmpNewLine);
i++;
}
}
*/
// offset 선들을 연장 시켜 주는 부분 2 - 두개의 선으로 표현
int i,j;
double Vertex1_2[2],Vertex2_1[2],Nor1[2],Nor2[2],NewNor1[2],NewNor2[2],CenterNor[2],CenterVertex[2];
CTwoDLine TmpNewLine1,TmpNewLine2,TmpOffsetLine;
for(i=0;i<OffsetLine.size();i++)
{
if( (i+1)==OffsetLine.size() )
j=0;
else
j=i+1;
OffsetLine.at(i).GetVertex2(Vertex1_2);
OffsetLine.at(j).GetVertex1(Vertex2_1);
Nature Biotechnology: doi:10.1038/nbt.3413
// if( (int)(Vertex1_2[0]*NumErrorFindDouble)!=(int)(Vertex2_1[0]*NumErrorFindDouble)
// || (int)(Vertex1_2[1]*NumErrorFindDouble)!=(int)(Vertex2_1[1]*NumErrorFindDouble) )
if( Vertex1_2[0]!=Vertex2_1[0] || Vertex1_2[1]!=Vertex2_1[1] )
{
OffsetLine.at(i).GetNorVec(Nor1);
OffsetLine.at(j).GetNorVec(Nor2);
CenterNor[0]=(Nor1[0]+Nor2[0])/2.0;
CenterNor[1]=(Nor1[1]+Nor2[1])/2.0;
TmpOffsetLine=OffsetLine.at(i);
TmpOffsetLine.DoOffsetLineUsingNorVec(OffsetValue*(-1.0));
TmpOffsetLine.InsertNorVec(CenterNor);
TmpOffsetLine.DoOffsetLineUsingNorVec(OffsetValue);
TmpOffsetLine.GetVertex2(CenterVertex);
NewNor1[0]=(Nor1[0]+CenterNor[0])/2.0;
NewNor1[1]=(Nor1[1]+CenterNor[1])/2.0;
NewNor2[0]=(Nor2[0]+CenterNor[0])/2.0;
NewNor2[1]=(Nor2[1]+CenterNor[1])/2.0;
TmpNewLine1.InsertOneLine(Vertex1_2,CenterVertex,NewNor1);
TmpNewLine1.SetIsInsertedLine();
TmpNewLine2.InsertOneLine(CenterVertex,Vertex2_1,NewNor2);
TmpNewLine2.SetIsInsertedLine();
if(j==0)
{
OffsetLine.push_back(TmpNewLine1);
OffsetLine.push_back(TmpNewLine2);
}
else
{
OffsetLine.insert(&OffsetLine.at(j),TmpNewLine2);
OffsetLine.insert(&OffsetLine.at(j),TmpNewLine1);
}
i+=2;
}
}
/*
// offset 선들을 연장 시켜 주는 부분 1 : 두 선의 연장선의 교점을 구한후 이를 연장
int i,j;
double TmpCrossPos[2];
for(i=0;i<OffsetLine.size();i++)
{
if( (i+1)==OffsetLine.size() )
Nature Biotechnology: doi:10.1038/nbt.3413
j=0;
else
j=i+1;
if(!CalCrossOfTwoLines(OffsetLine.at(i),OffsetLine.at(j),TmpCrossPos))
{
// AfxMessageBox("Line Crosspoint Caculation Error");
return;
}
OffsetLine.at(i).SetVertex2(TmpCrossPos);
OffsetLine.at(j).SetVertex1(TmpCrossPos);
}
*/
}
BOOL CClosedLoop::CheckConnectingWithOffsetLines(double CLoopSEPosition[], double CLoopSENorVec[], CTwoDLine
&MinDistConnectingLine, int &SEXOffsetValNum)
{
// 주어진 CLoopSEPosition과 가장 가까운 점을 찾고 이를 선으로 만들어서 반환하라.
// 그리고 연결되어 있으면 true 반환 연결되어 있지 않으면 false 및 선을 반환.
int i;
double SEPosition[2],MinDis,TmpDis,TmpNor[2],OffsetNor[2];
CTwoDLine TmpLine;
MinDis=10000000.0;
if(SEXOffsetVal.size()==0)
return true;
for(i=0;i<SEXOffsetVal.size();i++)
{
SEPosition[0]=SEXOffsetVal.at(i);
SEPosition[1]=SEYOffsetVal.at(i);
if(IsTwoPositionSame(SEPosition,CLoopSEPosition))
{
SEXOffsetValNum=i;
return true;
}
else
{
TmpDis=DistanceOfTwoPosition(SEPosition,CLoopSEPosition);
if( MinDis>TmpDis )
{
MinDis=TmpDis;
OffsetLine.at(SEOffsetNumber.at(i)).GetNorVec(OffsetNor);
TmpNor[0]=(OffsetNor[0]+CLoopSENorVec[0])/2.0;
TmpNor[1]=(OffsetNor[1]+CLoopSENorVec[1])/2.0;
Nature Biotechnology: doi:10.1038/nbt.3413
TmpLine.InsertOneLine(SEPosition,CLoopSEPosition,TmpNor);
SEXOffsetValNum=i;
}
}
}
MinDistConnectingLine=TmpLine;
return false;
}
double CClosedLoop::DistanceOfTwoPosition(double Pos1[], double Pos2[])
{
return sqrt( (Pos2[0]-Pos1[0])*(Pos2[0]-Pos1[0])+(Pos2[1]-Pos1[1])*(Pos2[1]-Pos1[1]) );
}
BOOL CClosedLoop::IsTwoPositionSame(double Point1[], double Point2[])
{
if( ((int)(Point1[0]*NumErrorFindDouble)==(int)(Point2[0]*NumErrorFindDouble))
&& ((int)(Point1[1]*NumErrorFindDouble)==(int)(Point2[1]*NumErrorFindDouble)) )
return true;
else
return false;
}
void CClosedLoop::FindSEXYOffsetVal()
{
// This ClosdeLoop의 시작점과 끝점을 찾아라
SEXOffsetVal.clear();
SEYOffsetVal.clear();
SEOffsetNumber.clear();
int BeforeIndex,AfterIndex,i,DisConnectingMode;
double TmpSEPos1[2],TmpSEPos2[2];
for(i=0;i<OffsetLine.size();i++)
{
if(i==0)
{
BeforeIndex=OffsetLine.size()-1;
AfterIndex=i+1;
}
else if(i==OffsetLine.size()-1)
{
BeforeIndex=i-1;
AfterIndex=0;
}
else
{
Nature Biotechnology: doi:10.1038/nbt.3413
BeforeIndex=i-1;
AfterIndex=i+1;
}
if( !OffsetLine.at(i).IsTheComparedLineConnected(OffsetLine.at(BeforeIndex),OffsetLine.at(AfterIndex),DisConnecti
ngMode) )
{
if(DisConnectingMode==1)
{
OffsetLine.at(i).GetVertex1(TmpSEPos1);
SEXOffsetVal.push_back(TmpSEPos1[0]);
SEYOffsetVal.push_back(TmpSEPos1[1]);
SEOffsetNumber.push_back(i);
SEOffsetMode.push_back(1);
}
else if(DisConnectingMode==2)
{
OffsetLine.at(i).GetVertex2(TmpSEPos2);
SEXOffsetVal.push_back(TmpSEPos2[0]);
SEYOffsetVal.push_back(TmpSEPos2[1]);
SEOffsetNumber.push_back(i);
SEOffsetMode.push_back(2);
}
else if(DisConnectingMode==3)
{
OffsetLine.at(i).GetVertex1(TmpSEPos1);
SEXOffsetVal.push_back(TmpSEPos1[0]);
SEYOffsetVal.push_back(TmpSEPos1[1]);
SEOffsetNumber.push_back(i);
SEOffsetMode.push_back(1);
OffsetLine.at(i).GetVertex2(TmpSEPos2);
SEXOffsetVal.push_back(TmpSEPos2[0]);
SEYOffsetVal.push_back(TmpSEPos2[1]);
SEOffsetNumber.push_back(i);
SEOffsetMode.push_back(2);
}
}
}
}
int CClosedLoop::GetNumOfSEOffsetVal()
{
return SEXOffsetVal.size();
}
BOOL CClosedLoop::GetSEOffsetValuesAndNorVec(int Index, double SEOffsetValues[], double SEOffValNorVec[], int
&SEOffsetNum, BOOL &SEOffMode)
Nature Biotechnology: doi:10.1038/nbt.3413
{
if( Index<0 || Index>GetNumOfSEOffsetVal()-1 )
return false;
SEOffsetValues[0]=SEXOffsetVal.at(Index);
SEOffsetValues[1]=SEYOffsetVal.at(Index);
OffsetLine.at( SEOffsetNumber.at(Index) ).GetNorVec(SEOffValNorVec);
SEOffMode=SEOffsetMode.at(Index);
SEOffsetNum=SEOffsetNumber.at(Index);
return true;
}
void CClosedLoop::InsertOffsetLine(int Index, CTwoDLine TmpOffsetLine)
{
if(Index<1)
OffsetLine.insert(&OffsetLine.at(0),TmpOffsetLine);
else if(Index>OffsetLine.size()-1)
OffsetLine.push_back(TmpOffsetLine);
else
OffsetLine.insert(&OffsetLine.at(Index),TmpOffsetLine);
}
void CClosedLoop::RemoveOverLapOffsetLine()
{
// 두 선이 같은 방향으로 Overlap 되면 하나면 지우고, 다른 방향(inverse)으로 OverLap 되면 둘다 지울것.
if(OffsetLine.size()==0)
return;
int i,j;
CTwoDLine TmpLine1,TmpLine2;
BOOL IsInverse;
for(i=0;i<OffsetLine.size()-1;i++)
{
TmpLine1=OffsetLine.at(i);
for(j=i+1;j<OffsetLine.size();j++)
{
TmpLine2=OffsetLine.at(j);
if( TmpLine1.IsTwoLineOverLap(TmpLine2,IsInverse) )
{
if(IsInverse)
{
OffsetLine.erase(&OffsetLine.at(j));
OffsetLine.erase(&OffsetLine.at(i));
TmpLine1=OffsetLine.at(i);
Nature Biotechnology: doi:10.1038/nbt.3413
}
else
{
OffsetLine.erase(&OffsetLine.at(j));
--j;
}
}
}
}
}
void CClosedLoop::MinErrorBoundOffset()
{
// DistanceOfTwoPosition
int i,j;
double Pos2_1[2],Pos1_2[2],ErrorBound;
ErrorBound=0.00010;
for(i=0;i<OffsetLine.size();i++)
{
if(i==OffsetLine.size()-1)
j=0;
else
j=i+1;
OffsetLine.at(i).GetVertex2(Pos1_2);
OffsetLine.at(j).GetVertex1(Pos2_1);
if( DistanceOfTwoPosition(Pos2_1,Pos1_2) <= ErrorBound )
{
OffsetLine.at(j).SetVertex1(Pos1_2);
}
}
}
void CClosedLoop::LineValueRefine()
{
int i,j;
double TmpVer1_2[2];
for(i=0;i<Line.size();i++)
{
if(i==Line.size()-1)
j=0;
else
j=i+1;
Nature Biotechnology: doi:10.1038/nbt.3413
Line.at(i).GetVertex2(TmpVer1_2);
Line.at(j).SetVertex1(TmpVer1_2);
}
}
void CClosedLoop::OffsetLineValueRefine()
{
int i,j;
double TmpVer1_2[2];
for(i=0;i<OffsetLine.size();i++)
{
if(i==OffsetLine.size()-1)
j=0;
else
j=i+1;
OffsetLine.at(i).GetVertex2(TmpVer1_2);
OffsetLine.at(j).SetVertex1(TmpVer1_2);
}
}
void CClosedLoop::DeleteOverlapOffsetLines(CClosedLoop TmpClosedLoop)
{
//Offset선의 내부에 있는 선들을 지워주는 역할
int i,j,NumOfOffsetLineOfTmpLoop;
double NorVec1[2],NorVec2[2],Pos1_1[2],Pos2_1[2],Pos2_2[2],LineCCWAngle,Length,TmpCenter[2],MinX,MaxX;
double TmpVertex1[2],TmpVertex2[2];
CTwoDLine TmpLine,TmpLine2,TmpOffsetLineOfTmpLoop;
BOOL IsPlusDir;
TmpCenter[0]=0.0;
TmpCenter[1]=0.0;
NumOfOffsetLineOfTmpLoop=TmpClosedLoop.GetNumOfOffsetLine();
for(i=0;i<NumOfOffsetLineOfTmpLoop;i++)
{
TmpOffsetLineOfTmpLoop=TmpClosedLoop.GetOffsetLine(i);
for(j=0;j<OffsetLine.size();j++)
{
TmpOffsetLineOfTmpLoop.GetNorVec(NorVec1);
OffsetLine.at(j).GetNorVec(NorVec2);
if( (int)(NorVec1[0]*NumErrorFindDouble)==(int)(NorVec2[0]*NumErrorFindDouble)
&&
Nature Biotechnology: doi:10.1038/nbt.3413
(int)(NorVec1[1]*NumErrorFindDouble)==(int)(NorVec2[1]*NumErrorFindDouble) )
{
TmpLine=OffsetLine.at(j);
LineCCWAngle=TmpOffsetLineOfTmpLoop.GetLineCCWAngle();
Length=TmpOffsetLineOfTmpLoop.GetLength();
TmpOffsetLineOfTmpLoop.GetVertex1(Pos1_1);
Pos1_1[0]*=-1.0;
Pos1_1[1]*=-1.0;
TmpLine.LineTranslation(Pos1_1);
TmpLine.LineCWRotation(TmpCenter,LineCCWAngle);
Pos1_1[0]*=-1.0;
Pos1_1[1]*=-1.0;
LineCCWAngle*=-1.0;
TmpLine.GetTwoPosition(Pos2_1,Pos2_2);
if( (int)(Pos2_1[1]*NumErrorFindDouble)==0 )
{
if( Pos2_1[0]<Pos2_2[0] )
{
MinX=Pos2_1[0];
MaxX=Pos2_2[0];
IsPlusDir=true;
}
else
{
MinX=Pos2_2[0];
MaxX=Pos2_1[0];
IsPlusDir=false;
}
if( MinX>=0.0 && MaxX<=Length )
{
OffsetLine.erase(&OffsetLine.at(j));
--j;
}
else if( MinX<0.0 && MaxX>0.0 && MaxX<=Length )
{
if(IsPlusDir)
Pos2_2[0]=0.0;
else
Pos2_1[0]=0.0;
Pos2_1[1]=0.0; Pos2_2[1]=0.0;
TmpLine.SetVertex1(Pos2_1);
TmpLine.SetVertex2(Pos2_2);
Nature Biotechnology: doi:10.1038/nbt.3413
TmpLine.LineCWRotation(TmpCenter,LineCCWAngle);
TmpLine.LineTranslation(Pos1_1);
OffsetLine.at(j)=TmpLine;
}
else if( MaxX>Length && MinX<Length && MinX>=0.0 )
{
if(IsPlusDir)
Pos2_1[0]=Length;
else
Pos2_2[0]=Length;
Pos2_1[1]=0.0; Pos2_2[1]=0.0;
TmpLine.SetVertex1(Pos2_1);
TmpLine.SetVertex2(Pos2_2);
TmpLine.LineCWRotation(TmpCenter,LineCCWAngle);
TmpLine.LineTranslation(Pos1_1);
OffsetLine.at(j)=TmpLine;
}
else if( MinX<0.0 && MaxX>Length)
{
if(IsPlusDir)
{
TmpVertex2[0]=0.0;
TmpVertex2[1]=0.0;
TmpVertex1[0]=Length;
TmpVertex1[1]=0.0;
}
else
{
TmpVertex2[0]=Length;
TmpVertex2[1]=0.0;
TmpVertex1[0]=0.0;
TmpVertex1[1]=0.0;
}
TmpLine2=TmpLine;
TmpLine.SetVertex2(TmpVertex2);
TmpLine2.SetVertex1(TmpVertex1);
TmpLine.LineCWRotation(TmpCenter,LineCCWAngle);
TmpLine.LineTranslation(Pos1_1);
TmpLine2.LineCWRotation(TmpCenter,LineCCWAngle);
TmpLine2.LineTranslation(Pos1_1);
Nature Biotechnology: doi:10.1038/nbt.3413
OffsetLine.at(j)=TmpLine;
OffsetLine.insert(&OffsetLine.at(j+1),TmpLine2);
j++;
}
}
}
}
}
}
void CClosedLoop::EraseSEXYOffsetVal(int Num)
{
SEXOffsetVal.erase(&SEXOffsetVal.at(Num));
SEYOffsetVal.erase(&SEYOffsetVal.at(Num));
SEOffsetNumber.erase(&SEOffsetNumber.at(Num));
SEOffsetMode.erase(&SEOffsetMode.at(Num));
}
void CClosedLoop::UsedSEOffsetNumForConnecting(int InsertedNum)
{
int i;
for(i=0;i<SEOffsetNumber.size();i++)
{
if( InsertedNum<=SEOffsetNumber.at(i) )
SEOffsetNumber.at(i)+=1;
}
}
void CClosedLoop::OffsetLineRefineAfterMerge()
{
int i,j;
double TmpVer1_2[2],TmpVer2_1[2];
for(i=0;i<OffsetLine.size();i++)
{
if(i==OffsetLine.size()-1)
j=0;
else
j=i+1;
OffsetLine.at(i).GetVertex2(TmpVer1_2);
OffsetLine.at(j).GetVertex1(TmpVer2_1);
if(DistanceOfTwoPosition(TmpVer1_2,TmpVer2_1)<0.0005)
OffsetLine.at(j).SetVertex1(TmpVer1_2);
}
Nature Biotechnology: doi:10.1038/nbt.3413
}
void CClosedLoop::SetContourBeamLine(int Num, CTwoDLine TmpLine)
{
ContourBeamLine.at(Num)=TmpLine;
}
void CClosedLoop::SetContourOffsetBeamLine(int Num, CTwoDLine TmpLine)
{
ContourOffsetBeamLine.at(Num)=TmpLine;
}
BOOL CClosedLoop::DivideLineOfContourBeamLine(int LineNum, double Point[])
{
CTwoDLine TmpLine;
if( LineNum<0 || LineNum>ContourBeamLine.size()-1 )
return false;
if( ContourBeamLine.at(LineNum).IsOnePointInnerBox(Point) )
{
TmpLine=ContourBeamLine.at(LineNum);
ContourBeamLine.at(LineNum).SetVertex2(Point);
TmpLine.SetVertex1(Point);
if(LineNum==ContourBeamLine.size()-1)
ContourBeamLine.push_back(TmpLine);
else
ContourBeamLine.insert(&ContourBeamLine.at(LineNum+1),TmpLine);
return true;
}
else
return false;
}
BOOL CClosedLoop::DivideLineOfContourOffsetBeamLine(int LineNum, double Point[])
{
CTwoDLine TmpLine;
if( LineNum<0 || LineNum>ContourOffsetBeamLine.size()-1 )
return false;
if( ContourOffsetBeamLine.at(LineNum).IsOnePointInnerBox(Point) )
{
TmpLine=ContourOffsetBeamLine.at(LineNum);
ContourOffsetBeamLine.at(LineNum).SetVertex2(Point);
TmpLine.SetVertex1(Point);
if(LineNum==ContourOffsetBeamLine.size()-1)
Nature Biotechnology: doi:10.1038/nbt.3413
ContourOffsetBeamLine.push_back(TmpLine);
else
ContourOffsetBeamLine.insert(&ContourOffsetBeamLine.at(LineNum+1),TmpLine);
return true;
}
else
return false;
}
void CClosedLoop::PushBackOneScanBeamLine(CTwoDLine TmpLine)
{
OneScanBeamLine.push_back(TmpLine);
}
CTwoDLine CClosedLoop::GetOneScanBeamLine(int Num)
{
return OneScanBeamLine.at(Num);
}
int CClosedLoop::GetNumOfOneScanBeamLine()
{
return OneScanBeamLine.size();
}
void CClosedLoop::InsertOneScanBeamLine(int Num, CTwoDLine TmpLine)
{
if(Num<1)
OneScanBeamLine.insert(&OneScanBeamLine.at(0),TmpLine);
else if(Num>OneScanBeamLine.size()-1)
OneScanBeamLine.push_back(TmpLine);
else
OneScanBeamLine.insert(&OneScanBeamLine.at(Num),TmpLine);
}
void CClosedLoop::OverWriteOffsetCBLToCBL()
{
int i;
ContourBeamLine.clear();
for(i=0;i<ContourOffsetBeamLine.size();i++)
ContourBeamLine.push_back(ContourOffsetBeamLine.at(i));
}
void CClosedLoop::InitializationWithoutLineOffsetBeamLine()
Nature Biotechnology: doi:10.1038/nbt.3413
{
OffsetLine.clear();
CrossBeamLine.clear();
ContourOffsetBeamLine.clear();
}
void CClosedLoop::CalAveNorVecOfOffsetLine(int StartNum, int EndNum, double AveNorVec[])
{
if( StartNum>EndNum || EndNum>=OffsetLine.size() )
return;
int i;
double TmpNorVec[2],SumNorVec[2];
SumNorVec[0]=0.0;
SumNorVec[1]=0.0;
for(i=StartNum;i<=EndNum;i++)
{
OffsetLine.at(i).GetNorVec(TmpNorVec);
SumNorVec[0]+=TmpNorVec[0];
SumNorVec[1]+=TmpNorVec[1];
}
AveNorVec[0]=SumNorVec[0]/(double)(EndNum-StartNum+1);
AveNorVec[1]=SumNorVec[1]/(double)(EndNum-StartNum+1);
}
void CClosedLoop::ArrangeContourBeamLine()
{
if(ContourBeamLine.size()==0)
return;
std::vector<CTwoDLine> TmpContourBeamLine;
int i,InverseStartNum;
CTwoDLine TmpLine1,TmpLine2;
for(i=0;i<ContourBeamLine.size();i++)
TmpContourBeamLine.push_back(ContourBeamLine.at(i));
ContourBeamLine.clear();
while(TmpContourBeamLine.size()!=0) {
TmpLine1=TmpContourBeamLine.at(0);
ContourBeamLine.push_back(TmpLine1);
TmpContourBeamLine.erase(&TmpContourBeamLine.at(0));
InverseStartNum=ContourBeamLine.size()-1;
for(i=0;i<TmpContourBeamLine.size();i++)
Nature Biotechnology: doi:10.1038/nbt.3413
{
TmpLine2=TmpContourBeamLine.at(i);
if( TmpLine1.IsTheComparedLineConnected(TmpLine2,21) )
{
TmpLine1=TmpLine2;
ContourBeamLine.push_back(TmpLine2);
TmpContourBeamLine.erase(&TmpContourBeamLine.at(i));
i=-1;
}
}
TmpLine1=ContourBeamLine.at(InverseStartNum);
for(i=0;i<TmpContourBeamLine.size();i++)
{
TmpLine2=TmpContourBeamLine.at(i);
if( TmpLine1.IsTheComparedLineConnected(TmpLine2,12) )
{
TmpLine1=TmpLine2;
ContourBeamLine.insert(&ContourBeamLine.at(InverseStartNum),TmpLine2);
TmpContourBeamLine.erase(&TmpContourBeamLine.at(i));
i=-1;
}
}
}
TmpContourBeamLine.clear();
}
void CClosedLoop::ArrangeContourOffsetBeamLine()
{
if(ContourOffsetBeamLine.size()==0)
return;
std::vector<CTwoDLine> TmpContourOffsetBeamLine;
int i,InverseStartNum;
CTwoDLine TmpLine1,TmpLine2;
for(i=0;i<ContourOffsetBeamLine.size();i++)
TmpContourOffsetBeamLine.push_back(ContourOffsetBeamLine.at(i));
ContourOffsetBeamLine.clear();
while(TmpContourOffsetBeamLine.size()!=0) {
TmpLine1=TmpContourOffsetBeamLine.at(0);
ContourOffsetBeamLine.push_back(TmpLine1);
TmpContourOffsetBeamLine.erase(&TmpContourOffsetBeamLine.at(0));
InverseStartNum=ContourOffsetBeamLine.size()-1;
Nature Biotechnology: doi:10.1038/nbt.3413
for(i=0;i<TmpContourOffsetBeamLine.size();i++)
{
TmpLine2=TmpContourOffsetBeamLine.at(i);
if( TmpLine1.IsTheComparedLineConnected(TmpLine2,21) )
{
TmpLine1=TmpLine2;
ContourOffsetBeamLine.push_back(TmpLine2);
TmpContourOffsetBeamLine.erase(&TmpContourOffsetBeamLine.at(i));
i=-1;
}
}
TmpLine1=ContourOffsetBeamLine.at(InverseStartNum);
for(i=0;i<TmpContourOffsetBeamLine.size();i++)
{
TmpLine2=TmpContourOffsetBeamLine.at(i);
if( TmpLine1.IsTheComparedLineConnected(TmpLine2,12) )
{
TmpLine1=TmpLine2;
ContourOffsetBeamLine.insert(&ContourOffsetBeamLine.at(InverseStartNum),TmpLine2);
TmpContourOffsetBeamLine.erase(&TmpContourOffsetBeamLine.at(i));
i=-1;
}
}
}
TmpContourOffsetBeamLine.clear();
}
void CClosedLoop::ArrangeOneScanBeamLine()
{
if(OneScanBeamLine.size()==0)
return;
std::vector<CTwoDLine> TmpOneScanBeamLine;
int i,InverseStartNum;
CTwoDLine TmpLine1,TmpLine2;
for(i=0;i<OneScanBeamLine.size();i++)
TmpOneScanBeamLine.push_back(OneScanBeamLine.at(i));
OneScanBeamLine.clear();
while(TmpOneScanBeamLine.size()!=0) {
TmpLine1=TmpOneScanBeamLine.at(0);
Nature Biotechnology: doi:10.1038/nbt.3413
OneScanBeamLine.push_back(TmpLine1);
TmpOneScanBeamLine.erase(&TmpOneScanBeamLine.at(0));
InverseStartNum=OneScanBeamLine.size()-1;
for(i=0;i<TmpOneScanBeamLine.size();i++)
{
TmpLine2=TmpOneScanBeamLine.at(i);
if( TmpLine1.IsTheComparedLineConnected(TmpLine2,21) )
{
TmpLine1=TmpLine2;
OneScanBeamLine.push_back(TmpLine2);
TmpOneScanBeamLine.erase(&TmpOneScanBeamLine.at(i));
i=-1;
}
}
for(i=0;i<TmpOneScanBeamLine.size();i++)
{
TmpLine2=TmpOneScanBeamLine.at(i);
if( TmpLine1.IsTheComparedLineConnected(TmpLine2,22) )
{
TmpLine2.InverseLineDirection();
TmpLine1=TmpLine2;
OneScanBeamLine.push_back(TmpLine2);
TmpOneScanBeamLine.erase(&TmpOneScanBeamLine.at(i));
i=-1;
}
}
TmpLine1=OneScanBeamLine.at(InverseStartNum);
for(i=0;i<TmpOneScanBeamLine.size();i++)
{
TmpLine2=TmpOneScanBeamLine.at(i);
if( TmpLine1.IsTheComparedLineConnected(TmpLine2,12) )
{
TmpLine1=TmpLine2;
OneScanBeamLine.insert(&OneScanBeamLine.at(InverseStartNum),TmpLine2);
TmpOneScanBeamLine.erase(&TmpOneScanBeamLine.at(i));
i=-1;
}
}
for(i=0;i<TmpOneScanBeamLine.size();i++)
{
TmpLine2=TmpOneScanBeamLine.at(i);
if( TmpLine1.IsTheComparedLineConnected(TmpLine2,11) )
{
TmpLine2.InverseLineDirection();
Nature Biotechnology: doi:10.1038/nbt.3413
TmpLine1=TmpLine2;
OneScanBeamLine.insert(&OneScanBeamLine.at(InverseStartNum),TmpLine2);
TmpOneScanBeamLine.erase(&TmpOneScanBeamLine.at(i));
i=-1;
}
}
}
TmpOneScanBeamLine.clear();
}
void CClosedLoop::InsertRecMoldLineToContourOffsetBeamLine(double MaxX, double MaxY, double MinX, double MinY)
{
CTwoDLine Up,Bottom,Left,Right;
double TmpVertex1[2],TmpVertex2[2];
double NorVector[2];
/*
TmpVertex1[0]=MinX; TmpVertex1[1]=(MaxY+MinY)/2.0;
TmpVertex2[0]=(MinX+MaxX)/2.0; TmpVertex2[1]=MaxY;
NorVector[0]=-1.0; NorVector[1]=1.0;
Up.SetVertex1(TmpVertex1);
Up.SetVertex2(TmpVertex2);
Up.InsertNorVec(NorVector);
TmpVertex1[0]=(MinX+MaxX)/2.0; TmpVertex1[1]=MaxY;
TmpVertex2[0]=MaxX; TmpVertex2[1]=(MaxY+MinY)/2.0;
NorVector[0]=1.0; NorVector[1]=1.0;
Right.SetVertex1(TmpVertex1);
Right.SetVertex2(TmpVertex2);
Right.InsertNorVec(NorVector);
TmpVertex1[0]=MaxX; TmpVertex1[1]=(MaxY+MinY)/2.0;
TmpVertex2[0]=(MaxX+MinX)/2.0; TmpVertex2[1]=MinY;
NorVector[0]=1.0; NorVector[1]=-1.0;
Bottom.SetVertex1(TmpVertex1);
Bottom.SetVertex2(TmpVertex2);
Bottom.InsertNorVec(NorVector);
TmpVertex1[0]=(MaxX+MinX)/2.0; TmpVertex1[1]=MinY;
TmpVertex2[0]=MinX; TmpVertex2[1]=(MaxY+MinY)/2.0;
NorVector[0]=-1.0; NorVector[1]=-1.0;
Left.SetVertex1(TmpVertex1);
Left.SetVertex2(TmpVertex2);
Left.InsertNorVec(NorVector);
*/
TmpVertex1[0]=MinX; TmpVertex1[1]=MaxY;
Nature Biotechnology: doi:10.1038/nbt.3413
TmpVertex2[0]=MaxX; TmpVertex2[1]=MaxY;
NorVector[0]=0.0; NorVector[1]=1.0;
Up.SetVertex1(TmpVertex1);
Up.SetVertex2(TmpVertex2);
Up.InsertNorVec(NorVector);
TmpVertex1[0]=MaxX; TmpVertex1[1]=MaxY;
TmpVertex2[0]=MaxX; TmpVertex2[1]=MinY;
NorVector[0]=1.0; NorVector[1]=0.0;
Right.SetVertex1(TmpVertex1);
Right.SetVertex2(TmpVertex2);
Right.InsertNorVec(NorVector);
TmpVertex1[0]=MaxX; TmpVertex1[1]=MinY;
TmpVertex2[0]=MinX; TmpVertex2[1]=MinY;
NorVector[0]=0.0; NorVector[1]=-1.0;
Bottom.SetVertex1(TmpVertex1);
Bottom.SetVertex2(TmpVertex2);
Bottom.InsertNorVec(NorVector);
TmpVertex1[0]=MinX; TmpVertex1[1]=MinY;
TmpVertex2[0]=MinX; TmpVertex2[1]=MaxY;
NorVector[0]=-1.0; NorVector[1]=0.0;
Left.SetVertex1(TmpVertex1);
Left.SetVertex2(TmpVertex2);
Left.InsertNorVec(NorVector);
ContourOffsetBeamLine.push_back(Up);
ContourOffsetBeamLine.push_back(Right);
ContourOffsetBeamLine.push_back(Bottom);
ContourOffsetBeamLine.push_back(Left);
}
double CClosedLoop::ReturnMaxXValInBeamLines()
{
double ReturnXVal=NumErrorFindDouble*(-1.0);
int i;
for(i=0;i<ContourBeamLine.size();i++)
{
if(ReturnXVal<ContourBeamLine.at(i).ReturnMaxXVal())
ReturnXVal=ContourBeamLine.at(i).ReturnMaxXVal();
}
for(i=0;i<ContourOffsetBeamLine.size();i++)
{
if(ReturnXVal<ContourOffsetBeamLine.at(i).ReturnMaxXVal())
ReturnXVal=ContourOffsetBeamLine.at(i).ReturnMaxXVal();
Nature Biotechnology: doi:10.1038/nbt.3413
}
return ReturnXVal;
}
double CClosedLoop::ReturnMinXValInBeamLines()
{
double ReturnXVal=NumErrorFindDouble;
int i;
for(i=0;i<ContourBeamLine.size();i++)
{
if(ReturnXVal>ContourBeamLine.at(i).ReturnMinXVal())
ReturnXVal=ContourBeamLine.at(i).ReturnMinXVal();
}
for(i=0;i<ContourOffsetBeamLine.size();i++)
{
if(ReturnXVal>ContourOffsetBeamLine.at(i).ReturnMinXVal())
ReturnXVal=ContourOffsetBeamLine.at(i).ReturnMinXVal();
}
return ReturnXVal;
}
void CClosedLoop::InsertRecMoldLineToContourBeamLine(double MaxX, double MaxY, double MinX, double MinY)
{
CTwoDLine Up,Bottom,Left,Right;
double TmpVertex1[2],TmpVertex2[2],NorVector[2];
/*
TmpVertex1[0]=MinX; TmpVertex1[1]=(MaxY+MinY)/2.0;
TmpVertex2[0]=(MinX+MaxX)/2.0; TmpVertex2[1]=MaxY;
NorVector[0]=-1.0; NorVector[1]=1.0;
Up.SetVertex1(TmpVertex1);
Up.SetVertex2(TmpVertex2);
Up.InsertNorVec(NorVector);
TmpVertex1[0]=(MinX+MaxX)/2.0; TmpVertex1[1]=MaxY;
TmpVertex2[0]=MaxX; TmpVertex2[1]=(MaxY+MinY)/2.0;
NorVector[0]=1.0; NorVector[1]=1.0;
Right.SetVertex1(TmpVertex1);
Right.SetVertex2(TmpVertex2);
Right.InsertNorVec(NorVector);
TmpVertex1[0]=MaxX; TmpVertex1[1]=(MaxY+MinY)/2.0;
TmpVertex2[0]=(MaxX+MinX)/2.0; TmpVertex2[1]=MinY;
Nature Biotechnology: doi:10.1038/nbt.3413
NorVector[0]=1.0; NorVector[1]=-1.0;
Bottom.SetVertex1(TmpVertex1);
Bottom.SetVertex2(TmpVertex2);
Bottom.InsertNorVec(NorVector);
TmpVertex1[0]=(MaxX+MinX)/2.0; TmpVertex1[1]=MinY;
TmpVertex2[0]=MinX; TmpVertex2[1]=(MaxY+MinY)/2.0;
NorVector[0]=-1.0; NorVector[1]=-1.0;
Left.SetVertex1(TmpVertex1);
Left.SetVertex2(TmpVertex2);
Left.InsertNorVec(NorVector);
*/
TmpVertex1[0]=MinX; TmpVertex1[1]=MaxY;
TmpVertex2[0]=MaxX; TmpVertex2[1]=MaxY;
NorVector[0]=0.0; NorVector[1]=1.0;
Up.SetVertex1(TmpVertex1);
Up.SetVertex2(TmpVertex2);
Up.InsertNorVec(NorVector);
TmpVertex1[0]=MaxX; TmpVertex1[1]=MaxY;
TmpVertex2[0]=MaxX; TmpVertex2[1]=MinY;
NorVector[0]=1.0; NorVector[1]=0.0;
Right.SetVertex1(TmpVertex1);
Right.SetVertex2(TmpVertex2);
Right.InsertNorVec(NorVector);
TmpVertex1[0]=MaxX; TmpVertex1[1]=MinY;
TmpVertex2[0]=MinX; TmpVertex2[1]=MinY;
NorVector[0]=0.0; NorVector[1]=-1.0;
Bottom.SetVertex1(TmpVertex1);
Bottom.SetVertex2(TmpVertex2);
Bottom.InsertNorVec(NorVector);
TmpVertex1[0]=MinX; TmpVertex1[1]=MinY;
TmpVertex2[0]=MinX; TmpVertex2[1]=MaxY;
NorVector[0]=-1.0; NorVector[1]=0.0;
Left.SetVertex1(TmpVertex1);
Left.SetVertex2(TmpVertex2);
Left.InsertNorVec(NorVector);
ContourBeamLine.push_back(Up);
ContourBeamLine.push_back(Right);
ContourBeamLine.push_back(Bottom);
ContourBeamLine.push_back(Left);
}
void CClosedLoop::SaveOrLoad(BOOL Save, CArchive &ar)
{
Nature Biotechnology: doi:10.1038/nbt.3413
int i,TmpNum;
if(Save)
{
ar<<IsMaxOffsetLoop;
TmpNum=SEOffsetMode.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
ar<<SEOffsetMode.at(i);
TmpNum=SEOffsetNumber.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
ar<<SEOffsetNumber.at(i);
TmpNum=SEXOffsetVal.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
ar<<SEXOffsetVal.at(i);
TmpNum=SEYOffsetVal.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
ar<<SEYOffsetVal.at(i);
TmpNum=OneScanBeamLine.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
OneScanBeamLine.at(i).SaveOrLoad(Save,ar);
TmpNum=CrossBeamLine.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
CrossBeamLine.at(i).SaveOrLoad(Save,ar);
TmpNum=ContourOffsetBeamLine.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
ContourOffsetBeamLine.at(i).SaveOrLoad(Save,ar);
TmpNum=ContourBeamLine.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
ContourBeamLine.at(i).SaveOrLoad(Save,ar);
TmpNum=OffsetLine.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
Nature Biotechnology: doi:10.1038/nbt.3413
OffsetLine.at(i).SaveOrLoad(Save,ar);
TmpNum=Line.size();
ar<<TmpNum;
for(i=0;i<TmpNum;i++)
Line.at(i).SaveOrLoad(Save,ar);
}
else
{
CTwoDLine TmpLine;
ar>>IsMaxOffsetLoop;
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
ar>>SEOffsetMode.at(i);
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
ar>>SEOffsetNumber.at(i);
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
ar<<SEXOffsetVal.at(i);
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
ar<<SEYOffsetVal.at(i);
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
{
TmpLine.SaveOrLoad(Save,ar);
OneScanBeamLine.push_back(TmpLine);
}
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
{
TmpLine.SaveOrLoad(Save,ar);
CrossBeamLine.push_back(TmpLine);
}
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
{
TmpLine.SaveOrLoad(Save,ar);
ContourOffsetBeamLine.push_back(TmpLine);
}
Nature Biotechnology: doi:10.1038/nbt.3413
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
{
TmpLine.SaveOrLoad(Save,ar);
ContourBeamLine.push_back(TmpLine);
}
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
{
TmpLine.SaveOrLoad(Save,ar);
OffsetLine.push_back(TmpLine);
}
ar>>TmpNum;
for(i=0;i<TmpNum;i++)
{
TmpLine.SaveOrLoad(Save,ar);
Line.push_back(TmpLine);
}
}
}
void CClosedLoop::Initialize()
{
IsMaxOffsetLoop=false;
SEOffsetMode.clear();
SEOffsetNumber.clear();
SEXOffsetVal.clear();
SEYOffsetVal.clear();
OneScanBeamLine.clear();
CrossBeamLine.clear();
ContourOffsetBeamLine.clear();
ContourBeamLine.clear();
OffsetLine.clear();
Line.clear();
}
void CClosedLoop::DeleteInvalidOffsetLine()
{
// std::vector<CTwoDLine> OffsetLine;
CTwoDLine TmpOffsetLine1, TmpOffsetLine2;
// double Vertex11[2],Vertex12[2];
// double Vertex21[2],Vertex22[2];
// double NormalVec10[2],NormalVec20[2];
double AngleOfLine1,AngleOfLine2;
double AngleOfNorOfLine1,AngleOfNorOfLine2;
Nature Biotechnology: doi:10.1038/nbt.3413
double AveAngle,AveNorAngle,AngDif;
int TmpAngDif,Start,End;
Start=-1;
End=-1;
int i,j;
for(i=0;i<OffsetLine.size()-1;i++)
{
TmpOffsetLine1=OffsetLine.at(i);
TmpOffsetLine2=OffsetLine.at(i+1);
AngleOfLine1=TmpOffsetLine1.GetLineCCWAngle();
AngleOfLine2=TmpOffsetLine2.GetLineCCWAngle();
AngleOfNorOfLine1=TmpOffsetLine1.GetNorVecCCWAngle();
AngleOfNorOfLine2=TmpOffsetLine2.GetNorVecCCWAngle();
AveAngle=(AngleOfLine1+AngleOfLine2)/2.0;
AveNorAngle=(AngleOfNorOfLine1+AngleOfNorOfLine2)/2.0;
AngDif=fabs(AveAngle-AveNorAngle)*180.0/3.141592;
TmpAngDif=(int)AngDif;
if( TmpAngDif!=87 && TmpAngDif!=90 && TmpAngDif!=91 && TmpAngDif!=270 && TmpAngDif!=269 &&
TmpAngDif!=271 )
{
if(Start<0)
Start=i;
else if(End<0)
End=i;
}
if(Start>=0 && End>=0)
{
for(j=End;j>=Start;j--)
OffsetLine.erase(&OffsetLine.at(j));
i=Start-1;
Start=-1;
End=-1;
}
}
}
Nature Biotechnology: doi:10.1038/nbt.3413