diff options
Diffstat (limited to 'docs/doxygen/nel/build__indoor_8cpp-source.html')
-rw-r--r-- | docs/doxygen/nel/build__indoor_8cpp-source.html | 754 |
1 files changed, 754 insertions, 0 deletions
diff --git a/docs/doxygen/nel/build__indoor_8cpp-source.html b/docs/doxygen/nel/build__indoor_8cpp-source.html new file mode 100644 index 00000000..fab34f41 --- /dev/null +++ b/docs/doxygen/nel/build__indoor_8cpp-source.html @@ -0,0 +1,754 @@ +<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> +<HTML> +<HEAD> + <TITLE>nevrax.org : docs</TITLE> + <LINK REL=stylesheet TYPE="text/css" HREF="http://www.nevrax.org/inc/css/nevrax.css"> + <link href="doxygen.css" rel="stylesheet" type="text/css"> +</HEAD> +<BODY MARGINHEIGHT="0" MARGINWIDTH="0"> + +<!-- uplinks --> +<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0> + <TR> + <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD WIDTH=140 BGCOLOR=#dddddd><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.org><b>Home</B></FONT></A> </TD> + <TD><IMG width=6 height=14 SRC="http://www.nevrax.org/inc/img/reddots.gif" ALT="#" VSPACE=2 HSPACE=2 BORDER=0 ></TD><TD VALIGN=middle> <A CLASS=uplinks HREF=http://www.nevrax.com><b>nevrax.com</B></FONT></A> </TD> + </TR> +</TABLE> + +<!-- banner Nevrax --> +<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=100%> + <TR><TD BGCOLOR="#000000" BACKGROUND="http://www.nevrax.org/inc/img/black_banner.jpg"><A HREF="http://www.nevrax.org"><IMG SRC="http://www.nevrax.org/inc/img/nevrax.gif" WIDTH="170" HEIGHT="45" BORDER=0 ALT="Nevrax" ></A></TD></TR> +</TABLE> + +<!-- main table --> +<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 height=100%> + <TR> + <TD WIDTH=16><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="10" BORDER=0 ALT=""></TD> + <TD WIDTH=140 BGCOLOR=#dddddd VALIGN=TOP ALIGN=middle><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT=""> + + <!------ Begin Box ------> + <TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 BGCOLOR=black><TR><TD><TABLE border=0 cellspacing=2 cellpadding=0 width=120><tr><TD ALIGN=middle bgcolor=black> + <FONT COLOR=white FACE="sans-serif"><B>Nevrax.org</B></FONT></TD></TR><tr><td colspan=2 bgcolor=#FFFFFF> + <TABLE cellspacing=0 cellpadding=1 border=0> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="Rubrique news"><img width=13 height=15 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-news.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/news/" TITLE="News">News</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Rubrique mail"><img width=15 height=11 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-mail.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/mail/" TITLE="Mailing list archive">Mailing-list</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Rubrique docs"><img width=14 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-docs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/docs/" TITLE="Documentation">Documentation</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="Rubrique cvs"><img width=13 height=17 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-cvs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/cvs/" TITLE="CVS Web">CVS</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Rubrique bugs"><img width=20 height=16 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-bugs.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/bugs/" TITLE="Bugtracking">Bugs</a></td></tr> + <tr><td ALIGN=middle><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="Rubrique license"><img width=18 height=12 hspace=5 border=0 src=http://www.nevrax.org/inc/img/picto-gpl.gif ALT=#></A></td><td><a class='linkbox' href="http://www.nevrax.org/GPL.php3" TITLE="License">License</a></td></tr> + </TABLE> + </TD></TR></TABLE></TD></TR></TABLE> + <!------ End Box ------> + + </TD> + <TD WIDTH=15><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="16" HEIGHT="16" BORDER=0 ALT=""></TD> + <TD ALIGN=left valign=top><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="140" HEIGHT="10" BORDER=0 ALT=""> + +<!-- title --> +<TABLE background="http://www.nevrax.org/inc/img/redline.gif" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td> +<A HREF="http://www.nevrax.org/docs/"><img src="http://www.nevrax.org/inc/img/t_docs.gif" ALT="Docs" HEIGHT=20 BORDER=0></A> +</td><td><IMG SRC="http://www.nevrax.org/inc/img/pixel.gif" WIDTH="1" HEIGHT="1" BORDER=0 ALT=""> +</td></tr></table> + + +<!-- block --> +<TABLE bgcolor="#dddddd" CELLSPACING=0 CELLPADDING=0 BORDER=0 width=100%><tr><td width=1% valign=middle><img width=6 height=14 hspace=2 vspace=2 src="http://www.nevrax.org/inc/img/reddots.gif"></TD> + <TD><B>Documentation</B></TD> + <TD ALIGN=RIGHT> </td> +</tr></table> +<!-- Generated by Doxygen 1.2.14 --> +<center> +<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="namespacemembers.html">Namespace Members</a> <a class="qindex" href="functions.html">Compound Members</a> <a class="qindex" href="globals.html">File Members</a> <a class="qindex" href="pages.html">Related Pages</a> <a class="qindexRef" doxygen="_cgi:http://www.nevrax.org/cgi-bin/nel-search.cgi" href="http://www.nevrax.org/cgi-bin/nel-search.cgi">Search</a> </center> +<hr><h1>build_indoor.cpp</h1><a href="build__indoor_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 +00007 <font class="comment">/* Copyright, 2001 Nevrax Ltd.</font> +00008 <font class="comment"> *</font> +00009 <font class="comment"> * This file is part of NEVRAX NEL.</font> +00010 <font class="comment"> * NEVRAX NEL is free software; you can redistribute it and/or modify</font> +00011 <font class="comment"> * it under the terms of the GNU General Public License as published by</font> +00012 <font class="comment"> * the Free Software Foundation; either version 2, or (at your option)</font> +00013 <font class="comment"> * any later version.</font> +00014 <font class="comment"></font> +00015 <font class="comment"> * NEVRAX NEL is distributed in the hope that it will be useful, but</font> +00016 <font class="comment"> * WITHOUT ANY WARRANTY; without even the implied warranty of</font> +00017 <font class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU</font> +00018 <font class="comment"> * General Public License for more details.</font> +00019 <font class="comment"></font> +00020 <font class="comment"> * You should have received a copy of the GNU General Public License</font> +00021 <font class="comment"> * along with NEVRAX NEL; see the file COPYING. If not, write to the</font> +00022 <font class="comment"> * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,</font> +00023 <font class="comment"> * MA 02111-1307, USA.</font> +00024 <font class="comment"> */</font> +00025 +00026 <font class="preprocessor">#include <map></font> +00027 <font class="preprocessor">#include <vector></font> +00028 +00029 <font class="preprocessor">#include "<a class="code" href="stdpacs_8h.html">stdpacs.h</a>"</font> +00030 +00031 <font class="preprocessor">#include "<a class="code" href="collision__mesh__build_8h.html">pacs/collision_mesh_build.h</a>"</font> +00032 <font class="preprocessor">#include "<a class="code" href="local__retriever_8h.html">pacs/local_retriever.h</a>"</font> +00033 <font class="preprocessor">#include "<a class="code" href="exterior__mesh_8h.html">pacs/exterior_mesh.h</a>"</font> +00034 +00035 <font class="preprocessor">#include "<a class="code" href="build__indoor_8h.html">build_indoor.h</a>"</font> +00036 +00037 <font class="keyword">using</font> <font class="keyword">namespace </font>std; +00038 <font class="keyword">using</font> <font class="keyword">namespace </font>NLMISC; +00039 +00040 <font class="keyword">namespace </font>NLPACS +00041 { +00042 +<a name="l00049"></a><a class="code" href="classNLPACS_1_1CInteriorSurface.html">00049</a> <font class="keyword">class </font>CInteriorSurface +00050 { +00051 <font class="keyword">public</font>: +<a name="l00053"></a><a class="code" href="classNLPACS_1_1CInteriorSurface.html#m0">00053</a> CCollisionMeshBuild *<a class="code" href="classNLPACS_1_1CInteriorSurface.html#m0">CollisionMeshBuild</a>; +00054 +<a name="l00056"></a><a class="code" href="classNLPACS_1_1CInteriorSurface.html#m1">00056</a> std::vector<uint32> <a class="code" href="classNLPACS_1_1CInteriorSurface.html#m1">Faces</a>; +00057 +<a name="l00059"></a><a class="code" href="classNLPACS_1_1CInteriorSurface.html#m2">00059</a> sint32 <a class="code" href="classNLPACS_1_1CInteriorSurface.html#m2">Id</a>; +00060 +<a name="l00062"></a><a class="code" href="classNLPACS_1_1CInteriorSurface.html#m3">00062</a> <a class="code" href="classNLMISC_1_1CVector.html">NLMISC::CVector</a> <a class="code" href="classNLPACS_1_1CInteriorSurface.html#m3">Center</a>; +00063 +<a name="l00065"></a><a class="code" href="classNLPACS_1_1CInteriorSurface.html#m4">00065</a> sint32 <a class="code" href="classNLPACS_1_1CInteriorSurface.html#m4">Material</a>; +00066 +00067 <font class="keyword">public</font>: +<a name="l00068"></a><a class="code" href="classNLPACS_1_1CInteriorSurface.html#a0">00068</a> CCollisionFace &<a class="code" href="classNLPACS_1_1CInteriorSurface.html#a0">getFace</a>(uint face) { <font class="keywordflow">return</font> <a class="code" href="classNLPACS_1_1CInteriorSurface.html#m0">CollisionMeshBuild</a>->Faces[<a class="code" href="classNLPACS_1_1CInteriorSurface.html#m1">Faces</a>[face]]; } +<a name="l00069"></a><a class="code" href="classNLPACS_1_1CInteriorSurface.html#a1">00069</a> CCollisionFace &<a class="code" href="classNLPACS_1_1CInteriorSurface.html#a1">getNeighbor</a>(uint face, uint edge) +00070 { +00071 <font class="keywordflow">return</font> <a class="code" href="classNLPACS_1_1CInteriorSurface.html#m0">CollisionMeshBuild</a>->Faces[<a class="code" href="classNLPACS_1_1CInteriorSurface.html#a0">getFace</a>(face).Edge[edge]]; +00072 } +00073 }; +00074 +00075 +<a name="l00082"></a><a class="code" href="classNLPACS_1_1CInteriorBorder.html">00082</a> <font class="keyword">class</font> CInteriorBorder +00083 { +00084 <font class="keyword">public</font>: +<a name="l00086"></a><a class="code" href="classNLPACS_1_1CInteriorBorder.html#m0">00086</a> std::vector<NLMISC::CVector> Vertices; +00087 +<a name="l00089"></a><a class="code" href="classNLPACS_1_1CInteriorBorder.html#m2">00089</a> sint32 Left, Right; +00090 +00091 <font class="keyword">public</font>: +00092 }; +00093 +00094 +00095 <font class="comment">// how to build interior snapping data</font> +00096 <font class="keywordtype">void</font> <a class="code" href="namespaceNLPACS.html#a15">buildSnapping</a>(CCollisionMeshBuild &cmb, CLocalRetriever &lr); +00097 +00098 +00099 <font class="comment">// how to build surfaces</font> +00100 <font class="keywordtype">void</font> <a class="code" href="namespaceNLPACS.html#a16">buildSurfaces</a>(CCollisionMeshBuild &cmb, CLocalRetriever &lr); +00101 +00102 +00103 +00104 <font class="comment">//</font> +00105 <font class="comment">// functions to build interior surfaces and borders from mesh</font> +00106 <font class="comment">//</font> +00107 +00108 <font class="comment">// how to generate connex surfaces</font> +00109 <font class="keywordtype">void</font> <a class="code" href="namespaceNLPACS.html#a17">floodFillSurfaces</a>(CCollisionMeshBuild &cmb, vector<CInteriorSurface> &surfaces) +00110 { +00111 sint32 currentId = 0; +00112 +00113 uint i; +00114 +00115 <font class="keywordflow">for</font> (i=0; i<cmb.Faces.size(); ++i) +00116 cmb.Faces[i].InternalSurface = -1; +00117 +00118 <font class="keywordflow">for</font> (i=0; i<cmb.Faces.size(); ++i) +00119 { +00120 CCollisionFace &face = cmb.Faces[i]; +00121 <font class="keywordflow">if</font> (face.Surface == CCollisionFace::ExteriorSurface || face.InternalSurface != -1) +00122 <font class="keywordflow">continue</font>; +00123 +00124 vector<uint> stack; +00125 stack.push_back(i); +00126 face.InternalSurface = currentId; +00127 +00128 surfaces.resize(surfaces.size()+1); +00129 surfaces.back().Id = currentId; +00130 surfaces.back().CollisionMeshBuild = &cmb; +00131 surfaces.back().Material = face.Material; +00132 +00133 <font class="keywordflow">while</font> (!stack.empty()) +00134 { +00135 uint pop = stack.back(); +00136 stack.pop_back(); +00137 +00138 surfaces.back().Faces.push_back(pop); +00139 CCollisionFace &popFace = cmb.Faces[pop]; +00140 +00141 uint edge, neighb; +00142 <font class="keywordflow">for</font> (edge=0; edge<3; ++edge) +00143 { +00144 <font class="keywordflow">if</font> ((neighb = popFace.Edge[edge]) != -1 && +00145 cmb.Faces[neighb].InternalSurface == -1 && +00146 cmb.Faces[neighb].Surface == popFace.Surface) +00147 { +00148 cmb.Faces[neighb].InternalSurface = currentId; +00149 stack.push_back(neighb); +00150 } +00151 } +00152 } +00153 +00154 ++currentId; +00155 } +00156 } +00157 +00158 +00159 <font class="comment">// reset the edge flags of the whole collision mesh build</font> +00160 <font class="keywordtype">void</font> <a class="code" href="namespaceNLPACS.html#a18">resetEdgeFlags</a>(CCollisionMeshBuild &cmb) +00161 { +00162 uint face, edge; +00163 +00164 <font class="keywordflow">for</font> (face=0; face<cmb.Faces.size(); ++face) +00165 <font class="keywordflow">for</font> (edge=0; edge<3; ++edge) +00166 cmb.Faces[face].EdgeFlags[edge] = <font class="keyword">false</font>; +00167 } +00168 +00169 +00170 +00171 <font class="comment">// how to generate the borders of a given surface</font> +00172 +00173 <font class="keywordtype">void</font> <a class="code" href="namespaceNLPACS.html#a19">followBorder</a>(CInteriorSurface &surface, uint first, uint edge, uint sens, vector<CVector> &vstore, <font class="keywordtype">bool</font> &loop) +00174 { +00175 CCollisionFace *current = &surface.getFace(first); +00176 CCollisionFace *next = (current->Edge[edge] == -1) ? NULL : &surface.CollisionMeshBuild->Faces[current->Edge[edge]]; +00177 current->EdgeFlags[edge] = <font class="keyword">true</font>; +00178 sint32 currentFace = surface.Faces[first]; +00179 +00180 <font class="keyword">const</font> sint32 currentSurfId = current->InternalSurface; +00181 <font class="keyword">const</font> sint32 oppositeSurfId = (next != NULL) ? next->InternalSurface : (current->Visibility[edge] ? -1 : -2); +00182 sint oedge; +00183 +00184 sint pivot = (edge+sens)%3; +00185 sint nextEdge = edge; +00186 +00187 <font class="keywordtype">bool</font> allowThis = <font class="keyword">true</font>; +00188 +00189 <font class="comment">// adds the pivot to the border and its normal</font> +00190 vstore.push_back(surface.CollisionMeshBuild->Vertices[current->V[pivot]]); +00191 +00192 <font class="keywordflow">while</font> (true) +00193 { +00194 loop = <font class="keyword">false</font>; +00195 <font class="comment">// -1 means no neighbor at all, -2 means a neighbor that is not available yet</font> +00196 sint32 thisOpposite = (next != NULL) ? next->InternalSurface : (current->Visibility[nextEdge] ? -1 : -2); +00197 <font class="keywordflow">if</font> (thisOpposite != currentSurfId && thisOpposite != oppositeSurfId || +00198 (loop = (current->EdgeFlags[nextEdge] && !allowThis))) +00199 { +00200 <font class="comment">// if reaches the end of the border, then quits.</font> +00201 <font class="keywordflow">break</font>; +00202 } +00203 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (thisOpposite == oppositeSurfId) +00204 { +00205 <font class="comment">// if the next edge belongs to the border, then go on the same element</font> +00206 current->EdgeFlags[nextEdge] = <font class="keyword">true</font>; +00207 <font class="keywordflow">if</font> (oppositeSurfId >= 0) +00208 { +00209 <font class="keywordflow">for</font> (oedge=0; oedge<3 && next->Edge[oedge]!=currentFace; ++oedge) +00210 ; +00211 <a class="code" href="debug_8h.html#a6">nlassert</a>(oedge != 3); +00212 <a class="code" href="debug_8h.html#a6">nlassert</a>(allowThis || !next->EdgeFlags[oedge]); +00213 next->EdgeFlags[oedge] = <font class="keyword">true</font>; +00214 } +00215 pivot = (pivot+sens)%3; +00216 nextEdge = (nextEdge+sens)%3; +00217 next = (current->Edge[nextEdge] == -1) ? NULL : &surface.CollisionMeshBuild->Faces[current->Edge[nextEdge]]; +00218 vstore.push_back(surface.CollisionMeshBuild->Vertices[current->V[pivot]]); +00219 } +00220 <font class="keywordflow">else</font> +00221 { +00222 <font class="comment">// if the next element is inside the surface, then go to the next element</font> +00223 <a class="code" href="debug_8h.html#a6">nlassert</a>(next->InternalSurface == currentSurfId); +00224 +00225 <font class="keywordflow">for</font> (oedge=0; oedge<3 && next->Edge[oedge]!=currentFace; ++oedge) +00226 ; +00227 <a class="code" href="debug_8h.html#a6">nlassert</a>(oedge != 3); +00228 currentFace = current->Edge[nextEdge]; +00229 current = next; +00230 pivot = (oedge+3-sens)%3; +00231 nextEdge = (oedge+sens)%3; +00232 next = (current->Edge[nextEdge] == -1) ? NULL : &surface.CollisionMeshBuild->Faces[current->Edge[nextEdge]]; +00233 } +00234 +00235 allowThis = <font class="keyword">false</font>; +00236 } +00237 } +00238 +00239 +00240 <font class="keywordtype">void</font> <a class="code" href="namespaceNLPACS.html#a20">computeSurfaceBorders</a>(CInteriorSurface &surface, vector<CInteriorBorder> &borders) +00241 { +00242 uint face, edge; +00243 +00244 <font class="keywordflow">for</font> (face=0; face<surface.Faces.size(); ++face) +00245 { +00246 <font class="comment">// for each element,</font> +00247 <font class="comment">// scan for a edge that points to a different surface</font> +00248 CCollisionFace &cf = surface.getFace(face); +00249 +00250 <font class="keywordflow">for</font> (edge=0; edge<3; ++edge) +00251 { +00252 <font class="keywordflow">if</font> ((cf.Edge[edge] == -1 || surface.getNeighbor(face, edge).InternalSurface != surface.Id) && +00253 !cf.EdgeFlags[edge]) +00254 { +00255 borders.resize(borders.size()+1); +00256 CInteriorBorder &<a class="code" href="driver__opengl__extension__def_8h.html#a392">border</a> = borders.back(); +00257 +00258 <a class="code" href="driver__opengl__extension__def_8h.html#a392">border</a>.Left = cf.InternalSurface; +00259 +00260 <font class="keywordflow">if</font> (cf.Edge[edge] == -1) +00261 { +00262 <font class="comment">// link on a neighbor retriever or not at all</font> +00263 <a class="code" href="driver__opengl__extension__def_8h.html#a392">border</a>.Right = cf.Visibility[edge] ? -1 : -2; +00264 } +00265 <font class="keywordflow">else</font> +00266 { +00267 <font class="comment">// link on the neighbor surface</font> +00268 <a class="code" href="driver__opengl__extension__def_8h.html#a392">border</a>.Right = surface.CollisionMeshBuild->Faces[cf.Edge[edge]].InternalSurface; +00269 } +00270 +00271 <a class="code" href="debug_8h.html#a0">nldebug</a>(<font class="stringliteral">"generate border %d (%d-%d)"</font>, borders.size()-1, <a class="code" href="driver__opengl__extension__def_8h.html#a392">border</a>.Left, <a class="code" href="driver__opengl__extension__def_8h.html#a392">border</a>.Right); +00272 +00273 <font class="keywordtype">bool</font> loop; +00274 vector<CVector> bwdVerts; +00275 vector<CVector> &fwdVerts = <a class="code" href="driver__opengl__extension__def_8h.html#a392">border</a>.Vertices; +00276 +00277 <a class="code" href="namespaceNLPACS.html#a19">followBorder</a>(surface, face, edge, 2, bwdVerts, loop); +00278 +00279 sint i; +00280 +00281 fwdVerts.reserve(bwdVerts.size()); +00282 fwdVerts.clear(); +00283 +00284 <font class="keywordflow">for</font> (i=(sint)(bwdVerts.size()-1); i>=0; --i) +00285 { +00286 fwdVerts.push_back(bwdVerts[i]); +00287 } +00288 +00289 <font class="keywordflow">if</font> (loop) +00290 { +00291 fwdVerts.push_back(fwdVerts.front()); +00292 } +00293 <font class="keywordflow">else</font> +00294 { +00295 fwdVerts.resize(fwdVerts.size()-2); +00296 <a class="code" href="namespaceNLPACS.html#a19">followBorder</a>(surface, face, edge, 1, fwdVerts, loop); +00297 } +00298 } +00299 } +00300 } +00301 } +00302 +00303 +00304 <font class="keywordtype">void</font> <a class="code" href="namespaceNLPACS.html#a21">computeSurfaceCenter</a>(CInteriorSurface &surface) +00305 { +00306 CCollisionMeshBuild &cmb = *(surface.CollisionMeshBuild); +00307 +00308 CVector center = CVector::Null; +00309 <font class="keywordtype">float</font> totalWeight = 0.0f; +00310 +00311 uint i, j; +00312 +00313 <font class="keywordflow">for</font> (i=0; i<surface.Faces.size(); ++i) +00314 { +00315 CCollisionFace &face = surface.getFace(i); +00316 CVector <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[3]; +00317 +00318 <font class="keywordflow">for</font> (j=0; j<3; ++j) +00319 <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[j] = cmb.Vertices[face.V[j]]; +00320 +00321 <font class="keywordtype">float</font> weight = ((<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[2]-<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[0])^(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[1]-<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[0])).norm(); +00322 +00323 center += (<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[0]+<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[1]+<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>[2])*(weight/3.0f); +00324 totalWeight += weight; +00325 } +00326 +00327 surface.Center = center/totalWeight; +00328 } +00329 +00330 +00331 <font class="keywordtype">void</font> <a class="code" href="namespaceNLPACS.html#a22">computeSurfaceQuadTree</a>(CInteriorSurface &surface, CSurfaceQuadTree &quad) +00332 { +00333 uint i, j; +00334 +00335 CAABBox box; +00336 <font class="keywordtype">bool</font> first = <font class="keyword">true</font>; +00337 <font class="keywordflow">for</font> (i=0; i<surface.Faces.size(); ++i) +00338 { +00339 <font class="keywordflow">for</font> (j=0; j<3; ++j) +00340 { +00341 <font class="keyword">const</font> CVector &<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a> = surface.CollisionMeshBuild->Vertices[surface.CollisionMeshBuild->Faces[surface.Faces[i]].V[j]]; +00342 <font class="keywordflow">if</font> (first) +00343 box.setCenter(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>), first=<font class="keyword">false</font>; +00344 <font class="keywordflow">else</font> +00345 box.extend(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>); +00346 } +00347 } +00348 +00349 quad.clear(); +00350 quad.init(4.0f, 6, box.getCenter(), std::max(box.getHalfSize().x, box.getHalfSize().y)); +00351 +00352 <font class="keywordflow">for</font> (i=0; i<surface.Faces.size(); ++i) +00353 { +00354 <font class="keywordflow">for</font> (j=0; j<3; ++j) +00355 { +00356 <font class="keyword">const</font> CVector &<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a> = surface.CollisionMeshBuild->Vertices[surface.CollisionMeshBuild->Faces[surface.Faces[i]].V[j]]; +00357 quad.addVertex(<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>); +00358 } +00359 } +00360 +00361 quad.compile(); +00362 } +00363 +00364 +00365 <font class="keywordtype">void</font> <a class="code" href="namespaceNLPACS.html#a16">buildSurfaces</a>(CCollisionMeshBuild &cmb, CLocalRetriever &lr) +00366 { +00367 vector<CInteriorSurface> surfaces; +00368 vector<CInteriorBorder> borders; +00369 +00370 <a class="code" href="namespaceNLPACS.html#a17">floodFillSurfaces</a>(cmb, surfaces); +00371 +00372 <a class="code" href="namespaceNLPACS.html#a18">resetEdgeFlags</a>(cmb); +00373 +00374 uint surf, bord; +00375 +00377 <font class="keywordflow">for</font> (surf=0; surf<surfaces.size(); ++surf) +00378 { +00379 CSurfaceQuadTree quad; +00380 <a class="code" href="namespaceNLPACS.html#a20">computeSurfaceBorders</a>(surfaces[surf], borders); +00381 <a class="code" href="namespaceNLPACS.html#a21">computeSurfaceCenter</a>(surfaces[surf]); +00382 <a class="code" href="namespaceNLPACS.html#a22">computeSurfaceQuadTree</a>(surfaces[surf], quad); +00383 lr.addSurface(0, 0, (uint8)surfaces[surf].<a class="code" href="classNLPACS_1_1CInteriorSurface.html#m4">Material</a>, 0, 0, <font class="keyword">false</font>, 0.0f, surfaces[surf].Center, quad); +00384 } +00385 +00386 sint numBorderChains = 0; +00387 +00388 <font class="keywordflow">for</font> (bord=0; bord<borders.size(); ++bord) +00389 { +00390 sint32 left = borders[bord].Left; +00391 sint32 right = (borders[bord].Right == -2) ? CChain::convertBorderChainId(numBorderChains++) : borders[bord].Right; +00392 +00393 <font class="keywordflow">if</font> (left<0 || left>=(sint)surfaces.size() || +00394 right>(sint)surfaces.size()) +00395 <a class="code" href="debug_8h.html#a12">nlstop</a>; +00396 +00397 lr.addChain(borders[bord].Vertices, left, right); +00398 } +00399 } +00400 +00401 +00402 <font class="comment">//</font> +00403 +00404 <font class="keywordtype">void</font> <a class="code" href="namespaceNLPACS.html#a15">buildSnapping</a>(CCollisionMeshBuild &cmb, CLocalRetriever &lr) +00405 { +00406 <font class="comment">// copy the vertices</font> +00407 lr.getInteriorVertices() = cmb.Vertices; +00408 +00409 <font class="comment">// create the faces</font> +00410 uint i; +00411 vector<CLocalRetriever::CInteriorFace> &faces = lr.getInteriorFaces(); +00412 <font class="keywordflow">for</font> (i=0; i<cmb.Faces.size(); ++i) +00413 { +00414 faces.push_back(CLocalRetriever::CInteriorFace()); +00415 faces.back().Verts[0] = cmb.Faces[i].V[0]; +00416 faces.back().Verts[1] = cmb.Faces[i].V[1]; +00417 faces.back().Verts[2] = cmb.Faces[i].V[2]; +00418 faces.back().Surface = cmb.Faces[i].InternalSurface; +00419 } +00420 +00421 <font class="comment">// create the face grid</font> +00422 lr.initFaceGrid(); +00423 } +00424 +00425 +00426 <font class="comment">//</font> +00427 <font class="comment">// functions to build local retrievers</font> +00428 <font class="comment">//</font> +00429 +00430 <font class="keywordtype">void</font> <a class="code" href="namespaceNLPACS.html#a23">buildExteriorMesh</a>(CCollisionMeshBuild &cmb, CExteriorMesh &em) +00431 { +00432 <font class="comment">// find the first non interior face</font> +00433 uint i, edge; +00434 <font class="keywordtype">bool</font> found = <font class="keyword">false</font>; +00435 <font class="keywordflow">for</font> (i=0; i<cmb.Faces.size() && !found; ++i) +00436 { +00437 <font class="keywordflow">if</font> (cmb.Faces[i].Surface != CCollisionFace::ExteriorSurface) +00438 <font class="keywordflow">continue</font>; +00439 +00440 <font class="keywordflow">for</font> (edge=0; edge<3 && !found; ++edge) +00441 <font class="keywordflow">if</font> (cmb.Faces[i].Edge[edge] == -1) +00442 { +00443 found = <font class="keyword">true</font>; +00444 <font class="keywordflow">break</font>; +00445 } +00446 +00447 <font class="keywordflow">if</font> (found) +00448 <font class="keywordflow">break</font>; +00449 } +00450 +00451 <font class="comment">//</font> +00452 <font class="keywordflow">if</font> (!found) +00453 <font class="keywordflow">return</font>; +00454 +00455 sint32 current = i; +00456 sint32 next = cmb.Faces[current].Edge[edge]; +00457 <font class="keywordflow">for</font> (i=0; i<cmb.Faces.size(); ++i) +00458 { +00459 cmb.Faces[i].EdgeFlags[0] = <font class="keyword">false</font>; +00460 cmb.Faces[i].EdgeFlags[1] = <font class="keyword">false</font>; +00461 cmb.Faces[i].EdgeFlags[2] = <font class="keyword">false</font>; +00462 } +00463 +00464 sint oedge; +00465 sint pivot = (edge+1)%3; +00466 sint nextEdge = edge; +00467 +00468 <font class="keywordtype">bool</font> allowThis = <font class="keyword">true</font>; +00469 +00470 vector<CExteriorMesh::CEdge> edges; +00471 uint numLink = 0; +00472 +00473 <font class="keywordflow">while</font> (true) +00474 { +00475 <font class="keywordflow">if</font> (cmb.Faces[current].EdgeFlags[nextEdge]) +00476 { +00477 <font class="comment">// if reaches the end of the border, then quits.</font> +00478 <font class="keywordflow">break</font>; +00479 } +00480 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (next == -1) +00481 { +00482 <font class="comment">// if the next edge belongs to the border, then go on the same element</font> +00483 cmb.Faces[current].EdgeFlags[nextEdge] = <font class="keyword">true</font>; +00485 sint link = (cmb.Faces[current].Visibility[nextEdge]) ? -1 : (numLink++); +00486 edges.push_back(CExteriorMesh::CEdge(cmb.Vertices[cmb.Faces[current].V[pivot]], link)); +00487 <a class="code" href="debug_8h.html#a0">nldebug</a>(<font class="stringliteral">"border: vertex=%d (%.2f,%.2f,%.2f) link=%d"</font>, cmb.Faces[current].V[pivot], cmb.Vertices[cmb.Faces[current].V[pivot]].x, cmb.Vertices[cmb.Faces[current].V[pivot]].y, cmb.Vertices[cmb.Faces[current].V[pivot]].z, link); +00488 pivot = (pivot+1)%3; +00489 nextEdge = (nextEdge+1)%3; +00490 next = cmb.Faces[current].Edge[nextEdge]; +00491 } +00492 <font class="keywordflow">else</font> +00493 { +00494 <font class="comment">// if the next element is inside the surface, then go to the next element</font> +00495 <font class="keywordflow">for</font> (oedge=0; oedge<3 && cmb.Faces[next].Edge[oedge]!=current; ++oedge) +00496 ; +00497 <a class="code" href="debug_8h.html#a6">nlassert</a>(oedge != 3); +00498 current = next; +00499 pivot = (oedge+2)%3; +00500 nextEdge = (oedge+1)%3; +00501 next = cmb.Faces[current].Edge[nextEdge]; +00502 } +00503 } +00504 +00505 edges.push_back(edges.front()); +00506 edges.back().Link = -1; +00507 +00508 em.setEdges(edges); +00509 } +00510 +00511 +00512 <font class="comment">//</font> +00513 <font class="keywordtype">void</font> <a class="code" href="namespaceNLPACS.html#a24">linkExteriorToInterior</a>(CLocalRetriever &lr) +00514 { +00515 CExteriorMesh em = lr.getExteriorMesh(); +00516 vector<CExteriorMesh::CEdge> edges = em.getEdges(); +00517 vector<CExteriorMesh::CLink> links; +00518 <font class="keyword">const</font> vector<CChain> &chains = lr.getChains(); +00519 <font class="keyword">const</font> vector<COrderedChain3f> &ochains = lr.getFullOrderedChains(); +00520 <font class="keyword">const</font> vector<uint16> &bchains = lr.getBorderChains(); +00521 +00522 { +00523 uint i; +00524 +00525 <font class="keywordflow">for</font> (i=0; i<bchains.size(); ++i) +00526 { +00527 <font class="keyword">static</font> <font class="keywordtype">char</font> buf[512], <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>[256]; +00528 <font class="keyword">const</font> CChain &chain = chains[bchains[i]]; +00529 sprintf(buf, <font class="stringliteral">"chain=%d "</font>, bchains[i]); +00530 uint och; +00531 <font class="keywordflow">for</font> (och=0; och<chain.getSubChains().size(); ++och) +00532 { +00533 <font class="keyword">const</font> COrderedChain3f &ochain = ochains[chain.getSubChain(och)]; +00534 sprintf(<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>, <font class="stringliteral">"subchain=%d"</font>, chain.getSubChain(och)); +00535 strcat(buf, <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>); +00536 uint <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>; +00537 <font class="keywordflow">for</font> (<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>=0; <a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a><ochain.getVertices().size(); ++<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>) +00538 { +00539 sprintf(<a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>, <font class="stringliteral">" (%.2f,%.2f)"</font>, ochain[<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>].<a class="code" href="driver__opengl__extension__def_8h.html#a364">x</a>, ochain[<a class="code" href="driver__opengl__extension__def_8h.html#a368">v</a>].<a class="code" href="driver__opengl__extension__def_8h.html#a365">y</a>); +00540 strcat(buf, <a class="code" href="driver__opengl__extension__def_8h.html#a367">w</a>); +00541 } +00542 } +00543 +00544 <a class="code" href="debug_8h.html#a1">nlinfo</a>(<font class="stringliteral">"%s"</font>, buf); +00545 } +00546 } +00547 +00548 uint edge, ch; +00549 <font class="keywordflow">for</font> (edge=0; edge+1<edges.size(); ++edge) +00550 { +00551 <font class="keywordflow">if</font> (edges[edge].Link == -1) +00552 <font class="keywordflow">continue</font>; +00553 +00554 CVector start = edges[edge].Start, stop = edges[edge+1].Start; +00555 <font class="keywordtype">bool</font> found = <font class="keyword">false</font>; +00556 +00557 <font class="keywordflow">for</font> (ch=0; ch<bchains.size() && !found; ++ch) +00558 { +00559 <font class="comment">// get the border chain.</font> +00560 <font class="comment">//const CChain &chain = chains[bchains[ch]];</font> +00561 +00562 <font class="keyword">const</font> CVector &cstart = lr.getStartVector(bchains[ch]), +00563 &cstop = lr.getStopVector(bchains[ch]); +00564 +00565 <font class="keywordtype">float</font> d = (start-cstart).norm()+(stop-cstop).norm(); +00566 <font class="keywordflow">if</font> (d < 1.0e-1f) +00567 { +00568 found = <font class="keyword">true</font>; +00569 <font class="keywordflow">break</font>; +00570 } +00571 } +00572 +00573 <font class="comment">// create a link</font> +00574 CExteriorMesh::CLink link; +00575 +00576 <font class="keywordflow">if</font> (!found) +00577 { +00578 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"in linkInteriorToExterior():"</font>); +00579 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"couldn't find any link to the exterior edge %d!!"</font>, edge); +00580 } +00581 <font class="keywordflow">else</font> +00582 { +00583 <font class="comment">// set it up to point on the chain and surface</font> +00584 link.BorderChainId = ch; +00585 link.ChainId = bchains[ch]; +00586 link.SurfaceId = (uint16)chains[link.ChainId].getLeft(); +00587 } +00588 +00589 <font class="comment">// enlarge the links</font> +00590 <font class="keywordflow">if</font> (edges[edge].Link >= (sint)links.size()) +00591 links.resize(edges[edge].Link+1); +00592 +00593 <font class="comment">// if the link already exists, warning</font> +00594 <font class="keywordflow">if</font> (links[edges[edge].Link].BorderChainId != 0xFFFF || +00595 links[edges[edge].Link].ChainId != 0xFFFF || +00596 links[edges[edge].Link].SurfaceId != 0xFFFF) +00597 { +00598 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"in linkInteriorToExterior():"</font>); +00599 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"link %d already set!!"</font>, edges[edge].Link); +00600 } +00601 +00602 <font class="comment">// setup the link</font> +00603 links[edges[edge].Link] = link; +00604 } +00605 +00606 em.setEdges(edges); +00607 em.setLinks(links); +00608 lr.setExteriorMesh(em); +00609 } +00610 +00611 +00612 +00613 +00614 +00615 <font class="comment">//</font> +00616 <font class="keywordtype">bool</font> <a class="code" href="namespaceNLPACS.html#a25">computeRetriever</a>(CCollisionMeshBuild &cmb, CLocalRetriever &lr, CVector &translation, string &error, <font class="keywordtype">bool</font> useCmbTrivialTranslation) +00617 { +00618 <font class="comment">// set the retriever</font> +00619 lr.setType(CLocalRetriever::Interior); +00620 +00621 <font class="comment">// if should use the own cmb bbox, then compute it</font> +00622 <font class="keywordflow">if</font> (useCmbTrivialTranslation) +00623 { +00624 translation = cmb.computeTrivialTranslation(); +00625 <font class="comment">// snap the translation vector to a meter wide grid</font> +00626 translation.x = (float)ceil(translation.x); +00627 translation.y = (float)ceil(translation.y); +00628 translation.z = 0.0f; +00629 } +00630 +00631 vector<string> errors; +00632 +00633 cmb.link(<font class="keyword">false</font>, errors); +00634 cmb.link(<font class="keyword">true</font>, errors); +00635 +00636 <font class="keywordflow">if</font> (!errors.empty()) +00637 { +00638 <a class="code" href="debug_8h.html#a2">nlwarning</a>(<font class="stringliteral">"Edge issues reported !!"</font>); +00639 uint i; +00640 error = <font class="stringliteral">""</font>; +00641 <font class="keywordflow">for</font> (i=0; i<errors.size(); ++i) +00642 error += errors[i]+<font class="stringliteral">"\n"</font>; +00643 <font class="keywordflow">return</font> <font class="keyword">false</font>; +00644 } +00645 +00646 <font class="comment">// translate the meshbuild to the local axis</font> +00647 cmb.translate(translation); +00648 +00649 <font class="comment">// find the exterior mesh border</font> +00650 CExteriorMesh extMesh; +00651 <a class="code" href="namespaceNLPACS.html#a23">buildExteriorMesh</a>(cmb, extMesh); +00652 lr.setExteriorMesh(extMesh); +00653 +00654 <font class="comment">// build the surfaces in the local retriever</font> +00655 <a class="code" href="namespaceNLPACS.html#a16">buildSurfaces</a>(cmb, lr); +00656 +00657 <font class="comment">// create the snapping faces and vertices</font> +00658 <font class="comment">// after the build surfaces because the InternalSurfaceId is filled within buildSurfaces()...</font> +00659 <a class="code" href="namespaceNLPACS.html#a15">buildSnapping</a>(cmb, lr); +00660 +00661 <font class="comment">//</font> +00662 lr.computeLoopsAndTips(); +00663 +00664 lr.findBorderChains(); +00665 lr.updateChainIds(); +00666 lr.computeTopologies(); +00667 +00668 lr.unify(); +00669 +00670 lr.computeCollisionChainQuad(); +00671 <font class="comment">/*</font> +00672 <font class="comment"> //</font> +00673 <font class="comment"> for (i=0; i<lr.getSurfaces().size(); ++i)</font> +00674 <font class="comment"> lr.dumpSurface(i);</font> +00675 <font class="comment">*/</font> +00676 <font class="comment">//</font> +00677 <a class="code" href="namespaceNLPACS.html#a24">linkExteriorToInterior</a>(lr); +00678 +00679 <font class="comment">// compute the bbox of the retriever</font> +00680 uint i, j; +00681 CAABBox bbox; +00682 <font class="keywordtype">bool</font> first = <font class="keyword">true</font>; +00683 +00684 <font class="keywordflow">for</font> (i=0; i<extMesh.getEdges().size(); ++i) +00685 <font class="keywordflow">if</font> (!first) +00686 bbox.extend(extMesh.getEdge(i).Start); +00687 <font class="keywordflow">else</font> +00688 bbox.setCenter(extMesh.getEdge(i).Start), first=<font class="keyword">false</font>; +00689 +00690 <font class="keywordflow">for</font> (i=0; i<lr.getOrderedChains().size(); ++i) +00691 <font class="keywordflow">for</font> (j=0; j<lr.getOrderedChain(i).getVertices().size(); ++j) +00692 <font class="keywordflow">if</font> (!first) +00693 bbox.extend(lr.getOrderedChain(i)[j].unpack3f()); +00694 <font class="keywordflow">else</font> +00695 bbox.setCenter(lr.getOrderedChain(i)[j].unpack3f()), first=<font class="keyword">false</font>; +00696 +00697 CVector bboxhs = bbox.getHalfSize(); +00698 bboxhs.z = 10000.0f; +00699 bbox.setHalfSize(bboxhs); +00700 +00701 lr.setBBox(bbox); +00702 +00703 <font class="keywordflow">return</font> <font class="keyword">true</font>; +00704 } +00705 +00706 } <font class="comment">// NLPACS</font> +</pre></div> + +<!-- footer --> +<BR><FONT Size=+5> </FONT> +</TD> +<TD WIDTH=15><IMG SRC=http://www.nevrax.org/inc/img/pixel.gif WIDTH=15 HEIGHT=15 BORDER=0 ALT=""></TD> +</TR> +</TABLE> +</BODY> +</HTML> |