Commit 9306a4d9 authored by Marcus D. Hanwell's avatar Marcus D. Hanwell
Browse files

ENH: Simplification of the chemistry core API.

Removed duplicated API, and shortened some function names.

Change-Id: Ia4b1d30b03fee496360bf2556877fd0f5c6000a8
parent ad5b329b
......@@ -196,7 +196,7 @@ void vtkCMLParser::NewAtom(const char **attr)
vtkAtom atom = this->Target->AppendAtom();
int attrInd = 0;
unsigned short atomicNum = 0;
double pos[3];
float pos[3];
const char * id;
while (const char * cur = attr[attrInd])
{
......
......@@ -526,9 +526,9 @@ void vtkMoleculeMapper::UpdateBondGlyphPolyData()
selectionId = numAtoms + bondInd; // mixing 1 and 0 indexed ids on purpose
// Extract bond info
vtkBond bond = molecule->GetBond(bondInd);
bondOrder = bond.GetBondOrder();
pos1 = bond.GetBeginAtomPositionAsVector3f();
pos2 = bond.GetEndAtomPositionAsVector3f();
bondOrder = bond.GetOrder();
pos1 = bond.GetBeginAtom().GetPosition();
pos2 = bond.GetEndAtom().GetPosition();
atomicNumbers[0] = bond.GetBeginAtom().GetAtomicNumber();
atomicNumbers[1] = bond.GetEndAtom().GetAtomicNumber();
......
......@@ -79,7 +79,7 @@ int vtkMoleculeToAtomBallFilter::RequestData(
vtkIdType numCellPoints, *cellPoints;
double scaledRadius;
unsigned short atomicNum;
double pos[3];
vtkVector3f pos;
// Build a sphere for each atom and append it's data to the output
// arrays.
......@@ -88,7 +88,7 @@ int vtkMoleculeToAtomBallFilter::RequestData(
// Extract atomic number, position
vtkAtom atom = input->GetAtom(atomInd);
atomicNum = atom.GetAtomicNumber();
atom.GetPosition(pos);
pos = atom.GetPosition();
// Get scaled radius:
switch (this->RadiusSource)
......@@ -114,7 +114,7 @@ int vtkMoleculeToAtomBallFilter::RequestData(
// Update sphere source
sphereSource->SetRadius(scaledRadius);
sphereSource->SetCenter(pos);
sphereSource->SetCenter(pos.Cast<double>().GetData());
sphereSource->Update();
// Extract polydata from sphere
......
......@@ -98,9 +98,9 @@ int vtkMoleculeToBondStickFilter::RequestData(
{
// Extract bond info
vtkBond bond = input->GetBond(bondInd);
bondOrder = bond.GetBondOrder();
bond.GetBeginAtomPosition(pos1);
bond.GetEndAtomPosition(pos2);
bondOrder = bond.GetOrder();
bond.GetBeginAtom().GetPosition(pos1);
bond.GetEndAtom().GetPosition(pos2);
// Compute additional bond info
// - Normalized vector in direction of bond
......
......@@ -162,7 +162,7 @@ void vtkOpenQubeMoleculeSource::CopyOQMoleculeToVtkMolecule(
{
vtkAtom atom = mol->AppendAtom();
pos = oqmol->atomPos(i);
atom.SetPosition(pos.data());
atom.SetPosition(vtkVector3d(pos.data()).Cast<float>().GetData());
atom.SetAtomicNumber(oqmol->atomAtomicNumber(i));
}
......
......@@ -54,27 +54,24 @@ void vtkAtom::SetAtomicNumber(unsigned short atomicNum)
}
//----------------------------------------------------------------------------
void vtkAtom::GetPosition(double pos[3])
{
return this->Molecule->GetAtomPosition(this->Id, pos);
}
//----------------------------------------------------------------------------
void vtkAtom::SetPosition(const double pos[3])
void vtkAtom::GetPosition(float pos[3])
{
this->Molecule->SetAtomPosition(this->Id, pos);
this->Molecule->GetAtomPosition(this->Id, pos);
}
//----------------------------------------------------------------------------
void vtkAtom::GetPosition(float pos[3])
void vtkAtom::GetPosition(double pos[3])
{
this->Molecule->GetAtomPosition(this->Id, pos);
vtkVector3f position = this->GetPosition();
pos[0] = position.X();
pos[1] = position.Y();
pos[2] = position.Z();
}
//----------------------------------------------------------------------------
void vtkAtom::SetPosition(const float pos[3])
{
this->Molecule->SetAtomPosition(this->Id, pos);
this->Molecule->SetAtomPosition(this->Id, vtkVector3f(pos));
}
//----------------------------------------------------------------------------
......@@ -86,7 +83,7 @@ void vtkAtom::SetPosition(float x, float y, float z)
//----------------------------------------------------------------------------
vtkVector3f vtkAtom::GetPosition()
{
return this->Molecule->GetAtomPositionAsVector3f(this->Id);
return this->Molecule->GetAtomPosition(this->Id);
}
//----------------------------------------------------------------------------
......
......@@ -52,9 +52,8 @@ class VTK_FILTERING_EXPORT vtkAtom
// Description:
// Get/Set the position of this atom
void GetPosition(double pos[3]);
void SetPosition(const double pos[3]);
void GetPosition(float pos[3]);
void GetPosition(double pos[3]);
void SetPosition(const float pos[3]);
void SetPosition(float x, float y, float z);
vtkVector3f GetPosition();
......
......@@ -41,21 +41,19 @@ void vtkBond::PrintSelf(ostream &os, vtkIndent indent)
{
os << indent << "Molecule: " << this->Molecule
<< " Id: " << this->Id
<< " Order: " << this->GetBondOrder()
<< " Length: " << this->GetBondLength()
<< " Order: " << this->GetOrder()
<< " Length: " << this->GetLength()
<< " BeginAtomId: " << this->BeginAtomId
<< " EndAtomId: " << this->EndAtomId << endl;
}
//----------------------------------------------------------------------------
double vtkBond::GetBondLength()
double vtkBond::GetLength()
{
// Reimplement here to avoid the potential cost of building the EdgeList
// (We already know the atomIds, no need to look them up)
vtkVector3d pos1 =
this->Molecule->GetAtomPositionAsVector3d(this->BeginAtomId);
vtkVector3d pos2 =
this->Molecule->GetAtomPositionAsVector3d(this->EndAtomId);
vtkVector3f pos1 = this->Molecule->GetAtomPosition(this->BeginAtomId);
vtkVector3f pos2 = this->Molecule->GetAtomPosition(this->EndAtomId);
return (pos2 - pos1).Norm();
}
......@@ -73,115 +71,7 @@ vtkAtom vtkBond::GetEndAtom()
}
//----------------------------------------------------------------------------
unsigned short vtkBond::GetBondOrder()
unsigned short vtkBond::GetOrder()
{
return this->Molecule->GetBondOrder(this->Id);
}
//----------------------------------------------------------------------------
void vtkBond::GetBeginAtomPosition(double pos[3])
{
this->Molecule->GetAtomPosition(this->BeginAtomId, pos);
}
//----------------------------------------------------------------------------
void vtkBond::SetBeginAtomPosition(const double pos[3])
{
this->Molecule->SetAtomPosition(this->BeginAtomId, pos);
}
//----------------------------------------------------------------------------
void vtkBond::GetEndAtomPosition(double pos[3])
{
this->Molecule->GetAtomPosition(this->EndAtomId, pos);
}
//----------------------------------------------------------------------------
void vtkBond::SetEndAtomPosition(const double pos[3])
{
this->Molecule->SetAtomPosition(this->EndAtomId, pos);
}
//----------------------------------------------------------------------------
void vtkBond::GetBeginAtomPosition(float pos[3])
{
this->Molecule->GetAtomPosition(this->BeginAtomId, pos);
}
//----------------------------------------------------------------------------
void vtkBond::SetBeginAtomPosition(const float pos[3])
{
this->Molecule->SetAtomPosition(this->BeginAtomId, pos);
}
//----------------------------------------------------------------------------
void vtkBond::GetEndAtomPosition(float pos[3])
{
this->Molecule->GetAtomPosition(this->EndAtomId, pos);
}
//----------------------------------------------------------------------------
void vtkBond::SetEndAtomPosition(const float pos[3])
{
this->Molecule->SetAtomPosition(this->EndAtomId, pos);
}
//----------------------------------------------------------------------------
void vtkBond::SetBeginAtomPosition(double x, double y, double z)
{
this->Molecule->SetAtomPosition(this->BeginAtomId, x, y, z);
}
//----------------------------------------------------------------------------
void vtkBond::SetEndAtomPosition(double x, double y, double z)
{
this->Molecule->SetAtomPosition(this->EndAtomId, x, y, z);
}
//----------------------------------------------------------------------------
void vtkBond::SetBeginAtomPosition(const vtkVector3f &pos)
{
this->Molecule->SetAtomPosition(this->BeginAtomId, pos);
}
//----------------------------------------------------------------------------
vtkVector3f vtkBond::GetBeginAtomPositionAsVector3f()
{
return this->Molecule->GetAtomPositionAsVector3f(this->BeginAtomId);
}
//----------------------------------------------------------------------------
void vtkBond::SetEndAtomPosition(const vtkVector3f &pos)
{
this->Molecule->SetAtomPosition(this->EndAtomId, pos);
}
//----------------------------------------------------------------------------
vtkVector3f vtkBond::GetEndAtomPositionAsVector3f()
{
return this->Molecule->GetAtomPositionAsVector3f(this->EndAtomId);
}
//----------------------------------------------------------------------------
void vtkBond::SetBeginAtomPosition(const vtkVector3d &pos)
{
this->Molecule->SetAtomPosition(this->BeginAtomId, pos);
}
//----------------------------------------------------------------------------
vtkVector3d vtkBond::GetBeginAtomPositionAsVector3d()
{
return this->Molecule->GetAtomPositionAsVector3d(this->BeginAtomId);
}
//----------------------------------------------------------------------------
void vtkBond::SetEndAtomPosition(const vtkVector3d &pos)
{
this->Molecule->SetAtomPosition(this->EndAtomId, pos);
}
//----------------------------------------------------------------------------
vtkVector3d vtkBond::GetEndAtomPositionAsVector3d()
{
return this->Molecule->GetAtomPositionAsVector3d(this->EndAtomId);
}
......@@ -22,12 +22,10 @@
#include "vtkAtom.h" // For vtkAtom
class vtkMolecule;
class vtkVector3d;
class vtkVector3f;
class VTK_FILTERING_EXPORT vtkBond
{
public:
public:
~vtkBond();
void PrintSelf(ostream &os, vtkIndent indent);
......@@ -64,37 +62,16 @@ class VTK_FILTERING_EXPORT vtkBond
// Description:
// Get the bond order for this bond.
unsigned short GetBondOrder();
unsigned short GetOrder();
// Description:
// Get the distance between the bonded atoms
// Get the distance between the bonded atoms.
//
// @note This function is faster than vtkMolecule::GetBondLength and
// should be used when possible.
double GetBondLength();
double GetLength();
// Description:
// Get/Set the positions of the starting/ending atoms
void GetBeginAtomPosition(double pos[3]);
void SetBeginAtomPosition(const double pos[3]);
void GetEndAtomPosition(double pos[3]);
void SetEndAtomPosition(const double pos[3]);
void GetBeginAtomPosition(float pos[3]);
void SetBeginAtomPosition(const float pos[3]);
void GetEndAtomPosition(float pos[3]);
void SetEndAtomPosition(const float pos[3]);
void SetBeginAtomPosition(double x, double y, double z);
void SetEndAtomPosition(double x, double y, double z);
void SetBeginAtomPosition(const vtkVector3f &pos);
vtkVector3f GetBeginAtomPositionAsVector3f();
void SetEndAtomPosition(const vtkVector3f &pos);
vtkVector3f GetEndAtomPositionAsVector3f();
void SetBeginAtomPosition(const vtkVector3d &pos);
vtkVector3d GetBeginAtomPositionAsVector3d();
void SetEndAtomPosition(const vtkVector3d &pos);
vtkVector3d GetEndAtomPositionAsVector3d();
protected:
protected:
friend class vtkMolecule;
vtkBond(vtkMolecule *parent, vtkIdType id,
......
......@@ -22,6 +22,7 @@ PURPOSE. See the above copyright notice for more information.
#include "vtkPlane.h"
#include "vtkPoints.h"
#include "vtkUnsignedShortArray.h"
#include "vtkFloatArray.h"
#include "vtkVector.h"
#include "vtkVectorOperators.h"
......@@ -112,7 +113,8 @@ void vtkMolecule::PrintSelf(ostream &os, vtkIndent indent)
}
//----------------------------------------------------------------------------
vtkAtom vtkMolecule::AppendAtom(unsigned short atomicNumber, const float pos[3])
vtkAtom vtkMolecule::AppendAtom(unsigned short atomicNumber,
const vtkVector3f &pos)
{
vtkUnsignedShortArray *atomicNums = vtkUnsignedShortArray::SafeDownCast
(this->GetVertexData()->GetScalars());
......@@ -123,27 +125,7 @@ vtkAtom vtkMolecule::AppendAtom(unsigned short atomicNumber, const float pos[3])
this->AddVertexInternal(0, &id);
atomicNums->InsertValue(id, atomicNumber);
vtkIdType coordID = this->Points->InsertNextPoint(pos);
(void)coordID;
assert("point ids synced with vertex ids" && coordID == id);
this->Modified();
return vtkAtom(this, id);
}
//----------------------------------------------------------------------------
vtkAtom vtkMolecule::AppendAtom(unsigned short atomicNumber, const double pos[3])
{
vtkUnsignedShortArray *atomicNums = vtkUnsignedShortArray::SafeDownCast
(this->GetVertexData()->GetScalars());
assert(atomicNums);
vtkIdType id;
this->AddVertexInternal(0, &id);
atomicNums->InsertValue(id, atomicNumber);
vtkIdType coordID = this->Points->InsertNextPoint(pos);
vtkIdType coordID = this->Points->InsertNextPoint(pos.GetData());
(void)coordID;
assert("point ids synced with vertex ids" && coordID == id);
......@@ -188,44 +170,38 @@ void vtkMolecule::SetAtomAtomicNumber(vtkIdType id, unsigned short atomicNum)
}
//----------------------------------------------------------------------------
void vtkMolecule::GetAtomPosition(vtkIdType id, double pos[3])
{
assert(id >= 0 && id < this->GetNumberOfAtoms());
this->Points->GetPoint(id, pos);
}
//----------------------------------------------------------------------------
void vtkMolecule::SetAtomPosition(vtkIdType id, const double pos[3])
void vtkMolecule::SetAtomPosition(vtkIdType id, const vtkVector3f &pos)
{
assert(id >= 0 && id < this->GetNumberOfAtoms());
this->Points->SetPoint(id, pos);
this->Points->SetPoint(id, pos.GetData());
this->Modified();
}
//----------------------------------------------------------------------------
void vtkMolecule::GetAtomPosition(vtkIdType id, float pos[3])
void vtkMolecule::SetAtomPosition(vtkIdType id, double x, double y, double z)
{
assert(id >= 0 && id < this->GetNumberOfAtoms());
double posd[3];
// There is no float overload of vtkPoints::GetPoint
this->Points->GetPoint(id, posd);
pos[0] = posd[0]; pos[1] = posd[1]; pos[2] = posd[2];
this->Points->SetPoint(id, x, y, z);
this->Modified();
}
//----------------------------------------------------------------------------
void vtkMolecule::SetAtomPosition(vtkIdType id, const float pos[3])
vtkVector3f vtkMolecule::GetAtomPosition(vtkIdType id)
{
assert(id >= 0 && id < this->GetNumberOfAtoms());
this->Points->SetPoint(id, pos);
this->Modified();
vtkFloatArray *positions = vtkFloatArray::SafeDownCast(this->Points->GetData());
assert(positions != NULL);
float *data = static_cast<float *>(positions->GetVoidPointer(id * 3));
return vtkVector3f(data);
}
//----------------------------------------------------------------------------
void vtkMolecule::SetAtomPosition(vtkIdType id, double x, double y, double z)
void vtkMolecule::GetAtomPosition(vtkIdType id, float pos[3])
{
assert(id >= 0 && id < this->GetNumberOfAtoms());
this->Points->SetPoint(id, x, y, z);
this->Modified();
vtkVector3f position = this->GetAtomPosition(id);
pos[0] = position.X();
pos[1] = position.Y();
pos[2] = position.Z();
}
//----------------------------------------------------------------------------
......@@ -305,8 +281,8 @@ double vtkMolecule::GetBondLength(vtkIdType bondId)
vtkIdType *ids = bonds->GetPointer(bondId);
// Get positions
vtkVector3d pos1 = this->GetAtomPositionAsVector3d(ids[0]);
vtkVector3d pos2 = this->GetAtomPositionAsVector3d(ids[1]);
vtkVector3f pos1 = this->GetAtomPosition(ids[0]);
vtkVector3f pos2 = this->GetAtomPosition(ids[1]);
return (pos2 - pos1).Norm();
}
......@@ -427,43 +403,38 @@ bool vtkMolecule::GetPlaneFromBond(vtkAtom atom1, vtkAtom atom2,
const double normal[3], vtkPlane *plane)
{
if (plane == NULL)
{
return false;
}
// TODO Remove or restore this when subtracting vectors is supported again
// vtkVector3d v (atom1.GetPositionAsVector3d() -
// atom2.GetPositionAsVector3d());
double pos1[3];
double pos2[3];
atom1.GetPosition(pos1);
atom2.GetPosition(pos2);
vtkVector3d v (pos1[0] - pos2[0], pos1[1] - pos2[1], pos1[2] - pos2[2]);
// end vtkVector reimplementation TODO
vtkVector3f v(atom1.GetPosition() - atom2.GetPosition());
vtkVector3d n_i (normal);
vtkVector3d unitV (v.Normalized());
vtkVector3f n_i(vtkVector3d(normal).Cast<float>().GetData());
vtkVector3f unitV(v.Normalized());
// Check if vectors are (nearly) parallel
if (unitV.Compare(n_i.Normalized(), 1e-7))
{
return false;
}
// calculate projection of n_i onto v
// TODO Remove or restore this when scalar mult. is supported again
// vtkVector3d proj (unitV * n_i.Dot(unitV));
double n_iDotUnitV = n_i.Dot(unitV);
vtkVector3d proj (unitV[0] * n_iDotUnitV, unitV[1] * n_iDotUnitV,
vtkVector3f proj (unitV[0] * n_iDotUnitV, unitV[1] * n_iDotUnitV,
unitV[2] * n_iDotUnitV);
// end vtkVector reimplementation TODO
// Calculate actual normal:
// TODO Remove/restore this when subtraction is supported again
// vtkVector3d realNormal (n_i - proj);
vtkVector3d realNormal (n_i[0]-proj[0], n_i[1]-proj[1], n_i[2]-proj[2]);
vtkVector3f realNormal (n_i[0]-proj[0], n_i[1]-proj[1], n_i[2]-proj[2]);
// end vtkVector reimplementation TODO
// Create plane:
double pos[3];
atom1.GetPosition(pos);
plane->SetOrigin(pos);
plane->SetNormal(realNormal.GetData());
vtkVector3f pos(atom1.GetPosition());
plane->SetOrigin(pos.Cast<double>().GetData());
plane->SetNormal(realNormal.Cast<double>().GetData());
return true;
}
......@@ -93,36 +93,21 @@ class VTK_FILTERING_EXPORT vtkMolecule : public vtkUndirectedGraph
// a vtkAtom that refers to the new atom.
vtkAtom AppendAtom()
{
const double pos[3] = {0.0, 0.0, 0.0};
return this->AppendAtom(0, pos);
return this->AppendAtom(0, vtkVector3f(0, 0, 0));
}
// Description:
// Add new atom with the specified atomic number and
// position. Return a vtkAtom that refers to the new atom.
vtkAtom AppendAtom(unsigned short atomicNumber,
const vtkVector3d &pos)
{
return this->AppendAtom(atomicNumber, pos.GetData());
}
vtkAtom AppendAtom(unsigned short atomicNumber,
const vtkVector3f &pos)
{
return this->AppendAtom(atomicNumber, pos.GetData());
}
vtkAtom AppendAtom(unsigned short atomicNumber,
double x, double y, double z)
// Add new atom with the specified atomic number and position. Return a
// vtkAtom that refers to the new atom.
vtkAtom AppendAtom(unsigned short atomicNumber, const vtkVector3f &pos);
// Description:
// Convenience methods to append a new atom with the specified atomic number
// and position.
vtkAtom AppendAtom(unsigned short atomicNumber, double x, double y, double z)
{
double pos[3];
pos[0] = x;
pos[1] = y;
pos[2] = z;
return this->AppendAtom(atomicNumber, pos);
return this->AppendAtom(atomicNumber, vtkVector3f(x, y, z));
}
vtkAtom AppendAtom(unsigned short atomicNumber,
const float pos[3]);
vtkAtom AppendAtom(unsigned short atomicNumber,
const double pos[3]);
// Description:
// Return a vtkAtom that refers to the atom with the specified id.
......@@ -163,32 +148,14 @@ class VTK_FILTERING_EXPORT vtkMolecule : public vtkUndirectedGraph
unsigned short atomicNum);
// Description:
// Get/Set the position of the atom with the specified id
void GetAtomPosition(vtkIdType atomId, double pos[3]);
void SetAtomPosition(vtkIdType atomId, const double pos[3]);
void GetAtomPosition(vtkIdType atomId, float pos[3]);
void SetAtomPosition(vtkIdType atomId, const float pos[3]);
// Set the position of the atom with the specified id.
void SetAtomPosition(vtkIdType atomId, const vtkVector3f &pos);
void SetAtomPosition(vtkIdType atomId, double x, double y, double z);
vtkVector3d GetAtomPositionAsVector3d(vtkIdType atomId)
{
double pos[3];
this->GetAtomPosition(atomId, pos);
return vtkVector3d(pos);
}
void SetAtomPosition(vtkIdType atomId, const vtkVector3d &pos)
{
return this->SetAtomPosition(atomId, pos.GetData());
}
vtkVector3f GetAtomPositionAsVector3f(vtkIdType atomId)
{
float pos[3];
this->GetAtomPosition(atomId, pos);
return vtkVector3f(pos);
}
void SetAtomPosition(vtkIdType atomId, const vtkVector3f &pos)
{
return this->SetAtomPosition(atomId, pos.GetData());
}
// Description:
// Get the position of the atom with the specified id.
vtkVector3f GetAtomPosition(vtkIdType atomId);
void GetAtomPosition(vtkIdType atomId, float pos[3]);
// Description
// Get/Set the bond order of the bond with the specified id
......
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