Commit 75499ca1 authored by David C. Lonie's avatar David C. Lonie

Add vtkMolecule::GetBondList().

This ensures the bond list both exists and is up to date. This prevents
crashes from accessing the edgelist/bondlist before it's created.
parent 39a2e117
Pipeline #20150 passed with stage
......@@ -234,11 +234,7 @@ vtkBond vtkMolecule::GetBond(vtkIdType bondId)
{
assert(bondId >= 0 && bondId < this->GetNumberOfBonds());
if (this->BondListIsDirty)
{
this->UpdateBondList();
}
vtkIdTypeArray *bonds = this->GetEdgeList();
vtkIdTypeArray *bonds = this->GetBondList();
// An array with two components holding the bonded atom's ids
vtkIdType *ids = bonds->GetPointer(2 * bondId);
return vtkBond (this, bondId, ids[0], ids[1]);
......@@ -277,7 +273,7 @@ double vtkMolecule::GetBondLength(vtkIdType bondId)
assert(bondId >= 0 && bondId < this->GetNumberOfBonds());
// Get list of bonds
vtkIdTypeArray *bonds = this->GetEdgeList();
vtkIdTypeArray *bonds = this->GetBondList();
// An array of length two holding the bonded atom's ids
vtkIdType *ids = bonds->GetPointer(bondId);
......@@ -415,6 +411,20 @@ void vtkMolecule::UpdateBondList()
this->BondListIsDirty = false;
}
//----------------------------------------------------------------------------
vtkIdTypeArray *vtkMolecule::GetBondList()
{
// Create the edge list if it doesn't exist, or is marked as dirty.
vtkIdTypeArray *edgeList = this->BondListIsDirty ? NULL : this->GetEdgeList();
if (!edgeList)
{
this->UpdateBondList();
edgeList = this->GetEdgeList();
}
assert(edgeList != NULL);
return edgeList;
}
//----------------------------------------------------------------------------
bool vtkMolecule::GetPlaneFromBond(const vtkBond &bond,
const vtkVector3f &normal,
......
......@@ -273,6 +273,7 @@ public:
bool BondListIsDirty;
void SetBondListDirty() {this->BondListIsDirty = true;}
void UpdateBondList();
vtkIdTypeArray* GetBondList();
friend class vtkAtom;
friend class vtkBond;
......
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