Commit 81a8f930 authored by David C. Lonie's avatar David C. Lonie
Browse files

Add unit cell lattices to vtkMolecule.

parent 1d461be6
Pipeline #23483 passed with stage
......@@ -17,6 +17,7 @@ PURPOSE. See the above copyright notice for more information.
#include "vtkDataSetAttributes.h"
#include "vtkEdgeListIterator.h"
#include "vtkIdTypeArray.h"
#include "vtkMatrix3x3.h"
#include "vtkNew.h"
#include "vtkObjectFactory.h"
#include "vtkPlane.h"
......@@ -33,7 +34,9 @@ vtkStandardNewMacro(vtkMolecule);
//----------------------------------------------------------------------------
vtkMolecule::vtkMolecule()
: ElectronicData(NULL)
: ElectronicData(NULL),
Lattice(NULL),
LatticeOrigin(0., 0., 0.)
{
this->Initialize();
}
......@@ -102,6 +105,19 @@ void vtkMolecule::PrintSelf(ostream &os, vtkIndent indent)
this->GetBond(i).PrintSelf(os, subIndent);
}
os << indent << "Lattice:\n";
if (this->HasLattice())
{
double *m = this->Lattice->GetData();
os << subIndent << "a: " << m[0] << " " << m[3] << " " << m[6] << "\n";
os << subIndent << "b: " << m[1] << " " << m[4] << " " << m[7] << "\n";
os << subIndent << "c: " << m[2] << " " << m[5] << " " << m[8] << "\n";
os << subIndent << "origin: "
<< this->LatticeOrigin[0] << " "
<< this->LatticeOrigin[1] << " "
<< this->LatticeOrigin[2] << "\n";
}
os << indent << "Electronic Data:\n";
if (this->ElectronicData)
{
......@@ -388,6 +404,26 @@ void vtkMolecule::CopyStructureInternal(vtkMolecule *m, bool deep)
{
this->Superclass::ShallowCopy(m);
}
if (!m->HasLattice())
{
this->ClearLattice();
}
else
{
if (deep)
{
vtkNew<vtkMatrix3x3> newLattice;
newLattice->DeepCopy(m->Lattice);
this->SetLattice(newLattice.Get());
}
else
{
this->SetLattice(m->Lattice);
}
this->LatticeOrigin = m->LatticeOrigin;
}
this->BondListIsDirty = true;
}
......@@ -472,3 +508,115 @@ bool vtkMolecule::GetPlaneFromBond(const vtkAtom &atom1, const vtkAtom &atom2,
plane->SetNormal(realNormal.Cast<double>().GetData());
return true;
}
//------------------------------------------------------------------------------
bool vtkMolecule::HasLattice()
{
return this->Lattice.Get() != NULL;
}
//------------------------------------------------------------------------------
void vtkMolecule::ClearLattice()
{
this->SetLattice(NULL);
}
//------------------------------------------------------------------------------
void vtkMolecule::SetLattice(vtkMatrix3x3 *matrix)
{
if (!matrix)
{
if (this->Lattice)
{
// If we're clearing a matrix, zero out the origin:
this->LatticeOrigin = vtkVector3d(0., 0., 0.);
this->Lattice = NULL;
this->Modified();
}
}
else if (this->Lattice != matrix)
{
this->Lattice = matrix;
this->Modified();
}
}
//------------------------------------------------------------------------------
void vtkMolecule::SetLattice(const vtkVector3d &a, const vtkVector3d &b,
const vtkVector3d &c)
{
if (this->Lattice.Get() == NULL)
{
this->Lattice.TakeReference(vtkMatrix3x3::New());
this->Modified();
}
double *mat = this->Lattice->GetData();
if (mat[0] != a[0] || mat[1] != b[0] || mat[2] != c[0] ||
mat[3] != a[1] || mat[4] != b[1] || mat[5] != c[1] ||
mat[6] != a[2] || mat[7] != b[2] || mat[8] != c[2])
{
mat[0] = a[0];
mat[1] = b[0];
mat[2] = c[0];
mat[3] = a[1];
mat[4] = b[1];
mat[5] = c[1];
mat[6] = a[2];
mat[7] = b[2];
mat[8] = c[2];
this->Modified();
}
}
//------------------------------------------------------------------------------
vtkMatrix3x3 *vtkMolecule::GetLattice()
{
return this->Lattice.Get();
}
//------------------------------------------------------------------------------
void vtkMolecule::GetLattice(vtkVector3d &a, vtkVector3d &b, vtkVector3d &c)
{
if (this->Lattice)
{
double *mat = this->Lattice->GetData();
a[0] = mat[0];
a[1] = mat[3];
a[2] = mat[6];
b[0] = mat[1];
b[1] = mat[4];
b[2] = mat[7];
c[0] = mat[2];
c[1] = mat[5];
c[2] = mat[8];
}
else
{
a = b = c = vtkVector3d(0., 0., 0.);
}
}
//------------------------------------------------------------------------------
void vtkMolecule::GetLattice(vtkVector3d &a, vtkVector3d &b, vtkVector3d &c,
vtkVector3d &origin)
{
if (this->Lattice)
{
double *mat = this->Lattice->GetData();
a[0] = mat[0];
a[1] = mat[3];
a[2] = mat[6];
b[0] = mat[1];
b[1] = mat[4];
b[2] = mat[7];
c[0] = mat[2];
c[1] = mat[5];
c[2] = mat[8];
origin = this->LatticeOrigin;
}
else
{
a = b = c = origin = vtkVector3d(0., 0., 0.);
}
}
......@@ -68,14 +68,16 @@
#include "vtkCommonDataModelModule.h" // For export macro
#include "vtkUndirectedGraph.h"
#include "vtkSmartPointer.h" // For vtkSmartPointer
#include "vtkAtom.h" // Simple proxy class dependent on vtkMolecule
#include "vtkBond.h" // Simple proxy class dependent on vtkMolecule
#include "vtkVector.h" // Small templated vector convenience class
class vtkPlane;
class vtkAbstractElectronicData;
class vtkMatrix3x3;
class vtkPlane;
class vtkPoints;
class vtkUnsignedShortArray;
......@@ -253,6 +255,40 @@ public:
static bool GetPlaneFromBond(const vtkAtom &atom1, const vtkAtom &atom2,
const vtkVector3f &normal, vtkPlane *plane);
// Description:
// Return true if a unit cell lattice is defined.
bool HasLattice();
// Description:
// Remove any unit cell lattice information from the molecule.
void ClearLattice();
// Description:
// The unit cell vectors. The matrix is stored using a row-major layout, with
// the vectors encoded as columns.
void SetLattice(vtkMatrix3x3 *matrix);
void SetLattice(const vtkVector3d &a,
const vtkVector3d &b,
const vtkVector3d &c);
// Description:
// Get the unit cell lattice vectors. The matrix is stored using a row-major
// layout, with the vectors encoded as columns. Will return NULL if no
// unit cell information is available.
// @sa GetLatticeOrigin
vtkMatrix3x3* GetLattice();
// Description:
// Get the unit cell lattice vectors, and optionally, the origin.
void GetLattice(vtkVector3d &a, vtkVector3d &b, vtkVector3d &c);
void GetLattice(vtkVector3d &a, vtkVector3d &b, vtkVector3d &c,
vtkVector3d &origin);
// Description:
// Get the unit cell origin (for rendering purposes).
vtkGetMacro(LatticeOrigin, vtkVector3d)
vtkSetMacro(LatticeOrigin, vtkVector3d)
protected:
vtkMolecule();
~vtkMolecule();
......@@ -279,6 +315,8 @@ public:
friend class vtkBond;
vtkAbstractElectronicData *ElectronicData;
vtkSmartPointer<vtkMatrix3x3> Lattice;
vtkVector3d LatticeOrigin;
private:
vtkMolecule(const vtkMolecule&) VTK_DELETE_FUNCTION;
......
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