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?
Subdivide mesh into connected pieces
Re: Subdivide mesh into connected pieces
Indeed, there's no such method.
Those kind of algorithm are easy to implement, but they tend to be greedy (in terms of memory).
Those kind of algorithm are easy to implement, but they tend to be greedy (in terms of memory).
Daniel, CloudCompare admin
Re: Subdivide mesh into connected pieces
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).
in selectedCloud i add indexes of interconected points.
But I got problem: createNewMeshFromSelection returns NULL, because of code in ccMesh.cpp
What is visibilityArray ?
Why do i need it?
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);
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;
}
Why do i need it?
Re: Subdivide mesh into connected pieces
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).
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
Re: Subdivide mesh into connected pieces
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?
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?
Re: Subdivide mesh into connected pieces
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:
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());
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;
assert(tri[0]<m_associatedCloud->size() && tri[1]<m_associatedCloud->size() && tri[2]<m_associatedCloud->size());
Re: Subdivide mesh into connected pieces
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
Re: Subdivide mesh into connected pieces
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.
You can however generate two new meshes (by inverting the visibility info between each) then delete the original mesh.
Daniel, CloudCompare admin