13 const std::vector<V> Y,
14 std::vector<std::vector<int> >& SX,
15 std::vector<std::vector<int> >& SY,
18 std::vector<std::vector<unsigned int> > subElementsX, subElementsY;
19 std::vector<std::vector<int> > faceIdsX, faceIdsY;
20 std::vector<V> subElementX(CM::grid1Dimension+1), subElementY(CM::grid2Dimension+1), sP;
21 std::vector<std::vector<int> > sSX, sSY;
23 CM::grid1_subdivisions(X,subElementsX,faceIdsX);
24 CM::grid2_subdivisions(Y,subElementsY,faceIdsY);
26 bool intersectionFound =
false;
28 for (
unsigned int i = 0; i < subElementsX.size(); ++i) {
29 for (
unsigned int ki = 0; ki < subElementsX[i].size(); ++ki)
30 subElementX[ki] = X[subElementsX[i][ki]];
31 for (
unsigned int j = 0; j < subElementsY.size(); ++j) {
32 for (
unsigned int kj = 0; kj < subElementsY[j].size(); ++kj)
33 subElementY[kj] = Y[subElementsY[j][kj]];
38 bool b = CM::computeIntersectionPoints(subElementX,subElementY,sSX,sSY,sP);
39 intersectionFound = intersectionFound || b;
42 for (
unsigned int ki = 0; ki < sSX.size(); ++ki) {
43 if (faceIdsX[i][ki] >= 0) {
44 for (
unsigned int kii = 0; kii < sSX[ki].size(); ++kii) {
46 SX[faceIdsX[i][ki]].push_back(k);
50 for (
unsigned int kj = 0; kj < sSY.size(); ++kj) {
51 if (faceIdsY[j][kj] >= 0) {
52 for (
unsigned int kjj = 0; kjj < sSY[kj].size(); ++kjj) {
54 SY[faceIdsY[j][kj]].push_back(k);
61 return intersectionFound;
70 std::integral_constant<int,3>,
72 const std::vector<std::vector<int> > SX,
73 const std::vector<std::vector<int> > SY,
74 const std::vector<V> P,
75 std::vector<std::vector<int> >& H)
77 int n_facesX = SX.size();
78 int n_facesY = SY.size();
81 std::vector<int> no,id,temp ;
83 std::vector<std::vector<int> > tempH;
85 std::vector<int> faceOrderingX(n_facesX);
86 std::vector<int> faceOrderingY(n_facesY);
89 faceOrderingX[0] = 0; faceOrderingX[1] = 2; faceOrderingX[2] = 1;
91 faceOrderingX[0] = 0; faceOrderingX[1] = 3; faceOrderingX[2] = 2; faceOrderingX[3] = 1;
94 faceOrderingY[0] = 0; faceOrderingY[1] = 2; faceOrderingY[2] = 1;
96 faceOrderingY[0] = 0; faceOrderingY[1] = 3; faceOrderingY[2] = 2; faceOrderingY[3] = 1;
100 for (
int i = 0; i < n_facesX; ++i) {
101 if (SX[i].size() > 0) {
102 no = SX[faceOrderingX[i]];
103 removeDuplicates(no);
105 if ((m>=3) && newFace3D(no,tempH))
107 for (
int l=0; l<m; ++l)
108 p.push_back(P[no[l]]);
109 orderPointsCC(std::integral_constant<int,3>(), centroid,
id,p);
110 for (
int l=0; l<m; ++l)
111 temp.push_back(no[
id[l]]) ;
112 tempH.push_back(temp) ;
120 for (
int i = 0; i < n_facesY; ++i) {
121 if (SY[i].size() > 0) {
122 no = SY[faceOrderingY[i]];
123 removeDuplicates(no);
125 if ((m>=3) && newFace3D(no,tempH))
127 for (
int l=0; l<m; ++l)
128 p.push_back(P[no[l]]) ;
129 orderPointsCC(std::integral_constant<int,3>(),centroid,
id,p);
130 for (
int l=0; l<m; ++l)
131 temp.push_back(no[
id[l]]) ;
132 tempH.push_back(temp) ;
142 for (
int i = 0; i < tempH.size(); ++i) {
143 int hs = tempH[i].size();
145 for (
int j = 1; j <= hs-2;++j) {
147 temp.push_back(tempH[i][0]);
148 for (
int k = 0; k < 2; ++k)
149 temp.push_back(tempH[i][j+k]);
157void IntersectionComputation<CM>::orderPoints_(std::integral_constant<int,2>,
158 std::integral_constant<int,2>,
160 const std::vector<std::vector<int> > SX,
161 const std::vector<std::vector<int> > SY,
162 const std::vector<V> P,
163 std::vector<std::vector<int> >& H)
166 std::vector<int> id, temp(2);
168 orderPointsCC(std::integral_constant<int,2>(),centroid,
id,P);
170 for (std::size_t i = 0; i <
id.size();++i) {
172 temp[1] =
id[(i+1)%(
id.size())];
178void IntersectionComputation<CM>::orderPoints_(std::integral_constant<int,2>,
179 std::integral_constant<int,3>,
181 const std::vector<std::vector<int> > SX,
182 const std::vector<std::vector<int> > SY,
183 const std::vector<V> P,
184 std::vector<std::vector<int> >& H)
187 std::vector<int> id, temp(2);
189 orderPointsCC(std::integral_constant<int,3>(),centroid,
id,P);
191 for (
int i = 0; i <
id.size();++i) {
193 temp[1] =
id[(i+1)%(
id.size())];
199void IntersectionComputation<CM>::removeDuplicates(std::vector<int> & p)
201 sort(p.begin(),p.end());
202 std::vector<int>::iterator it = std::unique(p.begin(),p.end());
207bool IntersectionComputation<CM>::newFace3D(
const std::vector<int>
id,
208 const std::vector<std::vector<int> > H)
211 typedef typename std::vector<Empty>::size_type size_type;
216 std::vector<int> B = id ;
217 sort(B.begin(),B.end()) ;
224 if ((H[i].size())>=m)
227 sort(A.begin(),A.end());
229 for ( size_type j=0 ; j < m; j++)
230 tp += std::fabs(A[j]-B[j]) ;
242void IntersectionComputation<CM>::orderPointsCC(std::integral_constant<int,3>,
244 std::vector<int>&
id,
245 const std::vector<V> P)
247 typedef typename std::vector<Empty>::size_type size_type;
252 V c,d1,d2,dr,dn,cross,d ;
253 std::vector<typename V::value_type> ai ;
258 cross[0] = d1[1]*d2[2] - d1[2]*d2[1] ;
259 cross[1] = d1[2]*d2[0] - d1[0]*d2[2] ;
260 cross[2] = d1[0]*d2[1] - d1[1]*d2[0] ;
262 if (((centroid - P[0])*cross)<0)
265 dr /= dr.two_norm() ;
269 dn /= dn.two_norm() ;
274 dr /= dr.two_norm() ;
278 dn /= dn.two_norm() ;
282 for ( size_type j=1 ; j < P.size() ; j++)
284 ai.push_back(atan2((P[j]-P[0])*dn,(P[j]-P[0])*dr)) ;
289 for ( size_type j=1; j < ai.size(); j++) {
290 for ( size_type i=0; i < j; i++) {
292 std::swap<typename V::value_type>(ai[i],ai[j]) ;
293 std::swap<int>(
id[i],
id[j]) ;
298 id.insert(
id.begin(),0);
302void IntersectionComputation<CM>::orderPointsCC(std::integral_constant<int,2>,
304 std::vector<int>&
id,
305 const std::vector<V> P)
307 typedef typename std::vector<Empty>::size_type size_type;
310 typedef typename std::vector<Empty>::size_type size_type;
312 std::vector<typename V::value_type> ai(P.size());
316 for ( size_type i=0; i < P.size(); i++) {
317 ai[i] = atan2(P[i][1]-centroid[1],P[i][0]-centroid[0]);
322 for ( size_type j=1; j < ai.size(); j++) {
323 for ( size_type i=0; i < j; i++)
if (ai[j]<ai[i]) {
324 std::swap<typename V::value_type>(ai[i],ai[j]);
325 std::swap<int>(
id[i],
id[j]);
Definition gridglue.hh:30
int insertPoint(const V p, std::vector< V > &P)
Definition computeintersection.hh:162
Intersection computation method for two elements of arbitrary dimension.
Definition computeintersection.hh:37
static bool computeIntersection(const std::vector< V > X, const std::vector< V > Y, std::vector< std::vector< int > > &SX, std::vector< std::vector< int > > &SY, std::vector< V > &P)
Compute the intersection of two elements X and Y Compute the intersection of two elements X and Y,...
Definition computeintersection.cc:12