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

234 lines
4.9 KiB

10 months ago
#include "stdafx.h"
#include "Clip.h"
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <iostream>
#include <fstream>
#include <sstream>
10 months ago
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()
{
10 months ago
init();
}
// ������������ʼ��
BranchPoint(Clip *c1, Clip *c2)
{
10 months ago
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)
{
10 months ago
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];
10 months ago
/*
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;
10 months ago
rc.push_back(pc1->id);
rc.push_back(pc2->id);
return rc;
}
/*������֧�㵽��������Ȩֵ
reverse=0ӷ֧p
reverse=1p֧
*/
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;
10 months ago
double X0 = p.x, Y0 = p.y, Z0 = p.z;
10 months ago
double FZ = (X1 - X0) * (X1 - X2) + (Y1 - Y0) * (Y1 - Y2) + (Z1 - Z0) * (Z1 - Z2);
double FM = 2 * Dis * Dis;
10 months ago
t = FZ / FM; // ��ʽ����t��Сֵ��
10 months ago
t = max(t, l);
t = min(t, r);
10 months ago
}
// if(!Equal(t,l)&&!Equal(t,r))cout<<"-------"<<endl;
coord = pc1->coord * (1 - t) + pc2->coord * t;
10 months ago
coord.type = 1;
10 months ago
if (reverse)
return distan(p, coord, inOut, 0);
return distan(coord, p, 0, inOut);
10 months ago
}
// ��¼��֧������λ��
void recordPos(int mode)
{
// if(!Equal(t,l)&&!Equal(t,r))cout<<"-------"<<endl;
// else t=(l+r)/2;
tempt[mode] = t;
10 months ago
}
void check(int i)
{
// if(!Equal(t,l)&&!Equal(t,r))cout<<"--"<<i<<"--"<<endl;
}
10 months ago
};
// ά�����з�֧���ļ���
struct BranchPointSet
{
BranchPoint b[MAXPointNum]; // ��֧������
int branchPointNum; // ��֧������
10 months ago
BranchPointSet()
{
branchPointNum = 0;
}
10 months ago
// ����һ����֧��,������ָ������ָ��
BranchPoint *addBranchPoint(Clip *pc1, Clip *pc2, int bundleNodeID)
{
10 months ago
branchPointNum++;
b[branchPointNum] = BranchPoint(pc1, pc2);
b[branchPointNum].bundleNodeID = bundleNodeID;
b[branchPointNum].id = branchPointNum;
b[branchPointNum].coord.type = 1;
b[branchPointNum].coord.ref = branchPointNum;
10 months ago
return &b[branchPointNum];
}
// ��ȡָ������Ϊid�ķ�֧����ָ��
BranchPoint *getBranchPointPointer(int id)
{
assert(id >= 1 && id <= branchPointNum);
10 months ago
return &b[id];
}
} branchPointSet;