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> ...@@ -53,6 +53,9 @@ template <typename PolygonT>
class Convex : public ConvexBase class Convex : public ConvexBase
{ {
public: 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 /// @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 /// \param ownStorage whether this class owns the pointers of points and
/// polygons. If owned, they are deleted upon destruction. /// polygons. If owned, they are deleted upon destruction.
......
...@@ -48,11 +48,11 @@ namespace fcl ...@@ -48,11 +48,11 @@ namespace fcl
template <typename PolygonT> template <typename PolygonT>
Convex<PolygonT>::Convex(bool own_storage, Vec3f* points_, int num_points_, Convex<PolygonT>::Convex(bool own_storage, Vec3f* points_, int num_points_,
PolygonT* polygons_, int num_polygons_) : PolygonT* polygons_, int num_polygons_) : ConvexBase(),
ConvexBase(own_storage, points_, num_points_),
polygons (polygons_), polygons (polygons_),
num_polygons (num_polygons_) num_polygons (num_polygons_)
{ {
initialize(own_storage, points_, num_points_);
fillNeighbors(); fillNeighbors();
} }
......
...@@ -312,10 +312,16 @@ public: ...@@ -312,10 +312,16 @@ public:
Vec3f center; Vec3f center;
protected: 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 points_ list of 3D points
/// \param num_points_ number 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 /// @brief Copy constructor
/// Only the list of neighbors is copied. /// Only the list of neighbors is copied.
......
...@@ -44,12 +44,11 @@ namespace hpp ...@@ -44,12 +44,11 @@ namespace hpp
namespace fcl namespace fcl
{ {
ConvexBase::ConvexBase(bool own_storage, Vec3f* points_, int num_points_) : void ConvexBase::initialize(bool own_storage, Vec3f* points_, int num_points_)
ShapeBase(),
points (points_),
num_points (num_points_),
own_storage_ (own_storage)
{ {
points = points_;
num_points = num_points_;
own_storage_ = own_storage;
computeCenter(); computeCenter();
} }
...@@ -60,7 +59,11 @@ ConvexBase::ConvexBase(const ConvexBase& other) : ...@@ -60,7 +59,11 @@ ConvexBase::ConvexBase(const ConvexBase& other) :
center (other.center), center (other.center),
own_storage_ (other.own_storage_) own_storage_ (other.own_storage_)
{ {
if (neighbors) delete [] neighbors;
if (nneighbors_) delete [] nneighbors_;
if (own_storage_) { if (own_storage_) {
if (own_storage_ && points) delete [] points;
points = new Vec3f[num_points]; points = new Vec3f[num_points];
memcpy(points, other.points, sizeof(Vec3f) * num_points); memcpy(points, other.points, sizeof(Vec3f) * num_points);
} }
...@@ -76,9 +79,9 @@ ConvexBase::ConvexBase(const ConvexBase& other) : ...@@ -76,9 +79,9 @@ ConvexBase::ConvexBase(const ConvexBase& other) :
ConvexBase::~ConvexBase () ConvexBase::~ConvexBase ()
{ {
delete [] neighbors; if (neighbors) delete [] neighbors;
delete [] nneighbors_; if (nneighbors_) delete [] nneighbors_;
if (own_storage_) delete [] points; if (own_storage_ && points) delete [] points;
} }
void ConvexBase::computeCenter() 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