|
|
|
#include "stdafx.h"
|
|
|
|
#include "Clip.h"
|
|
|
|
#include <cmath>
|
|
|
|
#include <vector>
|
|
|
|
#include <queue>
|
|
|
|
#include <map>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
// ��֧����������
|
|
|
|
struct BranchPoint
|
|
|
|
{
|
|
|
|
P coord; // ������
|
|
|
|
double t; // ��֧������λ�ã���0-1֮��
|
|
|
|
double Dis; // ����������֮���ľ���
|
|
|
|
bool fixed; // λ���Ƿ��Ѿ��̶�
|
|
|
|
Clip *pc1, *pc2; // �洢�����ڵ���������
|
|
|
|
BranchPoint *pb1, *pb2; // �洢�����ڵ�������֧��
|
|
|
|
double l, r; // ����t�ķ�Χ
|
|
|
|
vector<int> branchPointsInSameSegment; // ͬһ�ֶ���������֧���ı���
|
|
|
|
P ndir; // ���ڷ�֧�ķ��߷���
|
|
|
|
double position; // �����ο������ľ���
|
|
|
|
double tempt[2]; // �洢��֧�������������µ�����λ�ã�0�������ν�ͬ�γ�
|
|
|
|
string referClip; // �����������
|
|
|
|
int id; // ��֧������
|
|
|
|
int mode; // �洢��֧����һ�α�����·����������������0�������ν�ͬ�γ���1����ͬ�ν����˳�
|
|
|
|
int bundleNodeID; // ��֧�����ڵ�bundle��id
|
|
|
|
bool used; // ��֧���Ƿ���ʹ��
|
|
|
|
|
|
|
|
void init()
|
|
|
|
{
|
|
|
|
l = 0;
|
|
|
|
r = 1;
|
|
|
|
pc1 = pc2 = NULL;
|
|
|
|
pb1 = pb2 = NULL;
|
|
|
|
t = 0.5;
|
|
|
|
Dis = 0;
|
|
|
|
fixed = false;
|
|
|
|
position = 0;
|
|
|
|
id = 0;
|
|
|
|
bundleNodeID = 0;
|
|
|
|
used = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ��ʼ��
|
|
|
|
BranchPoint()
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ������������ʼ��
|
|
|
|
BranchPoint(Clip *c1, Clip *c2)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
pc1 = c1;
|
|
|
|
pc2 = c2;
|
|
|
|
Dis = distan1(c1->coord, c2->coord);
|
|
|
|
double ratio = MinClipToBranchPointDistance / Dis;
|
|
|
|
l = max(l, ratio);
|
|
|
|
r = min(r, 1 - ratio);
|
|
|
|
t = (l + r) / 2;
|
|
|
|
// cout<<"BranchPoint2: ratio:"<<ratio<<" l:"<<l<<" r:"<<r<<" t:"<<t<<endl;
|
|
|
|
coord = (c1->coord) * (1 - t) + (c2->coord) * t;
|
|
|
|
}
|
|
|
|
|
|
|
|
// �������ͷ�Χ��ʼ��
|
|
|
|
BranchPoint(Clip *c1, Clip *c2, double L, double R)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
pc1 = c1;
|
|
|
|
pc2 = c2;
|
|
|
|
Dis = distan1(c1->coord, c2->coord);
|
|
|
|
double ratio = MinClipToBranchPointDistance / Dis;
|
|
|
|
l = max(L, ratio);
|
|
|
|
r = min(R, 1 - ratio);
|
|
|
|
t = (l + r) / 2;
|
|
|
|
cout << "BranchPoint L+R: ratio:" << ratio << " l:" << l << " r:" << r << " t:" << t << endl;
|
|
|
|
coord = (c1->coord) * (1 - t) + (c2->coord) * t;
|
|
|
|
}
|
|
|
|
|
|
|
|
// �������ߵķ�֧��
|
|
|
|
void addL(BranchPoint b)
|
|
|
|
{
|
|
|
|
pb1 = &b;
|
|
|
|
}
|
|
|
|
|
|
|
|
// �����ұߵķ�֧��
|
|
|
|
void addR(BranchPoint b)
|
|
|
|
{
|
|
|
|
pb2 = &b;
|
|
|
|
}
|
|
|
|
|
|
|
|
// �����߽����ұ���d����
|
|
|
|
void pushL(double d)
|
|
|
|
{
|
|
|
|
if (d <= 0)
|
|
|
|
return;
|
|
|
|
l += d / Dis;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ���ұ߽���������d����
|
|
|
|
void pushR(double d)
|
|
|
|
{
|
|
|
|
if (d <= 0)
|
|
|
|
return;
|
|
|
|
r -= d / Dis;
|
|
|
|
}
|
|
|
|
|
|
|
|
// �̶���֧��λ��
|
|
|
|
void fix()
|
|
|
|
{
|
|
|
|
if (fixed == true)
|
|
|
|
return;
|
|
|
|
fixed = true;
|
|
|
|
t = tempt[mode];
|
|
|
|
/*
|
|
|
|
if(pb1!=NULL){
|
|
|
|
pb1->pushL(t*Dis+MinBranchPointDistance-r*Dis);
|
|
|
|
}
|
|
|
|
if(pb2!=NULL){
|
|
|
|
pb2->pushR(l*Dis-(t*Dis-MinBranchPointDistance));
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
cout << "***********";
|
|
|
|
if (!Equal(t, l) && !Equal(t, r))
|
|
|
|
cout << "-------";
|
|
|
|
cout << endl;
|
|
|
|
|
|
|
|
referClip = pc1->name;
|
|
|
|
position = t * Dis;
|
|
|
|
assert(position <= Dis);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ͨ����������֧��Ҳ�ı�����ʾ��ʽ
|
|
|
|
void reverse()
|
|
|
|
{
|
|
|
|
referClip = pc2->name;
|
|
|
|
position = Dis - position;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ���ط�֧���ڷ�֧�Ͽ������ӵ�����һ����
|
|
|
|
// offSet������֧��������ƫ��ֵ
|
|
|
|
inline vector<int> getNext(int offSet)
|
|
|
|
{
|
|
|
|
vector<int> rc = branchPointsInSameSegment;
|
|
|
|
for (int i = 0; i < rc.size(); i++)
|
|
|
|
rc[i] += offSet;
|
|
|
|
rc.push_back(pc1->id);
|
|
|
|
rc.push_back(pc2->id);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*������֧�㵽��������Ȩֵ
|
|
|
|
reverse=0�����ӷ�֧�㵽p
|
|
|
|
reverse=1������p����֧��
|
|
|
|
*/
|
|
|
|
inline double computeWeight(P &p, int inOut, bool reverse)
|
|
|
|
{
|
|
|
|
if (l >= r)
|
|
|
|
return 1e9;
|
|
|
|
|
|
|
|
if (fixed == false)
|
|
|
|
{
|
|
|
|
double X1 = pc1->coord.x, Y1 = pc1->coord.y, Z1 = pc1->coord.z;
|
|
|
|
double X2 = pc2->coord.x, Y2 = pc2->coord.y, Z2 = pc2->coord.z;
|
|
|
|
|
|
|
|
double X0 = p.x, Y0 = p.y, Z0 = p.z;
|
|
|
|
|
|
|
|
double FZ = (X1 - X0) * (X1 - X2) + (Y1 - Y0) * (Y1 - Y2) + (Z1 - Z0) * (Z1 - Z2);
|
|
|
|
double FM = 2 * Dis * Dis;
|
|
|
|
|
|
|
|
t = FZ / FM; // ��ʽ����t��Сֵ��
|
|
|
|
|
|
|
|
t = max(t, l);
|
|
|
|
t = min(t, r);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if(!Equal(t,l)&&!Equal(t,r))cout<<"-------"<<endl;
|
|
|
|
coord = pc1->coord * (1 - t) + pc2->coord * t;
|
|
|
|
|
|
|
|
coord.type = 1;
|
|
|
|
|
|
|
|
if (reverse)
|
|
|
|
return distan(p, coord, inOut, 0);
|
|
|
|
return distan(coord, p, 0, inOut);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ��¼��֧������λ��
|
|
|
|
void recordPos(int mode)
|
|
|
|
{
|
|
|
|
// if(!Equal(t,l)&&!Equal(t,r))cout<<"-------"<<endl;
|
|
|
|
// else t=(l+r)/2;
|
|
|
|
tempt[mode] = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
void check(int i)
|
|
|
|
{
|
|
|
|
// if(!Equal(t,l)&&!Equal(t,r))cout<<"--"<<i<<"--"<<endl;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// ά�����з�֧���ļ���
|
|
|
|
struct BranchPointSet
|
|
|
|
{
|
|
|
|
BranchPoint b[MAXPointNum]; // ��֧������
|
|
|
|
int branchPointNum; // ��֧������
|
|
|
|
|
|
|
|
BranchPointSet()
|
|
|
|
{
|
|
|
|
branchPointNum = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ����һ����֧��,������ָ������ָ��
|
|
|
|
BranchPoint *addBranchPoint(Clip *pc1, Clip *pc2, int bundleNodeID)
|
|
|
|
{
|
|
|
|
branchPointNum++;
|
|
|
|
b[branchPointNum] = BranchPoint(pc1, pc2);
|
|
|
|
b[branchPointNum].bundleNodeID = bundleNodeID;
|
|
|
|
b[branchPointNum].id = branchPointNum;
|
|
|
|
b[branchPointNum].coord.type = 1;
|
|
|
|
b[branchPointNum].coord.ref = branchPointNum;
|
|
|
|
return &b[branchPointNum];
|
|
|
|
}
|
|
|
|
|
|
|
|
// ��ȡָ������Ϊid�ķ�֧����ָ��
|
|
|
|
BranchPoint *getBranchPointPointer(int id)
|
|
|
|
{
|
|
|
|
assert(id >= 1 && id <= branchPointNum);
|
|
|
|
return &b[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
} branchPointSet;
|