Commit 84bc9672 authored by David C. Lonie's avatar David C. Lonie
Browse files

Added vtkMolecule, vtkAtom, and vtkBond to the vtkFiltering kit.

These data objects are in vtkFiltering to prevent circular
dependencies between vtkFiltering, vtkRendering, and vtkChemistry.

Change-Id: I6f6340b531f0364d0b7d7560ac600cefd1e18c2e
parent c57b0d49
......@@ -21,11 +21,13 @@ vtkAMRBox.cxx
vtkAnnotation.cxx
vtkAnnotationLayers.cxx
vtkAnnotationLayersAlgorithm.cxx
vtkAtom.cxx
vtkAttributesErrorMetric.cxx
vtkBiQuadraticQuad.cxx
vtkBiQuadraticQuadraticHexahedron.cxx
vtkBiQuadraticQuadraticWedge.cxx
vtkBiQuadraticTriangle.cxx
vtkBond.cxx
vtkBSPCuts.cxx
vtkBSPIntersections.cxx
vtkCachedStreamingDemandDrivenPipeline.cxx
......@@ -151,6 +153,7 @@ vtkMeanValueCoordinatesInterpolator.cxx
vtkMergePoints.cxx
vtkMarchingSquaresLineCases.cxx
vtkMarchingCubesTriangleCases.cxx
vtkMolecule.cxx
vtkMultiBlockDataSetAlgorithm.cxx
vtkMultiBlockDataSet.cxx
vtkMultiPieceDataSet.cxx
......@@ -269,6 +272,8 @@ vtkAbstractImageInterpolator
vtkAbstractInterpolatedVelocityField
vtkAbstractMapper
vtkAbstractPointLocator
vtkAtom
vtkBond
vtkCell
vtkCell3D
vtkCompositeDataIterator
......@@ -412,4 +417,3 @@ IF(NOT VTK_INSTALL_NO_DEVELOPMENT)
COMPONENT Development
)
ENDIF(NOT VTK_INSTALL_NO_DEVELOPMENT)
/*=========================================================================
Program: Visualization Toolkit
Module: vtkAtom.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkAtom.h"
#include "vtkMolecule.h"
#include "vtkVector.h"
#include <assert.h>
//----------------------------------------------------------------------------
vtkAtom::vtkAtom(vtkMolecule *parent, vtkIdType id)
: Molecule(parent), Id(id)
{
assert(parent != 0);
assert(id < parent->GetNumberOfAtoms());
}
//----------------------------------------------------------------------------
vtkAtom::~vtkAtom()
{
}
//----------------------------------------------------------------------------
void vtkAtom::PrintSelf(ostream &os, vtkIndent indent)
{
char buffer[80];
double coord[3];
this->GetPosition(coord);
snprintf(buffer, 80, "Molecule: %p Id: %4d Ele: %3d Pos: %9.5f %9.5f %9.5f\n",
this->Molecule, this->Id, this->GetAtomicNumber(),
coord[0], coord[1], coord[2]);
os << indent << buffer;
}
//----------------------------------------------------------------------------
unsigned short vtkAtom::GetAtomicNumber()
{
return this->Molecule->GetAtomAtomicNumber(this->Id);
}
//----------------------------------------------------------------------------
void vtkAtom::SetAtomicNumber(unsigned short atomicNum)
{
this->Molecule->SetAtomAtomicNumber(this->Id, atomicNum);
}
//----------------------------------------------------------------------------
void vtkAtom::GetPosition(double pos[3])
{
return this->Molecule->GetAtomPosition(this->Id, pos);
}
//----------------------------------------------------------------------------
void vtkAtom::SetPosition(const double pos[3])
{
this->Molecule->SetAtomPosition(this->Id, pos);
}
//----------------------------------------------------------------------------
void vtkAtom::GetPosition(float pos[3])
{
this->Molecule->GetAtomPosition(this->Id, pos);
}
//----------------------------------------------------------------------------
void vtkAtom::SetPosition(const float pos[3])
{
this->Molecule->SetAtomPosition(this->Id, pos);
}
//----------------------------------------------------------------------------
void vtkAtom::SetPosition(float x, float y, float z)
{
this->Molecule->SetAtomPosition(this->Id, x, y, z);
}
//----------------------------------------------------------------------------
vtkVector3f vtkAtom::GetPositionAsVector3f()
{
return this->Molecule->GetAtomPositionAsVector3f(this->Id);
}
//----------------------------------------------------------------------------
void vtkAtom::SetPosition(const vtkVector3f &pos)
{
this->Molecule->SetAtomPosition(this->Id, pos);
}
//----------------------------------------------------------------------------
vtkVector3d vtkAtom::GetPositionAsVector3d()
{
return this->Molecule->GetAtomPositionAsVector3d(this->Id);
}
//----------------------------------------------------------------------------
void vtkAtom::SetPosition(const vtkVector3d &pos)
{
this->Molecule->SetAtomPosition(this->Id, pos);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkAtom.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkAtom - convenience proxy for vtkMolecule
// .SECTION Description
#ifndef __vtkAtom_h
#define __vtkAtom_h
#include "vtkObject.h" // For macros, defines, etc
class vtkMolecule;
class vtkVector3d;
class vtkVector3f;
class VTK_FILTERING_EXPORT vtkAtom
{
public:
~vtkAtom();
void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Return the Id used to identify this atom in the parent molecule.
vtkIdType GetId()
{
return this->Id;
}
// Description:
// Return the parent molecule of this atom.
vtkMolecule * GetMolecule()
{
return this->Molecule;
}
// Description:
// Get/Set the atomic number of this atom
unsigned short GetAtomicNumber();
void SetAtomicNumber(unsigned short atomicNum);
// 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 SetPosition(const float pos[3]);
void SetPosition(float x, float y, float z);
vtkVector3f GetPositionAsVector3f();
void SetPosition(const vtkVector3f &pos);
vtkVector3d GetPositionAsVector3d();
void SetPosition(const vtkVector3d &pos);
protected:
friend class vtkMolecule;
vtkAtom(vtkMolecule *parent, vtkIdType id);
vtkMolecule *Molecule;
vtkIdType Id;
};
#endif
/*=========================================================================
Program: Visualization Toolkit
Module: vtkBond.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkBond.h"
#include "vtkAtom.h"
#include "vtkMolecule.h"
#include "vtkVector.h"
#include "vtkVectorOperators.h"
#include <assert.h>
//----------------------------------------------------------------------------
vtkBond::vtkBond(vtkMolecule *parent, vtkIdType id,
vtkIdType beginAtomId, vtkIdType endAtomId)
: Molecule(parent), Id(id), BeginAtomId(beginAtomId), EndAtomId(endAtomId)
{
assert(parent != 0);
assert(id < parent->GetNumberOfBonds());
assert(beginAtomId < parent->GetNumberOfAtoms());
assert(endAtomId < parent->GetNumberOfAtoms());
}
//----------------------------------------------------------------------------
vtkBond::~vtkBond()
{
}
//----------------------------------------------------------------------------
void vtkBond::PrintSelf(ostream &os, vtkIndent indent)
{
char buffer[80];
double coord[3];
snprintf(buffer, 80,
"Parent: %p Id: %4d Order: %1d Len: %9.5f BeginAtomId: %d "
"EndAtomId: %d\n", this->Molecule, this->Id, this->GetBondOrder(),
this->GetBondLength(), this->BeginAtomId, this->EndAtomId);
os << indent << buffer;
os << indent << "Bonded Atoms:\n";
this->Molecule->GetAtom(this->BeginAtomId).PrintSelf
(os, indent.GetNextIndent());
this->Molecule->GetAtom(this->EndAtomId).PrintSelf
(os, indent.GetNextIndent());
}
//----------------------------------------------------------------------------
double vtkBond::GetBondLength()
{
// 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);
return (pos2 - pos1).Norm();
}
//----------------------------------------------------------------------------
vtkAtom vtkBond::GetBeginAtom()
{
return this->Molecule->GetAtom(this->BeginAtomId);
}
//----------------------------------------------------------------------------
vtkAtom vtkBond::GetEndAtom()
{
return this->Molecule->GetAtom(this->EndAtomId);
}
//----------------------------------------------------------------------------
unsigned short vtkBond::GetBondOrder()
{
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);
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkBond.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkBond - convenience proxy for vtkMolecule
// .SECTION Description
#ifndef __vtkBond_h
#define __vtkBond_h
#include "vtkObject.h" // For macros, etc
#include "vtkAtom.h" // For vtkAtom
class vtkMolecule;
class vtkVector3d;
class vtkVector3f;
class VTK_FILTERING_EXPORT vtkBond
{
public:
~vtkBond();
void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Return the Id used to identify this bond in the parent molecule.
vtkIdType GetId()
{
return this->Id;
}
// Description:
// Return the parent molecule of this bond.
vtkMolecule * GetMolecule()
{
return this->Molecule;
}
// Description:
// Get the starting / ending atom ids for this bond.
vtkIdType GetBeginAtomId()
{
return this->BeginAtomId;
}
vtkIdType GetEndAtomId()
{
return this->EndAtomId;
}
// Description:
// Get a vtkAtom object that refers to the starting / ending atom
// for this bond.
vtkAtom GetBeginAtom();
vtkAtom GetEndAtom();
// Description:
// Get the bond order for this bond.
unsigned short GetBondOrder();
// Description:
// Get the distance between the bonded atoms
//
// @note This function is faster than vtkMolecule::GetBondLength and
// should be used when possible.
double GetBondLength();
// 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:
friend class vtkMolecule;
vtkBond(vtkMolecule *parent, vtkIdType id,
vtkIdType beginAtomId, vtkIdType endAtomId);
vtkMolecule *Molecule;
vtkIdType Id;
vtkIdType BeginAtomId;
vtkIdType EndAtomId;
};
#endif
......@@ -50,6 +50,10 @@ PURPOSE. See the above copyright notice for more information.
#include "vtkArrayData.h"
#endif
#ifdef VTK_USE_CHEMISTRY
#include "vtkMolecule.h"
#endif
vtkStandardNewMacro(vtkDataObjectTypes);
// This list should contain the data object class names in
......@@ -85,6 +89,9 @@ static const char* vtkDataObjectTypesStrings[] = {
"vtkDirectedAcyclicGraph",
"vtkArrayData",
"vtkReebGraph",
#ifdef VTK_USE_CHEMISTRY
"vtkMolecule",
#endif
NULL
};
......@@ -244,6 +251,12 @@ vtkDataObject* vtkDataObjectTypes::NewDataObject(const char* type)
{
return vtkReebGraph::New();
}
#ifdef VTK_USE_CHEMISTRY
else if(strcmp(type, "vtkMolecule") == 0)
{
return vtkMolecule::New();
}
#endif
#ifdef VTK_USE_N_WAY_ARRAYS
else if(strcmp(type, "vtkArrayData") == 0)
{
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkMolecule.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkMolecule.h"
#include "vtkDataSetAttributes.h"
#include "vtkEdgeListIterator.h"
#include "vtkIdTypeArray.h"
#include "vtkObjectFactory.h"
#include "vtkPlane.h"
#include "vtkPoints.h"
#include "vtkUnsignedShortArray.h"
#include "vtkVector.h"
#include "vtkVectorOperators.h"
#include <assert.h>
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkMolecule);
//----------------------------------------------------------------------------
vtkMolecule::vtkMolecule()
{
this->SetPoints(vtkPoints::New());
this->Initialize();
}
//----------------------------------------------------------------------------
void vtkMolecule::Initialize()
{
// Reset underlying data structure
this->Superclass::Initialize();
// Setup vertex data
vtkDataSetAttributes *vertData = this->GetVertexData();
vertData->AllocateArrays(1); // atomic nums
// Atomic numbers
vtkUnsignedShortArray *atomicNums = vtkUnsignedShortArray::New();
atomicNums->SetNumberOfComponents(1);
atomicNums->SetName("Atomic Numbers");
vertData->SetScalars(atomicNums);
// Nuclear coordinates
this->Points->Initialize();
// Setup edge data
vtkDataSetAttributes *edgeData = this->GetEdgeData();
edgeData->AllocateArrays(1); // Bond orders
vtkUnsignedShortArray *bondOrders = vtkUnsignedShortArray::New();
bondOrders->SetNumberOfComponents(1);
bondOrders->SetName("Bond Orders");
edgeData->SetScalars(bondOrders);
this->UpdateBondList();
this->Modified();
}
//----------------------------------------------------------------------------