50 #include "ComponentsPlugin.hh" 52 #include <MeshTools/MeshInfoT.hh> 61 emit setSlotDescription(
"splitComponents(int)",
"Split the mesh into connected components. The original mesh is deleted.",
62 QStringList(
"objectId"), QStringList(
"Id of an object"));
64 emit setSlotDescription(
"biggestComponent(int)",
"Get the biggest component and delete the smaller ones.",
65 QStringList(
"objectId"),QStringList(
"Id of an object"));
78 emit log(
LOGERR,
"Unable to get object");
82 QFileInfo fi(obj->
name());
88 emit log(
LOGERR,
"Unable to get mesh");
92 int components = MeshInfo::componentCount( mesh );
97 newIDs.push_back( _objectId );
103 QString currentName = obj->
name();
104 QString extension = currentName.section(
'.', -1);
105 currentName = currentName.section(
'.',0,-2);
108 obj->
setName(currentName+
"_component_"+QString::number(0)+
"."+extension);
111 for(
int i=0; i < components-1; i++){
115 emit copyObject(obj->
id(), id);
118 emit log(
LOGERR,
"Unable to generate a copy of object " + QString::number(obj->
id()) );
125 curObj->
setName(currentName+
"_component_"+QString::number(i+1)+
"."+extension);
129 if ( curMesh == 0 ) {
130 emit log(
LOGERR,
"Unable to get mesh");
137 newIDs.push_back(
id);
142 for (uint i=0; i < newIDs.size(); i++)
152 emit log(
LOGERR,
"Unable to get mesh");
156 int components = MeshInfo::componentCount( mesh );
159 std::vector< int > newIDs;
161 if (components == 1){
162 newIDs.push_back( _objectId );
166 QString currentName = obj->
name();
167 QString extension = currentName.section(
'.', -1);
168 currentName = currentName.section(
'.',0,-2);
171 obj->
setName(currentName+
"_component_"+QString::number(0)+
"."+extension);
173 for(
int i=0; i < components-1; i++){
177 emit copyObject(obj->
id(), id);
180 emit log(
LOGERR,
"Unable to generate a copy of object " + QString::number(obj->
id()) );
187 curObj->
setName(currentName+
"_component_"+QString::number(i+1)+
"."+extension);
191 if ( curMesh == 0 ) {
192 emit log(
LOGERR,
"Unable to get mesh");
199 newIDs.push_back(
id);
204 for (uint i=0; i < newIDs.size(); i++)
212 emit log(
LOGERR,
"Splitting into components currently only supported for meshes");
224 emit log(
LOGERR,
"Unable to get object");
void biggestComponent(QMouseEvent *_event)
Split into Components Button was hit.
void deleteUnselectedFaces(MeshT *_mesh)
Deletes all faces of a mesh that are not selected.
bool getObject(int _identifier, BSplineCurveObject *&_object)
PolyMesh * polyMesh(BaseObjectData *_object)
Get a poly mesh from an object.
bool dataType(DataType _type) const
void splitComponent(MeshT *_mesh, MeshT *_copy)
Split mesh into components.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
void setDescriptions()
set scripting slot descriptions
std::vector< int > IdList
Standard Type for id Lists used for scripting.
QString name() const
return the name of the object. The name defaults to NONAME if unset.
void selectBiggestComponent(MeshT *_mesh)
Select the biggest component of the mesh.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
#define DATA_TRIANGLE_MESH
void splitComponents(QMouseEvent *_event)
Split Components of picked object.
TriMesh * triMesh(BaseObjectData *_object)
Get a triangle mesh from an object.