Triangulating 3D solids.

Triangulating 3D solids.

Anonymous
Not applicable
2,841 Views
7 Replies
Message 1 of 8

Triangulating 3D solids.

Anonymous
Not applicable

Hello,

I am trying to triangulate solids with object arx.

I am trying to do in two ways, and they differ. I would like to use acdbGetObjectMesh, however i am getting different results.

 

Code 1.

bool getMesh(ap::STrng& mesh, const AcDb3dSolid* solid)
{
AcArray<AcGePoint3d> vs;
AcArray<Adesk::Int32> is;
AcGiFaceData* fs = nullptr;
AcDbFaceterSettings set = {};
AcDbExtents ext = {};

ThrowIfFailed(solid->getGeomExtents(ext));
const AcGeVector3d dir = ext.maxPoint() - ext.minPoint();
set.faceterMeshType = 2;
set.faceterMaxEdgeLength = dir.length() * 0.1;

AcDb3dSolid* s = const_cast<AcDb3dSolid*>(solid);
ThrowIfFailed(acdbGetObjectMesh(s, &set, vs, is, fs));

struct Triangle
{
int32_t m_dummy;
int32_t m_i0;
int32_t m_i1;
int32_t m_i2;
};

const auto size = is.length() / sizeof(Triangle);
const Triangle* ts = reinterpret_cast<const Triangle*>(&is[0]);

for (auto i = 0; i < size; ++i)
{
const Triangle* t = ts + i;

const AcGePoint3d pa = vs[t->m_i0];
const AcGePoint3d pb = vs[t->m_i1];
const AcGePoint3d pc = vs[t->m_i2];

const D3 p0 = { pa.x, pa.y, pa.z };
const D3 p1 = { pb.x, pb.y, pb.z };
const D3 p2 = { pc.x, pc.y, pc.z };

addTr(mesh, p0, p1, p2);

return true;
}

Code2 :

 

// Description : get mesh from face
bool getMesh(ap::STrng& mesh, const AcBrFace& face)
{
AcBr::ErrorStatus returnValue = AcBr::eOk;

AcGe::EntityId entId;
if(face.getSurfaceType(entId) != AcBr::eOk)
return false;

// conditionally set the mesh controls based on surface type
AcBrMesh2dControl meshCtrl;
meshCtrl.setElementShape(AcBr::kAllTriangles);

// make the mesh filter from the topology entity and the mesh controls
const AcBrEntity* meshEnt = (AcBrEntity*)&face;
AcBrMesh2dFilter meshFilter;
meshFilter.insert(make_pair(meshEnt, (const AcBrMesh2dControl)meshCtrl));

// generate the mesh, display any errors and attempt to dump all
// generated elements (most errors are not fatal so we want to do
// the best we can with whatever subset of the face was meshed).
AcBrMesh2d faceMesh;
if(faceMesh.generate(meshFilter) != eOk)
return false;

// traverse elements (triangles)
TVectorN<D3, 3> aPt;
AcBrMesh2dElement2dTraverser meshElemTrav;
meshElemTrav.setMesh(faceMesh);
for(; !meshElemTrav.done(); meshElemTrav.next())
{
// traverse nodes (points)
AcBrElement2dNodeTraverser elemNodeTrav;
elemNodeTrav.setElement(meshElemTrav);
aPt.setSize(0);
for(; !elemNodeTrav.done(); elemNodeTrav.next())
{
AcBrNode node;
elemNodeTrav.getNode(node);
AcGePoint3d p;
node.getPoint(p);
aPt.add().setValue(p.x, p.y, p.z);
}
addTr(mesh, aPt[0], aPt[1], aPt[2]);
}
return true;
}


bool getMesh(ap::STrng& mesh, const AcDb3dSolid* solid)
{

//create brep traverser
std::unique_ptr<AcBrBrep> brep = std::make_unique<AcBrBrep>();
if(brep->set(*solid) != AcBr::eOk)
return false;
AcBrBrepFaceTraverser trav;
if(trav.setBrep(*brep.get()) != AcBr::eOk)
return false;

//traverse all faces
AcBrFace face;
while(!trav.done())
{
trav.getFace(face);
getMesh(mesh, face);
if(trav.next() != AcBr::eOk)
break;
}

return true;
}

 

and I am getting different results.

2020-07-05.png

2020-07-05 (1).png

  

 

 

 

 

0 Likes
Accepted solutions (1)
2,842 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable

It looks like that acdbGetObjectMesh misses back faces or something else

0 Likes
Message 3 of 8

tbrammer
Advisor
Advisor

Have you tried to set up a reduced sample that shows different results?

Did you analyze the differences? Are really faces missing? Or does the order of points or the normal of faces differ?

If your 3DSOLID contains non-planar surfaces or surfaces with curved boundaries the result depends upon the precision and other AcDbFaceterSettings/AcBrMesh2dControl settings.

 


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 4 of 8

waseefur.rahman
Advocate
Advocate

Hi Stefan,

 

This Thread might help..!!

0 Likes
Message 5 of 8

tbrammer
Advisor
Advisor

@waseefur.rahman wrote:

This Thread might help..!!


Wrong link?


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 6 of 8

Anonymous
Not applicable

No, these links do not help.

If i triangulate with MeshOptions dialog a solid I get the results that i want,

If I use acdbGetObjectMesh api, i do not.

 

 

0 Likes
Message 7 of 8

Anonymous
Not applicable

Mesh Options Dialog what api uses internally ?

 

0 Likes
Message 8 of 8

Anonymous
Not applicable
Accepted solution

const auto size = is.length() / 4;

This fixes the issue,

Number of triangles were wrong before.

0 Likes