PrParametrizeInt.h

00001 //===========================================================================
00002 // GoTools - SINTEF Geometry Tools version 1.1
00003 //
00004 // GoTools module: parametrization
00005 //
00006 // Copyright (C) 2000-2005 SINTEF ICT, Applied Mathematics, Norway.
00007 //
00008 // This program is free software; you can redistribute it and/or          
00009 // modify it under the terms of the GNU General Public License            
00010 // as published by the Free Software Foundation version 2 of the License. 
00011 //
00012 // This program is distributed in the hope that it will be useful,        
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of         
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          
00015 // GNU General Public License for more details.                           
00016 //
00017 // You should have received a copy of the GNU General Public License      
00018 // along with this program; if not, write to the Free Software            
00019 // Foundation, Inc.,                                                      
00020 // 59 Temple Place - Suite 330,                                           
00021 // Boston, MA  02111-1307, USA.                                           
00022 //
00023 // Contact information: E-mail: tor.dokken@sintef.no                      
00024 // SINTEF ICT, Department of Applied Mathematics,                         
00025 // P.O. Box 124 Blindern,                                                 
00026 // 0314 Oslo, Norway.                                                     
00027 //
00028 // Other licenses are also available for this software, notably licenses
00029 // for:
00030 // - Building commercial software.                                        
00031 // - Building software whose source code you wish to keep private.        
00032 //===========================================================================
00033 #ifndef PRPARAMETRIZEINT_H
00034 #define PRPARAMETRIZEINT_H
00035 
00036 #include "PrOrganizedPoints.h"
00037 #include <boost/smart_ptr.hpp>
00038 
00039 /*<PrParametrizeInt-syntax: */
00040 
00041 enum PrParamStartVector {
00042   PrBARYCENTRE            = 1,
00043   PrFROMUV                = 2
00044 };
00045 
00060 class PrParametrizeInt
00061 {
00062 protected:
00063 
00064   double                 tolerance_;
00065   PrParamStartVector   startvectortype_;
00066 
00067   boost::shared_ptr<PrOrganizedPoints> g_;
00068 
00069   vector<int>            neighbours_;
00070   vector<double>           weights_;
00071 
00072   vector< vector<double> > allWeights_;
00073   vector< vector<int> >    allNeighbours_;
00074 
00075 // PRIVATE METHODS
00076 
00077 // Used for parametrizing the interior.
00078   int          getNumIntNghrs(int i);
00079   int          getNumInt2Nghrs(int i, vector<int>&);
00080   void         findBarycentre(double& ucentre, double& vcentre);
00081   bool         isFixed (int, vector<int>&);
00082 
00083   virtual bool makeWeights(int i) = 0;
00084 
00085   const vector< vector<double> >& getAllWeights() const
00086   {
00087       return allWeights_;
00088   }
00089   const vector< vector<int> >&    getAllNeighbours() const
00090   {
00091       return allNeighbours_;
00092   }
00093 
00094 public:
00096   PrParametrizeInt();
00098   virtual ~PrParametrizeInt();
00099 
00101   void attach(boost::shared_ptr<PrOrganizedPoints> graph);
00102 
00105   void setStartVectorKind(PrParamStartVector svtype = PrBARYCENTRE)
00106     {startvectortype_ = svtype;}
00107 
00109   void setBiCGTolerance(double tolerance = 1.0e-6) {tolerance_ = tolerance;}
00110 
00112   bool parametrize();
00113 
00118   bool parametrize3d(vector<int>&, vector<double>&);
00119 
00124   bool new_parametrize3d(vector<int>&, vector<double>&);
00125 
00132   void findFixedPntsFromXYZ(vector<int>& fixedPnts);
00133 
00135   void smooth(int nmb, vector<int>& fixedPnts); 
00136 
00138   void computeWeights();
00139 
00140 };
00141 
00142 /*>PrParametrizeInt-syntax: */
00143 
00144 /*Class:PrParametrizeInt
00145 
00146 Name:              PrParametrizeInt
00147 Syntax:            @PrParametrizeInt-syntax
00148 Keywords:
00149 Description:       This class implements an algorithm for creating a
00150                    parametrization in $R^2$ of the interior of
00151                    a given embedding of a planar graph in $R^3$.
00152                    The method is described in the paper: M. S. Floater,
00153                    "Parametrization and smooth approximation of
00154                    surface triangulations", CAGD 14 (1997), 231-250.
00155                    The method sets u and v values to each interior
00156                    node of the graph.
00157                    The class PrParametrizeInt is an abstract base class.
00158                    One must call one of its derived classes in order
00159                    to choose a particular method of parametrization.
00160                    We recommend the shape preserving parametrization
00161                    implemented in PrPrmShpPres.
00162 Member functions:
00163                    "attach(PrOrganizedPoints& graph)" --\\
00164                    Set the graph.
00165 
00166                    "setBiCGTolerance()" --\\
00167                    Set tolerance for Bi-CGSTAB.
00168 
00169                    "parametrize()" --\\
00170                    Parametrize the given planar graph.
00171 
00172                    "smooth(int nmb)" --\\
00173                    performs "nmb" Gauss-Seidel smoothing steps on the sphere
00174 
00175 Constructors:
00176 Files:
00177 Example:
00178 
00179 | #include "PrTriangulation_OP.h"
00180 | #include "PrPrmShpPres.h"
00181 | 
00182 | main(int argc, char* argv[])
00183 | {
00184 |   // Initialize LA tools because we're using PrParametrizeInt.
00185 |   initDIFFPACK(argc,argv,true);
00186 | 
00187 |   // Read in a triangulation called "gjoevik_triang" which
00188 |   // should be in the directory "src/app/param_pr_triang".
00189 |   // See PrTriangulation_OP.h for examples of the file format.
00190 |   Is infile ("gjoevik_triang", INFILE);
00191 |   PrTriangulation_OP pr_triang;
00192 |   pr_triang.scanRawData(infile);
00193 | 
00194 |   pr_triang.printInfo(s_o);
00195 |   Os xyz_nodes_file("xyz_nodes",NEWFILE);
00196 |   pr_triang.printXYZNodes(xyz_nodes_file);
00197 |   Os xyz_edges_file("xyz_edges",NEWFILE);
00198 |   pr_triang.printXYZEdges(xyz_edges_file);
00199 |   Os xyz_triangles_file("xyz_triangles",NEWFILE);
00200 |   pr_triang.printXYZTriangles(xyz_triangles_file);
00201 | 
00202 |   int no_comps = pr_triang.findNumComponents();
00203 |   int genus = pr_triang.findGenus();
00204 | 
00205 |   if(no_comps == 1 && genus == 1)
00206 |   {
00207 |     PrPrmShpPres p; // PrPrmShpPres is derived from PrParametrizeInt
00208 |     p.setBdyParam(PrCHORDLENGTHBDY); // this is the default anyway
00209 |     p.attach(pr_triang);
00210 | 
00211 |     int cor[4];
00212 |     p.findCornersFromXYZ(cor);
00213 |     s_o << "The corner indices and their xyz values are\n";
00214 |     CgPoint3d pt;
00215 |     for(int k=0; k<4; k++)
00216 |     {
00217 |       pt = pr_triang.get3dNode(cor[k]);
00218 |       s_o << oform("%d  %lf %lf %lf\n",cor[k],pt.x(),pt.y(),pt.z());
00219 |     }
00220 |     p.parametrize(cor[0],cor[1],cor[2],cor[3]);
00221 |   }
00222 | 
00223 |   Os uv_nodes_file("uv_nodes",NEWFILE);
00224 |   pr_triang.printUVNodes(uv_nodes_file);
00225 |   Os uv_edges_file("uv_edges",NEWFILE);
00226 |   pr_triang.printUVEdges(uv_edges_file);
00227 |   Os uv_triangles_file("uv_triangles",NEWFILE);
00228 |   pr_triang.printUVTriangles(uv_triangles_file);
00229 | 
00230 |   Os uvxyz_nodes_file("uvxyz_nodes",NEWFILE);
00231 |   pr_triang.printUVXYZNodes(uvxyz_nodes_file);
00232 |   Os triangulation_file("triangulation",NEWFILE);
00233 |   pr_triang.print(triangulation_file);
00234 | 
00235 |   return 0;
00236 | }
00237 
00238 See also:
00239 Developed by:      SINTEF Applied Mathematics, Oslo, Norway
00240 Author:            Michael Floater, SINTEF
00241 Date:              Mar. 97
00242 */
00243 
00244 #endif // PRPARAMETRIZEINT_H

Generated on Tue Jun 12 11:05:05 2007 for GoTools Parametrization Library by  doxygen 1.5.1