summaryrefslogtreecommitdiff
path: root/cad/plugins/NanoVision-1/src/Testing/OpenGL/TrajectoryGraphicsWindowTest.cpp
blob: 1cd29376314f5bc6c345d8a318f1f8c3f40392c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright 2008 Nanorex, Inc.  See LICENSE file for details.


#include <Nanorex/Interface/NXDataStoreInfo.h>
#include <Nanorex/Interface/NXEntityManager.h>
#include "TrajectoryTestGraphicsManager.h"
#include <Nanorex/Interface/NXAtomData.h>
#include <TrajectoryGraphicsWindow.h>

#include <cassert>

#include <QApplication>
#include <QMainWindow>

using namespace Nanorex;
using namespace OpenBabel;
using namespace std;

void initializeEntityManager(NXEntityManager *const entityManager,
                             NXMoleculeSet *theMoleculeSet[],
                             int const NUM_FRAMES);
void createMoleculeSets(NXMoleculeSet *molSetArray[], int const NUM_FRAMES);

int const NUM_FRAMES = 6;
int const NUM_ATOMS = 5;

// atom coordinates in Angstroms
double atomCoords[NUM_FRAMES][NUM_ATOMS][3] = {
	// frame-1
	{ { 0, 4}, { 0, 0}, { 2, 2}, { 4, 0}, { 4, 4} },
	{ {-1, 4}, { 0, 0}, { 1, 2}, { 3, 0}, { 4, 3} },
	{ {-1, 3}, { 0, 0}, { 1, 1}, { 3, 1}, { 4, 2} },
	{ { 0, 2}, { 0, 0}, { 1, 0}, { 4, 1}, { 5, 2} },
	{ {-1, 2}, { 0, 0}, { 2, 0}, { 4, 2}, { 6, 2} },
	{ {-1, 1}, { 0, 0}, { 2, 1}, { 4, 2}, { 6, 3} }
};

int atomicNums[NUM_ATOMS] = { 1, 8, 6, 16, 1 };


int main(int argc, char *argv[])
{
    // create application and main window
	QApplication app(argc, argv);
	QMainWindow mainWindow;
	mainWindow.resize(960, 600);
	
	NXDataStoreInfo dataStoreInfo;
	NXEntityManager entityManager;
	TrajectoryTestGraphicsManager graphicsManager;
	
	TrajectoryGraphicsWindow *trajectoryWindow =
		new TrajectoryGraphicsWindow((QWidget*) 0,
		                             &entityManager,
		                             &graphicsManager);
	
	mainWindow.setCentralWidget(trajectoryWindow);
	mainWindow.show();
	
	NXMoleculeSet *theMoleculeSet[NUM_FRAMES];
	assert(theMoleculeSet != NULL);
	createMoleculeSets(theMoleculeSet, NUM_FRAMES);
	initializeEntityManager(&entityManager, theMoleculeSet, NUM_FRAMES);
	trajectoryWindow->setFrameSetId(0);
	
	mainWindow.update();
	
	int retval = app.exec();
	
	// for(int iFrame = 0; iFrame < NUM_FRAMES; ++iFrame)
	//	delete theMoleculeSet[iFrame];
	
	return retval;
}


void initializeEntityManager(NXEntityManager *const entityManager,
                             NXMoleculeSet *theMoleculeSet[],
                             int const NUM_FRAMES)
{
	// assert(entityManager->getFrameCount(0) == 0);
	int frameSetId = entityManager->addFrameSet();
	for(int iFrame = 0; iFrame < NUM_FRAMES; ++iFrame) {
		int lastFrameId =
			entityManager->addFrame(frameSetId, theMoleculeSet[iFrame]);
		assert(lastFrameId == iFrame);
	}
	assert((int)entityManager->getFrameCount(frameSetId) == NUM_FRAMES);
}


void bond(OBMol *molPtr, OBAtom *atom1Ptr, OBAtom *atom2Ptr, int bondOrder)
{
	OBBond *bondPtr = molPtr->NewBond();
	assert(bondPtr != NULL);
	bondPtr->SetBegin(atom1Ptr);
	bondPtr->SetEnd(atom2Ptr);
	atom1Ptr->AddBond(bondPtr);
	atom2Ptr->AddBond(bondPtr);
	bondPtr->SetBondOrder(bondOrder);
}



void createMoleculeSets(NXMoleculeSet *molSetArray[], int const NUM_FRAMES)
{
	for(int iFrame = 0; iFrame < NUM_FRAMES; ++iFrame) {
		molSetArray[iFrame] = new NXMoleculeSet;
		assert(molSetArray[iFrame] != NULL);
		OBMol *mol = molSetArray[iFrame]->newMolecule();
		assert(mol != NULL);
		OBAtom *atom[NUM_ATOMS];
		for(int iAtom = 0; iAtom < NUM_ATOMS; ++iAtom) {
			atom[iAtom] = mol->NewAtom();
			assert(atom[iAtom] != NULL);
			atom[iAtom]->SetAtomicNum(atomicNums[iAtom]);
			NXAtomData *atomData = new NXAtomData(atomicNums[iAtom]);
			assert(atomData != NULL);
			atomData->setRenderStyleCode("def");
			atomData->setIdx(iAtom);
			atom[iAtom]->SetData(atomData);
			atom[iAtom]->SetVector(atomCoords[iFrame][iAtom][0],
			                       atomCoords[iFrame][iAtom][1],
			                       atomCoords[iFrame][iAtom][2]);
		}
		
		bond(mol, atom[0], atom[1], 1);
		bond(mol, atom[1], atom[2], 2);
		bond(mol, atom[2], atom[3], 2);
		bond(mol, atom[3], atom[4], 1);
	}
}