00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #include "SundanceSurf3DCalc.hpp"
00051
00052 using namespace Sundance;
00053
00054 const int SundanceSurf3DCalc::edegIndex[12][2] = { {0,1} , {0,2} , {0,4} , {1,3} , {1,5} , {2,3} , {2,6} , {3,7} ,
00055 {4,5} , {4,6} , {5,7} , {6,7} };
00056
00057 const int SundanceSurf3DCalc::faceEdges[6][4] = { {0,1,3,5} , {0,2,4,8} , {1,2,6,9} , {3,4,7,10} , {5,6,7,11} , {8,9,10,11} };
00058
00059
00060 const int SundanceSurf3DCalc::edgeFaces[12][2] = { {0,1} , {0,2} , {1,2} , {0,3} , {1,3} , {0,4} , {2,4} , {3,4} , {1,5} , {2,5} , {3,5} , {4,5} };
00061
00062
00063 const int SundanceSurf3DCalc::edgeNeighboredges[12][12] = { { 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0 , 0} ,
00064 { 1 , 1 , 1 , 1 , 0 , 1 , 1 , 0 , 0 , 1 , 0 , 0} ,
00065 { 1 , 1 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 1 , 0 , 0} ,
00066 { 1 , 1 , 0 , 1 , 1 , 1 , 0 , 1 , 0 , 0 , 1 , 0} ,
00067 { 1 , 0 , 1 , 1 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 0} ,
00068 { 1 , 1 , 0 , 1 , 0 , 1 , 1 , 1 , 0 , 0 , 0 , 1} ,
00069 { 0 , 1 , 1 , 0 , 0 , 1 , 1 , 1 , 0 , 1 , 0 , 1} ,
00070 { 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 1} ,
00071 { 1 , 0 , 1 , 0 , 1 , 0 , 0 , 0 , 1 , 1 , 1 , 1} ,
00072 { 0 , 1 , 1 , 0 , 0 , 0 , 1 , 0 , 1 , 1 , 1 , 1} ,
00073 { 0 , 0 , 0 , 1 , 1 , 0 , 0 , 1 , 1 , 1 , 1 , 1} ,
00074 { 0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1} , };
00075
00076 void SundanceSurf3DCalc::getCurveQuadPoints(CellType maxCellType ,
00077 int maxCellLID ,
00078 const Mesh& mesh ,
00079 const ParametrizedCurve& paramCurve,
00080 const Array<Point>& brickPoints,
00081 Array<Point>& intersectPoints ,
00082 Array<int>& edgeIndex,
00083 Array<int>& triangleIndex){
00084 TEUCHOS_TEST_FOR_EXCEPTION( maxCellType != BrickCell ,
00085 std::runtime_error , " maxCellType must be a BrickCell: " << BrickCell << " but it is:" << maxCellType);
00086
00087 int nrPoints , edge , t_inters_points = 0;
00088 int verb = 2;
00089 int tmp_i;
00090 int faceIntPoint[6] = { 0 , 0 , 0 , 0 , 0 , 0 };
00091 int edgePointI[12] = { -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 , -1 };
00092
00093
00094
00095
00096 for (edge = 0 ; edge < 12 ; edge++){
00097 Array<Point> result(0);
00098 paramCurve.returnIntersectPoints(brickPoints[edegIndex[edge][0]], brickPoints[edegIndex[edge][1]], nrPoints , result);
00099
00100 if (nrPoints == 1){
00101
00102
00103 if ( (faceIntPoint[ edgeFaces[edge][0]] < 2) && (faceIntPoint[ edgeFaces[edge][1] ] < 2 )) {
00104 faceIntPoint[ edgeFaces[edge][0] ]++; faceIntPoint[ edgeFaces[edge][1] ]++;
00105 intersectPoints.resize( t_inters_points + 1 );
00106 edgeIndex.resize( t_inters_points + 1 );
00107 intersectPoints[t_inters_points] = result[0];
00108 edgeIndex[t_inters_points] = edge;
00109 edgePointI[edge] = t_inters_points;
00110
00111 t_inters_points++;
00112 } else {
00113 SUNDANCE_MSG1(verb, "WARNING One face had already two intersection points :"
00114 << faceIntPoint[ edgeFaces[edge][0]] <<" , " << faceIntPoint[ edgeFaces[edge][1]]);
00115 }
00116 }
00117
00118 if (nrPoints > 1){
00119 SUNDANCE_MSG1(verb, " WARNING: nr of intersection points: " << nrPoints << " for edge [ " << brickPoints[edegIndex[edge][0]] << " , "
00120 << brickPoints[edegIndex[edge][1]] << "] , the first two points i1:" << result[0] << " , i2: " << result[1]);
00121 }
00122 }
00123
00124
00125 if ( t_inters_points < 3){
00126 intersectPoints.resize(0);
00127 edgeIndex.resize(0);
00128 triangleIndex.resize(0);
00129 SUNDANCE_MSG1(verb, " WARNING: less than 3 int point found : " << t_inters_points << " for maxCellLID=" << maxCellLID
00130 << " P[0]=" << brickPoints[0] );
00131 return;
00132 }
00133
00134
00135
00136 Array<int> polygonList(t_inters_points,-1);
00137 Array<int> pointUsed(t_inters_points,-1);
00138 int startIndex = -1 ;
00139 polygonList[0] = 0; pointUsed[0] = 1;
00140 SUNDANCE_MSG3(verb, " polygonList[ 0 ] = 0 , P: " << intersectPoints[ 0 ]);
00141 for (int jj = 1 ; jj < t_inters_points ; jj++){
00142
00143 tmp_i = -1;
00144 for (int ii = 0 ; ii < t_inters_points ; ii++){
00145
00146 if ( (pointUsed[ii] < 0) && (edgeNeighboredges[ edgeIndex[polygonList[jj-1]] ][ edgeIndex[ii] ] > 0) ) {
00147
00148 tmp_i = ii;
00149 polygonList[jj] = ii;
00150 pointUsed[ii] = 1;
00151 SUNDANCE_MSG3(verb, " polygonList[ " << jj << " ] = " << ii << " , P: " << intersectPoints[ ii ]);
00152 break;
00153 }
00154 }
00155 TEUCHOS_TEST_FOR_EXCEPTION( tmp_i < 0 , std::runtime_error , " error by polygon detecting tmp_i > -1 , might be that the surface is not KONVEX");
00156 // look for an intersection point which is in the same face as the current intersection point
00157 }
00158
00159 //get the starting point by getting the point which is closest
00160 Array<double> dist(t_inters_points);
00161 double dist_tmp = 1e+100;
00162 for (int jj = 0 ; jj < t_inters_points ; jj++){
00163 double sum = 0.0;
00164 for (int ii = 0 ; ii < t_inters_points ; ii++){
00165 sum = sum + ::sqrt( (intersectPoints[ polygonList[ii] ] - intersectPoints[ polygonList[jj] ])
00166 *(intersectPoints[ polygonList[ii] ] - intersectPoints[ polygonList[jj] ]) );
00167 }
00168 // store the minimum distance and the index
00169 if (sum < dist_tmp) { startIndex = jj; dist_tmp = sum; }
00170 }
00171 SUNDANCE_MSG3(verb, " central point found: " << startIndex << " P = " << intersectPoints[ polygonList[startIndex] ]);
00172
00173 // ----------------- having the polygon and the starting point define the triangles ---------------
00174 int fI = 0 , actIF = startIndex , actIL = startIndex;
00175 triangleIndex.resize(3*(t_inters_points-2),-1);
00176 for (int jj = 0 ; jj < t_inters_points-2 ; jj++){
00177 actIF = (actIF+1) % t_inters_points;
00178 actIL = (actIF+1) % t_inters_points;
00179 SUNDANCE_MSG3(verb, " startIndex = " << startIndex << " , actIF = " << actIF << " , actIL = " << actIL);
00180 triangleIndex[fI] = polygonList[startIndex];
00181 triangleIndex[fI+1] = polygonList[actIF];
00182 triangleIndex[fI+2] = polygonList[actIL];
00183 SUNDANCE_MSG3(verb, "add triangle [ " << polygonList[startIndex] << " , " << polygonList[actIF] << " , " << polygonList[actIL] << " ]");
00184 SUNDANCE_MSG3(verb, "add triangle points = [ " << intersectPoints[polygonList[startIndex]] << " , " << intersectPoints[polygonList[actIF]]
00185 << " , " << intersectPoints[ polygonList[actIL] ] << " ]");
00186 fI = fI + 3;
00187 }
00188 // end the triangle is set
00189 }