Fix the case of the only section without points

This commit is contained in:
skv 2014-09-30 19:45:14 +04:00
parent 4033cfe508
commit 302d0ca95c

View File

@ -34,45 +34,41 @@
void GEOMImpl_IPolyline2D::SetCoords void GEOMImpl_IPolyline2D::SetCoords
(const std::list <std::list <double> > &theValue) (const std::list <std::list <double> > &theValue)
{ {
// Compute the total number of points and fill the array of start indices. const Standard_Integer aNbSec = theValue.size();
Standard_Integer i;
const Standard_Integer aNbSec = theValue.size();
Standard_Integer aNbCoords = 0;
Handle(TColStd_HArray1OfInteger) anIndices;
std::list <std::list <double> >::const_iterator aSecIter;
if (aNbSec == 1) { if (aNbSec > 0) {
// There is only one section. // Compute the total number of points and fill the array of start indices.
aNbCoords = theValue.front().size(); Standard_Integer i;
} else { Standard_Integer aNbCoords = 0;
// Here we assume that there are more than one section. Handle(TColStd_HArray1OfInteger) anIndices =
anIndices = new TColStd_HArray1OfInteger(1, aNbSec - 1); new TColStd_HArray1OfInteger(1, aNbSec);
aSecIter = theValue.begin(); Handle(TColStd_HArray1OfReal) aCoords;
aNbCoords += aSecIter->size(); std::list <std::list <double> >::const_iterator aSecIter = theValue.begin();
for (i = 1, ++aSecIter; aSecIter != theValue.end(); ++aSecIter, ++i) { for (i = 1; aSecIter != theValue.end(); ++aSecIter, ++i) {
anIndices->SetValue(i, aNbCoords + 1); anIndices->SetValue(i, aNbCoords + 1);
aNbCoords += aSecIter->size(); aNbCoords += aSecIter->size();
} }
}
// Fill the array of coordinates. if (aNbCoords > 0) {
Handle(TColStd_HArray1OfReal) aCoords = // Fill the array of coordinates.
new TColStd_HArray1OfReal(1, aNbCoords); std::list<double>::const_iterator aCIter;
std::list<double>::const_iterator aCIter;
aSecIter = theValue.begin(); aCoords = new TColStd_HArray1OfReal(1, aNbCoords);
aSecIter = theValue.begin();
for (i = 1; aSecIter != theValue.end(); ++aSecIter) { for (i = 1; aSecIter != theValue.end(); ++aSecIter) {
for (aCIter = aSecIter->begin(); aCIter != aSecIter->end(); ++aCIter) { for (aCIter = aSecIter->begin(); aCIter != aSecIter->end(); ++aCIter) {
aCoords->SetValue(i++, *aCIter); aCoords->SetValue(i++, *aCIter);
}
}
} }
}
// Store the coordinates. // Store the coordinates.
_func->SetRealArray(POLY_ARG_COORDS, aCoords); if (aCoords.IsNull() == Standard_False) {
_func->SetRealArray(POLY_ARG_COORDS, aCoords);
}
if (anIndices.IsNull() == Standard_False) {
_func->SetIntegerArray(POLY_ARG_START_INDICES, anIndices); _func->SetIntegerArray(POLY_ARG_START_INDICES, anIndices);
} }
} }
@ -91,35 +87,26 @@ void GEOMImpl_IPolyline2D::GetCoords(std::list <std::list <double> > &theValue)
Handle(TColStd_HArray1OfInteger) anIndices = Handle(TColStd_HArray1OfInteger) anIndices =
_func->GetIntegerArray(POLY_ARG_START_INDICES); _func->GetIntegerArray(POLY_ARG_START_INDICES);
if (aCoords.IsNull() == Standard_False) { if (anIndices.IsNull() == Standard_False) {
std::list <double> anEmptyList; const Standard_Integer aNbSec = anIndices->Length();
Standard_Integer i;
Standard_Integer iNextSec = 0;
Standard_Integer aNextSecIndex = aCoords->Upper() + 1;
if (anIndices.IsNull() == Standard_False) { // Create an empty sections.
iNextSec = anIndices->Lower(); theValue.resize(aNbSec);
aNextSecIndex = anIndices->Value(iNextSec);
}
theValue.push_back(anEmptyList); if (aCoords.IsNull() == Standard_False) {
Standard_Integer i;
Standard_Integer j;
std::list <std::list <double> >::iterator anIt = theValue.begin();
for (i = aCoords->Lower(); i <= aCoords->Upper(); ++i) { for (i = anIndices->Lower(); i <= anIndices->Upper(); ++i, ++anIt) {
// Check if it is necessary to create a new section. const Standard_Integer iCoord1 = anIndices->Value(i);
// Assume a case if there are empty sections. const Standard_Integer iCoord2 = i + 1 > anIndices->Upper() ?
while (i == aNextSecIndex) { aCoords->Upper() + 1 : anIndices->Value(i + 1);
// Create a next section.
theValue.push_back(anEmptyList);
++iNextSec;
if (iNextSec > anIndices->Upper()) { for (j = iCoord1; j < iCoord2; ++j) {
aNextSecIndex = aCoords->Upper() + 1; anIt->push_back(aCoords->Value(j));
} else {
aNextSecIndex = anIndices->Value(iNextSec);
} }
} }
theValue.back().push_back(aCoords->Value(i));
} }
} }
} }