15 const std::vector<V>& Y,
16 std::vector<std::vector<int> >& SX,
17 std::vector<std::vector<int> >& SY,
20 std::vector<std::vector<unsigned int> > subElementsX, subElementsY;
21 std::vector<std::vector<int> > faceIdsX, faceIdsY;
22 std::vector<V> subElementX(CM::grid1Dimension+1), subElementY(CM::grid2Dimension+1), sP;
23 std::vector<std::vector<int> > sSX, sSY;
25 CM::grid1_subdivisions(X,subElementsX,faceIdsX);
26 CM::grid2_subdivisions(Y,subElementsY,faceIdsY);
28 bool intersectionFound =
false;
30 for (
unsigned int i = 0; i < subElementsX.size(); ++i) {
31 for (
unsigned int ki = 0; ki < subElementsX[i].size(); ++ki)
32 subElementX[ki] = X[subElementsX[i][ki]];
33 for (
unsigned int j = 0; j < subElementsY.size(); ++j) {
34 for (
unsigned int kj = 0; kj < subElementsY[j].size(); ++kj)
35 subElementY[kj] = Y[subElementsY[j][kj]];
40 bool b = CM::computeIntersectionPoints(subElementX,subElementY,sSX,sSY,sP);
41 intersectionFound = intersectionFound || b;
44 for (
unsigned int ki = 0; ki < sSX.size(); ++ki) {
45 if (faceIdsX[i][ki] >= 0) {
46 for (
unsigned int kii = 0; kii < sSX[ki].size(); ++kii) {
48 SX[faceIdsX[i][ki]].push_back(k);
52 for (
unsigned int kj = 0; kj < sSY.size(); ++kj) {
53 if (faceIdsY[j][kj] >= 0) {
54 for (
unsigned int kjj = 0; kjj < sSY[kj].size(); ++kjj) {
56 SY[faceIdsY[j][kj]].push_back(k);
63 return intersectionFound;
72 std::integral_constant<int,3>,
74 const std::vector<std::vector<int> >& SX,
75 const std::vector<std::vector<int> >& SY,
76 const std::vector<V>& P,
77 std::vector<std::vector<int> >& H)
79 int n_facesX = SX.size();
80 int n_facesY = SY.size();
83 std::vector<int> no,id,temp ;
85 std::vector<std::vector<int> > tempH;
87 std::vector<int> faceOrderingX(n_facesX);
88 std::vector<int> faceOrderingY(n_facesY);
91 faceOrderingX[0] = 0; faceOrderingX[1] = 2; faceOrderingX[2] = 1;
93 faceOrderingX[0] = 0; faceOrderingX[1] = 3; faceOrderingX[2] = 2; faceOrderingX[3] = 1;
96 faceOrderingY[0] = 0; faceOrderingY[1] = 2; faceOrderingY[2] = 1;
98 faceOrderingY[0] = 0; faceOrderingY[1] = 3; faceOrderingY[2] = 2; faceOrderingY[3] = 1;
102 for (
int i = 0; i < n_facesX; ++i) {
103 if (SX[i].size() > 0) {
104 no = SX[faceOrderingX[i]];
105 removeDuplicates(no);
107 if ((m>=3) && newFace3D(no,tempH))
109 for (
int l=0; l<m; ++l)
110 p.push_back(P[no[l]]);
111 orderPointsCC(std::integral_constant<int,3>(), centroid,
id,p);
112 for (
int l=0; l<m; ++l)
113 temp.push_back(no[
id[l]]) ;
114 tempH.push_back(temp) ;
122 for (
int i = 0; i < n_facesY; ++i) {
123 if (SY[i].size() > 0) {
124 no = SY[faceOrderingY[i]];
125 removeDuplicates(no);
127 if ((m>=3) && newFace3D(no,tempH))
129 for (
int l=0; l<m; ++l)
130 p.push_back(P[no[l]]) ;
131 orderPointsCC(std::integral_constant<int,3>(),centroid,
id,p);
132 for (
int l=0; l<m; ++l)
133 temp.push_back(no[
id[l]]) ;
134 tempH.push_back(temp) ;
144 for (
int i = 0; i < tempH.size(); ++i) {
145 int hs = tempH[i].size();
147 for (
int j = 1; j <= hs-2;++j) {
149 temp.push_back(tempH[i][0]);
150 for (
int k = 0; k < 2; ++k)
151 temp.push_back(tempH[i][j+k]);
159void IntersectionComputation<CM>::orderPoints_(std::integral_constant<int,2>,
160 std::integral_constant<int,2>,
162 const std::vector<std::vector<int> >& SX,
163 const std::vector<std::vector<int> >& SY,
164 const std::vector<V>& P,
165 std::vector<std::vector<int> >& H)
168 std::vector<int> id, temp(2);
170 orderPointsCC(std::integral_constant<int,2>(),centroid,
id,P);
172 for (std::size_t i = 0; i <
id.size();++i) {
174 temp[1] =
id[(i+1)%(
id.size())];
180void IntersectionComputation<CM>::orderPoints_(std::integral_constant<int,2>,
181 std::integral_constant<int,3>,
183 const std::vector<std::vector<int> >& SX,
184 const std::vector<std::vector<int> >& SY,
185 const std::vector<V>& P,
186 std::vector<std::vector<int> >& H)
189 std::vector<int> id, temp(2);
191 orderPointsCC(std::integral_constant<int,3>(),centroid,
id,P);
193 for (
int i = 0; i <
id.size();++i) {
195 temp[1] =
id[(i+1)%(
id.size())];
201void IntersectionComputation<CM>::removeDuplicates(std::vector<int> & p)
203 sort(p.begin(),p.end());
204 std::vector<int>::iterator it = std::unique(p.begin(),p.end());
209bool IntersectionComputation<CM>::newFace3D(
const std::vector<int>&
id,
210 const std::vector<std::vector<int> >& H)
213 typedef typename std::vector<Empty>::size_type size_type;
218 std::vector<int> B = id ;
219 sort(B.begin(),B.end()) ;
226 if ((H[i].size())>=m)
229 sort(A.begin(),A.end());
231 for ( size_type j=0 ; j < m; j++)
232 tp += std::fabs(A[j]-B[j]) ;
244void IntersectionComputation<CM>::orderPointsCC(std::integral_constant<int,3>,
246 std::vector<int>&
id,
247 const std::vector<V>& P)
249 typedef typename std::vector<Empty>::size_type size_type;
254 V c,d1,d2,dr,dn,cross,d ;
255 std::vector<typename V::value_type> ai ;
260 cross[0] = d1[1]*d2[2] - d1[2]*d2[1] ;
261 cross[1] = d1[2]*d2[0] - d1[0]*d2[2] ;
262 cross[2] = d1[0]*d2[1] - d1[1]*d2[0] ;
264 if (((centroid - P[0])*cross)<0)
267 dr /= dr.two_norm() ;
271 dn /= dn.two_norm() ;
276 dr /= dr.two_norm() ;
280 dn /= dn.two_norm() ;
284 for ( size_type j=1 ; j < P.size() ; j++)
286 ai.push_back(atan2((P[j]-P[0])*dn,(P[j]-P[0])*dr)) ;
291 for ( size_type j=1; j < ai.size(); j++) {
292 for ( size_type i=0; i < j; i++) {
294 std::swap<typename V::value_type>(ai[i],ai[j]) ;
295 std::swap<int>(
id[i],
id[j]) ;
300 id.insert(
id.begin(),0);
304void IntersectionComputation<CM>::orderPointsCC(std::integral_constant<int,2>,
306 std::vector<int>&
id,
307 const std::vector<V>& P)
309 typedef typename std::vector<Empty>::size_type size_type;
312 typedef typename std::vector<Empty>::size_type size_type;
314 std::vector<typename V::value_type> ai(P.size());
318 for ( size_type i=0; i < P.size(); i++) {
319 ai[i] = atan2(P[i][1]-centroid[1],P[i][0]-centroid[0]);
324 for ( size_type j=1; j < ai.size(); j++) {
325 for ( size_type i=0; i < j; i++)
if (ai[j]<ai[i]) {
326 std::swap<typename V::value_type>(ai[i],ai[j]);
327 std::swap<int>(
id[i],
id[j]);
Definition gridglue.hh:37
int insertPoint(const V p, std::vector< V > &P)
Definition computeintersection.hh:164
Intersection computation method for two elements of arbitrary dimension.
Definition computeintersection.hh:39
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:14