Home
Reply
Visitor
Zura
Posts: 3

SIMPLE_INDEXED_MESH_MENEGER

[ Edited ]

I don't know how to access mesh data when using SIMPLE_INDEXED_MESH_MANAGER

Spatial Employee
asdf
Posts: 30

Re: SIMPLE_INDEXED_MESH_MENEGER

[ Edited ]

Hi

 

Please see http://doc.spatial.com/index.php/Faceter_Operations#Other_Functions for some same code regarding how to use the mesh once it is output.

 

By the way: using the faceter is a lot simpler if you don't try to write you own mesh manager.  Unless you have specialized requirements which cannot be met using the INDEXED_MESH_MANAGER, we recommend using that.

 

hope this helps

 

Eric Zenk

Visitor
Zura
Posts: 3

Re: SIMPLE_INDEXED_MESH_MENEGER

I need to get points and vectors as simple x,y,z arrays that could be directly fed to OpenGL (also triangle indices). The only manager that provides data in this format is SIMPLE_MESH_MANAGER, am I wrong?

My problem is, I don't get how to get reference to the SIMPLE_MESH after facetting.

Spatial Employee
asdf
Posts: 30

Re: SIMPLE_INDEXED_MESH_MENEGER

No, actually any reasonable mesh manager will give you that information. Do you need the normals at the facet points as well? You will if you want to use shading, otherwise not. To facet a model with acis and get the data in the format you require I recommend the following. 1. Use api_set_mesh_manager to set the mesh manager to an indexed mesh manager. 2. Call api_facet_entity on the body of interest. 3. Use code like the code shown below to extract the triangles from the face's mesh #include "stdio.h" #include "kernapi.hxx" #include "af_api.hxx" #include "fct_utl.hxx" #include "face.hxx" void get_triangles_from_faceted_face( FACE* f , float*& points, int*& triangles //, double*& normals // uncomment if you need normals too ) { SEQUENTIAL_MESH* mesh = GetSequentialMesh( f ); int num_nodes = mesh->get_num_node(); int num_polynodes = mesh->get_num_polynode(); int num_polygons = mesh->get_num_polygon(); points = ACIS_NEW float[ 3*num_nodes ]; // three position coordinates for each point in the mesh. //normals = ACIS_NEW double[ 3*num_nodes]; //uncomment if you need normals. triangles = ACIS_NEW int[ 3*num_polygons]; // three indices into points array for each triangle MESH_NODE meshNode; if (mesh->get_first_node(meshNode)) { for (int ii = 0; ii < num_nodes; ii++) { const SPAposition& pos = mesh->get_position(meshNode); points[ii*3+0] = (float)pos.x(); points[ii*3+1] = (float)pos.y(); points[ii*3+2] = (float)pos.z(); // uncomment the following double commented lines if you need normals too. ////const SPAunit_vector& norm = mesh->get_normal( meshNode ); ////normals[ii*3+0] = norm.x(); ////normals[ii*3+1] = norm.y(); ////normals[ii*3+2] = norm.z(); logical ok = mesh->get_next_node(meshNode); } } MESH_POLYGON meshPolygon; logical ok = mesh->get_first_polygon(meshPolygon); int polyIdx = 0; int current_array_index = 0; while (polyIdx < num_polygons) { polyIdx++; // grab the polygon and find out how many vertices it has. int numNodes = mesh->get_num_polynode(meshPolygon); if( numNodes != 3 ) continue; // The next "numNodes" entries are indices into the "points" array. MESH_POLYNODE meshPolynode; logical first_polynode_ok = mesh->get_first_polynode(meshPolygon, meshPolynode); for (int jj = 0; jj < numNodes ; jj++ ) { int index = mesh->get_node_index(meshPolynode); triangles[current_array_index++] = index; } logical next_polynode_ok =mesh->get_next_polygon(meshPolygon); } }
Spatial Employee
asdf
Posts: 30

Re: SIMPLE_INDEXED_MESH_MENEGER

Sorry, on my first post the example code got poorly formatted. To answer your more specific question, you need af_query or GetSequentialMesh to get a mesh attribute from an already faceted face.
#include "af_api.hxx"
#include "fct_util.hxx"
#include "face.hxx"
void get_triangles_from_faceted_face( FACE* f , float*& points, int*& triangles
									 //, double*& normals // uncomment if you need normals too
									 )
{
	SEQUENTIAL_MESH* mesh = GetSequentialMesh( f );

	int num_nodes = mesh->get_num_node();
	int num_polynodes = mesh->get_num_polynode();
	int num_polygons = mesh->get_num_polygon();

	points = ACIS_NEW float[ 3*num_nodes ]; // three position coordinates for each point in the mesh.
	//normals = ACIS_NEW double[ 3*num_nodes]; //uncomment if you need normals.
	triangles = ACIS_NEW int[ 3*num_polygons]; // three indices into points array for each triangle

	MESH_NODE meshNode;
	if (mesh->get_first_node(meshNode))
	{
		for (int ii = 0; ii < num_nodes; ii++) 
		{
			const SPAposition& pos = mesh->get_position(meshNode);

			points[ii*3+0] = (float)pos.x();
			points[ii*3+1] = (float)pos.y();
			points[ii*3+2] = (float)pos.z();

			// uncomment the following double commented lines if you need normals too.
			////const SPAunit_vector& norm = mesh->get_normal( meshNode );

			////normals[ii*3+0] = norm.x();
			////normals[ii*3+1] = norm.y();
			////normals[ii*3+2] = norm.z();

			logical ok = mesh->get_next_node(meshNode);
		}
	}

	MESH_POLYGON meshPolygon;
	logical ok = mesh->get_first_polygon(meshPolygon);

	int polyIdx = 0;
	int current_array_index = 0;
	while (polyIdx < num_polygons)
	{
		polyIdx++;
		// grab the polygon and find out how many vertices it has.
		int numNodes = mesh->get_num_polynode(meshPolygon);
		if( numNodes != 3 )
			continue;

		// The next "numNodes" entries are indices into the "points" array.
		MESH_POLYNODE meshPolynode;
		logical first_polynode_ok = mesh->get_first_polynode(meshPolygon, meshPolynode);

		for (int jj = 0; jj < numNodes ; jj++ ) 
		{
			int index = mesh->get_node_index(meshPolynode);
			triangles[current_array_index++] = index;
		}

		logical next_polynode_ok =mesh->get_next_polygon(meshPolygon);
	}
}
Visitor
Zura
Posts: 3

Re: SIMPLE_INDEXED_MESH_MENEGER

My problem is, I'm working with huge meshes with millions of elements. Using INDEXED_MESH_MANAGER means that data is stored 2 times, once in a heap and once in my own arrays. It also takes about significant (in my context) time for the mentioned amount of data to be converted into arrays.

Wouldn't using SIMPLE_INDEXED_MESH and SIMPLE_INDEXED_MESH_MANAGER avoid mentioned overhead?

Spatial Employee
gweedo
Posts: 7

Re: SIMPLE_INDEXED_MESH_MENEGER

The SIMPLE_INDEXED_MESH_MANAGER is a very old piece of code, but still viable for reasons you stated. It is missing information that can be used for texture mapping and color strips/fans, but it is rather memory efficient.  I would access this mesh by wrapping the mesh manager, then expose the data through a public method or attach the mesh to the FACE. Since you whould facet the whole body in one API call, accessing the mesh through attributes on th FACEs may be easier.  Try the following...

 

    class MY_MESH_MANAGER : public SIMPLE_INDEXED_MESH_MANAGER
    {
    public:
        virtual void end_mesh_output( ENTITY *entity, ENTITY *app_ref, ENTITY *format)
        {
            SIMPLE_INDEXED_MESH_MANAGER::end_mesh_output( entity, app_ref, format );
            if ( mesh )
            {
                af_update( entity, MY_MESH_APP_ID, MY_MESH_USER_ID, mesh );
            }
        }
    };

 

 

Then access the data as follows...

 

        MESH * face_mesh = NULL;
        af_query( (ENTITY*)face, MY_MESH_APP_ID, MY_MESH_USER_ID, face_mesh );
        if ( face_mesh != NULL )
        {
            SIMPLE_INDEXED_MESH * mesh = (SIMPLE_INDEXED_MESH*) face_mesh;
            // For every facet (or polygon) ...
            for ( int polygon_index = 0; polygon_index < mesh->get_npoly(); polygon_index++ )

            {
                for ( int polynode_index = 0; polynode_index < mesh->get_npolynode( polygon_index ); polynode_index++ )
                {
                    const SPAposition & pos = mesh->get_position( mesh->get_polynode( polygon_index, polynode_index ) );
                }
            }
        }

What you may need is your own mesh manager.  You could store data as floats instead of doubles, store exactly what you need as you want it stored, or feed data directly to your renderer, or whatever.  Please watch this posting, and I will try to reply with a sample mesh manager you can use and modify to your liking.

 

 

Spatial Employee
gweedo
Posts: 7

Re: SIMPLE_INDEXED_MESH_MENEGER

Here is a link to an example of creating your own mesh manager.

http://doc.spatial.com/index.php/Mesh_Manager_Example

 

You may modify this example code to your needs.  For instance, you may not want the mesh attached as an attribute to faces, or you may need paramtric UV values for texture mapping.

 

FYI:  There are three types of meshes that the ACIS Faceter produces:

1. Coordinate polygon. Very simple, it returns coordinates and other info for every facet. This means that it repeats coordnates

2. Indexed mesh.  This is more efficient than coordinate polygon, and is what the example demonstrates.

3. Global mesh.  This is one mesh for the whole body, not just individual faces. Nodes are shared between faces.