SundanceSurf3DCalc.cpp
Go to the documentation of this file.
00001 /* @HEADER@ */
00002 // ************************************************************************
00003 // 
00004 //                             Sundance
00005 //                 Copyright 2011 Sandia Corporation
00006 // 
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00008 // the U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Kevin Long (kevin.long@ttu.edu)
00038 // 
00039 
00040 /* @HEADER@ */
00041 
00042 
00043 /*
00044  * SundanceSurf3DCalc.cpp
00045  *
00046  *  Created on: Oct 25, 2011
00047  *      Author: benk
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                                               //       0           1           2           3            4             5
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                                               //     0       1       2       3       4       5       6       7      8       9       10      11
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 //                                                            0   1   2   3   4   5   6   7   8   9   10  11
00063 const int SundanceSurf3DCalc::edgeNeighboredges[12][12] = { { 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 0 , 0 , 0} ,   /* 0 */
00064                                                         { 1 , 1 , 1 , 1 , 0 , 1 , 1 , 0 , 0 , 1 , 0 , 0} ,   /* 1 */
00065                                                         { 1 , 1 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 1 , 0 , 0} ,   /* 2 */
00066                                                         { 1 , 1 , 0 , 1 , 1 , 1 , 0 , 1 , 0 , 0 , 1 , 0} ,   /* 3 */
00067                                                         { 1 , 0 , 1 , 1 , 1 , 0 , 0 , 1 , 1 , 0 , 1 , 0} ,   /* 4 */
00068                                                         { 1 , 1 , 0 , 1 , 0 , 1 , 1 , 1 , 0 , 0 , 0 , 1} ,   /* 5 */
00069                                                         { 0 , 1 , 1 , 0 , 0 , 1 , 1 , 1 , 0 , 1 , 0 , 1} ,   /* 6 */
00070                                                         { 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 1} ,   /* 7 */
00071                                                         { 1 , 0 , 1 , 0 , 1 , 0 , 0 , 0 , 1 , 1 , 1 , 1} ,   /* 8 */
00072                                                         { 0 , 1 , 1 , 0 , 0 , 0 , 1 , 0 , 1 , 1 , 1 , 1} ,   /* 9 */
00073                                                         { 0 , 0 , 0 , 1 , 1 , 0 , 0 , 1 , 1 , 1 , 1 , 1} ,   /* 10 */
00074                                                         { 0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1} , };/* 11 */
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 // -------------------- get the intersection point according to the policy -------------------
00094 
00095   // get the intersection points between the edges of the brick and the surface
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     // test if we have intersection point, and take this only if there is one
00100       if (nrPoints == 1){
00101         // we test if the impacted faces have already two intersection points, if yes then, ignore the intersection point
00102         // ignore this intersection point
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            //SUNDANCE_MSG3(verb, "found Int. point [" << t_inters_points <<"]=" << result[0]);
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       // if there is more than one point than we ignore all of them, and just print a warning
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   // this means no surface point has found
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 // ------------------------ discover the triangles which form the surf -------------------------
00135   // get the polygon
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     // look for a point which is connected to polygonList[jj] ad has not been used yet
00143     tmp_i = -1;
00144     for (int ii = 0 ; ii < t_inters_points ; ii++){
00145       // test if this edge is neighboring
00146       if ( (pointUsed[ii] < 0) && (edgeNeighboredges[ edgeIndex[polygonList[jj-1]] ][ edgeIndex[ii] ] > 0) ) {
00147         // we found one neighboring point
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 }

Site Contact