Ejemplo n.º 1
0
bool AutoSegmentationTools::extractConnectedComponents(GenericIndexedCloudPersist* theCloud, ReferenceCloudContainer& cc)
{
	unsigned numberOfPoints = (theCloud ? theCloud->size() : 0);
	if (numberOfPoints == 0)
	{
		return false;
	}

	//components should have already been labeled and labels should have been stored in the active scalar field!
	if (!theCloud->isScalarFieldEnabled())
	{
		return false;
	}

	//empty the input vector if necessary
	while (!cc.empty())
	{
		delete cc.back();
		cc.pop_back();
	}

	for (unsigned i = 0; i < numberOfPoints; ++i)
	{
		ScalarType slabel = theCloud->getPointScalarValue(i);
		if (slabel >= 1) //labels start from 1! (this test rejects NaN values as well)
		{
			int ccLabel = static_cast<int>(theCloud->getPointScalarValue(i)) - 1;

			//we fill the components vector with empty components until we reach the current label
			//(they will be "used" later)
			try
			{
				while (static_cast<size_t>(ccLabel) >= cc.size())
				{
					cc.push_back(new ReferenceCloud(theCloud));
				}
			}
			catch (const std::bad_alloc&)
			{
				//not enough memory
				cc.clear();
				return false;
			}

			//add the point to the current component
			if (!cc[ccLabel]->addPointIndex(i))
			{
				//not enough memory
				while (!cc.empty())
				{
					delete cc.back();
					cc.pop_back();
				}
				return false;
			}
		}
	}

	return true;
}
Ejemplo n.º 2
0
//extrait les composantes connexes d'un nuage
//--> version avec des ReferenceCloud (uniquement des références vers les points)
//pour permettre une récupération au niveau de l'application cliente
//des couleurs, normales, etc.
bool AutoSegmentationTools::extractConnectedComponents(GenericIndexedCloudPersist* theCloud, ReferenceCloudContainer& cc)
{
	if (!theCloud)
		return false;
	unsigned numberOfPoints = theCloud->size();
	if (numberOfPoints<1)
		return false;

	//on admet que "labelConnectedComponents" a bien déjà été appelé
	//les labels des CCs sont alors stockées dans le champ scalaire "courant"
	cc.clear();

	//theCloud->placeIteratorAtBegining();
	for (unsigned i=0;i<numberOfPoints;++i)
	{
		int ccLabel=(int)theCloud->getPointScalarValue(i)-1; //les labels commencent à 1 !

		//on remplit le vecteur de "CCs" vides jusqu'à arriver au bon numéro de CC
		//on s'occupera en théorie des autres plus tard
		while (ccLabel>=(int)cc.size())
			cc.push_back(new ReferenceCloud(theCloud));

		//on rajoute le point à la CC courante
		cc[ccLabel]->addPointIndex(i);
	}

	return true;
}