Subdivide mesh into connected pieces

Any question about the main GUI application (frontend)
Post Reply
eimixas
Posts: 36
Joined: Thu Jan 17, 2013 8:14 am

Subdivide mesh into connected pieces

Post by eimixas »

for example i have cube and sphere in one mesh, i want to split them to separate meshes (cube in one, sphere in other).
(simple selection with polyline is not sollution for all cases)

In my algorithm i need:
to get triangles that share same vertice (has same summit). and after collecting all triangles that are connected in this way - i could move it them to other mesh.

I looked GenericMesh, GenericIndexedMesh, ccMesh - for methods i need, but could not find any similar.
Searched CCLib - no luck.

Maybe there is any already?
daniel
Site Admin
Posts: 7710
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Subdivide mesh into connected pieces

Post by daniel »

Indeed, there's no such method.

Those kind of algorithm are easy to implement, but they tend to be greedy (in terms of memory).
Daniel, CloudCompare admin
eimixas
Posts: 36
Joined: Thu Jan 17, 2013 8:14 am

Re: Subdivide mesh into connected pieces

Post by eimixas »

Yes it is gready, for mesh with ~1M triangles - i used 50M memory (with assumtion that 1 vertice could be shared between max 12 triangles).

Code: Select all

ccMesh *pMesh = static_cast<ccMesh*>(Entity);
ccGenericPointCloud *pCloud = pMesh->getAssociatedCloud();
...
CCLib::ReferenceCloud *selectedCloud = new CCLib::ReferenceCloud(pCloud);
...
ccGenericMesh *newMesh = pMesh->createNewMeshFromSelection(true, selectedCloud, pCloud);
in selectedCloud i add indexes of interconected points.
But I got problem: createNewMeshFromSelection returns NULL, because of code in ccMesh.cpp

Code: Select all

	ccGenericPointCloud::VisibilityTableType* visibilityArray = m_associatedCloud->getTheVisibilityArray();
	if (!visibilityArray || !visibilityArray->isAllocated())
	{
		//ccConsole::Error(QString("[Mesh %1] Visibility table not instantiated!").arg(getName()));
		return NULL;
	}
What is visibilityArray ?
Why do i need it?
daniel
Site Admin
Posts: 7710
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Subdivide mesh into connected pieces

Post by daniel »

The 'visibilityArray' is in fact the array used to flag 'visible/selected' vertices. The 'createNewMeshFromSelection' will create a mesh by keeping only the 'selected/visible' vertices (all triangles with at least one unselected vertex won't be exported). It's the method used after manually segmenting a mesh (verties are either inside or outside the polyline).

It's a simple byte array, with one value per point. If you want to use it you must enable it then set for each vertex either 0 (unselected/invisible) or any other value (e.g. 255, which means that the vertex is visible/selected).
Daniel, CloudCompare admin
eimixas
Posts: 36
Joined: Thu Jan 17, 2013 8:14 am

Re: Subdivide mesh into connected pieces

Post by eimixas »

I will try,
but isn't it a duplicate for second method parameter "CCLib::ReferenceCloud* selection"?

if visibility array is used - i do not need "CCLib::ReferenceCloud* selection" - right?
eimixas
Posts: 36
Joined: Thu Jan 17, 2013 8:14 am

Re: Subdivide mesh into connected pieces

Post by eimixas »

Tried with visibily array - but without selection array - works.
But with "removeSelectedVertices" - triangles are removed from current Mesh, but points are left in PointCloud, should it be removed too?

I tried to remove it manualy:

Code: Select all

	ccGenericPointCloud *deletedCloud = pCloud->createNewCloudFromVisibilitySelection(true);
	if (deletedCloud != NULL)
		delete deletedCloud;
but then i get error at ccMesh.cpp 427 line:
assert(tri[0]<m_associatedCloud->size() && tri[1]<m_associatedCloud->size() && tri[2]<m_associatedCloud->size());
daniel
Site Admin
Posts: 7710
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Subdivide mesh into connected pieces

Post by daniel »

No, you must use the 'visibilityArray' structure (the optional 'selection' and 'vertices' input are just in case you already have instantiated those structures - in order to avoid duplication - or if you want that the method use a particular point cloud). You must respect the same points order however.
Daniel, CloudCompare admin
daniel
Site Admin
Posts: 7710
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: Subdivide mesh into connected pieces

Post by daniel »

The issue here is that triangles that stay in the mesh keep their old indexes. So if you remove points, those indexes won't be valid anymore. The main issue is that vertices can be shared by multiple meshes. So in this case a single mesh don't know the others so we can't delete vertices that may be used by others...

You can however generate two new meshes (by inverting the visibility info between each) then delete the original mesh.
Daniel, CloudCompare admin
Post Reply