00001 00002 /* 00003 ** --------------------------------------------------------------- 00004 ** 00005 ** @name Parametrized Faceted Surface module 00006 ** 00007 ** --------------------------------------------------------------- 00008 ** 00009 ** @date 31-Aug-2006 00010 ** @author Luiz F. Martha 00011 ** @version 1.0 00012 ** 00013 ** --------------------------------------------------------------- 00014 ** pfs.h - Parametrized Faceted Surface module API. 00015 ** 00016 ** --------------------------------------------------------------- 00017 ** Description: 00018 ** 00019 ** This header file contains declarations of exported functions 00020 ** and global definitions of the parametric facet surface module. 00021 ** 00022 ** This module contains functions to represent a typical faceted 00023 ** (triangulated) surface mesh data and functions to create a 00024 ** two-dimensional parametric space associated to the faceted 00025 ** surface. 00026 ** Basically, a pair of surface parametric values are associated 00027 ** to each node in the mesh. This is mainly based on the wrk 00028 ** of Levy, Petitjean, Ray, and Maillot, "Least squares conformal 00029 ** maps for automatic texture atlas generation," SIGRAPH 00030 ** proceedings, 2002 00031 ** The local data structure consists of a node (vertex) vector 00032 ** with nodal coordinates and node-node adjacency relationships, 00033 ** and an element (face) vector with nodal connectivity. 00034 ** 00035 ** --------------------------------------------------------------- 00036 ** Initialization of nodal parametric coordinates: 00037 ** 00038 ** The initial parametric coordinates are obtained from the 00039 ** projection of the nodal points onto a reference plane. 00040 ** This plane contains the reference element, which is the 00041 ** the element that has the normal vector closest to the 00042 ** global average surface normal vector. 00043 ** The global average normal vector is obtained from the average 00044 ** of the normal vectors of all elements of the surface. This is 00045 ** a weighted average considering the area as the weight of each 00046 ** element. 00047 ** The reference element containts the origin of the parametric 00048 ** space. The origin is the first node of the element, which is 00049 ** called the reference node. The parametric coordinates of the 00050 ** reference node are (u,v) = (0,0), which will never change 00051 ** during the iterative solution described below. 00052 ** The algorithm tries to lay the first plane parametric vector 00053 ** be at the projection of the major x-axis with the plane. 00054 ** If the x-axis is almost (less then 30 degrees) parallel to the 00055 ** plane normal vector, it tries to do the same with the y-axis and 00056 ** z-axis (in this order). 00057 ** 00058 ** --------------------------------------------------------------- 00059 ** Iterative solution for nodal parametric coordinates: 00060 ** 00061 ** The solution of nodal parametric values is performed by means 00062 ** of an iterative procedure, which consists of several passes 00063 ** along the nodes of the surface. In each iteration of a pass, 00064 ** a local solution of the conformal mapping problem is performed 00065 ** at a node. A 2 by 2 system of equations is assembled in which 00066 ** the equation coefficients correspond to the conformal map 00067 ** coefficients of the node and the forcing vector is obtained 00068 ** from the current parametric values and coefficients of all the 00069 ** adjacent nodes. The solution of the system of equation furnishes 00070 ** the new parametric values of a node in each iteration. The 00071 ** iterative solution terminates when all changes in parametric 00072 ** values of one pass in relation to the previous pass are small 00073 ** (within a tolerance). The tolerance used to terminate the 00074 ** iterative solution is defined as a factor of the size of first 00075 ** reference element side (from the reference node to the next 00076 ** element node in counter-clockwise order). 00077 ** In each pass, the iterative solution follows an order that 00078 ** traverses the nodes by levels of adjacency. The first level 00079 ** contains the reference node. Each level is created with the 00080 ** nodes that are adjacent to the nodes of the previous level 00081 ** that have not been used by any level. 00082 ** 00083 ** --------------------------------------------------------------- 00084 ** Normalization of nodal parametric coordinates: 00085 ** 00086 ** After the iterative solution, the nodal parametric coordinates 00087 ** are normalized in such a way that the minimum parametric value 00088 ** is zero and the maximum is one. In the normalization, the same 00089 ** scaling factor is applyed to both u and v parametric coordinates 00090 ** 00091 ** ---------------------------------------------------------------- 00092 ** 00093 ** Created: 17-Jan-2005 Luiz F. Martha 00094 ** Stolen from old pfs module based on the work of 00095 ** Michael Floater: "Parametrization and smooth approximation 00096 ** of surface triangulation", Computer Aided Geometric Design, 00097 ** vol. 14, pp. 231-250, 1997. 00098 ** 00099 ** Modified: 17-Feb-2006 Alexandre A. Del Savio 00100 ** Created the function pfsProjectOn. 00101 ** This function was based on nSurfacePFS package, by 00102 ** William Lira and Antonio Miranda. 00103 ** 00104 ** Modified: 20-Feb-2006 Alexandre A. Del Savio 00105 ** Created the function pfsGetJacobian. 00106 ** This function was based on nSurfacePFS package, by 00107 ** William Lira and Antonio Miranda. 00108 ** 00109 ** Modified: 22-Feb-2006 Alexandre A. Del Savio 00110 ** Modified the function pfsGetJacobian. It passed to 00111 ** return the components of the normal vector of 00112 ** element face where is the point. 00113 ** 00114 ** Modified: 22-Feb-2006 William W. M. Lira 00115 ** Created the function pfsEval. 00116 ** This function was based on nSurfacePFS package, by 00117 ** William Lira and Antonio Miranda. 00118 ** 00119 ** Modified: 23-Feb-2006 Alexandre A. Del Savio 00120 ** Modified the function pfsAddElem. It passed to have 00121 ** a return. If there is no active surface it returns a 00122 ** false (0) status, otherwise it returns a true (1) 00123 ** status. 00124 ** 00125 ** Modified: 20-Apr-2006 Alexandre A. Del Savio 00126 ** Modified the global functions name from pfs to pfsR 00127 ** due names conflicts with nurbs_pfs.lib of Recon3D. 00128 ** 00129 ** Modified: 30-Jul-2006 Luiz F. Martha 00130 ** Created exported functions pfsItrNumLoops, pfsItrFirstLoopNode, 00131 ** pfsItrNextLoopNode. 00132 ** 00133 ** Modified: 31-Aug-2006 Luiz F. Martha 00134 ** Created exported functions pfsCompleteParSpace, pfsSetCurrElem ... 00135 ** 00136 ** Modified: 09-July-2007 Gisele Cunha Holtz 00137 ** Criada as variáveis pfs_iter e pfs_node, apenas por questões 00138 ** de facilitar a identificação da iteração e do nó quando 00139 ** ocorre um problema. 00140 ** 00141 **/ 00142 00143 #ifndef _PFS_H 00144 #define _PFS_H 00145 00146 00147 #ifdef __cplusplus 00148 extern "C" { 00149 #endif 00150 00151 /* 00152 ** --------------------------------------------------------------- 00153 ** Global definitions: 00154 */ 00155 #define PFS_SUCCESS 1 00156 #define PFS_ITERATION_END 0 00157 #define PFS_NO_SURFACE_DEFINED -1 00158 #define PFS_NON_MANIFOLD_EDGE -2 00159 #define PFS_INVERSE_INCIDENCE -3 00160 #define PFS_NON_MANIFOLD_VERTEX -4 00161 00162 int pfs_iter; 00163 int pfs_node; 00164 00165 /* 00166 ** --------------------------------------------------------------- 00167 ** Exported function: 00168 */ 00169 00182 void *pfsRInitSurf( int maxnodes, int maxelems ); 00183 00196 void pfsRActivateSurf( void *surf ); 00197 00206 void pfsRFreeSurf( void *surf ); 00207 00223 int pfsRAddNode( double x, double y, double z ); 00224 00240 int pfsRAddElem( int v0, int v1, int v2 ); 00241 00268 int pfsRCompleteSurf( void ); 00269 00284 void pfsRSolveSurfPar( int maxnumiter ); 00285 00304 void pfsCompleteParSpace( void ); 00305 00322 int pfsRItr3dBoundBox( double *xmin, double *xmax, 00323 double *ymin, double *ymax, 00324 double *zmin, double *zmax ); 00325 00340 int pfsRItrParBoundBox( double *umin, double *umax, 00341 double *vmin, double *vmax ); 00342 00354 int pfsRItrFirstElem( void ); 00355 00368 int pfsRItrNextElem( void ); 00369 00387 int pfsRItrFirst3dElem( double xmin, double xmax, 00388 double ymin, double ymax, 00389 double zmin, double zmax ); 00390 00408 int pfsRItrNext3dElem( double xmin, double xmax, 00409 double ymin, double ymax, 00410 double zmin, double zmax ); 00411 00427 int pfsRItrFirstParElem( double umin, double umax, 00428 double vmin, double vmax ); 00429 00445 int pfsRItrNextParElem( double umin, double umax, 00446 double vmin, double vmax ); 00447 00457 void pfsRSetCurrElem( void *elem ); 00458 00469 int pfsRGetElem( double x, double y, double z, void **elem ); 00470 00475 int pfsRGetLoopElem( double x, double y, double z, void **elem ); 00476 00491 int pfsRItrElemNode( int *id ); 00492 00502 void pfsRItrElemCenter( double *x, double *y, double *z ); 00503 00513 void pfsRItrElemNormal( double *nx, double *ny, double *nz ); 00514 00528 void pfsRItrElem3dBox( double *xmin, double *ymin, double *zmin, 00529 double *xmax, double *ymax, double *zmax ); 00530 00544 void pfsRItrElemParBox( double *umin, double *vmin, 00545 double *umax, double *vmax ); 00546 00554 int pfsRItrNumNodes( void ); 00555 00567 void pfsRItrNodeCoords( int id, double *x, double *y, double *z ); 00568 00580 void pfsRItrNodeNormal( int id, double *nx, double *ny, double *nz ); 00581 00595 void pfsRItrNodeJacobian( int id, 00596 double *xdu, double *ydu, double *zdu, 00597 double *xdv, double *ydv, double *zdv ); 00598 00609 void pfsRItrNodeParVals( int id, double *u, double *v ); 00610 00618 int pfsRItrNumLoops( void ); 00619 00634 int pfsRItrFirstLoopNode( int loop_id, int *id ); 00635 00657 int pfsRItrNextLoopNode( int loop_id, int ref_id, int *id ); 00658 00672 int pfsRProjectOn( double x, double y, double z, 00673 double *u, double *v ); 00674 00693 int pfsRGetJacobian( double u, double v, 00694 double *xdu, double *ydu, double *zdu, 00695 double *xdv, double *ydv, double *zdv, 00696 double *xdw, double *ydw, double *zdw ); 00697 00710 int pfsREval( double u, double v, double *x, double *y, double *z ); 00711 00712 int pfsRShot( void *init_elem, double x0, double y0, double z0, 00713 double u_shot, double v_shot, double len, 00714 void **end_elem, double *x1, double *y1, double *z1 ); 00715 #ifdef __cplusplus 00716 } 00717 #endif 00718 00719 #endif 00720