Commit 53d3daba authored by Joseph Mirabel's avatar Joseph Mirabel
Browse files

Fix initialization of Convex mesh.

parent e469907c
......@@ -53,6 +53,9 @@ template <typename PolygonT>
class Convex : public ConvexBase
{
public:
/// @brief Construct an uninitialized convex object
Convex () : ConvexBase(), polygons(NULL), num_polygons(0) {}
/// @brief Constructing a convex, providing normal and offset of each polytype surface, and the points and shape topology information
/// \param ownStorage whether this class owns the pointers of points and
/// polygons. If owned, they are deleted upon destruction.
......
......@@ -48,11 +48,11 @@ namespace fcl
template <typename PolygonT>
Convex<PolygonT>::Convex(bool own_storage, Vec3f* points_, int num_points_,
PolygonT* polygons_, int num_polygons_) :
ConvexBase(own_storage, points_, num_points_),
PolygonT* polygons_, int num_polygons_) : ConvexBase(),
polygons (polygons_),
num_polygons (num_polygons_)
{
initialize(own_storage, points_, num_points_);
fillNeighbors();
}
......
......@@ -312,10 +312,16 @@ public:
Vec3f center;
protected:
/// @brief Constructing a convex, providing normal and offset of each polytype surface, and the points and shape topology information
/// @brief Construct an uninitialized convex object
/// Initialization is done with ConvexBase::initialize.
ConvexBase () : ShapeBase(), points(NULL), num_points(0),
neighbors(NULL), nneighbors_(NULL), own_storage_(false) {}
/// @brief Initialize the points of the convex shape
/// This also initializes the ConvexBase::center.
/// \param points_ list of 3D points
/// \param num_points_ number of 3D points
ConvexBase(bool ownStorage, Vec3f* points_, int num_points_);
void initialize(bool ownStorage, Vec3f* points_, int num_points_);
/// @brief Copy constructor
/// Only the list of neighbors is copied.
......
......@@ -44,12 +44,11 @@ namespace hpp
namespace fcl
{
ConvexBase::ConvexBase(bool own_storage, Vec3f* points_, int num_points_) :
ShapeBase(),
points (points_),
num_points (num_points_),
own_storage_ (own_storage)
void ConvexBase::initialize(bool own_storage, Vec3f* points_, int num_points_)
{
points = points_;
num_points = num_points_;
own_storage_ = own_storage;
computeCenter();
}
......@@ -60,7 +59,11 @@ ConvexBase::ConvexBase(const ConvexBase& other) :
center (other.center),
own_storage_ (other.own_storage_)
{
if (neighbors) delete [] neighbors;
if (nneighbors_) delete [] nneighbors_;
if (own_storage_) {
if (own_storage_ && points) delete [] points;
points = new Vec3f[num_points];
memcpy(points, other.points, sizeof(Vec3f) * num_points);
}
......@@ -76,9 +79,9 @@ ConvexBase::ConvexBase(const ConvexBase& other) :
ConvexBase::~ConvexBase ()
{
delete [] neighbors;
delete [] nneighbors_;
if (own_storage_) delete [] points;
if (neighbors) delete [] neighbors;
if (nneighbors_) delete [] nneighbors_;
if (own_storage_ && points) delete [] points;
}
void ConvexBase::computeCenter()
......
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