Commit 893acdb1 authored by Robert Maynard's avatar Robert Maynard

Allow the user to fetch all the coordinates from a PointSet.

parent d2570608
......@@ -167,6 +167,21 @@ public:
//get all points held by this range of handle of a given dimension
virtual smtk::mesh::HandleRange getPoints(const smtk::mesh::HandleRange& cells) const = 0;
//----------------------------------------------------------------------------
//get all the coordinates for the points in this range
//xyz needs to be allocated to 3*points.size()
//Floats are not how we store the coordinates internally, so asking for
//the coordinates in such a manner could cause data inaccuracies to appear
//so generally this is only used if you fully understand the input domain
virtual bool getCoordinates(const smtk::mesh::HandleRange& points,
double* xyz) const = 0;
//----------------------------------------------------------------------------
//get all the coordinates for the points in this range
//xyz needs to be allocated to 3*points.size()
virtual bool getCoordinates(const smtk::mesh::HandleRange& points,
float* xyz) const = 0;
//----------------------------------------------------------------------------
virtual std::vector< std::string > computeNames(const smtk::mesh::HandleRange& meshsets) const = 0;
......
......@@ -96,53 +96,19 @@ std::size_t PointSet::find( const smtk::mesh::Handle& pointId ) const
return this->m_points.size();
}
// //----------------------------------------------------------------------------
// void PointSet::get(std::size_t index, double& x, double& y, double& z) const
// {
// }
// //----------------------------------------------------------------------------
// void PointSet::get(std::size_t startIndex, std::size_t endIndex, std::vector<double>& xyz) const
// {
// }
// //----------------------------------------------------------------------------
// void PointSet::get(std::size_t startIndex, std::size_t endIndex, const double* xyz) const
// {
// }
// //----------------------------------------------------------------------------
// void PointSet::set(std::size_t index, double& x, double& y, double& z)
// {
// }
// //----------------------------------------------------------------------------
// void PointSet::set(std::size_t startIndex, std::size_t endIndex, const std::vector<double>& xyz)
// {
// }
// //----------------------------------------------------------------------------
// void PointSet::set(std::size_t startIndex, std::size_t endIndex, const double* const xyz)
// {
// }
// //Floats are not how we store the coordinates internally, so asking for
// //the coordinates in such a manner could cause data inaccuracies to appear
// //so generally this is only used if you fully understand the input domain
// //----------------------------------------------------------------------------
// void PointSet::getAsFloats(std::size_t startIndex, std::size_t endIndex, std::vector<float>& xyz) const
// {
// }
// //----------------------------------------------------------------------------
// void PointSet::getAsFloats(std::size_t startIndex, std::size_t endIndex, const float* xyz) const
// {
// }
// //----------------------------------------------------------------------------
// void PointSet::setFromFloats(std::size_t startIndex, std::size_t endIndex, const std::vector<float>& xyz)
// {
// }
// //----------------------------------------------------------------------------
// void PointSet::setFromFloats(std::size_t startIndex, std::size_t endIndex, const float* const xyz)
// {
// }
//----------------------------------------------------------------------------
bool PointSet::get(double* xyz) const
{
const smtk::mesh::InterfacePtr& iface = this->m_parent->interface();
return iface->getCoordinates(this->m_points, xyz);
}
//----------------------------------------------------------------------------
bool PointSet::get(float* xyz) const
{
const smtk::mesh::InterfacePtr& iface = this->m_parent->interface();
return iface->getCoordinates(this->m_points, xyz);
}
//----------------------------------------------------------------------------
PointSet set_intersect( const PointSet& a, const PointSet& b )
......
......@@ -53,23 +53,14 @@ public:
//returns the index in this point set for the given point id
std::size_t find( const smtk::mesh::Handle& pointId ) const;
// //Get/Set a point coordinate. This interface is offered for when
// //you need
// void get(std::size_t index, double& x, double& y, double& z) const;
// void get(std::size_t startIndex, std::size_t endIndex, std::vector<double>& xyz) const;
// void get(std::size_t startIndex, std::size_t endIndex, const double* xyz) const;
// void set(std::size_t index, double& x, double& y, double& z);
// void set(std::size_t startIndex, std::size_t endIndex, const std::vector<double>& xyz);
// void set(std::size_t startIndex, std::size_t endIndex, const double* const xyz);
// //Floats are not how we store the coordinates internally, so asking for
// //the coordinates in such a manner could cause data inaccuracies to appear
// //so generally this is only used if you fully understand the input domain
// void getAsFloats(std::size_t startIndex, std::size_t endIndex, std::vector<float>& xyz);
// void getAsFloats(std::size_t startIndex, std::size_t endIndex, const float* xyz);
// void setFromFloats(std::size_t startIndex, std::size_t endIndex, const std::vector<float>& xyz);
// void setFromFloats(std::size_t startIndex, std::size_t endIndex, const float* const xyz);
//Get all the point coordinates and store them in a pre-allocated buffer
bool get(double* xyz) const;
//Get all the point coordinates and store them in a pre-allocated buffer
//Floats are not how we store the coordinates internally, so asking for
//the coordinates in such a manner could cause data inaccuracies to appear
//so generally this is only used if you fully understand the input domain
bool get(float* xyz) const;
private:
......
......@@ -547,6 +547,79 @@ smtk::mesh::HandleRange Interface::getPoints(const smtk::mesh::HandleRange& cell
return pointIds;
}
//----------------------------------------------------------------------------
bool Interface::getCoordinates(const smtk::mesh::HandleRange& points,
double* xyz) const
{
if(points.empty() )
{
return false;
}
m_iface->get_coords(points,xyz);
return true;
}
//----------------------------------------------------------------------------
bool Interface::getCoordinates(const smtk::mesh::HandleRange& points,
float* xyz) const
{
if(points.empty())
{
return false;
}
//Efficiently re-use memory when fetching a significant number of points
//this way we don't allocate a massive array of doubles, when that is most
//likely going to trash the system memory, and defeat the users goal of keeping
//memory usage low
std::vector<double> coords;
const std::size_t numPoints = points.size();
const std::size_t numPointsPerLoop =524288;
const std::size_t numLoops = numPoints / 524288;
coords.reserve(numPointsPerLoop*3);
smtk::mesh::HandleRange::const_iterator start = points.begin();
std::size_t xyz_index = 0;
for(std::size_t i=0; i < numLoops; ++i)
{
//determine where the end iterator should be
smtk::mesh::HandleRange::const_iterator end = start + numPointsPerLoop;
//needs to be insert so we use iterator insert, since we don't want
//all points between start and end values, but only those that are
//in the range. Think not 0 to N, but 0 - 10, 14 - N.
::moab::Range subset;
subset.insert(start,end);
//fetch all the coordinates for the start, end range
m_iface->get_coords( subset, &coords[0] );
for(std::size_t i=0; i < (numPointsPerLoop*3); ++i)
{
xyz[xyz_index++] = static_cast<float>(coords[i]);
}
}
std::size_t difference = numPoints - (numPointsPerLoop * numLoops);
smtk::mesh::HandleRange::const_iterator end = start + difference;
::moab::Range subset;
subset.insert(start,end);
//fetch all the coordinates for the start, end range
m_iface->get_coords( subset, &coords[0] );
for(std::size_t i=0; i < (difference*3); ++i)
{
xyz[xyz_index++] = static_cast<float>(coords[i]);
}
return true;
}
//----------------------------------------------------------------------------
std::vector< std::string > Interface::computeNames(const smtk::mesh::HandleRange& meshsets) const
{
......
......@@ -136,6 +136,21 @@ public:
//get all points held by this range of handle of a given dimension
smtk::mesh::HandleRange getPoints(const smtk::mesh::HandleRange& cells) const;
//----------------------------------------------------------------------------
//get all the coordinates for the points in this range
//xyz needs to be allocated to 3*points.size()
//Floats are not how we store the coordinates internally, so asking for
//the coordinates in such a manner could cause data inaccuracies to appear
//so generally this is only used if you fully understand the input domain
bool getCoordinates(const smtk::mesh::HandleRange& points,
double* xyz) const;
//----------------------------------------------------------------------------
//get all the coordinates for the points in this range
//xyz needs to be allocated to 3*points.size()
bool getCoordinates(const smtk::mesh::HandleRange& points,
float* xyz) const;
//----------------------------------------------------------------------------
std::vector< std::string > computeNames(const smtk::mesh::HandleRange& meshsets) const;
......
......@@ -130,6 +130,49 @@ void verify_find(const smtk::mesh::CollectionPtr& c)
}
}
//----------------------------------------------------------------------------
void verify_get(const smtk::mesh::CollectionPtr& c)
{
//this is really hard to test currently as we only have bulk gets() on
//points. So for now we are just going to make sure the function doesn't
//crash
smtk::mesh::PointSet all_points = c->points();
const std::size_t numCoords = 3 * all_points.size();
std::vector<double> coords(numCoords);
all_points.get(&coords[0]);
for(int i=0; i < smtk::mesh::CellType_MAX; ++i )
{
smtk::mesh::CellType cellType = static_cast<smtk::mesh::CellType>(i);
smtk::mesh::CellSet cells = c->cells( cellType );
test( cells.points().get(&coords[0]) != cells.is_empty() );
}
}
//----------------------------------------------------------------------------
void verify_float_get(const smtk::mesh::CollectionPtr& c)
{
//this is really hard to test currently as we only have bulk gets() on
//points. So for now we are just going to make sure the function doesn't
//crash
smtk::mesh::PointSet all_points = c->points();
const std::size_t numCoords = 3 * all_points.size();
std::vector<float> coords(numCoords);
all_points.get(&coords[0]);
for(int i=0; i < smtk::mesh::CellType_MAX; ++i )
{
smtk::mesh::CellType cellType = static_cast<smtk::mesh::CellType>(i);
smtk::mesh::CellSet cells = c->cells( cellType );
test( cells.points().get(&coords[0]) != cells.is_empty() );
}
}
//----------------------------------------------------------------------------
void verify_pointset_intersect(const smtk::mesh::CollectionPtr& c)
{
......@@ -273,6 +316,9 @@ int UnitTestPointSet(int, char**)
verify_contains(c);
verify_find(c);
verify_get(c);
verify_float_get(c);
verify_pointset_intersect(c);
verify_pointset_union(c);
verify_pointset_subtract(c);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment