1 /*=========================================================================
2
3 Program: Visualization Toolkit
4
5 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
6 All rights reserved.
7 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
8
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the above copyright notice for more information.
12
13 =========================================================================*/
14
15 #include "vtkMolecule.h"
16 #include "vtkNew.h"
17 #include "vtkVector.h"
18 #include "vtkVectorOperators.h"
19
20 // Example code from the molecule documentation. If this breaks,
21 // update the docs in vtkMolecule.h
MoleculeExampleCode1()22 bool MoleculeExampleCode1()
23 {
24 vtkNew<vtkMolecule> mol;
25 vtkAtom h1 = mol->AppendAtom(1, 0.0, 0.0, -0.5);
26 vtkAtom h2 = mol->AppendAtom(1, 0.0, 0.0, 0.5);
27 vtkBond b = mol->AppendBond(h1, h2, 1);
28 int errors(0);
29
30 if (fabs(b.GetLength() - 1.0) > 1e-8)
31 {
32 cout << "Error bond length incorrect. Expected 1.0, but got "
33 << b.GetLength() << endl;
34 ++errors;
35 }
36
37 if (!h1.GetPosition().Compare(vtkVector3f(0.0, 0.0, -0.5), 1e-8))
38 {
39 cout << "Error atom position incorrect. Expected 0.0, 0.0, -0.5 but got "
40 << h1.GetPosition() << endl;
41 ++errors;
42 }
43
44 if (!h2.GetPosition().Compare(vtkVector3f(0.0, 0.0, 0.5), 1e-8))
45 {
46 cout << "Error atom position incorrect. Expected 0.0, 0.0, 0.5 but got "
47 << h2.GetPosition() << endl;
48 ++errors;
49 }
50
51 if (h1.GetAtomicNumber() != 1)
52 {
53 cout << "Error atomic number incorrect. Expected 1 but got "
54 << h1.GetAtomicNumber() << endl;
55 ++errors;
56 }
57
58 if (h2.GetAtomicNumber() != 1)
59 {
60 cout << "Error atomic number incorrect. Expected 1 but got "
61 << h2.GetAtomicNumber() << endl;
62 ++errors;
63 }
64
65 return errors == 0;
66 }
67
68 // Example code from the molecule documentation. If this breaks,
69 // update the docs in vtkMolecule.h
MoleculeExampleCode2()70 bool MoleculeExampleCode2()
71 {
72 vtkNew<vtkMolecule> mol;
73
74 vtkAtom h1 = mol->AppendAtom();
75 h1.SetAtomicNumber(1);
76 h1.SetPosition(0.0, 0.0, -0.5);
77
78 vtkAtom h2 = mol->AppendAtom();
79 h2.SetAtomicNumber(1);
80 vtkVector3f displacement(0.0, 0.0, 1.0);
81 h2.SetPosition(h1.GetPosition() + displacement);
82
83 vtkBond b = mol->AppendBond(h1, h2, 1);
84
85 int errors(0);
86
87 if (fabs(b.GetLength() - 1.0) > 1e-8)
88 {
89 cout << "Error bond length incorrect. Expected 1.0, but got "
90 << b.GetLength() << endl;
91 ++errors;
92 }
93
94 if (!h1.GetPosition().Compare(vtkVector3f(0.0, 0.0, -0.5), 1e-8))
95 {
96 cout << "Error atom position incorrect. Expected 0.0, 0.0, -0.5 but got "
97 << h1.GetPosition() << endl;
98 ++errors;
99 }
100
101 if (!h2.GetPosition().Compare(vtkVector3f(0.0, 0.0, 0.5), 1e-8))
102 {
103 cout << "Error atom position incorrect. Expected 0.0, 0.0, 0.5 but got "
104 << h2.GetPosition() << endl;
105 ++errors;
106 }
107
108 if (h1.GetAtomicNumber() != 1)
109 {
110 cout << "Error atomic number incorrect. Expected 1 but got "
111 << h1.GetAtomicNumber() << endl;
112 ++errors;
113 }
114
115 if (h2.GetAtomicNumber() != 1)
116 {
117 cout << "Error atomic number incorrect. Expected 1 but got "
118 << h2.GetAtomicNumber() << endl;
119 ++errors;
120 }
121
122 return errors == 0;
123 }
124
TestMolecule(int,char * [])125 int TestMolecule(int, char * [])
126 {
127 // Check that the example code given in the molecule docs compiles:
128 bool test1 = MoleculeExampleCode1();
129 bool test2 = MoleculeExampleCode2();
130
131 return (test1 && test2) ? 0 : 1;
132 }
133