⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 _understanding_and_traversing_acis_topology_(part_iv).htm

📁 acis说明文档
💻 HTM
📖 第 1 页 / 共 5 页
字号:
			<span class="kw7">VERTEX</span> * v = <span class="br0">&#40;</span><span class="kw7">VERTEX</span>*<span class="br0">&#41;</span> vertex_list<span class="br0">&#91;</span>i<span class="br0">&#93;</span>;&nbsp;			<span class="co1">// The vertex points to one edge bounded by the vertex.</span>			<span class="co1">// We must find the other edges by traversing coedges.</span>			<span class="kw7">EDGE</span> * first_edge = v-&gt;<span class="me3">edge</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;&nbsp;			<span class="co1">// Get the coedge pointed to by the edge.</span>			<span class="kw7">COEDGE</span> * first_coedge = first_edge-&gt;<span class="me3">coedge</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;&nbsp;			<span class="co1">// If this coedge is directed toward the vertex,</span>			<span class="co1">// get its partner which is directed away from the vertex.</span>			<span class="kw1">if</span> <span class="br0">&#40;</span>first_coedge-&gt;<span class="me3">end</span><span class="br0">&#40;</span><span class="br0">&#41;</span> == v<span class="br0">&#41;</span>				first_coedge = first_coedge-&gt;<span class="me3">partner</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;&nbsp;			<span class="co1">// Now we can easily traverse around the edges of the vertex.</span>			<span class="kw7">COEDGE</span> * c = first_coedge;			<span class="kw4">int</span> temp_num_edges = <span class="nu0">0</span>;			<span class="kw1">do</span> <span class="br0">&#123;</span>				<span class="co1">// We have an uncounted edge associated with coedge 'c'.</span>				temp_num_edges++;&nbsp;				<span class="co1">// Get c's partner.  </span>				<span class="co1">// It is directed toward the vertex.</span>				<span class="kw7">COEDGE</span> * p = c-&gt;<span class="me3">partner</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;&nbsp;				<span class="co1">// Get the next coedge.  </span>				<span class="co1">// It is directed away from the vertex.</span>				c = p-&gt;<span class="me3">next</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;&nbsp;			<span class="br0">&#125;</span> <span class="kw1">while</span> <span class="br0">&#40;</span>c&nbsp;!= first_coedge<span class="br0">&#41;</span>;			<span class="kw3">printf</span> <span class="br0">&#40;</span><span class="st0">&quot;vertex[%d] has&nbsp;%d edges<span class="es0">\n</span>&quot;</span>, i, temp_num_edges<span class="br0">&#41;</span>;		<span class="br0">&#125;</span>		<span class="kw3">printf</span> <span class="br0">&#40;</span><span class="st0">&quot;<span class="es0">\n</span>&quot;</span><span class="br0">&#41;</span>;&nbsp;		<span class="co1">// We should delete the BODY before exiting this function.</span>&nbsp;		result = api_delent <span class="br0">&#40;</span>my_body<span class="br0">&#41;</span>;		<span class="kw1">if</span> <span class="br0">&#40;</span>!result.<span class="me1">ok</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>			<span class="kw7">err_mess_type</span> err_no = result.<span class="me1">error_number</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;			<span class="kw3">printf</span> <span class="br0">&#40;</span><span class="st0">&quot;ERROR in api_delent()&nbsp;%d:&nbsp;%s<span class="es0">\n</span>&quot;</span>,				err_no, find_err_mess <span class="br0">&#40;</span>err_no<span class="br0">&#41;</span><span class="br0">&#41;</span>;			sys_error <span class="br0">&#40;</span>err_no<span class="br0">&#41;</span>;		<span class="br0">&#125;</span>&nbsp;	<span class="kw6">API_END</span>&nbsp;	<span class="kw1">if</span> <span class="br0">&#40;</span>!result.<span class="me1">ok</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>		<span class="kw7">err_mess_type</span> err_no = result.<span class="me1">error_number</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;		<span class="kw3">printf</span> <span class="br0">&#40;</span><span class="st0">&quot;ERROR in do_something()&nbsp;%d:&nbsp;%s<span class="es0">\n</span>&quot;</span>,			err_no, find_err_mess <span class="br0">&#40;</span>err_no<span class="br0">&#41;</span><span class="br0">&#41;</span>;	<span class="br0">&#125;</span>	<span class="kw1">else</span> 		<span class="kw3">printf</span> <span class="br0">&#40;</span><span class="st0">&quot;do_something() completed successfully!<span class="es0">\n</span><span class="es0">\n</span>&quot;</span><span class="br0">&#41;</span>;&nbsp;<span class="br0">&#125;</span>&nbsp;<span class="kw4">int</span> my_initialization<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>&nbsp;	<span class="co1">// Start ACIS.</span>	<span class="kw5">outcome</span> result = api_start_modeller<span class="br0">&#40;</span><span class="nu0">0</span><span class="br0">&#41;</span>;	<span class="kw1">if</span> <span class="br0">&#40;</span>!result.<span class="me1">ok</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>		<span class="kw7">err_mess_type</span> err_no = result.<span class="me1">error_number</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;		<span class="kw3">printf</span> <span class="br0">&#40;</span><span class="st0">&quot;ERROR in api_start_modeller()&nbsp;%d:&nbsp;%s<span class="es0">\n</span>&quot;</span>,			err_no, find_err_mess <span class="br0">&#40;</span>err_no<span class="br0">&#41;</span><span class="br0">&#41;</span>;		<span class="kw1">return</span> err_no;	<span class="br0">&#125;</span>&nbsp;	<span class="co1">// Call the licensing function to unlock ACIS.</span>	unlock_spatial_products_&lt;NNN&gt; <span class="br0">&#40;</span><span class="br0">&#41;</span>;&nbsp;	<span class="co1">// Initialize all necessary components. </span>	result = api_initialize_constructors<span class="br0">&#40;</span><span class="br0">&#41;</span>;	<span class="kw1">if</span> <span class="br0">&#40;</span>!result.<span class="me1">ok</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>		<span class="kw7">err_mess_type</span> err_no = result.<span class="me1">error_number</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;		<span class="kw3">printf</span> <span class="br0">&#40;</span><span class="st0">&quot;ERROR in api_initialize_constructors()&nbsp;%d:&nbsp;%s<span class="es0">\n</span>&quot;</span>,			err_no, find_err_mess <span class="br0">&#40;</span>err_no<span class="br0">&#41;</span><span class="br0">&#41;</span>;		<span class="kw1">return</span> err_no;	<span class="br0">&#125;</span>&nbsp;	<span class="kw1">return</span> <span class="nu0">0</span>;<span class="br0">&#125;</span>&nbsp;<span class="kw4">int</span> my_termination<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>	<span class="co1">// Terminate all necessary components. </span>	<span class="kw5">outcome</span> result = api_terminate_constructors<span class="br0">&#40;</span><span class="br0">&#41;</span>;	<span class="kw1">if</span> <span class="br0">&#40;</span>!result.<span class="me1">ok</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>		<span class="kw7">err_mess_type</span> err_no = result.<span class="me1">error_number</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;		<span class="kw3">printf</span> <span class="br0">&#40;</span><span class="st0">&quot;ERROR in api_terminate_constructors()&nbsp;%d:&nbsp;%s<span class="es0">\n</span>&quot;</span>,			err_no, find_err_mess <span class="br0">&#40;</span>err_no<span class="br0">&#41;</span><span class="br0">&#41;</span>;		<span class="kw1">return</span> err_no;	<span class="br0">&#125;</span>&nbsp;	<span class="co1">// Stop ACIS and release any allocated memory.</span>	result = api_stop_modeller<span class="br0">&#40;</span><span class="br0">&#41;</span>;	<span class="kw1">if</span> <span class="br0">&#40;</span>!result.<span class="me1">ok</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>		<span class="kw7">err_mess_type</span> err_no = result.<span class="me1">error_number</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;		<span class="kw3">printf</span> <span class="br0">&#40;</span><span class="st0">&quot;ERROR in api_stop_modeller()&nbsp;%d:&nbsp;%s<span class="es0">\n</span>&quot;</span>,			err_no, find_err_mess <span class="br0">&#40;</span>err_no<span class="br0">&#41;</span><span class="br0">&#41;</span>;		<span class="kw1">return</span> err_no;	<span class="br0">&#125;</span>&nbsp;	<span class="kw1">return</span> <span class="nu0">0</span>;<span class="br0">&#125;</span></pre><a name="Discussion"></a><h3> <span class="mw-headline"> Discussion </span></h3><p>The first thing that should be apparent in this example is we added some new header files.We added api.hxx to define the API_BEGIN and API_END macros.  We added cstrapi.hxx because the API function to generate a block, api_make_cuboid( ), is in the constructors components not in the kernel.  We added alltop.hxx and get_top.hxx to provide the definitions of the topological entities and the global topological traversal functions.  And we added lists.hxx to provide the definition of the ENTITY_LIST class.</p><p>The next thing to notice is that instead of initializing and terminating the kernel component,we initialized and terminated the constructors component.  This is the only difference in our initialization and termination functions.  The reason for this is because be used an API function in the constructors component to create a block.</p><p>So, this leaves us with the do_something( ) function.  You will notice that the majority of the function is contained within the API_BEGIN and API_END statements.  We will describe these macros in much more depth in <a href="/r18/index.php/Tutorial:ACIS_Tutorial_10:_Dabbling_in_ACIS_History_Streams" title="Tutorial:ACIS Tutorial 10: Dabbling in ACIS History Streams"> Tutorial 10: Dabbling in ACIS history streams</a>, so for now let's just say that they provide us with exception handling capabilities and they cause all of the model changes to be recorded using the ACIS history mechanism.  Any errors that are propagated within the API_BEGIN/API_END block will be caught by the API_END statement.  (We are intentionally being vague about the mechanism for propagating errors, because the implementation of these macros may vary from release to release and depends upon on platforms and compilers.)  Within the API_BEGIN/API_END block we use the sys_error( ) function to propagate an error.  After sys_error( ) is called the processing of this function resumes after the API_END statement.  </p><p>So, what happens between the API_BEGIN and API_END statements?  The function begins by constructing a block with dimensions 10x10x10.  If the block construction fails we print an error message and effectively abort the algorithm.  (You can observe what happens in the event of an error by passing in an invalid value for one of the block's dimensions.  For instance, modify one of the dimensions of the block to be -1.0 and rerun the test application.  What happens?)  </p><p>After constructing our block we then use the global topological traversal functions to obtain lists of the lumps, shells, wires, faces, edges, and vertices of the block.  We report the number of each of these classes of objects by determining the size of each of the lists. </p><p>Next we demonstrate the traversal of the list of faces using the ENTITY_LIST index operator.  For each face in the list we determine how many edges it has by obtaining a list of edges and reporting its size.  </p><p>Following this we demonstrate the traversal of the list of edges using the init( ) and next( ) methods.  For each edge in the list we determine how many faces it has by obtaining a list of faces and reporting its size.  </p><p>This is followed by counting the coedges on each face.  This is done by traversing each face's singly-linked list of loops and each loop's doubly-linked list of coedges. (We simply follow the coedges' "next" pointers until we return to the coedge we started with.)</p><div class="floatright"><span><a href="/r18/index.php/Image:Tutorial3_Example1.jpg" class="image" title="Tutorial3 Example1.jpg"><img alt="" src="/r18/images/thumb/8/83/Tutorial3_Example1.jpg/300px-Tutorial3_Example1.jpg" width="300" height="242" border="0" /></a></span></div><p>The final traversal demonstration counts the number of edges connected to each vertex of the block.  This traversal algorithm makes several assumptions.  We assume (1) there are no non-manifold edges, (2) there are no non-manifold vertices, and (3) there are no closed edges.  These are all true for the block which we are traversing.  The topology at each vertex looks similar to what is shown in the diagram to the right.   As you can see from this diagram we can traverse the coedges by simply following "partner" and "next" pointers.  Given that we can traverse the coedges around each vertex, and we can easily obtain the edge from each coedge, we can thereby gather all the edges around each vertex.   </p><p>Before exiting the function we "delete" the block.  We will discuss memory allocations and de-allocations more thoroughly in <a href="/r18/index.php/Tutorial:ACIS_Tutorials_%28Memory_Management%29" title="Tutorial:ACIS Tutorials (Memory Management)">Tutorials (Memory Management)</a>.</p><a name="Example_2"></a><h2> <span class="mw-headline"> Example 2 </span></h2><p>In the second example we shall restore a wire body from a file and traverse its topology to count the number of edges, coedges, and vertices.  This example also demonstrates how to generate a debug file containing a dump of the ACIS data structure.</p><a name="Example_code_2"></a><h3> <span class="mw-headline"> Example code </span></h3><pre class="source-cpp"><span class="kw2">#include</span> &lt;stdio.<span class="me1">h</span>&gt;<span class="kw2">#include</span> <span class="st0">&quot;acis.hxx&quot;</span><span class="kw2">#include</span> <span class="st0">&quot;api.hxx&quot;</span><span class="kw2">#include</span> <span class="st0">&quot;api.err&quot;</span><span class="kw2">#include</span> <span class="st0">&quot;kernapi.hxx&quot;</span><span class="kw2">#include</span> <span class="st0">&quot;lists.hxx&quot;</span><span class="kw2">#include</span> <span class="st0">&quot;alltop.hxx&quot;</span><span class="kw2">#include</span> <span class="st0">&quot;get_top.hxx&quot;</span><span class="kw2">#include</span> <span class="st0">&quot;debug.hxx&quot;</span>&nbsp;<span class="co1">// Declaration of the ACIS licensing function.</span><span class="kw4">void</span> unlock_spatial_products_963<span class="br0">&#40;</span><span class="br0">&#41;</span>;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -