Example code from the molecule documentation. If this breaks, update the docs in vtkMolecule.h
| 58 | // Example code from the molecule documentation. If this breaks, |
| 59 | // update the docs in vtkMolecule.h |
| 60 | bool MoleculeExampleCode2() |
| 61 | { |
| 62 | vtkNew<vtkMolecule> mol; |
| 63 | |
| 64 | vtkAtom h1 = mol->AppendAtom(); |
| 65 | h1.SetAtomicNumber(1); |
| 66 | h1.SetPosition(0.0, 0.0, -0.5); |
| 67 | |
| 68 | vtkAtom h2 = mol->AppendAtom(); |
| 69 | h2.SetAtomicNumber(1); |
| 70 | vtkVector3f displacement(0.0, 0.0, 1.0); |
| 71 | h2.SetPosition(h1.GetPosition() + displacement); |
| 72 | |
| 73 | vtkBond b = mol->AppendBond(h1, h2, 1); |
| 74 | |
| 75 | int errors(0); |
| 76 | |
| 77 | if (fabs(b.GetLength() - 1.0) > 1e-8) |
| 78 | { |
| 79 | std::cout << "Error bond length incorrect. Expected 1.0, but got " << b.GetLength() |
| 80 | << std::endl; |
| 81 | ++errors; |
| 82 | } |
| 83 | |
| 84 | if (!h1.GetPosition().Compare(vtkVector3f(0.0, 0.0, -0.5), 1e-8)) |
| 85 | { |
| 86 | std::cout << "Error atom position incorrect. Expected 0.0, 0.0, -0.5 but got " |
| 87 | << h1.GetPosition() << std::endl; |
| 88 | ++errors; |
| 89 | } |
| 90 | |
| 91 | if (!h2.GetPosition().Compare(vtkVector3f(0.0, 0.0, 0.5), 1e-8)) |
| 92 | { |
| 93 | std::cout << "Error atom position incorrect. Expected 0.0, 0.0, 0.5 but got " |
| 94 | << h2.GetPosition() << std::endl; |
| 95 | ++errors; |
| 96 | } |
| 97 | |
| 98 | if (h1.GetAtomicNumber() != 1) |
| 99 | { |
| 100 | std::cout << "Error atomic number incorrect. Expected 1 but got " << h1.GetAtomicNumber() |
| 101 | << std::endl; |
| 102 | ++errors; |
| 103 | } |
| 104 | |
| 105 | if (h2.GetAtomicNumber() != 1) |
| 106 | { |
| 107 | std::cout << "Error atomic number incorrect. Expected 1 but got " << h2.GetAtomicNumber() |
| 108 | << std::endl; |
| 109 | ++errors; |
| 110 | } |
| 111 | |
| 112 | return errors == 0; |
| 113 | } |
| 114 | |
| 115 | int TestMolecule(int, char*[]) |
| 116 | { |
no test coverage detected